Skip to contentSkip to conversation

x86/process: Mark ret_from_fork() noinstr

PATCH New Karl Mehltretter 1 participant 1 message Nov 7 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/process: Mark ret_from_fork() noinstr

ret_from_fork() is traceable and returns after syscall_exit_to_user_mode() enters the RCU extended quiescent state via user_enter_irqoff() on NO_HZ_FULL CPUs. When function_graph tracing is enabled with FTRACE_VALIDATE_RCU_IS_WATCHING, the return hook runs in ret_from_fork() after RCU stops watching and triggers the ftrace_return_to_handler() warning.

Mark ret_from_fork() noinstr and bracket schedule_tail() and the kernel thread callback with instrumentation_begin() and instrumentation_end().

Fixes 3aec4ecb3d1f ("x86: Rewrite ret_from_fork() in C")

---
Assisted by an LLM.

Tested on v7.4-rc1 (d48723711bae) under QEMU x86_64 (-smp 4) with NO_HZ_FULL, FTRACE_VALIDATE_RCU_IS_WATCHING, PROVE_LOCKING, nohz_full=1-3 rcu_nocbs=1-3 on the kernel command line, and function_graph tracing during parallel fork bursts across CPUs 0-3. Without this patch, two consecutive runs trigger:
RCU not on for: ret_from_fork+0x4/0x370

  WARNING: include/linux/trace_recursion.h:132 at ftrace_return_to_handler+0x185/0x2e0, CPU#3

With this patch, two consecutive runs complete without the ftrace_return_to_handler() warning.

 arch/x86/kernel/process.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/process.c +3 -1
index 346c438ac8801..270d663e95c76 100644
@@ -148,9 +148,10 @@ static int set_new_tls(struct task_struct *p, unsigned long tls)
 		return do_set_thread_area_64(p, ARCH_SET_FS, tls);
 }
 
-__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
+__visible noinstr void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
 				     int (*fn)(void *), void *fn_arg)
 {
+	instrumentation_begin();
 	schedule_tail(prev);
 
 	/* Is this a kernel thread? */
@@ -163,6 +164,7 @@ __visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
 		 */
 		regs->ax = 0;
 	}
+	instrumentation_end();
 
 	syscall_exit_to_user_mode(regs);
 }

base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee

Signature · 1 line
2.39.5 (Apple Git-154)