Re: [PATCH bpf-next v2 07/11] LoongArch: BPF: Support atomics on arena pointers

From: Tiezhu Yang

Date: Mon Jul 06 2026 - 04:02:58 EST


On 2026/7/2 上午10:23, George Guo wrote:
From: George Guo <guodongtai@xxxxxxxxxx>

Implement atomic operations on arena pointers (BPF_PROBE_ATOMIC): the
read-modify-write ops, atomic_fetch_*, xchg, cmpxchg and
load-acquire/store-release. For each, the arena base held in REG_ARENA
is folded into the address and an exception table entry is registered on
the access so a fault is handled like the other arena probes.

The exception entry must point at the actual memory-accessing
instruction rather than the last one emitted: the fetch variants append
a zero-extend after the am* op, and cmpxchg accesses memory with the ll
of an ll/sc loop. Generalise add_exception_handler() to take explicit
fault and resume instruction indices. A faulting ll resumes past the
whole ll/sc loop: if the ll faults the sc is never reached, and once the
ll succeeds the page is mapped so the sc cannot fault, so a single entry
on the ll suffices.

...

bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
{
- if (!in_arena)
- return true;
-
- switch (insn->code) {
- case BPF_STX | BPF_ATOMIC | BPF_W:
- case BPF_STX | BPF_ATOMIC | BPF_DW:
- /* Atomics on arena pointers are not implemented yet. */
- return false;
- }
-

Adding code in patch 6 and deleting it in patch 7
is unnecessary code noise.

Please implement it cleanly in patch 6 from the start.

+ /*
+ * All arena access instructions are implemented: regular and
+ * sign-extending loads/stores (BPF_PROBE_MEM32 / BPF_PROBE_MEM32SX)
+ * and atomics (BPF_PROBE_ATOMIC). The default weak helper rejects
+ * everything, so the override is required to enable arena programs.
+ */
return true;
}

Thanks,
Tiezhu