summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2019-07-18 18:57:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 20:08:06 -0400
commit4c4b7f9ba9486c565aead99a198ceeef73ae81f6 (patch)
tree8830e026e9ae8704050ca76f1253c34663c78957
parent05f800a0bd08e14606ac63e0a5c63ed6880acaab (diff)
mm/memory_hotplug: remove memory block devices before arch_remove_memory()
Let's factor out removing of memory block devices, which is only necessary for memory added via add_memory() and friends that created memory block devices. Remove the devices before calling arch_remove_memory(). This finishes factoring out memory block device handling from arch_add_memory() and arch_remove_memory(). Link: http://lkml.kernel.org/r/20190527111152.16324-10-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: David Hildenbrand <david@redhat.com> Cc: "mike.travis@hpe.com" <mike.travis@hpe.com> Cc: Andrew Banman <andrew.banman@hpe.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Mark Brown <broonie@kernel.org> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Oscar Salvador <osalvador@suse.de> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Arun KS <arunks@codeaurora.org> Cc: Mathieu Malaterre <malat@debian.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Baoquan He <bhe@redhat.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chintan Pandya <cpandya@codeaurora.org> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Jun Yao <yaojun8558363@gmail.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oscar Salvador <osalvador@suse.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Qian Cai <cai@lca.pw> Cc: Rich Felker <dalias@libc.org> Cc: Rob Herring <robh@kernel.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Yu Zhao <yuzhao@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/base/memory.c37
-rw-r--r--drivers/base/node.c11
-rw-r--r--include/linux/memory.h2
-rw-r--r--include/linux/node.h6
-rw-r--r--mm/memory_hotplug.c5
5 files changed, 30 insertions, 31 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 18a30c3ac0ef..826dd76f662e 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -759,32 +759,31 @@ int create_memory_block_devices(unsigned long start, unsigned long size)
759 return ret; 759 return ret;
760} 760}
761 761
762void unregister_memory_section(struct mem_section *section) 762/*
763 * Remove memory block devices for the given memory area. Start and size
764 * have to be aligned to memory block granularity. Memory block devices
765 * have to be offline.
766 */
767void remove_memory_block_devices(unsigned long start, unsigned long size)
763{ 768{
769 const int start_block_id = pfn_to_block_id(PFN_DOWN(start));
770 const int end_block_id = pfn_to_block_id(PFN_DOWN(start + size));
764 struct memory_block *mem; 771 struct memory_block *mem;
772 int block_id;
765 773
766 if (WARN_ON_ONCE(!present_section(section))) 774 if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) ||
775 !IS_ALIGNED(size, memory_block_size_bytes())))
767 return; 776 return;
768 777
769 mutex_lock(&mem_sysfs_mutex); 778 mutex_lock(&mem_sysfs_mutex);
770 779 for (block_id = start_block_id; block_id != end_block_id; block_id++) {
771 /* 780 mem = find_memory_block_by_id(block_id, NULL);
772 * Some users of the memory hotplug do not want/need memblock to 781 if (WARN_ON_ONCE(!mem))
773 * track all sections. Skip over those. 782 continue;
774 */ 783 mem->section_count = 0;
775 mem = find_memory_block(section); 784 unregister_memory_block_under_nodes(mem);
776 if (!mem)
777 goto out_unlock;
778
779 unregister_mem_sect_under_nodes(mem, __section_nr(section));
780
781 mem->section_count--;
782 if (mem->section_count == 0)
783 unregister_memory(mem); 785 unregister_memory(mem);
784 else 786 }
785 put_device(&mem->dev);
786
787out_unlock:
788 mutex_unlock(&mem_sysfs_mutex); 787 mutex_unlock(&mem_sysfs_mutex);
789} 788}
790 789
diff --git a/drivers/base/node.c b/drivers/base/node.c
index aa878fbcf705..0b0f38c2c7cd 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -802,9 +802,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
802 return 0; 802 return 0;
803} 803}
804 804
805/* unregister memory section under all nodes that it spans */ 805/*
806int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 806 * Unregister memory block device under all nodes that it spans.
807 unsigned long phys_index) 807 */
808int unregister_memory_block_under_nodes(struct memory_block *mem_blk)
808{ 809{
809 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); 810 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
810 unsigned long pfn, sect_start_pfn, sect_end_pfn; 811 unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -817,8 +818,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
817 return -ENOMEM; 818 return -ENOMEM;
818 nodes_clear(*unlinked_nodes); 819 nodes_clear(*unlinked_nodes);
819 820
820 sect_start_pfn = section_nr_to_pfn(phys_index); 821 sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
821 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 822 sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
822 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 823 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
823 int nid; 824 int nid;
824 825
diff --git a/include/linux/memory.h b/include/linux/memory.h
index db3e8567f900..f26a5417ec5d 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -112,7 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb);
112extern int register_memory_isolate_notifier(struct notifier_block *nb); 112extern int register_memory_isolate_notifier(struct notifier_block *nb);
113extern void unregister_memory_isolate_notifier(struct notifier_block *nb); 113extern void unregister_memory_isolate_notifier(struct notifier_block *nb);
114int create_memory_block_devices(unsigned long start, unsigned long size); 114int create_memory_block_devices(unsigned long start, unsigned long size);
115extern void unregister_memory_section(struct mem_section *); 115void remove_memory_block_devices(unsigned long start, unsigned long size);
116extern int memory_dev_init(void); 116extern int memory_dev_init(void);
117extern int memory_notify(unsigned long val, void *v); 117extern int memory_notify(unsigned long val, void *v);
118extern int memory_isolate_notify(unsigned long val, void *v); 118extern int memory_isolate_notify(unsigned long val, void *v);
diff --git a/include/linux/node.h b/include/linux/node.h
index 1a557c589ecb..02a29e71b175 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -139,8 +139,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
139extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 139extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
140extern int register_mem_sect_under_node(struct memory_block *mem_blk, 140extern int register_mem_sect_under_node(struct memory_block *mem_blk,
141 void *arg); 141 void *arg);
142extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 142extern int unregister_memory_block_under_nodes(struct memory_block *mem_blk);
143 unsigned long phys_index);
144 143
145extern int register_memory_node_under_compute_node(unsigned int mem_nid, 144extern int register_memory_node_under_compute_node(unsigned int mem_nid,
146 unsigned int cpu_nid, 145 unsigned int cpu_nid,
@@ -176,8 +175,7 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
176{ 175{
177 return 0; 176 return 0;
178} 177}
179static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 178static inline int unregister_memory_block_under_nodes(struct memory_block *mem_blk)
180 unsigned long phys_index)
181{ 179{
182 return 0; 180 return 0;
183} 181}
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index fb9dc3fa1138..37c861e7a717 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -520,8 +520,6 @@ static void __remove_section(struct zone *zone, struct mem_section *ms,
520 if (WARN_ON_ONCE(!valid_section(ms))) 520 if (WARN_ON_ONCE(!valid_section(ms)))
521 return; 521 return;
522 522
523 unregister_memory_section(ms);
524
525 scn_nr = __section_nr(ms); 523 scn_nr = __section_nr(ms);
526 start_pfn = section_nr_to_pfn((unsigned long)scn_nr); 524 start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
527 __remove_zone(zone, start_pfn); 525 __remove_zone(zone, start_pfn);
@@ -1834,6 +1832,9 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
1834 memblock_free(start, size); 1832 memblock_free(start, size);
1835 memblock_remove(start, size); 1833 memblock_remove(start, size);
1836 1834
1835 /* remove memory block devices before removing memory */
1836 remove_memory_block_devices(start, size);
1837
1837 arch_remove_memory(nid, start, size, NULL); 1838 arch_remove_memory(nid, start, size, NULL);
1838 __release_memory_resource(start, size); 1839 __release_memory_resource(start, size);
1839 1840