From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 7/8] tracing: Show module names and addresses of last boot
Date: Wed, 05 Feb 2025 17:50:38 -0500 [thread overview]
Message-ID: <20250205225104.096389081@goodmis.org> (raw)
In-Reply-To: 20250205225031.799739376@goodmis.org
From: Steven Rostedt <rostedt@goodmis.org>
Add the last boot module's names and addresses to the last_boot_info file.
This only shows the module information from a previous boot. If the buffer
is started and is recording the current boot, this file still will only
show "current".
# cat instances/boot_mapped/last_boot_info
Offset: 10c00000
ffffffffc00ca000 usb_serial_simple
ffffffffc00ae000 usbserial
ffffffffc008b000 bfq
# echo function > instances/boot_mapped/current_tracer
# cat instances/boot_mapped/last_boot_info
Offset: current
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 103 +++++++++++++++++++++++++++++++++++++------
1 file changed, 90 insertions(+), 13 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a8e5f7ac2193..7b4027804cd4 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6005,6 +6005,8 @@ struct trace_scratch {
struct trace_mod_entry entries[];
};
+static DEFINE_MUTEX(scratch_mutex);
+
static int save_mod(struct module *mod, void *data)
{
struct trace_array *tr = data;
@@ -6012,6 +6014,8 @@ static int save_mod(struct module *mod, void *data)
struct trace_mod_entry *entry;
unsigned int size;
+ guard(mutex)(&scratch_mutex);
+
tscratch = tr->scratch;
if (!tscratch)
return -1;
@@ -6882,15 +6886,47 @@ tracing_total_entries_read(struct file *filp, char __user *ubuf,
return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}
-static ssize_t
-tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
+#define LAST_BOOT_HEADER ((void *)1)
+
+static void *l_next(struct seq_file *m, void *v, loff_t *pos)
{
- struct trace_array *tr = filp->private_data;
+ struct trace_array *tr = m->private;
struct trace_scratch *tscratch = tr->scratch;
- struct seq_buf seq;
- char buf[64];
+ unsigned int index = *pos;
+
+ (*pos)++;
+
+ if (*pos == 1)
+ return LAST_BOOT_HEADER;
+
+ /* Only show offsets of the last boot data */
+ if (!tscratch || !(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
+ return NULL;
+
+ /* *pos 0 is for the header, 1 is for the first module */
+ index--;
+
+ if (index >= tscratch->nr_entries)
+ return NULL;
- seq_buf_init(&seq, buf, 64);
+ return &tscratch->entries[index];
+}
+
+static void *l_start(struct seq_file *m, loff_t *pos)
+{
+ mutex_lock(&scratch_mutex);
+
+ return l_next(m, NULL, pos);
+}
+
+static void l_stop(struct seq_file *m, void *p)
+{
+ mutex_unlock(&scratch_mutex);
+}
+
+static void show_last_boot_header(struct seq_file *m, struct trace_array *tr)
+{
+ struct trace_scratch *tscratch = tr->scratch;
/*
* Do not leak KASLR address. This only shows the KASLR address of
@@ -6900,11 +6936,52 @@ tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t
* should not be the same as the current boot.
*/
if (!tscratch || !(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
- seq_buf_puts(&seq, "Offset: current\n");
+ seq_puts(m, "Offset: current\n");
else
- seq_buf_printf(&seq, "Offset: %lx\n", tscratch->kaslr_addr);
+ seq_printf(m, "Offset: %lx\n", tscratch->kaslr_addr);
+}
- return simple_read_from_buffer(ubuf, cnt, ppos, buf, seq_buf_used(&seq));
+static int l_show(struct seq_file *m, void *v)
+{
+ struct trace_array *tr = m->private;
+ struct trace_mod_entry *entry = v;
+
+ if (v == LAST_BOOT_HEADER) {
+ show_last_boot_header(m, tr);
+ return 0;
+ }
+
+ seq_printf(m, "%lx %s\n", entry->mod_addr, entry->mod_name);
+ return 0;
+}
+
+static const struct seq_operations last_boot_seq_ops = {
+ .start = l_start,
+ .next = l_next,
+ .stop = l_stop,
+ .show = l_show,
+};
+
+static int tracing_last_boot_open(struct inode *inode, struct file *file)
+{
+ struct trace_array *tr = inode->i_private;
+ struct seq_file *m;
+ int ret;
+
+ ret = tracing_check_open_get_tr(tr);
+ if (ret)
+ return ret;
+
+ ret = seq_open(file, &last_boot_seq_ops);
+ if (ret) {
+ trace_array_put(tr);
+ return ret;
+ }
+
+ m = file->private_data;
+ m->private = tr;
+
+ return 0;
}
static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
@@ -7533,10 +7610,10 @@ static const struct file_operations trace_time_stamp_mode_fops = {
};
static const struct file_operations last_boot_fops = {
- .open = tracing_open_generic_tr,
- .read = tracing_last_boot_read,
- .llseek = generic_file_llseek,
- .release = tracing_release_generic_tr,
+ .open = tracing_last_boot_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = tracing_seq_release,
};
#ifdef CONFIG_TRACER_SNAPSHOT
--
2.45.2
next prev parent reply other threads:[~2025-02-05 22:50 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 ` Steven Rostedt [this message]
2025-02-07 1:51 ` [PATCH 7/8] tracing: Show module names and addresses of last boot 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
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=20250205225104.096389081@goodmis.org \
--to=rostedt@goodmis.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=mhiramat@kernel.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