Skip to content

Commit 9a472ef

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix link lookup racing with link timeout
We can't just go over linked requests because it may race with linked timeouts. Take ctx->completion_lock in that case. Cc: [email protected] # v5.7+ Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6b47ab8 commit 9a472ef

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fs/io_uring.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -8470,7 +8470,21 @@ static bool io_timeout_remove_link(struct io_ring_ctx *ctx,
84708470

84718471
static bool io_cancel_link_cb(struct io_wq_work *work, void *data)
84728472
{
8473-
return io_match_link(container_of(work, struct io_kiocb, work), data);
8473+
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
8474+
bool ret;
8475+
8476+
if (req->flags & REQ_F_LINK_TIMEOUT) {
8477+
unsigned long flags;
8478+
struct io_ring_ctx *ctx = req->ctx;
8479+
8480+
/* protect against races with linked timeouts */
8481+
spin_lock_irqsave(&ctx->completion_lock, flags);
8482+
ret = io_match_link(req, data);
8483+
spin_unlock_irqrestore(&ctx->completion_lock, flags);
8484+
} else {
8485+
ret = io_match_link(req, data);
8486+
}
8487+
return ret;
84748488
}
84758489

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

0 commit comments

Comments
 (0)