From: Bagas Sanjaya <bagasdotme@gmail.com>
To: Eugen Hristev <eugen.hristev@linaro.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, tglx@linutronix.de, andersson@kernel.org,
pmladek@suse.com, rdunlap@infradead.org, corbet@lwn.net,
david@redhat.com, mhocko@suse.com
Cc: tudor.ambarus@linaro.org, mukesh.ojha@oss.qualcomm.com,
linux-arm-kernel@lists.infradead.org,
linux-hardening@vger.kernel.org, jonechou@google.com,
rostedt@goodmis.org, linux-doc@vger.kernel.org,
devicetree@vger.kernel.org, linux-remoteproc@vger.kernel.org,
linux-arch@vger.kernel.org, tony.luck@intel.com, kees@kernel.org
Subject: Re: [PATCH 01/26] kernel: Introduce meminspect
Date: Mon, 24 Nov 2025 10:02:37 +0700 [thread overview]
Message-ID: <aSPKzcsFixn48edg@archie.me> (raw)
In-Reply-To: <20251119154427.1033475-2-eugen.hristev@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 11925 bytes --]
On Wed, Nov 19, 2025 at 05:44:02PM +0200, Eugen Hristev wrote:
> diff --git a/Documentation/dev-tools/index.rst b/Documentation/dev-tools/index.rst
> index 4b8425e348ab..8ce605de8ee6 100644
> --- a/Documentation/dev-tools/index.rst
> +++ b/Documentation/dev-tools/index.rst
> @@ -38,6 +38,7 @@ Documentation/process/debugging/index.rst
> gpio-sloppy-logic-analyzer
> autofdo
> propeller
> + meminspect
>
>
> .. only:: subproject and html
> diff --git a/Documentation/dev-tools/meminspect.rst b/Documentation/dev-tools/meminspect.rst
> new file mode 100644
> index 000000000000..2a0bd4d6e448
> --- /dev/null
> +++ b/Documentation/dev-tools/meminspect.rst
> @@ -0,0 +1,139 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +==========
> +meminspect
> +==========
> +
> +This document provides information about the meminspect feature.
> +
> +Overview
> +========
> +
> +meminspect is a mechanism that allows the kernel to register a chunk of
> +memory into a table, to be used at a later time for a specific
> +inspection purpose like debugging, memory dumping or statistics.
> +
> +meminspect allows drivers to traverse the inspection table on demand,
> +or to register a notifier to be called whenever a new entry is being added
> +or removed.
> +
> +The reasoning for meminspect is also to minimize the required information
> +in case of a kernel problem. For example a traditional debug method involves
> +dumping the whole kernel memory and then inspecting it. Meminspect allows the
> +users to select which memory is of interest, in order to help this specific
> +use case in production, where memory and connectivity are limited.
> +
> +Although the kernel has multiple internal mechanisms, meminspect fits
> +a particular model which is not covered by the others.
> +
> +meminspect Internals
> +====================
> +
> +API
> +---
> +
> +Static memory can be registered at compile time, by instructing the compiler
> +to create a separate section with annotation info.
> +For each such annotated memory (variables usually), a dedicated struct
> +is being created with the required information.
> +To achieve this goal, some basic APIs are available:
> +
> + MEMINSPECT_ENTRY(idx, sym, sz)
> +is the basic macro that takes an ID, the symbol, and a size.
> +
> +To make it easier, some wrappers are also defined:
> + MEMINSPECT_SIMPLE_ENTRY(sym)
> +will use the dedicated MEMINSPECT_ID_##sym with a size equal to sizeof(sym)
> +
> + MEMINSPECT_NAMED_ENTRY(name, sym)
> +will be a simple entry that has an id that cannot be derived from the sym,
> +so a name has to be provided
> +
> + MEMINSPECT_AREA_ENTRY(sym, sz)
> +this will register sym, but with the size given as sz, useful for e.g.
> +arrays which do not have a fixed size at compile time.
> +
> +For dynamically allocated memory, or for other cases, the following APIs
> +are being defined:
> + meminspect_register_id_pa(enum meminspect_uid id, phys_addr_t zone,
> + size_t size, unsigned int type);
> +which takes the ID and the physical address.
> +Similarly there are variations:
> + meminspect_register_pa() omits the ID
> + meminspect_register_id_va() requires the ID but takes a virtual address
> + meminspect_register_va() omits the ID and requires a virtual address
> +
> +If the ID is not given, the next avialable dynamic ID is allocated.
> +
> +To unregister a dynamic entry, some APIs are being defined:
> + meminspect_unregister_pa(phys_addr_t zone, size_t size);
> + meminspect_unregister_id(enum meminspect_uid id);
> + meminspect_unregister_va(va, size);
> +
> +All of the above have a lock variant that ensures the lock on the table
> +is taken.
> +
> +
> +meminspect drivers
> +------------------
> +
> +Drivers are free to traverse the table by using a dedicated function
> +meminspect_traverse(void *priv, MEMINSPECT_ITERATOR_CB cb)
> +The callback will be called for each entry in the table.
> +
> +Drivers can also register a notifier with
> + meminspect_notifier_register()
> +and unregister with
> + meminspect_notifier_unregister()
> +to be called when a new entry is being added or removed.
> +
> +Data structures
> +---------------
> +
> +The regions are being stored in a simple fixed size array. It avoids
> +memory allocation overhead. This is not performance critical nor does
> +allocating a few hundred entries create a memory consumption problem.
> +
> +The static variables registered into meminspect are being annotated into
> +a dedicated .inspect_table memory section. This is then walked by meminspect
> +at a later time and each variable is then copied to the whole inspect table.
> +
> +meminspect Initialization
> +-------------------------
> +
> +At any time, meminspect will be ready to accept region registration
> +from any part of the kernel. The table does not require any initialization.
> +In case CONFIG_CRASH_DUMP is enabled, meminspect will create an ELF header
> +corresponding to a core dump image, in which each region is added as a
> +program header. In this scenario, the first region is this ELF header, and
> +the second region is the vmcoreinfo ELF note.
> +By using this mechanism, all the meminspect table, if dumped, can be
> +concatenated to obtain a core image that is loadable with the `crash` tool.
> +
> +meminspect example
> +==================
> +
> +A simple scenario for meminspect is the following:
> +The kernel registers the linux_banner variable into meminspect with
> +a simple annotation like:
> +
> + MEMINSPECT_SIMPLE_ENTRY(linux_banner);
> +
> +The meminspect late initcall will parse the compilation time created table
> +and copy the entry information into the inspection table.
> +At a later point, any interested driver can call the traverse function to
> +find out all entries in the table.
> +A specific driver will then note into a specific table the address of the
> +banner and the size of it.
> +The specific table is then written to a shared memory area that can be
> +read by upper level firmware.
> +When the kernel freezes (hypothetically), the kernel will no longer feed
> +the watchdog. The watchdog will trigger a higher exception level interrupt
> +which will be handled by the upper level firmware. This firmware will then
> +read the shared memory table and find an entry with the start and size of
> +the banner. It will then copy it for debugging purpose. The upper level
> +firmware will then be able to provide useful debugging information,
> +like in this example, the banner.
> +
> +As seen here, meminspect facilitates the interaction between the kernel
> +and a specific firmware.
Sphinx reports htmldocs warnings:
Documentation/dev-tools/meminspect.rst:42: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
Documentation/dev-tools/meminspect.rst:46: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
Documentation/dev-tools/meminspect.rst:49: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
Documentation/dev-tools/meminspect.rst:53: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
Documentation/dev-tools/meminspect.rst:58: ERROR: Unexpected indentation. [docutils]
Documentation/dev-tools/meminspect.rst:60: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
Documentation/dev-tools/meminspect.rst:62: ERROR: Unexpected indentation. [docutils]
Documentation/dev-tools/meminspect.rst:80: WARNING: Inline emphasis start-string without end-string. [docutils]
Documentation/dev-tools/meminspect.rst:88: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
I have to fix them up:
---- >8 ----
diff --git a/Documentation/dev-tools/meminspect.rst b/Documentation/dev-tools/meminspect.rst
index 2a0bd4d6e4481e..d6a221b1169f04 100644
--- a/Documentation/dev-tools/meminspect.rst
+++ b/Documentation/dev-tools/meminspect.rst
@@ -38,37 +38,43 @@ For each such annotated memory (variables usually), a dedicated struct
is being created with the required information.
To achieve this goal, some basic APIs are available:
- MEMINSPECT_ENTRY(idx, sym, sz)
-is the basic macro that takes an ID, the symbol, and a size.
+ * MEMINSPECT_ENTRY(idx, sym, sz)
+ is the basic macro that takes an ID, the symbol, and a size.
To make it easier, some wrappers are also defined:
- MEMINSPECT_SIMPLE_ENTRY(sym)
-will use the dedicated MEMINSPECT_ID_##sym with a size equal to sizeof(sym)
- MEMINSPECT_NAMED_ENTRY(name, sym)
-will be a simple entry that has an id that cannot be derived from the sym,
-so a name has to be provided
+ * MEMINSPECT_SIMPLE_ENTRY(sym)
+ will use the dedicated MEMINSPECT_ID_##sym with a size equal to sizeof(sym)
- MEMINSPECT_AREA_ENTRY(sym, sz)
-this will register sym, but with the size given as sz, useful for e.g.
-arrays which do not have a fixed size at compile time.
+ * MEMINSPECT_NAMED_ENTRY(name, sym)
+ will be a simple entry that has an id that cannot be derived from the sym,
+ so a name has to be provided
+
+ * MEMINSPECT_AREA_ENTRY(sym, sz)
+ this will register sym, but with the size given as sz, useful for e.g.
+ arrays which do not have a fixed size at compile time.
For dynamically allocated memory, or for other cases, the following APIs
-are being defined:
+are being defined::
+
meminspect_register_id_pa(enum meminspect_uid id, phys_addr_t zone,
size_t size, unsigned int type);
+
which takes the ID and the physical address.
+
Similarly there are variations:
- meminspect_register_pa() omits the ID
- meminspect_register_id_va() requires the ID but takes a virtual address
- meminspect_register_va() omits the ID and requires a virtual address
+
+ * meminspect_register_pa() omits the ID
+ * meminspect_register_id_va() requires the ID but takes a virtual address
+ * meminspect_register_va() omits the ID and requires a virtual address
If the ID is not given, the next avialable dynamic ID is allocated.
To unregister a dynamic entry, some APIs are being defined:
- meminspect_unregister_pa(phys_addr_t zone, size_t size);
- meminspect_unregister_id(enum meminspect_uid id);
- meminspect_unregister_va(va, size);
+
+ * meminspect_unregister_pa(phys_addr_t zone, size_t size);
+ * meminspect_unregister_id(enum meminspect_uid id);
+ * meminspect_unregister_va(va, size);
All of the above have a lock variant that ensures the lock on the table
is taken.
@@ -77,15 +83,15 @@ is taken.
meminspect drivers
------------------
-Drivers are free to traverse the table by using a dedicated function
-meminspect_traverse(void *priv, MEMINSPECT_ITERATOR_CB cb)
+Drivers are free to traverse the table by using a dedicated function::
+
+ meminspect_traverse(void *priv, MEMINSPECT_ITERATOR_CB cb)
+
The callback will be called for each entry in the table.
-Drivers can also register a notifier with
- meminspect_notifier_register()
-and unregister with
- meminspect_notifier_unregister()
-to be called when a new entry is being added or removed.
+Drivers can also register a notifier with meminspect_notifier_register()
+and unregister with meminspect_notifier_unregister() to be called when a new
+entry is being added or removed.
Data structures
---------------
@@ -115,7 +121,7 @@ meminspect example
A simple scenario for meminspect is the following:
The kernel registers the linux_banner variable into meminspect with
-a simple annotation like:
+a simple annotation like::
MEMINSPECT_SIMPLE_ENTRY(linux_banner);
Thanks.
--
An old man doll... just what I always wanted! - Clara
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-11-24 3:02 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 15:44 [PATCH 00/26] " Eugen Hristev
2025-11-19 15:44 ` [PATCH 01/26] kernel: " Eugen Hristev
2025-11-22 0:04 ` kernel test robot
2025-11-24 3:02 ` Bagas Sanjaya [this message]
2025-11-19 15:44 ` [PATCH 02/26] init/version: Annotate static information into meminspect Eugen Hristev
2025-11-19 15:44 ` [PATCH 03/26] mm/percpu: " Eugen Hristev
2025-11-21 17:13 ` kernel test robot
2025-11-21 19:13 ` kernel test robot
2025-11-19 15:44 ` [PATCH 04/26] cpu: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 05/26] genirq/irqdesc: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 06/26] timers: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 07/26] kernel/fork: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 08/26] mm/page_alloc: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 09/26] mm/show_mem: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 10/26] mm/swapfile: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 11/26] kernel/vmcore_info: Register dynamic " Eugen Hristev
2025-11-19 15:44 ` [PATCH 12/26] kernel/configs: " Eugen Hristev
2025-11-21 22:16 ` kernel test robot
2025-11-19 15:44 ` [PATCH 13/26] mm/init-mm: Annotate static " Eugen Hristev
2025-11-19 15:44 ` [PATCH 14/26] panic: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 15/26] kallsyms: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 16/26] mm/mm_init: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 17/26] sched/core: Annotate runqueues " Eugen Hristev
2025-11-19 15:44 ` [PATCH 18/26] mm/memblock: Add MEMBLOCK_INSPECT flag Eugen Hristev
2025-11-19 15:44 ` [PATCH 19/26] mm/numa: Register information into meminspect Eugen Hristev
2025-11-19 15:44 ` [PATCH 20/26] mm/sparse: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 21/26] printk: " Eugen Hristev
2025-11-19 15:44 ` [PATCH 22/26] remoteproc: qcom: Extract minidump definitions into a header Eugen Hristev
2025-11-19 15:44 ` [PATCH 23/26] soc: qcom: Add minidump driver Eugen Hristev
2025-11-22 4:55 ` kernel test robot
2025-11-22 7:54 ` kernel test robot
2025-11-19 15:44 ` [PATCH 24/26] soc: qcom: smem: Add minidump device Eugen Hristev
2025-11-19 15:44 ` [PATCH 25/26] dt-bindings: reserved-memory: Add Google Kinfo Pixel reserved memory Eugen Hristev
2025-11-19 16:02 ` Krzysztof Kozlowski
2025-11-19 16:19 ` Eugen Hristev
2025-11-20 7:21 ` Krzysztof Kozlowski
2025-11-19 16:33 ` Rob Herring (Arm)
2025-11-19 22:41 ` Rob Herring
2025-11-19 15:44 ` [PATCH 26/26] meminspect: Add Kinfo compatible driver Eugen Hristev
2025-11-19 16:30 ` [PATCH 00/26] Introduce meminspect Lorenzo Stoakes
2025-11-19 17:11 ` Eugen Hristev
2025-11-19 17:14 ` Lorenzo Stoakes
2025-11-19 17:19 ` Eugen Hristev
2025-11-19 18:15 ` Steven Rostedt
2025-11-19 18:24 ` Eugen Hristev
2025-11-19 18:38 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSPKzcsFixn48edg@archie.me \
--to=bagasdotme@gmail.com \
--cc=andersson@kernel.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=devicetree@vger.kernel.org \
--cc=eugen.hristev@linaro.org \
--cc=jonechou@google.com \
--cc=kees@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=mukesh.ojha@oss.qualcomm.com \
--cc=pmladek@suse.com \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=tudor.ambarus@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox