* [PATCH] async: access bottom half flags with qatomic_read
@ 2025-10-13 16:26 Paolo Bonzini
2025-10-13 19:07 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2025-10-13 16:26 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-block, qemu-stable
Running test-aio-multithread under TSAN reveals data races on bh->flags.
Because bottom halves may be scheduled or canceled asynchronously,
without taking a lock, adjust aio_compute_bh_timeout() and aio_ctx_check()
to use a relaxed read to access the flags.
Use an acquire load to ensure that anything that was written prior to
qemu_bh_schedule() is visible.
Resolves: #2749
Resolves: #851
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/async.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/util/async.c b/util/async.c
index 2719c629ae9..a736d2cd0d0 100644
--- a/util/async.c
+++ b/util/async.c
@@ -256,8 +256,9 @@ static int64_t aio_compute_bh_timeout(BHList *head, int timeout)
QEMUBH *bh;
QSLIST_FOREACH_RCU(bh, head, next) {
- if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
- if (bh->flags & BH_IDLE) {
+ int flags = qatomic_load_acquire(&bh->flags);
+ if ((flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
+ if (flags & BH_IDLE) {
/* idle bottom halves will be polled at least
* every 10ms */
timeout = 10000000;
@@ -335,14 +336,16 @@ aio_ctx_check(GSource *source)
aio_notify_accept(ctx);
QSLIST_FOREACH_RCU(bh, &ctx->bh_list, next) {
- if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
+ int flags = qatomic_load_acquire(&bh->flags);
+ if ((flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
return true;
}
}
QSIMPLEQ_FOREACH(s, &ctx->bh_slice_list, next) {
QSLIST_FOREACH_RCU(bh, &s->bh_list, next) {
- if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
+ int flags = qatomic_load_acquire(&bh->flags);
+ if ((flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) {
return true;
}
}
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] async: access bottom half flags with qatomic_read
2025-10-13 16:26 [PATCH] async: access bottom half flags with qatomic_read Paolo Bonzini
@ 2025-10-13 19:07 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-13 19:07 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: qemu-block, qemu-stable
On 13/10/25 18:26, Paolo Bonzini wrote:
> Running test-aio-multithread under TSAN reveals data races on bh->flags.
> Because bottom halves may be scheduled or canceled asynchronously,
> without taking a lock, adjust aio_compute_bh_timeout() and aio_ctx_check()
> to use a relaxed read to access the flags.
>
> Use an acquire load to ensure that anything that was written prior to
> qemu_bh_schedule() is visible.
>
> Resolves: #2749
> Resolves: #851
Preferably using the full URL:
https://gitlab.com/qemu-project/qemu/-/issues/851
https://gitlab.com/qemu-project/qemu/-/issues/2749
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> util/async.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-13 19:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-13 16:26 [PATCH] async: access bottom half flags with qatomic_read Paolo Bonzini
2025-10-13 19:07 ` Philippe Mathieu-Daudé
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).