summaryrefslogtreecommitdiffstatshomepage
path: root/mm
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2019-07-18 14:56:56 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 16:08:06 -0800
commitdb051a0dac13db24d58470d75cee0ce7c6b031a1 (patch)
treef245d7b2b4334de84555f6533e6af1e732aa152d /mm
parent80ec922dbd87fd38d15719c86a94457204648aeb (diff)
downloadlinux-stable-db051a0dac13db24d58470d75cee0ce7c6b031a1.tar.gz
linux-stable-db051a0dac13db24d58470d75cee0ce7c6b031a1.tar.bz2
linux-stable-db051a0dac13db24d58470d75cee0ce7c6b031a1.tar.xz
linux-stable-db051a0dac13db24d58470d75cee0ce7c6b031a1.zip
mm/memory_hotplug: create memory block devices after arch_add_memory()
Only memory to be added to the buddy and to be onlined/offlined by user space using /sys/devices/system/memory/... needs (and should have!) memory block devices. Factor out creation of memory block devices. Create all devices after arch_add_memory() succeeded. We can later drop the want_memblock parameter, because it is now effectively stale. Only after memory block devices have been added, memory can be onlined by user space. This implies, that memory is not visible to user space at all before arch_add_memory() succeeded. While at it - use WARN_ON_ONCE instead of BUG_ON in moved unregister_memory() - introduce find_memory_block_by_id() to search via block id - Use find_memory_block_by_id() in init_memory_block() to catch duplicates Link: http://lkml.kernel.org/r/20190527111152.16324-8-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Pavel Tatashin <pasha.tatashin@soleen.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: Ingo Molnar <mingo@kernel.org> Cc: Andrew Banman <andrew.banman@hpe.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Qian Cai <cai@lca.pw> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Arun KS <arunks@codeaurora.org> Cc: Mathieu Malaterre <malat@debian.org> Cc: Alex Deucher <alexander.deucher@amd.com> 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: Chris Wilson <chris@chris-wilson.co.uk> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.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 Brown <broonie@kernel.org> 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: Peter Zijlstra <peterz@infradead.org> 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: 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>
Diffstat (limited to 'mm')
-rw-r--r--mm/memory_hotplug.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index bc11888d5d7e..78291526eb4d 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -259,13 +259,7 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn,
259 return -EEXIST; 259 return -EEXIST;
260 260
261 ret = sparse_add_one_section(nid, phys_start_pfn, altmap); 261 ret = sparse_add_one_section(nid, phys_start_pfn, altmap);
262 if (ret < 0) 262 return ret < 0 ? ret : 0;
263 return ret;
264
265 if (!want_memblock)
266 return 0;
267
268 return hotplug_memory_register(nid, __pfn_to_section(phys_start_pfn));
269} 263}
270 264
271/* 265/*
@@ -1105,6 +1099,13 @@ int __ref add_memory_resource(int nid, struct resource *res)
1105 if (ret < 0) 1099 if (ret < 0)
1106 goto error; 1100 goto error;
1107 1101
1102 /* create memory block devices after memory was added */
1103 ret = create_memory_block_devices(start, size);
1104 if (ret) {
1105 arch_remove_memory(nid, start, size, NULL);
1106 goto error;
1107 }
1108
1108 if (new_node) { 1109 if (new_node) {
1109 /* If sysfs file of new node can't be created, cpu on the node 1110 /* If sysfs file of new node can't be created, cpu on the node
1110 * can't be hot-added. There is no rollback way now. 1111 * can't be hot-added. There is no rollback way now.