io_uring: ensure workqueue offload grabs ring mutex for poll list
authorJens Axboe <axboe@kernel.dk>
Thu, 16 Jan 2020 04:51:17 +0000 (21:51 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 16 Jan 2020 04:51:17 +0000 (21:51 -0700)
A previous commit moved the locking for the async sqthread, but didn't
take into account that the io-wq workers still need it. We can't use
req->in_async for this anymore as both the sqthread and io-wq workers
set it, gate the need for locking on io_wq_current_is_worker() instead.

Fixes: 8a4955ff1cca ("io_uring: sqthread should grab ctx->uring_lock for submissions")
Reported-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index 3130ed16456e4772f3fb1571babd029a2097fae3..52e5764540e4548820a5dc91471ce13fd42bc007 100644 (file)
@@ -3286,10 +3286,19 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                return ret;
 
        if (ctx->flags & IORING_SETUP_IOPOLL) {
+               const bool in_async = io_wq_current_is_worker();
+
                if (req->result == -EAGAIN)
                        return -EAGAIN;
 
+               /* workqueue context doesn't hold uring_lock, grab it now */
+               if (in_async)
+                       mutex_lock(&ctx->uring_lock);
+
                io_iopoll_req_issued(req);
+
+               if (in_async)
+                       mutex_unlock(&ctx->uring_lock);
        }
 
        return 0;