From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: gshan@redhat.com, eesposit@redhat.com, david@redhat.com,
stefanha@redhat.com, cohuck@redhat.com, eauger@redhat.com
Subject: Re: [PATCH v2 8/9] async: update documentation of the memory barriers
Date: Wed, 8 Mar 2023 11:49:11 +0100 [thread overview]
Message-ID: <9da5c9c5-0675-157d-f099-2b0b14c26002@redhat.com> (raw)
In-Reply-To: <aa14b8ad-8756-082b-3694-3c6177f6d46d@linaro.org>
On 3/7/23 18:26, Richard Henderson wrote:
> On 3/7/23 09:00, Paolo Bonzini wrote:
>> while QSLIST_REMOVE_HEAD in the dequeuing thread is not ordered at all:
>>
>> y.store(0, mo_relaxed); // QSLIST_REMOVE_HEAD
>> x.store(0, mo_release); // fetch_and
>>
>>> As I read aio_bh_queue, this is exactly the situation you describe in
>>> patch 1 justifying the introduction of the new barriers.
>>
>> Only store-store reordering is required between QSLIST_REMOVE_HEAD and
>> atomic_fetch_and(); and that one *is* blocked by atomic_fetch_and(),
>> since mo_seq_cst is a superset of both mo_release. The new barriers
>> are needed for store-load reordering.
>
> In patch 1 you say:
>
> # in C11, sequentially consistent atomics (except for seq-cst fences)
> # only affect the ordering of sequentially consistent operations.
>
> and the store in QSLIST_REMOVE_HEAD is not a sequentially consistent
> operation.
> Therefore by your own logic we must have a separate barrier here.
You're right that the comment is contradictory.
It's the comment that is wrong. The right text should be
---
in C11, with the exception of seq-cst fences, the order established by
sequentially consistent atomics does not propagate to other memory
accesses on either side of the seq-cst atomic. As far as those are
concerned, loads performed by a seq-cst atomic are just acquire loads,
and stores are just release stores. Even though loads that occur after
a RMW operation cannot move above the load, they can still sneak above
the store!
---
The first sentence is a more accurate way to say the same thing. The
rest sentence says what happens (mo_seq_cst downgrades to mo_acq_rel as
far as those other accesses are concerned) and I missed the opportunity
to include it because it didn't matter for the cases where the series
added barriers---except now it matters for *not* adding barriers.
Now, I also said that I don't understand mo_acq_rel and that is indeed
true. Instead, in this case I'm basically treating mo_seq_cst as a
superset of both mo_release (on the dequeue side) or mo_acquire (on the
enqueue side), individually.
> I wonder if your definition/description of smp_mb__before_rmw() isn't
> actively misleading in this case.
>
> - We could drop it entirely and be less confusing, by not having to
> explain it.
> - We could define it as signal_barrier() for all hosts, simply to fix the
> compiler-theoretic reordering problem.
The case that I was imagining for smp_mb__before_rmw() is something like
this:
wake_me = true;
smp_mb__before_rmw();
if (qatomic_xchg(&can_sleep, true)) { ... }
where you really need a full barrier.
Paolo
next prev parent reply other threads:[~2023-03-08 10:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 22:32 [PATCH v2 0/9] Fix missing memory barriers on ARM Paolo Bonzini
2023-03-06 22:32 ` [PATCH v2 1/9] qatomic: add smp_mb__before/after_rmw() Paolo Bonzini
2023-03-06 22:32 ` [PATCH v2 2/9] qemu-thread-posix: cleanup, fix, document QemuEvent Paolo Bonzini
2023-03-06 22:33 ` [PATCH v2 3/9] qemu-thread-win32: " Paolo Bonzini
2023-03-06 22:33 ` [PATCH v2 4/9] edu: add smp_mb__after_rmw() Paolo Bonzini
2023-03-06 22:33 ` [PATCH v2 5/9] aio-wait: switch to smp_mb__after_rmw() Paolo Bonzini
2023-03-07 10:50 ` David Hildenbrand
2023-03-06 22:33 ` [PATCH v2 6/9] qemu-coroutine-lock: add smp_mb__after_rmw() Paolo Bonzini
2023-03-06 22:33 ` [PATCH v2 7/9] physmem: add missing memory barrier Paolo Bonzini
2023-03-06 22:33 ` [PATCH v2 8/9] async: update documentation of the memory barriers Paolo Bonzini
2023-03-06 22:48 ` Stefan Hajnoczi
2023-03-06 23:39 ` Richard Henderson
2023-03-07 10:49 ` Paolo Bonzini
2023-03-07 15:54 ` Richard Henderson
2023-03-07 17:00 ` Paolo Bonzini
2023-03-07 17:26 ` Richard Henderson
2023-03-08 10:49 ` Paolo Bonzini [this message]
2023-03-08 16:47 ` Richard Henderson
2023-03-08 18:08 ` Paolo Bonzini
2023-03-08 18:41 ` Richard Henderson
2023-03-06 22:33 ` [PATCH v2 9/9] async: clarify usage of barriers in the polling case Paolo Bonzini
2023-03-06 22:49 ` Stefan Hajnoczi
2023-03-07 10:51 ` David Hildenbrand
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=9da5c9c5-0675-157d-f099-2b0b14c26002@redhat.com \
--to=pbonzini@redhat.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=eauger@redhat.com \
--cc=eesposit@redhat.com \
--cc=gshan@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).