[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250206142817.91853f475c681bc2ef7ca962@kernel.org>
Date: Thu, 6 Feb 2025 14:28:17 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org, Masami
Hiramatsu <mhiramat@...nel.org>, Mark Rutland <mark.rutland@....com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, Andrew Morton
<akpm@...ux-foundation.org>, Luis Chamberlain <mcgrof@...nel.org>, Petr
Pavlu <petr.pavlu@...e.com>, Sami Tolvanen <samitolvanen@...gle.com>,
Daniel Gomez <da.gomez@...sung.com>, linux-modules@...r.kernel.org
Subject: Re: [PATCH 5/8] module: Add module_for_each_mod() function
On Wed, 05 Feb 2025 17:50:36 -0500
Steven Rostedt <rostedt@...dmis.org> wrote:
> From: Steven Rostedt <rostedt@...dmis.org>
>
> The tracing system needs a way to save all the currently loaded modules
> and their addresses into persistent memory so that it can evaluate the
> addresses on a reboot from a crash. When the persistent memory trace
> starts, it will load the module addresses and names into the persistent
> memory. To do so, it will call the module_for_each_mod() function and pass
> it a function and data structure to get called on each loaded module. Then
> it can record the memory.
>
> This only implements that function.
>
> Cc: Luis Chamberlain <mcgrof@...nel.org>
> Cc: Petr Pavlu <petr.pavlu@...e.com>
> Cc: Sami Tolvanen <samitolvanen@...gle.com>
> Cc: Daniel Gomez <da.gomez@...sung.com>
> Cc: linux-modules@...r.kernel.org
> Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
> ---
> include/linux/module.h | 6 ++++++
> kernel/module/main.c | 14 ++++++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/include/linux/module.h b/include/linux/module.h
> index 23792d5d7b74..9e1f42f03511 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -779,6 +779,8 @@ static inline void *module_writable_address(struct module *mod, void *loc)
> return __module_writable_address(mod, loc);
> }
>
> +void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data);
> +
> #else /* !CONFIG_MODULES... */
>
> static inline struct module *__module_address(unsigned long addr)
> @@ -891,6 +893,10 @@ static inline void *module_writable_address(struct module *mod, void *loc)
> {
> return loc;
> }
> +
> +static inline void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data)
> +{
> +}
> #endif /* CONFIG_MODULES */
>
> #ifdef CONFIG_SYSFS
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 1fb9ad289a6f..ea1fe313fb89 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -3809,6 +3809,20 @@ bool is_module_text_address(unsigned long addr)
> return ret;
> }
>
It is better to add a kerneldoc for this API.
/**
* module_for_each_mod() - iterate all modules
* @func: Callback function
* @data: User data
*
* Call the @func with each module in the system. If @func returns !0, this
* stops itrating. Note that @func must not sleep since it is called under
* the preemption disabled.
*/
BTW, do we really need to disable preempt or is it enough to call
rcu_read_lock()?
Thank you,
> +void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data)
> +{
> + struct module *mod;
> +
> + preempt_disable();
> + list_for_each_entry_rcu(mod, &modules, list) {
> + if (mod->state == MODULE_STATE_UNFORMED)
> + continue;
> + if (func(mod, data))
> + break;
> + }
> + preempt_enable();
> +}
> +
> /**
> * __module_text_address() - get the module whose code contains an address.
> * @addr: the address.
> --
> 2.45.2
>
>
--
Masami Hiramatsu (Google) <mhiramat@...nel.org>
Powered by blists - more mailing lists