Skip to content

Commit dbe6e24

Browse files
hbathinimpe
authored andcommitted
powerpc/bpf/64: add support for atomic fetch operations
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 <[email protected]> Tested-by: Naveen N. Rao <[email protected]> (ppc64le) Reviewed-by: Naveen N. Rao <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6511270 commit dbe6e24

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arch/powerpc/net/bpf_jit_comp64.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -787,17 +787,25 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
787787
else
788788
EMIT(PPC_RAW_LWARX(tmp2_reg, tmp1_reg, dst_reg, 0));
789789

790+
/* Save old value in _R0 */
791+
if (imm & BPF_FETCH)
792+
EMIT(PPC_RAW_MR(_R0, tmp2_reg));
793+
790794
switch (imm) {
791795
case BPF_ADD:
796+
case BPF_ADD | BPF_FETCH:
792797
EMIT(PPC_RAW_ADD(tmp2_reg, tmp2_reg, src_reg));
793798
break;
794799
case BPF_AND:
800+
case BPF_AND | BPF_FETCH:
795801
EMIT(PPC_RAW_AND(tmp2_reg, tmp2_reg, src_reg));
796802
break;
797803
case BPF_OR:
804+
case BPF_OR | BPF_FETCH:
798805
EMIT(PPC_RAW_OR(tmp2_reg, tmp2_reg, src_reg));
799806
break;
800807
case BPF_XOR:
808+
case BPF_XOR | BPF_FETCH:
801809
EMIT(PPC_RAW_XOR(tmp2_reg, tmp2_reg, src_reg));
802810
break;
803811
default:
@@ -807,13 +815,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
807815
return -EOPNOTSUPP;
808816
}
809817

810-
/* store result back */
818+
/* store new value */
811819
if (size == BPF_DW)
812820
EMIT(PPC_RAW_STDCX(tmp2_reg, tmp1_reg, dst_reg));
813821
else
814822
EMIT(PPC_RAW_STWCX(tmp2_reg, tmp1_reg, dst_reg));
815823
/* we're done if this succeeded */
816824
PPC_BCC_SHORT(COND_NE, tmp_idx);
825+
826+
/* For the BPF_FETCH variant, get old value into src_reg */
827+
if (imm & BPF_FETCH)
828+
EMIT(PPC_RAW_MR(src_reg, _R0));
817829
break;
818830

819831
/*

0 commit comments

Comments
 (0)