summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2019-07-18 18:57:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 20:08:06 -0400
commitfbcf73ce65827c3d8935f38b832a43153a0c78d1 (patch)
tree096539bb9b1afeacca65c1e1e584857238bb6407
parent8d595c4c0f768f19db043d378b22e98405f9fd47 (diff)
mm/memory_hotplug: rename walk_memory_range() and pass start+size instead of pfns
walk_memory_range() was once used to iterate over sections. Now, it iterates over memory blocks. Rename the function, fixup the documentation. Also, pass start+size instead of PFNs, which is what most callers already have at hand. (we'll rework link_mem_sections() most probably soon) Follow-up patches will rework, simplify, and move walk_memory_blocks() to drivers/base/memory.c. Note: walk_memory_blocks() only works correctly right now if the start_pfn is aligned to a section start. This is the case right now, but we'll generalize the function in a follow up patch so the semantics match the documentation. [akpm@linux-foundation.org: remove unused variable] Link: http://lkml.kernel.org/r/20190614100114.311-5-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Len Brown <lenb@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: David Hildenbrand <david@redhat.com> Cc: Rashmica Gupta <rashmica.g@gmail.com> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Michael Neuling <mikey@neuling.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Oscar Salvador <osalvador@suse.de> Cc: Michal Hocko <mhocko@suse.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Juergen Gross <jgross@suse.com> Cc: Qian Cai <cai@lca.pw> Cc: Arun KS <arunks@codeaurora.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/powerpc/platforms/powernv/memtrace.c23
-rw-r--r--drivers/acpi/acpi_memhotplug.c19
-rw-r--r--drivers/base/node.c5
-rw-r--r--include/linux/memory_hotplug.h2
-rw-r--r--mm/memory_hotplug.c24
5 files changed, 32 insertions, 41 deletions
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c
index 5e53c1392d3b..eb2e75dac369 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -70,23 +70,23 @@ static int change_memblock_state(struct memory_block *mem, void *arg)
70/* called with device_hotplug_lock held */ 70/* called with device_hotplug_lock held */
71static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) 71static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
72{ 72{
73 u64 end_pfn = start_pfn + nr_pages - 1; 73 const unsigned long start = PFN_PHYS(start_pfn);
74 const unsigned long size = PFN_PHYS(nr_pages);
74 75
75 if (walk_memory_range(start_pfn, end_pfn, NULL, 76 if (walk_memory_blocks(start, size, NULL, check_memblock_online))
76 check_memblock_online))
77 return false; 77 return false;
78 78
79 walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE, 79 walk_memory_blocks(start, size, (void *)MEM_GOING_OFFLINE,
80 change_memblock_state); 80 change_memblock_state);
81 81
82 if (offline_pages(start_pfn, nr_pages)) { 82 if (offline_pages(start_pfn, nr_pages)) {
83 walk_memory_range(start_pfn, end_pfn, (void *)MEM_ONLINE, 83 walk_memory_blocks(start, size, (void *)MEM_ONLINE,
84 change_memblock_state); 84 change_memblock_state);
85 return false; 85 return false;
86 } 86 }
87 87
88 walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE, 88 walk_memory_blocks(start, size, (void *)MEM_OFFLINE,
89 change_memblock_state); 89 change_memblock_state);
90 90
91 91
92 return true; 92 return true;
@@ -242,9 +242,8 @@ static int memtrace_online(void)
242 */ 242 */
243 if (!memhp_auto_online) { 243 if (!memhp_auto_online) {
244 lock_device_hotplug(); 244 lock_device_hotplug();
245 walk_memory_range(PFN_DOWN(ent->start), 245 walk_memory_blocks(ent->start, ent->size, NULL,
246 PFN_UP(ent->start + ent->size - 1), 246 online_mem_block);
247 NULL, online_mem_block);
248 unlock_device_hotplug(); 247 unlock_device_hotplug();
249 } 248 }
250 249
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index db013dc21c02..e294f44a7850 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -155,16 +155,6 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
155 return 0; 155 return 0;
156} 156}
157 157
158static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info)
159{
160 return PFN_DOWN(info->start_addr);
161}
162
163static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info)
164{
165 return PFN_UP(info->start_addr + info->length-1);
166}
167
168static int acpi_bind_memblk(struct memory_block *mem, void *arg) 158static int acpi_bind_memblk(struct memory_block *mem, void *arg)
169{ 159{
170 return acpi_bind_one(&mem->dev, arg); 160 return acpi_bind_one(&mem->dev, arg);
@@ -173,9 +163,8 @@ static int acpi_bind_memblk(struct memory_block *mem, void *arg)
173static int acpi_bind_memory_blocks(struct acpi_memory_info *info, 163static int acpi_bind_memory_blocks(struct acpi_memory_info *info,
174 struct acpi_device *adev) 164 struct acpi_device *adev)
175{ 165{
176 return walk_memory_range(acpi_meminfo_start_pfn(info), 166 return walk_memory_blocks(info->start_addr, info->length, adev,
177 acpi_meminfo_end_pfn(info), adev, 167 acpi_bind_memblk);
178 acpi_bind_memblk);
179} 168}
180 169
181static int acpi_unbind_memblk(struct memory_block *mem, void *arg) 170static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
@@ -186,8 +175,8 @@ static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
186 175
187static void acpi_unbind_memory_blocks(struct acpi_memory_info *info) 176static void acpi_unbind_memory_blocks(struct acpi_memory_info *info)
188{ 177{
189 walk_memory_range(acpi_meminfo_start_pfn(info), 178 walk_memory_blocks(info->start_addr, info->length, NULL,
190 acpi_meminfo_end_pfn(info), NULL, acpi_unbind_memblk); 179 acpi_unbind_memblk);
191} 180}
192 181
193static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 182static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 27391f1e8f60..75b7e6f6535b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -834,8 +834,9 @@ void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
834 834
835int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) 835int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
836{ 836{
837 return walk_memory_range(start_pfn, end_pfn, (void *)&nid, 837 return walk_memory_blocks(PFN_PHYS(start_pfn),
838 register_mem_sect_under_node); 838 PFN_PHYS(end_pfn - start_pfn), (void *)&nid,
839 register_mem_sect_under_node);
839} 840}
840 841
841#ifdef CONFIG_HUGETLBFS 842#ifdef CONFIG_HUGETLBFS
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 79e0add6a597..d9fffc34949f 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -340,7 +340,7 @@ static inline void __remove_memory(int nid, u64 start, u64 size) {}
340#endif /* CONFIG_MEMORY_HOTREMOVE */ 340#endif /* CONFIG_MEMORY_HOTREMOVE */
341 341
342extern void __ref free_area_init_core_hotplug(int nid); 342extern void __ref free_area_init_core_hotplug(int nid);
343extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, 343extern int walk_memory_blocks(unsigned long start, unsigned long size,
344 void *arg, int (*func)(struct memory_block *, void *)); 344 void *arg, int (*func)(struct memory_block *, void *));
345extern int __add_memory(int nid, u64 start, u64 size); 345extern int __add_memory(int nid, u64 start, u64 size);
346extern int add_memory(int nid, u64 start, u64 size); 346extern int add_memory(int nid, u64 start, u64 size);
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index d1d0ceaaca88..b3ef84e408fa 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1124,8 +1124,7 @@ int __ref add_memory_resource(int nid, struct resource *res)
1124 1124
1125 /* online pages if requested */ 1125 /* online pages if requested */
1126 if (memhp_auto_online) 1126 if (memhp_auto_online)
1127 walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), 1127 walk_memory_blocks(start, size, NULL, online_memory_block);
1128 NULL, online_memory_block);
1129 1128
1130 return ret; 1129 return ret;
1131error: 1130error:
@@ -1663,20 +1662,24 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
1663#endif /* CONFIG_MEMORY_HOTREMOVE */ 1662#endif /* CONFIG_MEMORY_HOTREMOVE */
1664 1663
1665/** 1664/**
1666 * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) 1665 * walk_memory_blocks - walk through all present memory blocks overlapped
1667 * @start_pfn: start pfn of the memory range 1666 * by the range [start, start + size)
1668 * @end_pfn: end pfn of the memory range 1667 *
1668 * @start: start address of the memory range
1669 * @size: size of the memory range
1669 * @arg: argument passed to func 1670 * @arg: argument passed to func
1670 * @func: callback for each memory section walked 1671 * @func: callback for each memory block walked
1671 * 1672 *
1672 * This function walks through all present mem sections in range 1673 * This function walks through all present memory blocks overlapped by the
1673 * [start_pfn, end_pfn) and call func on each mem section. 1674 * range [start, start + size), calling func on each memory block.
1674 * 1675 *
1675 * Returns the return value of func. 1676 * Returns the return value of func.
1676 */ 1677 */
1677int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, 1678int walk_memory_blocks(unsigned long start, unsigned long size,
1678 void *arg, int (*func)(struct memory_block *, void *)) 1679 void *arg, int (*func)(struct memory_block *, void *))
1679{ 1680{
1681 const unsigned long start_pfn = PFN_DOWN(start);
1682 const unsigned long end_pfn = PFN_UP(start + size - 1);
1680 struct memory_block *mem = NULL; 1683 struct memory_block *mem = NULL;
1681 struct mem_section *section; 1684 struct mem_section *section;
1682 unsigned long pfn, section_nr; 1685 unsigned long pfn, section_nr;
@@ -1822,8 +1825,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
1822 * whether all memory blocks in question are offline and return error 1825 * whether all memory blocks in question are offline and return error
1823 * if this is not the case. 1826 * if this is not the case.
1824 */ 1827 */
1825 rc = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL, 1828 rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
1826 check_memblock_offlined_cb);
1827 if (rc) 1829 if (rc)
1828 goto done; 1830 goto done;
1829 1831