Skip to contentSkip to conversation

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

PATCH New Steven Rostedt 1 participant 1 message Nov 18

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH v2 1/1 fgraph: Read the task->ret_stack with a smp_load_acquire()

From: Steven Rostedt <[email protected]>

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

Also update graph_init_task() to use smp_store_release().

---
Changse since v1: https://patch.msgid.link/[email protected]

- Updated graph_init_task() to use smp_store_release() (Sashiko)

 kernel/trace/fgraph.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
kernel/trace/fgraph.c +6 -9
index bbf6e4e2da2d..0748eb67dea7 100644
@@ -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.
@@ -1125,8 +1123,7 @@ graph_init_task(struct task_struct *t, unsigned long *ret_stack)
 	t->curr_ret_stack = 0;
 	t->curr_ret_depth = -1;
 	/* make curr_ret_stack visible before we add the ret_stack */
-	smp_wmb();
-	t->ret_stack = ret_stack;
+	smp_store_release(&t->ret_stack, ret_stack);
 }
 
 /*
Signature · 1 line
2.53.0