From: Vineet Gupta <vineet.gupta@linux.dev>
To: rostedt@goodmis.org, mhiramat@kernel.org
Cc: mark.rutland@arm.com, mathieu.desnoyers@efficios.com,
andrii@kernel.org, peterz@infradead.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, kernel-team@meta.com,
Vineet Gupta <vineet.gupta@linux.dev>
Subject: [PATCH v4 2/2] tracing: fgraph: use scoped_guard() for the task list walk
Date: Wed, 21 Oct 2026 10:44:06 -0700 [thread overview]
Message-ID: <20261021174406.2891598-3-vineet.gupta@linux.dev> (raw)
In-Reply-To: <20261021174406.2891598-1-vineet.gupta@linux.dev>
alloc_retstack_tasklist() open-codes rcu_read_lock() and unwinds it
through an unlock label. Use scoped_guard(rcu) instead and let the
compiler emit the unlock on every exit path.
The -EAGAIN case now jumps straight to the free label rather than to
unlock; leaving the guard's scope releases the RCU read lock on the
way, so the unlock label has no remaining users and is removed.
No functional change: objdump of fgraph.o shows identical call targets
and counts, including the three __rcu_read_unlock() sites the compiler
emits for the exits from the read-side section. A PROVE_RCU +
DEBUG_ATOMIC_SLEEP build with the -EAGAIN path forced several thousand
times is clean.
The preceding patch deliberately left this alone so that it stays
straightforward to backport. This is the follow-up.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
Tested-by: Vineet Gupta <vineet.gupta@linux.dev>
---
kernel/trace/fgraph.c | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 4c74f1a15ad4..bbf6e4e2da2d 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -1057,32 +1057,31 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
}
}
- rcu_read_lock();
- for_each_process_thread(g, t) {
- unsigned long *rs;
+ scoped_guard (rcu) {
+ for_each_process_thread(g, t) {
+ unsigned long *rs;
- if (t->ret_stack)
- continue;
+ if (t->ret_stack)
+ continue;
- rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
- if (!rs) {
- if (start == end) {
- ret = -EAGAIN;
- goto unlock;
+ rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
+ if (!rs) {
+ if (start == end) {
+ ret = -EAGAIN;
+ goto free;
+ }
+ rs = ret_stack_list[start++];
}
- rs = ret_stack_list[start++];
- }
- atomic_set(&t->trace_overrun, 0);
- ret_stack_init_task_vars(rs);
- t->curr_ret_stack = 0;
- t->curr_ret_depth = -1;
- /* Make sure the tasks see the 0 first: */
- smp_store_release(&t->ret_stack, rs);
+ atomic_set(&t->trace_overrun, 0);
+ ret_stack_init_task_vars(rs);
+ t->curr_ret_stack = 0;
+ t->curr_ret_depth = -1;
+ /* Make sure the tasks see the 0 first: */
+ smp_store_release(&t->ret_stack, rs);
+ }
}
-unlock:
- rcu_read_unlock();
free:
for (i = start; i < end; i++)
kmem_cache_free(fgraph_stack_cachep, ret_stack_list[i]);
--
2.53.0-Meta
next prev parent reply other threads:[~2026-10-21 17:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 17:44 [PATCH v4 0/2] tracing: fgraph: fix the quadratic shadow stack walk Vineet Gupta
2026-10-21 17:44 ` [PATCH v4 1/2] tracing: fgraph: allocate shadow stacks inline with GFP_NOWAIT Vineet Gupta
2026-10-23 18:13 ` Andrii Nakryiko
2026-10-23 18:38 ` Steven Rostedt
2026-10-23 20:13 ` Vineet Gupta
2026-10-23 22:09 ` Steven Rostedt
2026-10-23 22:25 ` Vineet Gupta
2026-10-21 17:44 ` Vineet Gupta [this message]
2026-10-21 17:53 ` [PATCH v4 2/2] tracing: fgraph: use scoped_guard() for the task list walk sashiko-bot
2026-10-21 17:56 ` Vineet Gupta
2026-10-21 22:01 ` [PATCH v4 0/2] tracing: fgraph: fix the quadratic shadow stack walk Alexei Starovoitov
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=20261021174406.2891598-3-vineet.gupta@linux.dev \
--to=vineet.gupta@linux.dev \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/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