Skip to content

Commit

Permalink
io_uring: never attempt iopoll reissue from release path
Browse files Browse the repository at this point in the history
[ Upstream commit 3c30ef0 ]

There are two reasons why this shouldn't be done:

1) Ring is exiting, and we're canceling requests anyway. Any request
   should be canceled anyway. In theory, this could iterate for a
   number of times if someone else is also driving the target block
   queue into request starvation, however the likelihood of this
   happening is miniscule.

2) If the original task decided to pass the ring to another task, then
   we don't want to be reissuing from this context as it may be an
   unrelated task or context. No assumptions should be made about
   the context in which ->release() is run. This can only happen for pure
   read/write, and we'll get -EFAULT on them anyway.

Link: https://lore.kernel.org/io-uring/YPr4OaHv0iv0KTOc@zeniv-ca.linux.org.uk/
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
axboe authored and gregkh committed Aug 8, 2021
1 parent eb9b9c6 commit f7be9c7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/io_uring.c
Expand Up @@ -2252,7 +2252,7 @@ static inline bool io_run_task_work(void)
* Find and free completed poll iocbs
*/
static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
struct list_head *done)
struct list_head *done, bool resubmit)
{
struct req_batch rb;
struct io_kiocb *req;
Expand All @@ -2267,7 +2267,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
req = list_first_entry(done, struct io_kiocb, inflight_entry);
list_del(&req->inflight_entry);

if (READ_ONCE(req->result) == -EAGAIN &&
if (READ_ONCE(req->result) == -EAGAIN && resubmit &&
!(req->flags & REQ_F_DONT_REISSUE)) {
req->iopoll_completed = 0;
req_ref_get(req);
Expand All @@ -2291,7 +2291,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
}

static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
long min)
long min, bool resubmit)
{
struct io_kiocb *req, *tmp;
LIST_HEAD(done);
Expand Down Expand Up @@ -2334,7 +2334,7 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events,
}

if (!list_empty(&done))
io_iopoll_complete(ctx, nr_events, &done);
io_iopoll_complete(ctx, nr_events, &done, resubmit);

return ret;
}
Expand All @@ -2352,7 +2352,7 @@ static void io_iopoll_try_reap_events(struct io_ring_ctx *ctx)
while (!list_empty(&ctx->iopoll_list)) {
unsigned int nr_events = 0;

io_do_iopoll(ctx, &nr_events, 0);
io_do_iopoll(ctx, &nr_events, 0, false);

/* let it sleep and repeat later if can't complete a request */
if (nr_events == 0)
Expand Down Expand Up @@ -2410,7 +2410,7 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min)
if (list_empty(&ctx->iopoll_list))
break;
}
ret = io_do_iopoll(ctx, &nr_events, min);
ret = io_do_iopoll(ctx, &nr_events, min, true);
} while (!ret && nr_events < min && !need_resched());
out:
mutex_unlock(&ctx->uring_lock);
Expand Down Expand Up @@ -6804,7 +6804,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)

mutex_lock(&ctx->uring_lock);
if (!list_empty(&ctx->iopoll_list))
io_do_iopoll(ctx, &nr_events, 0);
io_do_iopoll(ctx, &nr_events, 0, true);

/*
* Don't submit if refs are dying, good for io_uring_register(),
Expand Down

0 comments on commit f7be9c7

Please sign in to comment.