[SRU][N/J:linux][PATCH 3/4] powerpc/bpf/64: add support for atomic fetch operations

Andrei Gherzan andrei.gherzan at canonical.com
Tue Jun 30 17:04:40 UTC 2026


On Tue, 30 Jun 2026 at 17:58, Andrei Gherzan <andrei.gherzan at canonical.com>
wrote:

> BugLink: https://bugs.launchpad.net/bugs/1955011


Wrong subject series tag and missed the cover letter - scripts have failed.
I will send a v2.


>
>
> Adding instructions for ppc64 for
>
> atomic[64]_fetch_add
> atomic[64]_fetch_and
> atomic[64]_fetch_or
> atomic[64]_fetch_xor
>
> Signed-off-by: Hari Bathini <hbathini at linux.ibm.com>
> Tested-by: Naveen N. Rao <naveen.n.rao at linux.vnet.ibm.com> (ppc64le)
> Reviewed-by: Naveen N. Rao <naveen.n.rao at linux.vnet.ibm.com>
> Signed-off-by: Michael Ellerman <mpe at ellerman.id.au>
> Link:
> https://lore.kernel.org/r/20220610155552.25892-3-hbathini@linux.ibm.com
> (backported from commit dbe6e2456fb0263a5a961a92836d2cebdbca979c)
> [agherzan: Context adjustment - used b2p[TMP_REG_x] notation consistent
>  with existing Ubuntu Jammy code instead of upstream's tmp1_reg/tmp2_reg
>  local variables.]
> Signed-off-by: Andrei Gherzan <andrei.gherzan at canonical.com>
> ---
>  arch/powerpc/net/bpf_jit_comp64.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp64.c
> b/arch/powerpc/net/bpf_jit_comp64.c
> index b3729f511ac0..5c55bf41b03e 100644
> --- a/arch/powerpc/net/bpf_jit_comp64.c
> +++ b/arch/powerpc/net/bpf_jit_comp64.c
> @@ -752,17 +752,25 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32
> *image, struct codegen_context *
>                         else
>                                 EMIT(PPC_RAW_LWARX(b2p[TMP_REG_2],
> b2p[TMP_REG_1], dst_reg, 0));
>
> +                       /* Save old value in _R0 */
> +                       if (imm & BPF_FETCH)
> +                               EMIT(PPC_RAW_MR(_R0, b2p[TMP_REG_2]));
> +
>                         switch (imm) {
>                         case BPF_ADD:
> +                       case BPF_ADD | BPF_FETCH:
>                                 EMIT(PPC_RAW_ADD(b2p[TMP_REG_2],
> b2p[TMP_REG_2], src_reg));
>                                 break;
>                         case BPF_AND:
> +                       case BPF_AND | BPF_FETCH:
>                                 EMIT(PPC_RAW_AND(b2p[TMP_REG_2],
> b2p[TMP_REG_2], src_reg));
>                                 break;
>                         case BPF_OR:
> +                       case BPF_OR | BPF_FETCH:
>                                 EMIT(PPC_RAW_OR(b2p[TMP_REG_2],
> b2p[TMP_REG_2], src_reg));
>                                 break;
>                         case BPF_XOR:
> +                       case BPF_XOR | BPF_FETCH:
>                                 EMIT(PPC_RAW_XOR(b2p[TMP_REG_2],
> b2p[TMP_REG_2], src_reg));
>                                 break;
>                         default:
> @@ -772,13 +780,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32
> *image, struct codegen_context *
>                                 return -EOPNOTSUPP;
>                         }
>
> -                       /* store result back */
> +                       /* store new value */
>                         if (BPF_SIZE(code) == BPF_DW)
>                                 EMIT(PPC_RAW_STDCX(b2p[TMP_REG_2],
> b2p[TMP_REG_1], dst_reg));
>                         else
>                                 EMIT(PPC_RAW_STWCX(b2p[TMP_REG_2],
> b2p[TMP_REG_1], dst_reg));
>                         /* we're done if this succeeded */
>                         PPC_BCC_SHORT(COND_NE, tmp_idx);
> +
> +                       /* For the BPF_FETCH variant, get old value into
> src_reg */
> +                       if (imm & BPF_FETCH)
> +                               EMIT(PPC_RAW_MR(src_reg, _R0));
>                         break;
>
>                 /*
> --
> 2.43.0
>
>

-- 
Andrei Gherzan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20260630/2806b73c/attachment-0001.html>


More information about the kernel-team mailing list