From: Meijing Zhao Commit 7d163a75f821 ("memblock: make HugeTLB bootmem allocation work with KHO") added MEMBLOCK_RSRV_HUGETLB but did not add the corresponding entry to flagname[]. As a result, memblock debugfs cannot report the flag by name. Add the missing RSV_HUGETLB entry. Fixes: 7d163a75f821 ("memblock: make HugeTLB bootmem allocation work with KHO") Signed-off-by: Meijing Zhao --- mm/memblock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memblock.c b/mm/memblock.c index 9ce86349a29f..f2952d725c10 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2886,6 +2886,7 @@ static const char * const flagname[] = { [ilog2(MEMBLOCK_RSRV_NOINIT)] = "RSV_NIT", [ilog2(MEMBLOCK_RSRV_KERN)] = "RSV_KERN", [ilog2(MEMBLOCK_KHO_SCRATCH)] = "KHO_SCRATCH", + [ilog2(MEMBLOCK_RSRV_HUGETLB)] = "RSV_HUGETLB", }; static int memblock_debug_show(struct seq_file *m, void *private) -- 2.25.1 From: Meijing Zhao Commit 493f349e38d0 ("memblock: Add flags and nid info in memblock debugfs") made memblock_debug_show() stop after finding the first set flag. A memblock region can carry multiple flags, so the remaining flags are hidden from debugfs. In particular, memory allocated for HugeTLB pages is reserved with both MEMBLOCK_RSRV_KERN and MEMBLOCK_RSRV_HUGETLB, but debugfs only reports RSV_KERN. Walk all bits in the region flags and print every set flag separated by "|". Keep walking beyond flagname[] so that a set flag without a known name is reported as UNKNOWN rather than silently ignored. A HugeTLB reservation is now shown as: RSV_KERN|RSV_HUGETLB instead of: RSV_KERN Fixes: 493f349e38d0 ("memblock: Add flags and nid info in memblock debugfs") Signed-off-by: Meijing Zhao --- mm/memblock.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index f2952d725c10..36a8d2a9378d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2895,7 +2895,9 @@ static int memblock_debug_show(struct seq_file *m, void *private) struct memblock_region *reg; int i, j, nid; unsigned int count = ARRAY_SIZE(flagname); + unsigned int flags; phys_addr_t end; + bool first; for (i = 0; i < type->cnt; i++) { reg = &type->regions[i]; @@ -2909,16 +2911,20 @@ static int memblock_debug_show(struct seq_file *m, void *private) else seq_printf(m, "%4c ", 'x'); if (reg->flags) { - for (j = 0; j < count; j++) { - if (reg->flags & (1U << j)) { - seq_printf(m, "%s\n", flagname[j]); - break; - } + flags = reg->flags; + first = true; + for (j = 0; flags; j++, flags >>= 1) { + if (!(flags & 1)) + continue; + if (!first) + seq_putc(m, '|'); + seq_puts(m, j < count && flagname[j] ? + flagname[j] : "UNKNOWN"); + first = false; } - if (j == count) - seq_printf(m, "%s\n", "UNKNOWN"); + seq_putc(m, '\n'); } else { - seq_printf(m, "%s\n", "NONE"); + seq_puts(m, "NONE\n"); } } return 0; -- 2.25.1 From: Meijing Zhao 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 --- 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 #include #include +#include #include #include #include @@ -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