Re: [PATCH v2 1/5] powerpc64/bpf: do not increment tailcall count when prog is NULL

Venkat Rao Bagalkote
2026-02-21T03:41:03Z

On 20/02/26 12:09 pm, Hari Bathini wrote:
> Do not increment tailcall count, if tailcall did not succeed due to
> missing BPF program.
>
> Fixes: ce0761419fae ("powerpc/bpf: Implement support for tail calls")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
> ---
>
> * No changes since v1.
>
>
> arch/powerpc/net/bpf_jit_comp64.c | 39 +++++++++++++++++--------------
> 1 file changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
> index b1a3945ccc9f..44ce8a8783f9 100644
> --- a/arch/powerpc/net/bpf_jit_comp64.c
> +++ b/arch/powerpc/net/bpf_jit_comp64.c
> @@ -522,9 +522,30 @@ static int bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 o
>
> /*
> * tail_call_info++; <- Actual value of tcc here
> + * Writeback this updated value only if tailcall succeeds.
> */
> EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), 1));
>
> + /* prog = array->ptrs[index]; */
> + EMIT(PPC_RAW_MULI(bpf_to_ppc(TMP_REG_2), b2p_index, 8));
> + EMIT(PPC_RAW_ADD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2), b2p_bpf_array));
> + EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
> + offsetof(struct bpf_array, ptrs)));
> +
> + /*
> + * if (prog == NULL)
> + * goto out;
> + */
> + EMIT(PPC_RAW_CMPLDI(bpf_to_ppc(TMP_REG_2), 0));
> + PPC_BCC_SHORT(COND_EQ, out);
> +
> + /* goto *(prog->bpf_func + prologue_size); */
> + EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
> + offsetof(struct bpf_prog, bpf_func)));
> + EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_2), bpf_to_ppc(TMP_REG_2),
> + FUNCTION_DESCR_SIZE + bpf_tailcall_prologue_size));
> + EMIT(PPC_RAW_MTCTR(bpf_to_ppc(TMP_REG_2)));
> +
> /*
> * Before writing updated tail_call_info, distinguish if current frame
> * is storing a reference to tail_call_info or actual tcc value in
> @@ -539,24 +560,6 @@ static int bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 o
> /* Writeback updated value to tail_call_info */
> EMIT(PPC_RAW_STD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_2), 0));
>
> - /* prog = array->ptrs[index]; */
> - EMIT(PPC_RAW_MULI(bpf_to_ppc(TMP_REG_1), b2p_index, 8));
> - EMIT(PPC_RAW_ADD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), b2p_bpf_array));
> - EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), offsetof(struct bpf_array, ptrs)));
> -
> - /*
> - * if (prog == NULL)
> - * goto out;
> - */
> - EMIT(PPC_RAW_CMPLDI(bpf_to_ppc(TMP_REG_1), 0));
> - PPC_BCC_SHORT(COND_EQ, out);
> -
> - /* goto *(prog->bpf_func + prologue_size); */
> - EMIT(PPC_RAW_LD(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1), offsetof(struct bpf_prog, bpf_func)));
> - EMIT(PPC_RAW_ADDI(bpf_to_ppc(TMP_REG_1), bpf_to_ppc(TMP_REG_1),
> - FUNCTION_DESCR_SIZE + bpf_tailcall_prologue_size));
> - EMIT(PPC_RAW_MTCTR(bpf_to_ppc(TMP_REG_1)));
> -
> /* tear down stack, restore NVRs, ... */
> bpf_jit_emit_common_epilogue(image, ctx);
>

Tested this by patch, Please add below tag.

Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>

Regards,

Venkat.