mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Brian Gerst <brgerst@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] x86/process: Mark ret_from_fork() noinstr
Date: Sat,  7 Nov 2026 20:16:09 +0100	[thread overview]
Message-ID: <20261107191609.60336-1-kmehltretter@gmail.com> (raw)

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")
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
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(-)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 346c438ac8801..270d663e95c76 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -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

-- 
2.39.5 (Apple Git-154)


                 reply	other threads:[~2026-11-07 19:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261107191609.60336-1-kmehltretter@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®