Skip to content

Commit

Permalink
io_uring: fix link lookup racing with link timeout
Browse files Browse the repository at this point in the history
We can't just go over linked requests because it may race with linked
timeouts. Take ctx->completion_lock in that case.

Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Nov 5, 2020
1 parent 6b47ab8 commit 9a472ef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8470,7 +8470,21 @@ static bool io_timeout_remove_link(struct io_ring_ctx *ctx,

static bool io_cancel_link_cb(struct io_wq_work *work, void *data)
{
return io_match_link(container_of(work, struct io_kiocb, work), data);
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
bool ret;

if (req->flags & REQ_F_LINK_TIMEOUT) {
unsigned long flags;
struct io_ring_ctx *ctx = req->ctx;

/* protect against races with linked timeouts */
spin_lock_irqsave(&ctx->completion_lock, flags);
ret = io_match_link(req, data);
spin_unlock_irqrestore(&ctx->completion_lock, flags);
} else {
ret = io_match_link(req, data);
}
return ret;
}

static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
Expand Down

0 comments on commit 9a472ef

Please sign in to comment.