[PATCH bpf-next v1 10/14] bpf, powerpc: JIT arena kfunc argument rebasing
Kumar Kartikeya Dwivedi <[email protected]>
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
Kfunc parameters annotated with __arena carry a 32-bit arena offset in a BPF register. The kernel function expects a directly dereferenceable kernel address, so the JIT must add the arena kernel mapping base before making the call. Nullable parameters must preserve offset zero as NULL. PowerPC64 already keeps the arena kernel base in r26 for arena memory accesses. Reuse it in the kfunc ABI preparation path: zero-extend each arena argument to 32 bits, skip the addition for nullable zero, and otherwise add r26. Advertise the kfunc-argument capability on PowerPC64 so arena allocation kfuncs can move to suffix annotations without losing PowerPC support. Cc: Hari Bathini <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Naveen N. Rao <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> --- arch/powerpc/net/bpf_jit_comp.c | 5 +++++ arch/powerpc/net/bpf_jit_comp64.c | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index 7b07b43575f1..911088cbabb9 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -527,6 +527,11 @@ bool bpf_jit_supports_kfunc_call(void) return IS_ENABLED(CONFIG_PPC64); } +bool bpf_jit_supports_arena_kfunc_args(void) +{ + return IS_ENABLED(CONFIG_PPC64); +} + bool bpf_jit_supports_private_stack(void) { return IS_ENABLED(CONFIG_PPC64); diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index fc9db691e820..fc235fbfbeb9 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -624,8 +624,24 @@ static int prepare_for_kfunc_call(const struct bpf_prog *fp, u32 *image, for (i = 0; i < m->nr_args; i++) { /* Note that BPF ABI only allows up to 5 args for kfuncs */ u32 reg = bpf_to_ppc(BPF_REG_1 + i), size = m->arg_size[i]; + u8 flags = m->arg_flags[i]; - if (!(m->arg_flags[i] & BTF_FMODEL_SIGNED_ARG)) { + if (flags & BTF_FMODEL_ARENA_ARG) { + if (WARN_ON_ONCE(!ctx->arena_vm_start)) + return -1; + + /* rN = kern_vm_start + (u32)rN */ + if (zero_extend(image, ctx, reg, reg, 4)) + return -1; + if (flags & BTF_FMODEL_NULLABLE_ARG) { + EMIT(PPC_RAW_CMPLDI(reg, 0)); + PPC_BCC_CONST_SHORT(COND_EQ, 8); + } + EMIT(PPC_RAW_ADD(reg, reg, bpf_to_ppc(ARENA_VM_START))); + continue; + } + + if (!(flags & BTF_FMODEL_SIGNED_ARG)) { if (zero_extend(image, ctx, reg, reg, size)) return -1; } else { -- 2.53.0