From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE17F277017 for ; Tue, 24 Mar 2026 01:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774315736; cv=none; b=agxiSpd9pZAV8anhzxcWOzue+XRlMXyf4PUY3R9GVAtGPaebmp4DwbGNTLLEnbl47oW8RjZ7G0jLd6WZkjyCsh1ZhQX31NUgroeJRzDd6I3ztDKiuBP6BinCIxdjv3EQlskhWbKp+hFeIcXikQnbn23NzPxj1PYeedpDOD61+qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774315736; c=relaxed/simple; bh=iElfMyrFAGWF6kSv3xsxHTR5EqvWNyk4azObQwHAI7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ADe4NZM/1tF9Xih3XNypuWVERMUJLuuSJD8oS3oPHkcsB+CYQP2cSUHlL7AJzcN5ZS9RSLCw9UaMQQ4OK1BPi7UQAwJOhNrJhMKxV+TfoZLIgn0Bb5v13ILrMMmzKWKou6Hs1tyXUI1VLHLtAhc2+EULDqxs/G2kjWPUfSpzpwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=UUVp0Lic; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="UUVp0Lic" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Vl65OewpyCNb1x+ocrpJYTSNh8NK5VQ+ZXQ5NOHIbn0=; b=UUVp0LicBjb96wh5AXNZ3wFGBA BB9wP/mHQWju/1m3lCwIBLKBI96h/oKA6YpMkEWwCQ9AxehRtJ2dqUKZ0O0JX41n6DBd5GJF62DWi iVWkGgxxdU8rzQP5w5C4TkhBjEDvlY+g705KMYtY1t4II+OPuuL+uLoNdJgWvDaPZm23AN8zi4wpy pg2FvX2YbemW2d9EbjKllhjFcIaShhhBWsqmLLI1qllY/y9P9/T5o2DNbubnq7a2S99uHP8OILlNX XA2KLPSybXgezXdrJ8lgSKYocpmnycBhD4cC5JtGkFLw+dG9oV3/rABzvly+YjsbKyHoYFOFmR/4a RkqVBzfQ==; Received: from [179.93.15.111] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1w4qZg-0058EG-Bd; Tue, 24 Mar 2026 02:28:52 +0100 From: "Guilherme G. Piccoli" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, "Guilherme G. Piccoli" , Andrew Morton , Mike Rapoport , Steven Rostedt , SeongJae Park Subject: [PATCH v4 2/2] mm/memblock: Add reserve_mem debugfs info Date: Mon, 23 Mar 2026 22:22:18 -0300 Message-ID: <20260324012839.1991765-2-gpiccoli@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260324012839.1991765-1-gpiccoli@igalia.com> References: <20260318190816.1811325-1-gpiccoli@igalia.com> <20260324012839.1991765-1-gpiccoli@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Mike Rapoport Cc: Steven Rostedt Cc: SeongJae Park Signed-off-by: Guilherme G. Piccoli --- 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 #include #include +#include #ifdef CONFIG_KEXEC_HANDOVER #include @@ -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