Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] fgraph: Read the task->ret_stack with a smp_load_acquire()
@ 2026-11-18  0:30 Steven Rostedt
  2026-11-18  0:40 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2026-11-18  0:30 UTC (permalink / raw)
  To: LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Vineet Gupta, Peter Zijlstra,
	Andrii Nakryiko

From: Steven Rostedt <rostedt@goodmis.org>

The setting of task->ret_stack was switched from a smp_wmb() and the
update to the variable with a smp_store_release(). Match the reading of
the task->ret_stack with a smp_load_acquire() to replace the read and
smp_rmb().

Link: https://lore.kernel.org/all/20261021174406.2891598-2-vineet.gupta@linux.dev/

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/fgraph.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index bbf6e4e2da2d..1383cc3db1b1 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -568,7 +568,11 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 	if (unlikely(ftrace_graph_is_dead()))
 		return -EBUSY;
 
-	if (!current->ret_stack)
+	/*
+	 * We must make sure the ret_stack is tested before we read
+	 * anything else (See alloc_retstack_tasklist()).
+	 */
+	if (!smp_load_acquire(&current->ret_stack))
 		return -EBUSY;
 
 	BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long));
@@ -576,12 +580,6 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 	/* Set val to "reserved" with the delta to the new fgraph frame */
 	val = (FGRAPH_TYPE_RESERVED << FGRAPH_TYPE_SHIFT) | FGRAPH_FRAME_OFFSET;
 
-	/*
-	 * We must make sure the ret_stack is tested before we read
-	 * anything else.
-	 */
-	smp_rmb();
-
 	/*
 	 * Check if there's room on the shadow stack to fit a fraph frame
 	 * and a bitmap word.
-- 
2.53.0


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

* Re: [PATCH] fgraph: Read the task->ret_stack with a smp_load_acquire()
  2026-11-18  0:30 [PATCH] fgraph: Read the task->ret_stack with a smp_load_acquire() Steven Rostedt
@ 2026-11-18  0:40 ` sashiko-bot
  2026-11-18  0:42   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-11-18  0:40 UTC (permalink / raw)
  To: Steven Rostedt, Linux Trace Kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] fgraph: missing smp_store_release() conversion for
  task->ret_stack writers
--

commit b7c8f41f039b807327203effc627ecc71bfa14c8
Author: Steven Rostedt <rostedt@goodmis.org>

fgraph: Read the task->ret_stack with a smp_load_acquire()

This commit replaces the plain read of current->ret_stack and subsequent
smp_rmb() in ftrace_push_return_trace() with smp_load_acquire().

Link: https://lore.kernel.org/all/20261021174406.2891598-2-vineet.gupta@linux.dev/

> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index ed455b53513be..eaa8d6aadb0e8 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c
> @@ -568,7 +568,11 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
>  	if (unlikely(ftrace_graph_is_dead()))
>  		return -EBUSY;
>  
> -	if (!current->ret_stack)
> +	/*
> +	 * We must make sure the ret_stack is tested before we read
> +	 * anything else (See alloc_retstack_tasklist()).
> +	 */
> +	if (!smp_load_acquire(&current->ret_stack))
>  		return -EBUSY;
>  
>  	BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long));
> @@ -576,12 +580,6 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
>  	/* Set val to "reserved" with the delta to the new fgraph frame */
>  	val = (FGRAPH_TYPE_RESERVED << FGRAPH_TYPE_SHIFT) | FGRAPH_FRAME_OFFSET;
>  
> -	/*
> -	 * We must make sure the ret_stack is tested before we read
> -	 * anything else.
> -	 */
> -	smp_rmb();
> -

[Severity: Medium]
Should alloc_retstack_tasklist() and graph_init_task() also be updated to
use smp_store_release() when assigning t->ret_stack?

The commit message notes that setting task->ret_stack was switched from
smp_wmb() to smp_store_release(), and the new comment points to
alloc_retstack_tasklist().  However, both alloc_retstack_tasklist() and
graph_init_task() still use smp_wmb() followed by a plain store to
t->ret_stack:

kernel/trace/fgraph.c:alloc_retstack_tasklist() {
	...
			/* Make sure the tasks see the 0 first: */
			smp_wmb();
			t->ret_stack = ret_stack_list[start++];
	...
}

kernel/trace/fgraph.c:graph_init_task() {
	...
	/* make curr_ret_stack visible before we add the ret_stack */
	smp_wmb();
	t->ret_stack = ret_stack;
	...
}

Without converting those writers to smp_store_release(&t->ret_stack, ...),
the store side remains an unmarked plain assignment when racing with
smp_load_acquire(&current->ret_stack).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117193007.6ee9f605@gandalf.local.home?part=1

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

* Re: [PATCH] fgraph: Read the task->ret_stack with a smp_load_acquire()
  2026-11-18  0:40 ` sashiko-bot
@ 2026-11-18  0:42   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2026-11-18  0:42 UTC (permalink / raw)
  To: sashiko-bot; +Cc: sashiko-reviews, Linux Trace Kernel

On Wed, 18 Nov 2026 00:40:05 +0000
sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] fgraph: missing smp_store_release() conversion for
>   task->ret_stack writers
> --
> 
> commit b7c8f41f039b807327203effc627ecc71bfa14c8
> Author: Steven Rostedt <rostedt@goodmis.org>
> 
> fgraph: Read the task->ret_stack with a smp_load_acquire()
> 
> This commit replaces the plain read of current->ret_stack and subsequent
> smp_rmb() in ftrace_push_return_trace() with smp_load_acquire().
> 
> Link: https://lore.kernel.org/all/20261021174406.2891598-2-vineet.gupta@linux.dev/
> 
> > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> > index ed455b53513be..eaa8d6aadb0e8 100644
> > --- a/kernel/trace/fgraph.c
> > +++ b/kernel/trace/fgraph.c
> > @@ -568,7 +568,11 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
> >  	if (unlikely(ftrace_graph_is_dead()))
> >  		return -EBUSY;
> >  
> > -	if (!current->ret_stack)
> > +	/*
> > +	 * We must make sure the ret_stack is tested before we read
> > +	 * anything else (See alloc_retstack_tasklist()).
> > +	 */
> > +	if (!smp_load_acquire(&current->ret_stack))
> >  		return -EBUSY;
> >  
> >  	BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long));
> > @@ -576,12 +580,6 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
> >  	/* Set val to "reserved" with the delta to the new fgraph frame */
> >  	val = (FGRAPH_TYPE_RESERVED << FGRAPH_TYPE_SHIFT) | FGRAPH_FRAME_OFFSET;
> >  
> > -	/*
> > -	 * We must make sure the ret_stack is tested before we read
> > -	 * anything else.
> > -	 */
> > -	smp_rmb();
> > -  
> 
> [Severity: Medium]
> Should alloc_retstack_tasklist() and graph_init_task() also be updated to
> use smp_store_release() when assigning t->ret_stack?
> 
> The commit message notes that setting task->ret_stack was switched from
> smp_wmb() to smp_store_release(), and the new comment points to
> alloc_retstack_tasklist().  However, both alloc_retstack_tasklist() and
> graph_init_task() still use smp_wmb() followed by a plain store to
> t->ret_stack:
> 
> kernel/trace/fgraph.c:alloc_retstack_tasklist() {
> 	...
> 			/* Make sure the tasks see the 0 first: */
> 			smp_wmb();
> 			t->ret_stack = ret_stack_list[start++];
> 	...
> }

This is fixed by the patch that I have the Link tag pointing to.

> 
> kernel/trace/fgraph.c:graph_init_task() {
> 	...
> 	/* make curr_ret_stack visible before we add the ret_stack */
> 	smp_wmb();
> 	t->ret_stack = ret_stack;

Ah, I'll update this one too and send a v2.

Thanks,

-- Steve

> 	...
> }
> 
> Without converting those writers to smp_store_release(&t->ret_stack, ...),
> the store side remains an unmarked plain assignment when racing with
> smp_load_acquire(&current->ret_stack).
> 


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

end of thread, other threads:[~2026-11-18  0:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  0:30 [PATCH] fgraph: Read the task->ret_stack with a smp_load_acquire() Steven Rostedt
2026-11-18  0:40 ` sashiko-bot
2026-11-18  0:42   ` Steven Rostedt

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