Skip to content

Commit ab0f247

Browse files
committed
Merge tag 'io_uring-5.8-2020-06-26' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: "Three small fixes: - Close a corner case for polled IO resubmission (Pavel) - Toss commands when exiting (Pavel) - Fix SQPOLL conditional reschedule on perpetually busy submit (Xuan)" * tag 'io_uring-5.8-2020-06-26' of git://git.kernel.dk/linux-block: io_uring: fix current->mm NULL dereference on exit io_uring: fix hanging iopoll in case of -EAGAIN io_uring: fix io_sq_thread no schedule when busy
2 parents 9b8d020 + d60b5fb commit ab0f247

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

fs/io_uring.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
890890
struct io_uring_files_update *ip,
891891
unsigned nr_args);
892892
static int io_grab_files(struct io_kiocb *req);
893+
static void io_complete_rw_common(struct kiocb *kiocb, long res);
893894
static void io_cleanup_req(struct io_kiocb *req);
894895
static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
895896
int fd, struct file **out_file, bool fixed);
@@ -1749,6 +1750,14 @@ static void io_iopoll_queue(struct list_head *again)
17491750
do {
17501751
req = list_first_entry(again, struct io_kiocb, list);
17511752
list_del(&req->list);
1753+
1754+
/* shouldn't happen unless io_uring is dying, cancel reqs */
1755+
if (unlikely(!current->mm)) {
1756+
io_complete_rw_common(&req->rw.kiocb, -EAGAIN);
1757+
io_put_req(req);
1758+
continue;
1759+
}
1760+
17521761
refcount_inc(&req->refs);
17531762
io_queue_async_work(req);
17541763
} while (!list_empty(again));
@@ -1994,10 +2003,8 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
19942003

19952004
WRITE_ONCE(req->result, res);
19962005
/* order with io_poll_complete() checking ->result */
1997-
if (res != -EAGAIN) {
1998-
smp_wmb();
1999-
WRITE_ONCE(req->iopoll_completed, 1);
2000-
}
2006+
smp_wmb();
2007+
WRITE_ONCE(req->iopoll_completed, 1);
20012008
}
20022009

20032010
/*
@@ -5353,9 +5360,6 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
53535360
if ((ctx->flags & IORING_SETUP_IOPOLL) && req->file) {
53545361
const bool in_async = io_wq_current_is_worker();
53555362

5356-
if (req->result == -EAGAIN)
5357-
return -EAGAIN;
5358-
53595363
/* workqueue context doesn't hold uring_lock, grab it now */
53605364
if (in_async)
53615365
mutex_lock(&ctx->uring_lock);
@@ -6011,7 +6015,7 @@ static int io_sq_thread(void *data)
60116015
* If submit got -EBUSY, flag us as needing the application
60126016
* to enter the kernel to reap and flush events.
60136017
*/
6014-
if (!to_submit || ret == -EBUSY) {
6018+
if (!to_submit || ret == -EBUSY || need_resched()) {
60156019
/*
60166020
* Drop cur_mm before scheduling, we can't hold it for
60176021
* long periods (or over schedule()). Do this before
@@ -6027,7 +6031,7 @@ static int io_sq_thread(void *data)
60276031
* more IO, we should wait for the application to
60286032
* reap events and wake us up.
60296033
*/
6030-
if (!list_empty(&ctx->poll_list) ||
6034+
if (!list_empty(&ctx->poll_list) || need_resched() ||
60316035
(!time_after(jiffies, timeout) && ret != -EBUSY &&
60326036
!percpu_ref_is_dying(&ctx->refs))) {
60336037
if (current->task_works)

0 commit comments

Comments
 (0)