* [PATCH bpf] riscv, bpf: make some atomic operations fully ordered
@ 2024-05-05 20:16 Puranjay Mohan
2024-05-06 15:38 ` Pu Lehui
2024-05-13 0:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Puranjay Mohan @ 2024-05-05 20:16 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Björn Töpel, Pu Lehui, Paul E. McKenney, Paul Walmsley,
Palmer Dabbelt, Albert Ou, bpf, linux-riscv, linux-kernel
Cc: puranjay12
The BPF atomic operations with the BPF_FETCH modifier along with
BPF_XCHG and BPF_CMPXCHG are fully ordered but the RISC-V JIT implements
all atomic operations except BPF_CMPXCHG with relaxed ordering.
Section 8.1 of the "The RISC-V Instruction Set Manual Volume I:
Unprivileged ISA" [1], titled, "Specifying Ordering of Atomic
Instructions" says:
| To provide more efficient support for release consistency [5], each
| atomic instruction has two bits, aq and rl, used to specify additional
| memory ordering constraints as viewed by other RISC-V harts.
and
| If only the aq bit is set, the atomic memory operation is treated as
| an acquire access.
| If only the rl bit is set, the atomic memory operation is treated as a
| release access.
|
| If both the aq and rl bits are set, the atomic memory operation is
| sequentially consistent.
Fix this by setting both aq and rl bits as 1 for operations with
BPF_FETCH and BPF_XCHG.
[1] https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf
Fixes: dd642ccb45ec ("riscv, bpf: Implement more atomic operations for RV64")
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
---
arch/riscv/net/bpf_jit_comp64.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ec9d692838fc..fb5d1950042b 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -498,33 +498,33 @@ static void emit_atomic(u8 rd, u8 rs, s16 off, s32 imm, bool is64,
break;
/* src_reg = atomic_fetch_<op>(dst_reg + off16, src_reg) */
case BPF_ADD | BPF_FETCH:
- emit(is64 ? rv_amoadd_d(rs, rs, rd, 0, 0) :
- rv_amoadd_w(rs, rs, rd, 0, 0), ctx);
+ emit(is64 ? rv_amoadd_d(rs, rs, rd, 1, 1) :
+ rv_amoadd_w(rs, rs, rd, 1, 1), ctx);
if (!is64)
emit_zextw(rs, rs, ctx);
break;
case BPF_AND | BPF_FETCH:
- emit(is64 ? rv_amoand_d(rs, rs, rd, 0, 0) :
- rv_amoand_w(rs, rs, rd, 0, 0), ctx);
+ emit(is64 ? rv_amoand_d(rs, rs, rd, 1, 1) :
+ rv_amoand_w(rs, rs, rd, 1, 1), ctx);
if (!is64)
emit_zextw(rs, rs, ctx);
break;
case BPF_OR | BPF_FETCH:
- emit(is64 ? rv_amoor_d(rs, rs, rd, 0, 0) :
- rv_amoor_w(rs, rs, rd, 0, 0), ctx);
+ emit(is64 ? rv_amoor_d(rs, rs, rd, 1, 1) :
+ rv_amoor_w(rs, rs, rd, 1, 1), ctx);
if (!is64)
emit_zextw(rs, rs, ctx);
break;
case BPF_XOR | BPF_FETCH:
- emit(is64 ? rv_amoxor_d(rs, rs, rd, 0, 0) :
- rv_amoxor_w(rs, rs, rd, 0, 0), ctx);
+ emit(is64 ? rv_amoxor_d(rs, rs, rd, 1, 1) :
+ rv_amoxor_w(rs, rs, rd, 1, 1), ctx);
if (!is64)
emit_zextw(rs, rs, ctx);
break;
/* src_reg = atomic_xchg(dst_reg + off16, src_reg); */
case BPF_XCHG:
- emit(is64 ? rv_amoswap_d(rs, rs, rd, 0, 0) :
- rv_amoswap_w(rs, rs, rd, 0, 0), ctx);
+ emit(is64 ? rv_amoswap_d(rs, rs, rd, 1, 1) :
+ rv_amoswap_w(rs, rs, rd, 1, 1), ctx);
if (!is64)
emit_zextw(rs, rs, ctx);
break;
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH bpf] riscv, bpf: make some atomic operations fully ordered
2024-05-05 20:16 [PATCH bpf] riscv, bpf: make some atomic operations fully ordered Puranjay Mohan
@ 2024-05-06 15:38 ` Pu Lehui
2024-05-13 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Pu Lehui @ 2024-05-06 15:38 UTC (permalink / raw)
To: Puranjay Mohan
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Björn Töpel, Paul E. McKenney, Paul Walmsley,
Palmer Dabbelt, Albert Ou, bpf, linux-riscv, linux-kernel,
puranjay12
On 2024/5/6 4:16, Puranjay Mohan wrote:
> The BPF atomic operations with the BPF_FETCH modifier along with
> BPF_XCHG and BPF_CMPXCHG are fully ordered but the RISC-V JIT implements
> all atomic operations except BPF_CMPXCHG with relaxed ordering.
>
> Section 8.1 of the "The RISC-V Instruction Set Manual Volume I:
> Unprivileged ISA" [1], titled, "Specifying Ordering of Atomic
> Instructions" says:
>
> | To provide more efficient support for release consistency [5], each
> | atomic instruction has two bits, aq and rl, used to specify additional
> | memory ordering constraints as viewed by other RISC-V harts.
>
> and
>
> | If only the aq bit is set, the atomic memory operation is treated as
> | an acquire access.
> | If only the rl bit is set, the atomic memory operation is treated as a
> | release access.
> |
> | If both the aq and rl bits are set, the atomic memory operation is
> | sequentially consistent.
>
> Fix this by setting both aq and rl bits as 1 for operations with
> BPF_FETCH and BPF_XCHG.
>
> [1] https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf
>
> Fixes: dd642ccb45ec ("riscv, bpf: Implement more atomic operations for RV64")
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> ---
> arch/riscv/net/bpf_jit_comp64.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index ec9d692838fc..fb5d1950042b 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -498,33 +498,33 @@ static void emit_atomic(u8 rd, u8 rs, s16 off, s32 imm, bool is64,
> break;
> /* src_reg = atomic_fetch_<op>(dst_reg + off16, src_reg) */
> case BPF_ADD | BPF_FETCH:
> - emit(is64 ? rv_amoadd_d(rs, rs, rd, 0, 0) :
> - rv_amoadd_w(rs, rs, rd, 0, 0), ctx);
> + emit(is64 ? rv_amoadd_d(rs, rs, rd, 1, 1) :
> + rv_amoadd_w(rs, rs, rd, 1, 1), ctx);
> if (!is64)
> emit_zextw(rs, rs, ctx);
> break;
> case BPF_AND | BPF_FETCH:
> - emit(is64 ? rv_amoand_d(rs, rs, rd, 0, 0) :
> - rv_amoand_w(rs, rs, rd, 0, 0), ctx);
> + emit(is64 ? rv_amoand_d(rs, rs, rd, 1, 1) :
> + rv_amoand_w(rs, rs, rd, 1, 1), ctx);
> if (!is64)
> emit_zextw(rs, rs, ctx);
> break;
> case BPF_OR | BPF_FETCH:
> - emit(is64 ? rv_amoor_d(rs, rs, rd, 0, 0) :
> - rv_amoor_w(rs, rs, rd, 0, 0), ctx);
> + emit(is64 ? rv_amoor_d(rs, rs, rd, 1, 1) :
> + rv_amoor_w(rs, rs, rd, 1, 1), ctx);
> if (!is64)
> emit_zextw(rs, rs, ctx);
> break;
> case BPF_XOR | BPF_FETCH:
> - emit(is64 ? rv_amoxor_d(rs, rs, rd, 0, 0) :
> - rv_amoxor_w(rs, rs, rd, 0, 0), ctx);
> + emit(is64 ? rv_amoxor_d(rs, rs, rd, 1, 1) :
> + rv_amoxor_w(rs, rs, rd, 1, 1), ctx);
> if (!is64)
> emit_zextw(rs, rs, ctx);
> break;
> /* src_reg = atomic_xchg(dst_reg + off16, src_reg); */
> case BPF_XCHG:
> - emit(is64 ? rv_amoswap_d(rs, rs, rd, 0, 0) :
> - rv_amoswap_w(rs, rs, rd, 0, 0), ctx);
> + emit(is64 ? rv_amoswap_d(rs, rs, rd, 1, 1) :
> + rv_amoswap_w(rs, rs, rd, 1, 1), ctx);
> if (!is64)
> emit_zextw(rs, rs, ctx);
> break;
Reviewed-by: Pu Lehui <pulehui@huawei.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf] riscv, bpf: make some atomic operations fully ordered
2024-05-05 20:16 [PATCH bpf] riscv, bpf: make some atomic operations fully ordered Puranjay Mohan
2024-05-06 15:38 ` Pu Lehui
@ 2024-05-13 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-13 0:00 UTC (permalink / raw)
To: Puranjay Mohan
Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, bjorn, pulehui,
paulmck, paul.walmsley, palmer, aou, bpf, linux-riscv,
linux-kernel, puranjay12
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Sun, 5 May 2024 20:16:33 +0000 you wrote:
> The BPF atomic operations with the BPF_FETCH modifier along with
> BPF_XCHG and BPF_CMPXCHG are fully ordered but the RISC-V JIT implements
> all atomic operations except BPF_CMPXCHG with relaxed ordering.
>
> Section 8.1 of the "The RISC-V Instruction Set Manual Volume I:
> Unprivileged ISA" [1], titled, "Specifying Ordering of Atomic
> Instructions" says:
>
> [...]
Here is the summary with links:
- [bpf] riscv, bpf: make some atomic operations fully ordered
https://git.kernel.org/bpf/bpf-next/c/20a759df3bba
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-13 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-05 20:16 [PATCH bpf] riscv, bpf: make some atomic operations fully ordered Puranjay Mohan
2024-05-06 15:38 ` Pu Lehui
2024-05-13 0:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox