Skip to content

Commit 7455ff1

Browse files
esposemkevmw
authored andcommitted
aio_wait_kick: add missing memory barrier
It seems that aio_wait_kick always required a memory barrier or atomic operation in the caller, but nobody actually took care of doing it. Let's put the barrier in the function instead, and pair it with another one in AIO_WAIT_WHILE. Read aio_wait_kick() comment for further explanation. Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Emanuele Giuseppe Esposito <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 9b38fc5 commit 7455ff1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/block/aio-wait.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;
8181
AioContext *ctx_ = (ctx); \
8282
/* Increment wait_->num_waiters before evaluating cond. */ \
8383
qatomic_inc(&wait_->num_waiters); \
84+
/* Paired with smp_mb in aio_wait_kick(). */ \
85+
smp_mb(); \
8486
if (ctx_ && in_aio_context_home_thread(ctx_)) { \
8587
while ((cond)) { \
8688
aio_poll(ctx_, true); \

util/aio-wait.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ static void dummy_bh_cb(void *opaque)
3535

3636
void aio_wait_kick(void)
3737
{
38-
/* The barrier (or an atomic op) is in the caller. */
38+
/*
39+
* Paired with smp_mb in AIO_WAIT_WHILE. Here we have:
40+
* write(condition);
41+
* aio_wait_kick() {
42+
* smp_mb();
43+
* read(num_waiters);
44+
* }
45+
*
46+
* And in AIO_WAIT_WHILE:
47+
* write(num_waiters);
48+
* smp_mb();
49+
* read(condition);
50+
*/
51+
smp_mb();
52+
3953
if (qatomic_read(&global_aio_wait.num_waiters)) {
4054
aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
4155
}

0 commit comments

Comments
 (0)