riscv: entry: Mark ret_from_fork_kernel() and ret_from_fork_user() noinstr
PATCH 1/1 riscv: entry: Mark ret_from_fork_kernel() and ret_from_fork_user() noinstr
ret_from_fork_kernel() and ret_from_fork_user() are traceable and return 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 after RCU stops watching and triggers the ftrace_return_to_handler() warning.
Mark ret_from_fork_kernel() and ret_from_fork_user() noinstr and bracket the kernel thread callback with instrumentation_begin() and instrumentation_end().
---
Assisted by an LLM.
Tested on v7.4-rc1 (d48723711bae) under QEMU riscv64 (-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_user+0x4/0x368
WARNING: include/linux/trace_recursion.h:132 at ftrace_return_to_handler+0x2e0/0x2f0, CPU#2
followed by an observed kernel paging request Oops in ftrace_graph_ret_addr() while unwinding the warning backtrace. With this patch, two consecutive runs complete without the ftrace_return_to_handler() warning or unwind fault.
arch/riscv/kernel/process.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/riscv/kernel/process.c +5 -2
@@ -225,14 +225,17 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)return 0 ; } -asmlinkage void ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), struct pt_regs *regs) +asmlinkage void noinstr ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), +struct pt_regs *regs) { +instrumentation_begin ();fn (fn_arg); +instrumentation_end ();syscall_exit_to_user_mode (regs); } -asmlinkage void ret_from_fork_user(struct pt_regs *regs) +asmlinkage void noinstr ret_from_fork_user(struct pt_regs *regs) {syscall_exit_to_user_mode (regs); }
base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 36 lines · Karl Mehltretter
ret_from_fork_kernel()andret_from_fork_user()are traceable and return aftersyscall_exit_to_user_mode()enters the RCU extended quiescent state viauser_enter_irqoff()onNO_HZ_FULLCPUs. Whenfunction_graphtracing is enabled withFTRACE_VALIDATE_RCU_IS_WATCHING, the return hook runs after RCU stops watching and triggers theftrace_return_to_handler()warning.Mark
ret_from_fork_kernel()andret_from_fork_user()noinstr and bracket the kernel thread callback withinstrumentation_begin()andinstrumentation_end().Fixes f955aa8723a6 ("riscv: entry: Convert ret_from_fork() to C")Signed-off-by Karl Mehltretter <[email protected]>---
Assisted by an LLM.Tested on v7.4-rc1 (
d48723711bae) under QEMU riscv64 (-smp 4) withNO_HZ_FULL,FTRACE_VALIDATE_RCU_IS_WATCHING,PROVE_LOCKING, nohz_full=1-3 rcu_nocbs=1-3 on the kernel command line, andfunction_graphtracing during parallel fork bursts across CPUs 0-3. Without this patch, two consecutive runs trigger:
RCU not on for:ret_from_fork_user+0x4/0x368WARNING: include/linux/trace_recursion.h:132 at ftrace_return_to_handler+0x2e0/0x2f0, CPU#2followed by an observed kernel paging request Oops in
ftrace_graph_ret_addr()while unwinding the warning backtrace. With this patch, two consecutive runs complete without theftrace_return_to_handler()warning or unwind fault.arch/riscv/kernel/process.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)arch/riscv/kernel/process.c +0
-0
arch/riscv/kernel/process.c int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) · line 231
Quoted 8 lines
arch/riscv/kernel/process.c +3
-1@@ -225,14 +225,17 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)return 0 ; } -asmlinkage void ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), struct pt_regs *regs) +asmlinkage void noinstr ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), +struct pt_regs *regs) { +instrumentation_begin ();
since riscv has no objtool support, this can be removed.
Quoted 21 lines
arch/riscv/kernel/process.c +2
-1fn (fn_arg); +instrumentation_end ();syscall_exit_to_user_mode (regs); } -asmlinkage void ret_from_fork_user(struct pt_regs *regs) +asmlinkage void noinstr ret_from_fork_user(struct pt_regs *regs) {syscall_exit_to_user_mode (regs); }base-commit:
d48723711bae9b8cdc56719c448ba42fef28cbeeSignature · 7 lines
2.39.5 (Apple Git-154) _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv