Main programs receive a single 32-bit pointer as the first argument, so the current prologue converts it to the 64-bit BPF_REG_1 by moving R3 to R4 and zeroing R3. However, subprograms are called like helper functions, so there the first argument already is 64-bit - but the prologue still does its conversion, so the argument ends up with its halves swapped and the upper one zeroed. The same problem applies to the return value. In particular, in the common case where the first argument is a context pointer, the callee ends up with the upper (zeroed) 32 bits, which then triggers a kernel panic as soon as it's used. Therefore, make JIT emit the appropriate 64-bit prologue/epilogue for subprograms. Fixes: 51c66ad849a7 ("powerpc/bpf: Implement extended BPF on PPC32") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index f5b9441cf46a..261ac0646b96 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -179,9 +179,11 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx) if (ctx->seen & SEEN_TAILCALL) EMIT(PPC_RAW_STW(_R4, _R1, bpf_jit_stack_offsetof(ctx, BPF_PPC_TC))); - /* First arg comes in as a 32 bits pointer. */ - EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_1), _R3)); - EMIT(PPC_RAW_LI(bpf_to_ppc(BPF_REG_1) - 1, 0)); + /* Programs receive the first arg as a 32 bits pointer, subprograms don't. */ + if (!ctx->is_subprog) { + EMIT(PPC_RAW_MR(bpf_to_ppc(BPF_REG_1), _R3)); + EMIT(PPC_RAW_LI(bpf_to_ppc(BPF_REG_1) - 1, 0)); + } /* * We need a stack frame, but we don't necessarily need to @@ -231,7 +233,13 @@ static void bpf_jit_emit_common_epilogue(u32 *image, struct codegen_context *ctx void bpf_jit_build_epilogue(u32 *image, u32 *fimage, struct codegen_context *ctx) { - EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0))); + /* Programs return a 32-bit value, while subprograms return 64 bit. */ + if (ctx->is_subprog) { + EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0) - 1)); + EMIT(PPC_RAW_MR(_R4, bpf_to_ppc(BPF_REG_0))); + } else { + EMIT(PPC_RAW_MR(_R3, bpf_to_ppc(BPF_REG_0))); + } bpf_jit_emit_common_epilogue(image, ctx); -- 2.56.0 Commit 7dd0e2848764 ("powerpc/bpf/32: BPF prog is never called with more than one arg") removed the BPF_REG_5 load since it's not used for program arguments, but that is only true for regular programs - subprograms may get up to five arguments, so the load is required there. Fixes: 7dd0e2848764 ("powerpc/bpf/32: BPF prog is never called with more than one arg") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 261ac0646b96..9f55dd4bdfd6 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -199,6 +199,13 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx) if (bpf_is_seen_register(ctx, i)) EMIT(PPC_RAW_STW(i, _R1, bpf_jit_stack_offsetof(ctx, i))); + /* If this is a subprogram, load fifth argument from the stack */ + if (ctx->is_subprog && bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_5))) { + int offset = bpf_has_stack_frame(ctx) ? BPF_PPC_STACKFRAME(ctx) : 0; + EMIT(PPC_RAW_LWZ(bpf_to_ppc(BPF_REG_5) - 1, _R1, offset + 8)); + EMIT(PPC_RAW_LWZ(bpf_to_ppc(BPF_REG_5), _R1, offset + 12)); + } + /* Setup frame pointer to point to the bpf stack area */ if (bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_FP))) { EMIT(PPC_RAW_LI(bpf_to_ppc(BPF_REG_FP) - 1, 0)); -- 2.56.0 The JIT code tracks which registers are used and remaps based on that, but currently does not account for the fact that function calls implicitly use registers because the called function will treat them as arguments. Therefore, if a function merely passes through one of its arguments to another function call, it will incorrectly be considered unused and may be overwritten with another register's contents. In practice, this is unlikely to affect main programs as they only get one argument (the context, which they are very likely to touch somehow in addition to passing it on), so they'll have to touch other registers if they want to pass them as arguments. Subprograms, however, are much likelier to hit this. Similarly, tail calls pass R1 to the callee, so mark it used as well. Fixes: 51c66ad849a7 ("powerpc/bpf: Implement extended BPF on PPC32") Fixes: a8936569a07b ("powerpc/bpf: Always reallocate BPF_REG_5, BPF_REG_AX and TMP_REG when possible") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 9f55dd4bdfd6..7414e350d2d4 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -339,7 +339,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code { const struct bpf_insn *insn = fp->insnsi; int flen = fp->len; - int i, ret; + int i, ret, max_arg; /* Start of epilogue code - will only be valid 2nd pass onwards */ u32 exit_addr = addrs[flen]; @@ -1183,6 +1183,18 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code if (ret < 0) return ret; + /* + * We don't know which arguments the called function will use, + * so if this is a subprogram, assume the worst case where it + * uses all of them. Regular programs only get one argument, + * so any others would have been explicitly set. + */ + max_arg = ctx->is_subprog ? BPF_REG_5 : BPF_REG_1; + for (int reg = BPF_REG_1; reg <= max_arg; ++reg) { + bpf_set_seen_register(ctx, bpf_to_ppc(reg) - 1); + bpf_set_seen_register(ctx, bpf_to_ppc(reg)); + } + if (bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_5))) { EMIT(PPC_RAW_STW(bpf_to_ppc(BPF_REG_5) - 1, _R1, 8)); EMIT(PPC_RAW_STW(bpf_to_ppc(BPF_REG_5), _R1, 12)); @@ -1412,6 +1424,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code * Tail call */ case BPF_JMP | BPF_TAIL_CALL: + bpf_set_seen_register(ctx, bpf_to_ppc(BPF_REG_1) - 1); + bpf_set_seen_register(ctx, bpf_to_ppc(BPF_REG_1)); + ctx->seen |= SEEN_TAILCALL; ret = bpf_jit_emit_tail_call(image, ctx, addrs[i + 1]); if (ret < 0) -- 2.56.0 The PPC32 eBPF JIT folds MOVs followed by an ALU operation to the same destination into 3-operand PPC instructions, but currently it doesn't check whether the MOV is supposed to perform sign-extension, so MOVSX effectively gets transformed into a plain MOV. To fix this, just skip 3-op folding for MOVSX. Fixes: 8ecf3c1dab1c ("powerpc/bpf/32: Fix failing test_bpf tests") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 7414e350d2d4..c6cc562cf88c 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -367,7 +367,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code if (i && (BPF_CLASS(code) == BPF_ALU64 || BPF_CLASS(code) == BPF_ALU) && (BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) == BPF_ALU) && BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X && - insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm != 1) { + insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm != 1 && + insn[i - 1].off == 0) { src2_reg = bpf_to_ppc(insn[i - 1].src_reg); src2_reg_h = src2_reg - 1; ctx->idx = addrs[i - 1] / 4; -- 2.56.0 The current 3-operand folding combines a MOV to a register with a subsequent ALU operation to the same register into 3-op instructions, which use the source of the MOV and the operand of the ALU op as the two source operands. However, if the source of the ALU op is the same register that the previous MOV was supposed to go to, the resulting instruction will end up using the previous content of the destination register. For example, "r2 = r1; r2 += r2" gets folded to "r2 = r1 + r2", while the correct result would be "r2 = r1 + r1". Therefore, check for this, and use the MOV source for both operands in that case. Fixes: 19daf0aef84f ("powerpc/bpf/32: perform three operands ALU operations") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index c6cc562cf88c..2c3d94c94ed7 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -371,6 +371,10 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code insn[i - 1].off == 0) { src2_reg = bpf_to_ppc(insn[i - 1].src_reg); src2_reg_h = src2_reg - 1; + if (BPF_SRC(code) == BPF_X && insn[i].src_reg == insn[i - 1].dst_reg) { + src_reg = src2_reg; + src_reg_h = src2_reg_h; + } ctx->idx = addrs[i - 1] / 4; } -- 2.56.0 ALU operations in the PPC32 eBPF JIT are supposed to use src2_reg, not dst_reg, as the second source operand in order to work correctly when a MOV was folded into them. However, a few operations don't correctly do this yet, so fix them. Fixes: 19daf0aef84f ("powerpc/bpf/32: perform three operands ALU operations") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 32 ++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 2c3d94c94ed7..83457b21d0a8 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -495,7 +495,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code } else if (imm > 0 && is_power_of_2(imm)) { imm = ilog2(imm); EMIT(PPC_RAW_RLWINM(dst_reg_h, src2_reg_h, imm, 0, 31 - imm)); - EMIT(PPC_RAW_RLWIMI(dst_reg_h, dst_reg, imm, 32 - imm, 31)); + EMIT(PPC_RAW_RLWIMI(dst_reg_h, src2_reg, imm, 32 - imm, 31)); EMIT(PPC_RAW_SLWI(dst_reg, src2_reg, imm)); } else { bpf_set_seen_register(ctx, tmp_reg); @@ -603,6 +603,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code EMIT(PPC_RAW_SUBFZE(dst_reg_h, src2_reg_h)); imm = -imm; src2_reg = dst_reg; + src2_reg_h = dst_reg_h; } if (imm == 1) { EMIT(PPC_RAW_MR(dst_reg, src2_reg)); @@ -635,6 +636,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code case BPF_ALU64 | BPF_AND | BPF_K: /* dst = dst & imm */ if (imm >= 0) EMIT(PPC_RAW_LI(dst_reg_h, 0)); + else if (dst_reg_h != src2_reg_h) + EMIT(PPC_RAW_MR(dst_reg_h, src2_reg_h)); fallthrough; case BPF_ALU | BPF_AND | BPF_K: /* (u32) dst = dst & imm */ if (!IMM_H(imm)) { @@ -660,6 +663,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code /* Sign-extended */ if (imm < 0) EMIT(PPC_RAW_LI(dst_reg_h, -1)); + else if (dst_reg_h != src2_reg_h) + EMIT(PPC_RAW_MR(dst_reg_h, src2_reg_h)); fallthrough; case BPF_ALU | BPF_OR | BPF_K:/* dst = (u32) dst | (u32) imm */ if (IMM_L(imm)) { @@ -668,6 +673,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code } if (IMM_H(imm)) EMIT(PPC_RAW_ORIS(dst_reg, src2_reg, IMM_H(imm))); + else if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); break; case BPF_ALU64 | BPF_XOR | BPF_X: /* dst ^= src */ if (dst_reg == src_reg) { @@ -687,6 +694,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code case BPF_ALU64 | BPF_XOR | BPF_K: /* dst ^= imm */ if (imm < 0) EMIT(PPC_RAW_NOR(dst_reg_h, src2_reg_h, src2_reg_h)); + else if (dst_reg_h != src2_reg_h) + EMIT(PPC_RAW_MR(dst_reg_h, src2_reg_h)); fallthrough; case BPF_ALU | BPF_XOR | BPF_K: /* (u32) dst ^= (u32) imm */ if (IMM_L(imm)) { @@ -695,6 +704,8 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code } if (IMM_H(imm)) EMIT(PPC_RAW_XORIS(dst_reg, src2_reg, IMM_H(imm))); + else if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); break; case BPF_ALU | BPF_LSH | BPF_X: /* (u32) dst <<= (u32) src */ EMIT(PPC_RAW_SLW(dst_reg, src2_reg, src_reg)); @@ -720,7 +731,10 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code if (imm < 0) return -EINVAL; if (!imm) { - EMIT(PPC_RAW_MR(dst_reg, src2_reg)); + if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); + if (dst_reg_h != src2_reg_h) + EMIT(PPC_RAW_MR(dst_reg_h, src2_reg_h)); } else if (imm < 32) { EMIT(PPC_RAW_RLWINM(dst_reg_h, src2_reg_h, imm, 0, 31 - imm)); EMIT(PPC_RAW_RLWIMI(dst_reg_h, src2_reg, imm, 32 - imm, 31)); @@ -742,7 +756,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code EMIT(PPC_RAW_SRW(dst_reg, src2_reg, src_reg)); EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); EMIT(PPC_RAW_SLW(_R0, src2_reg_h, _R0)); - EMIT(PPC_RAW_SRW(tmp_reg, dst_reg_h, tmp_reg)); + EMIT(PPC_RAW_SRW(tmp_reg, src2_reg_h, tmp_reg)); EMIT(PPC_RAW_OR(dst_reg, dst_reg, _R0)); EMIT(PPC_RAW_SRW(dst_reg_h, src2_reg_h, src_reg)); EMIT(PPC_RAW_OR(dst_reg, dst_reg, tmp_reg)); @@ -834,8 +848,11 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code break; case BPF_ALU | BPF_MOV | BPF_X: /* (u32) dst = src */ /* special mov32 for zext */ - if (imm == 1) + if (imm == 1) { + if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); EMIT(PPC_RAW_LI(dst_reg_h, 0)); + } else if (off == 8) EMIT(PPC_RAW_EXTSB(dst_reg, src_reg)); else if (off == 16) @@ -858,6 +875,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code case BPF_ALU64 | BPF_END | BPF_FROM_LE: switch (imm) { case 16: + /* Copy lower half if needed. */ + if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); /* Copy 16 bits to upper part */ EMIT(PPC_RAW_RLWIMI(dst_reg, src2_reg, 16, 0, 15)); /* Rotate 8 bits right & mask */ @@ -901,7 +921,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code break; case 32: case 64: - /* nop */ + /* nop, just move if needed */ + if (dst_reg != src2_reg) + EMIT(PPC_RAW_MR(dst_reg, src2_reg)); break; } break; -- 2.56.0 If a BPF program jumps to an ALU instruction that was combined with a preceding MOV, it will incorrectly execute both the MOV and the ALU operation. Therefore, avoid 3-op folding if the second instruction is a jump target. Fixes: 19daf0aef84f ("powerpc/bpf/32: perform three operands ALU operations") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit.h | 4 ++-- arch/powerpc/net/bpf_jit_comp.c | 8 ++++---- arch/powerpc/net/bpf_jit_comp32.c | 6 +++--- arch/powerpc/net/bpf_jit_comp64.c | 5 +++-- include/linux/bpf.h | 2 ++ kernel/bpf/core.c | 9 +++++++++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h index 4da8bde92e1e..fea87cc88b85 100644 --- a/arch/powerpc/net/bpf_jit.h +++ b/arch/powerpc/net/bpf_jit.h @@ -224,8 +224,8 @@ static inline void bpf_clear_seen_register(struct codegen_context *ctx, int i) void bpf_jit_init_reg_mapping(struct codegen_context *ctx); int bpf_jit_emit_func_call_rel(u32 *image, u32 *fimage, struct codegen_context *ctx, u64 func); -int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct codegen_context *ctx, - u32 *addrs, int pass, bool extra_pass); +int bpf_jit_build_body(struct bpf_verifier_env *env, struct bpf_prog *fp, u32 *image, u32 *fimage, + struct codegen_context *ctx, u32 *addrs, int pass, bool extra_pass); void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx); void bpf_jit_build_epilogue(u32 *image, u32 *fimage, struct codegen_context *ctx); void bpf_jit_build_fentry_stubs(u32 *image, u32 *fimage, struct codegen_context *ctx); diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index ce2966c52ac5..01151a78f2b2 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -289,7 +289,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr } /* Scouting faux-generate pass 0 */ - if (bpf_jit_build_body(fp, NULL, NULL, &cgctx, addrs, 0, false)) + if (bpf_jit_build_body(env, fp, NULL, NULL, &cgctx, addrs, 0, false)) /* We hit something illegal or unsupported. */ goto out_err; @@ -303,7 +303,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr if (cgctx.seen & SEEN_TAILCALL || !is_offset_in_branch_range((long)cgctx.idx * 4)) { cgctx.idx = 0; cgctx.alt_exit_addr = 0; - if (bpf_jit_build_body(fp, NULL, NULL, &cgctx, addrs, 0, false)) + if (bpf_jit_build_body(env, fp, NULL, NULL, &cgctx, addrs, 0, false)) goto out_err; } @@ -344,8 +344,8 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr cgctx.exentry_idx = 0; cgctx.alt_exit_addr = 0; bpf_jit_build_prologue(code_base, &cgctx); - if (bpf_jit_build_body(fp, code_base, fcode_base, &cgctx, addrs, pass, - extra_pass)) { + if (bpf_jit_build_body(env, fp, code_base, fcode_base, &cgctx, addrs, + pass, extra_pass)) { bpf_arch_text_copy(&fhdr->size, &hdr->size, sizeof(hdr->size)); bpf_jit_binary_pack_free(fhdr, hdr); goto out_err; diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 83457b21d0a8..ec2d5ce2f70a 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -334,8 +334,8 @@ static int bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 o } /* Assemble the body code between the prologue & epilogue */ -int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct codegen_context *ctx, - u32 *addrs, int pass, bool extra_pass) +int bpf_jit_build_body(struct bpf_verifier_env *env, struct bpf_prog *fp, u32 *image, u32 *fimage, + struct codegen_context *ctx, u32 *addrs, int pass, bool extra_pass) { const struct bpf_insn *insn = fp->insnsi; int flen = fp->len; @@ -368,7 +368,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code (BPF_CLASS(prevcode) == BPF_ALU64 || BPF_CLASS(prevcode) == BPF_ALU) && BPF_OP(prevcode) == BPF_MOV && BPF_SRC(prevcode) == BPF_X && insn[i - 1].dst_reg == insn[i].dst_reg && insn[i - 1].imm != 1 && - insn[i - 1].off == 0) { + insn[i - 1].off == 0 && !bpf_insn_is_jump_target(env, fp, i)) { src2_reg = bpf_to_ppc(insn[i - 1].src_reg); src2_reg_h = src2_reg - 1; if (BPF_SRC(code) == BPF_X && insn[i].src_reg == insn[i - 1].dst_reg) { diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index c1e86fe0bd79..d7edb2723f42 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -964,8 +964,9 @@ static int emit_atomic_ld_st(const struct bpf_insn insn, struct codegen_context } /* Assemble the body code between the prologue & epilogue */ -int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct codegen_context *ctx, - u32 *addrs, int pass, bool extra_pass) +int bpf_jit_build_body(struct bpf_verifier_env *env __always_unused, struct bpf_prog *fp, + u32 *image, u32 *fimage, struct codegen_context *ctx, u32 *addrs, int pass, + bool extra_pass) { enum stf_barrier_type stf_barrier = stf_barrier_type_get(); bool sync_emitted, ori31_emitted; diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 1dd9db16f324..c1a7a0be3a9c 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1697,6 +1697,8 @@ void bpf_jit_uncharge_modmem(u32 size); bool bpf_prog_has_trampoline(const struct bpf_prog *prog); bool bpf_insn_is_indirect_target(const struct bpf_verifier_env *env, const struct bpf_prog *prog, int insn_idx); +bool bpf_insn_is_jump_target(const struct bpf_verifier_env *env, const struct bpf_prog *prog, + int insn_idx); u16 bpf_out_stack_arg_cnt(const struct bpf_verifier_env *env, const struct bpf_prog *prog); #else static inline int bpf_trampoline_link_prog(struct bpf_tramp_node *node, diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 0bfd23a41401..27c200f43dd5 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1662,6 +1662,15 @@ bool bpf_insn_is_indirect_target(const struct bpf_verifier_env *env, const struc return env->insn_aux_data[insn_idx].indirect_target; } +bool bpf_insn_is_jump_target(const struct bpf_verifier_env *env, const struct bpf_prog *prog, + int insn_idx) +{ + if (!env) + return false; + insn_idx += prog->aux->subprog_start; + return env->insn_aux_data[insn_idx].jump_target; +} + u16 bpf_out_stack_arg_cnt(const struct bpf_verifier_env *env, const struct bpf_prog *prog) { const struct bpf_subprog_info *sub; -- 2.56.0