aio_wait_kick: add missing memory barrier
PATCH 1/1 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.
--- include/block/aio-wait.h | 2 ++ util/aio-wait.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
include/block/aio-wait.h +2 -0
@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;AioContext *ctx_ = (ctx); \/* Increment wait_->num_waiters before evaluating cond. */ \qatomic_inc (&wait_->num_waiters); \ +/* Paired with smp_mb in aio_wait_kick(). */ \ +smp_mb (); \if (ctx_ &&in_aio_context_home_thread (ctx_)) { \while ((cond)) { \aio_poll (ctx_, true); \
util/aio-wait.c +15 -1
@@ -35,7 +35,21 @@ static void dummy_bh_cb(void *opaque)void aio_wait_kick (void ) { -/* The barrier (or an atomic op) is in the caller. */ +/* +* Paired with smp_mb in AIO_WAIT_WHILE. Here we have: +* write(condition); +* aio_wait_kick() { +* smp_mb(); +* read(num_waiters); +* } +* +* And in AIO_WAIT_WHILE: +* write(num_waiters); +* smp_mb(); +* read(condition); +*/ +smp_mb (); +if (qatomic_read (&global_aio_wait.num_waiters)) {aio_bh_schedule_oneshot (qemu_get_aio_context (), dummy_bh_cb,NULL ); }
Signature · 1 line
2.31.1
Quoted 10 lines · Emanuele Giuseppe Esposito
It seems that
aio_wait_kickalways 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. Readaio_wait_kick()comment for further explanation.Suggested-by Paolo Bonzini<[email protected]>Signed-off-by Emanuele Giuseppe Esposito<[email protected]>
Thanks!
Signature · 2 lines
Best regards, Vladimir
Quoted 8 lines · Emanuele Giuseppe Esposito
It seems that
aio_wait_kickalways 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. Readaio_wait_kick()comment for further explanation.
Quoted 6 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- include/block/aio-wait.h | 2 ++ util/aio-wait.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
Kevin Wolf
AppliedAm 24.05.2022 um 19:30 hat Emanuele Giuseppe Esposito geschrieben:
Quoted 10 lines
It seems that
aio_wait_kickalways 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. Readaio_wait_kick()comment for further explanation.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Emanuele Giuseppe Esposito <[email protected]>
Thanks, applied to the block branch.
Kevin
Quoted 20 lines · Emanuele Giuseppe Esposito
It seems that
aio_wait_kickalways 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. Readaio_wait_kick()comment for further explanation.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- include/block/aio-wait.h | 2 ++ util/aio-wait.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)include/block/aio-wait.h +0
-0
include/block/aio-wait.h extern AioWait global_aio_wait; · line 85
Quoted 5 lines
include/block/aio-wait.h +2
-0@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;AioContext *ctx_ = (ctx); \/* Increment wait_->num_waiters before evaluating cond. */ \qatomic_inc (&wait_->num_waiters); \ +/* Paired with smp_mb in aio_wait_kick(). */ \ +smp_mb (); \
IIRC qatomic_inc() ensures sequential consistency, isn't it enough here?
include/block/aio-wait.h extern AioWait global_aio_wait; · line 88
Quoted 3 lines
include/block/aio-wait.h +0
-0if (ctx_ &&in_aio_context_home_thread (ctx_)) { \while ((cond)) { \aio_poll (ctx_, true); \
Roman.
Quoted 16 lines · Roman Kagan
Quoted 15 lines · Emanuele Giuseppe Esposito
It seems that
aio_wait_kickalways 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. Readaio_wait_kick()comment for further explanation.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- include/block/aio-wait.h | 2 ++ util/aio-wait.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
Quoted 12 lines
include/block/aio-wait.h extern AioWait global_aio_wait; · line 85
Quoted 10 lines
include/block/aio-wait.h +2
-0@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;AioContext *ctx_ = (ctx); \/* Increment wait_->num_waiters before evaluating cond. */ \qatomic_inc (&wait_->num_waiters); \ +/* Paired with smp_mb in aio_wait_kick(). */ \ +smp_mb (); \IIRC
qatomic_inc()ensures sequential consistency, isn't it enough here?
Nope, it only ensures sequential consistency with other SEQ_CST operations, i.e. not with qatomic_read or qatomic_set. :(
The smp_mb() is needed on ARM, in particular.
Paolo