* [PATCH v4 0/5] io_uring passthrough for nvme [not found] <CGME20220505061142epcas5p2c943572766bfd5088138fe0f7873c96c@epcas5p2.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi [not found] ` <CGME20220505061144epcas5p3821a9516dad2b5eff5a25c56dbe164df@epcas5p3.samsung.com> ` (4 more replies) 0 siblings, 5 replies; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev This iteration is against io_uring-big-sqe brach (linux-block). On top of a739b2354 ("io_uring: enable CQE32"). fio testing branch: https://github.com/joshkan/fio/tree/big-cqe-pt.v4 Changes since v3: https://lore.kernel.org/linux-nvme/[email protected]/ - Cleaned up placements of new fields in sqe and io_uring_cmd - Removed packed-attribute from nvme_uring_cmd struct - Applied all other Christoph's feedback too - Applied Jens feedback - Collected reviewed-by Changes since v2: https://lore.kernel.org/linux-nvme/[email protected]/ - Rewire uring-cmd infrastructure on top of new big CQE - Prep patch (refactored) and feedback from Christoph - Add new opcode and structure in nvme for uring-cmd - Enable vectored-io Changes since v1: https://lore.kernel.org/linux-nvme/[email protected]/ - Trim down by removing patches for polling, fixed-buffer and bio-cache - Add big CQE and move uring-cmd to use that - Remove indirect (pointer) submission Anuj Gupta (1): nvme: add vectored-io support for uring-cmd Christoph Hellwig (1): nvme: refactor nvme_submit_user_cmd() Jens Axboe (2): fs,io_uring: add infrastructure for uring-cmd block: wire-up support for passthrough plugging Kanchan Joshi (1): nvme: wire-up uring-cmd support for io-passthru on char-device. block/blk-mq.c | 73 ++++++----- drivers/nvme/host/core.c | 1 + drivers/nvme/host/ioctl.c | 215 +++++++++++++++++++++++++++++++- drivers/nvme/host/multipath.c | 1 + drivers/nvme/host/nvme.h | 5 + fs/io_uring.c | 82 ++++++++++-- include/linux/fs.h | 2 + include/linux/io_uring.h | 27 ++++ include/uapi/linux/io_uring.h | 21 ++-- include/uapi/linux/nvme_ioctl.h | 26 ++++ 10 files changed, 398 insertions(+), 55 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20220505061144epcas5p3821a9516dad2b5eff5a25c56dbe164df@epcas5p3.samsung.com>]
* [PATCH v4 1/5] fs,io_uring: add infrastructure for uring-cmd [not found] ` <CGME20220505061144epcas5p3821a9516dad2b5eff5a25c56dbe164df@epcas5p3.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi 2022-05-05 12:52 ` Jens Axboe [not found] ` <[email protected]> 0 siblings, 2 replies; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev From: Jens Axboe <[email protected]> file_operations->uring_cmd is a file private handler. This is somewhat similar to ioctl but hopefully a lot more sane and useful as it can be used to enable many io_uring capabilities for the underlying operation. IORING_OP_URING_CMD is a file private kind of request. io_uring doesn't know what is in this command type, it's for the provider of ->uring_cmd() to deal with. This operation can be issued only on the ring that is setup with both IORING_SETUP_SQE128 and IORING_SETUP_CQE32 flags. Co-developed-by: Kanchan Joshi <[email protected]> Signed-off-by: Kanchan Joshi <[email protected]> Signed-off-by: Jens Axboe <[email protected]> --- fs/io_uring.c | 82 ++++++++++++++++++++++++++++++++--- include/linux/fs.h | 2 + include/linux/io_uring.h | 27 ++++++++++++ include/uapi/linux/io_uring.h | 21 +++++---- 4 files changed, 117 insertions(+), 15 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index c7e3f7e74d92..3436507f04eb 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -202,13 +202,6 @@ struct io_rings { struct io_uring_cqe cqes[] ____cacheline_aligned_in_smp; }; -enum io_uring_cmd_flags { - IO_URING_F_COMPLETE_DEFER = 1, - IO_URING_F_UNLOCKED = 2, - /* int's last bit, sign checks are usually faster than a bit test */ - IO_URING_F_NONBLOCK = INT_MIN, -}; - struct io_mapped_ubuf { u64 ubuf; u64 ubuf_end; @@ -969,6 +962,7 @@ struct io_kiocb { struct io_xattr xattr; struct io_socket sock; struct io_nop nop; + struct io_uring_cmd uring_cmd; }; u8 opcode; @@ -1254,6 +1248,10 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_SOCKET] = { .audit_skip = 1, }, + [IORING_OP_URING_CMD] = { + .needs_file = 1, + .plug = 1, + }, }; /* requests with any of those set should undergo io_disarm_next() */ @@ -1393,6 +1391,8 @@ const char *io_uring_get_opcode(u8 opcode) return "GETXATTR"; case IORING_OP_SOCKET: return "SOCKET"; + case IORING_OP_URING_CMD: + return "URING_CMD"; case IORING_OP_LAST: return "INVALID"; } @@ -4907,6 +4907,67 @@ static int io_linkat(struct io_kiocb *req, unsigned int issue_flags) return 0; } +static void io_uring_cmd_work(struct io_kiocb *req, bool *locked) +{ + req->uring_cmd.task_work_cb(&req->uring_cmd); +} + +void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, + void (*task_work_cb)(struct io_uring_cmd *)) +{ + struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd); + + req->uring_cmd.task_work_cb = task_work_cb; + req->io_task_work.func = io_uring_cmd_work; + io_req_task_work_add(req, !!(req->ctx->flags & IORING_SETUP_SQPOLL)); +} +EXPORT_SYMBOL_GPL(io_uring_cmd_complete_in_task); + +/* + * Called by consumers of io_uring_cmd, if they originally returned + * -EIOCBQUEUED upon receiving the command. + */ +void io_uring_cmd_done(struct io_uring_cmd *ioucmd, ssize_t ret, ssize_t res2) +{ + struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd); + + if (ret < 0) + req_set_fail(req); + __io_req_complete32(req, 0, ret, 0, res2, 0); +} +EXPORT_SYMBOL_GPL(io_uring_cmd_done); + +static int io_uring_cmd_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_uring_cmd *ioucmd = &req->uring_cmd; + struct io_ring_ctx *ctx = req->ctx; + + if (ctx->flags & IORING_SETUP_IOPOLL) + return -EOPNOTSUPP; + /* do not support uring-cmd without big SQE/CQE */ + if (!(ctx->flags & IORING_SETUP_SQE128)) + return -EOPNOTSUPP; + if (!(ctx->flags & IORING_SETUP_CQE32)) + return -EOPNOTSUPP; + if (sqe->ioprio || sqe->rw_flags) + return -EINVAL; + ioucmd->cmd = sqe->cmd; + ioucmd->cmd_op = READ_ONCE(sqe->cmd_op); + return 0; +} + +static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags) +{ + struct file *file = req->file; + struct io_uring_cmd *ioucmd = &req->uring_cmd; + + if (!req->file->f_op->uring_cmd) + return -EOPNOTSUPP; + file->f_op->uring_cmd(ioucmd, issue_flags); + return 0; +} + static int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -7764,6 +7825,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_getxattr_prep(req, sqe); case IORING_OP_SOCKET: return io_socket_prep(req, sqe); + case IORING_OP_URING_CMD: + return io_uring_cmd_prep(req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -8085,6 +8148,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_SOCKET: ret = io_socket(req, issue_flags); break; + case IORING_OP_URING_CMD: + ret = io_uring_cmd(req, issue_flags); + break; default: ret = -EINVAL; break; @@ -12688,6 +12754,8 @@ static int __init io_uring_init(void) BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST); BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int)); + BUILD_BUG_ON(sizeof(struct io_uring_cmd) > 64); + req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); return 0; diff --git a/include/linux/fs.h b/include/linux/fs.h index bbde95387a23..30c98d9993df 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1953,6 +1953,7 @@ struct dir_context { #define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN) struct iov_iter; +struct io_uring_cmd; struct file_operations { struct module *owner; @@ -1995,6 +1996,7 @@ struct file_operations { struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); + void (*uring_cmd)(struct io_uring_cmd *ioucmd, unsigned int issue_flags); } __randomize_layout; struct inode_operations { diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h index 24651c229ed2..e4cbc80949ce 100644 --- a/include/linux/io_uring.h +++ b/include/linux/io_uring.h @@ -5,7 +5,26 @@ #include <linux/sched.h> #include <linux/xarray.h> +enum io_uring_cmd_flags { + IO_URING_F_COMPLETE_DEFER = 1, + IO_URING_F_UNLOCKED = 2, + /* int's last bit, sign checks are usually faster than a bit test */ + IO_URING_F_NONBLOCK = INT_MIN, +}; + +struct io_uring_cmd { + struct file *file; + const u8 *cmd; + /* callback to defer completions to task context */ + void (*task_work_cb)(struct io_uring_cmd *cmd); + u32 cmd_op; + u8 pdu[32]; /* available inline for free use */ +}; + #if defined(CONFIG_IO_URING) +void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2); +void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, + void (*task_work_cb)(struct io_uring_cmd *)); struct sock *io_uring_get_socket(struct file *file); void __io_uring_cancel(bool cancel_all); void __io_uring_free(struct task_struct *tsk); @@ -30,6 +49,14 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); } #else +static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, + ssize_t ret2) +{ +} +static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, + void (*task_work_cb)(struct io_uring_cmd *)) +{ +} static inline struct sock *io_uring_get_socket(struct file *file) { return NULL; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 881e508767f8..92af2169ef58 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -22,6 +22,7 @@ struct io_uring_sqe { union { __u64 off; /* offset into file */ __u64 addr2; + __u32 cmd_op; }; union { __u64 addr; /* pointer to buffer or iovecs */ @@ -61,14 +62,17 @@ struct io_uring_sqe { __s32 splice_fd_in; __u32 file_index; }; - __u64 addr3; - __u64 __pad2[1]; - - /* - * If the ring is initialized with IORING_SETUP_SQE128, then this field - * contains 64-bytes of padding, doubling the size of the SQE. - */ - __u64 __big_sqe_pad[0]; + union { + struct { + __u64 addr3; + __u64 __pad2[1]; + }; + /* + * If the ring is initialized with IORING_SETUP_SQE128, then + * this field is used for 80 bytes of arbitrary command data + */ + __u8 cmd[0]; + }; }; enum { @@ -160,6 +164,7 @@ enum io_uring_op { IORING_OP_FGETXATTR, IORING_OP_GETXATTR, IORING_OP_SOCKET, + IORING_OP_URING_CMD, /* this goes last, obviously */ IORING_OP_LAST, -- 2.25.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 1/5] fs,io_uring: add infrastructure for uring-cmd 2022-05-05 6:06 ` [PATCH v4 1/5] fs,io_uring: add infrastructure for uring-cmd Kanchan Joshi @ 2022-05-05 12:52 ` Jens Axboe [not found] ` <[email protected]> 1 sibling, 0 replies; 10+ messages in thread From: Jens Axboe @ 2022-05-05 12:52 UTC (permalink / raw) To: Kanchan Joshi, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev On 5/5/22 12:06 AM, Kanchan Joshi wrote: > From: Jens Axboe <[email protected]> > > file_operations->uring_cmd is a file private handler. > This is somewhat similar to ioctl but hopefully a lot more sane and > useful as it can be used to enable many io_uring capabilities for the > underlying operation. > > IORING_OP_URING_CMD is a file private kind of request. io_uring doesn't > know what is in this command type, it's for the provider of ->uring_cmd() > to deal with. This operation can be issued only on the ring that is > setup with both IORING_SETUP_SQE128 and IORING_SETUP_CQE32 flags. One thing that occured to me that I think we need to change is what you mention above, code here: > +static int io_uring_cmd_prep(struct io_kiocb *req, > + const struct io_uring_sqe *sqe) > +{ > + struct io_uring_cmd *ioucmd = &req->uring_cmd; > + struct io_ring_ctx *ctx = req->ctx; > + > + if (ctx->flags & IORING_SETUP_IOPOLL) > + return -EOPNOTSUPP; > + /* do not support uring-cmd without big SQE/CQE */ > + if (!(ctx->flags & IORING_SETUP_SQE128)) > + return -EOPNOTSUPP; > + if (!(ctx->flags & IORING_SETUP_CQE32)) > + return -EOPNOTSUPP; > + if (sqe->ioprio || sqe->rw_flags) > + return -EINVAL; > + ioucmd->cmd = sqe->cmd; > + ioucmd->cmd_op = READ_ONCE(sqe->cmd_op); > + return 0; > +} I've been thinking of this mostly in the context of passthrough for nvme, but it originally started as a generic feature to be able to wire up anything for these types of commands. The SQE128/CQE32 requirement is really an nvme passthrough restriction, we don't necessarily need this for any kind of URING_CMD. Ditto IOPOLL as well. These are all things that should be validated further down, but there's no way to do that currently. Let's not have that hold up merging this, but we do need it fixed up for 5.19-final so we don't have this restriction. Suggestions welcome... -- Jens Axboe ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <[email protected]>]
[parent not found: <CA+1E3r+airL_U0BzmLhiVPVkWdbiAXxxyHXONy9bGx4uuJFhdA@mail.gmail.com>]
* Re: [PATCH v4 1/5] fs,io_uring: add infrastructure for uring-cmd [not found] ` <CA+1E3r+airL_U0BzmLhiVPVkWdbiAXxxyHXONy9bGx4uuJFhdA@mail.gmail.com> @ 2022-05-10 14:35 ` Jens Axboe 0 siblings, 0 replies; 10+ messages in thread From: Jens Axboe @ 2022-05-10 14:35 UTC (permalink / raw) To: Kanchan Joshi Cc: Kanchan Joshi, Christoph Hellwig, io-uring, linux-nvme, Pavel Begunkov, Ming Lei, Luis Chamberlain, Stefan Roesch, Anuj Gupta, gost.dev On 5/10/22 8:23 AM, Kanchan Joshi wrote: > On Thu, May 5, 2022 at 9:47 PM Jens Axboe <[email protected]> wrote: >> >> On 5/5/22 12:06 AM, Kanchan Joshi wrote: >>> +static int io_uring_cmd_prep(struct io_kiocb *req, >>> + const struct io_uring_sqe *sqe) >>> +{ >>> + struct io_uring_cmd *ioucmd = &req->uring_cmd; >>> + struct io_ring_ctx *ctx = req->ctx; >>> + >>> + if (ctx->flags & IORING_SETUP_IOPOLL) >>> + return -EOPNOTSUPP; >>> + /* do not support uring-cmd without big SQE/CQE */ >>> + if (!(ctx->flags & IORING_SETUP_SQE128)) >>> + return -EOPNOTSUPP; >>> + if (!(ctx->flags & IORING_SETUP_CQE32)) >>> + return -EOPNOTSUPP; >>> + if (sqe->ioprio || sqe->rw_flags) >>> + return -EINVAL; >>> + ioucmd->cmd = sqe->cmd; >>> + ioucmd->cmd_op = READ_ONCE(sqe->cmd_op); >>> + return 0; >>> +} >> >> While looking at the other suggested changes, I noticed a more >> fundamental issue with the passthrough support. For any other command, >> SQE contents are stable once prep has been done. The above does do that >> for the basic items, but this case is special as the lower level command >> itself resides in the SQE. >> >> For cases where the command needs deferral, it's problematic. There are >> two main cases where this can happen: >> >> - The issue attempt yields -EAGAIN (we ran out of requests, etc). If you >> look at other commands, if they have data that doesn't fit in the >> io_kiocb itself, then they need to allocate room for that data and have >> it be persistent > > While we have io-wq retrying for this case, async_data is not allocated. > We need to do that explicitly inside io_uring_cmd(). Something like this - > > if (ret == -EAGAIN) { > if (!req_has_async_data(req)) { > if (io_alloc_async_data(req)) return -ENOMEM; > io_uring_cmd_prep_async(req); > } > return ret; > } > >> - Deferral is specified by the application, using eg IOSQE_IO_LINK or >> IOSQE_ASYNC. > For this to work, we are missing ".needs_async_setup = 1" for > IORING_OP_URING_CMD. Agree on both, the op handler itself should alloc the async_data for this case and that flag does need to be set. -- Jens Axboe ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20220505061146epcas5p3919c48d58d353a62a5858ee10ad162a0@epcas5p3.samsung.com>]
* [PATCH v4 2/5] block: wire-up support for passthrough plugging [not found] ` <CGME20220505061146epcas5p3919c48d58d353a62a5858ee10ad162a0@epcas5p3.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi 0 siblings, 0 replies; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev From: Jens Axboe <[email protected]> Add support for plugging in passthrough path. When plugging is enabled, the requests are added to a plug instead of getting dispatched to the driver. And when the plug is finished, the whole batch gets dispatched via ->queue_rqs which turns out to be more efficient. Otherwise dispatching used to happen via ->queue_rq, one request at a time. Signed-off-by: Jens Axboe <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> --- block/blk-mq.c | 73 +++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 84d749511f55..2cf011b57cf9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2340,6 +2340,40 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, blk_mq_hctx_mark_pending(hctx, ctx); } +/* + * Allow 2x BLK_MAX_REQUEST_COUNT requests on plug queue for multiple + * queues. This is important for md arrays to benefit from merging + * requests. + */ +static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug) +{ + if (plug->multiple_queues) + return BLK_MAX_REQUEST_COUNT * 2; + return BLK_MAX_REQUEST_COUNT; +} + +static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq) +{ + struct request *last = rq_list_peek(&plug->mq_list); + + if (!plug->rq_count) { + trace_block_plug(rq->q); + } else if (plug->rq_count >= blk_plug_max_rq_count(plug) || + (!blk_queue_nomerges(rq->q) && + blk_rq_bytes(last) >= BLK_PLUG_FLUSH_SIZE)) { + blk_mq_flush_plug_list(plug, false); + trace_block_plug(rq->q); + } + + if (!plug->multiple_queues && last && last->q != rq->q) + plug->multiple_queues = true; + if (!plug->has_elevator && (rq->rq_flags & RQF_ELV)) + plug->has_elevator = true; + rq->rq_next = NULL; + rq_list_add(&plug->mq_list, rq); + plug->rq_count++; +} + /** * blk_mq_request_bypass_insert - Insert a request at dispatch list. * @rq: Pointer to request to be inserted. @@ -2353,7 +2387,12 @@ void blk_mq_request_bypass_insert(struct request *rq, bool at_head, bool run_queue) { struct blk_mq_hw_ctx *hctx = rq->mq_hctx; + struct blk_plug *plug = current->plug; + if (plug) { + blk_add_rq_to_plug(plug, rq); + return; + } spin_lock(&hctx->lock); if (at_head) list_add(&rq->queuelist, &hctx->dispatch); @@ -2676,40 +2715,6 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, hctx->queue->mq_ops->commit_rqs(hctx); } -/* - * Allow 2x BLK_MAX_REQUEST_COUNT requests on plug queue for multiple - * queues. This is important for md arrays to benefit from merging - * requests. - */ -static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug) -{ - if (plug->multiple_queues) - return BLK_MAX_REQUEST_COUNT * 2; - return BLK_MAX_REQUEST_COUNT; -} - -static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq) -{ - struct request *last = rq_list_peek(&plug->mq_list); - - if (!plug->rq_count) { - trace_block_plug(rq->q); - } else if (plug->rq_count >= blk_plug_max_rq_count(plug) || - (!blk_queue_nomerges(rq->q) && - blk_rq_bytes(last) >= BLK_PLUG_FLUSH_SIZE)) { - blk_mq_flush_plug_list(plug, false); - trace_block_plug(rq->q); - } - - if (!plug->multiple_queues && last && last->q != rq->q) - plug->multiple_queues = true; - if (!plug->has_elevator && (rq->rq_flags & RQF_ELV)) - plug->has_elevator = true; - rq->rq_next = NULL; - rq_list_add(&plug->mq_list, rq); - plug->rq_count++; -} - static bool blk_mq_attempt_bio_merge(struct request_queue *q, struct bio *bio, unsigned int nr_segs) { -- 2.25.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
[parent not found: <CGME20220505061148epcas5p188618b5b15a95cbe48c8c1559a18c994@epcas5p1.samsung.com>]
* [PATCH v4 3/5] nvme: refactor nvme_submit_user_cmd() [not found] ` <CGME20220505061148epcas5p188618b5b15a95cbe48c8c1559a18c994@epcas5p1.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi 0 siblings, 0 replies; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev From: Christoph Hellwig <[email protected]> Divide the work into two helpers, namely nvme_alloc_user_request and nvme_execute_user_rq. This is a prep patch, to help wiring up uring-cmd support in nvme. Signed-off-by: Christoph Hellwig <[email protected]> --- drivers/nvme/host/ioctl.c | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 554566371ffa..3531de8073a6 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -19,6 +19,13 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval) return (void __user *)ptrval; } +static inline void *nvme_meta_from_bio(struct bio *bio) +{ + struct bio_integrity_payload *bip = bio_integrity(bio); + + return bip ? bvec_virt(bip->bip_vec) : NULL; +} + static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, unsigned len, u32 seed, bool write) { @@ -53,10 +60,10 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, return ERR_PTR(ret); } -static int nvme_submit_user_cmd(struct request_queue *q, +static struct request *nvme_alloc_user_request(struct request_queue *q, struct nvme_command *cmd, void __user *ubuffer, unsigned bufflen, void __user *meta_buffer, unsigned meta_len, - u32 meta_seed, u64 *result, unsigned timeout, bool vec) + u32 meta_seed, unsigned timeout, bool vec) { bool write = nvme_is_write(cmd); struct nvme_ns *ns = q->queuedata; @@ -68,7 +75,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0); if (IS_ERR(req)) - return PTR_ERR(req); + return req; nvme_init_request(req, cmd); if (timeout) @@ -108,7 +115,26 @@ static int nvme_submit_user_cmd(struct request_queue *q, } } + return req; + +out_unmap: + if (bio) + blk_rq_unmap_user(bio); +out: + blk_mq_free_request(req); + return ERR_PTR(ret); +} + +static int nvme_execute_user_rq(struct request *req, void __user *meta_buffer, + unsigned meta_len, u64 *result) +{ + struct bio *bio = req->bio; + bool write = bio_op(bio) == REQ_OP_DRV_OUT; + int ret; + void *meta = nvme_meta_from_bio(bio); + ret = nvme_execute_passthru_rq(req); + if (result) *result = le64_to_cpu(nvme_req(req)->result.u64); if (meta && !ret && !write) { @@ -116,14 +142,25 @@ static int nvme_submit_user_cmd(struct request_queue *q, ret = -EFAULT; } kfree(meta); - out_unmap: if (bio) blk_rq_unmap_user(bio); - out: blk_mq_free_request(req); return ret; } +static int nvme_submit_user_cmd(struct request_queue *q, + struct nvme_command *cmd, void __user *ubuffer, + unsigned bufflen, void __user *meta_buffer, unsigned meta_len, + u32 meta_seed, u64 *result, unsigned timeout, bool vec) +{ + struct request *req; + + req = nvme_alloc_user_request(q, cmd, ubuffer, bufflen, meta_buffer, + meta_len, meta_seed, timeout, vec); + if (IS_ERR(req)) + return PTR_ERR(req); + return nvme_execute_user_rq(req, meta_buffer, meta_len, result); +} static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) { -- 2.25.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
[parent not found: <CGME20220505061150epcas5p2b60880c541a4b2f144c348834c7cbf0b@epcas5p2.samsung.com>]
* [PATCH v4 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device. [not found] ` <CGME20220505061150epcas5p2b60880c541a4b2f144c348834c7cbf0b@epcas5p2.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi [not found] ` <[email protected]> 0 siblings, 1 reply; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev Introduce handler for fops->uring_cmd(), implementing async passthru on char device (/dev/ngX). The handler supports newly introduced operation NVME_URING_CMD_IO. This operates on a new structure nvme_uring_cmd, which is similar to struct nvme_passthru_cmd64 but without the embedded 8b result field. This field is not needed since uring-cmd allows to return additional result via big-CQE. Signed-off-by: Kanchan Joshi <[email protected]> Signed-off-by: Anuj Gupta <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> --- drivers/nvme/host/core.c | 1 + drivers/nvme/host/ioctl.c | 168 +++++++++++++++++++++++++++++++- drivers/nvme/host/multipath.c | 1 + drivers/nvme/host/nvme.h | 5 + include/uapi/linux/nvme_ioctl.h | 25 +++++ 5 files changed, 197 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e1846d04817f..682df98db341 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3699,6 +3699,7 @@ static const struct file_operations nvme_ns_chr_fops = { .release = nvme_ns_chr_release, .unlocked_ioctl = nvme_ns_chr_ioctl, .compat_ioctl = compat_ptr_ioctl, + .uring_cmd = nvme_ns_chr_uring_cmd, }; static int nvme_add_ns_cdev(struct nvme_ns *ns) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 3531de8073a6..3687cb8d7428 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -26,6 +26,80 @@ static inline void *nvme_meta_from_bio(struct bio *bio) return bip ? bvec_virt(bip->bip_vec) : NULL; } +/* + * This overlays struct io_uring_cmd pdu. + * Expect build errors if this grows larger than that. + */ +struct nvme_uring_cmd_pdu { + union { + struct bio *bio; + struct request *req; + }; + void *meta; /* kernel-resident buffer */ + void __user *meta_buffer; + u32 meta_len; +}; + +static inline struct nvme_uring_cmd_pdu *nvme_uring_cmd_pdu( + struct io_uring_cmd *ioucmd) +{ + return (struct nvme_uring_cmd_pdu *)&ioucmd->pdu; +} + +static void nvme_uring_task_cb(struct io_uring_cmd *ioucmd) +{ + struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd); + struct request *req = pdu->req; + struct bio *bio = req->bio; + bool write = req_op(req) == REQ_OP_DRV_OUT; + int status; + u64 result; + + if (nvme_req(req)->flags & NVME_REQ_CANCELLED) + status = -EINTR; + else + status = nvme_req(req)->status; + + result = le64_to_cpu(nvme_req(req)->result.u64); + blk_mq_free_request(req); + if (bio) + blk_rq_unmap_user(bio); + + if (pdu->meta && !status && !write) { + if (copy_to_user(pdu->meta_buffer, pdu->meta, pdu->meta_len)) + status = -EFAULT; + } + kfree(pdu->meta); + io_uring_cmd_done(ioucmd, status, result); +} + +static void nvme_end_async_pt(struct request *req, blk_status_t err) +{ + struct io_uring_cmd *ioucmd = req->end_io_data; + struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd); + /* extract bio before reusing the same field for request */ + struct bio *bio = pdu->bio; + + pdu->req = req; + req->bio = bio; + /* this takes care of moving rest of completion-work to task context */ + io_uring_cmd_complete_in_task(ioucmd, nvme_uring_task_cb); +} + +static void nvme_setup_uring_cmd_data(struct request *rq, + struct io_uring_cmd *ioucmd, void __user *meta_buffer, + u32 meta_len) +{ + struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd); + + /* to free bio on completion, as req->bio will be null at that time */ + pdu->bio = rq->bio; + pdu->meta = nvme_meta_from_bio(rq->bio); + pdu->meta_buffer = meta_buffer; + pdu->meta_len = meta_len; + rq->end_io_data = ioucmd; +} + static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, unsigned len, u32 seed, bool write) { @@ -63,7 +137,8 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, static struct request *nvme_alloc_user_request(struct request_queue *q, struct nvme_command *cmd, void __user *ubuffer, unsigned bufflen, void __user *meta_buffer, unsigned meta_len, - u32 meta_seed, unsigned timeout, bool vec) + u32 meta_seed, unsigned timeout, bool vec, unsigned int rq_flags, + blk_mq_req_flags_t blk_flags) { bool write = nvme_is_write(cmd); struct nvme_ns *ns = q->queuedata; @@ -73,7 +148,7 @@ static struct request *nvme_alloc_user_request(struct request_queue *q, void *meta = NULL; int ret; - req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0); + req = blk_mq_alloc_request(q, nvme_req_op(cmd) | rq_flags, blk_flags); if (IS_ERR(req)) return req; nvme_init_request(req, cmd); @@ -156,7 +231,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, struct request *req; req = nvme_alloc_user_request(q, cmd, ubuffer, bufflen, meta_buffer, - meta_len, meta_seed, timeout, vec); + meta_len, meta_seed, timeout, vec, 0, 0); if (IS_ERR(req)) return PTR_ERR(req); return nvme_execute_user_rq(req, meta_buffer, meta_len, result); @@ -333,6 +408,55 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns, return status; } +static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, + struct io_uring_cmd *ioucmd, unsigned int issue_flags) +{ + struct nvme_uring_cmd *cmd = + (struct nvme_uring_cmd *)ioucmd->cmd; + struct request_queue *q = ns ? ns->queue : ctrl->admin_q; + struct nvme_command c; + struct request *req; + unsigned int rq_flags = 0; + blk_mq_req_flags_t blk_flags = 0; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + if (cmd->flags) + return -EINVAL; + if (!nvme_validate_passthru_nsid(ctrl, ns, cmd->nsid)) + return -EINVAL; + + if (issue_flags & IO_URING_F_NONBLOCK) { + rq_flags = REQ_NOWAIT; + blk_flags = BLK_MQ_REQ_NOWAIT; + } + memset(&c, 0, sizeof(c)); + c.common.opcode = cmd->opcode; + c.common.flags = cmd->flags; + c.common.nsid = cpu_to_le32(cmd->nsid); + c.common.cdw2[0] = cpu_to_le32(cmd->cdw2); + c.common.cdw2[1] = cpu_to_le32(cmd->cdw3); + c.common.cdw10 = cpu_to_le32(cmd->cdw10); + c.common.cdw11 = cpu_to_le32(cmd->cdw11); + c.common.cdw12 = cpu_to_le32(cmd->cdw12); + c.common.cdw13 = cpu_to_le32(cmd->cdw13); + c.common.cdw14 = cpu_to_le32(cmd->cdw14); + c.common.cdw15 = cpu_to_le32(cmd->cdw15); + + req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(cmd->addr), + cmd->data_len, nvme_to_user_ptr(cmd->metadata), + cmd->metadata_len, 0, cmd->timeout_ms ? + msecs_to_jiffies(cmd->timeout_ms) : 0, 0, rq_flags, + blk_flags); + if (IS_ERR(req)) + return PTR_ERR(req); + + nvme_setup_uring_cmd_data(req, ioucmd, nvme_to_user_ptr(cmd->metadata), + cmd->metadata_len); + blk_execute_rq_nowait(req, 0, nvme_end_async_pt); + return -EIOCBQUEUED; +} + static bool is_ctrl_ioctl(unsigned int cmd) { if (cmd == NVME_IOCTL_ADMIN_CMD || cmd == NVME_IOCTL_ADMIN64_CMD) @@ -424,6 +548,32 @@ long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return __nvme_ioctl(ns, cmd, (void __user *)arg); } +static void nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd, + unsigned int issue_flags) +{ + int ret; + + BUILD_BUG_ON(sizeof(struct nvme_uring_cmd_pdu) > sizeof(ioucmd->pdu)); + + switch (ioucmd->cmd_op) { + case NVME_URING_CMD_IO: + ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, issue_flags); + break; + default: + ret = -ENOTTY; + } + + if (ret != -EIOCBQUEUED) + io_uring_cmd_done(ioucmd, ret, 0); +} + +void nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags) +{ + struct nvme_ns *ns = container_of(file_inode(ioucmd->file)->i_cdev, + struct nvme_ns, cdev); + nvme_ns_uring_cmd(ns, ioucmd, issue_flags); +} + #ifdef CONFIG_NVME_MULTIPATH static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd, void __user *argp, struct nvme_ns_head *head, int srcu_idx) @@ -490,6 +640,18 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, srcu_read_unlock(&head->srcu, srcu_idx); return ret; } +void nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd, + unsigned int issue_flags) +{ + struct cdev *cdev = file_inode(ioucmd->file)->i_cdev; + struct nvme_ns_head *head = container_of(cdev, struct nvme_ns_head, cdev); + int srcu_idx = srcu_read_lock(&head->srcu); + struct nvme_ns *ns = nvme_find_path(head); + + if (ns) + nvme_ns_uring_cmd(ns, ioucmd, issue_flags); + srcu_read_unlock(&head->srcu, srcu_idx); +} #endif /* CONFIG_NVME_MULTIPATH */ static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index d464fdf978fb..d3e2440d8abb 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -437,6 +437,7 @@ static const struct file_operations nvme_ns_head_chr_fops = { .release = nvme_ns_head_chr_release, .unlocked_ioctl = nvme_ns_head_chr_ioctl, .compat_ioctl = compat_ptr_ioctl, + .uring_cmd = nvme_ns_head_chr_uring_cmd, }; static int nvme_add_ns_head_cdev(struct nvme_ns_head *head) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index a2b53ca63335..761ad6c629c4 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -16,6 +16,7 @@ #include <linux/rcupdate.h> #include <linux/wait.h> #include <linux/t10-pi.h> +#include <linux/io_uring.h> #include <trace/events/block.h> @@ -782,6 +783,10 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg); long nvme_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +void nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd, + unsigned int issue_flags); +void nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd, + unsigned int issue_flags); int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo); extern const struct attribute_group *nvme_ns_id_attr_groups[]; diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h index b2e43185e3b5..04e458c649ab 100644 --- a/include/uapi/linux/nvme_ioctl.h +++ b/include/uapi/linux/nvme_ioctl.h @@ -70,6 +70,28 @@ struct nvme_passthru_cmd64 { __u64 result; }; +/* same as struct nvme_passthru_cmd64, minus the 8b result field */ +struct nvme_uring_cmd { + __u8 opcode; + __u8 flags; + __u16 rsvd1; + __u32 nsid; + __u32 cdw2; + __u32 cdw3; + __u64 metadata; + __u64 addr; + __u32 metadata_len; + __u32 data_len; + __u32 cdw10; + __u32 cdw11; + __u32 cdw12; + __u32 cdw13; + __u32 cdw14; + __u32 cdw15; + __u32 timeout_ms; + __u32 rsvd2; +}; + #define nvme_admin_cmd nvme_passthru_cmd #define NVME_IOCTL_ID _IO('N', 0x40) @@ -83,4 +105,7 @@ struct nvme_passthru_cmd64 { #define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct nvme_passthru_cmd64) #define NVME_IOCTL_IO64_CMD_VEC _IOWR('N', 0x49, struct nvme_passthru_cmd64) +/* io_uring async commands: */ +#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd) + #endif /* _UAPI_LINUX_NVME_IOCTL_H */ -- 2.25.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
[parent not found: <[email protected]>]
* Re: [PATCH v4 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device. [not found] ` <[email protected]> @ 2022-05-07 12:53 ` Jens Axboe 2022-05-09 6:00 ` Christoph Hellwig 0 siblings, 1 reply; 10+ messages in thread From: Jens Axboe @ 2022-05-07 12:53 UTC (permalink / raw) To: Christoph Hellwig Cc: Kanchan Joshi, io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev On 5/6/22 11:03 PM, Christoph Hellwig wrote: > Getting back to this after a good night's worth of sleep: > > On Fri, May 06, 2022 at 08:57:53AM -0600, Jens Axboe wrote: >>> Just add this: >>> >>> "Add a small helper to act as the counterpart to nvme_add_user_metadata." >>> >>> with my signoff: >>> >>> Signed-off-by: Christoph Hellwig <[email protected]> >> >> Both done, thanks. > > I think we're much better of folding "nvme: add nvme_finish_user_metadata > helper" into "nvme: refactor nvme_submit_user_cmd()" as the first basically > just redos the split done in the first patch in a more fine grained way > to allow sharing some of the metadata end I/O code with the uring path, > and basically only touches code changes in the first patch again. Yes good point, I've folded the two. >>>> I did not do your async_size changes, I think you're jetlagged eyes >>>> missed that this isn't a sizeof thing on a flexible array, it's just the >>>> offset of it. Hence for non-sqe128, the the async size is io_uring_sqe - >>>> offsetof where pdu starts, and so forth. >>> >>> Hmm, this still seems a bit odd to me. So without sqe128 you don't even >>> get the cmd data that would fit into the 64-bit SQE? >> >> You do. Without sqe128, you get sizeof(sqe) - offsetof(cmd) == 16 bytes. >> With, you get 16 + 64, 80. > > Can we please get a little documented helper that does this instead of > the two open coded places? How about we just add a comment? We use it in two spots, but one has knowledge of the sqe64 vs sqe128 state, the other one does not. Hence not sure how best to add a helper for this. One also must be a compile time constant. Best I can think of is the below. Not the prettiest, but it does keep it in one spot and with a single comment rather than in two spots. diff --git a/fs/io_uring.c b/fs/io_uring.c index 1860c50f7f8e..0a9b0fde55af 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1044,6 +1044,14 @@ struct io_cancel_data { int seq; }; +/* + * The URING_CMD payload starts at 'cmd' in the first sqe, and continues into + * the following sqe if SQE128 is used. + */ +#define uring_cmd_pdu_size(is_sqe128) \ + ((1 + !!(is_sqe128)) * sizeof(struct io_uring_sqe) - \ + offsetof(struct io_uring_sqe, cmd)) + struct io_op_def { /* needs req->file assigned */ unsigned needs_file : 1; @@ -1286,8 +1294,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_URING_CMD] = { .needs_file = 1, .plug = 1, - .async_size = 2 * sizeof(struct io_uring_sqe) - - offsetof(struct io_uring_sqe, cmd), + .async_size = uring_cmd_pdu_size(1), }, }; @@ -4947,11 +4954,9 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done); static int io_uring_cmd_prep_async(struct io_kiocb *req) { - size_t cmd_size = sizeof(struct io_uring_sqe) - - offsetof(struct io_uring_sqe, cmd); + size_t cmd_size; - if (req->ctx->flags & IORING_SETUP_SQE128) - cmd_size += sizeof(struct io_uring_sqe); + cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128); memcpy(req->async_data, req->uring_cmd.cmd, cmd_size); return 0; -- Jens Axboe ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device. 2022-05-07 12:53 ` Jens Axboe @ 2022-05-09 6:00 ` Christoph Hellwig 0 siblings, 0 replies; 10+ messages in thread From: Christoph Hellwig @ 2022-05-09 6:00 UTC (permalink / raw) To: Jens Axboe Cc: Christoph Hellwig, Kanchan Joshi, io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev On Sat, May 07, 2022 at 06:53:30AM -0600, Jens Axboe wrote: > How about we just add a comment? We use it in two spots, but one has > knowledge of the sqe64 vs sqe128 state, the other one does not. Hence > not sure how best to add a helper for this. One also must be a compile > time constant. Best I can think of is the below. Not the prettiest, but > it does keep it in one spot and with a single comment rather than in two > spots. If you think just a comment is better I can live with that, also the proposed macro also looks fine to me. ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20220505061151epcas5p2523dc661a0daf3e6185dee771eade393@epcas5p2.samsung.com>]
* [PATCH v4 5/5] nvme: add vectored-io support for uring-cmd [not found] ` <CGME20220505061151epcas5p2523dc661a0daf3e6185dee771eade393@epcas5p2.samsung.com> @ 2022-05-05 6:06 ` Kanchan Joshi 0 siblings, 0 replies; 10+ messages in thread From: Kanchan Joshi @ 2022-05-05 6:06 UTC (permalink / raw) To: axboe, hch Cc: io-uring, linux-nvme, asml.silence, ming.lei, mcgrof, shr, joshiiitr, anuj20.g, gost.dev From: Anuj Gupta <[email protected]> wire up support for async passthru that takes an array of buffers (using iovec). Exposed via a new op NVME_URING_CMD_IO_VEC. Same 'struct nvme_uring_cmd' is to be used with - 1. cmd.addr as base address of user iovec array 2. cmd.data_len as count of iovec array elements Signed-off-by: Kanchan Joshi <[email protected]> Signed-off-by: Anuj Gupta <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> --- drivers/nvme/host/ioctl.c | 10 +++++++--- include/uapi/linux/nvme_ioctl.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 3687cb8d7428..8c3b15d3e86d 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -409,7 +409,7 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns, } static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, - struct io_uring_cmd *ioucmd, unsigned int issue_flags) + struct io_uring_cmd *ioucmd, unsigned int issue_flags, bool vec) { struct nvme_uring_cmd *cmd = (struct nvme_uring_cmd *)ioucmd->cmd; @@ -446,7 +446,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(cmd->addr), cmd->data_len, nvme_to_user_ptr(cmd->metadata), cmd->metadata_len, 0, cmd->timeout_ms ? - msecs_to_jiffies(cmd->timeout_ms) : 0, 0, rq_flags, + msecs_to_jiffies(cmd->timeout_ms) : 0, vec, rq_flags, blk_flags); if (IS_ERR(req)) return PTR_ERR(req); @@ -557,7 +557,11 @@ static void nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd, switch (ioucmd->cmd_op) { case NVME_URING_CMD_IO: - ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, issue_flags); + ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, issue_flags, + false); + break; + case NVME_URING_CMD_IO_VEC: + ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, issue_flags, true); break; default: ret = -ENOTTY; diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h index 04e458c649ab..0b1876aa5a59 100644 --- a/include/uapi/linux/nvme_ioctl.h +++ b/include/uapi/linux/nvme_ioctl.h @@ -107,5 +107,6 @@ struct nvme_uring_cmd { /* io_uring async commands: */ #define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd) +#define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd) #endif /* _UAPI_LINUX_NVME_IOCTL_H */ -- 2.25.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-05-10 15:05 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <CGME20220505061142epcas5p2c943572766bfd5088138fe0f7873c96c@epcas5p2.samsung.com> 2022-05-05 6:06 ` [PATCH v4 0/5] io_uring passthrough for nvme Kanchan Joshi [not found] ` <CGME20220505061144epcas5p3821a9516dad2b5eff5a25c56dbe164df@epcas5p3.samsung.com> 2022-05-05 6:06 ` [PATCH v4 1/5] fs,io_uring: add infrastructure for uring-cmd Kanchan Joshi 2022-05-05 12:52 ` Jens Axboe [not found] ` <[email protected]> [not found] ` <CA+1E3r+airL_U0BzmLhiVPVkWdbiAXxxyHXONy9bGx4uuJFhdA@mail.gmail.com> 2022-05-10 14:35 ` Jens Axboe [not found] ` <CGME20220505061146epcas5p3919c48d58d353a62a5858ee10ad162a0@epcas5p3.samsung.com> 2022-05-05 6:06 ` [PATCH v4 2/5] block: wire-up support for passthrough plugging Kanchan Joshi [not found] ` <CGME20220505061148epcas5p188618b5b15a95cbe48c8c1559a18c994@epcas5p1.samsung.com> 2022-05-05 6:06 ` [PATCH v4 3/5] nvme: refactor nvme_submit_user_cmd() Kanchan Joshi [not found] ` <CGME20220505061150epcas5p2b60880c541a4b2f144c348834c7cbf0b@epcas5p2.samsung.com> 2022-05-05 6:06 ` [PATCH v4 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device Kanchan Joshi [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> [not found] ` <[email protected]> 2022-05-07 12:53 ` Jens Axboe 2022-05-09 6:00 ` Christoph Hellwig [not found] ` <CGME20220505061151epcas5p2523dc661a0daf3e6185dee771eade393@epcas5p2.samsung.com> 2022-05-05 6:06 ` [PATCH v4 5/5] nvme: add vectored-io support for uring-cmd Kanchan Joshi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox