riscv, bpf: Implement more atomic operations for RV64
Subsystems (4)
Pu Lehui
maintainerPATCH 1/1 riscv, bpf: Implement more atomic operations for RV64
This patch implement more bpf atomic operations for RV64. The added operations are shown below:
atomic[64]_[fetch_]add
atomic[64]_[fetch_]and
atomic[64]_[fetch_]or
atomic[64]_xchg
atomic[64]_cmpxchg
Since riscv specification does not provide AMO instruction for CAS operation, we use lr/sc instruction for cmpxchg operation, and AMO instructions for the rest ops. Tests "test_bpf.ko" and "test_progs -t atomic" have passed, as well as "test_verifier" with no new failure ceses.
--- arch/riscv/net/bpf_jit.h | 67 +++++++++++++++++++ arch/riscv/net/bpf_jit_comp64.c | 110 +++++++++++++++++++++++++------- 2 files changed, 153 insertions(+), 24 deletions(-)
arch/riscv/net/bpf_jit.h +67 -0
@@ -535,6 +535,43 @@ static inline u32 rv_amoadd_w(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl)return rv_amo_insn (0 , aq, rl, rs2, rs1,2 , rd,0x2f ); } +static inline u32 rv_amoand_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0xc , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_amoor_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x8 , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_amoxor_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x4 , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_amoswap_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x1 , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_lr_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x2 , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_sc_w (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x3 , aq, rl, rs2, rs1,2 , rd,0x2f ); +} + +static inline u32 rv_fence (u8 pred,u8 succ) +{ +u16 imm11_0 = pred <<4 | succ; + +return rv_i_insn (imm11_0,0 ,0 ,0 ,0xf ); +} +/* RVC instrutions. */ static inline u16 rvc_addi4spn (u8 rd,u32 imm10)
@@ -753,6 +790,36 @@ static inline u32 rv_amoadd_d(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl)return rv_amo_insn (0 , aq, rl, rs2, rs1,3 , rd,0x2f ); } +static inline u32 rv_amoand_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0xc , aq, rl, rs2, rs1,3 , rd,0x2f ); +} + +static inline u32 rv_amoor_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x8 , aq, rl, rs2, rs1,3 , rd,0x2f ); +} + +static inline u32 rv_amoxor_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x4 , aq, rl, rs2, rs1,3 , rd,0x2f ); +} + +static inline u32 rv_amoswap_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x1 , aq, rl, rs2, rs1,3 , rd,0x2f ); +} + +static inline u32 rv_lr_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x2 , aq, rl, rs2, rs1,3 , rd,0x2f ); +} + +static inline u32 rv_sc_d (u8 rd,u8 rs2,u8 rs1,u8 aq,u8 rl) +{ +return rv_amo_insn (0x3 , aq, rl, rs2, rs1,3 , rd,0x2f ); +} +/* RV64-only RVC instructions. */ static inline u16 rvc_ld (u8 rd,u32 imm8,u8 rs1)
arch/riscv/net/bpf_jit_comp64.c +86 -24
122 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 13 lines · Pu Lehui
This patch implement more bpf atomic operations for RV64. The added operations are shown below:
atomic[64]_[fetch_]add
atomic[64]_[fetch_]and
atomic[64]_[fetch_]or
atomic[64]_xchg
atomic[64]_cmpxchg
Quoted 7 lines
Since riscv specification does not provide AMO instruction for CAS operation, we use lr/sc instruction for cmpxchg operation, and AMO instructions for the rest ops. Tests "test_bpf.ko" and "
test_progs-t atomic" have passed, as well as "test_verifier" with no new failure ceses.Signed-off-by Pu Lehui <[email protected]>
LGTM.
Quoted 10 lines · Pu Lehui
This patch implement more bpf atomic operations for RV64. The added operations are shown below:
atomic[64]_[fetch_]add
atomic[64]_[fetch_]and
atomic[64]_[fetch_]or
atomic[64]_xchg
atomic[64]_cmpxchg
Quoted 7 lines
Since riscv specification does not provide AMO instruction for CAS operation, we use lr/sc instruction for cmpxchg operation, and AMO instructions for the rest ops. Tests "test_bpf.ko" and "
test_progs-t atomic" have passed, as well as "test_verifier" with no new failure ceses.Signed-off-by Pu Lehui <[email protected]>
Thank you for implementing this! It's been long overdue.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 10 lines · On Sun, 10 Apr 2022 18:12:46 +0800 you wrote:
This patch implement more bpf atomic operations for RV64. The added operations are shown below:
atomic[64]_[fetch_]add
atomic[64]_[fetch_]and
atomic[64]_[fetch_]or
atomic[64]_xchg
atomic[64]_cmpxchg[...]
Here is the summary with links:
- [bpf-next] riscv, bpf: Implement more atomic operations for RV64
https://git.kernel.org/bpf/bpf-next/c/dd642ccb45ec
You are awesome, thank you!
Signature · 9 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv