Skip to content

Commit 4d8d713

Browse files
hbathinigregkh
authored andcommitted
powerpc64/bpf: do not increment tailcall count when prog is NULL
commit 521bd39 upstream. Do not increment tailcall count, if tailcall did not succeed due to missing BPF program. Fixes: ce07614 ("powerpc/bpf: Implement support for tail calls") Cc: stable@vger.kernel.org Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20260303181031.390073-2-hbathini@linux.ibm.com [ Conflict due to missing feature commit 2ed2d8f ("powerpc64/bpf: Support tailcalls with subprogs") resolved accordingly. ] Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c02419f commit 4d8d713

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,27 +430,32 @@ static int bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 o
430430

431431
/*
432432
* tail_call_cnt++;
433+
* Writeback this updated value only if tailcall succeeds.
433434
*/
434435
EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), 1));
435-
EMIT(PPC_RAW_STD(bpf_to_ppc(TMP_REG_1), _R1, bpf_jit_stack_tailcallcnt(ctx)));
436436

437437
/* prog = array->ptrs[index]; */
438-
EMIT(PPC_RAW_MULI(bpf_to_ppc(TMP_REG_1), b2p_index, 8));
439-
EMIT(PPC_RAW_ADD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), b2p_bpf_array));
440-
EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), offsetof(struct bpf_array, ptrs)));
438+
EMIT(PPC_RAW_MULI(bpf_to_ppc(TMP_REG_2), b2p_index, 8));
439+
EMIT(PPC_RAW_ADD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2), b2p_bpf_array));
440+
EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
441+
offsetof(struct bpf_array, ptrs)));
441442

442443
/*
443444
* if (prog == NULL)
444445
* goto out;
445446
*/
446-
EMIT(PPC_RAW_CMPLDI(bpf_to_ppc(TMP_REG_1), 0));
447+
EMIT(PPC_RAW_CMPLDI(bpf_to_ppc(TMP_REG_2), 0));
447448
PPC_BCC_SHORT(COND_EQ, out);
448449

449450
/* goto *(prog->bpf_func + prologue_size); */
450-
EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), offsetof(struct bpf_prog, bpf_func)));
451-
EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1),
452-
FUNCTION_DESCR_SIZE + bpf_tailcall_prologue_size));
453-
EMIT(PPC_RAW_MTCTR(bpf_to_ppc(TMP_REG_1)));
451+
EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
452+
offsetof(struct bpf_prog, bpf_func)));
453+
EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
454+
FUNCTION_DESCR_SIZE + bpf_tailcall_prologue_size));
455+
EMIT(PPC_RAW_MTCTR(bpf_to_ppc(TMP_REG_2)));
456+
457+
/* Writeback updated tailcall count */
458+
EMIT(PPC_RAW_STD(bpf_to_ppc(TMP_REG_1), _R1, bpf_jit_stack_tailcallcnt(ctx)));
454459

455460
/* tear down stack, restore NVRs, ... */
456461
bpf_jit_emit_common_epilogue(image, ctx);

0 commit comments

Comments
 (0)