Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Antoine Tenart <atenart@kernel.org>
Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
	vmalik@redhat.com, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	"Uladzislau Rezki (Sony)" <urezki@gmail.com>
Subject: Re: [PATCH] tracing/probes: fix race between probe execution and event unregistering
Date: Fri, 27 Nov 2026 14:06:16 -0500	[thread overview]
Message-ID: <20261127140616.20616c68@gandalf.local.home> (raw)
In-Reply-To: <20261126132830.14992-1-atenart@kernel.org>

On Thu, 26 Nov 2026 14:28:30 +0100
Antoine Tenart <atenart@kernel.org> wrote:

> 
> Hi,
> 
> I found this while debugging another (downstream) issue, reusing the
> same reproducer on mainline. The reproducer registers/enables and
> disables/unregisters a kretprobe on a syscall in a loop while triggering
> it (I can share if you're interested). It should work with other probe
> types.
> 
> I'm not versed into the tracing subsystem so I went the safe way and
> reverted back to the previous behaviour. There might be something more
> clever to do.

I would hate having to put back the inline synchronize_rcu() as that has
noticeable impact on removing kprobes.


> 
> Thanks!
> Antoine
> 
>  kernel/trace/trace_probe.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index cff55dcae36f..8addaf641431 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -2841,7 +2841,13 @@ int trace_probe_remove_file(struct trace_probe *tp,
>  		return -ENOENT;
>  
>  	list_del_rcu(&link->list);
> -	kvfree_rcu_mightsleep(link);
> +
> +	/*
> +	 * Synchronize with probes being executed. This is not only for freeing
> +	 * link but also for related objects (e.g. link->file).
> +	 */
> +	synchronize_rcu();
> +	kvfree(link);
>  
>  	if (list_empty(&tp->event->files))
>  		trace_probe_clear_flag(tp, TP_FLAG_TRACE);

Would something like this work? I haven't fully tested it though:

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index cff55dcae36f..c249256dea80 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
 		return -ENOMEM;
 
 	link->file = file;
+	event_file_get(file);
 	INIT_LIST_HEAD(&link->list);
 	list_add_tail_rcu(&link->list, &tp->event->files);
 	trace_probe_set_flag(tp, TP_FLAG_TRACE);
@@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
 	return NULL;
 }
 
+static void free_link_rcu(struct rcu_head *rcu)
+{
+	struct event_file_link *link = container_of(rcu, struct event_file_link, rcu);
+
+	event_file_put(link->file);
+	kvfree(link);
+}
+
 int trace_probe_remove_file(struct trace_probe *tp,
 			    struct trace_event_file *file)
 {
@@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp,
 		return -ENOENT;
 
 	list_del_rcu(&link->list);
-	kvfree_rcu_mightsleep(link);
+	call_rcu(&link->rcu, free_link_rcu);
 
 	if (list_empty(&tp->event->files))
 		trace_probe_clear_flag(tp, TP_FLAG_TRACE);
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index d1fb3520700f..aecc9f24951d 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -281,6 +281,7 @@ struct trace_probe {
 struct event_file_link {
 	struct trace_event_file		*file;
 	struct list_head		list;
+	struct rcu_head			rcu;
 };
 
 static inline unsigned int trace_probe_load_flag(struct trace_probe *tp)

-- Steve

  reply	other threads:[~2026-11-27 19:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:28 [PATCH] tracing/probes: fix race between probe execution and event unregistering Antoine Tenart
2026-11-27 19:06 ` Steven Rostedt [this message]
2026-11-28  2:31   ` Masami Hiramatsu (Google)
2026-12-01 13:21   ` Antoine Tenart
2026-12-01 13:58     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127140616.20616c68@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=atenart@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=urezki@gmail.com \
    --cc=vmalik@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox