* [PATCH] parisc: Fix register corruption in 32-bit dynamic ftrace
@ 2026-11-14 18:02 Karl Mehltretter
2026-11-18 22:04 ` Helge Deller
0 siblings, 1 reply; 2+ messages in thread
From: Karl Mehltretter @ 2026-11-14 18:02 UTC (permalink / raw)
To: Helge Deller, James E . J . Bottomley
Cc: Karl Mehltretter, Sven Schnelle, Steven Rostedt, Masami Hiramatsu,
Mark Rutland, linux-parisc, linux-trace-kernel, linux-kernel
The 32-bit dynamic ftrace trampoline allocates a 64-byte frame.
ftrace_caller() saves %r26 at offset 20, which overlaps the third
argument's spill slot for ftrace_function_trampoline().
In the failing build, GCC spills org_sp_gr3 into that slot, overwriting
saved %r26 with the original stack pointer. Tracing preempt_count_add()
then passes that pointer as val and corrupts the preempt count.
Allocate two frames on 32-bit, as 64-bit already does, and update the
generated trampoline instruction to match.
Fixes: 6ca6366220ed ("parisc: add dynamic ftrace")
Cc: stable@vger.kernel.org
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Tested with GCC 16.2.0 on a 32-bit SMP kernel under QEMU 10.0.13:
function tracing of preempt_count_add(), preempt_count_sub() and
update_rq_clock(), followed by a combined function/function-graph
workload. No warnings or faults.
I used an LLM to help isolate the failure, inspect the generated code,
write the test harness and prepare the commit message.
arch/parisc/kernel/entry.S | 4 ----
arch/parisc/kernel/ftrace.c | 2 +-
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/arch/parisc/kernel/entry.S b/arch/parisc/kernel/entry.S
index e04c5d806c105..b0728dbee53d7 100644
--- a/arch/parisc/kernel/entry.S
+++ b/arch/parisc/kernel/entry.S
@@ -1949,11 +1949,7 @@ ENDPROC_CFI(mcount)
#ifdef CONFIG_DYNAMIC_FTRACE
-#ifdef CONFIG_64BIT
#define FTRACE_FRAME_SIZE (2*FRAME_SIZE)
-#else
-#define FTRACE_FRAME_SIZE FRAME_SIZE
-#endif
ENTRY_CFI(ftrace_caller, caller,frame=FTRACE_FRAME_SIZE,CALLS,SAVE_RP,SAVE_SP)
ftrace_caller:
.global ftrace_caller
diff --git a/arch/parisc/kernel/ftrace.c b/arch/parisc/kernel/ftrace.c
index 10fd5b3e63e75..963a741faa42d 100644
--- a/arch/parisc/kernel/ftrace.c
+++ b/arch/parisc/kernel/ftrace.c
@@ -146,7 +146,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
#else
u32 ftrace_trampoline[] = {
(u32)addr,
- 0x6fc10080, /* stw,ma r1,40(sp) */
+ 0x6fc10100, /* stw,ma r1,80(sp) */
0x48213fd1, /* ldw -18(r1),r1 */
0xe820c002, /* bv,n r0(r1) */
0xe83f1fdf, /* b,l,n .-c,r1 */
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] parisc: Fix register corruption in 32-bit dynamic ftrace
2026-11-14 18:02 [PATCH] parisc: Fix register corruption in 32-bit dynamic ftrace Karl Mehltretter
@ 2026-11-18 22:04 ` Helge Deller
0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2026-11-18 22:04 UTC (permalink / raw)
To: Karl Mehltretter, James E . J . Bottomley
Cc: Sven Schnelle, Steven Rostedt, Masami Hiramatsu, Mark Rutland,
linux-parisc, linux-trace-kernel, linux-kernel
On 11/14/26 19:02, Karl Mehltretter wrote:
> The 32-bit dynamic ftrace trampoline allocates a 64-byte frame.
> ftrace_caller() saves %r26 at offset 20, which overlaps the third
> argument's spill slot for ftrace_function_trampoline().
>
> In the failing build, GCC spills org_sp_gr3 into that slot, overwriting
> saved %r26 with the original stack pointer. Tracing preempt_count_add()
> then passes that pointer as val and corrupts the preempt count.
>
> Allocate two frames on 32-bit, as 64-bit already does, and update the
> generated trampoline instruction to match.
>
> Fixes: 6ca6366220ed ("parisc: add dynamic ftrace")
> Cc: stable@vger.kernel.org
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> Tested with GCC 16.2.0 on a 32-bit SMP kernel under QEMU 10.0.13:
> function tracing of preempt_count_add(), preempt_count_sub() and
> update_rq_clock(), followed by a combined function/function-graph
> workload. No warnings or faults.
>
> I used an LLM to help isolate the failure, inspect the generated code,
> write the test harness and prepare the commit message.
>
> arch/parisc/kernel/entry.S | 4 ----
> arch/parisc/kernel/ftrace.c | 2 +-
> 2 files changed, 1 insertion(+), 5 deletions(-)
applied.
Thanks!
Helge
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 22:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 18:02 [PATCH] parisc: Fix register corruption in 32-bit dynamic ftrace Karl Mehltretter
2026-11-18 22:04 ` Helge Deller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox