From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, yangtiezhu@loongson.cn
Cc: hengqi.chen@gmail.com, guodongtai@kylinos.cn,
bpf@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 4/6] LoongArch: BPF: Add support for signed arena loads
Date: Tue, 1 Dec 2026 01:51:04 -0800 [thread overview]
Message-ID: <20261201095106.468000-5-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20261201095106.468000-1-dongtai.guo@linux.dev>
From: George Guo <guodongtai@kylinos.cn>
Currently, the verifier rejects sign-extending loads from arena on
LoongArch with "sign extending loads from arena are not supported yet",
because the JIT does not implement bpf_jit_supports_insn() and the weak
default returns false.
In order to support them, implement bpf_jit_supports_insn() and handle
BPF_PROBE_MEM32SX like BPF_PROBE_MEM32: add the arena base held in
REG_ARENA to the address, use sign-extending load instructions, and add
an exception table entry for the load.
This is similar to commit b4757714cc63 ("bpf, riscv: Add support for
signed arena loads").
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
arch/loongarch/net/bpf_jit.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 04b40558a859..423c9807a84a 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -741,7 +741,8 @@ static int add_exception_handler(const struct bpf_insn *insn,
if (BPF_MODE(insn->code) != BPF_PROBE_MEM &&
BPF_MODE(insn->code) != BPF_PROBE_MEMSX &&
- BPF_MODE(insn->code) != BPF_PROBE_MEM32)
+ BPF_MODE(insn->code) != BPF_PROBE_MEM32 &&
+ BPF_MODE(insn->code) != BPF_PROBE_MEM32SX)
return 0;
if (WARN_ON_ONCE(ctx->num_exentries >= ctx->prog->aux->num_exentries))
@@ -1421,10 +1422,16 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
case BPF_LDX | BPF_PROBE_MEM32 | BPF_H:
case BPF_LDX | BPF_PROBE_MEM32 | BPF_W:
case BPF_LDX | BPF_PROBE_MEM32 | BPF_DW:
+ /* LDX | PROBE_MEM32SX: dst = *(signed size *)(src + REG_ARENA + off) */
+ case BPF_LDX | BPF_PROBE_MEM32SX | BPF_B:
+ case BPF_LDX | BPF_PROBE_MEM32SX | BPF_H:
+ case BPF_LDX | BPF_PROBE_MEM32SX | BPF_W:
sign_extend = BPF_MODE(code) == BPF_MEMSX ||
- BPF_MODE(code) == BPF_PROBE_MEMSX;
+ BPF_MODE(code) == BPF_PROBE_MEMSX ||
+ BPF_MODE(code) == BPF_PROBE_MEM32SX;
- if (BPF_MODE(code) == BPF_PROBE_MEM32) {
+ if (BPF_MODE(code) == BPF_PROBE_MEM32 ||
+ BPF_MODE(code) == BPF_PROBE_MEM32SX) {
emit_insn(ctx, addd, t2, src, REG_ARENA);
src = t2;
}
@@ -2708,6 +2715,11 @@ bool bpf_jit_supports_arena(void)
#endif
}
+bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
+{
+ return true;
+}
+
bool bpf_jit_supports_fsession(void)
{
return true;
--
2.53.0
next prev parent reply other threads:[~2026-12-01 9:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:51 [PATCH v4 0/6] LoongArch: BPF: Add private stack, exceptions, large stack and arena support George Guo
2026-12-01 9:51 ` [PATCH v4 1/6] LoongArch: BPF: Add support for private stack George Guo
2026-12-01 9:51 ` [PATCH v4 2/6] LoongArch: BPF: Allow programs 2 KiB of stack George Guo
2026-12-01 9:51 ` [PATCH v4 3/6] LoongArch: BPF: Add support for exceptions George Guo
2026-12-01 9:51 ` George Guo [this message]
2026-12-01 9:51 ` [PATCH v4 5/6] LoongArch: BPF: Consolidate zero-extension in emit_atomic_rmw() George Guo
2026-12-01 9:51 ` [PATCH v4 6/6] LoongArch: BPF: Add support for arena atomics George Guo
2026-12-01 10:11 ` sashiko-bot
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=20261201095106.468000-5-dongtai.guo@linux.dev \
--to=dongtai.guo@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=chenhuacai@kernel.org \
--cc=guodongtai@kylinos.cn \
--cc=hengqi.chen@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=yangtiezhu@loongson.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.