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

Configure Feed

Select the types of activity you want to include in your feed.

device-dax/kmem: introduce dax_kmem_range()

Towards removing the mode specific @dax_kmem_res attribute from the
generic 'struct dev_dax', and preparing for multi-range support, teach the
driver to calculate the hotplug range from the device range. The hotplug
range is the trivially calculated memory-block-size aligned version of the
device range.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jia He <justin.he@arm.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
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: Catalin Marinas <catalin.marinas@arm.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
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: 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: 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: 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: 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/160106111109.30709.3173462396758431559.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dan Williams and committed by
Linus Torvalds
59bc8d10 f5516ec5

+17 -23
+17 -23
drivers/dax/kmem.c
··· 19 19 /* Set if any memory will remain added when the driver will be unloaded. */ 20 20 static bool any_hotremove_failed; 21 21 22 + static struct range dax_kmem_range(struct dev_dax *dev_dax) 23 + { 24 + struct range range; 25 + 26 + /* memory-block align the hotplug range */ 27 + range.start = ALIGN(dev_dax->range.start, memory_block_size_bytes()); 28 + range.end = ALIGN_DOWN(dev_dax->range.end + 1, memory_block_size_bytes()) - 1; 29 + return range; 30 + } 31 + 22 32 int dev_dax_kmem_probe(struct device *dev) 23 33 { 24 34 struct dev_dax *dev_dax = to_dev_dax(dev); 25 - struct range *range = &dev_dax->range; 26 - resource_size_t kmem_start; 27 - resource_size_t kmem_size; 28 - resource_size_t kmem_end; 35 + struct range range = dax_kmem_range(dev_dax); 29 36 struct resource *new_res; 30 37 const char *new_res_name; 31 38 int numa_node; ··· 51 44 return -EINVAL; 52 45 } 53 46 54 - /* Hotplug starting at the beginning of the next block: */ 55 - kmem_start = ALIGN(range->start, memory_block_size_bytes()); 56 - 57 - kmem_size = range_len(range); 58 - /* Adjust the size down to compensate for moving up kmem_start: */ 59 - kmem_size -= kmem_start - range->start; 60 - /* Align the size down to cover only complete blocks: */ 61 - kmem_size &= ~(memory_block_size_bytes() - 1); 62 - kmem_end = kmem_start + kmem_size; 63 - 64 47 new_res_name = kstrdup(dev_name(dev), GFP_KERNEL); 65 48 if (!new_res_name) 66 49 return -ENOMEM; 67 50 68 51 /* Region is permanently reserved if hotremove fails. */ 69 - new_res = request_mem_region(kmem_start, kmem_size, new_res_name); 52 + new_res = request_mem_region(range.start, range_len(&range), new_res_name); 70 53 if (!new_res) { 71 - dev_warn(dev, "could not reserve region [%pa-%pa]\n", 72 - &kmem_start, &kmem_end); 54 + dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end); 73 55 kfree(new_res_name); 74 56 return -EBUSY; 75 57 } ··· 92 96 static int dev_dax_kmem_remove(struct device *dev) 93 97 { 94 98 struct dev_dax *dev_dax = to_dev_dax(dev); 99 + struct range range = dax_kmem_range(dev_dax); 95 100 struct resource *res = dev_dax->dax_kmem_res; 96 - resource_size_t kmem_start = res->start; 97 - resource_size_t kmem_size = resource_size(res); 98 101 const char *res_name = res->name; 99 102 int rc; 100 103 ··· 103 108 * there is no way to hotremove this memory until reboot because device 104 109 * unbind will succeed even if we return failure. 105 110 */ 106 - rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size); 111 + rc = remove_memory(dev_dax->target_node, range.start, range_len(&range)); 107 112 if (rc) { 108 113 any_hotremove_failed = true; 109 - dev_err(dev, 110 - "DAX region %pR cannot be hotremoved until the next reboot\n", 111 - res); 114 + dev_err(dev, "%#llx-%#llx cannot be hotremoved until the next reboot\n", 115 + range.start, range.end); 112 116 return rc; 113 117 } 114 118