From: Vineet Gupta <vineet.gupta@linux.dev>
To: bot+bpf-ci@kernel.org, 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,
stable@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org, eddyz87@gmail.com,
yonghong.song@linux.dev, mason@kernel.org,
ihor.solodrai@linux.dev
Subject: Re: [PATCH v2 1/1] tracing: fgraph: allocate shadow stacks inline with GFP_NOWAIT
Date: Thu, 1 Oct 2026 03:32:05 -0700 [thread overview]
Message-ID: <a10ad8db-c344-4c24-bab6-88e9f7055f10@linux.dev> (raw)
In-Reply-To: <2dc04cf6f1e0c474da152cb4afcd0e264930b4d1d9b969de1b7cfbdd50b1bd35@mail.kernel.org>
On 9/29/26 4:46 PM, bot+bpf-ci@kernel.org wrote:
>> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
>> index ed455b53513b..336f40dc6618 100644
>> --- a/kernel/trace/fgraph.c
>> +++ b/kernel/trace/fgraph.c
>> @@ -1036,10 +1036,9 @@ trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub;
>> /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */
>> static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
>> {
> Does this comment still match the function's behavior? Before the patch,
> alloc_retstack_tasklist() assigned at most FTRACE_RETSTACK_ALLOC_SIZE
> stacks per call and returned -EAGAIN to trigger another batch. After the
> patch, it walks every thread in one pass, allocating inline with
> GFP_NOWAIT. The FTRACE_RETSTACK_ALLOC_SIZE pre-allocated entries are now
> only a fallback when GFP_NOWAIT fails, and in the normal case they're all
> freed at the free: label.
Posted v3 [1] with comment fix.
Thx,
-Vineet
[1]
https://lore.kernel.org/bpf/20261001102909.1152572-1-vineet.gupta@linux.dev/T/#t
>
>> - int i;
>> - int ret = 0;
>> int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE;
>> struct task_struct *g, *t;
>> + int i, ret = 0;
>>
>> if (WARN_ON_ONCE(!fgraph_stack_cachep))
>> return -ENOMEM;
>> @@ -1054,26 +1053,37 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
>> }
>> }
>>
>> - rcu_read_lock();
>> - for_each_process_thread(g, t) {
>> - if (start == end) {
>> - ret = -EAGAIN;
>> - goto unlock;
>> - }
>> + scoped_guard (rcu) {
>> + for_each_process_thread(g, t) {
>> + unsigned long *rs;
>> +
>> + if (t->ret_stack)
>> + continue;
>> +
>> + rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
>> + if (!rs) {
>> + /*
>> + * Returning from inside scoped_guard() drops
>> + * the RCU read lock, but skips the free loop
>> + * below. That is only safe because start ==
>> + * end here, which leaves that loop nothing to
>> + * free. Keep the two in step if this
>> + * exhaustion check ever changes.
>> + */
>> + if (start == end)
>> + return -EAGAIN;
>> + rs = ret_stack_list[start++];
>> + }
>>
>> - if (t->ret_stack == NULL) {
>> atomic_set(&t->trace_overrun, 0);
>> - ret_stack_init_task_vars(ret_stack_list[start]);
>> + 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_wmb();
>> - t->ret_stack = ret_stack_list[start++];
>> + 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]);
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/36644771324
prev parent reply other threads:[~2026-10-01 10:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 0:54 [PATCH v2] tracing: fgraph: fix the quadratic shadow stack walk Vineet Gupta
2026-09-29 0:54 ` [PATCH v2 1/1] tracing: fgraph: allocate shadow stacks inline with GFP_NOWAIT Vineet Gupta
[not found] ` <20260929010327.024281F000FF@smtp.kernel.org>
2026-09-29 1:22 ` Vineet Gupta
2026-09-29 2:25 ` Andrii Nakryiko
2026-09-29 8:03 ` Peter Zijlstra
2026-09-29 23:46 ` bot+bpf-ci
2026-10-01 10:32 ` Vineet Gupta [this message]
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=a10ad8db-c344-4c24-bab6-88e9f7055f10@linux.dev \
--to=vineet.gupta@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®