From: sashiko-bot@kernel.org
To: "George Guo" <dongtai.guo@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v3 2/5] LoongArch: BPF: Add support for exceptions
Date: Thu, 26 Nov 2026 03:59:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-234712@kernel.org> (raw)
In-Reply-To: <20261126034048.7370-3-dongtai.guo@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] LoongArch: BPF: missing save/restore of s7 and s8 for exception
progs
--
commit 64e60e0cab39cdd5da1ae8974c3aaebabf22619c
Author: George Guo <guodongtai@kylinos.cn>
LoongArch: BPF: Add support for exceptions
This commit adds BPF exception handling support to the LoongArch JIT compiler
when CONFIG_UNWINDER_ORC is enabled, updating build_prologue() and
__build_epilogue() so exception callbacks reuse the boundary program's stack
frame.
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 3ff15b64925f1..19907612a51c5 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -120,8 +120,8 @@ static void prepare_bpf_tail_call_cnt(struct jit_ctx *ctx, int *store_offset)
> * +-------------------------+
> * | tcc_ptr |
> * +-------------------------+
> - * | arena |
> - * | (optional) |
> + * | $s6 (arena/exception) |
> + * | (optional) |
> * +-------------------------+ <--BPF_REG_FP
> * | prog->aux->stack_depth |
> * | (optional) |
> @@ -133,6 +133,13 @@ static void build_prologue(struct jit_ctx *ctx)
> int i, stack_adjust = 0, store_offset, bpf_stack_adjust;
> const struct bpf_prog *prog = ctx->prog;
> const bool is_main_prog = !bpf_is_subprog(prog);
> + /*
> + * Exception boundary and callback programs must agree on the frame
> + * layout: the callback reuses the boundary's frame to restore its
> + * callee-saved registers, so the s6 slot is always reserved for them.
> + */
> + const bool is_exception_prog = prog->aux->exception_boundary ||
> + prog->aux->exception_cb;
>
> bpf_stack_adjust = round_up(ctx->prog->aux->stack_depth, 16);
>
> @@ -142,7 +149,7 @@ static void build_prologue(struct jit_ctx *ctx)
> /* To store tcc and tcc_ptr */
> stack_adjust += sizeof(long) * 2;
>
> - if (ctx->arena_vm_start)
> + if (ctx->arena_vm_start || is_exception_prog)
> stack_adjust += sizeof(long);
[ ... ]
> @@ -201,13 +221,14 @@ static void build_prologue(struct jit_ctx *ctx)
>
> prepare_bpf_tail_call_cnt(ctx, &store_offset);
>
> - if (ctx->arena_vm_start) {
> + if (ctx->arena_vm_start || is_exception_prog) {
> store_offset -= sizeof(long);
> emit_insn(ctx, std, REG_ARENA, LOONGARCH_GPR_SP, store_offset);
> }
[ ... ]
> @@ -261,7 +285,7 @@ static void __build_epilogue(struct jit_ctx *ctx, bool is_tail_call)
> /* Skip the unused local 'tcc_ptr' slot to align with arena */
> load_offset -= sizeof(long);
>
> - if (ctx->arena_vm_start) {
> + if (ctx->arena_vm_start || is_exception_prog) {
> load_offset -= sizeof(long);
> emit_insn(ctx, ldd, REG_ARENA, LOONGARCH_GPR_SP, load_offset);
> }
[Severity: High]
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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126034048.7370-1-dongtai.guo@linux.dev?part=2
next prev parent reply other threads:[~2026-11-26 3:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 3:40 [PATCH v3 0/5] LoongArch: BPF: Add private stack, exceptions, large stack and arena support George Guo
2026-11-26 3:40 ` [PATCH v3 1/5] LoongArch: BPF: Add support for private stack George Guo
2026-11-26 3:40 ` [PATCH v3 2/5] LoongArch: BPF: Add support for exceptions George Guo
2026-11-26 3:59 ` sashiko-bot [this message]
2026-11-26 3:40 ` [PATCH v3 3/5] LoongArch: BPF: Allow programs 2 KiB of stack George Guo
2026-11-26 3:40 ` [PATCH v3 4/5] LoongArch: BPF: Add support for signed arena loads George Guo
2026-11-26 3:40 ` [PATCH v3 5/5] LoongArch: BPF: Add support for arena atomics George Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-234712@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dongtai.guo@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox