* [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization
@ 2026-08-21 2:09 Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Meijing Zhao @ 2026-08-21 2:09 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
The memblock debugfs interface has two issues when reporting region
flags. MEMBLOCK_RSRV_HUGETLB has no corresponding name, and regions
with multiple flags only show the lowest set bit.
In addition, memblock_debug_show() walks the region arrays without
synchronizing against memory hotplug. If memory hotplug grows an array,
the debugfs reader may continue accessing the old array after it has
been freed.
Add the missing HugeTLB flag name, report every set bit including those
beyond flagname[], and hold the memory hotplug read lock while walking
the arrays.
With the series applied, a HugeTLB bootmem reservation is reported as:
RSV_KERN|RSV_HUGETLB
RESEND:
- Regenerate the series from the same clean base as v1. The previous v2
was inadvertently generated with an unrelated MEMBLOCK_NODUMP change
in the patch context, causing apply failures. No code changes.
Changes in v2:
- Report set bits beyond flagname[] as UNKNOWN instead of ignoring them.
- Add a separate patch to synchronize debugfs reads with memory hotplug.
v1: https://lore.kernel.org/linux-mm/20260819075422.2387980-1-zhaomeijing100@gmail.com/
Meijing Zhao (3):
mm: memblock: add missing HugeTLB flag name
mm: memblock: show all region flags in debugfs
mm: memblock: synchronize debugfs reads with memory hotplug
mm/memblock.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 RESEND 1/3] mm: memblock: add missing HugeTLB flag name
2026-08-21 2:09 [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
@ 2026-08-21 2:09 ` Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Meijing Zhao @ 2026-08-21 2:09 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
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 <zhaomeijing@lixiang.com>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs
2026-08-21 2:09 [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
@ 2026-08-21 2:09 ` Meijing Zhao
2026-08-24 15:15 ` Mike Rapoport
2026-08-21 2:09 ` [PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Meijing Zhao
2026-08-23 14:43 ` [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Mike Rapoport
3 siblings, 1 reply; 6+ messages in thread
From: Meijing Zhao @ 2026-08-21 2:09 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
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 <zhaomeijing@lixiang.com>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug
2026-08-21 2:09 [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
@ 2026-08-21 2:09 ` Meijing Zhao
2026-08-23 14:43 ` [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Mike Rapoport
3 siblings, 0 replies; 6+ messages in thread
From: Meijing Zhao @ 2026-08-21 2:09 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
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 <zhaomeijing@lixiang.com>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization
2026-08-21 2:09 [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
` (2 preceding siblings ...)
2026-08-21 2:09 ` [PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Meijing Zhao
@ 2026-08-23 14:43 ` Mike Rapoport
3 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-08-23 14:43 UTC (permalink / raw)
To: Meijing Zhao
Cc: Andrew Morton, linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
Hi,
On Fri, Aug 21, 2026 at 10:09:07AM +0800, Meijing Zhao wrote:
> From: Meijing Zhao <zhaomeijing@lixiang.com>
>
> The memblock debugfs interface has two issues when reporting region
> flags. MEMBLOCK_RSRV_HUGETLB has no corresponding name, and regions
> with multiple flags only show the lowest set bit.
>
> In addition, memblock_debug_show() walks the region arrays without
> synchronizing against memory hotplug. If memory hotplug grows an array,
> the debugfs reader may continue accessing the old array after it has
> been freed.
>
> Add the missing HugeTLB flag name, report every set bit including those
> beyond flagname[], and hold the memory hotplug read lock while walking
> the arrays.
>
> With the series applied, a HugeTLB bootmem reservation is reported as:
>
> RSV_KERN|RSV_HUGETLB
>
> RESEND:
> - Regenerate the series from the same clean base as v1. The previous v2
> was inadvertently generated with an unrelated MEMBLOCK_NODUMP change
> in the patch context, causing apply failures. No code changes.
I presume the changes were on top of linux-next and it's not clear how to
apply them before the end of the merge window.
Can you please resend the patches after v7.3-rc1 is out and base them on
that?
> Changes in v2:
> - Report set bits beyond flagname[] as UNKNOWN instead of ignoring them.
> - Add a separate patch to synchronize debugfs reads with memory hotplug.
>
> v1: https://lore.kernel.org/linux-mm/20260819075422.2387980-1-zhaomeijing100@gmail.com/
>
> Meijing Zhao (3):
> mm: memblock: add missing HugeTLB flag name
> mm: memblock: show all region flags in debugfs
> mm: memblock: synchronize debugfs reads with memory hotplug
>
> mm/memblock.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> --
> 2.25.1
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs
2026-08-21 2:09 ` [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
@ 2026-08-24 15:15 ` Mike Rapoport
0 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-08-24 15:15 UTC (permalink / raw)
To: Meijing Zhao
Cc: Andrew Morton, linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
On Fri, Aug 21, 2026 at 10:09:09AM +0800, Meijing Zhao wrote:
> From: Meijing Zhao <zhaomeijing@lixiang.com>
>
> 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 <zhaomeijing@lixiang.com>
> ---
> 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;
first and flags can be declared here.
> + 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");
Can we really have both j < count and !flagname[j]?
> + 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");
No need to change this
> }
> }
> return 0;
> --
> 2.25.1
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-24 15:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-21 2:09 [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
2026-08-21 2:09 ` [PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
2026-08-24 15:15 ` Mike Rapoport
2026-08-21 2:09 ` [PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Meijing Zhao
2026-08-23 14:43 ` [PATCH v2 RESEND 0/3] mm: memblock: fix debugfs flag reporting and synchronization Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox