提交 34b64663 编写于 作者: D David Hildenbrand 提交者: Yang Yingliang

mm/memory_hotplug: allow arch_remove_memory() without CONFIG_MEMORY_HOTREMOVE

stable inclusion
from linux-4.19.100
commit 000a1d59cfe9d6e875462ed72de32770322c282b

--------------------------------

commit 80ec922d upstream.

-- snip --

Missing arm64 memory hot(un)plug support.

-- snip --

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.comSigned-off-by: NDavid Hildenbrand <david@redhat.com>
Reviewed-by: NPavel 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: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NDavid Hildenbrand <david@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
[yyl: remove CONFIG_MEMORY_HOTREMOVE in arch/arm64/mm/mmu.c]
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 283884fd
...@@ -1051,7 +1051,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -1051,7 +1051,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT,
altmap, want_memblock); altmap, want_memblock);
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
void arch_remove_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -1070,4 +1069,3 @@ void arch_remove_memory(int nid, u64 start, u64 size, ...@@ -1070,4 +1069,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
} }
#endif #endif
#endif
...@@ -661,7 +661,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -661,7 +661,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
return ret; return ret;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
void arch_remove_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -673,4 +672,3 @@ void arch_remove_memory(int nid, u64 start, u64 size, ...@@ -673,4 +672,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
} }
#endif #endif
#endif
...@@ -139,7 +139,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm ...@@ -139,7 +139,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm
return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
void __ref arch_remove_memory(int nid, u64 start, u64 size, void __ref arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -172,7 +171,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size, ...@@ -172,7 +171,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
resize_hpt_for_hotplug(memblock_phys_mem_size()); resize_hpt_for_hotplug(memblock_phys_mem_size());
} }
#endif #endif
#endif /* CONFIG_MEMORY_HOTPLUG */
/* /*
* walk_memory_resource() needs to make sure there is no holes in a given * walk_memory_resource() needs to make sure there is no holes in a given
......
...@@ -242,7 +242,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -242,7 +242,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
return rc; return rc;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
void arch_remove_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -254,5 +253,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, ...@@ -254,5 +253,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
vmem_remove_mapping(start, size); vmem_remove_mapping(start, size);
} }
#endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
...@@ -443,7 +443,6 @@ int memory_add_physaddr_to_nid(u64 addr) ...@@ -443,7 +443,6 @@ int memory_add_physaddr_to_nid(u64 addr)
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
#endif #endif
#ifdef CONFIG_MEMORY_HOTREMOVE
void arch_remove_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -454,5 +453,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, ...@@ -454,5 +453,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
zone = page_zone(pfn_to_page(start_pfn)); zone = page_zone(pfn_to_page(start_pfn));
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
} }
#endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
...@@ -860,7 +860,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -860,7 +860,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock); return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
void arch_remove_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap) struct vmem_altmap *altmap)
{ {
...@@ -872,7 +871,6 @@ void arch_remove_memory(int nid, u64 start, u64 size, ...@@ -872,7 +871,6 @@ void arch_remove_memory(int nid, u64 start, u64 size,
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
} }
#endif #endif
#endif
int kernel_set_to_readonly __read_mostly; int kernel_set_to_readonly __read_mostly;
......
...@@ -1132,7 +1132,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end, ...@@ -1132,7 +1132,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
remove_pagetable(start, end, false, altmap); remove_pagetable(start, end, false, altmap);
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
static void __meminit static void __meminit
kernel_physical_mapping_remove(unsigned long start, unsigned long end) kernel_physical_mapping_remove(unsigned long start, unsigned long end)
{ {
...@@ -1157,7 +1156,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size, ...@@ -1157,7 +1156,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
__remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
kernel_physical_mapping_remove(start, start + size); kernel_physical_mapping_remove(start, start + size);
} }
#endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
static struct kcore_list kcore_vsyscall; static struct kcore_list kcore_vsyscall;
......
...@@ -737,7 +737,6 @@ int hotplug_memory_register(int nid, struct mem_section *section) ...@@ -737,7 +737,6 @@ int hotplug_memory_register(int nid, struct mem_section *section)
return ret; return ret;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
static void static void
unregister_memory(struct memory_block *memory) unregister_memory(struct memory_block *memory)
{ {
...@@ -776,7 +775,6 @@ void unregister_memory_section(struct mem_section *section) ...@@ -776,7 +775,6 @@ void unregister_memory_section(struct mem_section *section)
out_unlock: out_unlock:
mutex_unlock(&mem_sysfs_mutex); mutex_unlock(&mem_sysfs_mutex);
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */
/* return true if the memory block is offlined, otherwise, return false */ /* return true if the memory block is offlined, otherwise, return false */
bool is_memblock_offlined(struct memory_block *mem) bool is_memblock_offlined(struct memory_block *mem)
......
...@@ -112,9 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb); ...@@ -112,9 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb);
extern int register_memory_isolate_notifier(struct notifier_block *nb); extern int register_memory_isolate_notifier(struct notifier_block *nb);
extern void unregister_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb);
int hotplug_memory_register(int nid, struct mem_section *section); int hotplug_memory_register(int nid, struct mem_section *section);
#ifdef CONFIG_MEMORY_HOTREMOVE
extern void unregister_memory_section(struct mem_section *); extern void unregister_memory_section(struct mem_section *);
#endif
extern int memory_dev_init(void); extern int memory_dev_init(void);
extern int memory_notify(unsigned long val, void *v); extern int memory_notify(unsigned long val, void *v);
extern int memory_isolate_notify(unsigned long val, void *v); extern int memory_isolate_notify(unsigned long val, void *v);
......
...@@ -108,12 +108,10 @@ static inline bool movable_node_is_enabled(void) ...@@ -108,12 +108,10 @@ static inline bool movable_node_is_enabled(void)
return movable_node_enabled; return movable_node_enabled;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
extern void arch_remove_memory(int nid, u64 start, u64 size, extern void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap); struct vmem_altmap *altmap);
extern void __remove_pages(struct zone *zone, unsigned long start_pfn, extern void __remove_pages(struct zone *zone, unsigned long start_pfn,
unsigned long nr_pages, struct vmem_altmap *altmap); unsigned long nr_pages, struct vmem_altmap *altmap);
#endif /* CONFIG_MEMORY_HOTREMOVE */
/* reasonably generic interface to expand the physical pages */ /* reasonably generic interface to expand the physical pages */
extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
......
...@@ -315,7 +315,6 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, ...@@ -315,7 +315,6 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,
return err; return err;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
/* find the smallest valid pfn in the range [start_pfn, end_pfn) */ /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn, unsigned long start_pfn,
...@@ -542,7 +541,6 @@ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn, ...@@ -542,7 +541,6 @@ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
set_zone_contiguous(zone); set_zone_contiguous(zone);
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */
int set_online_page_callback(online_page_callback_t callback) int set_online_page_callback(online_page_callback_t callback)
{ {
......
...@@ -586,7 +586,6 @@ static void __kfree_section_memmap(struct page *memmap, ...@@ -586,7 +586,6 @@ static void __kfree_section_memmap(struct page *memmap,
vmemmap_free(start, end, altmap); vmemmap_free(start, end, altmap);
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
static void free_map_bootmem(struct page *memmap) static void free_map_bootmem(struct page *memmap)
{ {
unsigned long start = (unsigned long)memmap; unsigned long start = (unsigned long)memmap;
...@@ -594,7 +593,6 @@ static void free_map_bootmem(struct page *memmap) ...@@ -594,7 +593,6 @@ static void free_map_bootmem(struct page *memmap)
vmemmap_free(start, end, NULL); vmemmap_free(start, end, NULL);
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */
#else #else
static struct page *__kmalloc_section_memmap(void) static struct page *__kmalloc_section_memmap(void)
{ {
...@@ -633,7 +631,6 @@ static void __kfree_section_memmap(struct page *memmap, ...@@ -633,7 +631,6 @@ static void __kfree_section_memmap(struct page *memmap,
get_order(sizeof(struct page) * PAGES_PER_SECTION)); get_order(sizeof(struct page) * PAGES_PER_SECTION));
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
static void free_map_bootmem(struct page *memmap) static void free_map_bootmem(struct page *memmap)
{ {
unsigned long maps_section_nr, removing_section_nr, i; unsigned long maps_section_nr, removing_section_nr, i;
...@@ -663,7 +660,6 @@ static void free_map_bootmem(struct page *memmap) ...@@ -663,7 +660,6 @@ static void free_map_bootmem(struct page *memmap)
put_page_bootmem(page); put_page_bootmem(page);
} }
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */
#endif /* CONFIG_SPARSEMEM_VMEMMAP */ #endif /* CONFIG_SPARSEMEM_VMEMMAP */
/* /*
...@@ -722,7 +718,6 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, ...@@ -722,7 +718,6 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn,
return ret; return ret;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE
#ifdef CONFIG_MEMORY_FAILURE #ifdef CONFIG_MEMORY_FAILURE
static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
{ {
...@@ -790,5 +785,4 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, ...@@ -790,5 +785,4 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms,
PAGES_PER_SECTION - map_offset); PAGES_PER_SECTION - map_offset);
free_section_usemap(memmap, usemap, altmap); free_section_usemap(memmap, usemap, altmap);
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册