[PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug
Meijing Zhao <[email protected]>
| Newsgroups | org.kvack.linux-mm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Meijing Zhao <[email protected]> memblock_debug_show() walks a memblock region array without synchronization. With CONFIG_ARCH_KEEP_MEMBLOCK, memory hotplug can concurrently add a region. If the array has to grow, memblock_double_array() replaces type->regions and frees the old allocation while the debugfs reader may still be using it. Hold mem_hotplug_lock in read mode while producing the debugfs output. Memory hotplug updates already hold the write side of this lock, so the region array remains stable throughout the walk. The helpers are no-ops when CONFIG_MEMORY_HOTPLUG is disabled. Fixes: f9126ab9241f ("memory-hotplug: fix wrong edge when hot add a new node") Signed-off-by: Meijing Zhao <[email protected]> --- mm/memblock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memblock.c b/mm/memblock.c index 36a8d2a9378d..f1ddbcce47ac 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -14,6 +14,7 @@ #include <linux/pfn.h> #include <linux/debugfs.h> #include <linux/kmemleak.h> +#include <linux/memory_hotplug.h> #include <linux/seq_file.h> #include <linux/memblock.h> #include <linux/mutex.h> @@ -2899,6 +2900,7 @@ static int memblock_debug_show(struct seq_file *m, void *private) phys_addr_t end; bool first; + get_online_mems(); for (i = 0; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size - 1; @@ -2927,6 +2929,7 @@ static int memblock_debug_show(struct seq_file *m, void *private) seq_puts(m, "NONE\n"); } } + put_online_mems(); return 0; } DEFINE_SHOW_ATTRIBUTE(memblock_debug); -- 2.25.1