Commit dbe6e245 authored by Hari Bathini's avatar Hari Bathini Committed by Michael Ellerman

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: default avatarHari Bathini <hbathini@linux.ibm.com>
Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> (ppc64le)
Reviewed-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610155552.25892-3-hbathini@linux.ibm.com
parent 65112709
...@@ -787,17 +787,25 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * ...@@ -787,17 +787,25 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
else else
EMIT(PPC_RAW_LWARX(tmp2_reg, tmp1_reg, dst_reg, 0)); EMIT(PPC_RAW_LWARX(tmp2_reg, tmp1_reg, dst_reg, 0));
/* Save old value in _R0 */
if (imm & BPF_FETCH)
EMIT(PPC_RAW_MR(_R0, tmp2_reg));
switch (imm) { switch (imm) {
case BPF_ADD: case BPF_ADD:
case BPF_ADD | BPF_FETCH:
EMIT(PPC_RAW_ADD(tmp2_reg, tmp2_reg, src_reg)); EMIT(PPC_RAW_ADD(tmp2_reg, tmp2_reg, src_reg));
break; break;
case BPF_AND: case BPF_AND:
case BPF_AND | BPF_FETCH:
EMIT(PPC_RAW_AND(tmp2_reg, tmp2_reg, src_reg)); EMIT(PPC_RAW_AND(tmp2_reg, tmp2_reg, src_reg));
break; break;
case BPF_OR: case BPF_OR:
case BPF_OR | BPF_FETCH:
EMIT(PPC_RAW_OR(tmp2_reg, tmp2_reg, src_reg)); EMIT(PPC_RAW_OR(tmp2_reg, tmp2_reg, src_reg));
break; break;
case BPF_XOR: case BPF_XOR:
case BPF_XOR | BPF_FETCH:
EMIT(PPC_RAW_XOR(tmp2_reg, tmp2_reg, src_reg)); EMIT(PPC_RAW_XOR(tmp2_reg, tmp2_reg, src_reg));
break; break;
default: default:
...@@ -807,13 +815,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * ...@@ -807,13 +815,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
/* store result back */ /* store new value */
if (size == BPF_DW) if (size == BPF_DW)
EMIT(PPC_RAW_STDCX(tmp2_reg, tmp1_reg, dst_reg)); EMIT(PPC_RAW_STDCX(tmp2_reg, tmp1_reg, dst_reg));
else else
EMIT(PPC_RAW_STWCX(tmp2_reg, tmp1_reg, dst_reg)); EMIT(PPC_RAW_STWCX(tmp2_reg, tmp1_reg, dst_reg));
/* we're done if this succeeded */ /* we're done if this succeeded */
PPC_BCC_SHORT(COND_NE, tmp_idx); 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; break;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment