Commit 5163b1ec authored by David Hildenbrand's avatar David Hildenbrand Committed by Greg Kroah-Hartman

mm/memory_hotplug: make __remove_pages() and arch_remove_memory() never fail

commit ac5c9426 upstream.

-- snip --

Minor conflict in arch/powerpc/mm/mem.c

-- snip --

All callers of arch_remove_memory() ignore errors.  And we should really
try to remove any errors from the memory removal path.  No more errors are
reported from __remove_pages().  BUG() in s390x code in case
arch_remove_memory() is triggered.  We may implement that properly later.
WARN in case powerpc code failed to remove the section mapping, which is
better than ignoring the error completely right now.

Link: http://lkml.kernel.org/r/20190409100148.24703-5-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.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: Martin Schwidefsky <schwidefsky@de.ibm.com>
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: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Oscar Salvador <osalvador@suse.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Arun KS <arunks@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Qian Cai <cai@lca.pw>
Cc: Mathieu Malaterre <malat@debian.org>
Cc: Andrew Banman <andrew.banman@hpe.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mike Travis <mike.travis@hpe.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 58ddf0b0
...@@ -662,20 +662,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -662,20 +662,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap)
{ {
unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT;
struct zone *zone; struct zone *zone;
int ret;
zone = page_zone(pfn_to_page(start_pfn)); zone = page_zone(pfn_to_page(start_pfn));
ret = __remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
if (ret)
pr_warn("%s: Problem encountered in __remove_pages() as"
" ret=%d\n", __func__, ret);
return ret;
} }
#endif #endif
#endif #endif
...@@ -140,7 +140,7 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm ...@@ -140,7 +140,7 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
int __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)
{ {
unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long start_pfn = start >> PAGE_SHIFT;
...@@ -156,14 +156,13 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size, ...@@ -156,14 +156,13 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size,
if (altmap) if (altmap)
page += vmem_altmap_offset(altmap); page += vmem_altmap_offset(altmap);
ret = __remove_pages(page_zone(page), start_pfn, nr_pages, altmap); __remove_pages(page_zone(page), start_pfn, nr_pages, altmap);
if (ret)
return ret;
/* Remove htab bolted mappings for this section of memory */ /* Remove htab bolted mappings for this section of memory */
start = (unsigned long)__va(start); start = (unsigned long)__va(start);
flush_inval_dcache_range(start, start + size); flush_inval_dcache_range(start, start + size);
ret = remove_section_mapping(start, start + size); ret = remove_section_mapping(start, start + size);
WARN_ON_ONCE(ret);
/* Ensure all vmalloc mappings are flushed in case they also /* Ensure all vmalloc mappings are flushed in case they also
* hit that section of memory * hit that section of memory
...@@ -171,8 +170,6 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size, ...@@ -171,8 +170,6 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size,
vm_unmap_aliases(); vm_unmap_aliases();
resize_hpt_for_hotplug(memblock_phys_mem_size()); resize_hpt_for_hotplug(memblock_phys_mem_size());
return ret;
} }
#endif #endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
......
...@@ -240,14 +240,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -240,14 +240,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap)
{ {
/* /*
* There is no hardware or firmware interface which could trigger a * There is no hardware or firmware interface which could trigger a
* hot memory remove on s390. So there is nothing that needs to be * hot memory remove on s390. So there is nothing that needs to be
* implemented. * implemented.
*/ */
return -EBUSY; BUG();
} }
#endif #endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
...@@ -444,20 +444,15 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); ...@@ -444,20 +444,15 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
#endif #endif
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap)
{ {
unsigned long start_pfn = PFN_DOWN(start); unsigned long start_pfn = PFN_DOWN(start);
unsigned long nr_pages = size >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT;
struct zone *zone; struct zone *zone;
int ret;
zone = page_zone(pfn_to_page(start_pfn)); zone = page_zone(pfn_to_page(start_pfn));
ret = __remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
if (unlikely(ret))
pr_warn("%s: Failed, __remove_pages() == %d\n", __func__,
ret);
return ret;
} }
#endif #endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
...@@ -861,14 +861,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, ...@@ -861,14 +861,15 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) void arch_remove_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap)
{ {
unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT;
struct zone *zone; struct zone *zone;
zone = page_zone(pfn_to_page(start_pfn)); zone = page_zone(pfn_to_page(start_pfn));
return __remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
} }
#endif #endif
#endif #endif
......
...@@ -1142,24 +1142,20 @@ kernel_physical_mapping_remove(unsigned long start, unsigned long end) ...@@ -1142,24 +1142,20 @@ kernel_physical_mapping_remove(unsigned long start, unsigned long end)
remove_pagetable(start, end, true, NULL); remove_pagetable(start, end, true, NULL);
} }
int __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)
{ {
unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT;
struct page *page = pfn_to_page(start_pfn); struct page *page = pfn_to_page(start_pfn);
struct zone *zone; struct zone *zone;
int ret;
/* With altmap the first mapped page is offset from @start */ /* With altmap the first mapped page is offset from @start */
if (altmap) if (altmap)
page += vmem_altmap_offset(altmap); page += vmem_altmap_offset(altmap);
zone = page_zone(page); zone = page_zone(page);
ret = __remove_pages(zone, start_pfn, nr_pages, altmap); __remove_pages(zone, start_pfn, nr_pages, altmap);
WARN_ON_ONCE(ret);
kernel_physical_mapping_remove(start, start + size); kernel_physical_mapping_remove(start, start + size);
return ret;
} }
#endif #endif
#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* CONFIG_MEMORY_HOTPLUG */
......
...@@ -109,10 +109,10 @@ static inline bool movable_node_is_enabled(void) ...@@ -109,10 +109,10 @@ static inline bool movable_node_is_enabled(void)
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
extern int 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 int __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 */ #endif /* CONFIG_MEMORY_HOTREMOVE */
/* reasonably generic interface to expand the physical pages */ /* reasonably generic interface to expand the physical pages */
......
...@@ -509,8 +509,8 @@ static void __remove_section(struct zone *zone, struct mem_section *ms, ...@@ -509,8 +509,8 @@ static void __remove_section(struct zone *zone, struct mem_section *ms,
* sure that pages are marked reserved and zones are adjust properly by * sure that pages are marked reserved and zones are adjust properly by
* calling offline_pages(). * calling offline_pages().
*/ */
int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, void __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
unsigned long nr_pages, struct vmem_altmap *altmap) unsigned long nr_pages, struct vmem_altmap *altmap)
{ {
unsigned long i; unsigned long i;
unsigned long map_offset = 0; unsigned long map_offset = 0;
...@@ -541,7 +541,6 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, ...@@ -541,7 +541,6 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
} }
set_zone_contiguous(zone); set_zone_contiguous(zone);
return 0;
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_MEMORY_HOTREMOVE */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment