Skip to content

Commit 6f27bbf

Browse files
axboegregkh
authored andcommitted
nvme: always punt polled uring_cmd end_io work to task_work
Commit 9ce6c98 upstream. Currently NVMe uring_cmd completions will complete locally, if they are polled. This is done because those completions are always invoked from task context. And while that is true, there's no guarantee that it's invoked under the right ring context, or even task. If someone does NVMe passthrough via multiple threads and with a limited number of poll queues, then ringA may find completions from ringB. For that case, completing the request may not be sound. Always just punt the passthrough completions via task_work, which will redirect the completion, if needed. Cc: stable@vger.kernel.org Fixes: 585079b ("nvme: wire up async polling for io passthrough commands") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cdfb20e commit 6f27bbf

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

drivers/nvme/host/ioctl.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,14 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req,
526526
pdu->u.result = le64_to_cpu(nvme_req(req)->result.u64);
527527

528528
/*
529-
* For iopoll, complete it directly.
530-
* Otherwise, move the completion to task work.
529+
* IOPOLL could potentially complete this request directly, but
530+
* if multiple rings are polling on the same queue, then it's possible
531+
* for one ring to find completions for another ring. Punting the
532+
* completion via task_work will always direct it to the right
533+
* location, rather than potentially complete requests for ringA
534+
* under iopoll invocations from ringB.
531535
*/
532-
if (blk_rq_is_poll(req)) {
533-
WRITE_ONCE(ioucmd->cookie, NULL);
534-
nvme_uring_task_cb(ioucmd, IO_URING_F_UNLOCKED);
535-
} else {
536-
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);
537-
}
538-
536+
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);
539537
return RQ_END_IO_FREE;
540538
}
541539

0 commit comments

Comments
 (0)