* [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses
@ 2025-03-25 21:38 Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 1/4] tracing: Update function trace addresses with " Steven Rostedt
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-25 21:38 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/174282689201.356346.17647540360450727687.stgit@mhiramat.tok.corp.google.com/
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.
Changes since v1: https://lore.kernel.org/linux-trace-kernel/20250304231545.708806702@goodmis.org/
- Rebased on the latest code
- Some minor updates to the trace_adjust_address() to print original
address if not in kernel proper.
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 | 8 ++++++--
kernel/trace/trace_output.c | 46 +++++++++++++++++++++++++++++----------------
2 files changed, 36 insertions(+), 18 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/4] tracing: Update function trace addresses with module addresses
2025-03-25 21:38 [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
@ 2025-03-25 21:38 ` Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-25 21:38 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 1ad54fcf25cb..ca8e09436a0a 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -1006,10 +1006,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);
@@ -1028,7 +1028,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);
@@ -1614,7 +1614,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);
@@ -1700,7 +1700,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] 5+ messages in thread
* [PATCH v2 2/4] tracing: Show function names when possible when listing fields
2025-03-25 21:38 [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 1/4] tracing: Update function trace addresses with " Steven Rostedt
@ 2025-03-25 21:38 ` Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 3/4] tracing: Only return an adjusted address if it matches the kernel address Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 4/4] tracing: Adjust addresses for printing out fields Steven Rostedt
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-25 21:38 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 ca8e09436a0a..ef6307a6ca5e 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -935,14 +935,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 (%lld)",
+ *(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] 5+ messages in thread
* [PATCH v2 3/4] tracing: Only return an adjusted address if it matches the kernel address
2025-03-25 21:38 [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 1/4] tracing: Update function trace addresses with " Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
@ 2025-03-25 21:38 ` Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 4/4] tracing: Adjust addresses for printing out fields Steven Rostedt
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-25 21:38 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: Steven Rostedt <rostedt@goodmis.org>
The trace_adjust_address() will take a given address and examine the
persistent ring buffer to see if the address matches a module that is
listed there. If it does not, it will just adjust the value to the core
kernel delta. But if the address was for something that was not part of
the core kernel text or data it should not be adjusted.
Check the result of the adjustment and only return the adjustment if it
lands in the current kernel text or data. If not, return the original
address.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 7ca8a0dbd4fa..85128ef96246 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6023,6 +6023,7 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
struct trace_module_delta *module_delta;
struct trace_scratch *tscratch;
struct trace_mod_entry *entry;
+ unsigned long raddr;
int idx = 0, nr_entries;
/* If we don't have last boot delta, return the address */
@@ -6034,8 +6035,11 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
tscratch = tr->scratch;
/* if there is no tscrach, module_delta must be NULL. */
module_delta = READ_ONCE(tr->module_delta);
- if (!module_delta || tscratch->entries[0].mod_addr > addr)
- return addr + tr->text_delta;
+ if (!module_delta || tscratch->entries[0].mod_addr > addr) {
+ raddr = addr + tr->text_delta;
+ return is_kernel_core_data(raddr) || is_kernel_rodata(raddr) ||
+ __is_kernel(raddr) ? raddr : addr;
+ }
/* Note that entries must be sorted. */
nr_entries = tscratch->nr_entries;
--
2.47.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 4/4] tracing: Adjust addresses for printing out fields
2025-03-25 21:38 [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
` (2 preceding siblings ...)
2025-03-25 21:38 ` [PATCH v2 3/4] tracing: Only return an adjusted address if it matches the kernel address Steven Rostedt
@ 2025-03-25 21:38 ` Steven Rostedt
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-25 21:38 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 ef6307a6ca5e..f4bae713a99a 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -858,6 +858,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;
@@ -894,8 +897,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);
@@ -904,8 +907,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:
@@ -935,24 +938,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 (%lld)",
- *(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] 5+ messages in thread
end of thread, other threads:[~2025-03-25 21:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 21:38 [PATCH v2 0/4] tracing: Have function tracing and events handle module addresses Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 1/4] tracing: Update function trace addresses with " Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 2/4] tracing: Show function names when possible when listing fields Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 3/4] tracing: Only return an adjusted address if it matches the kernel address Steven Rostedt
2025-03-25 21:38 ` [PATCH v2 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;
as well as URLs for NNTP newsgroup(s).