From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 8/8] tracing: Update modules to persistent instances when loaded
Date: Fri, 7 Feb 2025 01:53:30 +0900 [thread overview]
Message-ID: <20250207015330.5c71ad55ed2f516da1410711@kernel.org> (raw)
In-Reply-To: <20250206103612.355a4be9@gandalf.local.home>
On Thu, 6 Feb 2025 10:36:12 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Thu, 6 Feb 2025 19:01:24 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
>
> > > +static void trace_module_record(struct module *mod)
> > > +{
> > > + struct trace_array *tr;
> > > +
> > > + list_for_each_entry(tr, &ftrace_trace_arrays, list) {
> > > + /* Update any persistent trace array that has already been started */
> > > + if ((tr->flags & (TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT)) ==
> > > + TRACE_ARRAY_FL_BOOT) {
> > > + /* Only update if the trace array is active */
> > > + if (trace_array_active(tr))
> >
> > Do we really need this check? It seems that we can just save_mod() if the
> > above condition is true.
>
> It gets a little more complicated if we need to add and remove modules.
Yeah, but for converting the module address, we don't want to see other
module information.
>
> >
> > > + save_mod(mod, tr);
> > > + }
> > > + }
> > > +}
> > > +
> > > static int trace_module_notify(struct notifier_block *self,
> > > unsigned long val, void *data)
> > > {
> > > @@ -10096,6 +10120,7 @@ static int trace_module_notify(struct notifier_block *self,
> > > switch (val) {
> > > case MODULE_STATE_COMING:
> > > trace_module_add_evals(mod);
> > > + trace_module_record(mod);
> > > break;
> > > case MODULE_STATE_GOING:
> > > trace_module_remove_evals(mod);
> >
> > Don't we need to remove the module entry when a module is removed?
> > (everytime we remove a module, trace data is cleared?)
>
> I do have a patch that that removes entries, but I decided we don't really
> want to do that.
>
> If we want to have events for modules that were removed. Note, the ring
> buffer is cleared if any module event was ever enabled and then the module
> is removed, as how to print it is removed too. But we could disable that
> for the persistent ring buffers as they should not be using the default
> trace event print format anyway.
Yeah, if the event is on the module the buffer is cleared.
But the module address can be in the stacktrace. In that case, the event
in the module is not enabled, but other events like sched_switch can
take stacktrace which can include the module address. In that case, the
buffer is also cleared when the module is removed?
> As for stack traces, we still want the module it was for when the stack
> trace happens. A common bug we see is when a module is removed, it can
> cause other bugs. We want to know about modules that were removed. Keeping
> that information about removed modules will allow us to see what functions
> were called by a stack trace for a module that was removed.
Hmm, but that should be covered by module load/unload events?
Anyway, this series does not cover the module text address in the stacktrace.
I just made a series of patches (which also not cover the module removal yet),
but it can show the basic idea.
My idea is to sort the previous module entries in the persistent buffer
when it is setup. We also make a "module_delta" array in the trace_array.
Then the print function can searche the appropriate module info from
the sorted table and find corresponding delta from "module_delta".
For example,
/sys/kernel/tracing/instances/boot_mapped # cat trace
<...>-1629 [006] ..... 202.860051: foo_bar_with_fn: foo Look at me 4
<...>-1629 [006] ..... 202.860059: <stack trace>
=> trace_event_raw_event_foo_bar_with_fn
=> simple_thread_fn
=> kthread
=> ret_from_fork
=> ret_from_fork_asm
/sys/kernel/tracing/instances/boot_mapped # cat last_boot_info
Offset: 0
ffffffffa0016000 trace_events_sample
ffffffffa0025000 trace_printk
/sys/kernel/tracing/instances/boot_mapped # lsmod
trace_events_sample 45056 0 - Live 0xffffffffa001c000
trace_printk 12288 0 - Live 0xffffffffa0016000
Let me share it.
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-02-06 16:53 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 22:50 [PATCH 0/8] ring-buffer/tracing: Save module information in persistent memory Steven Rostedt
2025-02-05 22:50 ` [PATCH 1/8] ring-buffer: Use kaslr address instead of text delta Steven Rostedt
2025-02-06 0:32 ` Masami Hiramatsu
2025-02-05 22:50 ` [PATCH 2/8] ring-buffer: Add buffer meta data for persistent ring buffer Steven Rostedt
2025-02-06 5:10 ` Masami Hiramatsu
2025-02-06 15:19 ` Steven Rostedt
2025-02-05 22:50 ` [PATCH 3/8] ring-buffer: Add ring_buffer_meta_scratch() Steven Rostedt
2025-02-06 5:13 ` Masami Hiramatsu
2025-02-05 22:50 ` [PATCH 4/8] tracing: Have persistent trace instances save KASLR offset Steven Rostedt
2025-02-06 5:22 ` Masami Hiramatsu
2025-02-06 15:24 ` Steven Rostedt
2025-02-07 0:58 ` Masami Hiramatsu
2025-02-07 1:03 ` Steven Rostedt
2025-02-07 2:15 ` Masami Hiramatsu
2025-02-05 22:50 ` [PATCH 5/8] module: Add module_for_each_mod() function Steven Rostedt
2025-02-06 5:28 ` Masami Hiramatsu
2025-02-06 15:27 ` Steven Rostedt
2025-02-10 13:04 ` Petr Pavlu
2025-02-10 14:08 ` Sebastian Andrzej Siewior
2025-02-14 22:30 ` Steven Rostedt
2025-02-18 21:21 ` Luis Chamberlain
2025-02-18 21:29 ` Steven Rostedt
2025-02-19 0:24 ` Steven Rostedt
2025-02-19 16:02 ` Luis Chamberlain
2025-02-05 22:50 ` [PATCH 6/8] tracing: Have persistent trace instances save module addresses Steven Rostedt
2025-02-06 8:26 ` Masami Hiramatsu
2025-02-06 15:29 ` Steven Rostedt
2025-02-06 16:53 ` Masami Hiramatsu
2025-02-05 22:50 ` [PATCH 7/8] tracing: Show module names and addresses of last boot Steven Rostedt
2025-02-07 1:51 ` Masami Hiramatsu
2025-02-07 2:02 ` Steven Rostedt
2025-02-07 2:25 ` Masami Hiramatsu
2025-02-05 22:50 ` [PATCH 8/8] tracing: Update modules to persistent instances when loaded Steven Rostedt
2025-02-06 10:01 ` Masami Hiramatsu
2025-02-06 15:36 ` Steven Rostedt
2025-02-06 16:53 ` Masami Hiramatsu [this message]
2025-02-06 16:58 ` [PATCH 1/3] tracing: Skip update_last_data() if it is already updated Masami Hiramatsu (Google)
2025-02-06 16:58 ` [PATCH 2/3] tracing: Remove checking the activity when module map is updating Masami Hiramatsu (Google)
2025-03-07 15:21 ` Steven Rostedt
2025-03-11 0:40 ` Masami Hiramatsu
2025-02-06 16:59 ` [PATCH 3/3] tracing: Show last module text symbols in the stacktrace Masami Hiramatsu (Google)
2025-02-06 17:46 ` Steven Rostedt
2025-02-07 1:50 ` Masami Hiramatsu
2025-02-06 17:18 ` [PATCH 8/8] tracing: Update modules to persistent instances when loaded Steven Rostedt
2025-02-07 0:47 ` Masami Hiramatsu
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=20250207015330.5c71ad55ed2f516da1410711@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.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