Skip to content

Commit

Permalink
io_uring: fix race condition when sq threads goes sleeping
Browse files Browse the repository at this point in the history
Reading the SQ tail needs to come after setting IORING_SQ_NEED_WAKEUP in
flags; there is no cheap barrier for ordering a store before a load, a
full memory barrier is required.

Userspace needs a full memory barrier between updating SQ tail and
checking for the IORING_SQ_NEED_WAKEUP too.

Signed-off-by: Stefan Bühler <source@stbuehler.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Stefan Bühler authored and Jens Axboe committed Apr 22, 2019
1 parent e523a29 commit 0d7bae6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,8 @@ static int io_sq_thread(void *data)

/* Tell userspace we may need a wakeup call */
ctx->sq_ring->flags |= IORING_SQ_NEED_WAKEUP;
smp_wmb();
/* make sure to read SQ tail after writing flags */
smp_mb();

if (!io_get_sqring(ctx, &sqes[0])) {
if (kthread_should_stop()) {
Expand Down

0 comments on commit 0d7bae6

Please sign in to comment.