Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

device-dax: make align a per-device property

Introduce @align to struct dev_dax.

When creating a new device, we still initialize to the default dax_region
@align. Child devices belonging to a region may wish to keep a different
alignment property instead of a global region-defined one.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: David Airlie <airlied@linux.ie>
Cc: David Hildenbrand <david@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hulk Robot <hulkci@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: Jason Yan <yanaijie@huawei.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: "Jérôme Glisse" <jglisse@redhat.com>
Cc: Jia He <justin.he@arm.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/r/159643105377.4062302.4159447829955683131.stgit@dwillia2-desk3.amr.corp.intel.com
Link: https://lore.kernel.org/r/20200716172913.19658-2-joao.m.martins@oracle.com
Link: https://lkml.kernel.org/r/160106117957.30709.1142303024324655705.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joao Martins and committed by
Linus Torvalds
33cf94d7 0b07ce87

+19 -26
+1
drivers/dax/bus.c
··· 1218 1218 1219 1219 dev_dax->dax_dev = dax_dev; 1220 1220 dev_dax->target_node = dax_region->target_node; 1221 + dev_dax->align = dax_region->align; 1221 1222 ida_init(&dev_dax->ida); 1222 1223 kref_get(&dax_region->kref); 1223 1224
+3
drivers/dax/dax-private.h
··· 62 62 struct dev_dax { 63 63 struct dax_region *region; 64 64 struct dax_device *dax_dev; 65 + unsigned int align; 65 66 int target_node; 66 67 int id; 67 68 struct ida ida; ··· 85 84 { 86 85 return container_of(dev, struct dax_mapping, dev); 87 86 } 87 + 88 + phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size); 88 89 #endif
+15 -26
drivers/dax/device.c
··· 17 17 static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, 18 18 const char *func) 19 19 { 20 - struct dax_region *dax_region = dev_dax->region; 21 20 struct device *dev = &dev_dax->dev; 22 21 unsigned long mask; 23 22 ··· 31 32 return -EINVAL; 32 33 } 33 34 34 - mask = dax_region->align - 1; 35 + mask = dev_dax->align - 1; 35 36 if (vma->vm_start & mask || vma->vm_end & mask) { 36 37 dev_info_ratelimited(dev, 37 38 "%s: %s: fail, unaligned vma (%#lx - %#lx, %#lx)\n", ··· 77 78 struct vm_fault *vmf, pfn_t *pfn) 78 79 { 79 80 struct device *dev = &dev_dax->dev; 80 - struct dax_region *dax_region; 81 81 phys_addr_t phys; 82 82 unsigned int fault_size = PAGE_SIZE; 83 83 84 84 if (check_vma(dev_dax, vmf->vma, __func__)) 85 85 return VM_FAULT_SIGBUS; 86 86 87 - dax_region = dev_dax->region; 88 - if (dax_region->align > PAGE_SIZE) { 87 + if (dev_dax->align > PAGE_SIZE) { 89 88 dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", 90 - dax_region->align, fault_size); 89 + dev_dax->align, fault_size); 91 90 return VM_FAULT_SIGBUS; 92 91 } 93 92 94 - if (fault_size != dax_region->align) 93 + if (fault_size != dev_dax->align) 95 94 return VM_FAULT_SIGBUS; 96 95 97 96 phys = dax_pgoff_to_phys(dev_dax, vmf->pgoff, PAGE_SIZE); ··· 108 111 { 109 112 unsigned long pmd_addr = vmf->address & PMD_MASK; 110 113 struct device *dev = &dev_dax->dev; 111 - struct dax_region *dax_region; 112 114 phys_addr_t phys; 113 115 pgoff_t pgoff; 114 116 unsigned int fault_size = PMD_SIZE; ··· 115 119 if (check_vma(dev_dax, vmf->vma, __func__)) 116 120 return VM_FAULT_SIGBUS; 117 121 118 - dax_region = dev_dax->region; 119 - if (dax_region->align > PMD_SIZE) { 122 + if (dev_dax->align > PMD_SIZE) { 120 123 dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", 121 - dax_region->align, fault_size); 124 + dev_dax->align, fault_size); 122 125 return VM_FAULT_SIGBUS; 123 126 } 124 127 125 - if (fault_size < dax_region->align) 128 + if (fault_size < dev_dax->align) 126 129 return VM_FAULT_SIGBUS; 127 - else if (fault_size > dax_region->align) 130 + else if (fault_size > dev_dax->align) 128 131 return VM_FAULT_FALLBACK; 129 132 130 133 /* if we are outside of the VMA */ ··· 149 154 { 150 155 unsigned long pud_addr = vmf->address & PUD_MASK; 151 156 struct device *dev = &dev_dax->dev; 152 - struct dax_region *dax_region; 153 157 phys_addr_t phys; 154 158 pgoff_t pgoff; 155 159 unsigned int fault_size = PUD_SIZE; ··· 157 163 if (check_vma(dev_dax, vmf->vma, __func__)) 158 164 return VM_FAULT_SIGBUS; 159 165 160 - dax_region = dev_dax->region; 161 - if (dax_region->align > PUD_SIZE) { 166 + if (dev_dax->align > PUD_SIZE) { 162 167 dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", 163 - dax_region->align, fault_size); 168 + dev_dax->align, fault_size); 164 169 return VM_FAULT_SIGBUS; 165 170 } 166 171 167 - if (fault_size < dax_region->align) 172 + if (fault_size < dev_dax->align) 168 173 return VM_FAULT_SIGBUS; 169 - else if (fault_size > dax_region->align) 174 + else if (fault_size > dev_dax->align) 170 175 return VM_FAULT_FALLBACK; 171 176 172 177 /* if we are outside of the VMA */ ··· 260 267 { 261 268 struct file *filp = vma->vm_file; 262 269 struct dev_dax *dev_dax = filp->private_data; 263 - struct dax_region *dax_region = dev_dax->region; 264 270 265 - if (!IS_ALIGNED(addr, dax_region->align)) 271 + if (!IS_ALIGNED(addr, dev_dax->align)) 266 272 return -EINVAL; 267 273 return 0; 268 274 } ··· 270 278 { 271 279 struct file *filp = vma->vm_file; 272 280 struct dev_dax *dev_dax = filp->private_data; 273 - struct dax_region *dax_region = dev_dax->region; 274 281 275 - return dax_region->align; 282 + return dev_dax->align; 276 283 } 277 284 278 285 static const struct vm_operations_struct dax_vm_ops = { ··· 310 319 { 311 320 unsigned long off, off_end, off_align, len_align, addr_align, align; 312 321 struct dev_dax *dev_dax = filp ? filp->private_data : NULL; 313 - struct dax_region *dax_region; 314 322 315 323 if (!dev_dax || addr) 316 324 goto out; 317 325 318 - dax_region = dev_dax->region; 319 - align = dax_region->align; 326 + align = dev_dax->align; 320 327 off = pgoff << PAGE_SHIFT; 321 328 off_end = off + len; 322 329 off_align = round_up(off, align);