Skip to content

Commit 9670aa1

Browse files
author
Fox Snowpatch
committed
1 parent 85ff933 commit 9670aa1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,22 @@ 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+
474+
bool bpf_jit_inlines_helper_call(s32 imm)
475+
{
476+
switch (imm) {
477+
case BPF_FUNC_get_smp_processor_id:
478+
case BPF_FUNC_get_current_task:
479+
return true;
480+
default:
481+
return false;
482+
}
483+
}
484+
469485
void *arch_alloc_bpf_trampoline(unsigned int size)
470486
{
471487
return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 19 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));
@@ -1390,6 +1399,16 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
13901399
case BPF_JMP | BPF_CALL:
13911400
ctx->seen |= SEEN_FUNC;
13921401

1402+
if (insn[i].src_reg == BPF_REG_0) {
1403+
if (imm == BPF_FUNC_get_smp_processor_id) {
1404+
EMIT(PPC_RAW_LHZ(insn[i].src_reg, _R13, offsetof(struct paca_struct, paca_index)));
1405+
break;
1406+
} else if (imm == BPF_FUNC_get_current_task) {
1407+
EMIT(PPC_RAW_LD(insn[i].src_reg, _R13, offsetof(struct paca_struct, __current)));
1408+
break;
1409+
}
1410+
}
1411+
13931412
ret = bpf_jit_get_func_addr(fp, &insn[i], extra_pass,
13941413
&func_addr, &func_addr_fixed);
13951414
if (ret < 0)

0 commit comments

Comments
 (0)