Skip to content

Commit 232585d

Browse files
Saket Kumar BhaskarKernel Patches Daemon
Saket Kumar Bhaskar
authored and
Kernel Patches Daemon
committed
powerpc, 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: mr dst_reg, src_reg //Move src_reg to dst_reg, if src_reg != dst_reg ld tmp1_reg, 48(13) //Load per-CPU data offset from paca(r13) in tmp1_reg. add dst_reg, dst_reg, tmp1_reg //Add the per cpu offset to the dst. 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 44c3a1d commit 232585d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

+5
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ bool bpf_jit_supports_far_kfunc_call(void)
440440
return IS_ENABLED(CONFIG_PPC64);
441441
}
442442

443+
bool bpf_jit_supports_percpu_insn(void)
444+
{
445+
return true;
446+
}
447+
443448
void *arch_alloc_bpf_trampoline(unsigned int size)
444449
{
445450
return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);

arch/powerpc/net/bpf_jit_comp64.c

+8
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,14 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
679679
*/
680680
case BPF_ALU | BPF_MOV | BPF_X: /* (u32) dst = src */
681681
case BPF_ALU64 | BPF_MOV | BPF_X: /* dst = src */
682+
if (insn_is_mov_percpu_addr(&insn[i])) {
683+
if (dst_reg != src_reg)
684+
EMIT(PPC_RAW_MR(dst_reg, src_reg));
685+
#ifdef CONFIG_SMP
686+
EMIT(PPC_RAW_LD(tmp1_reg, _R13, offsetof(struct paca_struct, data_offset)));
687+
EMIT(PPC_RAW_ADD(dst_reg, dst_reg, tmp1_reg));
688+
#endif
689+
}
682690
if (imm == 1) {
683691
/* special mov32 for zext */
684692
EMIT(PPC_RAW_RLWINM(dst_reg, dst_reg, 0, 0, 31));

0 commit comments

Comments
 (0)