Skip to content

Commit 3f02bc4

Browse files
Saket Kumar BhaskarKernel Patches Daemon
authored andcommitted
powerpc64/bpf: Support internal-only MOV instruction to resolve per-CPU addrs
With the introduction of commit 7bdbf74 ("bpf: add special internal-only MOV instruction to resolve per-CPU addrs"), a new BPF instruction BPF_MOV64_PERCPU_REG has been added to resolve absolute addresses of per-CPU data from their per-CPU offsets. This update requires enabling support for this instruction in the powerpc JIT compiler. As of commit 7a0268f ("[PATCH] powerpc/64: per cpu data optimisations"), the per-CPU data offset for the CPU is stored in the paca. To support this BPF instruction in the powerpc JIT, the following powerpc instructions are emitted: ld tmp1_reg, 48(13) //Load per-CPU data offset from paca(r13) in tmp1_reg. add dst_reg, src_reg, tmp1_reg //Add the per cpu offset to the dst. mr dst_reg, src_reg //Move src_reg to dst_reg, if src_reg != dst_reg To evaluate the performance improvements introduced by this change, the benchmark described in [1] was employed. Before Change: glob-arr-inc : 41.580 ± 0.034M/s arr-inc : 39.592 ± 0.055M/s hash-inc : 25.873 ± 0.012M/s After Change: glob-arr-inc : 42.024 ± 0.049M/s arr-inc : 55.447 ± 0.031M/s hash-inc : 26.565 ± 0.014M/s [1] anakryiko/linux@8dec900975ef Signed-off-by: Saket Kumar Bhaskar <[email protected]>
1 parent 2412df8 commit 3f02bc4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
466466
return true;
467467
}
468468

469+
bool bpf_jit_supports_percpu_insn(void)
470+
{
471+
return IS_ENABLED(CONFIG_PPC64);
472+
}
473+
469474
void *arch_alloc_bpf_trampoline(unsigned int size)
470475
{
471476
return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
918918
case BPF_ALU | BPF_MOV | BPF_X: /* (u32) dst = src */
919919
case BPF_ALU64 | BPF_MOV | BPF_X: /* dst = src */
920920

921+
if (insn_is_mov_percpu_addr(&insn[i])) {
922+
if (IS_ENABLED(CONFIG_SMP)) {
923+
EMIT(PPC_RAW_LD(tmp1_reg, _R13, offsetof(struct paca_struct, data_offset)));
924+
EMIT(PPC_RAW_ADD(dst_reg, src_reg, tmp1_reg));
925+
} else {
926+
EMIT(PPC_RAW_MR(dst_reg, src_reg));
927+
}
928+
}
929+
921930
if (insn_is_cast_user(&insn[i])) {
922931
EMIT(PPC_RAW_RLDICL_DOT(tmp1_reg, src_reg, 0, 32));
923932
PPC_LI64(dst_reg, (ctx->user_vm_start & 0xffffffff00000000UL));

0 commit comments

Comments
 (0)