From: Pu Lehui <pulehui@huawei.com>
To: Puranjay Mohan <puranjay@kernel.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Björn Töpel" <bjorn@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
bpf@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, puranjay12@gmail.com
Subject: Re: [PATCH bpf] riscv, bpf: make some atomic operations fully ordered
Date: Mon, 6 May 2024 23:38:04 +0800 [thread overview]
Message-ID: <5df237e2-5bfd-4f31-a168-abfbf7808822@huawei.com> (raw)
In-Reply-To: <20240505201633.123115-1-puranjay@kernel.org>
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>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-05-06 15:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 20:16 [PATCH bpf] riscv, bpf: make some atomic operations fully ordered Puranjay Mohan
2024-05-06 15:38 ` Pu Lehui [this message]
2024-05-13 0:00 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5df237e2-5bfd-4f31-a168-abfbf7808822@huawei.com \
--to=pulehui@huawei.com \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=martin.lau@linux.dev \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=paulmck@kernel.org \
--cc=puranjay12@gmail.com \
--cc=puranjay@kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox