public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids
@ 2026-03-03  2:35 Steven Rostedt
  2026-03-03  4:17 ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2026-03-03  2:35 UTC (permalink / raw)
  To: LKML, Linux Trace Kernel; +Cc: Masami Hiramatsu, Mathieu Desnoyers

From: Steven Rostedt <rostedt@goodmis.org>

When function trace PID filtering is enabled, the function tracer will
attach a callback to the fork tracepoint as well as the exit tracepoint
that will add the forked child PID to the PID filtering list as well as
remove the PID that is exiting.

Commit a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of
__DO_TRACE_CALL() with SRCU-fast") removed the disabling of preemption
when calling tracepoint callbacks.

The callbacks used for the PID filtering accounting depended on preemption
being disabled, and now the trigger a "suspicious RCU usage" warning message.

Make them explicitly disable preemption.

Fixes: a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1ce17c8af409..5274e0cab8f3 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -8611,6 +8611,7 @@ ftrace_pid_follow_sched_process_fork(void *data,
 	struct trace_pid_list *pid_list;
 	struct trace_array *tr = data;
 
+	guard(preempt)();
 	pid_list = rcu_dereference_sched(tr->function_pids);
 	trace_filter_add_remove_task(pid_list, self, task);
 
@@ -8624,6 +8625,7 @@ ftrace_pid_follow_sched_process_exit(void *data, struct task_struct *task)
 	struct trace_pid_list *pid_list;
 	struct trace_array *tr = data;
 
+	guard(preempt)();
 	pid_list = rcu_dereference_sched(tr->function_pids);
 	trace_filter_add_remove_task(pid_list, NULL, task);
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids
  2026-03-03  2:35 [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids Steven Rostedt
@ 2026-03-03  4:17 ` Masami Hiramatsu
  2026-03-03 14:39   ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2026-03-03  4:17 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers

On Mon, 2 Mar 2026 21:35:46 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> When function trace PID filtering is enabled, the function tracer will
> attach a callback to the fork tracepoint as well as the exit tracepoint
> that will add the forked child PID to the PID filtering list as well as
> remove the PID that is exiting.
> 
> Commit a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of
> __DO_TRACE_CALL() with SRCU-fast") removed the disabling of preemption
> when calling tracepoint callbacks.
> 
> The callbacks used for the PID filtering accounting depended on preemption
> being disabled, and now the trigger a "suspicious RCU usage" warning message.
> 
> Make them explicitly disable preemption.
> 

Hmm, we still have another "WARNING: suspicious RCU usage" 

[37] event tracing - restricts events based on pid notrace filtering[  155.874095] 
[  155.874869] =============================
[  155.876037] WARNING: suspicious RCU usage
[  155.877287] 7.0.0-rc1-00004-g8cd473a19bc7 #7 Not tainted
[  155.879263] -----------------------------
[  155.882839] kernel/trace/trace_events.c:1057 suspicious rcu_dereference_check() usage!
[  155.889281] 
[  155.889281] other info that might help us debug this:
[  155.889281] 
[  155.894519] 
[  155.894519] rcu_scheduler_active = 2, debug_locks = 1
[  155.898068] no locks held by ftracetest/4364.
[  155.900524] 
[  155.900524] stack backtrace:
[  155.902645] CPU: 1 UID: 0 PID: 4364 Comm: ftracetest Not tainted 7.0.0-rc1-00004-g8cd473a19bc7 #7 PREEMPT(lazy) 
[  155.902648] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014
[  155.902651] Call Trace:
[  155.902655]  <TASK>
[  155.902659]  dump_stack_lvl+0x67/0x90
[  155.902665]  lockdep_rcu_suspicious+0x154/0x1a0
[  155.902672]  event_filter_pid_sched_process_fork+0x9a/0xd0
[  155.902678]  kernel_clone+0x367/0x3a0
[  155.902689]  __x64_sys_clone+0x116/0x140
[  155.902696]  do_syscall_64+0x158/0x460
[  155.902700]  ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  155.902702]  ? trace_irq_disable+0x1d/0xc0
[  155.902709]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  155.902711] RIP: 0033:0x4697c3
[  155.902716] Code: 1f 84 00 00 00 00 00 64 48 8b 04 25 10 00 00 00 45 31 c0 31 d2 31 f6 bf 11 00 20 01 4c 8d 90 d0 02 00 00 b8 38 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 89 c2 85 c0 75 2c 64 48 8b 04 25 10 00 00
[  155.902718] RSP: 002b:00007ffc41150428 EFLAGS: 00000246 ORIG_RAX: 0000000000000038
[  155.902721] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004697c3
[  155.902722] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000001200011
[  155.902724] RBP: 0000000000000000 R08: 0000000000000000 R09: 000000003fccf990
[  155.902725] R10: 000000003fccd690 R11: 0000000000000246 R12: 0000000000000001
[  155.902726] R13: 000000003fce8103 R14: 0000000000000001 R15: 0000000000000000
[  155.902733]  </TASK>
[  155.902747] 

It seems we need 2 more guard()s.

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 9928da636c9d..3b3aaf4831e9 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1039,6 +1039,7 @@ event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
 	struct trace_pid_list *pid_list;
 	struct trace_array *tr = data;
 
+	guard(preempt)();
 	pid_list = rcu_dereference_raw(tr->filtered_pids);
 	trace_filter_add_remove_task(pid_list, NULL, task);
 
@@ -1054,6 +1055,7 @@ event_filter_pid_sched_process_fork(void *data,
 	struct trace_pid_list *pid_list;
 	struct trace_array *tr = data;
 
+	guard(preempt)();
 	pid_list = rcu_dereference_sched(tr->filtered_pids);
 	trace_filter_add_remove_task(pid_list, self, task);
 

Thanks,

> Fixes: a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ftrace.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 1ce17c8af409..5274e0cab8f3 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -8611,6 +8611,7 @@ ftrace_pid_follow_sched_process_fork(void *data,
>  	struct trace_pid_list *pid_list;
>  	struct trace_array *tr = data;
>  
> +	guard(preempt)();
>  	pid_list = rcu_dereference_sched(tr->function_pids);
>  	trace_filter_add_remove_task(pid_list, self, task);
>  
> @@ -8624,6 +8625,7 @@ ftrace_pid_follow_sched_process_exit(void *data, struct task_struct *task)
>  	struct trace_pid_list *pid_list;
>  	struct trace_array *tr = data;
>  
> +	guard(preempt)();
>  	pid_list = rcu_dereference_sched(tr->function_pids);
>  	trace_filter_add_remove_task(pid_list, NULL, task);
>  
> -- 
> 2.51.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids
  2026-03-03  4:17 ` Masami Hiramatsu
@ 2026-03-03 14:39   ` Steven Rostedt
  2026-03-04  1:48     ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2026-03-03 14:39 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: LKML, Linux Trace Kernel, Mathieu Desnoyers

On Tue, 3 Mar 2026 13:17:06 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:

> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 9928da636c9d..3b3aaf4831e9 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -1039,6 +1039,7 @@ event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
>  	struct trace_pid_list *pid_list;
>  	struct trace_array *tr = data;
>  
> +	guard(preempt)();
>  	pid_list = rcu_dereference_raw(tr->filtered_pids);
>  	trace_filter_add_remove_task(pid_list, NULL, task);
>  
> @@ -1054,6 +1055,7 @@ event_filter_pid_sched_process_fork(void *data,
>  	struct trace_pid_list *pid_list;
>  	struct trace_array *tr = data;
>  
> +	guard(preempt)();
>  	pid_list = rcu_dereference_sched(tr->filtered_pids);
>  	trace_filter_add_remove_task(pid_list, self, task);
>  

Yep. I can make them two different patches. Do you want me to take this as
your patch? I'll need a SoB from you then.

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids
  2026-03-03 14:39   ` Steven Rostedt
@ 2026-03-04  1:48     ` Masami Hiramatsu
  2026-03-04  2:13       ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2026-03-04  1:48 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Linux Trace Kernel, Mathieu Desnoyers

On Tue, 3 Mar 2026 09:39:49 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Tue, 3 Mar 2026 13:17:06 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> 
> > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> > index 9928da636c9d..3b3aaf4831e9 100644
> > --- a/kernel/trace/trace_events.c
> > +++ b/kernel/trace/trace_events.c
> > @@ -1039,6 +1039,7 @@ event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
> >  	struct trace_pid_list *pid_list;
> >  	struct trace_array *tr = data;
> >  
> > +	guard(preempt)();
> >  	pid_list = rcu_dereference_raw(tr->filtered_pids);
> >  	trace_filter_add_remove_task(pid_list, NULL, task);
> >  
> > @@ -1054,6 +1055,7 @@ event_filter_pid_sched_process_fork(void *data,
> >  	struct trace_pid_list *pid_list;
> >  	struct trace_array *tr = data;
> >  
> > +	guard(preempt)();
> >  	pid_list = rcu_dereference_sched(tr->filtered_pids);
> >  	trace_filter_add_remove_task(pid_list, self, task);
> >  
> 
> Yep. I can make them two different patches. Do you want me to take this as
> your patch? I'll need a SoB from you then.

I think we can combine those since it fixes the same commit.
(just for bisectability)

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you,

> 
> -- Steve


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids
  2026-03-04  1:48     ` Masami Hiramatsu
@ 2026-03-04  2:13       ` Steven Rostedt
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2026-03-04  2:13 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: LKML, Linux Trace Kernel, Mathieu Desnoyers

On Wed, 4 Mar 2026 10:48:33 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:

> I think we can combine those since it fixes the same commit.
> (just for bisectability)

They can still be separate. One is for function tracing and the other
is for events. They both may have the same fixes tag, but it shouldn't
affect bisectablility, as they require different things to be enabled
to trigger.

> 
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-04  2:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03  2:35 [PATCH] ftrace: Disable preemption in the tracepoint callbacks handling filtered pids Steven Rostedt
2026-03-03  4:17 ` Masami Hiramatsu
2026-03-03 14:39   ` Steven Rostedt
2026-03-04  1:48     ` Masami Hiramatsu
2026-03-04  2:13       ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox