From: Anuj Gupta Allow registering a dma-buf against an NVMe namespace character device and using it as the data buffer of fixed uring_cmd passthrough I/O. Complete through io_uring_cmd_hw_done(), so the dma-buf map is released at hardware completion. Signed-off-by: Anuj Gupta Reviewed-by: Christoph Hellwig Reviewed-by: Pavel Begunkov --- drivers/nvme/host/core.c | 16 ++++++++++++++++ drivers/nvme/host/ioctl.c | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index a7a4d09644c1..33dbaa319bb9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -4008,6 +4009,20 @@ static int nvme_ns_chr_release(struct inode *inode, struct file *file) return 0; } +static int nvme_ns_chr_init_dma_buf_io_ctx(struct file *file, + struct dma_buf_io_ctx *ctx) +{ + struct nvme_ns *ns = + container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev); + struct nvme_ctrl *ctrl = ns->ctrl; + + if (ctx->dmabuf->size > UINT_MAX) + return -EINVAL; + if (!ctrl->ops->init_dma_buf_io_ctx) + return -EOPNOTSUPP; + return ctrl->ops->init_dma_buf_io_ctx(ctrl, ctx); +} + static const struct file_operations nvme_ns_chr_fops = { .owner = THIS_MODULE, .open = nvme_ns_chr_open, @@ -4016,6 +4031,7 @@ static const struct file_operations nvme_ns_chr_fops = { .compat_ioctl = compat_ptr_ioctl, .uring_cmd = nvme_ns_chr_uring_cmd, .uring_cmd_iopoll = nvme_ns_chr_uring_cmd_iopoll, + .init_dma_buf_io_ctx = nvme_ns_chr_init_dma_buf_io_ctx, }; static void nvme_add_ns_cdev(struct nvme_ns *ns) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index d342ccad067a..3f240c9a537f 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -472,7 +472,7 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req, blk_rq_unmap_user(pdu->bio); __io_uring_cmd_done(ioucmd, 0); } else { - io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb); + io_uring_cmd_hw_done(ioucmd, nvme_uring_task_cb); } return RQ_END_IO_FREE; } @@ -533,7 +533,8 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, ddir, &iter, issue_flags); else ret = io_uring_cmd_import_fixed(d.addr, d.data_len, - ddir, &iter, ioucmd, issue_flags, 0); + ddir, &iter, ioucmd, issue_flags, + IO_URING_CMD_IMPORT_DMABUF); if (ret < 0) return ret; -- 2.43.0