Skip to content

Commit 3025209

Browse files
Saket Kumar BhaskarKernel Patches Daemon
authored andcommitted
powerpc64/bpf: Implement bpf_addr_space_cast instruction
LLVM generates bpf_addr_space_cast instruction while translating pointers between native (zero) address space and __attribute__((address_space(N))). The addr_space=0 is reserved as bpf_arena address space. rY = addr_space_cast(rX, 0, 1) is processed by the verifier and converted to normal 32-bit move: wX = wY. rY = addr_space_cast(rX, 1, 0) : used to convert a bpf arena pointer to a pointer in the userspace vma. This has to be converted by the JIT. PPC_RAW_RLDICL_DOT, a variant of PPC_RAW_RLDICL is introduced to set condition register as well. Reviewed-by: Hari Bathini <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Signed-off-by: Saket Kumar Bhaskar <[email protected]>
1 parent f1b1615 commit 3025209

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

arch/powerpc/include/asm/ppc-opcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@
571571
(0x54000001 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH(i) | __PPC_MB(mb) | __PPC_ME(me))
572572
#define PPC_RAW_RLWIMI(d, a, i, mb, me) (0x50000000 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH(i) | __PPC_MB(mb) | __PPC_ME(me))
573573
#define PPC_RAW_RLDICL(d, a, i, mb) (0x78000000 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_MB64(mb))
574+
#define PPC_RAW_RLDICL_DOT(d, a, i, mb) (0x78000000 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_MB64(mb) | 0x1)
574575
#define PPC_RAW_RLDICR(d, a, i, me) (0x78000004 | ___PPC_RA(d) | ___PPC_RS(a) | __PPC_SH64(i) | __PPC_ME64(me))
575576

576577
/* slwi = rlwinm Rx, Ry, n, 0, 31-n */

arch/powerpc/net/bpf_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct codegen_context {
165165
unsigned int exentry_idx;
166166
unsigned int alt_exit_addr;
167167
u64 arena_vm_start;
168+
u64 user_vm_start;
168169
};
169170

170171
#define bpf_to_ppc(r) (ctx->b2p[r])

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
205205
/* Make sure that the stack is quadword aligned. */
206206
cgctx.stack_size = round_up(fp->aux->stack_depth, 16);
207207
cgctx.arena_vm_start = bpf_arena_get_kern_vm_start(fp->aux->arena);
208+
cgctx.user_vm_start = bpf_arena_get_user_vm_start(fp->aux->arena);
208209

209210
/* Scouting faux-generate pass 0 */
210211
if (bpf_jit_build_body(fp, NULL, NULL, &cgctx, addrs, 0, false)) {
@@ -439,6 +440,11 @@ bool bpf_jit_supports_kfunc_call(void)
439440
return true;
440441
}
441442

443+
bool bpf_jit_supports_arena(void)
444+
{
445+
return IS_ENABLED(CONFIG_PPC64);
446+
}
447+
442448
bool bpf_jit_supports_far_kfunc_call(void)
443449
{
444450
return IS_ENABLED(CONFIG_PPC64);

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,16 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
812812
*/
813813
case BPF_ALU | BPF_MOV | BPF_X: /* (u32) dst = src */
814814
case BPF_ALU64 | BPF_MOV | BPF_X: /* dst = src */
815+
816+
if (insn_is_cast_user(&insn[i])) {
817+
EMIT(PPC_RAW_RLDICL_DOT(tmp1_reg, src_reg, 0, 32));
818+
PPC_LI64(dst_reg, (ctx->user_vm_start & 0xffffffff00000000UL));
819+
PPC_BCC_SHORT(COND_EQ, (ctx->idx + 2) * 4);
820+
EMIT(PPC_RAW_OR(tmp1_reg, dst_reg, tmp1_reg));
821+
EMIT(PPC_RAW_MR(dst_reg, tmp1_reg));
822+
break;
823+
}
824+
815825
if (imm == 1) {
816826
/* special mov32 for zext */
817827
EMIT(PPC_RAW_RLWINM(dst_reg, dst_reg, 0, 0, 31));

0 commit comments

Comments
 (0)