[PATCHv2 bpf-next 1/2] arm64/ftrace,bpf: Fix partial regs after bpf_prog_run
Jiri Olsa
olsajiri at gmail.com
Sat Jan 10 09:06:11 PST 2026
On Fri, Jan 09, 2026 at 01:47:23PM +0000, Will Deacon wrote:
> On Fri, Jan 09, 2026 at 10:34:53AM +0100, Jiri Olsa wrote:
> > Mahe reported issue with bpf_override_return helper not working when
> > executed from kprobe.multi bpf program on arm.
> >
> > The problem is that on arm we use alternate storage for pt_regs object
> > that is passed to bpf_prog_run and if any register is changed (which
> > is the case of bpf_override_return) it's not propagated back to actual
> > pt_regs object.
> >
> > Fixing this by introducing and calling ftrace_partial_regs_update function
> > to propagate the values of changed registers (ip and stack).
> >
> > Reported-by: Mahe Tardy <mahe.tardy at gmail.com>
> > Signed-off-by: Jiri Olsa <jolsa at kernel.org>
> > ---
> > v2 changes:
> > - moved ftrace_partial_regs_update to generic code [Will]
> >
> > include/linux/ftrace_regs.h | 25 +++++++++++++++++++++++++
> > kernel/trace/bpf_trace.c | 1 +
> > 2 files changed, 26 insertions(+)
> >
> > diff --git a/include/linux/ftrace_regs.h b/include/linux/ftrace_regs.h
> > index 15627ceea9bc..f9a7c009cdae 100644
> > --- a/include/linux/ftrace_regs.h
> > +++ b/include/linux/ftrace_regs.h
> > @@ -33,6 +33,31 @@ struct ftrace_regs;
> > #define ftrace_regs_get_frame_pointer(fregs) \
> > frame_pointer(&arch_ftrace_regs(fregs)->regs)
> >
> > +static __always_inline void
> > +ftrace_partial_regs_update(const struct ftrace_regs *fregs, struct pt_regs *regs) { }
> > +
> > +#else
> > +
> > +/*
> > + * 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)
> > +{
> > + ftrace_regs_set_instruction_pointer(fregs, instruction_pointer(regs));
> > + ftrace_regs_set_return_value(fregs, regs_return_value(regs));
> > +}
>
> I think the AI thingy is right about dropping the const qualifier here
yes, will resend, thanks
jirka
> but overall I prefer this to the previous revisions. Thanks for sticking
> with it!
>
> Acked-by: Will Deacon <will at kernel.org>
>
> Will
More information about the linux-arm-kernel
mailing list