Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] fgraph: Do not mark index 0 in every shadow stack frame" failed to apply to 6.12-stable tree
@ 2026-12-02 13:01 gregkh
  2026-12-03 22:02 ` [PATCH 6.12.y 1/2] fgraph: Get ftrace recursion lock in function_graph_enter Sasha Levin
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-12-02 13:01 UTC (permalink / raw)
  To: leitao, rostedt; +Cc: stable


The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 65f42f1fa03829e0ab1473369461a7aabf525cb2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120236-tripping-outlast-4f1d@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 65f42f1fa03829e0ab1473369461a7aabf525cb2 Mon Sep 17 00:00:00 2001
From: Breno Leitao <leitao@debian.org>
Date: Thu, 12 Nov 2026 07:18:42 -0800
Subject: [PATCH] fgraph: Do not mark index 0 in every shadow stack frame

We are seeing this warning on an arm64 host:

  WARNING: kernel/trace/fprobe.c:676 at fprobe_return+0x260/0x2c8, CPU#16: FuncSched/3281330
  Call trace:
   fprobe_return+0x260/0x2c8 (P)
   ftrace_return_to_handler+0x2bc/0x5a8
   return_to_handler+0x20/0x48
   futex_wait+0xa4/0x218
   do_futex+0xb4/0x1d0
   __arm64_sys_futex+0x15c/0x278

The theory is that function_graph_enter_regs() sets BIT(0) in the bitmap
of every frame, a leftover of an old tail-call check, while the return
path calls the retfunc of every set bit.

A reproducer on linux-next supports the theory. On a fresh boot, with no
other fgraph user yet:

  cd /sys/kernel/tracing
  echo 'f:fpexit vfs_read%return' >> dynamic_events
  echo 1 > events/fprobes/fpexit/enable	# fprobe_graph_ops: index 0
  echo vfs_write > set_ftrace_filter
  echo function_graph > current_tracer	# function_graph: index 1
  echo x > /dev/null			# WARN on vfs_write return

Removing the bit was agreed in the review of the series that added it
[0], but the line stayed. Drop it now.

[0] https://lore.kernel.org/all/20240527093436.7060d358a64cc2ea3213b07b@kernel.org/

Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261112-fgraph-bit0-v1-1-695ad14f4b1e@debian.org
Fixes: 7aa1eaef9f42 ("function_graph: Allow multiple users to attach to function graph")
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 1d900445d23a..d1f79a85ed2e 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -698,11 +698,7 @@ int function_graph_enter_regs(unsigned long ret, unsigned long func,
 	if (!bitmap)
 		goto out_ret;
 
-	/*
-	 * Since this function uses fgraph_idx = 0 as a tail-call checking
-	 * flag, set that bit always.
-	 */
-	set_bitmap(current, offset, bitmap | BIT(0));
+	set_bitmap(current, offset, bitmap);
 	ftrace_test_recursion_unlock(bit);
 	return 0;
  out_ret:


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

* [PATCH 6.12.y 1/2] fgraph: Get ftrace recursion lock in function_graph_enter
  2026-12-02 13:01 FAILED: patch "[PATCH] fgraph: Do not mark index 0 in every shadow stack frame" failed to apply to 6.12-stable tree gregkh
@ 2026-12-03 22:02 ` Sasha Levin
  2026-12-03 22:02   ` [PATCH 6.12.y 2/2] fgraph: Do not mark index 0 in every shadow stack frame Sasha Levin
  0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-12-03 22:02 UTC (permalink / raw)
  To: stable
  Cc: Masami Hiramatsu (Google), Alexei Starovoitov, Florent Revest,
	Martin KaFai Lau, bpf, Jiri Olsa, Alan Maguire, Mark Rutland,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N Rao,
	Madhavan Srinivasan, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Mathieu Desnoyers, Steven Rostedt (Google), Sasha Levin

From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>

[ Upstream commit d576aec24df9f58ed0ebe2ff854daafe837f0225 ]

Get the ftrace recursion lock in the generic function_graph_enter()
instead of each architecture code.
This changes all function_graph tracer callbacks running in
non-preemptive state. On x86 and powerpc, this is by default, but
on the other architecutres, this will be new.

Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Florent Revest <revest@chromium.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf <bpf@vger.kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/173379653720.973433.18438622234884980494.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Stable-dep-of: 65f42f1fa038 ("fgraph: Do not mark index 0 in every shadow stack frame")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/powerpc/kernel/trace/ftrace.c       | 6 ------
 arch/powerpc/kernel/trace/ftrace_64_pg.c | 6 ------
 arch/x86/kernel/ftrace.c                 | 7 -------
 kernel/trace/fgraph.c                    | 8 +++++++-
 4 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index df41f4a7c738b..4e09d140c5625 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -422,7 +422,6 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 		       struct ftrace_ops *op, struct ftrace_regs *fregs)
 {
 	unsigned long sp = arch_ftrace_regs(fregs)->regs.gpr[1];
-	int bit;
 
 	if (unlikely(ftrace_graph_is_dead()))
 		goto out;
@@ -430,14 +429,9 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		goto out;
 
-	bit = ftrace_test_recursion_trylock(ip, parent_ip);
-	if (bit < 0)
-		goto out;
-
 	if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp))
 		parent_ip = ppc_function_entry(return_to_handler);
 
-	ftrace_test_recursion_unlock(bit);
 out:
 	arch_ftrace_regs(fregs)->regs.link = parent_ip;
 }
diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.c b/arch/powerpc/kernel/trace/ftrace_64_pg.c
index d3c5552e4984d..9613717880de0 100644
--- a/arch/powerpc/kernel/trace/ftrace_64_pg.c
+++ b/arch/powerpc/kernel/trace/ftrace_64_pg.c
@@ -803,7 +803,6 @@ static unsigned long
 __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp)
 {
 	unsigned long return_hooker;
-	int bit;
 
 	if (unlikely(ftrace_graph_is_dead()))
 		goto out;
@@ -811,16 +810,11 @@ __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		goto out;
 
-	bit = ftrace_test_recursion_trylock(ip, parent);
-	if (bit < 0)
-		goto out;
-
 	return_hooker = ppc_function_entry(return_to_handler);
 
 	if (!function_graph_enter(parent, ip, 0, (unsigned long *)sp))
 		parent = return_hooker;
 
-	ftrace_test_recursion_unlock(bit);
 out:
 	return parent;
 }
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 6bcc080f361e3..2653cae451928 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -620,7 +620,6 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
 			   unsigned long frame_pointer)
 {
 	unsigned long return_hooker = (unsigned long)&return_to_handler;
-	int bit;
 
 	/*
 	 * When resuming from suspend-to-ram, this function can be indirectly
@@ -640,14 +639,8 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		return;
 
-	bit = ftrace_test_recursion_trylock(ip, *parent);
-	if (bit < 0)
-		return;
-
 	if (!function_graph_enter(*parent, ip, frame_pointer, parent))
 		*parent = return_hooker;
-
-	ftrace_test_recursion_unlock(bit);
 }
 
 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index c2d9937158117..a58ec55a47f9b 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -622,8 +622,13 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	struct ftrace_graph_ent trace;
 	unsigned long bitmap = 0;
 	int offset;
+	int bit;
 	int i;
 
+	bit = ftrace_test_recursion_trylock(func, ret);
+	if (bit < 0)
+		return -EBUSY;
+
 	trace.func = func;
 	trace.depth = ++current->curr_ret_depth;
 
@@ -669,12 +674,13 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	 * flag, set that bit always.
 	 */
 	set_bitmap(current, offset, bitmap | BIT(0));
-
+	ftrace_test_recursion_unlock(bit);
 	return 0;
  out_ret:
 	current->curr_ret_stack -= FGRAPH_FRAME_OFFSET + 1;
  out:
 	current->curr_ret_depth--;
+	ftrace_test_recursion_unlock(bit);
 	return -EBUSY;
 }
 
-- 
2.53.0


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

* [PATCH 6.12.y 2/2] fgraph: Do not mark index 0 in every shadow stack frame
  2026-12-03 22:02 ` [PATCH 6.12.y 1/2] fgraph: Get ftrace recursion lock in function_graph_enter Sasha Levin
@ 2026-12-03 22:02   ` Sasha Levin
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-12-03 22:02 UTC (permalink / raw)
  To: stable; +Cc: Breno Leitao, Steven Rostedt, Sasha Levin

From: Breno Leitao <leitao@debian.org>

[ Upstream commit 65f42f1fa03829e0ab1473369461a7aabf525cb2 ]

We are seeing this warning on an arm64 host:

  WARNING: kernel/trace/fprobe.c:676 at fprobe_return+0x260/0x2c8, CPU#16: FuncSched/3281330
  Call trace:
   fprobe_return+0x260/0x2c8 (P)
   ftrace_return_to_handler+0x2bc/0x5a8
   return_to_handler+0x20/0x48
   futex_wait+0xa4/0x218
   do_futex+0xb4/0x1d0
   __arm64_sys_futex+0x15c/0x278

The theory is that function_graph_enter_regs() sets BIT(0) in the bitmap
of every frame, a leftover of an old tail-call check, while the return
path calls the retfunc of every set bit.

A reproducer on linux-next supports the theory. On a fresh boot, with no
other fgraph user yet:

  cd /sys/kernel/tracing
  echo 'f:fpexit vfs_read%return' >> dynamic_events
  echo 1 > events/fprobes/fpexit/enable	# fprobe_graph_ops: index 0
  echo vfs_write > set_ftrace_filter
  echo function_graph > current_tracer	# function_graph: index 1
  echo x > /dev/null			# WARN on vfs_write return

Removing the bit was agreed in the review of the series that added it
[0], but the line stayed. Drop it now.

[0] https://lore.kernel.org/all/20240527093436.7060d358a64cc2ea3213b07b@kernel.org/

Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261112-fgraph-bit0-v1-1-695ad14f4b1e@debian.org
Fixes: 7aa1eaef9f42 ("function_graph: Allow multiple users to attach to function graph")
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/trace/fgraph.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index a58ec55a47f9b..b69a0248da3cb 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -669,11 +669,7 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	if (!bitmap)
 		goto out_ret;
 
-	/*
-	 * Since this function uses fgraph_idx = 0 as a tail-call checking
-	 * flag, set that bit always.
-	 */
-	set_bitmap(current, offset, bitmap | BIT(0));
+	set_bitmap(current, offset, bitmap);
 	ftrace_test_recursion_unlock(bit);
 	return 0;
  out_ret:
-- 
2.53.0


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

end of thread, other threads:[~2026-12-03 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:01 FAILED: patch "[PATCH] fgraph: Do not mark index 0 in every shadow stack frame" failed to apply to 6.12-stable tree gregkh
2026-12-03 22:02 ` [PATCH 6.12.y 1/2] fgraph: Get ftrace recursion lock in function_graph_enter Sasha Levin
2026-12-03 22:02   ` [PATCH 6.12.y 2/2] fgraph: Do not mark index 0 in every shadow stack frame Sasha Levin

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