* [PATCH 0/4] tracing: Have function tracing and events handle module addresses
@ 2025-03-04 23:15 Steven Rostedt
2025-03-04 23:15 ` [PATCH 1/4] tracing: Update function trace addresses with " Steven Rostedt
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Steven Rostedt @ 2025-03-04 23:15 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
This is based on top of Masami's patch:
https://lore.kernel.org/linux-trace-kernel/173886114516.496116.8314066678313037503.stgit@devnote2/
As it requires the function trace_adjust_address() for both kernel text
and modules.
This updates the function tracer as well as the pointers used in events
to be updated via the trace_adjust_address() function.
Steven Rostedt (4):
tracing: Update function trace addresses with module addresses
tracing: Show function names when possible when listing fields
tracing: Only return an adjusted address if it matches the kernel address
tracing: Adjust addresses for printing out fields
----
kernel/trace/trace.c | 5 ++++-
kernel/trace/trace_output.c | 46 +++++++++++++++++++++++++++++----------------
2 files changed, 34 insertions(+), 17 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/4] tracing: Update function trace addresses with module addresses
2025-03-04 23:15 [PATCH 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
@ 2025-03-04 23:15 ` Steven Rostedt
2025-03-04 23:15 ` [PATCH 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
2025-03-04 23:15 ` [PATCH 4/4] tracing: Adjust addresses for printing out fields Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2025-03-04 23:15 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: Steven Rostedt <rostedt@goodmis.org>
Now that module addresses are saved in the persistent ring buffer, their
addresses can be used to adjust the address in the persistent ring buffer
to the address of the module that is currently loaded.
Instead of blindly using the text_delta that only works for core kernel
code, call the trace_adjust_address() that will see if the address matches
an address saved in the persistent ring buffer, and then uses that against
the matching module if it is loaded.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace_output.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index a5336c4ece8e..5f3b698afc07 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -1005,10 +1005,10 @@ enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
}
static void print_fn_trace(struct trace_seq *s, unsigned long ip,
- unsigned long parent_ip, long delta, int flags)
+ unsigned long parent_ip, struct trace_array *tr, int flags)
{
- ip += delta;
- parent_ip += delta;
+ ip = trace_adjust_address(tr, ip);
+ parent_ip = trace_adjust_address(tr, parent_ip);
seq_print_ip_sym(s, ip, flags);
@@ -1027,7 +1027,7 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
trace_assign_type(field, iter->ent);
- print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, flags);
+ print_fn_trace(s, field->ip, field->parent_ip, iter->tr, flags);
trace_seq_putc(s, '\n');
return trace_handle_return(s);
@@ -1613,7 +1613,7 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter,
trace_assign_type(field, iter->ent);
- ip = field->ip + iter->tr->text_delta;
+ ip = trace_adjust_address(iter->tr, field->ip);
seq_print_ip_sym(s, ip, flags);
trace_seq_printf(s, ": %s", field->buf);
@@ -1699,7 +1699,7 @@ trace_func_repeats_print(struct trace_iterator *iter, int flags,
trace_assign_type(field, iter->ent);
- print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, flags);
+ print_fn_trace(s, field->ip, field->parent_ip, iter->tr, flags);
trace_seq_printf(s, " (repeats: %u, last_ts:", field->count);
trace_print_time(s, iter,
iter->ts - FUNC_REPEATS_GET_DELTA_TS(field));
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/4] tracing: Show function names when possible when listing fields
2025-03-04 23:15 [PATCH 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-04 23:15 ` [PATCH 1/4] tracing: Update function trace addresses with " Steven Rostedt
@ 2025-03-04 23:15 ` Steven Rostedt
2025-03-04 23:15 ` [PATCH 4/4] tracing: Adjust addresses for printing out fields Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2025-03-04 23:15 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: Steven Rostedt <rostedt@goodmis.org>
When the "fields" option is enabled, the "print fmt" of the trace event is
ignored and only the fields are printed. But some fields contain function
pointers. Instead of just showing the hex value in this case, show the
function name when possible:
Instead of having:
# echo 1 > options/fields
# cat trace
[..]
kmem_cache_free: call_site=0xffffffffa9afcf31 (-1448095951) ptr=0xffff888124452910 (-131386736039664) name=kmemleak_object
Have it output:
kmem_cache_free: call_site=rcu_do_batch+0x3d1/0x14a0 (-1768960207) ptr=0xffff888132ea5ed0 (854220496) name=kmemleak_object
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace_output.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 5f3b698afc07..3a43128e604a 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -934,14 +934,24 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
break;
}
- trace_seq_printf(&iter->seq, "0x%x (%d)",
- *(unsigned int *)pos,
- *(unsigned int *)pos);
+ if (sizeof(long) == 4)
+ trace_seq_printf(&iter->seq, "%pS (%d)",
+ *(void **)pos,
+ *(unsigned int *)pos);
+ else
+ trace_seq_printf(&iter->seq, "0x%x (%d)",
+ *(unsigned int *)pos,
+ *(unsigned int *)pos);
break;
case 8:
- trace_seq_printf(&iter->seq, "0x%llx (%lld)",
- *(unsigned long long *)pos,
- *(unsigned long long *)pos);
+ if (sizeof(long) == 8)
+ trace_seq_printf(&iter->seq, "%pS (%d)",
+ *(void **)pos,
+ *(unsigned long long *)pos);
+ else
+ trace_seq_printf(&iter->seq, "0x%llx (%lld)",
+ *(unsigned long long *)pos,
+ *(unsigned long long *)pos);
break;
default:
trace_seq_puts(&iter->seq, "<INVALID-SIZE>");
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/4] tracing: Adjust addresses for printing out fields
2025-03-04 23:15 [PATCH 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-04 23:15 ` [PATCH 1/4] tracing: Update function trace addresses with " Steven Rostedt
2025-03-04 23:15 ` [PATCH 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
@ 2025-03-04 23:15 ` Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2025-03-04 23:15 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: Steven Rostedt <rostedt@goodmis.org>
Add adjustments to the values of the "fields" output if the buffer is a
persistent ring buffer to adjust the addresses to both the kernel core and
kernel modules if they match a module in the persistent memory and that
module is also loaded.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace_output.c | 38 ++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 3a43128e604a..aa716cf69caa 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -857,6 +857,9 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
struct list_head *head)
{
struct ftrace_event_field *field;
+ struct trace_array *tr = iter->tr;
+ unsigned long long laddr;
+ unsigned long addr;
int offset;
int len;
int ret;
@@ -893,8 +896,8 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
case FILTER_PTR_STRING:
if (!iter->fmt_size)
trace_iter_expand_format(iter);
- pos = *(void **)pos;
- ret = strncpy_from_kernel_nofault(iter->fmt, pos,
+ addr = trace_adjust_address(tr, *(unsigned long *)pos);
+ ret = strncpy_from_kernel_nofault(iter->fmt, (void *)addr,
iter->fmt_size);
if (ret < 0)
trace_seq_printf(&iter->seq, "(0x%px)", pos);
@@ -903,8 +906,8 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
pos, iter->fmt);
break;
case FILTER_TRACE_FN:
- pos = *(void **)pos;
- trace_seq_printf(&iter->seq, "%pS", pos);
+ addr = trace_adjust_address(tr, *(unsigned long *)pos);
+ trace_seq_printf(&iter->seq, "%pS", (void *)addr);
break;
case FILTER_CPU:
case FILTER_OTHER:
@@ -934,24 +937,25 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
break;
}
- if (sizeof(long) == 4)
+ addr = *(unsigned int *)pos;
+ if (sizeof(long) == 4) {
+ addr = trace_adjust_address(tr, addr);
trace_seq_printf(&iter->seq, "%pS (%d)",
- *(void **)pos,
- *(unsigned int *)pos);
- else
+ (void *)addr, (int)addr);
+ } else {
trace_seq_printf(&iter->seq, "0x%x (%d)",
- *(unsigned int *)pos,
- *(unsigned int *)pos);
+ (unsigned int)addr, (int)addr);
+ }
break;
case 8:
- if (sizeof(long) == 8)
+ laddr = *(unsigned long long *)pos;
+ if (sizeof(long) == 8) {
+ laddr = trace_adjust_address(tr, (unsigned long)laddr);
trace_seq_printf(&iter->seq, "%pS (%d)",
- *(void **)pos,
- *(unsigned long long *)pos);
- else
- trace_seq_printf(&iter->seq, "0x%llx (%lld)",
- *(unsigned long long *)pos,
- *(unsigned long long *)pos);
+ (void *)laddr, laddr);
+ } else {
+ trace_seq_printf(&iter->seq, "0x%llx (%lld)", laddr, laddr);
+ }
break;
default:
trace_seq_puts(&iter->seq, "<INVALID-SIZE>");
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-04 23:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 23:15 [PATCH 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-04 23:15 ` [PATCH 1/4] tracing: Update function trace addresses with " Steven Rostedt
2025-03-04 23:15 ` [PATCH 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
2025-03-04 23:15 ` [PATCH 4/4] tracing: Adjust addresses for printing out fields Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox