summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2019-07-18 18:56:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 20:08:06 -0400
commit80ec922dbd87fd38d15719c86a94457204648aeb (patch)
treed7ed87106ca1faf7fc1cc2fd4f26699447e44872
parent1811582587c43bdf13d690d83345610d4df433bb (diff)
mm/memory_hotplug: allow arch_remove_memory() without CONFIG_MEMORY_HOTREMOVE
We want to improve error handling while adding memory by allowing to use arch_remove_memory() and __remove_pages() even if CONFIG_MEMORY_HOTREMOVE is not set to e.g., implement something like: arch_add_memory() rc = do_something(); if (rc) { arch_remove_memory(); } We won't get rid of CONFIG_MEMORY_HOTREMOVE for now, as it will require quite some dependencies for memory offlining. Link: http://lkml.kernel.org/r/20190527111152.16324-7-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Rich Felker <dalias@libc.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: David Hildenbrand <david@redhat.com> Cc: Oscar Salvador <osalvador@suse.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> 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: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Rob Herring <robh@kernel.org> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: "mike.travis@hpe.com" <mike.travis@hpe.com> Cc: Andrew Banman <andrew.banman@hpe.com> Cc: Arun KS <arunks@codeaurora.org> Cc: Qian Cai <cai@lca.pw> Cc: Mathieu Malaterre <malat@debian.org> Cc: Baoquan He <bhe@redhat.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chintan Pandya <cpandya@codeaurora.org> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Jun Yao <yaojun8558363@gmail.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Will Deacon <will.deacon@arm.com> 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--arch/arm64/mm/mmu.c2
-rw-r--r--arch/ia64/mm/init.c2
-rw-r--r--arch/powerpc/mm/mem.c2
-rw-r--r--arch/s390/mm/init.c2
-rw-r--r--arch/sh/mm/init.c2
-rw-r--r--arch/x86/mm/init_32.c2
-rw-r--r--arch/x86/mm/init_64.c2
-rw-r--r--drivers/base/memory.c2
-rw-r--r--include/linux/memory.h2
-rw-r--r--include/linux/memory_hotplug.h2
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/sparse.c6
12 files changed, 0 insertions, 28 deletions
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index a21fa7e1167d..750a69dde39b 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1074,7 +1074,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
1074 return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, 1074 return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT,
1075 restrictions); 1075 restrictions);
1076} 1076}
1077#ifdef CONFIG_MEMORY_HOTREMOVE
1078void arch_remove_memory(int nid, u64 start, u64 size, 1077void arch_remove_memory(int nid, u64 start, u64 size,
1079 struct vmem_altmap *altmap) 1078 struct vmem_altmap *altmap)
1080{ 1079{
@@ -1093,4 +1092,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
1093 __remove_pages(zone, start_pfn, nr_pages, altmap); 1092 __remove_pages(zone, start_pfn, nr_pages, altmap);
1094} 1093}
1095#endif 1094#endif
1096#endif
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index d28e29103bdb..aae75fd7b810 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -681,7 +681,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
681 return ret; 681 return ret;
682} 682}
683 683
684#ifdef CONFIG_MEMORY_HOTREMOVE
685void arch_remove_memory(int nid, u64 start, u64 size, 684void arch_remove_memory(int nid, u64 start, u64 size,
686 struct vmem_altmap *altmap) 685 struct vmem_altmap *altmap)
687{ 686{
@@ -693,4 +692,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
693 __remove_pages(zone, start_pfn, nr_pages, altmap); 692 __remove_pages(zone, start_pfn, nr_pages, altmap);
694} 693}
695#endif 694#endif
696#endif
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 26a8da3723bb..9259337d7374 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -125,7 +125,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size,
125 return __add_pages(nid, start_pfn, nr_pages, restrictions); 125 return __add_pages(nid, start_pfn, nr_pages, restrictions);
126} 126}
127 127
128#ifdef CONFIG_MEMORY_HOTREMOVE
129void __ref arch_remove_memory(int nid, u64 start, u64 size, 128void __ref arch_remove_memory(int nid, u64 start, u64 size,
130 struct vmem_altmap *altmap) 129 struct vmem_altmap *altmap)
131{ 130{
@@ -151,7 +150,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
151 pr_warn("Hash collision while resizing HPT\n"); 150 pr_warn("Hash collision while resizing HPT\n");
152} 151}
153#endif 152#endif
154#endif /* CONFIG_MEMORY_HOTPLUG */
155 153
156#ifndef CONFIG_NEED_MULTIPLE_NODES 154#ifndef CONFIG_NEED_MULTIPLE_NODES
157void __init mem_topology_setup(void) 155void __init mem_topology_setup(void)
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 5b1ec2f532e0..4e5bbe328594 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -286,7 +286,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
286 return rc; 286 return rc;
287} 287}
288 288
289#ifdef CONFIG_MEMORY_HOTREMOVE
290void arch_remove_memory(int nid, u64 start, u64 size, 289void arch_remove_memory(int nid, u64 start, u64 size,
291 struct vmem_altmap *altmap) 290 struct vmem_altmap *altmap)
292{ 291{
@@ -298,5 +297,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
298 __remove_pages(zone, start_pfn, nr_pages, altmap); 297 __remove_pages(zone, start_pfn, nr_pages, altmap);
299 vmem_remove_mapping(start, size); 298 vmem_remove_mapping(start, size);
300} 299}
301#endif
302#endif /* CONFIG_MEMORY_HOTPLUG */ 300#endif /* CONFIG_MEMORY_HOTPLUG */
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 13c6a6bb5fd9..dfdbaa50946e 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -429,7 +429,6 @@ int memory_add_physaddr_to_nid(u64 addr)
429EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); 429EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
430#endif 430#endif
431 431
432#ifdef CONFIG_MEMORY_HOTREMOVE
433void arch_remove_memory(int nid, u64 start, u64 size, 432void arch_remove_memory(int nid, u64 start, u64 size,
434 struct vmem_altmap *altmap) 433 struct vmem_altmap *altmap)
435{ 434{
@@ -440,5 +439,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
440 zone = page_zone(pfn_to_page(start_pfn)); 439 zone = page_zone(pfn_to_page(start_pfn));
441 __remove_pages(zone, start_pfn, nr_pages, altmap); 440 __remove_pages(zone, start_pfn, nr_pages, altmap);
442} 441}
443#endif
444#endif /* CONFIG_MEMORY_HOTPLUG */ 442#endif /* CONFIG_MEMORY_HOTPLUG */
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index f265a4316179..4068abb9427f 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -860,7 +860,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
860 return __add_pages(nid, start_pfn, nr_pages, restrictions); 860 return __add_pages(nid, start_pfn, nr_pages, restrictions);
861} 861}
862 862
863#ifdef CONFIG_MEMORY_HOTREMOVE
864void arch_remove_memory(int nid, u64 start, u64 size, 863void arch_remove_memory(int nid, u64 start, u64 size,
865 struct vmem_altmap *altmap) 864 struct vmem_altmap *altmap)
866{ 865{
@@ -872,7 +871,6 @@ void arch_remove_memory(int nid, u64 start, u64 size,
872 __remove_pages(zone, start_pfn, nr_pages, altmap); 871 __remove_pages(zone, start_pfn, nr_pages, altmap);
873} 872}
874#endif 873#endif
875#endif
876 874
877int kernel_set_to_readonly __read_mostly; 875int kernel_set_to_readonly __read_mostly;
878 876
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 08bbf648827b..5a289a2ab108 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1198,7 +1198,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
1198 remove_pagetable(start, end, false, altmap); 1198 remove_pagetable(start, end, false, altmap);
1199} 1199}
1200 1200
1201#ifdef CONFIG_MEMORY_HOTREMOVE
1202static void __meminit 1201static void __meminit
1203kernel_physical_mapping_remove(unsigned long start, unsigned long end) 1202kernel_physical_mapping_remove(unsigned long start, unsigned long end)
1204{ 1203{
@@ -1219,7 +1218,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
1219 __remove_pages(zone, start_pfn, nr_pages, altmap); 1218 __remove_pages(zone, start_pfn, nr_pages, altmap);
1220 kernel_physical_mapping_remove(start, start + size); 1219 kernel_physical_mapping_remove(start, start + size);
1221} 1220}
1222#endif
1223#endif /* CONFIG_MEMORY_HOTPLUG */ 1221#endif /* CONFIG_MEMORY_HOTPLUG */
1224 1222
1225static struct kcore_list kcore_vsyscall; 1223static struct kcore_list kcore_vsyscall;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index e0aa7f9abb36..92459d6f12be 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -723,7 +723,6 @@ out:
723 return ret; 723 return ret;
724} 724}
725 725
726#ifdef CONFIG_MEMORY_HOTREMOVE
727static void 726static void
728unregister_memory(struct memory_block *memory) 727unregister_memory(struct memory_block *memory)
729{ 728{
@@ -762,7 +761,6 @@ void unregister_memory_section(struct mem_section *section)
762out_unlock: 761out_unlock:
763 mutex_unlock(&mem_sysfs_mutex); 762 mutex_unlock(&mem_sysfs_mutex);
764} 763}
765#endif /* CONFIG_MEMORY_HOTREMOVE */
766 764
767/* return true if the memory block is offlined, otherwise, return false */ 765/* return true if the memory block is offlined, otherwise, return false */
768bool is_memblock_offlined(struct memory_block *mem) 766bool is_memblock_offlined(struct memory_block *mem)
diff --git a/include/linux/memory.h b/include/linux/memory.h
index e1dc1bb2b787..474c7c60c8f2 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -112,9 +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 hotplug_memory_register(int nid, struct mem_section *section); 114int hotplug_memory_register(int nid, struct mem_section *section);
115#ifdef CONFIG_MEMORY_HOTREMOVE
116extern void unregister_memory_section(struct mem_section *); 115extern void unregister_memory_section(struct mem_section *);
117#endif
118extern int memory_dev_init(void); 116extern int memory_dev_init(void);
119extern int memory_notify(unsigned long val, void *v); 117extern int memory_notify(unsigned long val, void *v);
120extern int memory_isolate_notify(unsigned long val, void *v); 118extern int memory_isolate_notify(unsigned long val, void *v);
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 988fde33cd7f..87bf9c4a889e 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -123,12 +123,10 @@ static inline bool movable_node_is_enabled(void)
123 return movable_node_enabled; 123 return movable_node_enabled;
124} 124}
125 125
126#ifdef CONFIG_MEMORY_HOTREMOVE
127extern void arch_remove_memory(int nid, u64 start, u64 size, 126extern void arch_remove_memory(int nid, u64 start, u64 size,
128 struct vmem_altmap *altmap); 127 struct vmem_altmap *altmap);
129extern void __remove_pages(struct zone *zone, unsigned long start_pfn, 128extern void __remove_pages(struct zone *zone, unsigned long start_pfn,
130 unsigned long nr_pages, struct vmem_altmap *altmap); 129 unsigned long nr_pages, struct vmem_altmap *altmap);
131#endif /* CONFIG_MEMORY_HOTREMOVE */
132 130
133/* 131/*
134 * Do we want sysfs memblock files created. This will allow userspace to online 132 * Do we want sysfs memblock files created. This will allow userspace to online
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index a8c25fd85ee3..bc11888d5d7e 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -318,7 +318,6 @@ out:
318 return err; 318 return err;
319} 319}
320 320
321#ifdef CONFIG_MEMORY_HOTREMOVE
322/* find the smallest valid pfn in the range [start_pfn, end_pfn) */ 321/* find the smallest valid pfn in the range [start_pfn, end_pfn) */
323static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, 322static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
324 unsigned long start_pfn, 323 unsigned long start_pfn,
@@ -580,7 +579,6 @@ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
580 579
581 set_zone_contiguous(zone); 580 set_zone_contiguous(zone);
582} 581}
583#endif /* CONFIG_MEMORY_HOTREMOVE */
584 582
585int set_online_page_callback(online_page_callback_t callback) 583int set_online_page_callback(online_page_callback_t callback)
586{ 584{
diff --git a/mm/sparse.c b/mm/sparse.c
index fd13166949b5..d1d5e05f5b8d 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -604,7 +604,6 @@ static void __kfree_section_memmap(struct page *memmap,
604 604
605 vmemmap_free(start, end, altmap); 605 vmemmap_free(start, end, altmap);
606} 606}
607#ifdef CONFIG_MEMORY_HOTREMOVE
608static void free_map_bootmem(struct page *memmap) 607static void free_map_bootmem(struct page *memmap)
609{ 608{
610 unsigned long start = (unsigned long)memmap; 609 unsigned long start = (unsigned long)memmap;
@@ -612,7 +611,6 @@ static void free_map_bootmem(struct page *memmap)
612 611
613 vmemmap_free(start, end, NULL); 612 vmemmap_free(start, end, NULL);
614} 613}
615#endif /* CONFIG_MEMORY_HOTREMOVE */
616#else 614#else
617static struct page *__kmalloc_section_memmap(void) 615static struct page *__kmalloc_section_memmap(void)
618{ 616{
@@ -651,7 +649,6 @@ static void __kfree_section_memmap(struct page *memmap,
651 get_order(sizeof(struct page) * PAGES_PER_SECTION)); 649 get_order(sizeof(struct page) * PAGES_PER_SECTION));
652} 650}
653 651
654#ifdef CONFIG_MEMORY_HOTREMOVE
655static void free_map_bootmem(struct page *memmap) 652static void free_map_bootmem(struct page *memmap)
656{ 653{
657 unsigned long maps_section_nr, removing_section_nr, i; 654 unsigned long maps_section_nr, removing_section_nr, i;
@@ -681,7 +678,6 @@ static void free_map_bootmem(struct page *memmap)
681 put_page_bootmem(page); 678 put_page_bootmem(page);
682 } 679 }
683} 680}
684#endif /* CONFIG_MEMORY_HOTREMOVE */
685#endif /* CONFIG_SPARSEMEM_VMEMMAP */ 681#endif /* CONFIG_SPARSEMEM_VMEMMAP */
686 682
687/** 683/**
@@ -746,7 +742,6 @@ out:
746 return ret; 742 return ret;
747} 743}
748 744
749#ifdef CONFIG_MEMORY_HOTREMOVE
750#ifdef CONFIG_MEMORY_FAILURE 745#ifdef CONFIG_MEMORY_FAILURE
751static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) 746static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
752{ 747{
@@ -823,5 +818,4 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms,
823 PAGES_PER_SECTION - map_offset); 818 PAGES_PER_SECTION - map_offset);
824 free_section_usemap(memmap, usemap, altmap); 819 free_section_usemap(memmap, usemap, altmap);
825} 820}
826#endif /* CONFIG_MEMORY_HOTREMOVE */
827#endif /* CONFIG_MEMORY_HOTPLUG */ 821#endif /* CONFIG_MEMORY_HOTPLUG */