From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: gshan@redhat.com, eesposit@redhat.com, david@redhat.com,
stefanha@redhat.com, cohuck@redhat.com, eauger@redhat.com
Subject: [PATCH 5/8] util/async: add smp_mb__after_rmw() around BH enqueue/dequeue
Date: Fri, 3 Mar 2023 18:19:36 +0100 [thread overview]
Message-ID: <20230303171939.237819-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20230303171939.237819-1-pbonzini@redhat.com>
There is no implicit memory barrier in qatomic_fetch_or() and
atomic_fetch_and() on ARM systems. Add an explicit
smp_mb__after_rmw() to match the intended semantics.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/async.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/util/async.c b/util/async.c
index 0657b7539777..6129f2c991cb 100644
--- a/util/async.c
+++ b/util/async.c
@@ -74,13 +74,15 @@ static void aio_bh_enqueue(QEMUBH *bh, unsigned new_flags)
unsigned old_flags;
/*
- * The memory barrier implicit in qatomic_fetch_or makes sure that:
- * 1. idle & any writes needed by the callback are done before the
- * locations are read in the aio_bh_poll.
+ * The memory barrier makes sure that:
+ * 1. any writes needed by the callback are visible from the callback
+ * after aio_bh_dequeue() returns bh.
* 2. ctx is loaded before the callback has a chance to execute and bh
* could be freed.
*/
old_flags = qatomic_fetch_or(&bh->flags, BH_PENDING | new_flags);
+ smp_mb__after_rmw();
+
if (!(old_flags & BH_PENDING)) {
QSLIST_INSERT_HEAD_ATOMIC(&ctx->bh_list, bh, next);
}
@@ -107,14 +109,15 @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags)
QSLIST_REMOVE_HEAD(head, next);
/*
- * The qatomic_and is paired with aio_bh_enqueue(). The implicit memory
- * barrier ensures that the callback sees all writes done by the scheduling
+ * The memory barrier is paired with aio_bh_enqueue() and it
+ * ensures that the callback sees all writes done by the scheduling
* thread. It also ensures that the scheduling thread sees the cleared
* flag before bh->cb has run, and thus will call aio_notify again if
* necessary.
*/
*flags = qatomic_fetch_and(&bh->flags,
~(BH_PENDING | BH_SCHEDULED | BH_IDLE));
+ smp_mb__after_rmw();
return bh;
}
--
2.39.1
next prev parent reply other threads:[~2023-03-03 17:21 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 ` Paolo Bonzini [this message]
2023-03-05 19:32 ` [PATCH 5/8] util/async: add smp_mb__after_rmw() around BH enqueue/dequeue 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
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=20230303171939.237819-6-pbonzini@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=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).