Skip to content

Commit

Permalink
io_uring : correct timeout req sequence when waiting timeout
Browse files Browse the repository at this point in the history
The sequence number of reqs on the timeout_list before the timeout req
should be adjusted in io_timeout_fn(), because the current timeout req
will consumes a slot in the cq_ring and cq_tail pointer will be
increased, otherwise other timeout reqs may return in advance without
waiting for enough wait_nr.

Signed-off-by: zhangyi (F) <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
zhangyi089 authored and axboe committed Oct 24, 2019
1 parent bc808bc commit ef03681
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1877,14 +1877,23 @@ static int io_poll_add(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer)
{
struct io_ring_ctx *ctx;
struct io_kiocb *req;
struct io_kiocb *req, *prev;
unsigned long flags;

req = container_of(timer, struct io_kiocb, timeout.timer);
ctx = req->ctx;
atomic_inc(&ctx->cq_timeouts);

spin_lock_irqsave(&ctx->completion_lock, flags);
/*
* Adjust the reqs sequence before the current one because it
* will consume a slot in the cq_ring and the the cq_tail pointer
* will be increased, otherwise other timeout reqs may return in
* advance without waiting for enough wait_nr.
*/
prev = req;
list_for_each_entry_continue_reverse(prev, &ctx->timeout_list, list)
prev->sequence++;
list_del(&req->list);

io_cqring_fill_event(ctx, req->user_data, -ETIME);
Expand Down

0 comments on commit ef03681

Please sign in to comment.