Re: [PATCH RFC bpf-next v1 2/4] bpf: Introduce load-acquire and store-release instructions

From: Peilin Ye
Date: Fri Dec 27 2024 - 04:20:30 EST


On Fri, Dec 27, 2024 at 12:23:22AM +0000, Peilin Ye wrote:
> if (off) {
> - emit_a64_mov_i(true, tmp, off, ctx);
> - emit(A64_ADD(true, tmp, tmp, ptr), ctx);
> - ptr = tmp;
> + if (is_addsub_imm(off)) {
> + emit(A64_ADD_I(true, ptr, ptr, off), ctx);
~~~

> + } else if (is_addsub_imm(-off)) {
> + emit(A64_SUB_I(true, ptr, ptr, -off), ctx);
~~~

No, I must not write to the 'ptr' register here.

> + } else {
> + emit_a64_mov_i(true, tmp, off, ctx);
> + emit(A64_ADD(true, tmp, tmp, ptr), ctx);
> + ptr = tmp;
> + }
> }

I will do this instead:

--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -658,8 +658,14 @@ static int emit_atomic_load_store(const struct bpf_insn *insn, struct jit_ctx *c
ptr = dst;

if (off) {
- emit_a64_mov_i(true, tmp, off, ctx);
- emit(A64_ADD(true, tmp, tmp, ptr), ctx);
+ if (is_addsub_imm(off)) {
+ emit(A64_ADD_I(true, tmp, ptr, off), ctx);
+ } else if (is_addsub_imm(-off)) {
+ emit(A64_SUB_I(true, tmp, ptr, -off), ctx);
+ } else {
+ emit_a64_mov_i(true, tmp, off, ctx);
+ emit(A64_ADD(true, tmp, tmp, ptr), ctx);
+ }
ptr = tmp;
}
if (arena) {

Thanks,
Peilin Ye