From: "Björn Töpel" <bjorn@kernel.org>
To: Puranjay Mohan <puranjay@kernel.org>,
Andrea Parri <parri.andrea@gmail.com>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, pulehui@huawei.com, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu, paulmck@kernel.org,
puranjay12@gmail.com
Cc: bpf@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org,
Andrea Parri <parri.andrea@gmail.com>
Subject: Re: [PATCH] riscv, bpf: Make BPF_CMPXCHG fully ordered
Date: Thu, 17 Oct 2024 17:11:03 +0200 [thread overview]
Message-ID: <87iktq7ojc.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <mb61piktqpz25.fsf@kernel.org>
Thanks, Andrea!
Puranjay Mohan <puranjay@kernel.org> writes:
> Andrea Parri <parri.andrea@gmail.com> writes:
>
>> According to the prototype formal BPF memory consistency model
>> discussed e.g. in [1] and following the ordering properties of
>> the C/in-kernel macro atomic_cmpxchg(), a BPF atomic operation
>> with the BPF_CMPXCHG modifier is fully ordered. However, the
>> current RISC-V JIT lowerings fail to meet such memory ordering
>> property. This is illustrated by the following litmus test:
>>
>> BPF BPF__MP+success_cmpxchg+fence
>> {
>> 0:r1=x; 0:r3=y; 0:r5=1;
>> 1:r2=y; 1:r4=f; 1:r7=x;
>> }
>> P0 | P1 ;
>> *(u64 *)(r1 + 0) = 1 | r1 = *(u64 *)(r2 + 0) ;
>> r2 = cmpxchg_64 (r3 + 0, r4, r5) | r3 = atomic_fetch_add((u64 *)(r4 + 0), r5) ;
>> | r6 = *(u64 *)(r7 + 0) ;
>> exists (1:r1=1 /\ 1:r6=0)
>>
>> whose "exists" clause is not satisfiable according to the BPF
>> memory model. Using the current RISC-V JIT lowerings, the test
>> can be mapped to the following RISC-V litmus test:
>>
>> RISCV RISCV__MP+success_cmpxchg+fence
>> {
>> 0:x1=x; 0:x3=y; 0:x5=1;
>> 1:x2=y; 1:x4=f; 1:x7=x;
>> }
>> P0 | P1 ;
>> sd x5, 0(x1) | ld x1, 0(x2) ;
>> L00: | amoadd.d.aqrl x3, x5, 0(x4) ;
>> lr.d x2, 0(x3) | ld x6, 0(x7) ;
>> bne x2, x4, L01 | ;
>> sc.d x6, x5, 0(x3) | ;
>> bne x6, x4, L00 | ;
>> fence rw, rw | ;
>> L01: | ;
>> exists (1:x1=1 /\ 1:x6=0)
>>
>> where the two stores in P0 can be reordered. Update the RISC-V
>> JIT lowerings/implementation of BPF_CMPXCHG to emit an SC with
>> RELEASE ("rl") annotation in order to meet the expected memory
>> ordering guarantees. The resulting RISC-V JIT lowerings of
>> BPF_CMPXCHG match the RISC-V lowerings of the C atomic_cmpxchg().
>
> Thanks for fixing this, I fixed all others in:
>
> 20a759df3bba ("riscv, bpf: make some atomic operations fully ordered")
>
>> Fixes: dd642ccb45ec ("riscv, bpf: Implement more atomic operations for RV64")
>> Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
>
> Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Björn Töpel <bjorn@kernel.org>
next prev parent reply other threads:[~2024-10-17 15:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 14:36 [PATCH] riscv, bpf: Make BPF_CMPXCHG fully ordered Andrea Parri
2024-10-17 14:46 ` Puranjay Mohan
2024-10-17 15:11 ` Björn Töpel [this message]
2024-10-17 15:10 ` 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=87iktq7ojc.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@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=parri.andrea@gmail.com \
--cc=paul.walmsley@sifive.com \
--cc=paulmck@kernel.org \
--cc=pulehui@huawei.com \
--cc=puranjay12@gmail.com \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--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