From nobody Mon Apr 6 16:41:39 2026 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 CE02936F40D for ; Tue, 24 Mar 2026 01:28:53 +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=jUW6xzOwN+/7w/Y+zkxt+nShcAya0bfd6Ru0/2oJtSkkS6xbf7Lzk03WOgxf+JH2i2cHsREa2A/MLzJz1l+VpmzfZUQh+uIAcQreT3wjbSz+vJfqYBT2C0iExhG2NNef8L0eR0xAiEXUGmaiyKj8esjwilBjIwLxVLlAdZG0RGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774315736; c=relaxed/simple; bh=35YGp2+T6VXCB4RzIR/kfBxXhny6PETIzMsFZuQjqK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WmPbIBbEJrjcnKyjUzeDTUOw1JcJWdXr90wPoRtycw4qZcuTCIOrJ1dzbSd8Qidb03g1+FRuUQ1EYFf3bzmkbFp8uR9ZRFkeI2MJLUGez/gEV6kEwoqdlY8kAu1o+xTJRj68ILnP3zj46Kx7/6h1lHSZBPFDa0vR7N62LUYnxZM= 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=YnWJ9ElD; 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="YnWJ9ElD" 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=W6JRFOUadqjciaiNHE1QDofRIxwv1kmNDZZ2Wj8Ios4=; b=YnWJ9ElDJrJ3NE6m8liGiTosd8 ybIFtdCxq4+uGxr0YUoML5Ie4NFc3ZRtUgXVtjfyMvDgiQ1HEimnkEtYs/fEMjzzVDl7dBm6fGdnh U/AkPcYscEjH4ztWCgUuD6DIwGjquju7iyDuC0y8fzslplZdJnAgz8Fgf5JPldCzjD+/tpOin4wDq G4sXk3gFYN0vpgWv8mHtxKGDWba9xJQ9n/y0PZDpCOP4dvaKu3tKsKjhRB09mXmobwkoX+H0Ti3zN y2UHdHmrSGtbZ4G59/TatYnuWdSenszH3SSKQFnfUqRqXGj4Qp356UKE0F6DKPjFIDhxRwruuCFJp eb6buPJQ==; 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 1w4qZc-0058EB-PU; Tue, 24 Mar 2026 02:28:49 +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 1/2] mm/memblock: Print out errors on reserve_mem parser Date: Mon, 23 Mar 2026 22:22:17 -0300 Message-ID: <20260324012839.1991765-1-gpiccoli@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260318190816.1811325-1-gpiccoli@igalia.com> References: <20260318190816.1811325-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: quoted-printable Content-Type: text/plain; charset="utf-8" The parsing of kernel parameter "reserve_mem=3D" 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 Cc: Mike Rapoport Cc: Steven Rostedt Reviewed-by: SeongJae Park Signed-off-by: Guilherme G. Piccoli --- V4: no changes. V3 thread: https://lore.kernel.org/r/20260318190816.1811325-1-gpiccoli@igal= ia.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; =20 if (!p) - return -EINVAL; + goto err_param; =20 /* Check if there's room for more reserved memory */ - if (reserved_mem_count >=3D RESERVE_MEM_MAX_ENTRIES) + if (reserved_mem_count >=3D RESERVE_MEM_MAX_ENTRIES) { + pr_err("reserve_mem: no more room for reserved memory\n"); return -EBUSY; + } =20 oldp =3D p; size =3D memparse(p, &p); if (!size || p =3D=3D oldp) - return -EINVAL; + goto err_param; =20 if (*p !=3D ':') - return -EINVAL; + goto err_param; =20 align =3D memparse(p+1, &p); if (*p !=3D ':') - return -EINVAL; + goto err_param; =20 /* * memblock_phys_alloc() doesn't like a zero size align, @@ -2672,7 +2674,7 @@ static int __init reserve_mem(char *p) =20 /* name needs to have length but not too big */ if (!len || len >=3D RESERVE_MEM_NAME_SIZE) - return -EINVAL; + goto err_param; =20 /* Make sure that name has text */ for (p =3D name; *p; p++) { @@ -2680,11 +2682,13 @@ static int __init reserve_mem(char *p) break; } if (!*p) - return -EINVAL; + goto err_param; =20 /* 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; + } =20 /* 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) =20 /* TODO: Allocation must be outside of scratch region */ start =3D memblock_phys_alloc(size, align); - if (!start) + if (!start) { + pr_err("reserve_mem: memblock allocation failed\n"); return -ENOMEM; + } =20 reserved_mem_add(start, size, name); =20 return 1; +err_param: + pr_err("reserve_mem: empty or malformed parameter\n"); + return -EINVAL; } __setup("reserve_mem=3D", reserve_mem); =20 --=20 2.50.1 From nobody Mon Apr 6 16:41:39 2026 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 44A283EF65D for ; Wed, 18 Mar 2026 19:09:49 +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=1773860993; cv=none; b=OBASAQRbKgxN0vY4Poo+rvqfPPM6rvPFLP6gdPJAkUoQHeUUCVHLoJEbeTWfrX/LJfxrxvNjuLbVokQIYo3jnGagK9mVoU5jm1R57QEDhvC5q2bPeI6JpeYODIjdoDUx/ku+MFTlt0Q5lF5DU386cYyW4b4S/lZNed5sVnXqXQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773860993; c=relaxed/simple; bh=a5FRB9kQRdFCAY6J56PenoUIuCgyNROgXYr2/HQMLU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LqRT0y38vW80QnuSECrXUnGgKw4y8+L5rqRdTuqX5/H8C/2dplwLZ/jOY7QRP/sfQ+mms70iy4uUi2GE9/PrxsMU+hE/AdZLar27bF0x8/pbLmEgtMnEe7Zv4Hlfs9zYLvU6mFxXG2K4grFWlWmcGgtV3T/QXosl1e5bFS4jcWI= 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=YNRPCRI5; 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="YNRPCRI5" 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=c5teEie7C3ePZgybh/X+lnNmt1q5goT5Jx00idPTCrA=; b=YNRPCRI57rf3zAqRC0P7QRYu92 p7mPCnkVq2GJl1vWixeCAsenGmp9lGyZantrZEIOtPonMlp9y2rbDcbvT7w3hP0MkUvi3TyHlNcxi fsBIY7KIxgeCu31eC7xpDBAdnBetqAD/A8qVAp2yDuF0euH5Pfw8wgB3qg3PaqcTTjSQ3xTjs4eZF Mk1oo5K6Wl9qqFXsXybx5w1hG1UWJrlH6sdhVCppR/IK+Z/T1f3miUeuZMQUKNo89wcK8tRgu5U81 s0sfBV4ZKKD1EEt+qDul1FlJUOpkOzPXuLTi0k5N87mfCBLMQ/kXRwGdYpuya1WnewsG2jw/6yzr6 soGTiMGA==; 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 1w2wH5-002x5r-Ku; Wed, 18 Mar 2026 20:09:48 +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 v3 1/2] mm/memblock: Print out errors on reserve_mem parser Date: Wed, 18 Mar 2026 15:56:32 -0300 Message-ID: <20260318190816.1811325-2-gpiccoli@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260318190816.1811325-1-gpiccoli@igalia.com> References: <20260318190816.1811325-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: quoted-printable Content-Type: text/plain; charset="utf-8" The parsing of kernel parameter "reserve_mem=3D" 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 Cc: Mike Rapoport Cc: Steven Rostedt Reviewed-by: SeongJae Park Signed-off-by: Guilherme G. Piccoli --- 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; =20 if (!p) - return -EINVAL; + goto err_param; =20 /* Check if there's room for more reserved memory */ - if (reserved_mem_count >=3D RESERVE_MEM_MAX_ENTRIES) + if (reserved_mem_count >=3D RESERVE_MEM_MAX_ENTRIES) { + pr_err("reserve_mem: no more room for reserved memory\n"); return -EBUSY; + } =20 oldp =3D p; size =3D memparse(p, &p); if (!size || p =3D=3D oldp) - return -EINVAL; + goto err_param; =20 if (*p !=3D ':') - return -EINVAL; + goto err_param; =20 align =3D memparse(p+1, &p); if (*p !=3D ':') - return -EINVAL; + goto err_param; =20 /* * memblock_phys_alloc() doesn't like a zero size align, @@ -2672,7 +2674,7 @@ static int __init reserve_mem(char *p) =20 /* name needs to have length but not too big */ if (!len || len >=3D RESERVE_MEM_NAME_SIZE) - return -EINVAL; + goto err_param; =20 /* Make sure that name has text */ for (p =3D name; *p; p++) { @@ -2680,11 +2682,13 @@ static int __init reserve_mem(char *p) break; } if (!*p) - return -EINVAL; + goto err_param; =20 /* 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; + } =20 /* 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) =20 /* TODO: Allocation must be outside of scratch region */ start =3D memblock_phys_alloc(size, align); - if (!start) + if (!start) { + pr_err("reserve_mem: memblock allocation failed\n"); return -ENOMEM; + } =20 reserved_mem_add(start, size, name); =20 return 1; +err_param: + pr_err("reserve_mem: empty or malformed parameter\n"); + return -EINVAL; } __setup("reserve_mem=3D", reserve_mem); =20 --=20 2.50.1 From nobody Mon Apr 6 16:41:39 2026 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 69CD33EFD36 for ; Wed, 18 Mar 2026 19:09:53 +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=1773860994; cv=none; b=k5Zos9xr8e8AZgTopZHSpggag/mQvHay9HaKfLJogUC2vhjWqKBWiMl33cPnGFV6SEC2CG+6pql3tlxRytsBNgsLpuJ3IIXye/moNHPpfnPplhlQ4vzp7aDo1/xxPoURK1h+RxulrmeN4d32JD6kPDm4Ru8L5P/93XDXNsz7xSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773860994; c=relaxed/simple; bh=yOiZff4PgJXLja5WDgjTag2i+ylitVAwREb/ivrJVZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ncC3NDxYZA2YV8d/P/q13nbLyanoeIPrqUts9AQkvtj3zDCQJvjy0M/RrrsMe58rjMMKThBGw3M22Cn7VI+HXiUShUj1IvDNj/P0jr1cDsDZmvSJ4amI7hZpCHfWhJqKFBBwi5JdFlNI+cVjt5dXifpxYXcUfWeOV+vWtfz/pB0= 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=mEMl3BB8; 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="mEMl3BB8" 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=s9aQ9DqpNpZmEebvsRHFhSx+09H/nA+yNH+hxL6fCjs=; b=mEMl3BB8rYYMAsvbZBVmtVsl9s yrkMpj60e++5MMR4RsqQiF5ugE2gsz9q70Sj6emPfXbl/T56VIrtcLn2AkVcyhveZtoiOju0p+rU/ UpY4xpCfTBaaEWS1KwjrJNwbpqEw6VXsurRah48NbvW9FS9Mm5akDaRijndqkybNJKygXJq+Rdyus ZKktJMO9bCWzOvMvT3oodRsYaAbZ0y0gjB4yQBzeEInUDzIsHApgJtedxC+vB4ExY4GEt9MyOFPD6 7/akArpQK7PPycQjhOz5BcbkYc2ooMaFeLZkzkNJyA7skvN4WCHB7MPzICt0IHSYE9iKEIXh7EC03 CMs9BQ6A==; 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 1w2wH8-002x66-Uv; Wed, 18 Mar 2026 20:09:51 +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 v3 2/2] mm/memblock: Add reserve_mem debugfs info Date: Wed, 18 Mar 2026 15:56:33 -0300 Message-ID: <20260318190816.1811325-3-gpiccoli@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260318190816.1811325-1-gpiccoli@igalia.com> References: <20260318190816.1811325-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D" 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 --- 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 #include #include +#include =20 #ifdef CONFIG_KEXEC_HANDOVER #include @@ -2710,7 +2711,8 @@ static int __init reserve_mem(char *p) } __setup("reserve_mem=3D", reserve_mem); =20 -#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) +#ifdef CONFIG_DEBUG_FS +#ifdef CONFIG_ARCH_KEEP_MEMBLOCK static const char * const flagname[] =3D { [ilog2(MEMBLOCK_HOTPLUG)] =3D "HOTPLUG", [ilog2(MEMBLOCK_MIRROR)] =3D "MIRROR", @@ -2757,19 +2759,57 @@ static int memblock_debug_show(struct seq_file *m, = void *private) } DEFINE_SHOW_ATTRIBUTE(memblock_debug); =20 -static int __init memblock_init_debugfs(void) +static inline void memblock_debugfs_make_dirs(struct dentry *root) { - struct dentry *root =3D 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); +} =20 +#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 =3D 0; i < reserved_mem_count; i++) { + map =3D &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 =3D 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 --=20 2.50.1