From nobody Wed Dec 17 08:54:24 2025 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 C7324291881 for ; Fri, 9 May 2025 13:12:58 +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=1746796378; cv=none; b=o+SLphBlSLcphmujNBHYvY5usUJtP+YkLZjcitdAaL8dMdncYkydVCi0s07ErrdnFVfDHZGbpOM3uEJ8QQZvOSSfJ9eUEtdkUf0c+wBlJJC3fFwelWp3AXzorI+M2MDIXjoDHPoCYaPogMOSpolrNdNgzyHCFdp0oY8pZCY6oRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796378; c=relaxed/simple; bh=8rec8zMYyPtWG77kE1jVUaH5/n35o46IbwU7XIWi2r8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rSMSxfwtIfmrvZS2s5dYwKQO+q83EeFoIv/U6pyo2wJQbqr4XObWpW7jo2ljE5eIxcZ1YvUvfEM1ohQYfHK3jKOUNOpo/9/Wpxorywx1YN7OV3zzHF38VBHgHQze8vMcatpLBtA1LweRVEilLkdxVCAMVJgnaM3++JIIMxO+X38= 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 5CB27C4CEEE; Fri, 9 May 2025 13:12:58 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXN-00000002boI-36Ru; Fri, 09 May 2025 09:13:13 -0400 Message-ID: <20250509131313.599215203@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 01/31] tracing: Update function trace addresses with module addresses References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250506111648.5df7f3ec@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_output.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index b9ab06c99543..aab6816f0249 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1086,11 +1086,11 @@ enum print_line_t trace_nop_print(struct trace_iter= ator *iter, int flags, } =20 static void print_fn_trace(struct trace_seq *s, unsigned long ip, - unsigned long parent_ip, long delta, - unsigned long *args, int flags) + unsigned long parent_ip, unsigned long *args, + struct trace_array *tr, int flags) { - ip +=3D delta; - parent_ip +=3D delta; + ip =3D trace_adjust_address(tr, ip); + parent_ip =3D trace_adjust_address(tr, parent_ip); =20 seq_print_ip_sym(s, ip, flags); if (args) @@ -1119,8 +1119,7 @@ static enum print_line_t trace_fn_trace(struct trace_= iterator *iter, int flags, else args =3D NULL; =20 - print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, - args, flags); + print_fn_trace(s, field->ip, field->parent_ip, args, iter->tr, flags); trace_seq_putc(s, '\n'); =20 return trace_handle_return(s); @@ -1706,7 +1705,7 @@ static enum print_line_t trace_print_print(struct tra= ce_iterator *iter, =20 trace_assign_type(field, iter->ent); =20 - ip =3D field->ip + iter->tr->text_delta; + ip =3D trace_adjust_address(iter->tr, field->ip); =20 seq_print_ip_sym(s, ip, flags); trace_seq_printf(s, ": %s", field->buf); @@ -1792,7 +1791,7 @@ trace_func_repeats_print(struct trace_iterator *iter,= int flags, =20 trace_assign_type(field, iter->ent); =20 - print_fn_trace(s, field->ip, field->parent_ip, iter->tr->text_delta, NULL= , flags); + print_fn_trace(s, field->ip, field->parent_ip, NULL, 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)); --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 DE3F4291885 for ; Fri, 9 May 2025 13:12:58 +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=1746796378; cv=none; b=qz+Y2k065HvatpvojYKwt5NyH/fOJFJbc44HBllqrWy8eitvEz3DiMVg/HtLYcZMjspQDNvAXvoI7itvLy0k+lHvjURvR7BlXMV3IQ1s5Q1cFeDFjxcxaOff7hT/6yIYAflMBxwPAO3cK9Su8lHLIYtH5KX10C+rpOpYj7/m/m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796378; c=relaxed/simple; bh=80eGUuMKueuJ/ihAj2jSJbQh90YSw31csO4ocx/C2xQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=lojJuDq+FiX7sZyE6XpUruhFJeZAJ2ZXrcDxNpfA4T9FjjdLVpBbZTqzyB+EOem+rYbj5KvD+lqqJvWmp6ZnWol5NkfI9eL9kxjHqRfbZXrfRIDRACYTF4/n4m+ajUKpT7whm9+P+yvWpRf4pbNsXxX119KGcyCCmaIVQLE3Oj0= 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 6E106C4CEF0; Fri, 9 May 2025 13:12:58 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXN-00000002bom-3pDT; Fri, 09 May 2025 09:13:13 -0400 Message-ID: <20250509131313.761474477@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 02/31] tracing: Show function names when possible when listing fields References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D0xffffffffa9afcf31 (-1448095951) ptr=3D0xfff= f888124452910 (-131386736039664) name=3Dkmemleak_object Have it output: kmem_cache_free: call_site=3Drcu_do_batch+0x3d1/0x14a0 (-1768960207) ptr= =3D0xffff888132ea5ed0 (854220496) name=3Dkmemleak_object Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250325213919.624181915@goodmis.org 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 aab6816f0249..73037efdb45f 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1015,14 +1015,24 @@ static void print_fields(struct trace_iterator *ite= r, struct trace_event_call *c break; } =20 - trace_seq_printf(&iter->seq, "0x%x (%d)", - *(unsigned int *)pos, - *(unsigned int *)pos); + if (sizeof(long) =3D=3D 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) =3D=3D 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, ""); --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 01C77291896 for ; Fri, 9 May 2025 13:12:58 +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=1746796379; cv=none; b=TTd8KOwVy6XcM+fhTJ/l4QYNJWYFkDyiFRg59fPSkSNmtZm98i/nOlVIh5e6aXUmWaWKJa0+yhslnbknmQz/+PaSUEyNoaCW9bhIpvmNShOjIdRslmsnJ2eKjq+hRxwWX+8K+8Nji0Bkp1uFHDk0G0HPu5DMfnUNEjcU4vzpYZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=fG5VfAxDzNeQARtxqoK/2gXkOWqg2TdqudyazUO9QW8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BTTyvozEPEBsgbuTSFpDLoVap83f/AQJ4tP25ulJjKs/M4RxrTW6x9f8cjKuViPKEYynljpvhMxB8kMHJdRWI0iAj+h85xrBEZeLOMcA4H5qUYIl0pNYjE5kjfmbVXixDyAl2CpxrYVqZq3Cc6gdDoLvMdBlixCvtPA/mJxdtjs= 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 9C4A5C4CEEB; Fri, 9 May 2025 13:12:58 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002bpH-0Jto; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131313.932699225@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 03/31] tracing: Only return an adjusted address if it matches the kernel address References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250506102300.0ba2f9e0@gandalf.local.home 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 5b8db27fb6ef..01572ef79802 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6032,6 +6032,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 =3D 0, nr_entries; =20 /* If we don't have last boot delta, return the address */ @@ -6045,7 +6046,9 @@ unsigned long trace_adjust_address(struct trace_array= *tr, unsigned long addr) module_delta =3D READ_ONCE(tr->module_delta); if (!module_delta || !tscratch->nr_entries || tscratch->entries[0].mod_addr > addr) { - return addr + tr->text_delta; + raddr =3D addr + tr->text_delta; + return __is_kernel(raddr) || is_kernel_core_data(raddr) || + is_kernel_rodata(raddr) ? raddr : addr; } =20 /* Note that entries must be sorted. */ --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 48F672918D5 for ; Fri, 9 May 2025 13:12:58 +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=1746796379; cv=none; b=V+BNJUITRpiLPjeu3r2PEDJwhlWODiX2uxHW4VMiPQiCaGHNxYPCJSiu54nesC8BcEwvaWm6uRfmiWE3bG7bobgrISRSJRvRIl79COQbU7KBVH5RxTixFo4IyyxwTIWb94eXd2Rp8IotcRhnv3kXCsS/59O3NjdFNg19U9bL/N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=M6W2vb58uFOUcQ+8LnVusimQhoqu4ku91G803QbGz7A=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=iNxOw+89pFyG4rOVQ4F26FXpONDqAyEQgi7qtoz+8lmWcNt3C2FDrFhChbfoWh+viUfToeT1FAXTKek2T+A992iIcVsdpTri+3/IwMRaOS/dsMrK+J0Cc1q5JmmWFEV7cZIKzqGUf+N4SQPrWgKz4SabIXJhVJs8dzsOuqFudfI= 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 C562FC4CEF3; Fri, 9 May 2025 13:12:58 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002bpm-12z4; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.097898419@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 04/31] tracing: Adjust addresses for printing out fields References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Mark Rutland Cc: Andrew Morton Link: https://lore.kernel.org/20250325185619.54b85587@gandalf.local.home 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 73037efdb45f..e7ebad177679 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -938,6 +938,9 @@ static void print_fields(struct trace_iterator *iter, s= truct trace_event_call *c struct list_head *head) { struct ftrace_event_field *field; + struct trace_array *tr =3D iter->tr; + unsigned long long laddr; + unsigned long addr; int offset; int len; int ret; @@ -974,8 +977,8 @@ static void print_fields(struct trace_iterator *iter, s= truct trace_event_call *c case FILTER_PTR_STRING: if (!iter->fmt_size) trace_iter_expand_format(iter); - pos =3D *(void **)pos; - ret =3D strncpy_from_kernel_nofault(iter->fmt, pos, + addr =3D trace_adjust_address(tr, *(unsigned long *)pos); + ret =3D strncpy_from_kernel_nofault(iter->fmt, (void *)addr, iter->fmt_size); if (ret < 0) trace_seq_printf(&iter->seq, "(0x%px)", pos); @@ -984,8 +987,8 @@ static void print_fields(struct trace_iterator *iter, s= truct trace_event_call *c pos, iter->fmt); break; case FILTER_TRACE_FN: - pos =3D *(void **)pos; - trace_seq_printf(&iter->seq, "%pS", pos); + addr =3D trace_adjust_address(tr, *(unsigned long *)pos); + trace_seq_printf(&iter->seq, "%pS", (void *)addr); break; case FILTER_CPU: case FILTER_OTHER: @@ -1015,24 +1018,25 @@ static void print_fields(struct trace_iterator *ite= r, struct trace_event_call *c break; } =20 - if (sizeof(long) =3D=3D 4) + addr =3D *(unsigned int *)pos; + if (sizeof(long) =3D=3D 4) { + addr =3D 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) =3D=3D 8) + laddr =3D *(unsigned long long *)pos; + if (sizeof(long) =3D=3D 8) { + laddr =3D 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 *)(long)laddr, laddr); + } else { + trace_seq_printf(&iter->seq, "0x%llx (%lld)", laddr, laddr); + } break; default: trace_seq_puts(&iter->seq, ""); --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 0C80429189A for ; Fri, 9 May 2025 13:12:59 +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=1746796379; cv=none; b=WWgG8Wupf20StORJco72WaDx4ilvXyojq34wGhCQZ+we392eRvXSIXUWB7oRvKLzplzHoTpQsW/Bi9hpTV/cE5rWQvO7twdunPOkUN8yxm9DEbxVk0C8MBkPKUyLzCIJvRCzOfOcVSvUMh8pVcniAhZcVDICIWigpmcRJhOluEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=HituxbUAVh1vLtMD8XS8+Wr9KmT3hEqvbhv7vTTM2A0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cbCLHLvpILkSpMUhDNrRxFObXj+04K8fBUgwbcBGbPe7To5SelNj+SrbhBRcKfRM19w0TNiBpRc7wzZV0foXb1Uvo8Zf5qaPj97fXaCAzuiN93yjQb7oMyRXrM/xmG+WFisuMTlsvAv6zsOo7KjLls93vve+JeJGX5PVeRCSwcE= 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 E47B3C4CEE4; Fri, 9 May 2025 13:12:58 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002bqG-1lI8; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.271971264@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:54 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 05/31] tracing: Show preempt and irq events callsites from the offsets in field print References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt When the "fields" option is set in a trace instance, it ignores the "print = fmt" portion of the trace event and just prints the raw fields defined by the TP_STRUCT__entry() of the TRACE_EVENT() macro. The preempt_disable/enable and irq_disable/enable events record only the caller offset from _stext to save space in the ring buffer. Even though the "fields" option only prints the fields, it also tries to print what they represent too, which includes function names. Add a check in the output of the event field printing to see if the field name is "caller_offs" or "parent_offs" and then print the function at the offset from _stext of that field. Instead of just showing: irq_disable: caller_offs=3D0xba634d (12215117) parent_offs=3D0x39d10e2 (6= 0625122) Show: irq_disable: caller_offs=3Dtrace_hardirqs_off.part.0+0xad/0x130 0xba634d = (12215117) parent_offs=3D_raw_spin_lock_irqsave+0x62/0x70 0x39d10e2 (606251= 22) Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250506105131.4b6089a9@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_output.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index e7ebad177679..0b3db02030a7 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1019,6 +1019,17 @@ static void print_fields(struct trace_iterator *iter= , struct trace_event_call *c } =20 addr =3D *(unsigned int *)pos; + + /* Some fields reference offset from _stext. */ + if (!strcmp(field->name, "caller_offs") || + !strcmp(field->name, "parent_offs")) { + unsigned long ip; + + ip =3D addr + (unsigned long)_stext; + ip =3D trace_adjust_address(tr, ip); + trace_seq_printf(&iter->seq, "%pS ", (void *)ip); + } + if (sizeof(long) =3D=3D 4) { addr =3D trace_adjust_address(tr, addr); trace_seq_printf(&iter->seq, "%pS (%d)", --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 2F0A22918C9 for ; Fri, 9 May 2025 13:12:59 +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=1746796379; cv=none; b=UCHG9AQVvKsPhlPT/+SAKFze4uviicBEhyTSxdULI40bEEdLcxpPoEUgbWmTqX/W7u4WD1UP7wE3lKsMBQbQDpPdbPNU1RN8jiWbhF7Ye2HIC+y6UzW7KhfDEzttjKDvp5KOaqe/BibduufQXk+w3Z9U6+0MefOkhDDE/ADDxdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=7em6pxWBPfhqwKqZ7y3TDw5C478HqI15eUEpPFij0Xs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hJx/UF/V1rwHzhiPMbnBsOrAuD2RZRqBt1gGStivgVY01hYFYY+iTMxF6/P1idQC9nc+d09GdHQMqRkL+M6QEtqpPkVmINjNQt/8CQJXqWhkL2UnEf3LiTAbwgP0HZfHpAfWhqhOtzKOLlSHkESiUSnMfPtNDuRA7ynQnzZEE9U= 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 145FDC4CEEE; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002bqk-2T8c; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.441795527@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:55 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Kees Cook , Tom Zanussi Subject: [for-next][PATCH 06/31] tracing: Always use memcpy() in histogram add_to_key() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The add_to_key() function tests if the key is a string or some data. If it's a string it does some further calculations of the string size (still truncating it to the max size it can be), and calls strncpy(). If the key isn't as string it calls memcpy(). The interesting point is that both use the exact same parameters: strncpy(compound_key + key_field->offset, (char *)key, size= ); } else memcpy(compound_key + key_field->offset, key, size); As strncpy() is being used simply as a memcpy() for a string, and since strncpy() is deprecated, just call memcpy() for both memory and string keys. Cc: Mathieu Desnoyers Cc: Kees Cook Link: https://lore.kernel.org/20250403210637.1c477d4a@gandalf.local.home Acked-by: Masami Hiramatsu (Google) Reviewed-by: Tom Zanussi Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index 1260c23cfa5f..e139b58c3a43 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -5224,10 +5224,8 @@ static inline void add_to_key(char *compound_key, vo= id *key, /* ensure NULL-termination */ if (size > key_field->size - 1) size =3D key_field->size - 1; - - strncpy(compound_key + key_field->offset, (char *)key, size); - } else - memcpy(compound_key + key_field->offset, key, size); + } + memcpy(compound_key + key_field->offset, key, size); } =20 static void --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 704AF2918E9 for ; Fri, 9 May 2025 13:12:59 +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=1746796379; cv=none; b=QQ/iJZQUq7eCfoA9jchNSkEHvJ71cKHciwyxd+Z/gcXd+a/SBAQTm7mEce6Eiu/so0f8QreUF7fwRT+kNEHTX0Ur4+SqoCpE10YwdbzWMfejCYIi2dsLbEuJJjmxAnauqxbDzhLAh/u5ml7rRcYPbAoXhp5ekpZ86l//UYpnemk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=1dqt/iLrVzdZmcZj4RDI7tkfapBy+unWQnbgexFvsAs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HH/WzqQ5WtoR1w3ZgGdz71FcwtOmpwT9cMmSjXxvzcloYH6Egyp76x8y9LcCfEs2yjRMRIDpcNTyObF9+V7P6/0L+GN9urxEp7sejD5wH5EbqwlKxy3ZI6R7cEwb9QrHdepvTcooZcTkiYqg+a4n2SrTyFx+Hwu2URfRmYc3RJs= 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 50E3AC4CEF1; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002brF-3BQ3; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.611110671@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:56 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi Subject: [for-next][PATCH 07/31] tracing: Move histogram trigger variables from stack to per CPU structure References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The histogram trigger has three somewhat large arrays on the kernel stack: unsigned long entries[HIST_STACKTRACE_DEPTH]; u64 var_ref_vals[TRACING_MAP_VARS_MAX]; char compound_key[HIST_KEY_SIZE_MAX]; Checking the function event_hist_trigger() stack frame size, it currently uses 816 bytes for its stack frame due to these variables! Instead, allocate a per CPU structure that holds these arrays for each context level (normal, softirq, irq and NMI). That is, each CPU will have 4 of these structures. This will be allocated when the first histogram trigger is enabled and freed when the last is disabled. When the histogram callback triggers, it will request this structure. The request will disable preemption, get the per CPU structure at the index of the per CPU variable, and increment that variable. The callback will use the arrays in this structure to perform its work and then release the structure. That in turn will simply decrement the per CPU index and enable preemption. Moving the variables from the kernel stack to the per CPU structure brings the stack frame of event_hist_trigger() down to just 112 bytes. Cc: Mathieu Desnoyers Cc: Tom Zanussi Link: https://lore.kernel.org/20250407123851.74ea8d58@gandalf.local.home Fixes: 067fe038e70f6 ("tracing: Add variable reference handling to hist tri= ggers") Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 120 +++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 15 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index e139b58c3a43..e85bc59c0421 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -5244,17 +5244,94 @@ hist_trigger_actions(struct hist_trigger_data *hist= _data, } } =20 +/* + * The hist_pad structure is used to save information to create + * a histogram from the histogram trigger. It's too big to store + * on the stack, so when the histogram trigger is initialized + * a percpu array of 4 hist_pad structures is allocated. + * This will cover every context from normal, softirq, irq and NMI + * in the very unlikely event that a tigger happens at each of + * these contexts and interrupts a currently active trigger. + */ +struct hist_pad { + unsigned long entries[HIST_STACKTRACE_DEPTH]; + u64 var_ref_vals[TRACING_MAP_VARS_MAX]; + char compound_key[HIST_KEY_SIZE_MAX]; +}; + +static struct hist_pad __percpu *hist_pads; +static DEFINE_PER_CPU(int, hist_pad_cnt); +static refcount_t hist_pad_ref; + +/* One hist_pad for every context (normal, softirq, irq, NMI) */ +#define MAX_HIST_CNT 4 + +static int alloc_hist_pad(void) +{ + lockdep_assert_held(&event_mutex); + + if (refcount_read(&hist_pad_ref)) { + refcount_inc(&hist_pad_ref); + return 0; + } + + hist_pads =3D __alloc_percpu(sizeof(struct hist_pad) * MAX_HIST_CNT, + __alignof__(struct hist_pad)); + if (!hist_pads) + return -ENOMEM; + + refcount_set(&hist_pad_ref, 1); + return 0; +} + +static void free_hist_pad(void) +{ + lockdep_assert_held(&event_mutex); + + if (!refcount_dec_and_test(&hist_pad_ref)) + return; + + free_percpu(hist_pads); + hist_pads =3D NULL; +} + +static struct hist_pad *get_hist_pad(void) +{ + struct hist_pad *hist_pad; + int cnt; + + if (WARN_ON_ONCE(!hist_pads)) + return NULL; + + preempt_disable(); + + hist_pad =3D per_cpu_ptr(hist_pads, smp_processor_id()); + + if (this_cpu_read(hist_pad_cnt) =3D=3D MAX_HIST_CNT) { + preempt_enable(); + return NULL; + } + + cnt =3D this_cpu_inc_return(hist_pad_cnt) - 1; + + return &hist_pad[cnt]; +} + +static void put_hist_pad(void) +{ + this_cpu_dec(hist_pad_cnt); + preempt_enable(); +} + static void event_hist_trigger(struct event_trigger_data *data, struct trace_buffer *buffer, void *rec, struct ring_buffer_event *rbe) { struct hist_trigger_data *hist_data =3D data->private_data; bool use_compound_key =3D (hist_data->n_keys > 1); - unsigned long entries[HIST_STACKTRACE_DEPTH]; - u64 var_ref_vals[TRACING_MAP_VARS_MAX]; - char compound_key[HIST_KEY_SIZE_MAX]; struct tracing_map_elt *elt =3D NULL; struct hist_field *key_field; + struct hist_pad *hist_pad; u64 field_contents; void *key =3D NULL; unsigned int i; @@ -5262,12 +5339,18 @@ static void event_hist_trigger(struct event_trigger= _data *data, if (unlikely(!rbe)) return; =20 - memset(compound_key, 0, hist_data->key_size); + hist_pad =3D get_hist_pad(); + if (!hist_pad) + return; + + memset(hist_pad->compound_key, 0, hist_data->key_size); =20 for_each_hist_key_field(i, hist_data) { key_field =3D hist_data->fields[i]; =20 if (key_field->flags & HIST_FIELD_FL_STACKTRACE) { + unsigned long *entries =3D hist_pad->entries; + memset(entries, 0, HIST_STACKTRACE_SIZE); if (key_field->field) { unsigned long *stack, n_entries; @@ -5291,26 +5374,31 @@ static void event_hist_trigger(struct event_trigger= _data *data, } =20 if (use_compound_key) - add_to_key(compound_key, key, key_field, rec); + add_to_key(hist_pad->compound_key, key, key_field, rec); } =20 if (use_compound_key) - key =3D compound_key; + key =3D hist_pad->compound_key; =20 if (hist_data->n_var_refs && - !resolve_var_refs(hist_data, key, var_ref_vals, false)) - return; + !resolve_var_refs(hist_data, key, hist_pad->var_ref_vals, false)) + goto out; =20 elt =3D tracing_map_insert(hist_data->map, key); if (!elt) - return; + goto out; =20 - hist_trigger_elt_update(hist_data, elt, buffer, rec, rbe, var_ref_vals); + hist_trigger_elt_update(hist_data, elt, buffer, rec, rbe, hist_pad->var_r= ef_vals); =20 - if (resolve_var_refs(hist_data, key, var_ref_vals, true)) - hist_trigger_actions(hist_data, elt, buffer, rec, rbe, key, var_ref_vals= ); + if (resolve_var_refs(hist_data, key, hist_pad->var_ref_vals, true)) { + hist_trigger_actions(hist_data, elt, buffer, rec, rbe, + key, hist_pad->var_ref_vals); + } =20 hist_poll_wakeup(); + + out: + put_hist_pad(); } =20 static void hist_trigger_stacktrace_print(struct seq_file *m, @@ -6155,6 +6243,9 @@ static int event_hist_trigger_init(struct event_trigg= er_data *data) { struct hist_trigger_data *hist_data =3D data->private_data; =20 + if (alloc_hist_pad() < 0) + return -ENOMEM; + if (!data->ref && hist_data->attrs->name) save_named_trigger(hist_data->attrs->name, data); =20 @@ -6199,6 +6290,7 @@ static void event_hist_trigger_free(struct event_trig= ger_data *data) =20 destroy_hist_data(hist_data); } + free_hist_pad(); } =20 static const struct event_trigger_ops event_hist_trigger_ops =3D { @@ -6214,9 +6306,7 @@ static int event_hist_trigger_named_init(struct event= _trigger_data *data) =20 save_named_trigger(data->named_data->name, data); =20 - event_hist_trigger_init(data->named_data); - - return 0; + return event_hist_trigger_init(data->named_data); } =20 static void event_hist_trigger_named_free(struct event_trigger_data *data) --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 10AFB292099 for ; Fri, 9 May 2025 13:12:59 +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=1746796380; cv=none; b=bY+xbXT4PmaMdf36Dyia1Db6pEdYTcu9DuHB4ObePNYw48kgMZuHwyHJLtn1289PVkfnHkhadjGzk69weZ9/jOADUI6jrvYZ8PceogTbHEL/jluDBbK0UviTtuEc551d+4nNCT1s2yqvE6OlTUm+WFCUmVKr9ocOvfnsT8cmDto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=aB5ChLg+sd/ahTtsLC+FEEEjtrIaTPRnuGFbw2aQwIw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Jn0BpHZgDR3SWX3QHqPps8IoRXPy1XqKjp/7Nb3uVuuWHnJ4MSVeocTvtW+8dtprvLbFpZXFq1EQYisuHpUvqyEsgYigTzDXK2fir1/tSsFwB/I7FVH3yjZfcLLeskZz/dsYB6m7PvMiM5aSlEur4uw3vX40vNQOpvVCe55xqpo= 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 63C21C4AF0B; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXO-00000002brl-3t2b; Fri, 09 May 2025 09:13:14 -0400 Message-ID: <20250509131314.779021770@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi Subject: [for-next][PATCH 08/31] tracing: Add common_comm to histograms References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt If one wants to trace the name of the task that wakes up a process and pass that to the synthetic events, there's nothing currently that lets the synthetic events do that. Add a "common_comm" to the histogram logic that allows histograms save the current->comm as a variable that can be passed through and added to a synthetic event: # cd /sys/kernel/tracing # echo 's:wake_lat char[] waker; char[] wakee; u64 delta;' >> dynamic_even= ts # echo 'hist:keys=3Dpid:comm=3Dcommon_comm:ts=3Dcommon_timestamp.usecs if = !(common_flags & 0x18)' > events/sched/sched_waking/trigger # echo 'hist:keys=3Dnext_pid:wake_comm=3D$comm:delta=3Dcommon_timestamp.us= ecs-$ts:onmatch(sched.sched_waking).trace(wake_lat,$wake_comm,next_comm,$de= lta)' > events/sched/sched_switch/trigger The above will create a synthetic trace event that will save both the name of the waker and the wakee but only if the wakeup did not happen in a hard or soft interrupt context. The "common_comm" is used to save the task->comm at the time of the initial event and is passed via the "comm" variable to the second event, and that is saved as the "waker" field in the "wake_lat" synthetic event. Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250407154912.3c6c6246@gandalf.local.home Acked-by: Masami Hiramatsu (Google) Reviewed-by: Tom Zanussi Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 51 ++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index e85bc59c0421..58c9535f61df 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -114,6 +114,7 @@ enum hist_field_fn { HIST_FIELD_FN_BUCKET, HIST_FIELD_FN_TIMESTAMP, HIST_FIELD_FN_CPU, + HIST_FIELD_FN_COMM, HIST_FIELD_FN_STRING, HIST_FIELD_FN_DYNSTRING, HIST_FIELD_FN_RELDYNSTRING, @@ -506,6 +507,7 @@ enum hist_field_flags { HIST_FIELD_FL_CONST =3D 1 << 18, HIST_FIELD_FL_PERCENT =3D 1 << 19, HIST_FIELD_FL_GRAPH =3D 1 << 20, + HIST_FIELD_FL_COMM =3D 1 << 21, }; =20 struct var_defs { @@ -885,6 +887,15 @@ static u64 hist_field_cpu(struct hist_field *hist_fiel= d, return cpu; } =20 +static u64 hist_field_comm(struct hist_field *hist_field, + struct tracing_map_elt *elt, + struct trace_buffer *buffer, + struct ring_buffer_event *rbe, + void *event) +{ + return (u64)(unsigned long)current->comm; +} + /** * check_field_for_var_ref - Check if a VAR_REF field references a variable * @hist_field: The VAR_REF field to check @@ -1338,6 +1349,8 @@ static const char *hist_field_name(struct hist_field = *field, field_name =3D hist_field_name(field->operands[0], ++level); else if (field->flags & HIST_FIELD_FL_CPU) field_name =3D "common_cpu"; + else if (field->flags & HIST_FIELD_FL_COMM) + field_name =3D "common_comm"; else if (field->flags & HIST_FIELD_FL_EXPR || field->flags & HIST_FIELD_FL_VAR_REF) { if (field->system) { @@ -2015,6 +2028,13 @@ static struct hist_field *create_hist_field(struct h= ist_trigger_data *hist_data, goto out; } =20 + if (flags & HIST_FIELD_FL_COMM) { + hist_field->fn_num =3D HIST_FIELD_FN_COMM; + hist_field->size =3D MAX_FILTER_STR_VAL; + hist_field->type =3D "char[]"; + goto out; + } + if (WARN_ON_ONCE(!field)) goto out; =20 @@ -2359,9 +2379,11 @@ parse_field(struct hist_trigger_data *hist_data, str= uct trace_event_file *file, hist_data->attrs->ts_in_usecs =3D true; } else if (strcmp(field_name, "common_stacktrace") =3D=3D 0) { *flags |=3D HIST_FIELD_FL_STACKTRACE; - } else if (strcmp(field_name, "common_cpu") =3D=3D 0) + } else if (strcmp(field_name, "common_cpu") =3D=3D 0) { *flags |=3D HIST_FIELD_FL_CPU; - else if (strcmp(field_name, "hitcount") =3D=3D 0) + } else if (strcmp(field_name, "common_comm") =3D=3D 0) { + *flags |=3D HIST_FIELD_FL_COMM | HIST_FIELD_FL_STRING; + } else if (strcmp(field_name, "hitcount") =3D=3D 0) *flags |=3D HIST_FIELD_FL_HITCOUNT; else { field =3D trace_find_event_field(file->event_call, field_name); @@ -2377,6 +2399,8 @@ parse_field(struct hist_trigger_data *hist_data, stru= ct trace_event_file *file, *flags |=3D HIST_FIELD_FL_CPU; } else if (field && field->filter_type =3D=3D FILTER_STACKTRACE) { *flags |=3D HIST_FIELD_FL_STACKTRACE; + } else if (field && field->filter_type =3D=3D FILTER_COMM) { + *flags |=3D HIST_FIELD_FL_COMM | HIST_FIELD_FL_STRING; } else { hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, errpos(field_name)); @@ -4327,6 +4351,8 @@ static u64 hist_fn_call(struct hist_field *hist_field, return hist_field_timestamp(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_CPU: return hist_field_cpu(hist_field, elt, buffer, rbe, event); + case HIST_FIELD_FN_COMM: + return hist_field_comm(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_STRING: return hist_field_string(hist_field, elt, buffer, rbe, event); case HIST_FIELD_FN_DYNSTRING: @@ -5212,14 +5238,19 @@ static inline void add_to_key(char *compound_key, v= oid *key, size_t size =3D key_field->size; =20 if (key_field->flags & HIST_FIELD_FL_STRING) { - struct ftrace_event_field *field; =20 - field =3D key_field->field; - if (field->filter_type =3D=3D FILTER_DYN_STRING || - field->filter_type =3D=3D FILTER_RDYN_STRING) - size =3D *(u32 *)(rec + field->offset) >> 16; - else if (field->filter_type =3D=3D FILTER_STATIC_STRING) - size =3D field->size; + if (key_field->flags & HIST_FIELD_FL_COMM) { + size =3D strlen((char *)key); + } else { + struct ftrace_event_field *field; + + field =3D key_field->field; + if (field->filter_type =3D=3D FILTER_DYN_STRING || + field->filter_type =3D=3D FILTER_RDYN_STRING) + size =3D *(u32 *)(rec + field->offset) >> 16; + else if (field->filter_type =3D=3D FILTER_STATIC_STRING) + size =3D field->size; + } =20 /* ensure NULL-termination */ if (size > key_field->size - 1) @@ -6097,6 +6128,8 @@ static void hist_field_print(struct seq_file *m, stru= ct hist_field *hist_field) =20 if (hist_field->flags & HIST_FIELD_FL_CPU) seq_puts(m, "common_cpu"); + if (hist_field->flags & HIST_FIELD_FL_COMM) + seq_puts(m, "common_comm"); else if (hist_field->flags & HIST_FIELD_FL_CONST) seq_printf(m, "%llu", hist_field->constant); else if (field_name) { --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 A46612918FE for ; Fri, 9 May 2025 13:12:59 +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=1746796379; cv=none; b=W0qLhBDUQM0aAiHOayjUmbSIvf3Umlx6RbDsYtyssEAGHrFU09D8vtowXugu4LfpwwvHbA/RmH4jtktrEm78Ef+/Xeqhjg62C9e4CJx4R8GafVOaCk3pYRQLXHfqIE3dx9jpE6zIjYV0lKppnLhI0QSseXfZNvyYHoOCAOcAolw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=6O9ZY+vRjaugem8TgG5YHfcqQ/Puh0suiIv1HEG/R7g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=GjRZrMidcE6VTQLubgKKgvYDShVMz+sUXmBd628k+uf1HLTpUTtmLEXX6/ZTFS6sSgp1R4jVADIiOEWqx8Rty4ikTGL5k557PpQCSdcKOJnV4mzrpZ/Mha+cWChNAY58u/BZsmcnY17aFW7dQd/bprlRCTG5q1HNA+JFoUh4uA8= 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 8E761C4CEF0; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002bsF-0Pdd; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131314.948496900@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:58 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 09/31] ftrace: Show subops in enabled_functions References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The function graph infrastructure uses subops of the function tracer. These are not shown in enabled_functions. Add a "subops:" section to the enabled_functions line to show what functions are attached via subops. If the subops is from the function_graph infrastructure, then show the entry and return callbacks that are attached. Here's an example of the output: schedule_on_each_cpu (1) tramp: 0xffffffffc03ef000 (ftrace_g= raph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60 subops: {ent:trace_gra= ph_entry+0x0/0x20 ret:trace_graph_return+0x0/0x150} Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250410153830.5d97f108@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- include/linux/ftrace.h | 2 ++ kernel/trace/fgraph.c | 2 ++ kernel/trace/ftrace.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index fbabc3d848b3..fc939ca2ff66 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -328,6 +328,7 @@ ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *op= s); * DIRECT - Used by the direct ftrace_ops helper for direct functions * (internal ftrace only, should not be used by others) * SUBOP - Is controlled by another op in field managed. + * GRAPH - Is a component of the fgraph_ops structure */ enum { FTRACE_OPS_FL_ENABLED =3D BIT(0), @@ -349,6 +350,7 @@ enum { FTRACE_OPS_FL_PERMANENT =3D BIT(16), FTRACE_OPS_FL_DIRECT =3D BIT(17), FTRACE_OPS_FL_SUBOP =3D BIT(18), + FTRACE_OPS_FL_GRAPH =3D BIT(19), }; =20 #ifndef CONFIG_DYNAMIC_FTRACE_WITH_ARGS diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 8d925cbdce3a..c5b207992fb4 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1382,6 +1382,8 @@ int register_ftrace_graph(struct fgraph_ops *gops) /* Always save the function, and reset at unregistering */ gops->saved_func =3D gops->entryfunc; =20 + gops->ops.flags |=3D FTRACE_OPS_FL_GRAPH; + ret =3D ftrace_startup_subops(&graph_ops, &gops->ops, command); if (!ret) fgraph_array[i] =3D gops; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 6981830c3128..014cd2cedae3 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4373,6 +4373,42 @@ static inline int print_rec(struct seq_file *m, unsi= gned long ip) } #endif =20 +static void print_subops(struct seq_file *m, struct ftrace_ops *ops, struc= t dyn_ftrace *rec) +{ + struct ftrace_ops *subops; + bool first =3D true; + + list_for_each_entry(subops, &ops->subop_list, list) { + if (!((subops->flags & FTRACE_OPS_FL_ENABLED) && + hash_contains_ip(rec->ip, subops->func_hash))) + continue; + if (first) { + seq_printf(m, "\tsubops:"); + first =3D false; + } +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + if (subops->flags & FTRACE_OPS_FL_GRAPH) { + struct fgraph_ops *gops; + + gops =3D container_of(subops, struct fgraph_ops, ops); + seq_printf(m, " {ent:%pS ret:%pS}", + (void *)gops->entryfunc, + (void *)gops->retfunc); + continue; + } +#endif + if (subops->trampoline) { + seq_printf(m, " {%pS (%pS)}", + (void *)subops->trampoline, + (void *)subops->func); + add_trampoline_func(m, subops, rec); + } else { + seq_printf(m, " {%pS}", + (void *)subops->func); + } + } +} + static int t_show(struct seq_file *m, void *v) { struct ftrace_iterator *iter =3D m->private; @@ -4425,6 +4461,7 @@ static int t_show(struct seq_file *m, void *v) (void *)ops->trampoline, (void *)ops->func); add_trampoline_func(m, ops, rec); + print_subops(m, ops, rec); ops =3D ftrace_find_tramp_ops_next(rec, ops); } while (ops); } else @@ -4437,6 +4474,7 @@ static int t_show(struct seq_file *m, void *v) if (ops) { seq_printf(m, "\tops: %pS (%pS)", ops, ops->func); + print_subops(m, ops, rec); } else { seq_puts(m, "\tops: ERROR!"); } --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 D629029188D for ; Fri, 9 May 2025 13:12:59 +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=1746796379; cv=none; b=h63BbaC3pjj0xpnGLXagiql5ZEebtLnu6ScWVZpknMNswE5C8Ak4VppRLU4HVcn4L2+I88Xv8W/2QYlwUo2Z5muQz5Xjnp4sOsGxxKsrXatit1DdS3rf9OxdB7olLvRq7owSrQCz7MRNzSLIY1ZvDxyENbxLKY5zP7QEdZrGD9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796379; c=relaxed/simple; bh=FySwLMTTHapApbkpXbk0tTrB6EUHbUQ9d5aoxVDHLMs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Jla3xLhd2uY9Hbmeqo7klcwHeCpKWlKCNC9U7RZXyhkYRdhPR5OsmceeIpPj4cMJ3WJzeGmw0qR8jfyulqKQqErf4C1cYSfXVCFiFZWq+aS+rpUsGMwdmcdEKXg2IsNUHUUord3XNDcbV4/R8NC3ombr+cbKvG9LN1A0hwzcpQg= 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 BB4D6C4CEEE; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002bsk-17f0; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131315.118353893@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:12:59 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Sven Schnelle , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Ilya Leoshkevich Subject: [for-next][PATCH 10/31] ftrace: Expose call graph depth as unsigned int References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich Depth is stored as int because the code uses negative values to break out of iterations. But what is recorded is always zero or positive. So expose it as unsigned int instead of int. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Sven Schnelle Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Link: https://lore.kernel.org/20250412221847.17310-3-iii@linux.ibm.com Signed-off-by: Ilya Leoshkevich Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_entries.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index 4ef4df6623a8..de294ae2c5c5 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h @@ -97,11 +97,11 @@ FTRACE_ENTRY_PACKED(fgraph_retaddr_entry, fgraph_retadd= r_ent_entry, F_STRUCT( __field_struct( struct fgraph_retaddr_ent, graph_ent ) __field_packed( unsigned long, graph_ent, func ) - __field_packed( int, graph_ent, depth ) + __field_packed( unsigned int, graph_ent, depth ) __field_packed( unsigned long, graph_ent, retaddr ) ), =20 - F_printk("--> %ps (%d) <- %ps", (void *)__entry->func, __entry->depth, + F_printk("--> %ps (%u) <- %ps", (void *)__entry->func, __entry->depth, (void *)__entry->retaddr) ); =20 @@ -124,13 +124,13 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_= entry, __field_struct( struct ftrace_graph_ret, ret ) __field_packed( unsigned long, ret, func ) __field_packed( unsigned long, ret, retval ) - __field_packed( int, ret, depth ) + __field_packed( unsigned int, ret, depth ) __field_packed( unsigned int, ret, overrun ) __field(unsigned long long, calltime ) __field(unsigned long long, rettime ) ), =20 - F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d retval: %lx", + F_printk("<-- %ps (%u) (start: %llx end: %llx) over: %u retval: %lx", (void *)__entry->func, __entry->depth, __entry->calltime, __entry->rettime, __entry->depth, __entry->retval) @@ -146,13 +146,13 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_= entry, F_STRUCT( __field_struct( struct ftrace_graph_ret, ret ) __field_packed( unsigned long, ret, func ) - __field_packed( int, ret, depth ) + __field_packed( unsigned int, ret, depth ) __field_packed( unsigned int, ret, overrun ) __field(unsigned long long, calltime ) __field(unsigned long long, rettime ) ), =20 - F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d", + F_printk("<-- %ps (%u) (start: %llx end: %llx) over: %u", (void *)__entry->func, __entry->depth, __entry->calltime, __entry->rettime, __entry->depth) --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 08B5C292092 for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=W9F7PBGbQUbTv9fTYUFE/6E6VBb/dqYQNMI45dlI6H0PnH7ftHS7guSRd1Romv8bjRW/vjPA9QF6xEFbXFsjOcxfhDCWSFoD+PuJ1ZQDsjbkac4eLUl7zgxrk8w8XEGwcKG2rwOJlWBDOXrsEIhZ2bwx8lvL3oQ7RAZYnQdhLAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=wJ9ipE6e2LkBVZBuk9cIGc5UX7gHXqIZ5mEVNHd9v7s=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rIFm3VqVDRn8qKzPgeI29NFYJAr69ubi8RTio9vlm9eNyWO1PfDnHdSm5yhIynNmJtBsGe/zRuXy2it9XqbcOOtrCMlEVd3KquGDbWPeXgwJAYpuEsJJehef2TCjqwWk4FGzDtgKvM4yFRVAHBQfLho3JoCzF4eI+DNKdjYArfY= 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 E3D3EC4CEF1; Fri, 9 May 2025 13:12:59 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002btH-1q1L; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131315.289970442@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:00 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 11/31] ftrace: Comment that ftrace_func_mapper is freed with free_ftrace_hash() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The structure ftrace_func_mapper only contains a single field and that is a ftrace_hash. It is used to abstract it out from a normal hash to control users of how it gets modified. The freeing of a ftrace_func_mapper structure is: free_ftrace_hash(&mapper->hash); Without context, this looks like a bug. It should be commented that it is not a bug and it is freed this way. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Mark Rutland Link: https://lore.kernel.org/20250416165420.5c717420@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 014cd2cedae3..1af952cba48d 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5208,8 +5208,12 @@ struct ftrace_func_map { void *data; }; =20 +/* + * Note, ftrace_func_mapper is freed by free_ftrace_hash(&mapper->hash). + * The hash field must be the first field. + */ struct ftrace_func_mapper { - struct ftrace_hash hash; + struct ftrace_hash hash; /* Must be first! */ }; =20 /** @@ -5344,6 +5348,7 @@ void free_ftrace_func_mapper(struct ftrace_func_mappe= r *mapper, } } } + /* This also frees the mapper itself */ free_ftrace_hash(&mapper->hash); } =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 4904A2920AE for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=Wlx4PTka3Eq5TPjudJ5qegit1/P+tQFmtqoD1f2O31mBrHefHE9QJpxVWTVu5BcKMctHFEtBYUPko7gRvZ1uUX3GRBY31ItPcBw0bzzy1jmwSYFOjEAjpXXDlBkZ9+3dR7WGWXm2mPEuOT2D6T5QQ/zkLCaOk9d3L9JfN4FQEr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=2xgcDWQ1Wm6asJEBC/4gPWKZccRqj0GwASpqR3U/o7Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=b4j8XH2/XhHh3QF+pQhKEtrTZsYciREMVxdnswqG+5mxPWfbXUP3ZQWtAygdyE86mne6uXWWpynUerziB6wpW2yeWNgjnWzIBDrYdprJRcGYgKP44t3h9O+faPbQUTdwO3vtqzuzM7qKG66ZUhrXzlJbI5yNqD3o+2qnhYv5f00= 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 2F7ABC4CEF1; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002btm-2XWq; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131315.459424785@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:01 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tomas Glozar Subject: [for-next][PATCH 12/31] tracing/osnoise: Allow arbitrarily long CPU string References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tomas Glozar Allocate kernel memory for processing CPU string (/sys/kernel/tracing/osnoise/cpus) also in osnoise_cpus_write to allow the writing of a CPU string of an arbitrary length. This replaces the 256-byte buffer, which is insufficient with the rising number of CPUs. For example, if I wanted to measure on every even CPU on a system with 256 CPUs, the string would be 456 characters long. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250425091839.343289-1-tglozar@redhat.com Signed-off-by: Tomas Glozar Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index e732c9e37e14..6819b93309ce 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2302,7 +2302,7 @@ osnoise_cpus_read(struct file *filp, char __user *ubu= f, size_t count, * osnoise_cpus_write - Write function for "cpus" entry * @filp: The active open file structure * @ubuf: The user buffer that contains the value to write - * @cnt: The maximum number of bytes to write to "file" + * @count: The maximum number of bytes to write to "file" * @ppos: The current position in @file * * This function provides a write implementation for the "cpus" @@ -2320,10 +2320,11 @@ osnoise_cpus_write(struct file *filp, const char __= user *ubuf, size_t count, { cpumask_var_t osnoise_cpumask_new; int running, err; - char buf[256]; + char *buf __free(kfree) =3D NULL; =20 - if (count >=3D 256) - return -EINVAL; + buf =3D kmalloc(count, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 if (copy_from_user(buf, ubuf, count)) return -EFAULT; --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 C377229291A for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=sPpzCaGHMx+J2aV7PDwuGLsSA9TQM4OynOvzcgzJmui4mT0V/Kc/PXuaWQs1BUqvwlPoL/pA7hKsCzngufDCS2JQoC4V3tZFPwHNNO7qa1v2rXOy3c0O+dnMz+pEDTlzdV2lmCotU4WfvwrycRKnBNov8sPNmheZ3vO4B3tSmlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=6s9eu20TM2vzFU32ijFQgmiLWZKG/xNugMZygTtdbhw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aNuD7UkVDXy5S7F5mAXtRRCaOsdgcRFMfAsyxoDYBvQwB/6fj+HQDfPSKIl1GM/wyxP717rfXYS2MLa1tDUJcw73DjkK+XxybgnHKbjOpiONPC1aoqH/F9Ae8YaSzZnScbYZe3wBCa8GqdZZu8OqaXXzAEG35NKhFc6PFpPfgE4= 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 3F694C4CEF5; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002buG-3FPm; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131315.626033814@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:02 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 13/31] tracing/mmiotrace: Remove reference to unused per CPU data pointer References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The mmiotracer referenced the per CPU array_buffer->data descriptor but never actually used it. Remove the references to it. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212234.696945463@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_mmiotrace.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c index ba5858866b2f..c706544be60c 100644 --- a/kernel/trace/trace_mmiotrace.c +++ b/kernel/trace/trace_mmiotrace.c @@ -291,7 +291,6 @@ __init static int init_mmio_trace(void) device_initcall(init_mmio_trace); =20 static void __trace_mmiotrace_rw(struct trace_array *tr, - struct trace_array_cpu *data, struct mmiotrace_rw *rw) { struct trace_buffer *buffer =3D tr->array_buffer.buffer; @@ -315,12 +314,10 @@ static void __trace_mmiotrace_rw(struct trace_array *= tr, void mmio_trace_rw(struct mmiotrace_rw *rw) { struct trace_array *tr =3D mmio_trace_array; - struct trace_array_cpu *data =3D per_cpu_ptr(tr->array_buffer.data, smp_p= rocessor_id()); - __trace_mmiotrace_rw(tr, data, rw); + __trace_mmiotrace_rw(tr, rw); } =20 static void __trace_mmiotrace_map(struct trace_array *tr, - struct trace_array_cpu *data, struct mmiotrace_map *map) { struct trace_buffer *buffer =3D tr->array_buffer.buffer; @@ -344,12 +341,7 @@ static void __trace_mmiotrace_map(struct trace_array *= tr, void mmio_trace_mapping(struct mmiotrace_map *map) { struct trace_array *tr =3D mmio_trace_array; - struct trace_array_cpu *data; - - preempt_disable(); - data =3D per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); - __trace_mmiotrace_map(tr, data, map); - preempt_enable(); + __trace_mmiotrace_map(tr, map); } =20 int mmio_trace_printk(const char *fmt, va_list args) --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 7D61D2920B9 for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=oArqireb5g03teOfjkvUWMvmlK6WJSPl9SR8N2Bid1gszhibTkhyX++Bg1zjHsH6gK5nOUtGt6swg/yfpUnq/EGp/8Of5ekW7WsmWRThuFX+LVuoxtaKlIpiLUjS1Ns6d+DM1117rRcuIH9dMMSl8kcDlW6oCwMhunTfCD2SQdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=wEecE7svTPb11DcdMrTx0WAMQTb7eJNFeUdjgQ8JSws=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cWxb3PNeVXOB2fBjs6L/KSWEe5ZgHmLTIsjOqShqCb6T4c10k60G6PKSIt4W+RrazUjGUQEwHvo+CPkNgYrO86tFeGttnwZsgLP2G5d7iLadEjL2tlnj3JM8ljSqsrGyHOo8MlLVypzGItSLwqZslnm8s+LifRzK3+IE0GngBAM= 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 671B5C4CEEE; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXP-00000002bum-3y4B; Fri, 09 May 2025 09:13:15 -0400 Message-ID: <20250509131315.794682410@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:03 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 14/31] ftrace: Do not bother checking per CPU "disabled" flag References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. There's no reason for the function tracer to check it, if tracing is disabled, the ring buffer will not record the event anyway. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212234.868972758@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 98ccf3f00c51..bd153219a712 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -209,7 +209,6 @@ function_trace_call(unsigned long ip, unsigned long par= ent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; =20 @@ -224,9 +223,7 @@ function_trace_call(unsigned long ip, unsigned long par= ent_ip, =20 trace_ctx =3D tracing_gen_ctx_dec(); =20 - data =3D this_cpu_ptr(tr->array_buffer.data); - if (!atomic_read(&data->disabled)) - trace_function(tr, ip, parent_ip, trace_ctx, NULL); + trace_function(tr, ip, parent_ip, trace_ctx, NULL); =20 ftrace_test_recursion_unlock(bit); } @@ -236,10 +233,8 @@ function_args_trace_call(unsigned long ip, unsigned lo= ng parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; - int cpu; =20 if (unlikely(!tr->function_enabled)) return; @@ -250,10 +245,7 @@ function_args_trace_call(unsigned long ip, unsigned lo= ng parent_ip, =20 trace_ctx =3D tracing_gen_ctx(); =20 - cpu =3D smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - if (!atomic_read(&data->disabled)) - trace_function(tr, ip, parent_ip, trace_ctx, fregs); + trace_function(tr, ip, parent_ip, trace_ctx, fregs); =20 ftrace_test_recursion_unlock(bit); } @@ -352,7 +344,6 @@ function_no_repeats_trace_call(unsigned long ip, unsign= ed long parent_ip, { struct trace_func_repeats *last_info; struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; =20 @@ -364,8 +355,7 @@ function_no_repeats_trace_call(unsigned long ip, unsign= ed long parent_ip, return; =20 parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); - data =3D this_cpu_ptr(tr->array_buffer.data); - if (atomic_read(&data->disabled)) + if (!tracer_tracing_is_on(tr)) goto out; =20 /* --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 BD70D292916 for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=aBkm+UTv4ykSnL5TT/zi2lPWNs69IPMTAa36YvsrOTD6loyDIrBKJ5IM07q79dKLHQLd6gKFSMm30igIoRXf113CCpfhwTaBoQJGSoYYSACeOPehpW0an1tzLoBli1LgIgAmV7S3wMjbv1JDLUv84C61qPavug6OSp6FWc5mGQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=ZQGu6eZZrhG2/2ZDBobBKGfXqtVNgDKv1TETlsatHak=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=M7PV52usxJwQj87Xaxr/mzSmupTaU3euEJcohv8LwbxEzdRGbm35cLdqA9lKIwUidv0HF2FsccBz1M1kbcWn35+gdj6xaRNUb/ueeFr3hCw71fz+rCASEvdU0MIfPRZiT3epyaTc1J9JYLxk7HRPdJkgKhJIcvuJU8oQu5n/HCU= 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 9EAADC4CEF2; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bvH-0Umh; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131315.968672086@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:04 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 15/31] tracing: Just use this_cpu_read() to access ignore_pid References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ignore_pid boolean on the per CPU data descriptor is updated at sched_switch when a new task is scheduled in. If the new task is to be ignored, it is set to true, otherwise it is set to false. The current task should always have the correct value as it is updated when the task is scheduled in. Instead of breaking up the read of this value, which requires preemption to be disabled, just use this_cpu_read() which gives a snapshot of the value. Since the value will always be correct for a given task (because it's updated at sched switch) it doesn't need preemption disabled. This will also allow trace events to be called with preemption enabled. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212235.038958766@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 069e92856bda..fe0ea14d809e 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -622,7 +622,6 @@ EXPORT_SYMBOL_GPL(trace_event_raw_init); bool trace_event_ignore_this_pid(struct trace_event_file *trace_file) { struct trace_array *tr =3D trace_file->tr; - struct trace_array_cpu *data; struct trace_pid_list *no_pid_list; struct trace_pid_list *pid_list; =20 @@ -632,9 +631,11 @@ bool trace_event_ignore_this_pid(struct trace_event_fi= le *trace_file) if (!pid_list && !no_pid_list) return false; =20 - data =3D this_cpu_ptr(tr->array_buffer.data); - - return data->ignore_pid; + /* + * This is recorded at every sched_switch for this task. + * Thus, even if the task migrates the ignore value will be the same. + */ + return this_cpu_read(tr->array_buffer.data->ignore_pid) !=3D 0; } EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid); =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 DBF47292921 for ; Fri, 9 May 2025 13:13:00 +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=1746796380; cv=none; b=qTPUuXQqRJgwT+s5fSWU5dWPQgDuF9rl8PvhDWatICZINg7/zwAiPvg2zQmk/RyihdvBWssjUonj8JKnSYz/yyUsA70x8R6SF2rB1b79UVDgntdi6XpvYo+8UtPnyjjESMUq2sM9XsbOMSsqbpIQT8dyK0kMCXq7smxExCK5xdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796380; c=relaxed/simple; bh=u5+NyPKVhcSjs1F3L149FjDH9sUxOKaY4ilHqBMPNe0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=YkgILL3PZs2mJcEsrCpV7m1yWi3UVqORpwMJzJ+fMhsJiX/r3fHBNEm0NnqZxdyraxPvDk5hOJ3CTOCBqcZpvlmOZJhO85cW2FGLS05PaCjwPNQfGMT85jIeiWrv0mRfUQcjNMvxoQV882t74fsgR/MbW++te1dQcj+qfe7iaNg= 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 C1145C4CEF6; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bvm-1EIO; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131316.139772566@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [for-next][PATCH 16/31] tracing: Add tracer_tracing_disable/enable() functions References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Allow a tracer to disable writing to its buffer for a temporary amount of time and re-enable it. The tracer_tracing_disable() will disable writing to the trace array buffer, and requires a tracer_tracing_enable() to re-enable it. The difference between tracer_tracing_disable() and tracer_tracing_off() is that the disable version can nest, and requires as many enable() calls as disable() calls to re-enable the buffer. Where as the off() function can be called multiple times and only requires a singe tracer_tracing_on() to re-enable the buffer. Cc: Jason Wessel Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Daniel Thompson Cc: Douglas Anderson Link: https://lore.kernel.org/20250505212235.210330010@goodmis.org Signed-off-by: Steven Rostedt (Google) Reviewed-by: Douglas Anderson --- kernel/trace/trace.c | 33 +++++++++++++++++++++++++++++++++ kernel/trace/trace.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 01572ef79802..b691af1c1b5a 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1582,6 +1582,39 @@ void tracer_tracing_off(struct trace_array *tr) smp_wmb(); } =20 +/** + * tracer_tracing_disable() - temporary disable the buffer from write + * @tr: The trace array to disable its buffer for + * + * Expects trace_tracing_enable() to re-enable tracing. + * The difference between this and tracer_tracing_off() is that this + * is a counter and can nest, whereas, tracer_tracing_off() can + * be called multiple times and a single trace_tracing_on() will + * enable it. + */ +void tracer_tracing_disable(struct trace_array *tr) +{ + if (WARN_ON_ONCE(!tr->array_buffer.buffer)) + return; + + ring_buffer_record_disable(tr->array_buffer.buffer); +} + +/** + * tracer_tracing_enable() - counter part of tracer_tracing_disable() + * @tr: The trace array that had tracer_tracincg_disable() called on it + * + * This is called after tracer_tracing_disable() has been called on @tr, + * when it's safe to re-enable tracing. + */ +void tracer_tracing_enable(struct trace_array *tr) +{ + if (WARN_ON_ONCE(!tr->array_buffer.buffer)) + return; + + ring_buffer_record_enable(tr->array_buffer.buffer); +} + /** * tracing_off - turn off tracing buffers * diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 79be1995db44..74f1fe5788d4 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -665,6 +665,8 @@ bool tracing_is_disabled(void); bool tracer_tracing_is_on(struct trace_array *tr); void tracer_tracing_on(struct trace_array *tr); void tracer_tracing_off(struct trace_array *tr); +void tracer_tracing_disable(struct trace_array *tr); +void tracer_tracing_enable(struct trace_array *tr); struct dentry *trace_create_file(const char *name, umode_t mode, struct dentry *parent, --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 6B53D293454 for ; Fri, 9 May 2025 13:13:01 +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=1746796381; cv=none; b=oF6QY9fDeEHOr3H81HFcu3kl5lsWYOFqR3XD3je4g/ZZFnE22RHM0JeSOY6LFLmdaJcel2k3S0biyUHmbTII/mnqERgrdvEED4Eena5qA4rOUAAjTPdMJGvZaeIDo+Dysjymp34D1P1S4Zwjr005aMS0aAgyqGwaE/DgmtEavow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796381; c=relaxed/simple; bh=xwQUJHkXERbxk/si81Gpn8n1YOu4O5M9Z89z+7M7IpQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gWu7pUs9Hxhd0zijDX4dY/korgGxMfAXGq7J+wmGnDwLX7MHkZEOwWdEa8agj6yiM82FE+EbHi5oamaM1WG9eCvjjvNyresW44768iKmgtE6J6o5rijHdzuOxSdvKtcZBBdqyimGQgmde8ymA8Mv1OnJrzgM8Z/alARtvk7B4+M= 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 E7D40C4CEEE; Fri, 9 May 2025 13:13:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bwH-1vyP; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131316.315091499@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:06 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 17/31] tracing: Use tracer_tracing_disable() instead of "disabled" field for ftrace_dump_one() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. The ftrace_dump_one() function iterates over all the current tracing CPUs a= nd increments the "disabled" counter before doing the dump, and decrements it afterward. As the disabled flag can be ignored, doing this today is not reliable. Instead use the new tracer_tracing_disable() that calls into the ring buffer code to do the disabling. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212235.381188238@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b691af1c1b5a..bb514e988f22 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10484,7 +10484,7 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m static struct trace_iterator iter; unsigned int old_userobj; unsigned long flags; - int cnt =3D 0, cpu; + int cnt =3D 0; =20 /* * Always turn off tracing when we dump. @@ -10501,9 +10501,8 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m /* Simulate the iterator */ trace_init_iter(&iter, tr); =20 - for_each_tracing_cpu(cpu) { - atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + /* While dumping, do not allow the buffer to be enable */ + tracer_tracing_disable(tr); =20 old_userobj =3D tr->trace_flags & TRACE_ITER_SYM_USEROBJ; =20 @@ -10562,9 +10561,7 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m =20 tr->trace_flags |=3D old_userobj; =20 - for_each_tracing_cpu(cpu) { - atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_enable(tr); local_irq_restore(flags); } =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 88317293462 for ; Fri, 9 May 2025 13:13:01 +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=1746796381; cv=none; b=HgSDydkCZlm1hgugZmHkcyr0gUZNhjXRsT7veXBgn/Jdcbndol1aAS7NPG53gve3fmpT9c5LrM9mSu6bCZiNBAlDDJ45gRcr1w+oDNXx6hhzBBqMtDqXdPNxOrg1CbTtv2bwAX8ht9cKIEeddBVdBGbx/PcAt2ovW4+gGnJZeJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796381; c=relaxed/simple; bh=M4oC3js/6GRG4hCXpowDgVIbV4NBdtJSRz/ZIWx5O3c=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ZLIfVdBAKrkXIAyQgsB0v0vL1RUwBUQT5YL6z/oYkkn6evFd+l1HuGKEF+anNuaRmLzvvSpHDv3blucwuuMIXDcSwSX1b/hl+Dk6uzEDlQdvl8McTkIczirJXsqc8DVm9ElGHsrP9v+h1+b8n4DhEomwTRu1Vv8uwvUxuQcml4g= 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 1A955C4CEF2; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bwl-2ev3; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131316.483054226@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [for-next][PATCH 18/31] tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. The kdb_ftdump() function iterates over all the current tracing CPUs and increments the "disabled" counter before doing the dump, and decrements it afterward. As the disabled flag can be ignored, doing this today is not reliable. Instead, simply call tracer_tracing_off() and then tracer_tracing_on() to disable and then enabled the entire ring buffer in one go! Cc: Jason Wessel Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Daniel Thompson Cc: Douglas Anderson Link: https://lore.kernel.org/20250505212235.549033722@goodmis.org Signed-off-by: Steven Rostedt (Google) Reviewed-by: Douglas Anderson --- kernel/trace/trace_kdb.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 1e72d20b3c2f..d7b135de958a 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -98,7 +98,6 @@ static int kdb_ftdump(int argc, const char **argv) long cpu_file; int err; int cnt; - int cpu; =20 if (argc > 2) return KDB_ARGCOUNT; @@ -120,9 +119,7 @@ static int kdb_ftdump(int argc, const char **argv) trace_init_global_iter(&iter); iter.buffer_iter =3D buffer_iter; =20 - for_each_tracing_cpu(cpu) { - atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_disable(iter.tr); =20 /* A negative skip_entries means skip all but the last entries */ if (skip_entries < 0) { @@ -135,9 +132,7 @@ static int kdb_ftdump(int argc, const char **argv) =20 ftrace_dump_buf(skip_entries, cpu_file); =20 - for_each_tracing_cpu(cpu) { - atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_enable(iter.tr); =20 kdb_trap_printk--; =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 BF68E29372C for ; Fri, 9 May 2025 13:13:01 +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=1746796381; cv=none; b=S0l0npQZGVoapCAWrnkWdu48LmSd+1xjXP0kTrkaFAKKDCvQtcHy79gFZQsdLzdup6ZJu0Wy5drBehAF47kyix9nt0P1ntANg01+hgoUt9V/qEZh3FrUxAd1x4cs4Xj6JGYbHrXqDOfYRX75lhibb/3vEqAVpxDH28jdWP7w6Yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796381; c=relaxed/simple; bh=3OsHc8XwoJH6dpKHNcBXd6XkR5G+RBAew+FYYhGeYYk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=MUO1am8iYEGYrCiDArPi4d48oU8dzgNIQTTUPyzMH2/BfA+yh6vGVkKuhEAsAoeUfNO+0bQBWc8dNpAYD6vQLdGlLLzQnmUIM7wkdfm6k94y5ylLkegODu3S+yI+78rGIkqJPVOGjYIWsEEMETtCOu65gmDH00rpIeoLtp1rfBs= 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 47B75C4CEF7; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bxH-3Ma2; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131316.655384145@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:08 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 19/31] ftrace: Do not disabled function graph based on "disabled" field References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. Do not bother disabling the function graph tracer if the per CPU disabled field is set. Just record as normal. If tracing is disabled in the ring buffer it will not be recorded. Also, when tracing is enabled again, it will not drop the return call of the function. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212235.715752008@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions_graph.c | 38 +++++++--------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_func= tions_graph.c index 0c357a89c58e..9234e2c39abf 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -202,12 +202,9 @@ static int graph_entry(struct ftrace_graph_ent *trace, { unsigned long *task_var =3D fgraph_get_task_var(gops); struct trace_array *tr =3D gops->private; - struct trace_array_cpu *data; struct fgraph_times *ftimes; unsigned int trace_ctx; - long disabled; int ret =3D 0; - int cpu; =20 if (*task_var & TRACE_GRAPH_NOTRACE) return 0; @@ -257,21 +254,14 @@ static int graph_entry(struct ftrace_graph_ent *trace, if (tracing_thresh) return 1; =20 - preempt_disable_notrace(); - cpu =3D raw_smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_read(&data->disabled); - if (likely(!disabled)) { - trace_ctx =3D tracing_gen_ctx(); - if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) && - tracer_flags_is_set(TRACE_GRAPH_PRINT_RETADDR)) { - unsigned long retaddr =3D ftrace_graph_top_ret_addr(current); - ret =3D __trace_graph_retaddr_entry(tr, trace, trace_ctx, retaddr); - } else { - ret =3D __graph_entry(tr, trace, trace_ctx, fregs); - } + trace_ctx =3D tracing_gen_ctx(); + if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) && + tracer_flags_is_set(TRACE_GRAPH_PRINT_RETADDR)) { + unsigned long retaddr =3D ftrace_graph_top_ret_addr(current); + ret =3D __trace_graph_retaddr_entry(tr, trace, trace_ctx, retaddr); + } else { + ret =3D __graph_entry(tr, trace, trace_ctx, fregs); } - preempt_enable_notrace(); =20 return ret; } @@ -351,13 +341,10 @@ void trace_graph_return(struct ftrace_graph_ret *trac= e, { unsigned long *task_var =3D fgraph_get_task_var(gops); struct trace_array *tr =3D gops->private; - struct trace_array_cpu *data; struct fgraph_times *ftimes; unsigned int trace_ctx; u64 calltime, rettime; - long disabled; int size; - int cpu; =20 rettime =3D trace_clock_local(); =20 @@ -376,15 +363,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace, =20 calltime =3D ftimes->calltime; =20 - preempt_disable_notrace(); - cpu =3D raw_smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_read(&data->disabled); - if (likely(!disabled)) { - trace_ctx =3D tracing_gen_ctx(); - __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); - } - preempt_enable_notrace(); + trace_ctx =3D tracing_gen_ctx(); + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); } =20 static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 89AC4293464 for ; Fri, 9 May 2025 13:13:01 +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=1746796381; cv=none; b=nrUgj9d55kPOe+lpKYeVOxdpuXBemdoYPQ+DbuGMW/buutBJCZKil8VuqwiA8X/JCT8HO5ONSqmH+nezHMRDJhBTAhieGbghdM0/XJUKCp916BIiMWtoI4tezpsLYesw7MvDpRQ/eJ9HT2p6bkCEpWgW/l4rYjiog06poYLXq/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796381; c=relaxed/simple; bh=gX/BulkDUJDwwS4uSbgk0YaF4aNaSOdd1ywJ8eDw4Kg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UTZIr3e8DmU40RJ7THAyD5/xP+ShRA55UYlPWVrXczglsNSMudiNlNQJZAjKPFwZDSApjp/dXuQVEiZOsToRlLQaIG3sq7+BOFtEeNwEKiq+g57dNDFTJz0M9ogRdIg2mlPMRybnPpPDlAeBo/umfIQRwykt8fPZNtAa/jCPb/g= 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 70BF3C4CEEB; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXQ-00000002bxm-44H5; Fri, 09 May 2025 09:13:16 -0400 Message-ID: <20250509131316.822900740@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:09 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 20/31] tracing: Do not use per CPU array_buffer.data->disabled for cpumask References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. Do not bother setting the per CPU disabled flag of the array_buffer data to use to determine what CPUs can write to the buffer and only rely on the ring buffer code itself to disabled it. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212235.885452497@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index bb514e988f22..0cd681516438 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5081,7 +5081,6 @@ int tracing_set_cpumask(struct trace_array *tr, */ if (cpumask_test_cpu(cpu, tr->tracing_cpumask) && !cpumask_test_cpu(cpu, tracing_cpumask_new)) { - atomic_inc(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu); #ifdef CONFIG_TRACER_MAX_TRACE ring_buffer_record_disable_cpu(tr->max_buffer.buffer, cpu); @@ -5089,7 +5088,6 @@ int tracing_set_cpumask(struct trace_array *tr, } if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && cpumask_test_cpu(cpu, tracing_cpumask_new)) { - atomic_dec(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu); #ifdef CONFIG_TRACER_MAX_TRACE ring_buffer_record_enable_cpu(tr->max_buffer.buffer, cpu); --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 B4C0D293725 for ; Fri, 9 May 2025 13:13:01 +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=1746796381; cv=none; b=LUFQ2n5sC4WFsgvJO4M/RrB2xq2h/S/Z79tkhfhNoiHA1rKPoTA39ZRokdN/H1ljyIYC674tFijzlxgVtFSHXZKI/rbgXGh+30+BM7Kp0KxkA00QugahlenH9Pd5HgNKiXGSLC7PwfIgxxS7rWQJvsSnLiAZ2V+9KlP3SB8mqf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796381; c=relaxed/simple; bh=IHAUeL2KBD9XuOVLlSBj9mntsqSOSSRKDRivd7fbx6E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=DOco4QF2AEc5ECiPzwPery/3x2wNJtA0/+NmSRIp7NroN8oXEzH7c7AnuoGCo3VeYdNhn0XmpgSRt1z99c3TTvJnzxZqXQ6T5eBktNfbGgiQY8Nn6BFpAysci9QbgYg/vpErWTr5P+2rAwByACeRwODxt55ZqBOli2Dsej9S9MA= 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 99C06C4CEF9; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXR-00000002byH-0b24; Fri, 09 May 2025 09:13:17 -0400 Message-ID: <20250509131316.991102877@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:10 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 21/31] ring-buffer: Add ring_buffer_record_is_on_cpu() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Add the function ring_buffer_record_is_on_cpu() that returns true if the ring buffer for a give CPU is writable and false otherwise. Also add tracer_tracing_is_on_cpu() to return if the ring buffer for a given CPU is writeable for a given trace_array. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212236.059853898@goodmis.org Signed-off-by: Steven Rostedt (Google) --- include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 18 ++++++++++++++++++ kernel/trace/trace.h | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 56e27263acf8..cd7f0ae26615 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -192,6 +192,7 @@ void ring_buffer_record_off(struct trace_buffer *buffer= ); void ring_buffer_record_on(struct trace_buffer *buffer); bool ring_buffer_record_is_on(struct trace_buffer *buffer); bool ring_buffer_record_is_set_on(struct trace_buffer *buffer); +bool ring_buffer_record_is_on_cpu(struct trace_buffer *buffer, int cpu); void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu); void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu); =20 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index c0f877d39a24..1ca482955dae 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4882,6 +4882,24 @@ bool ring_buffer_record_is_set_on(struct trace_buffe= r *buffer) return !(atomic_read(&buffer->record_disabled) & RB_BUFFER_OFF); } =20 +/** + * ring_buffer_record_is_on_cpu - return true if the ring buffer can write + * @buffer: The ring buffer to see if write is enabled + * @cpu: The CPU to test if the ring buffer can write too + * + * Returns true if the ring buffer is in a state that it accepts writes + * for a particular CPU. + */ +bool ring_buffer_record_is_on_cpu(struct trace_buffer *buffer, int cpu) +{ + struct ring_buffer_per_cpu *cpu_buffer; + + cpu_buffer =3D buffer->buffers[cpu]; + + return ring_buffer_record_is_set_on(buffer) && + !atomic_read(&cpu_buffer->record_disabled); +} + /** * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer * @buffer: The ring buffer to stop writes to. diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 74f1fe5788d4..69c1ecfb2290 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -673,6 +673,21 @@ struct dentry *trace_create_file(const char *name, void *data, const struct file_operations *fops); =20 + +/** + * tracer_tracing_is_on_cpu - show real state of ring buffer enabled on fo= r a cpu + * @tr : the trace array to know if ring buffer is enabled + * @cpu: The cpu buffer to check if enabled + * + * Shows real state of the per CPU buffer if it is enabled or not. + */ +static inline bool tracer_tracing_is_on_cpu(struct trace_array *tr, int cp= u) +{ + if (tr->array_buffer.buffer) + return ring_buffer_record_is_on_cpu(tr->array_buffer.buffer, cpu); + return false; +} + int tracing_init_dentry(void); =20 struct ring_buffer_event; --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 28F5F29375A for ; Fri, 9 May 2025 13:13:01 +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=1746796382; cv=none; b=mv8C6C3jUotJd2cDjHoGX8cTFrVV3X43pdkGcXZNZDYkkk6jfrmpafttPEypTyiElhT1EB3JwEiG0ruZKJNXNr2sqvWOD5vGBz2psphYfJyRMdgxPbrbmvRE0PbvRwNX9TXaATKeDm3gaD+348N1LsAn8s54VDGjTRESuO+FR/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=fE0eJpd6kBWM05p3RQocRcUqNTeOZ31V1UkwHVx9TOM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=vAy9D1x5+Wh7pG8ys5O7yMhhwaevRaa2bJR7fY5hmgv9iNv7DASEj8ldQl3hB2Hiws6PFnLXdxCkyskVn7uCpG218kgIR1LV5jrzRu90twQ0DEU+jQr1v2vnylDQd5GjgUum3rbIdTHwdmQfUbiC5K1z8e1195dp3R0NFIqPdbQ= 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 C3885C4AF09; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXR-00000002byn-1JnC; Fri, 09 May 2025 09:13:17 -0400 Message-ID: <20250509131317.164151927@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:11 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 22/31] tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The branch tracer currently checks the per CPU "disabled" field to know if tracing is enabled or not for the CPU. As the "disabled" value is not used anymore to turn of tracing generically, use tracing_tracer_is_on_cpu() instead. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212236.224658526@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_branch.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c index 6d08a5523ce0..6809b370e991 100644 --- a/kernel/trace/trace_branch.c +++ b/kernel/trace/trace_branch.c @@ -32,7 +32,6 @@ probe_likely_condition(struct ftrace_likely_data *f, int = val, int expect) { struct trace_array *tr =3D branch_tracer; struct trace_buffer *buffer; - struct trace_array_cpu *data; struct ring_buffer_event *event; struct trace_branch *entry; unsigned long flags; @@ -54,8 +53,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int = val, int expect) =20 raw_local_irq_save(flags); current->trace_recursion |=3D TRACE_BRANCH_BIT; - data =3D this_cpu_ptr(tr->array_buffer.data); - if (atomic_read(&data->disabled)) + if (!tracer_tracing_is_on_cpu(tr, raw_smp_processor_id())) goto out; =20 trace_ctx =3D tracing_gen_ctx_flags(flags); --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 20FE6293754 for ; Fri, 9 May 2025 13:13:02 +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=1746796382; cv=none; b=cYFFmv2KV3I5tczGcpZnres4+TY86Qe51gbMMujZK8bRjs5IcVubiJXS/uqUkYO1QLOcqApF+IbSS1X03zSt7K8qitjiaBKIt7MrD8G4fSwhZIp8ihejnciSKGm5dim2NNO8/8mVsEl04Mi708T0AbcyF7xuU26GrhSdFgLqZFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=PEMsRAkVfHqbpumS0gpvPHxCdF+Z5gl5B8yoDg7XsTU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UmbPXTw1mwzxSo+4/dPBGVCpgzxNNu7dhrVEV1dmRVQF+QpIkGHbqDkJLWrUBKUj0RYl6tb6Dms0d/HFGBq9ZNCbQFeaOBKNSQdxy+HYyM2+SfNI2wR5cOoe/Cei7rxJCfDpqO3ZGv3IS3NdXTugxkyBKLqpzOHCLuuuxIT3N0E= 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 ED586C4CEF0; Fri, 9 May 2025 13:13:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXR-00000002bzI-23O7; Fri, 09 May 2025 09:13:17 -0400 Message-ID: <20250509131317.337063144@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:12 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 23/31] tracing: Convert the per CPU "disabled" counter to local from atomic References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" counter is used for the latency tracers and stack tracers to make sure that their accounting isn't messed up by an NMI or interrupt coming in and affecting the same CPU data. But the counter is an atomic_t type. As it only needs to synchronize against the current CPU, switch it over to local_t type. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212236.394925376@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 2 +- kernel/trace/trace_functions.c | 8 ++++---- kernel/trace/trace_irqsoff.c | 22 +++++++++++----------- kernel/trace/trace_sched_wakeup.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 69c1ecfb2290..188032d4ab69 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -183,7 +183,7 @@ struct trace_array; * the trace, etc.) */ struct trace_array_cpu { - atomic_t disabled; + local_t disabled; void *buffer_page; /* ring buffer spare */ =20 unsigned long entries; diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index bd153219a712..99a90f182485 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -291,7 +291,7 @@ function_stack_trace_call(unsigned long ip, unsigned lo= ng parent_ip, parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); cpu =3D raw_smp_processor_id(); data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 if (likely(disabled =3D=3D 1)) { trace_ctx =3D tracing_gen_ctx_flags(flags); @@ -303,7 +303,7 @@ function_stack_trace_call(unsigned long ip, unsigned lo= ng parent_ip, __trace_stack(tr, trace_ctx, skip); } =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); local_irq_restore(flags); } =20 @@ -402,7 +402,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, = unsigned long parent_ip, parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); cpu =3D raw_smp_processor_id(); data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 if (likely(disabled =3D=3D 1)) { last_info =3D per_cpu_ptr(tr->last_func_repeats, cpu); @@ -417,7 +417,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, = unsigned long parent_ip, } =20 out: - atomic_dec(&data->disabled); + local_dec(&data->disabled); local_irq_restore(flags); } =20 diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 40c39e946940..0b6d932a931e 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -123,12 +123,12 @@ static int func_prolog_dec(struct trace_array *tr, return 0; =20 *data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&(*data)->disabled); + disabled =3D local_inc_return(&(*data)->disabled); =20 if (likely(disabled =3D=3D 1)) return 1; =20 - atomic_dec(&(*data)->disabled); + local_dec(&(*data)->disabled); =20 return 0; } @@ -152,7 +152,7 @@ irqsoff_tracer_call(unsigned long ip, unsigned long par= ent_ip, =20 trace_function(tr, ip, parent_ip, trace_ctx, fregs); =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); } #endif /* CONFIG_FUNCTION_TRACER */ =20 @@ -209,7 +209,7 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent = *trace, =20 trace_ctx =3D tracing_gen_ctx_flags(flags); ret =3D __trace_graph_entry(tr, trace, trace_ctx); - atomic_dec(&data->disabled); + local_dec(&data->disabled); =20 return ret; } @@ -238,7 +238,7 @@ static void irqsoff_graph_return(struct ftrace_graph_re= t *trace, =20 trace_ctx =3D tracing_gen_ctx_flags(flags); __trace_graph_return(tr, trace, trace_ctx, *calltime, rettime); - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 static struct fgraph_ops fgraph_ops =3D { @@ -408,10 +408,10 @@ start_critical_timing(unsigned long ip, unsigned long= parent_ip) =20 data =3D per_cpu_ptr(tr->array_buffer.data, cpu); =20 - if (unlikely(!data) || atomic_read(&data->disabled)) + if (unlikely(!data) || local_read(&data->disabled)) return; =20 - atomic_inc(&data->disabled); + local_inc(&data->disabled); =20 data->critical_sequence =3D max_sequence; data->preempt_timestamp =3D ftrace_now(cpu); @@ -421,7 +421,7 @@ start_critical_timing(unsigned long ip, unsigned long p= arent_ip) =20 per_cpu(tracing_cpu, cpu) =3D 1; =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 static nokprobe_inline void @@ -445,16 +445,16 @@ stop_critical_timing(unsigned long ip, unsigned long = parent_ip) data =3D per_cpu_ptr(tr->array_buffer.data, cpu); =20 if (unlikely(!data) || - !data->critical_start || atomic_read(&data->disabled)) + !data->critical_start || local_read(&data->disabled)) return; =20 - atomic_inc(&data->disabled); + local_inc(&data->disabled); =20 trace_ctx =3D tracing_gen_ctx(); __trace_function(tr, ip, parent_ip, trace_ctx); check_critical_timing(tr, data, parent_ip ? : ip, cpu); data->critical_start =3D 0; - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 /* start and stop critical timings used to for stoppage (in idle) */ diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_w= akeup.c index a0db3404f7f7..bf1cb80742ae 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c @@ -83,14 +83,14 @@ func_prolog_preempt_disable(struct trace_array *tr, goto out_enable; =20 *data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&(*data)->disabled); + disabled =3D local_inc_return(&(*data)->disabled); if (unlikely(disabled !=3D 1)) goto out; =20 return 1; =20 out: - atomic_dec(&(*data)->disabled); + local_dec(&(*data)->disabled); =20 out_enable: preempt_enable_notrace(); @@ -144,7 +144,7 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *= trace, *calltime =3D trace_clock_local(); =20 ret =3D __trace_graph_entry(tr, trace, trace_ctx); - atomic_dec(&data->disabled); + local_dec(&data->disabled); preempt_enable_notrace(); =20 return ret; @@ -173,7 +173,7 @@ static void wakeup_graph_return(struct ftrace_graph_ret= *trace, return; =20 __trace_graph_return(tr, trace, trace_ctx, *calltime, rettime); - atomic_dec(&data->disabled); + local_dec(&data->disabled); =20 preempt_enable_notrace(); return; @@ -243,7 +243,7 @@ wakeup_tracer_call(unsigned long ip, unsigned long pare= nt_ip, trace_function(tr, ip, parent_ip, trace_ctx, fregs); local_irq_restore(flags); =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); preempt_enable_notrace(); } =20 @@ -471,7 +471,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt, =20 /* disable local data, not wakeup_cpu data */ cpu =3D raw_smp_processor_id(); - disabled =3D atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.da= ta, cpu)->disabled); + disabled =3D local_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.dat= a, cpu)->disabled); if (likely(disabled !=3D 1)) goto out; =20 @@ -508,7 +508,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt, arch_spin_unlock(&wakeup_lock); local_irq_restore(flags); out: - atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); + local_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); } =20 static void __wakeup_reset(struct trace_array *tr) @@ -563,7 +563,7 @@ probe_wakeup(void *ignore, struct task_struct *p) (!dl_task(p) && (p->prio >=3D wakeup_prio || p->prio >=3D current->pr= io))) return; =20 - disabled =3D atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.da= ta, cpu)->disabled); + disabled =3D local_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.dat= a, cpu)->disabled); if (unlikely(disabled !=3D 1)) goto out; =20 @@ -610,7 +610,7 @@ probe_wakeup(void *ignore, struct task_struct *p) out_locked: arch_spin_unlock(&wakeup_lock); out: - atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); + local_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); } =20 static void start_wakeup_tracer(struct trace_array *tr) --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 392E0293B42 for ; Fri, 9 May 2025 13:13:02 +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=1746796382; cv=none; b=jD520gbHMaLCe/evHUmk+mDxTx09TZI4rm5nHnf+h4GAUkc+EHwEsvL9wyMn5LM/vEJtj9jo7Xi6yWZTwJ8sYPPpr7eB84qgc9YuVDATNukUpoOo9eT54Zfgp13PPxlv/fgcxzIVgzyJWn5NjxNGPqnBtmIMmPq3TIqsEhEf4rU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=qPP3CvHK8t4fr7gLX3mL04NCQ8w/oQ01akHffgDkhj8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=L/1U8flERSuUo/pi6RSAY77dCr4FI9GX6YcNI1K3X8fv2vOZFB55uflFuQnW+KZ6tgAVELYV4qqDqAkcjLqQcGf+fw6WmzZQY225Sspa+6WtBBWfgkdeTvyTijZDFVfuGAhVy5Xl6tz0it8qvTUdS8aifCT1lJfRnDIF1tD5xkk= 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 20324C4CEF1; Fri, 9 May 2025 13:13:02 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXR-00000002bzn-2nIO; Fri, 09 May 2025 09:13:17 -0400 Message-ID: <20250509131317.512092358@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:13 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 24/31] tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The irqsoff tracer uses the per CPU "disabled" field to prevent corruption of the accounting when it starts to trace interrupts disabled, but there's a slight race that could happen if for some reason it was called twice. Use atomic_inc_return() instead. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212236.567884756@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_irqsoff.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 0b6d932a931e..5496758b6c76 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -397,6 +397,7 @@ start_critical_timing(unsigned long ip, unsigned long p= arent_ip) int cpu; struct trace_array *tr =3D irqsoff_trace; struct trace_array_cpu *data; + long disabled; =20 if (!tracer_enabled || !tracing_is_enabled()) return; @@ -411,15 +412,17 @@ start_critical_timing(unsigned long ip, unsigned long= parent_ip) if (unlikely(!data) || local_read(&data->disabled)) return; =20 - local_inc(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 - data->critical_sequence =3D max_sequence; - data->preempt_timestamp =3D ftrace_now(cpu); - data->critical_start =3D parent_ip ? : ip; + if (disabled =3D=3D 1) { + data->critical_sequence =3D max_sequence; + data->preempt_timestamp =3D ftrace_now(cpu); + data->critical_start =3D parent_ip ? : ip; =20 - __trace_function(tr, ip, parent_ip, tracing_gen_ctx()); + __trace_function(tr, ip, parent_ip, tracing_gen_ctx()); =20 - per_cpu(tracing_cpu, cpu) =3D 1; + per_cpu(tracing_cpu, cpu) =3D 1; + } =20 local_dec(&data->disabled); } @@ -431,6 +434,7 @@ stop_critical_timing(unsigned long ip, unsigned long pa= rent_ip) struct trace_array *tr =3D irqsoff_trace; struct trace_array_cpu *data; unsigned int trace_ctx; + long disabled; =20 cpu =3D raw_smp_processor_id(); /* Always clear the tracing cpu on stopping the trace */ @@ -448,12 +452,15 @@ stop_critical_timing(unsigned long ip, unsigned long = parent_ip) !data->critical_start || local_read(&data->disabled)) return; =20 - local_inc(&data->disabled); + disabled =3D local_inc_return(&data->disabled); + + if (disabled =3D=3D 1) { + trace_ctx =3D tracing_gen_ctx(); + __trace_function(tr, ip, parent_ip, trace_ctx); + check_critical_timing(tr, data, parent_ip ? : ip, cpu); + data->critical_start =3D 0; + } =20 - trace_ctx =3D tracing_gen_ctx(); - __trace_function(tr, ip, parent_ip, trace_ctx); - check_critical_timing(tr, data, parent_ip ? : ip, cpu); - data->critical_start =3D 0; local_dec(&data->disabled); } =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 67E7D293B67 for ; Fri, 9 May 2025 13:13:02 +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=1746796382; cv=none; b=XLePEXLEGrJSSrnv7/kkWvwU9Q6h6Z7Q6CEvKfX2magvupnztHogj5zZnQQfxhdUDlf+547p2uCaIxT515F6Fag/XMgo8wBD/uhckCAHWwZZPvj3j2RRPtH/XHMd2hej8Y08u0OwS+5AO/BHAKrJLE7kpd9a0xhCQRrilSaVMVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=O9kf3HWu7xRO07iMKHCpcIKY+YPtXFMQK7uZxXvdRdA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=MpN1sq3Ap4pYWmrNitN4QGDTU8qI6UkILnojK4crtcsi38cP74+XN3FSGXExNV8BPuObG5tmEkIB/E/EPxxn3PkkVfbLeSDb6Fk57T2Oc99uxDxvPYd3Y2iWDutwjZex7FVfSZKGqJeELeb0qF+87wtqJ/qETUSLFhyYF5kbf+A= 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 4E168C4CEEB; Fri, 9 May 2025 13:13:02 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXR-00000002c0I-3W9W; Fri, 09 May 2025 09:13:17 -0400 Message-ID: <20250509131317.688383909@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:14 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 25/31] tracing: Remove unused buffer_page field from trace_array_cpu structure References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The trace_array_cpu had a "buffer_page" field that was originally going to be used as a backup page for the ring buffer. But the ring buffer has its own way of reusing pages and this field was never used. Remove it. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250505212236.738849456@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 188032d4ab69..4e67ee92e05c 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -184,7 +184,6 @@ struct trace_array; */ struct trace_array_cpu { local_t disabled; - void *buffer_page; /* ring buffer spare */ =20 unsigned long entries; unsigned long saved_latency; --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 9E14A2949E9 for ; Fri, 9 May 2025 13:13:02 +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=1746796382; cv=none; b=DZ+IgxbBuQCQajBB7mBLfCPBPnjLn7Twl28X1auXDjsRZgB5yebBZBW8lfBHNOsO1VTvCU8HR0wPWl2P4npLkfJaywvi7CQE+yxPmCCuS/fAQGUscVkNhrBgFPjkwIcon+NMfwswLuzeFfJNkRX+49vGEEapThrgoCEnFYxdQVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=EeVzafSY4XTLi4pqdsQZL2xG9bFvwuL8mqOrFuJJ6VI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=G7/IcwlEBzeu8+j8hx0VGlssbbwa0Ejv+XXfewr7Natl5q4bd7y4q7d7QHtS92Mc9Se3mIsz6/xRWfxWrkWc3DhEuCQMpVh78MKUoemqZZc8cgA1MqQi+IIWJu9Cm33IAOi8YysM6guLTX6lfGIlTTbDKFskHZnHx7alXQjAIeE= 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 7BF47C4CEE4; Fri, 9 May 2025 13:13:02 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c0n-01iI; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131317.861075722@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:15 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Devaansh Kumar Subject: [for-next][PATCH 26/31] tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Devaansh Kumar strncpy() is deprecated for NUL-terminated destination buffers and must be replaced by strscpy(). See issue: https://github.com/KSPP/linux/issues/90 Link: https://lore.kernel.org/20250507133837.19640-1-devaanshk840@gmail.com Signed-off-by: Devaansh Kumar Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index 14c6f272c4d8..4c349db381cb 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c @@ -542,7 +542,7 @@ static __init int enable_stacktrace(char *str) int len; =20 if ((len =3D str_has_prefix(str, "_filter=3D"))) - strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE); + strscpy(stack_trace_filter_buf, str + len); =20 stack_tracer_enabled =3D 1; return 1; --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 2531E294A1C for ; Fri, 9 May 2025 13:13:02 +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=1746796383; cv=none; b=QC4V8GjaIKdeMx+Zqu/XO85aMo855n4o3y5DVDgGZFU+l3KF+fqDNKtj6APnVNRE534gL7Mf4WQD+/PTT4N5qRfZVj/Xj1+PWCp1+ZJ34x9vS8sP7h+OEkiK+GwPp3QQJJWJcD9GqwxsOkgUNXAGSHuuecC/l/zqO8O12H6puoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796383; c=relaxed/simple; bh=jq9Owi/+9mbZr1A2hvJpkBYZMWiknPtUn2FHMj/XLaM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RaiTl0PZnJtLsekY7oiYmRbqqcBb5PWylPjlfXEPwM71RcOGEzIONaT0KI0RFBa0QHXf+YbibYu1TKN/G7pQ8fNNJS2CoEKIm5KQjajdholKBmBDLh5LYMlTormXVctjHufTDLG7OE2NeRnERqxfb56ovhVRmf0JIu4OHXSL0Qk= 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 A0BFBC4CEEF; Fri, 9 May 2025 13:13:02 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c1J-0kYX; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131318.027720878@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:16 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi Subject: [for-next][PATCH 27/31] tracing: Rename event_trigger_alloc() to trigger_data_alloc() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The function event_trigger_alloc() creates an event_trigger_data descriptor and states that it needs to be freed via event_trigger_free(). This is incorrect, it needs to be freed by trigger_data_free() as event_trigger_free() adds ref counting. Rename event_trigger_alloc() to trigger_data_alloc() and state that it needs to be freed via trigger_data_free(). This naming convention was introducing bugs. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Tom Zanussi Link: https://lore.kernel.org/20250507145455.776436410@goodmis.org Fixes: 86599dbe2c527 ("tracing: Add helper functions to simplify event_comm= and.parse() callback handling") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 8 +++----- kernel/trace/trace_events_hist.c | 2 +- kernel/trace/trace_events_trigger.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 4e67ee92e05c..86e9d7dcddba 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1788,6 +1788,9 @@ extern int event_enable_register_trigger(char *glob, extern void event_enable_unregister_trigger(char *glob, struct event_trigger_data *test, struct trace_event_file *file); +extern struct event_trigger_data * +trigger_data_alloc(struct event_command *cmd_ops, char *cmd, char *param, + void *private_data); extern void trigger_data_free(struct event_trigger_data *data); extern int event_trigger_init(struct event_trigger_data *data); extern int trace_event_trigger_enable_disable(struct trace_event_file *fil= e, @@ -1814,11 +1817,6 @@ extern bool event_trigger_check_remove(const char *g= lob); extern bool event_trigger_empty_param(const char *param); extern int event_trigger_separate_filter(char *param_and_filter, char **pa= ram, char **filter, bool param_required); -extern struct event_trigger_data * -event_trigger_alloc(struct event_command *cmd_ops, - char *cmd, - char *param, - void *private_data); extern int event_trigger_parse_num(char *trigger, struct event_trigger_data *trigger_data); extern int event_trigger_set_filter(struct event_command *cmd_ops, diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index 58c9535f61df..1d536219b624 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -6826,7 +6826,7 @@ static int event_hist_trigger_parse(struct event_comm= and *cmd_ops, return PTR_ERR(hist_data); } =20 - trigger_data =3D event_trigger_alloc(cmd_ops, cmd, param, hist_data); + trigger_data =3D trigger_data_alloc(cmd_ops, cmd, param, hist_data); if (!trigger_data) { ret =3D -ENOMEM; goto out_free; diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_event= s_trigger.c index b66b6d235d91..dac3344ee345 100644 --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -804,7 +804,7 @@ int event_trigger_separate_filter(char *param_and_filte= r, char **param, } =20 /** - * event_trigger_alloc - allocate and init event_trigger_data for a trigger + * trigger_data_alloc - allocate and init event_trigger_data for a trigger * @cmd_ops: The event_command operations for the trigger * @cmd: The cmd string * @param: The param string @@ -815,14 +815,14 @@ int event_trigger_separate_filter(char *param_and_fil= ter, char **param, * trigger_ops to assign to the event_trigger_data. @private_data can * also be passed in and associated with the event_trigger_data. * - * Use event_trigger_free() to free an event_trigger_data object. + * Use trigger_data_free() to free an event_trigger_data object. * * Return: The trigger_data object success, NULL otherwise */ -struct event_trigger_data *event_trigger_alloc(struct event_command *cmd_o= ps, - char *cmd, - char *param, - void *private_data) +struct event_trigger_data *trigger_data_alloc(struct event_command *cmd_op= s, + char *cmd, + char *param, + void *private_data) { struct event_trigger_data *trigger_data; const struct event_trigger_ops *trigger_ops; @@ -989,7 +989,7 @@ event_trigger_parse(struct event_command *cmd_ops, return ret; =20 ret =3D -ENOMEM; - trigger_data =3D event_trigger_alloc(cmd_ops, cmd, param, file); + trigger_data =3D trigger_data_alloc(cmd_ops, cmd, param, file); if (!trigger_data) goto out; =20 @@ -1793,7 +1793,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, enable_data->enable =3D enable; enable_data->file =3D event_enable_file; =20 - trigger_data =3D event_trigger_alloc(cmd_ops, cmd, param, enable_data); + trigger_data =3D trigger_data_alloc(cmd_ops, cmd, param, enable_data); if (!trigger_data) { kfree(enable_data); goto out; --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 DDC5A294A0C for ; Fri, 9 May 2025 13:13:02 +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=1746796382; cv=none; b=PlzhvfjUUvE9YNLwctjVipoxiPOg+E0IUVzpoYohOAAmTwyzRCus32Hoo1ztvU9t0L0D4xg6QR8M/Yp3sA2L3g1DQj8w+65QDTzZPalBDTj98LVRGzDuPfV2Z4LZ70Jv1N80d7is+6nxnaHTKLRNJHqcsPunbMX/n9npnm9iQh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796382; c=relaxed/simple; bh=SzPqlg0Eque0YCACbS3nlNWvZVzenw1a+Kzf9qe87js=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=MEJWkAC7SIeORjB7P7O3+QThscUnVOkHLmkL7ioe+2iQsCtY4jm0YhRQlT3SkkAu2qPFgaXa+Jvy48ppp374a+r90OlLcuXOwcQXeCpqFuHwIAcTJ9GYiZDJkul8WRE3f42haTyOKhJCkU2+uMMwndFsvNh8SHGStY5SGcrj5/o= 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 C89F6C4CEEB; Fri, 9 May 2025 13:13:02 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c1o-1SnJ; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131318.200556507@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:17 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi , Miaoqian Lin Subject: [for-next][PATCH 28/31] tracing: Fix error handling in event_trigger_parse() References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miaoqian Lin According to trigger_data_alloc() doc, trigger_data_free() should be used to free an event_trigger_data object. This fixes a mismatch introduced when kzalloc was replaced with trigger_data_alloc without updating the corresponding deallocation calls. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Cc: Mathieu Desnoyers Cc: Tom Zanussi Link: https://lore.kernel.org/20250507145455.944453325@goodmis.org Link: https://lore.kernel.org/20250318112737.4174-1-linmq006@gmail.com Fixes: e1f187d09e11 ("tracing: Have existing event_command.parse() implemen= tations use helpers") Signed-off-by: Miaoqian Lin [ SDR: Changed event_trigger_alloc/free() to trigger_data_alloc/free() ] Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_trigger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_event= s_trigger.c index dac3344ee345..c316badc608b 100644 --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -995,7 +995,7 @@ event_trigger_parse(struct event_command *cmd_ops, =20 if (remove) { event_trigger_unregister(cmd_ops, file, glob+1, trigger_data); - kfree(trigger_data); + trigger_data_free(trigger_data); ret =3D 0; goto out; } @@ -1022,7 +1022,7 @@ event_trigger_parse(struct event_command *cmd_ops, =20 out_free: event_trigger_reset_filter(cmd_ops, trigger_data); - kfree(trigger_data); + trigger_data_free(trigger_data); goto out; } =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 1D5AC294A1B for ; Fri, 9 May 2025 13:13:03 +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=1746796383; cv=none; b=SWYWoa+CSFCQC1RgWbMIhPDyUa0IF8AOnnRLe71u6ODnV/EyxSHLg3p1+Q5A2eZcCw2MvvULyi4geLw5oEsHMhwtXYh+yJGW9Qw6I6qAIzhLM9gUWzujuS2Rv/g/PLOxk7nKIC2W5JqbufneArMSsnmTR4A/RoGnFDH6aYIwmRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796383; c=relaxed/simple; bh=1zmGiOZSZMjt3Jn6dGwz+xn7J6vCjYuQbICTyk0l8Wc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BdGbBRXkYz9uO2fzGlx5E0ZWeV4hCP+GdDBKXfHQJCEUMuol/PHBTBkfQxkVFkoBVNVy/03NKO2TaKtyCc43L12WxiN4sgiPWvTVuUuep40xi5C+HlrvGbqdTX5yrfDl3pxM7kkZtC17cWtck4eQWg8JMBRuOrJYqIv2vLGBq5U= 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 0621EC4CEEE; Fri, 9 May 2025 13:13:03 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c2J-2B6W; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131318.371456142@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:18 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tom Zanussi Subject: [for-next][PATCH 29/31] tracing: Remove unnecessary "goto out" that simply returns ret is trigger code References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt There's several functions that have "goto out;" where the label out is just: out: return ret; Simplify the code by just doing the return in the location and removing all the out labels and jumps. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Tom Zanussi Link: https://lore.kernel.org/20250507145456.121186494@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_trigger.c | 44 +++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_event= s_trigger.c index c316badc608b..fdd1112388e9 100644 --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -552,16 +552,14 @@ static int register_trigger(char *glob, lockdep_assert_held(&event_mutex); =20 list_for_each_entry(test, &file->triggers, list) { - if (test->cmd_ops->trigger_type =3D=3D data->cmd_ops->trigger_type) { - ret =3D -EEXIST; - goto out; - } + if (test->cmd_ops->trigger_type =3D=3D data->cmd_ops->trigger_type) + return -EEXIST; } =20 if (data->ops->init) { ret =3D data->ops->init(data); if (ret < 0) - goto out; + return ret; } =20 list_add_rcu(&data->list, &file->triggers); @@ -572,7 +570,6 @@ static int register_trigger(char *glob, list_del_rcu(&data->list); update_cond_flag(file); } -out: return ret; } =20 @@ -770,7 +767,7 @@ int event_trigger_separate_filter(char *param_and_filte= r, char **param, if (!param_and_filter) { if (param_required) ret =3D -EINVAL; - goto out; + return ret; } =20 /* @@ -781,7 +778,7 @@ int event_trigger_separate_filter(char *param_and_filte= r, char **param, */ if (!param_required && param_and_filter && !isdigit(param_and_filter[0]))= { *filter =3D param_and_filter; - goto out; + return ret; } =20 /* @@ -799,7 +796,6 @@ int event_trigger_separate_filter(char *param_and_filte= r, char **param, if (!**filter) *filter =3D NULL; } -out: return ret; } =20 @@ -991,13 +987,12 @@ event_trigger_parse(struct event_command *cmd_ops, ret =3D -ENOMEM; trigger_data =3D trigger_data_alloc(cmd_ops, cmd, param, file); if (!trigger_data) - goto out; + return ret; =20 if (remove) { event_trigger_unregister(cmd_ops, file, glob+1, trigger_data); trigger_data_free(trigger_data); - ret =3D 0; - goto out; + return 0; } =20 ret =3D event_trigger_parse_num(param, trigger_data); @@ -1017,13 +1012,12 @@ event_trigger_parse(struct event_command *cmd_ops, =20 /* Down the counter of trigger_data or free it if not used anymore */ event_trigger_free(trigger_data); - out: return ret; =20 out_free: event_trigger_reset_filter(cmd_ops, trigger_data); trigger_data_free(trigger_data); - goto out; + return ret; } =20 /** @@ -1057,10 +1051,10 @@ int set_trigger_filter(char *filter_str, s =3D strsep(&filter_str, " \t"); =20 if (!strlen(s) || strcmp(s, "if") !=3D 0) - goto out; + return ret; =20 if (!filter_str) - goto out; + return ret; =20 /* The filter is for the 'trigger' event, not the triggered event */ ret =3D create_event_filter(file->tr, file->event_call, @@ -1104,7 +1098,6 @@ int set_trigger_filter(char *filter_str, ret =3D -ENOMEM; } } - out: return ret; } =20 @@ -1772,7 +1765,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, ret =3D -EINVAL; event_enable_file =3D find_event_file(tr, system, event); if (!event_enable_file) - goto out; + return ret; =20 #ifdef CONFIG_HIST_TRIGGERS hist =3D ((strcmp(cmd, ENABLE_HIST_STR) =3D=3D 0) || @@ -1787,7 +1780,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, =20 enable_data =3D kzalloc(sizeof(*enable_data), GFP_KERNEL); if (!enable_data) - goto out; + return ret; =20 enable_data->hist =3D hist; enable_data->enable =3D enable; @@ -1796,7 +1789,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, trigger_data =3D trigger_data_alloc(cmd_ops, cmd, param, enable_data); if (!trigger_data) { kfree(enable_data); - goto out; + return ret; } =20 if (remove) { @@ -1804,7 +1797,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, kfree(trigger_data); kfree(enable_data); ret =3D 0; - goto out; + return ret; } =20 /* Up the trigger_data count to make sure nothing frees it on failure */ @@ -1834,7 +1827,6 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, goto out_disable; =20 event_trigger_free(trigger_data); - out: return ret; out_disable: trace_event_enable_disable(event_enable_file, 0, 1); @@ -1845,7 +1837,7 @@ int event_enable_trigger_parse(struct event_command *= cmd_ops, event_trigger_free(trigger_data); kfree(enable_data); =20 - goto out; + return ret; } =20 int event_enable_register_trigger(char *glob, @@ -1865,15 +1857,14 @@ int event_enable_register_trigger(char *glob, (test->cmd_ops->trigger_type =3D=3D data->cmd_ops->trigger_type) && (test_enable_data->file =3D=3D enable_data->file)) { - ret =3D -EEXIST; - goto out; + return -EEXIST; } } =20 if (data->ops->init) { ret =3D data->ops->init(data); if (ret < 0) - goto out; + return ret; } =20 list_add_rcu(&data->list, &file->triggers); @@ -1884,7 +1875,6 @@ int event_enable_register_trigger(char *glob, list_del_rcu(&data->list); update_cond_flag(file); } -out: return ret; } =20 --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 458E32951AF for ; Fri, 9 May 2025 13:13:03 +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=1746796383; cv=none; b=ZrbXhgHMSF91RfXIA9149eKsfC19b+OBwyDLjvnb40iN1/spbkWM/1oHKLFFe7IOg66Y5vaX71U2goIErLysoEfzJ/x4teeYxFqeUgIVBwkKoauavEQVsxbWJ6/MhcTaosIK5cjHSTYjcp1hmyt9iHjUAq0/o/uJPhsZyC6bDjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796383; c=relaxed/simple; bh=s/f1WOZINXsqbCEyArw9h0+7djiEJThn/JJePbdtQQc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=l46GgNxID5HeH1OK4n/dagZ+uskoh+SgDocXkLO9RzelXA+aBoOuK404JjiZmyzRJeMAxr5IhUL9fWtoKJiAXA70FqaHn13ghqiXdLjBZFjS6A4kEe9HblPH3KCGwjIhHr6YgOTrTdSPpPB/JqngvULXuPRHMajVQl4nursfHyE= 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 2AA6AC4CEF1; Fri, 9 May 2025 13:13:03 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c2o-2tRf; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131318.540432016@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:19 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 30/31] tracing: Add a helper function to handle the dereference arg in verifier References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Add a helper function called handle_dereference_arg() to replace the logic that is identical in two locations of test_event_printk(). Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250507191703.5dd8a61d@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index fe0ea14d809e..120531268abf 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -400,6 +400,20 @@ static bool process_string(const char *fmt, int len, s= truct trace_event_call *ca return true; } =20 +static void handle_dereference_arg(const char *arg_str, u64 string_flags, = int len, + u64 *dereference_flags, int arg, + struct trace_event_call *call) +{ + if (string_flags & (1ULL << arg)) { + if (process_string(arg_str, len, call)) + *dereference_flags &=3D ~(1ULL << arg); + } else if (process_pointer(arg_str, len, call)) + *dereference_flags &=3D ~(1ULL << arg); + else + pr_warn("TRACE EVENT ERROR: Bad dereference argument: '%.*s'\n", + len, arg_str); +} + /* * Examine the print fmt of the event looking for unsafe dereference * pointers using %p* that could be recorded in the trace event and @@ -563,11 +577,9 @@ static void test_event_printk(struct trace_event_call = *call) } =20 if (dereference_flags & (1ULL << arg)) { - if (string_flags & (1ULL << arg)) { - if (process_string(fmt + start_arg, e - start_arg, call)) - dereference_flags &=3D ~(1ULL << arg); - } else if (process_pointer(fmt + start_arg, e - start_arg, call)) - dereference_flags &=3D ~(1ULL << arg); + handle_dereference_arg(fmt + start_arg, string_flags, + e - start_arg, + &dereference_flags, arg, call); } =20 start_arg =3D i; @@ -578,11 +590,9 @@ static void test_event_printk(struct trace_event_call = *call) } =20 if (dereference_flags & (1ULL << arg)) { - if (string_flags & (1ULL << arg)) { - if (process_string(fmt + start_arg, i - start_arg, call)) - dereference_flags &=3D ~(1ULL << arg); - } else if (process_pointer(fmt + start_arg, i - start_arg, call)) - dereference_flags &=3D ~(1ULL << arg); + handle_dereference_arg(fmt + start_arg, string_flags, + i - start_arg, + &dereference_flags, arg, call); } =20 /* --=20 2.47.2 From nobody Wed Dec 17 08:54:24 2025 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 96F5B2951D4 for ; Fri, 9 May 2025 13:13:03 +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=1746796383; cv=none; b=S0fRH9Mea9hSD/joAznZFVrKMGpPfz6LVziyvbirw2D6NPZG0PP+KTaekDgYlu5hN31M9NbTaYjcZf/zk3pjRvl+i0vuR/+A4gxkS9vli6WKVP/dgiHEwJNJFzLnoqW139XXUI+rEfZGeY6Rmv7ZkfVX1IKl7e7MBYZiJs3umBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746796383; c=relaxed/simple; bh=jxnyDtgzCCeJmHux/euXLxxYH66XnwzobqV9aOHStsU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=krecqRNEwlkVhgoLeEIzeHUTG1xHXvWMQyd27KgNQp2/LPfQGhZSFld8gOOenPHf/NbIkcoo0LALTskiVm6GrOI/tacblrAmZo6VVOIG23C0ynCg/luzscfJXfzQ1wrSCpjRSjJyZxu5JXbr6IPm9h09JXpHQpWKw6uXLI8M9jw= 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 56430C4CEF2; Fri, 9 May 2025 13:13:03 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uDNXS-00000002c3J-3ccg; Fri, 09 May 2025 09:13:18 -0400 Message-ID: <20250509131318.712657970@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 09 May 2025 09:13:20 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 31/31] tracing: Allow the top level trace_marker to write into another instances References: <20250509131249.340302366@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt There are applications that have it hard coded to write into the top level trace_marker instance (/sys/kernel/tracing/trace_marker). This can be annoying if a profiler is using that instance for other work, or if it needs all writes to go into a new instance. A new option is created called "copy_trace_marker". By default, the top level has this set, as that is the default buffer that writing into the top level trace_marker file will go to. But now if an instance is created and sets this option, all writes into the top level trace_marker will also be written into that instance buffer just as if an application were to write into the instance's trace_marker file. If the top level instance disables this option, then writes to its own trace_marker and trace_marker_raw files will not go into its buffer. If no instance has this option set, then the write will return an error and errno will contain ENODEV. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250508095639.39f84eda@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/ftrace.rst | 13 +++ kernel/trace/trace.c | 144 ++++++++++++++++++++++++++------- kernel/trace/trace.h | 2 + 3 files changed, 128 insertions(+), 31 deletions(-) diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst index c9e88bf65709..af66a05e18cc 100644 --- a/Documentation/trace/ftrace.rst +++ b/Documentation/trace/ftrace.rst @@ -1205,6 +1205,19 @@ Here are the available options: default instance. The only way the top level instance has this flag cleared, is by it being set in another instance. =20 + copy_trace_marker + If there are applications that hard code writing into the top level + trace_marker file (/sys/kernel/tracing/trace_marker or trace_marker_raw), + and the tooling would like it to go into an instance, this option can + be used. Create an instance and set this option, and then all writes + into the top level trace_marker file will also be redirected into this + instance. + + Note, by default this option is set for the top level instance. If it + is disabled, then writes to the trace_marker or trace_marker_raw files + will not be written into the top level file. If no instance has this + option set, then a write will error with the errno of ENODEV. + annotate It is sometimes confusing when the CPU buffers are full and one CPU buffer had a lot of events recently, thus diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 0cd681516438..cf51c30b137f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -493,7 +493,8 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_export); TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | \ TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | \ TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | \ - TRACE_ITER_HASH_PTR | TRACE_ITER_TRACE_PRINTK) + TRACE_ITER_HASH_PTR | TRACE_ITER_TRACE_PRINTK | \ + TRACE_ITER_COPY_MARKER) =20 /* trace_options that are only supported by global_trace */ #define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK | \ @@ -501,7 +502,8 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_export); =20 /* trace_flags that are default zero for instances */ #define ZEROED_TRACE_FLAGS \ - (TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK | TRACE_ITER_TRACE_PRINTK) + (TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK | TRACE_ITER_TRACE_PRINTK |= \ + TRACE_ITER_COPY_MARKER) =20 /* * The global_trace is the descriptor that holds the top-level tracing @@ -513,6 +515,9 @@ static struct trace_array global_trace =3D { =20 static struct trace_array *printk_trace =3D &global_trace; =20 +/* List of trace_arrays interested in the top level trace_marker */ +static LIST_HEAD(marker_copies); + static __always_inline bool printk_binsafe(struct trace_array *tr) { /* @@ -534,6 +539,28 @@ static void update_printk_trace(struct trace_array *tr) tr->trace_flags |=3D TRACE_ITER_TRACE_PRINTK; } =20 +/* Returns true if the status of tr changed */ +static bool update_marker_trace(struct trace_array *tr, int enabled) +{ + lockdep_assert_held(&event_mutex); + + if (enabled) { + if (!list_empty(&tr->marker_list)) + return false; + + list_add_rcu(&tr->marker_list, &marker_copies); + tr->trace_flags |=3D TRACE_ITER_COPY_MARKER; + return true; + } + + if (list_empty(&tr->marker_list)) + return false; + + list_del_init(&tr->marker_list); + tr->trace_flags &=3D ~TRACE_ITER_COPY_MARKER; + return true; +} + void trace_set_ring_buffer_expanded(struct trace_array *tr) { if (!tr) @@ -5220,7 +5247,8 @@ int set_tracer_flag(struct trace_array *tr, unsigned = int mask, int enabled) { if ((mask =3D=3D TRACE_ITER_RECORD_TGID) || (mask =3D=3D TRACE_ITER_RECORD_CMD) || - (mask =3D=3D TRACE_ITER_TRACE_PRINTK)) + (mask =3D=3D TRACE_ITER_TRACE_PRINTK) || + (mask =3D=3D TRACE_ITER_COPY_MARKER)) lockdep_assert_held(&event_mutex); =20 /* do nothing if flag is already set */ @@ -5251,6 +5279,9 @@ int set_tracer_flag(struct trace_array *tr, unsigned = int mask, int enabled) } } =20 + if (mask =3D=3D TRACE_ITER_COPY_MARKER) + update_marker_trace(tr, enabled); + if (enabled) tr->trace_flags |=3D mask; else @@ -7134,11 +7165,9 @@ tracing_free_buffer_release(struct inode *inode, str= uct file *filp) =20 #define TRACE_MARKER_MAX_SIZE 4096 =20 -static ssize_t -tracing_mark_write(struct file *filp, const char __user *ubuf, - size_t cnt, loff_t *fpos) +static ssize_t write_marker_to_buffer(struct trace_array *tr, const char _= _user *ubuf, + size_t cnt, unsigned long ip) { - struct trace_array *tr =3D filp->private_data; struct ring_buffer_event *event; enum event_trigger_type tt =3D ETT_NONE; struct trace_buffer *buffer; @@ -7152,18 +7181,6 @@ tracing_mark_write(struct file *filp, const char __u= ser *ubuf, #define FAULTED_STR "" #define FAULTED_SIZE (sizeof(FAULTED_STR) - 1) /* '\0' is already accounte= d for */ =20 - if (tracing_disabled) - return -EINVAL; - - if (!(tr->trace_flags & TRACE_ITER_MARKERS)) - return -EINVAL; - - if ((ssize_t)cnt < 0) - return -EINVAL; - - if (cnt > TRACE_MARKER_MAX_SIZE) - cnt =3D TRACE_MARKER_MAX_SIZE; - meta_size =3D sizeof(*entry) + 2; /* add '\0' and possible '\n' */ again: size =3D cnt + meta_size; @@ -7196,7 +7213,7 @@ tracing_mark_write(struct file *filp, const char __us= er *ubuf, } =20 entry =3D ring_buffer_event_data(event); - entry->ip =3D _THIS_IP_; + entry->ip =3D ip; =20 len =3D __copy_from_user_inatomic(&entry->buf, ubuf, cnt); if (len) { @@ -7229,18 +7246,12 @@ tracing_mark_write(struct file *filp, const char __= user *ubuf, } =20 static ssize_t -tracing_mark_raw_write(struct file *filp, const char __user *ubuf, +tracing_mark_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *fpos) { struct trace_array *tr =3D filp->private_data; - struct ring_buffer_event *event; - struct trace_buffer *buffer; - struct raw_data_entry *entry; - ssize_t written; - int size; - int len; - -#define FAULT_SIZE_ID (FAULTED_SIZE + sizeof(int)) + ssize_t written =3D -ENODEV; + unsigned long ip; =20 if (tracing_disabled) return -EINVAL; @@ -7248,10 +7259,42 @@ tracing_mark_raw_write(struct file *filp, const cha= r __user *ubuf, if (!(tr->trace_flags & TRACE_ITER_MARKERS)) return -EINVAL; =20 - /* The marker must at least have a tag id */ - if (cnt < sizeof(unsigned int)) + if ((ssize_t)cnt < 0) return -EINVAL; =20 + if (cnt > TRACE_MARKER_MAX_SIZE) + cnt =3D TRACE_MARKER_MAX_SIZE; + + /* The selftests expect this function to be the IP address */ + ip =3D _THIS_IP_; + + /* The global trace_marker can go to multiple instances */ + if (tr =3D=3D &global_trace) { + guard(rcu)(); + list_for_each_entry_rcu(tr, &marker_copies, marker_list) { + written =3D write_marker_to_buffer(tr, ubuf, cnt, ip); + if (written < 0) + break; + } + } else { + written =3D write_marker_to_buffer(tr, ubuf, cnt, ip); + } + + return written; +} + +static ssize_t write_raw_marker_to_buffer(struct trace_array *tr, + const char __user *ubuf, size_t cnt) +{ + struct ring_buffer_event *event; + struct trace_buffer *buffer; + struct raw_data_entry *entry; + ssize_t written; + int size; + int len; + +#define FAULT_SIZE_ID (FAULTED_SIZE + sizeof(int)) + size =3D sizeof(*entry) + cnt; if (cnt < FAULT_SIZE_ID) size +=3D FAULT_SIZE_ID - cnt; @@ -7282,6 +7325,40 @@ tracing_mark_raw_write(struct file *filp, const char= __user *ubuf, return written; } =20 +static ssize_t +tracing_mark_raw_write(struct file *filp, const char __user *ubuf, + size_t cnt, loff_t *fpos) +{ + struct trace_array *tr =3D filp->private_data; + ssize_t written =3D -ENODEV; + +#define FAULT_SIZE_ID (FAULTED_SIZE + sizeof(int)) + + if (tracing_disabled) + return -EINVAL; + + if (!(tr->trace_flags & TRACE_ITER_MARKERS)) + return -EINVAL; + + /* The marker must at least have a tag id */ + if (cnt < sizeof(unsigned int)) + return -EINVAL; + + /* The global trace_marker_raw can go to multiple instances */ + if (tr =3D=3D &global_trace) { + guard(rcu)(); + list_for_each_entry_rcu(tr, &marker_copies, marker_list) { + written =3D write_raw_marker_to_buffer(tr, ubuf, cnt); + if (written < 0) + break; + } + } else { + written =3D write_raw_marker_to_buffer(tr, ubuf, cnt); + } + + return written; +} + static int tracing_clock_show(struct seq_file *m, void *v) { struct trace_array *tr =3D m->private; @@ -9775,6 +9852,7 @@ trace_array_create_systems(const char *name, const ch= ar *systems, INIT_LIST_HEAD(&tr->events); INIT_LIST_HEAD(&tr->hist_vars); INIT_LIST_HEAD(&tr->err_log); + INIT_LIST_HEAD(&tr->marker_list); =20 #ifdef CONFIG_MODULES INIT_LIST_HEAD(&tr->mod_events); @@ -9934,6 +10012,9 @@ static int __remove_instance(struct trace_array *tr) if (printk_trace =3D=3D tr) update_printk_trace(&global_trace); =20 + if (update_marker_trace(tr, 0)) + synchronize_rcu(); + tracing_set_nop(tr); clear_ftrace_function_probes(tr); event_trace_del_tracer(tr); @@ -10999,6 +11080,7 @@ __init static int tracer_alloc_buffers(void) INIT_LIST_HEAD(&global_trace.events); INIT_LIST_HEAD(&global_trace.hist_vars); INIT_LIST_HEAD(&global_trace.err_log); + list_add(&global_trace.marker_list, &marker_copies); list_add(&global_trace.list, &ftrace_trace_arrays); =20 apply_trace_boot_options(); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 86e9d7dcddba..bd084953a98b 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -403,6 +403,7 @@ struct trace_array { struct trace_options *topts; struct list_head systems; struct list_head events; + struct list_head marker_list; struct trace_event_file *trace_marker_file; cpumask_var_t tracing_cpumask; /* only trace on set CPUs */ /* one per_cpu trace_pipe can be opened by only one user */ @@ -1384,6 +1385,7 @@ extern int trace_get_user(struct trace_parser *parser= , const char __user *ubuf, C(MARKERS, "markers"), \ C(EVENT_FORK, "event-fork"), \ C(TRACE_PRINTK, "trace_printk_dest"), \ + C(COPY_MARKER, "copy_trace_marker"),\ C(PAUSE_ON_TRACE, "pause-on-trace"), \ C(HASH_PTR, "hash-ptr"), /* Print hashed pointer */ \ FUNCTION_FLAGS \ --=20 2.47.2