From: sashiko-bot@kernel.org
To: "Chenguang Zhao" <zhaochenguang@kylinos.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 1/4] LoongArch: bpf: Use amswap_db for BPF atomic xchg
Date: Wed, 03 Jun 2026 10:16:32 +0000 [thread overview]
Message-ID: <20260603101633.25FFA1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603100438.2177817-2-zhaochenguang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch incompletely fixes memory ordering for value-returning BPF atomic RMW instructions. While it adds full barriers for 32/64-bit BPF_XCHG by emitting `amswap_db`, it misses other BPF_FETCH operations, sub-word BPF_XCHG, and BPF_CMPXCHG, leaving them weakly ordered.
--
commit f10ece83a8a616fba153a535a64e9160f3060f64
Author: Chenguang Zhao <zhaochenguang@kylinos.cn>
LoongArch: bpf: Use amswap_db for BPF atomic xchg
The patch updates the LoongArch BPF JIT to use amswap_db.{w,d} instead of
plain amswap.{w,d} for 32-bit and 64-bit BPF_XCHG instructions. This ensures
that value-returning atomic exchanges provide the full memory barrier required
by the Linux Kernel Memory Model.
> diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h
> index 76b723590023d..636cfc524b020 100644
> --- a/arch/loongarch/include/asm/inst.h
> +++ b/arch/loongarch/include/asm/inst.h
[ ... ]
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 24913dc7f4e83..f071d913e0545 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -482,11 +482,11 @@ static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
> emit_zext_32(ctx, src, true);
> break;
> case BPF_W:
> - emit_insn(ctx, amswapw, src, t1, t3);
> + emit_insn(ctx, amswapdbw, src, t1, t3);
> emit_zext_32(ctx, src, true);
> break;
> case BPF_DW:
> - emit_insn(ctx, amswapd, src, t1, t3);
> + emit_insn(ctx, amswapdbd, src, t1, t3);
> break;
> }
> break;
[Severity: High]
This is a pre-existing issue, but does this patch fully resolve the memory
ordering requirements for BPF atomics?
Per the LKMM and BPF documentation, all atomic RMW operations that return a
value must have sequentially consistent memory ordering (a full memory
barrier). While this patch addresses 32-bit and 64-bit BPF_XCHG, several other
value-returning atomics in emit_atomic_rmw() appear to still use weakly
ordered instructions.
For example, BPF_FETCH operations use plain amadd.w and amadd.d:
case BPF_ADD | BPF_FETCH:
switch (BPF_SIZE(insn->code)) {
...
case BPF_W:
emit_insn(ctx, amaddw, src, t1, t3);
emit_zext_32(ctx, src, true);
break;
case BPF_DW:
emit_insn(ctx, amaddd, src, t1, t3);
break;
Sub-word BPF_XCHG operations still emit weakly ordered amswap.b and amswap.h
without explicit barriers:
case BPF_XCHG:
switch (BPF_SIZE(insn->code)) {
case BPF_B:
...
emit_insn(ctx, amswapb, src, t1, t3);
...
case BPF_H:
...
emit_insn(ctx, amswaph, src, t1, t3);
Additionally, BPF_CMPXCHG emits a bare ll and sc loop without the required
dbar (e.g., dbar 0x700) before and after the loop:
case BPF_CMPXCHG:
...
if (isdw) {
emit_insn(ctx, lld, r0, t1, 0);
emit_insn(ctx, bne, t2, r0, 4);
move_reg(ctx, t3, src);
emit_insn(ctx, scd, t3, t1, 0);
emit_insn(ctx, beq, t3, LOONGARCH_GPR_ZERO, -4);
Could we also update these other value-returning atomic instructions in
emit_atomic_rmw() so that all lockless BPF algorithms execute safely?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260603100438.2177817-1-zhaochenguang@kylinos.cn?part=1
next prev parent reply other threads:[~2026-06-03 10:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 10:04 [PATCH v2 0/4] LoongArch bpf kptr xchg inline support Chenguang Zhao
2026-06-03 10:04 ` [PATCH v2 1/4] LoongArch: bpf: Use amswap_db for BPF atomic xchg Chenguang Zhao
2026-06-03 10:16 ` sashiko-bot [this message]
2026-06-03 10:59 ` bot+bpf-ci
2026-06-03 10:04 ` [PATCH v2 2/4] LoongArch: bpf: Advertise JIT support for kptr xchg inline Chenguang Zhao
2026-06-03 10:27 ` sashiko-bot
2026-06-03 10:41 ` bot+bpf-ci
2026-06-03 10:04 ` [PATCH v2 3/4] selftests/bpf: Enable kptr_xchg_inline test on LoongArch Chenguang Zhao
2026-06-03 10:04 ` [PATCH v2 4/4] selftests/bpf: Add kptr-xchg benchmark Chenguang Zhao
2026-06-03 10:40 ` 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=20260603101633.25FFA1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhaochenguang@kylinos.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.