Skip to content

Commit

Permalink
io_uring: fix race condition reading SQ entries
Browse files Browse the repository at this point in the history
A read memory barrier is required between reading SQ tail and reading
the actual data belonging to the SQ entry.

Userspace needs a matching write barrier between writing SQ entries and
updating SQ tail (using smp_store_release to update tail will do).

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 35fa71a commit e523a29
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 @@ -1739,7 +1739,8 @@ static bool io_get_sqring(struct io_ring_ctx *ctx, struct sqe_submit *s)
head = ctx->cached_sq_head;
/* See comment at the top of this file */
smp_rmb();
if (head == READ_ONCE(ring->r.tail))
/* make sure SQ entry isn't read before tail */
if (head == smp_load_acquire(&ring->r.tail))
return false;

head = READ_ONCE(ring->array[head & ctx->sq_mask]);
Expand Down

0 comments on commit e523a29

Please sign in to comment.