From: Yonghong Song <yonghong.song@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Peilin Ye <yepeilin@google.com>,
"Jose E. Marchesi" <jemarch@gnu.org>, bpf <bpf@vger.kernel.org>,
Josh Don <joshdon@google.com>, Barret Rhoden <brho@google.com>,
Neel Natu <neelnatu@google.com>,
Benjamin Segall <bsegall@google.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
David Vernet <dvernet@meta.com>,
Dave Marchevsky <davemarchevsky@meta.com>
Subject: Re: Supporting New Memory Barrier Types in BPF
Date: Tue, 30 Jul 2024 20:51:15 -0700 [thread overview]
Message-ID: <87c8159d-602b-470c-a46c-87f5fd853a23@linux.dev> (raw)
In-Reply-To: <CAADnVQLLjPe3cnb7RSqHHVAP=4W1mbwTz1OFKq51=TR0utyaJQ@mail.gmail.com>
On 7/30/24 6:19 PM, Alexei Starovoitov wrote:
> On Mon, Jul 29, 2024 at 10:14 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>>> This sounds like a compiler bug.
>>>
>>> Yonghong, Jose,
>>> do you know what compilers do for other backends?
>>> Is it allowed to convert sycn_fetch_add into sync_add when fetch part is unused?
>> This behavior is introduced by the following llvm commit:
>> https://github.com/llvm/llvm-project/commit/286daafd65129228e08a1d07aa4ca74488615744
>>
>> Specifically the following commit message:
>>
>> =======
>> Similar to xadd, atomic xadd, xor and xxor (atomic_<op>)
>> instructions are added for atomic operations which do not
>> have return values. LLVM will check the return value for
>> __sync_fetch_and_{add,and,or,xor}.
>> If the return value is used, instructions atomic_fetch_<op>
>> will be used. Otherwise, atomic_<op> instructions will be used.
> So it's a bpf backend bug. Great. That's fixable.
> Would have been much harder if this transformation was performed
> by the middle end.
>
>> ======
>>
>> Basically, if no return value, __sync_fetch_and_add() will use
>> xadd insn. The decision is made at that time to maintain backward compatibility.
>> For one example, in bcc
>> https://github.com/iovisor/bcc/blob/master/src/cc/export/helpers.h#L1444
>> we have
>> #define lock_xadd(ptr, val) ((void)__sync_fetch_and_add(ptr, val))
>>
>> Should we use atomic_fetch_*() always regardless of whether the return
>> val is used or not? Probably, it should still work. Not sure what gcc
>> does for this case.
> Right. We did it for backward compat. Older llvm was
> completely wrong to generate xadd for __sync_fetch_and_add.
> That was my hack from 10 years ago when xadd was all we had.
> So we fixed that old llvm bug, but introduced another with all
> good intentions.
> Since proper atomic insns were introduced 3 years ago we should
> remove this backward compat feature/bug from llvm.
> The only breakage is for kernels older than 5.12.
> I think that's an acceptable risk.
Sounds good, I will remove the backward compat part in llvm20.
next prev parent reply other threads:[~2024-07-31 3:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 18:32 Supporting New Memory Barrier Types in BPF Peilin Ye
2024-07-30 1:28 ` Alexei Starovoitov
2024-07-30 3:49 ` Paul E. McKenney
2024-07-30 4:03 ` Alexei Starovoitov
2024-07-30 5:14 ` Yonghong Song
2024-07-31 1:19 ` Alexei Starovoitov
2024-07-31 3:51 ` Yonghong Song [this message]
2024-07-31 20:44 ` Peilin Ye
2024-07-31 23:17 ` Yonghong Song
2024-08-01 0:11 ` Peilin Ye
2024-08-01 12:47 ` Jose E. Marchesi
2024-08-01 14:20 ` Jose E. Marchesi
2024-08-01 16:44 ` Yonghong Song
2024-08-05 16:13 ` Jose E. Marchesi
2024-08-01 22:00 ` Peilin Ye
2024-08-06 19:22 ` Peilin Ye
2024-08-08 16:33 ` Alexei Starovoitov
2024-08-08 20:59 ` Peilin Ye
2024-09-16 21:14 ` Peilin Ye
2024-09-17 0:08 ` Peilin Ye
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=87c8159d-602b-470c-a46c-87f5fd853a23@linux.dev \
--to=yonghong.song@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brho@google.com \
--cc=bsegall@google.com \
--cc=davemarchevsky@meta.com \
--cc=dvernet@meta.com \
--cc=jemarch@gnu.org \
--cc=joshdon@google.com \
--cc=neelnatu@google.com \
--cc=paulmck@kernel.org \
--cc=yepeilin@google.com \
/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