From: David Hildenbrand <david@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: gshan@redhat.com, eesposit@redhat.com, stefanha@redhat.com,
cohuck@redhat.com, eauger@redhat.com
Subject: Re: [PATCH 7/8] qemu-coroutine-lock: add smp_mb__after_rmw()
Date: Mon, 6 Mar 2023 14:33:33 +0100 [thread overview]
Message-ID: <476a9abf-a4f4-bc0c-02f6-06c24061b782@redhat.com> (raw)
In-Reply-To: <20230303171939.237819-8-pbonzini@redhat.com>
On 03.03.23 18:19, Paolo Bonzini wrote:
> mutex->from_push and mutex->handoff in qemu-coroutine-lock implement
> the familiar pattern:
>
> write a write b
> smp_mb() smp_mb()
> read b read a
>
> The memory barrier is required by the C memory model even after a
> SEQ_CST read-modify-write operation such as QSLIST_INSERT_HEAD_ATOMIC.
> Add it and avoid the unclear qatomic_mb_read() operation.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> util/qemu-coroutine-lock.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
> index 58f3f771817b..84a50a9e9117 100644
> --- a/util/qemu-coroutine-lock.c
> +++ b/util/qemu-coroutine-lock.c
> @@ -201,10 +201,16 @@ static void coroutine_fn qemu_co_mutex_lock_slowpath(AioContext *ctx,
> trace_qemu_co_mutex_lock_entry(mutex, self);
> push_waiter(mutex, &w);
>
> + /*
> + * Add waiter before reading mutex->handoff. Pairs with qatomic_mb_set
> + * in qemu_co_mutex_unlock.
> + */
> + smp_mb__after_rmw();
> +
> /* This is the "Responsibility Hand-Off" protocol; a lock() picks from
> * a concurrent unlock() the responsibility of waking somebody up.
> */
> - old_handoff = qatomic_mb_read(&mutex->handoff);
> + old_handoff = qatomic_read(&mutex->handoff);
> if (old_handoff &&
> has_waiters(mutex) &&
> qatomic_cmpxchg(&mutex->handoff, old_handoff, 0) == old_handoff) {
> @@ -303,6 +309,7 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex)
> }
>
> our_handoff = mutex->sequence;
> + /* Set handoff before checking for waiters. */
> qatomic_mb_set(&mutex->handoff, our_handoff);
> if (!has_waiters(mutex)) {
> /* The concurrent lock has not added itself yet, so it
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-03-06 13:37 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 17:19 [PATCH 0/8] Fix missing memory barriers on ARM Paolo Bonzini
2023-03-03 17:19 ` [PATCH 1/8] qatomic: add smp_mb__before/after_rmw() Paolo Bonzini
2023-03-05 18:57 ` Richard Henderson
2023-03-05 21:00 ` Paolo Bonzini
2023-03-06 13:21 ` David Hildenbrand
2023-03-06 13:22 ` David Hildenbrand
2023-03-03 17:19 ` [PATCH 2/8] qemu-thread-posix: cleanup, fix, document QemuEvent Paolo Bonzini
2023-03-05 19:11 ` Richard Henderson
2023-03-06 13:28 ` David Hildenbrand
2023-03-03 17:19 ` [PATCH 3/8] qemu-thread-win32: " Paolo Bonzini
2023-03-05 19:14 ` Richard Henderson
2023-03-06 13:31 ` David Hildenbrand
2023-03-06 14:20 ` Paolo Bonzini
2023-03-06 14:32 ` David Hildenbrand
2023-03-06 15:17 ` Paolo Bonzini
2023-03-03 17:19 ` [PATCH 4/8] edu: add smp_mb__after_rmw() Paolo Bonzini
2023-03-05 19:14 ` Richard Henderson
2023-03-06 13:31 ` David Hildenbrand
2023-03-06 13:38 ` Peter Maydell
2023-03-06 14:10 ` Paolo Bonzini
2023-03-06 14:24 ` Peter Maydell
2023-03-06 15:06 ` Paolo Bonzini
2023-03-06 15:36 ` Peter Maydell
2023-03-03 17:19 ` [PATCH 5/8] util/async: add smp_mb__after_rmw() around BH enqueue/dequeue Paolo Bonzini
2023-03-05 19:32 ` Richard Henderson
2023-03-06 9:55 ` Paolo Bonzini
2023-03-03 17:19 ` [PATCH 6/8] aio-wait: switch to smp_mb__after_rmw() Paolo Bonzini
2023-03-05 19:32 ` Richard Henderson
2023-03-06 13:32 ` David Hildenbrand
2023-03-06 14:38 ` Stefan Hajnoczi
2023-03-03 17:19 ` [PATCH 7/8] qemu-coroutine-lock: add smp_mb__after_rmw() Paolo Bonzini
2023-03-05 19:36 ` Richard Henderson
2023-03-06 13:33 ` David Hildenbrand [this message]
2023-03-03 17:19 ` [PATCH 8/8] physmem: add missing memory barrier Paolo Bonzini
2023-03-05 19:40 ` Richard Henderson
2023-03-06 13:34 ` David Hildenbrand
2023-03-06 13:35 ` [PATCH 0/8] Fix missing memory barriers on ARM David Hildenbrand
2023-03-06 14:14 ` Paolo Bonzini
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=476a9abf-a4f4-bc0c-02f6-06c24061b782@redhat.com \
--to=david@redhat.com \
--cc=cohuck@redhat.com \
--cc=eauger@redhat.com \
--cc=eesposit@redhat.com \
--cc=gshan@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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).