public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt
@ 2026-03-18 18:56 Guilherme G. Piccoli
  2026-03-18 18:56 ` [PATCH v3 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-18 18:56 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-dev, kernel, Guilherme G. Piccoli,
	Andrew Morton, Mike Rapoport, Steven Rostedt, SeongJae Park

Hi folks, this the 3rd iteration of this patchset.

tl; dr: we are adding here error messages in case of failures when
reserve_mem parameter is used, and also a debugfs file to show
successful reservations, with name and size as passed in the cmdline.

More details and history, please take a look at:

V2: lore.kernel.org/r/20260304203300.1414286-2-gpiccoli@igalia.com/
V1: lore.kernel.org/r/20260217195816.861684-1-gpiccoli@igalia.com/

Special thanks to Mike and SJ for the reviews =)
Thanks in advance for suggestions / reviews.
Cheers,

Guilherme G. Piccoli (2):
  mm/memblock: Print out errors on reserve_mem parser
  mm/memblock: Add reserve_mem debugfs info

 mm/memblock.c                                 | 83 +++++++++++++++----
 tools/testing/memblock/linux/string_helpers.h | 10 +++
 2 files changed, 76 insertions(+), 17 deletions(-)
 create mode 100644 tools/testing/memblock/linux/string_helpers.h

-- 
2.50.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 1/2] mm/memblock: Print out errors on reserve_mem parser
  2026-03-18 18:56 [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Guilherme G. Piccoli
@ 2026-03-18 18:56 ` Guilherme G. Piccoli
  2026-03-18 18:56 ` [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-18 18:56 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-dev, kernel, Guilherme G. Piccoli,
	Andrew Morton, Mike Rapoport, Steven Rostedt, SeongJae Park

The parsing of kernel parameter "reserve_mem=" is subject to
multiple failures, like duplicate naming, malformed expression
or even lack of available memory. Right now, all of these fail
silently. Let's add some messages so the kernel log can provide
useful information in case of failures.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>

---

V3:
- Removed unnecessary blank line (thanks SJ!).


 mm/memblock.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index b3ddfdec7a80..ac08d7f8c15e 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2642,23 +2642,25 @@ static int __init reserve_mem(char *p)
 	int len;
 
 	if (!p)
-		return -EINVAL;
+		goto err_param;
 
 	/* Check if there's room for more reserved memory */
-	if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES)
+	if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES) {
+		pr_err("reserve_mem: no more room for reserved memory\n");
 		return -EBUSY;
+	}
 
 	oldp = p;
 	size = memparse(p, &p);
 	if (!size || p == oldp)
-		return -EINVAL;
+		goto err_param;
 
 	if (*p != ':')
-		return -EINVAL;
+		goto err_param;
 
 	align = memparse(p+1, &p);
 	if (*p != ':')
-		return -EINVAL;
+		goto err_param;
 
 	/*
 	 * memblock_phys_alloc() doesn't like a zero size align,
@@ -2672,7 +2674,7 @@ static int __init reserve_mem(char *p)
 
 	/* name needs to have length but not too big */
 	if (!len || len >= RESERVE_MEM_NAME_SIZE)
-		return -EINVAL;
+		goto err_param;
 
 	/* Make sure that name has text */
 	for (p = name; *p; p++) {
@@ -2680,11 +2682,13 @@ static int __init reserve_mem(char *p)
 			break;
 	}
 	if (!*p)
-		return -EINVAL;
+		goto err_param;
 
 	/* Make sure the name is not already used */
-	if (reserve_mem_find_by_name(name, &start, &tmp))
+	if (reserve_mem_find_by_name(name, &start, &tmp)) {
+		pr_err("reserve_mem: name \"%s\" was already used\n", name);
 		return -EBUSY;
+	}
 
 	/* Pick previous allocations up from KHO if available */
 	if (reserve_mem_kho_revive(name, size, align))
@@ -2692,12 +2696,17 @@ static int __init reserve_mem(char *p)
 
 	/* TODO: Allocation must be outside of scratch region */
 	start = memblock_phys_alloc(size, align);
-	if (!start)
+	if (!start) {
+		pr_err("reserve_mem: memblock allocation failed\n");
 		return -ENOMEM;
+	}
 
 	reserved_mem_add(start, size, name);
 
 	return 1;
+err_param:
+	pr_err("reserve_mem: empty or malformed parameter\n");
+	return -EINVAL;
 }
 __setup("reserve_mem=", reserve_mem);
 
-- 
2.50.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-18 18:56 [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Guilherme G. Piccoli
  2026-03-18 18:56 ` [PATCH v3 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
@ 2026-03-18 18:56 ` Guilherme G. Piccoli
  2026-03-19 16:34   ` Mike Rapoport
  2026-03-24  1:22 ` [PATCH v4 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
  2026-03-24 15:17 ` [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Mike Rapoport
  3 siblings, 1 reply; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-18 18:56 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-dev, kernel, Guilherme G. Piccoli,
	Andrew Morton, Mike Rapoport, Steven Rostedt, SeongJae Park

When using the "reserve_mem" parameter, users aim at having an
area that (hopefully) persists across boots, so pstore infrastructure
(like ramoops module) can make use of that to save oops/ftrace logs,
for example.

There is no easy way to determine if this kernel parameter is properly
set though; the kernel doesn't show information about this memory in
memblock debugfs, neither in /proc/iomem nor dmesg. This is a relevant
information for tools like kdumpst[0], to determine if it's reliable
to use the reserved area as ramoops persistent storage; checking only
/proc/cmdline is not sufficient as it doesn't tell if the reservation
effectively succeeded or not.

Add here a new file under memblock debugfs showing properly set memory
reservations, with name and size as passed to "reserve_mem". Notice that
if no "reserve_mem=" is passed on command-line or if the reservation
attempts fail, the file is not created.

[0] https://aur.archlinux.org/packages/kdumpst

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: SeongJae Park <sj@kernel.org>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>

---

V3:
- Added header stub to avoid build failure (thanks Mike!).

- Refactored the debugfs creation routine to avoid too many
ifdefs, also changing (!(a || b)) to (!a && !b) in the function
(thanks SJ and Mike for the suggestions in this one!).

Notice that I've inverted the order of file creation, putting
physmem (and its ifdef) *before* - the reason for that is purely
because in my view, the code looks better this way, the ifdefs
are a bit more far from each other. I'm totally OK in changing
it, up yo you folks.

Cheers!


 mm/memblock.c                                 | 56 ++++++++++++++++---
 tools/testing/memblock/linux/string_helpers.h | 10 ++++
 2 files changed, 58 insertions(+), 8 deletions(-)
 create mode 100644 tools/testing/memblock/linux/string_helpers.h

diff --git a/mm/memblock.c b/mm/memblock.c
index ac08d7f8c15e..f4219f434ce5 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -17,6 +17,7 @@
 #include <linux/seq_file.h>
 #include <linux/memblock.h>
 #include <linux/mutex.h>
+#include <linux/string_helpers.h>
 
 #ifdef CONFIG_KEXEC_HANDOVER
 #include <linux/libfdt.h>
@@ -2710,7 +2711,8 @@ static int __init reserve_mem(char *p)
 }
 __setup("reserve_mem=", reserve_mem);
 
-#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK)
+#ifdef CONFIG_DEBUG_FS
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
 static const char * const flagname[] = {
 	[ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG",
 	[ilog2(MEMBLOCK_MIRROR)] = "MIRROR",
@@ -2757,19 +2759,57 @@ static int memblock_debug_show(struct seq_file *m, void *private)
 }
 DEFINE_SHOW_ATTRIBUTE(memblock_debug);
 
-static int __init memblock_init_debugfs(void)
+static inline void memblock_debugfs_make_dirs(struct dentry *root)
 {
-	struct dentry *root = debugfs_create_dir("memblock", NULL);
-
-	debugfs_create_file("memory", 0444, root,
-			    &memblock.memory, &memblock_debug_fops);
-	debugfs_create_file("reserved", 0444, root,
-			    &memblock.reserved, &memblock_debug_fops);
 #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
 	debugfs_create_file("physmem", 0444, root, &physmem,
 			    &memblock_debug_fops);
 #endif
+	debugfs_create_file("memory", 0444, root,
+			    &memblock.memory, &memblock_debug_fops);
+	debugfs_create_file("reserved", 0444, root,
+			    &memblock.reserved, &memblock_debug_fops);
+}
 
+#else
+
+static inline void memblock_debugfs_make_dirs(struct dentry *root) { }
+
+#endif /* CONFIG_ARCH_KEEP_MEMBLOCK */
+
+static int memblock_reserve_mem_show(struct seq_file *m, void *private)
+{
+	struct reserve_mem_table *map;
+	char txtsz[16];
+
+	for (int i = 0; i < reserved_mem_count; i++) {
+		map = &reserved_mem_table[i];
+		if (!map->size)
+			continue;
+
+		memset(txtsz, 0, sizeof(txtsz));
+		string_get_size(map->size, 1, STRING_UNITS_2, txtsz, sizeof(txtsz));
+		seq_printf(m, "%s\t\t(%s)\n", map->name, txtsz);
+	}
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(memblock_reserve_mem);
+
+static int __init memblock_init_debugfs(void)
+{
+	struct dentry *root;
+
+	if (!IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK) && !reserved_mem_count)
+		return 0;
+
+	root = debugfs_create_dir("memblock", NULL);
+
+	if (reserved_mem_count)
+		debugfs_create_file("reserve_mem_param", 0444, root, NULL,
+				    &memblock_reserve_mem_fops);
+
+	memblock_debugfs_make_dirs(root);
 	return 0;
 }
 __initcall(memblock_init_debugfs);
diff --git a/tools/testing/memblock/linux/string_helpers.h b/tools/testing/memblock/linux/string_helpers.h
new file mode 100644
index 000000000000..dbf015cfff31
--- /dev/null
+++ b/tools/testing/memblock/linux/string_helpers.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_STRING_HELPERS_H_
+#define _LINUX_STRING_HELPERS_H_
+
+/*
+ * Header stub to avoid test build breakage; we don't need to
+ * actually implement string_get_size() as it's not used in the tests.
+ */
+
+#endif
-- 
2.50.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-18 18:56 ` [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
@ 2026-03-19 16:34   ` Mike Rapoport
  2026-03-19 17:14     ` Guilherme G. Piccoli
  0 siblings, 1 reply; 10+ messages in thread
From: Mike Rapoport @ 2026-03-19 16:34 UTC (permalink / raw)
  To: Guilherme G. Piccoli
  Cc: linux-mm, linux-kernel, kernel-dev, kernel, Andrew Morton,
	Steven Rostedt, SeongJae Park

On Wed, Mar 18, 2026 at 03:56:33PM -0300, Guilherme G. Piccoli wrote:
> When using the "reserve_mem" parameter, users aim at having an
> area that (hopefully) persists across boots, so pstore infrastructure
> (like ramoops module) can make use of that to save oops/ftrace logs,
> for example.
> 
> There is no easy way to determine if this kernel parameter is properly
> set though; the kernel doesn't show information about this memory in
> memblock debugfs, neither in /proc/iomem nor dmesg. This is a relevant
> information for tools like kdumpst[0], to determine if it's reliable
> to use the reserved area as ramoops persistent storage; checking only
> /proc/cmdline is not sufficient as it doesn't tell if the reservation
> effectively succeeded or not.
> 
> Add here a new file under memblock debugfs showing properly set memory
> reservations, with name and size as passed to "reserve_mem". Notice that
> if no "reserve_mem=" is passed on command-line or if the reservation
> attempts fail, the file is not created.

...

> -static int __init memblock_init_debugfs(void)
> +static inline void memblock_debugfs_make_dirs(struct dentry *root)

This does not make dirs but rather exposes files representing memblock
arrays.

How about calling this function 
memblock_debugfs_expose_arrays()?

>  {
> -	struct dentry *root = debugfs_create_dir("memblock", NULL);
> -
> -	debugfs_create_file("memory", 0444, root,
> -			    &memblock.memory, &memblock_debug_fops);
> -	debugfs_create_file("reserved", 0444, root,
> -			    &memblock.reserved, &memblock_debug_fops);
>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
>  	debugfs_create_file("physmem", 0444, root, &physmem,
>  			    &memblock_debug_fops);
>  #endif
> +	debugfs_create_file("memory", 0444, root,
> +			    &memblock.memory, &memblock_debug_fops);
> +	debugfs_create_file("reserved", 0444, root,
> +			    &memblock.reserved, &memblock_debug_fops);

No need to move these after PHYS_MAP attribute

> +}

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-19 16:34   ` Mike Rapoport
@ 2026-03-19 17:14     ` Guilherme G. Piccoli
  2026-03-19 18:01       ` Mike Rapoport
  0 siblings, 1 reply; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-19 17:14 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, linux-kernel, kernel-dev, kernel, Andrew Morton,
	Steven Rostedt, SeongJae Park

On 19/03/2026 13:34, Mike Rapoport wrote:
> [...]
>> -static int __init memblock_init_debugfs(void)
>> +static inline void memblock_debugfs_make_dirs(struct dentry *root)
> 
> This does not make dirs but rather exposes files representing memblock
> arrays.
> 
> How about calling this function 
> memblock_debugfs_expose_arrays()?
> 

I sincerely couldn't agree more - it should have have been a braino, why
on earth I called it this way?! Apologies, will respin soon...will wait
until weekend in case someone else has opinions.


>>  {
>> -	struct dentry *root = debugfs_create_dir("memblock", NULL);
>> -
>> -	debugfs_create_file("memory", 0444, root,
>> -			    &memblock.memory, &memblock_debug_fops);
>> -	debugfs_create_file("reserved", 0444, root,
>> -			    &memblock.reserved, &memblock_debug_fops);
>>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
>>  	debugfs_create_file("physmem", 0444, root, &physmem,
>>  			    &memblock_debug_fops);
>>  #endif
>> +	debugfs_create_file("memory", 0444, root,
>> +			    &memblock.memory, &memblock_debug_fops);
>> +	debugfs_create_file("reserved", 0444, root,
>> +			    &memblock.reserved, &memblock_debug_fops);
> 
> No need to move these after PHYS_MAP attribute
> 

OK, your call, will change it in the respin as well.
Thanks,


Guilherme


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-19 17:14     ` Guilherme G. Piccoli
@ 2026-03-19 18:01       ` Mike Rapoport
  0 siblings, 0 replies; 10+ messages in thread
From: Mike Rapoport @ 2026-03-19 18:01 UTC (permalink / raw)
  To: Guilherme G. Piccoli
  Cc: linux-mm, linux-kernel, kernel-dev, kernel, Andrew Morton,
	Steven Rostedt, SeongJae Park

On Thu, Mar 19, 2026 at 02:14:00PM -0300, Guilherme G. Piccoli wrote:
> On 19/03/2026 13:34, Mike Rapoport wrote:
> > [...]
> >>  {
> >> -	struct dentry *root = debugfs_create_dir("memblock", NULL);
> >> -
> >> -	debugfs_create_file("memory", 0444, root,
> >> -			    &memblock.memory, &memblock_debug_fops);
> >> -	debugfs_create_file("reserved", 0444, root,
> >> -			    &memblock.reserved, &memblock_debug_fops);
> >>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
> >>  	debugfs_create_file("physmem", 0444, root, &physmem,
> >>  			    &memblock_debug_fops);
> >>  #endif
> >> +	debugfs_create_file("memory", 0444, root,
> >> +			    &memblock.memory, &memblock_debug_fops);
> >> +	debugfs_create_file("reserved", 0444, root,
> >> +			    &memblock.reserved, &memblock_debug_fops);
> > 
> > No need to move these after PHYS_MAP attribute
> > 
> 
> OK, your call, will change it in the respin as well.
> Thanks,

That's actually more of a rule in the kernel: don't introduce unnecessary
changes :)
  
> Guilherme
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 1/2] mm/memblock: Print out errors on reserve_mem parser
  2026-03-18 18:56 [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Guilherme G. Piccoli
  2026-03-18 18:56 ` [PATCH v3 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
  2026-03-18 18:56 ` [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
@ 2026-03-24  1:22 ` Guilherme G. Piccoli
  2026-03-24  1:22   ` [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
  2026-03-24 15:17 ` [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Mike Rapoport
  3 siblings, 1 reply; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-24  1:22 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-dev, kernel, Guilherme G. Piccoli,
	Andrew Morton, Mike Rapoport, Steven Rostedt, SeongJae Park

The parsing of kernel parameter "reserve_mem=" is subject to
multiple failures, like duplicate naming, malformed expression
or even lack of available memory. Right now, all of these fail
silently. Let's add some messages so the kernel log can provide
useful information in case of failures.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---

V4: no changes.

V3 thread: https://lore.kernel.org/r/20260318190816.1811325-1-gpiccoli@igalia.com/


 mm/memblock.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index b3ddfdec7a80..ac08d7f8c15e 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2642,23 +2642,25 @@ static int __init reserve_mem(char *p)
 	int len;
 
 	if (!p)
-		return -EINVAL;
+		goto err_param;
 
 	/* Check if there's room for more reserved memory */
-	if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES)
+	if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES) {
+		pr_err("reserve_mem: no more room for reserved memory\n");
 		return -EBUSY;
+	}
 
 	oldp = p;
 	size = memparse(p, &p);
 	if (!size || p == oldp)
-		return -EINVAL;
+		goto err_param;
 
 	if (*p != ':')
-		return -EINVAL;
+		goto err_param;
 
 	align = memparse(p+1, &p);
 	if (*p != ':')
-		return -EINVAL;
+		goto err_param;
 
 	/*
 	 * memblock_phys_alloc() doesn't like a zero size align,
@@ -2672,7 +2674,7 @@ static int __init reserve_mem(char *p)
 
 	/* name needs to have length but not too big */
 	if (!len || len >= RESERVE_MEM_NAME_SIZE)
-		return -EINVAL;
+		goto err_param;
 
 	/* Make sure that name has text */
 	for (p = name; *p; p++) {
@@ -2680,11 +2682,13 @@ static int __init reserve_mem(char *p)
 			break;
 	}
 	if (!*p)
-		return -EINVAL;
+		goto err_param;
 
 	/* Make sure the name is not already used */
-	if (reserve_mem_find_by_name(name, &start, &tmp))
+	if (reserve_mem_find_by_name(name, &start, &tmp)) {
+		pr_err("reserve_mem: name \"%s\" was already used\n", name);
 		return -EBUSY;
+	}
 
 	/* Pick previous allocations up from KHO if available */
 	if (reserve_mem_kho_revive(name, size, align))
@@ -2692,12 +2696,17 @@ static int __init reserve_mem(char *p)
 
 	/* TODO: Allocation must be outside of scratch region */
 	start = memblock_phys_alloc(size, align);
-	if (!start)
+	if (!start) {
+		pr_err("reserve_mem: memblock allocation failed\n");
 		return -ENOMEM;
+	}
 
 	reserved_mem_add(start, size, name);
 
 	return 1;
+err_param:
+	pr_err("reserve_mem: empty or malformed parameter\n");
+	return -EINVAL;
 }
 __setup("reserve_mem=", reserve_mem);
 
-- 
2.50.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-24  1:22 ` [PATCH v4 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
@ 2026-03-24  1:22   ` Guilherme G. Piccoli
  2026-03-25  1:24     ` SeongJae Park
  0 siblings, 1 reply; 10+ messages in thread
From: Guilherme G. Piccoli @ 2026-03-24  1:22 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-dev, kernel, Guilherme G. Piccoli,
	Andrew Morton, Mike Rapoport, Steven Rostedt, SeongJae Park

When using the "reserve_mem" parameter, users aim at having an
area that (hopefully) persists across boots, so pstore infrastructure
(like ramoops module) can make use of that to save oops/ftrace logs,
for example.

There is no easy way to determine if this kernel parameter is properly
set though; the kernel doesn't show information about this memory in
memblock debugfs, neither in /proc/iomem nor dmesg. This is a relevant
information for tools like kdumpst[0], to determine if it's reliable
to use the reserved area as ramoops persistent storage; checking only
/proc/cmdline is not sufficient as it doesn't tell if the reservation
effectively succeeded or not.

Add here a new file under memblock debugfs showing properly set memory
reservations, with name and size as passed to "reserve_mem". Notice that
if no "reserve_mem=" is passed on command-line or if the reservation
attempts fail, the file is not created.

[0] https://aur.archlinux.org/packages/kdumpst

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: SeongJae Park <sj@kernel.org>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---

Hi folks, here is the V4 with the changes suggested.
Thanks for reviews and suggestions!

V4:
- s/memblock_debugfs_make_dirs/memblock_debugfs_expose_arrays/g
  (thanks Mike, apologies for my braino!)

- Didn't change the code order of `#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP`
  (Mike also - thanks)

V3 thread: https://lore.kernel.org/r/20260318190816.1811325-1-gpiccoli@igalia.com/


 mm/memblock.c                                 | 48 +++++++++++++++++--
 tools/testing/memblock/linux/string_helpers.h | 10 ++++
 2 files changed, 54 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/memblock/linux/string_helpers.h

diff --git a/mm/memblock.c b/mm/memblock.c
index ac08d7f8c15e..ef9c0bf59338 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -17,6 +17,7 @@
 #include <linux/seq_file.h>
 #include <linux/memblock.h>
 #include <linux/mutex.h>
+#include <linux/string_helpers.h>
 
 #ifdef CONFIG_KEXEC_HANDOVER
 #include <linux/libfdt.h>
@@ -2710,7 +2711,8 @@ static int __init reserve_mem(char *p)
 }
 __setup("reserve_mem=", reserve_mem);
 
-#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK)
+#ifdef CONFIG_DEBUG_FS
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
 static const char * const flagname[] = {
 	[ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG",
 	[ilog2(MEMBLOCK_MIRROR)] = "MIRROR",
@@ -2757,10 +2759,8 @@ static int memblock_debug_show(struct seq_file *m, void *private)
 }
 DEFINE_SHOW_ATTRIBUTE(memblock_debug);
 
-static int __init memblock_init_debugfs(void)
+static inline void memblock_debugfs_expose_arrays(struct dentry *root)
 {
-	struct dentry *root = debugfs_create_dir("memblock", NULL);
-
 	debugfs_create_file("memory", 0444, root,
 			    &memblock.memory, &memblock_debug_fops);
 	debugfs_create_file("reserved", 0444, root,
@@ -2769,7 +2769,47 @@ static int __init memblock_init_debugfs(void)
 	debugfs_create_file("physmem", 0444, root, &physmem,
 			    &memblock_debug_fops);
 #endif
+}
 
+#else
+
+static inline void memblock_debugfs_expose_arrays(struct dentry *root) { }
+
+#endif /* CONFIG_ARCH_KEEP_MEMBLOCK */
+
+static int memblock_reserve_mem_show(struct seq_file *m, void *private)
+{
+	struct reserve_mem_table *map;
+	char txtsz[16];
+
+	for (int i = 0; i < reserved_mem_count; i++) {
+		map = &reserved_mem_table[i];
+		if (!map->size)
+			continue;
+
+		memset(txtsz, 0, sizeof(txtsz));
+		string_get_size(map->size, 1, STRING_UNITS_2, txtsz, sizeof(txtsz));
+		seq_printf(m, "%s\t\t(%s)\n", map->name, txtsz);
+	}
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(memblock_reserve_mem);
+
+static int __init memblock_init_debugfs(void)
+{
+	struct dentry *root;
+
+	if (!IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK) && !reserved_mem_count)
+		return 0;
+
+	root = debugfs_create_dir("memblock", NULL);
+
+	if (reserved_mem_count)
+		debugfs_create_file("reserve_mem_param", 0444, root, NULL,
+				    &memblock_reserve_mem_fops);
+
+	memblock_debugfs_expose_arrays(root);
 	return 0;
 }
 __initcall(memblock_init_debugfs);
diff --git a/tools/testing/memblock/linux/string_helpers.h b/tools/testing/memblock/linux/string_helpers.h
new file mode 100644
index 000000000000..dbf015cfff31
--- /dev/null
+++ b/tools/testing/memblock/linux/string_helpers.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_STRING_HELPERS_H_
+#define _LINUX_STRING_HELPERS_H_
+
+/*
+ * Header stub to avoid test build breakage; we don't need to
+ * actually implement string_get_size() as it's not used in the tests.
+ */
+
+#endif
-- 
2.50.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt
  2026-03-18 18:56 [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Guilherme G. Piccoli
                   ` (2 preceding siblings ...)
  2026-03-24  1:22 ` [PATCH v4 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
@ 2026-03-24 15:17 ` Mike Rapoport
  3 siblings, 0 replies; 10+ messages in thread
From: Mike Rapoport @ 2026-03-24 15:17 UTC (permalink / raw)
  To: linux-mm, Guilherme G. Piccoli
  Cc: Mike Rapoport, linux-kernel, kernel-dev, kernel, Andrew Morton,
	Steven Rostedt, SeongJae Park

On Wed, 18 Mar 2026 15:56:31 -0300, Guilherme G. Piccoli wrote:
> tl; dr: we are adding here error messages in case of failures when
> reserve_mem parameter is used, and also a debugfs file to show
> successful reservations, with name and size as passed in the cmdline.
> 
> More details and history, please take a look at:
> 
> V2: lore.kernel.org/r/20260304203300.1414286-2-gpiccoli@igalia.com/
> V1: lore.kernel.org/r/20260217195816.861684-1-gpiccoli@igalia.com/
> 
> [...]

Applied to for-next branch of memblock.git tree, thanks!

[1/2] mm/memblock: Print out errors on reserve_mem parser
      commit: 855b388182df35d2907cb2d5723270b0df3a9e6e
[2/2] mm/memblock: Add reserve_mem debugfs info
      commit: 2db6cd07805051744036235f7ee9f24a9be9e283

tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next

--
Sincerely yours,
Mike.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info
  2026-03-24  1:22   ` [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
@ 2026-03-25  1:24     ` SeongJae Park
  0 siblings, 0 replies; 10+ messages in thread
From: SeongJae Park @ 2026-03-25  1:24 UTC (permalink / raw)
  To: Guilherme G. Piccoli
  Cc: SeongJae Park, linux-mm, linux-kernel, kernel-dev, kernel,
	Andrew Morton, Mike Rapoport, Steven Rostedt

On Mon, 23 Mar 2026 22:22:18 -0300 "Guilherme G. Piccoli" <gpiccoli@igalia.com> wrote:

> When using the "reserve_mem" parameter, users aim at having an
> area that (hopefully) persists across boots, so pstore infrastructure
> (like ramoops module) can make use of that to save oops/ftrace logs,
> for example.
> 
> There is no easy way to determine if this kernel parameter is properly
> set though; the kernel doesn't show information about this memory in
> memblock debugfs, neither in /proc/iomem nor dmesg. This is a relevant
> information for tools like kdumpst[0], to determine if it's reliable
> to use the reserved area as ramoops persistent storage; checking only
> /proc/cmdline is not sufficient as it doesn't tell if the reservation
> effectively succeeded or not.
> 
> Add here a new file under memblock debugfs showing properly set memory
> reservations, with name and size as passed to "reserve_mem". Notice that
> if no "reserve_mem=" is passed on command-line or if the reservation
> attempts fail, the file is not created.
> 
> [0] https://aur.archlinux.org/packages/kdumpst
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: SeongJae Park <sj@kernel.org>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-25  1:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 18:56 [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Guilherme G. Piccoli
2026-03-18 18:56 ` [PATCH v3 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
2026-03-18 18:56 ` [PATCH v3 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
2026-03-19 16:34   ` Mike Rapoport
2026-03-19 17:14     ` Guilherme G. Piccoli
2026-03-19 18:01       ` Mike Rapoport
2026-03-24  1:22 ` [PATCH v4 1/2] mm/memblock: Print out errors on reserve_mem parser Guilherme G. Piccoli
2026-03-24  1:22   ` [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info Guilherme G. Piccoli
2026-03-25  1:24     ` SeongJae Park
2026-03-24 15:17 ` [PATCH v3 0/2] Small improvements to reserve_mem, 3rd attempt Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox