From patchwork Tue Mar 4 23:15:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 14001622 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA201FAC4C; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; cv=none; b=U8ShUg608MvZuT9+8AzXq/CMS3e2sG8BBfXkW1LrEYmuWRRk1dF0AVSFO4xo9ql5ZmTrAlCJFnVW1pZHnDnzzyKK5o2epo9262OKrYKS/4/J3uqgt8djMxZ6xK7ZlaWGWQNHTChEoMT9Ta6JL7f08dR9p8CskKh6DVlsnfp+xkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; c=relaxed/simple; bh=Sc+tHgnrwcvbiAJXC4eaEryDgMZlPRgI9XOGIB2esok=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sc7o5eh/054ot9MGWQu2vs52WhoM/JyAHWBXKG73YP9Tkl8CK5tUblejI59blbPjDuAzLni+mEs9lkJ9HIYc2KJM0KmQMEtnbNb6H4LRigTUHNgH/a25qz4De3qSmTtvK4oVLQYMuDLN1tW+htT/oLOXADwo7t18xEX81BTltm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EE26C4CEE5; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tpbUo-0000000CSZP-12u6; Tue, 04 Mar 2025 18:16:18 -0500 Message-ID: <20250304231618.104482909@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Mar 2025 18:15:46 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 1/4] tracing: Update function trace addresses with module addresses References: <20250304231545.708806702@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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) --- 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)); From patchwork Tue Mar 4 23:15:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 14001623 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA721FBCB6; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; cv=none; b=ggTCX+Oi1L2EwQmEqL9f/B70kBXh0V7Fj8XrYk+9fM0ZVFG3n/9cg755NDLNBHrfG3N6OU9BnpvDEIDPLJ/hXgsq/VzGFPPYzJZLpVvL2DZ7cP9awk9HNKHjbmkNYvos8fYPuv5/Y7xRgEDZvu0So8GFpFuGgCLBaCycsw+1BsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; c=relaxed/simple; bh=V9gx0HsTlECxlQahRJQNVpXycuv4g24XdXLlhxz+4kg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=PDWgmxF5l8p4FYGHn7XkHsbmv0GVqA0PoCKfaiVutWJH0jNswkVclPkQ0gya/00Q+B5CC8Px31n3rvRHvdVhzvH2fBTMJAhhsqxKIq+WCtpwqm+egNaoxxXCrtObMT3Zp8lo585HpTNJeL7D0QxLN2O5B6x3ebPOTWDIF3urBiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78A8CC4CEEA; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tpbUo-0000000CSZv-1kvR; Tue, 04 Mar 2025 18:16:18 -0500 Message-ID: <20250304231618.270670190@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Mar 2025 18:15:47 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 2/4] tracing: Show function names when possible when listing fields References: <20250304231545.708806702@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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) --- 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, ""); From patchwork Tue Mar 4 23:15:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 14001621 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC9C81F8697; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; cv=none; b=ngciAZlNCn6BtCwxon1pY5aMDUxFVmVUUkgindJIttfbUAVlMjC3GzMcW+h/3NhD9AZkn5WiW/rUS+c+lgaAEK9z2qVgC0Kb8opOJBHMzk+QOtbZeCTu5QZmZxGb9nQ73dUMSK27dO6pvodRTmFVbAOsxOmvne0sTN/chVg14iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130122; c=relaxed/simple; bh=wC/IeTaVY4YGXDLvAUqyWXaYfQfr59gdDdHoBxGilKY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=XYuBQaXuc/tVOwRRYomfU2Q+vN8tyNDEMX8I3MfQdbkxIoojuzBo2HkXeBu1rpAIGMWKXKNgEbPagfPvx0bal+c064UFrSo8pYyWSOkWVpiuIKKH2ygcm3DT9G0hSM9g8dsRz+L7iBm5u/rIwnfU5iC07gGl6kT0cxcagKCGEb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1AEC4CEEC; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tpbUo-0000000CSaQ-2R1E; Tue, 04 Mar 2025 18:16:18 -0500 Message-ID: <20250304231618.438023367@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Mar 2025 18:15:48 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 3/4] tracing: Only return an adjusted address if it matches the kernel address References: <20250304231545.708806702@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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) --- kernel/trace/trace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c37dd3b6acb3..2ad2686f39f3 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6005,6 +6005,7 @@ static DEFINE_MUTEX(scratch_mutex); unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr) { struct trace_scratch *tscratch; + unsigned long raddr; int i; /* If we don't have last boot delta, return the address */ @@ -6020,7 +6021,9 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr) return addr + tr->module_delta[i - 1]; } - return addr + tr->text_delta; + raddr = addr + tr->text_delta; + return is_kernel_core_data(raddr) || is_kernel_rodata(raddr) || + __is_kernel(raddr) ? raddr : addr; } static int save_mod(struct module *mod, void *data) From patchwork Tue Mar 4 23:15:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 14001624 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6269927933B; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130123; cv=none; b=UTLuG4cYowytoR/lFBHFDU/RJoLE4r/ZzGuk75r5DrjbAXlZUHGLw/gGvW28uMp30oo9eoUKfIrVIJKNYBpbluLSxmKBucpCFdoOS4FLejHrqTqfZyQLIQTHYOcCVCBJmYHso11DGSVWK2tpnf7fyTSSUL5VKKi79BzoEpXYi9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741130123; c=relaxed/simple; bh=+QANBucFIezUoXX7P8kYb2sbC27r0CAnf9rNssJhRm8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=glULuwBFJfNPGixmY2d6hRY0Uv49nMVJY0Z05Pk4x44/QrI5Y9frbAtURH362JCoW+vSHErgPONV/DbPDL+zLD8F8QlZpvvXi9RIYvJR6pHQufOliHAp7qxmSikE8eg9b2eYu/0BsNl1IVhOr0MFay9DyzytPkDDZuozkLTNAFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5F07C4CEE8; Tue, 4 Mar 2025 23:15:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tpbUo-0000000CSau-39dy; Tue, 04 Mar 2025 18:16:18 -0500 Message-ID: <20250304231618.602571527@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Mar 2025 18:15:49 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 4/4] tracing: Adjust addresses for printing out fields References: <20250304231545.708806702@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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) --- 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, "");