Linux Trace Kernel
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: vineet.gupta@linux.dev,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@linux.dev,stable@vger.kernel.org,ast@kernel.org,andrii@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: Tue, 29 Sep 2026 23:46:21 +0000 (UTC)	[thread overview]
Message-ID: <2dc04cf6f1e0c474da152cb4afcd0e264930b4d1d9b969de1b7cfbdd50b1bd35@mail.kernel.org> (raw)
In-Reply-To: <20260929005411.4105448-2-vineet.gupta@linux.dev>

[-- Attachment #1: Type: text/plain, Size: 2709 bytes --]

> 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.

> -	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

  parent reply	other threads:[~2026-09-29 23:46 UTC|newest]

Thread overview: 8+ 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
2026-09-29  1:03   ` sashiko-bot
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 [this message]
2026-10-01 10:32     ` Vineet Gupta

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=2dc04cf6f1e0c474da152cb4afcd0e264930b4d1d9b969de1b7cfbdd50b1bd35@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@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=vineet.gupta@linux.dev \
    --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