From nobody Sat Feb 7 23:12:08 2026 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 CD7B31EB5DB; Fri, 2 May 2025 20:53:48 +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=1746219228; cv=none; b=BiL3va4kX6hI0hXv9HzCkI+eonzQF9yz6pm5+sbUZtvbD2Pt7GIYc7+yD8Uy3yHFwG8fFE6KXbjMYw1ZclcpzawXL09Gmp028tZNbWRjcrSndqW33CiJy6oxpBNki7qkAa5reIiMxxXA3RIgPRzMNWYvswcHqKd+XXDcA6S9gjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219228; c=relaxed/simple; bh=eGoXC6PxV7+R1ceOCIV5HnJX5yRFgYWLtD6ouKR5GnQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ARQoUxtbSrYCwYu/nIBMh8gvpvi0HXSuxtPQb6ql0HNJx4nvRdvL6Ba2ayCcIzT4DHS7Or27B0+qkrRNPRW8vZ65BRvbsV5KM06BSLQk9WOmE3EW11WavkKMAzDzSYAsp/IgahJg5nUL+8sMfu89NHLovCqEi4UM3v0Z248Z3Bc= 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 63A9BC4CEE9; Fri, 2 May 2025 20:53:48 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-0000000069d-0Sj6; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205347.961733858@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:48 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 01/12] tracing/mmiotrace: Remove reference to unused per CPU data pointer References: <20250502205147.283272733@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. 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 Sat Feb 7 23:12:08 2026 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 2AB7E20296A; Fri, 2 May 2025 20:53:48 +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=1746219229; cv=none; b=ixUuGTT+n14DzQ7g34yD65+EbLc8Sp1xQE7hoHCVVxqCiMGMfUmKjCm9m50cGtFeDMJJoFV/zB+1rxXqTGsAxRMO1VX5i662JlVFnY99opDqTz07S/5Y3qCV1pqQpme2IUgrhFsjmvlNYRMUMUQenGkgxF0kED1j3iimA0aJ+gQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=XN5M+G+GG6rlRQyIqM1WZQZvm+6qsb8A6OZxP+hWE8s=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VJ7jmUc13RVl41XWcmepKDK6h2VE2OhPMmsNDD/rE1DWXJxBHoy3xAQ025UCXybS5GAO9y7asVU6Bt6iYC0SJER33q+0Mbo3aQoGkv8Fl1b0l85OFOjNEPQurMGRANgYnw/wkbOEhB2CKd4RXIwPBc/B6jKPn3/5w0BopevNhCE= 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 903EEC4CEF1; Fri, 2 May 2025 20:53:48 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-000000006A8-1BE0; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205348.131916206@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:49 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 02/12] tracing: Do not bother setting "disabled" field for ftrace_dump_one() References: <20250502205147.283272733@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. The code already calls tracer_tracing_off() which disables the ring buffer, there's no reason to use the "disabled" flags. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8ddf6b17215c..bae32778b292 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10445,7 +10445,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. @@ -10462,10 +10462,6 @@ 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); - } - old_userobj =3D tr->trace_flags & TRACE_ITER_SYM_USEROBJ; =20 /* don't look at user memory in panic mode */ @@ -10523,9 +10519,6 @@ 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); - } local_irq_restore(flags); } =20 --=20 2.47.2 From nobody Sat Feb 7 23:12:08 2026 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 39D2F20297D; Fri, 2 May 2025 20:53:48 +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=1746219229; cv=none; b=I4+S9fx+LTzacBEXOMnuGWg4KNhURICvD8l4LXKYrqv0tFHmap8OhuCCIozJWJEPOHHCAMNFj2oTDXqGU0Iah4AyVSlYktFDl9yIqOAYo23F235bRY60upYwWybM+ZD9wVcQS6xmRqMNRyYdhP3wk5TX/yR68+wIRGmmaMR3qx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=TqkD8LxtVBklZh0dnSpjx7PjTTWwl2OLh6qRcV+8HgA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=bCnydG+tREpgIwXvoVKgF7OppdeFcSaWkledkJMyK1/I9CPSLnEIQo5YUruXxT2xaAPLRI94DtjS49Wkm2cB+u01ftVC0dVmJCtZCmNsjF+cZo7+sbllfHd6Pb0ugIc0yo4SDbgtKxHnZ2NdGbBiSFj9yWnsXZJIT0Shjpa1Yb8= 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 D19FCC4CEF2; Fri, 2 May 2025 20:53:48 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-000000006Ac-1tfM; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205348.303564071@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 03/12] ftrace: Do not bother checking per CPU "disabled" flag References: <20250502205147.283272733@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. 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 Sat Feb 7 23:12:08 2026 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 EE9D11FFC67; Fri, 2 May 2025 20:53:48 +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=1746219229; cv=none; b=E+1iY37GiwXR3fFMTFnxIrFttxtW68lz8dUjYw3CteSagEFJPUhQrRvXq06DB5iW61DxfsjAXz6X89q7TMxhGe5VbNTr3mCvqE5BOIj8JLJqf/UKUvRvQuQf6R2arJy5Dxu9AIG0AbkdPg42CLrQfCx+jzXKocIRIeKwUtEC+Ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=RD0ncGsvrCJ0pZLeWa6ErfBpjmRnol++5MfNHvNqgks=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Uaov5Rkz7nJkt6v2AavEDVLhYUtuvPGTtJgllZE+mhCbDeLD5YFYuTh12wh7onkn2UPveFVmFUgkBET+NA0y9DpIj85gU2S3EvnL9+9QfvKFQYi6rizsvTtVudeL079l71xecDLABFDojk/m4ZiPs0EEdSggDoJDBl7ADsHJX+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 D19CAC4CEED; Fri, 2 May 2025 20:53:48 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-000000006B6-2bsw; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205348.472044554@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 04/12] tracing: Just use this_cpu_read() to access ignore_pid References: <20250502205147.283272733@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. 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 Sat Feb 7 23:12:08 2026 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 26682202961; Fri, 2 May 2025 20:53:49 +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=1746219229; cv=none; b=l4osMOI64T1yA3oT/CPQlqKfuuJLOPOIpytMaERCTsBTioAXuZAxaNmvQSRaDCRWVg3SEmWCGTEeCY63fMshdItmL+6YRL7WDYiZpA2fiF9DBlpY6roZXXCWr1DPkzqopnErzgTDansmirPEsrJ4ozvBy3ZVMCwOyZlhMjMoC0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=UhlkJQmGdRqpLD2EEhmHlUnthvoNi84W9rp7qzGQuxc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=peFeWj7i+jR+agsMYiMwevPi0e/U3BHLDDB6yok+q4vC5sOjvKQCDQ0V6Fv+xCkDIpkJsWOZUzwxg7vMGHkm/Y3FUgb05fytLGSsUtlokmuYSQP7+n3T1+U1jPlK7XVeOoFLGQFT49/JyTfkFjaOnGvutRLfeiGu1jnzw56rErU= 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 0B981C4CEE4; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-000000006Ba-3J83; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205348.643055437@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [PATCH 05/12] tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled References: <20250502205147.283272733@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: Daniel Thompson Cc: Douglas Anderson Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_kdb.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 1e72d20b3c2f..b5cf3fdde8cb 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -120,9 +120,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_off(iter.tr); =20 /* A negative skip_entries means skip all but the last entries */ if (skip_entries < 0) { @@ -135,9 +133,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_on(iter.tr); =20 kdb_trap_printk--; =20 --=20 2.47.2 From nobody Sat Feb 7 23:12:08 2026 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 46FB5202C3B; Fri, 2 May 2025 20:53:49 +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=1746219229; cv=none; b=WoqqIZzFH/wY3nnA7F15TSW8YnHQLknh0HYJS1bDcfhW799tOs9WuJ8a+4wxS2RnjNGhmRcf4195sjUSCnsn5YIr1UhwvHmX4ImeLQldA0wY7c34QvzW+DxJVge4Vz83kZGkX35Rqyyc1hjFCNI7tnwGZt6lpLRa0dmJbIU5fGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=PD0PEZGjhOGV9Ehhf7jbkf7/uE2maQPnTBmxaJdraT4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=F5bD+Q/key39EkL6ZCI/H642pwCwHUzzTeU7ib8Jbb3XRwFAL+JrnP0NxkQvPttDwVlQ+Lr1500G/aOsfxZigUPMA2PzBmgGGogsBuT1TJRWiOAKILhYVCyVId/f5A80B4vAD+DS7soafMsQkvLM1n2VqS1kBG+Kzy/lFaHj594= 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 318E3C4CEF5; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOG-000000006C4-405A; Fri, 02 May 2025 16:53:48 -0400 Message-ID: <20250502205348.809872652@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 06/12] ftrace: Do not disabled function graph based on "disabled" field References: <20250502205147.283272733@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. 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 Sat Feb 7 23:12:08 2026 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 E9EA220D4F8; Fri, 2 May 2025 20:53:49 +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=1746219230; cv=none; b=ql4mbb7gKSaGDzj7yl7j6Mla+5dMXe+Oov+r3x4Iohcd2eX0d1TVXPnk8W8iNYxH3TyVqSrhOpRZAI9cMkrd5rdy6l3f6buHXxdyR6zWiE07+bSwpj3y0QruHLFgYY+gK1AWvht1EYF+hvE2DFTm6oM9WvX0jKVH1/aXzLtmiNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219230; c=relaxed/simple; bh=KBSu9SzGK7jFP/cW6FtoJKxk4mpVMjFrcGbCGflAdck=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=CWtYh/90Twytbr5J2yEkmTcvY/0VWu2keyKAYwiEE1RT3/SVCWcgq1R9DJMEzrbGfttQEHG6EuJuOLHFivsQUlgopUcuweEP90ym9rgtLZYCtpa1CcAzMxAo57QZx3nRoJ6dwSIupdknneD8/ynDzVDuZyN9ntBHxB6/ZideEm4= 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 617B9C4CEE4; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006Ca-0Tst; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205348.972501388@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:54 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 07/12] tracing: Do not use per CPU array_buffer.data->disabled for cpumask References: <20250502205147.283272733@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. 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 bae32778b292..8cee71683fe3 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5048,7 +5048,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); @@ -5056,7 +5055,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 Sat Feb 7 23:12:08 2026 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 96ECD20B804; Fri, 2 May 2025 20:53:49 +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=1746219229; cv=none; b=KhxPPqNM/7LIRyPzO9UZuPlCF+QCANB/zn3P7UHf1JSd/lNXPuB3FQsE/kOKBongY6s1MEYBTFb/LCbHgvWzscF2x2swi5RdbKQC5znjz2l2ozxfmaaO+B/bjNiHd79fpNEWvGahy9DhALT80ICR71BJSDiPd+C+oqKOtP66tbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=pId5/Jcxvem2yAo/sd/QFa3MIyaShk8NSYQziKIW174=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cNdyLm4KCFbPuZEpboHZkV0Imh4IDTq5WUKpx2l3GKasrsRRodjeIsvHjkQWN/SevmvHVnDkEz/42L9MgRawpgt8LeJoyQ0yP8RnlspAqGRin05PrxHe+0L021owznw/LPXsvCk0d7cb+wUTJ06RGvCVPv2/WE1+knzENq7nDHU= 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 7F5D6C4AF0C; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006D4-1AFQ; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205349.134949967@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:55 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 08/12] ring-buffer: Add ring_buffer_record_is_on_cpu() References: <20250502205147.283272733@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. 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 79be1995db44..294d92179a02 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -671,6 +671,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 Sat Feb 7 23:12:08 2026 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 CC21E20C48C; Fri, 2 May 2025 20:53:49 +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=1746219229; cv=none; b=PfyqwYt4LSOYss8u4KN13di35uvdmWIa0jNQuX1UCGr2PFzaH1wTM6mK2U1KRF/Xibh0Uw4QugrAPlWvyI0qJ6VxD7Hlk/Wt390Gg+fi/rmDmZw6W1I5lF+W+lu3A2NWgPd+h/Jm0780yUSHZsAj62XWSdDRCg6zenxfXI2fZRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219229; c=relaxed/simple; bh=cETHAQ1zqWANjfr1MjlhdGt4/vZ0FNpoIBmdpt8H8+w=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=MRSltqHYdKeceObxq14kQDbOPI3/OJ4frSYYKTfXtO0PuzXiJYH5emN37bqTXTI+wdyumVFQeL+VkOOBfiOXO7l5a8pHJBayPlVPDZYQCydsab9lLTx3BUzgD7eHGX8F2XEsmQqaCMrH7UnkyMqB1jAjK8mLb6jmr0PFeEXkNc4= 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 B7B5FC4CEEF; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006DZ-1sYm; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205349.299144667@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:56 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 09/12] tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field References: <20250502205147.283272733@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. 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..2a1a06eb7939 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_process_id())) goto out; =20 trace_ctx =3D tracing_gen_ctx_flags(flags); --=20 2.47.2 From nobody Sat Feb 7 23:12:08 2026 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 00AE820D516; Fri, 2 May 2025 20:53:49 +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=1746219230; cv=none; b=aVmmcD51/C6ggfjSUm8wLkpV/izJAYJFYHqVPi/7rx9BQ0WS1PBZ8KuaDb69MBlmq9ut/mzwOcOdRtViNKILv0ykrX2ZotVgOvRI93JcXMIUb+UB00yHnrcUYABgtKVFKFC8Ov7do/xi78ztB1eR+LZwAmtph76unWWW7thOEPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219230; c=relaxed/simple; bh=jd3UAWytv+v+AL94/BjSW2Z/6zLjZgVNuYwZCJtb6TU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pcl7z3U1C7qcP4ha+B23yZLBGIhQWkijCMG7DcKHceek7jHvRHracXMdoMhjR2Q+Wuc6wqyJJfJGy11BlUGi4kDj/hI7FkT6VaGu1eVn/bZQ9G3Ajtinhsd52gIrwRTl1/GqKRDnRXv2mlg5HFM2ZShmdjgx6tK8s/GUv4MP/SU= 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 D330BC4CEF3; Fri, 2 May 2025 20:53:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006E5-2Wyg; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205349.468501496@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 10/12] tracing: Convert the per CPU "disabled" counter to local from atomic References: <20250502205147.283272733@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. 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 294d92179a02..646fb5c1066e 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 Sat Feb 7 23:12:08 2026 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 14F6F20E01E; Fri, 2 May 2025 20:53:50 +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=1746219230; cv=none; b=aQnxy+PbQbRs87ttZLThYxZtRM4sSw1Ut2hfVwc3YUmdy4VEeUxJnUCC6P01dwIbSgPjXL7zp+sjsUTiVWJe6rDDM/jQcvXbyeXU7BmntKKJI9kx4HsSU+qlUxgzB6BHoSRvWDZ1aRK71fsRmXl3BCMSsdWGl4d1b27CZtPU6Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219230; c=relaxed/simple; bh=LfbYZrkrwSHhr03nwF7TAzWMZMSOM7lGFrPKQJo3J/Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=P+AD74qqy4Qes0Mj85/yP/aBYdIDIvtHWp4MVQ6GxUQfkzNRKo8gBphWxTUiP9SlLzzwFeZrMPavK+INP0t0I/cVFu68BBrDnxW46KEzvZLu26HQnfj57Wmq/2FM8BuiwAIFJxuGC+u73YzdOKLwb/Dj+Qfi8dP3vUTNWO1GjrA= 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 024F2C4CEF4; Fri, 2 May 2025 20:53:50 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006Ea-3Bqw; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205349.623319847@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:58 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 11/12] tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer References: <20250502205147.283272733@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. 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 Sat Feb 7 23:12:08 2026 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 4ED03211A05; Fri, 2 May 2025 20:53:50 +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=1746219230; cv=none; b=coHkn/kwrGpSNaYT6hTfZIHiio4XbR0BQbz3Za+tsDEf7/+SwOWLBHCg5jghnhkKuMbSgSvWFoDCJlGMWpW1OsvaavAO6defUjUYFEuyyeA+29/jVGhtMyJjSi7ZgYLEXqlXEIyLOSyagoB5QKki9Hm0OQPuf9h2HzCIj/TCJAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746219230; c=relaxed/simple; bh=ntjYQudrFrlV6oqiTHASZOhqo5CjgZj8Hu+aw8K3usg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=mMQVZ5ITtQM3VamlKYqqtWUmehxZdSG2Zm3dloF/HI9rd83S9n9Er+NPkA9fvL6CbyupdjjZ3om+Be8IfK5sNxzCtSVsIHUekIib3S3DtUez3CT4XCMRDp5ku1YWpBorqhmdyO70UiJg9Rlyd4eS2OBfD13YM1kYze6sbDQb86I= 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 2FB3FC4CEF1; Fri, 2 May 2025 20:53:50 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uAxOH-000000006F5-3rJ6; Fri, 02 May 2025 16:53:49 -0400 Message-ID: <20250502205349.780984353@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 02 May 2025 16:51:59 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH 12/12] tracing: Remove unused buffer_page field from trace_array_cpu structure References: <20250502205147.283272733@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. 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 646fb5c1066e..499f8d294861 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