Re: [PATCH bpf-next 1/2] arm64/ftrace,bpf: Fix partial regs after bpf_prog_run
From: Jiri Olsa <hidden>
Date: 2026-01-08 14:32:45
Also in:
bpf, linux-arm-kernel
On Wed, Jan 07, 2026 at 11:03:52AM -0500, Steven Rostedt wrote:
On Wed, 7 Jan 2026 10:32:55 +0100 Jiri Olsa [off-list ref] wrote:quoted
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 1621c84f44b3..177c7bbf3b84 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h@@ -157,6 +157,30 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) return regs; }See my reply in the other email thread: https://lore.kernel.org/all/20260107105316.2b70a308@gandalf.local.home/ (local)
ah ok, thanks jirka
-- Stevequoted
+/* + * ftrace_partial_regs_update - update the original ftrace_regs from regs + * @fregs: The ftrace_regs to update from @regs + * @regs: The partial regs from ftrace_partial_regs() that was updated + * + * Some architectures have the partial regs living in the ftrace_regs + * structure, whereas other architectures need to make a different copy + * of the @regs. If a partial @regs is retrieved by ftrace_partial_regs() and + * if the code using @regs updates a field (like the instruction pointer or + * stack pointer) it may need to propagate that change to the original @fregs + * it retrieved the partial @regs from. Use this function to guarantee that + * update happens. + */ +static __always_inline void +ftrace_partial_regs_update(const struct ftrace_regs *fregs, struct pt_regs *regs) +{ + struct __arch_ftrace_regs *afregs = arch_ftrace_regs(fregs); + + if (afregs->pc != regs->pc) { + afregs->pc = regs->pc; + afregs->regs[0] = regs->regs[0]; + } +}