Re: [PATCH v3 2/5] LoongArch: BPF: Add support for exceptions
From: George Guo
Date: Tue Dec 01 2026 - 03:08:23 EST
On 2026/11/26 03:59, sashiko-bot@xxxxxxxxxx wrote:
> Do build_prologue() and __build_epilogue() also need to save and restore
> LOONGARCH_GPR_S7 and LOONGARCH_GPR_S8 when is_exception_prog is true?
>
> In the LoongArch C ABI, s0 through s8 are callee-saved registers. JITed BPF
> programs normally leave s7 and s8 untouched, and any called C function saves
> and restores them in its own frame. When bpf_throw() unwinds the stack,
> however, bpf_throw() and its callees never run their epilogues; the exception
> callback restores only the boundary frame and returns directly to the
> boundary program's caller, leaving s7 and s8 clobbered if any unwound C
> function used them.
Yes, this is a real issue. The JIT does not save $s7 and $s8 because it
never uses them, but the C functions between the boundary program and
bpf_throw() may use them, and their epilogues never run. So the caller
of the boundary program can get $s7 and $s8 back clobbered.
Will fix in v4: reserve two more slots below the $s6 slot for the
boundary and callback programs, save $s7 and $s8 there in the prologue
and restore them in the epilogue. The callback reuses the frame of the
boundary program, so its epilogue restores the values saved by the
boundary program.
Thanks,
George