From patchwork Fri Sep 23 09:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12986390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6D9CC6FA90 for ; Fri, 23 Sep 2022 09:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbiIWJmY (ORCPT ); Fri, 23 Sep 2022 05:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231793AbiIWJkp (ORCPT ); Fri, 23 Sep 2022 05:40:45 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8282C130BEE for ; Fri, 23 Sep 2022 02:39:22 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220923093919epoutp01a14e55473d4f0c0b0f827faa4190bfb1~Xc9gSwNMm1879018790epoutp01X for ; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220923093919epoutp01a14e55473d4f0c0b0f827faa4190bfb1~Xc9gSwNMm1879018790epoutp01X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663925959; bh=6HR7pDfEWCQApaFHaY1z8P5ClzoEBjIEJhDVePj5Z8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mS9huhtF8Icv35QDt3bH4RcrAy0tWjp3Vc25t5r5NQoVzxTch7jz42CNIl5NoBU+H qEER2AsvMVmFKXS0YKAwIIRcLbW8+TjY95QzMhfcvKoY6fQxG5axAnCoPfkC1YeQSf pvJSRNB4/GuXtYOJ7Jv/6TiW9oxK97iSG6lYUDh0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220923093918epcas5p432ce7e34fc24a4e400b382e903067bad~Xc9fqoljb0959609596epcas5p4F; Fri, 23 Sep 2022 09:39:18 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.178]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4MYnD32FSVz4x9Pq; Fri, 23 Sep 2022 09:39:15 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 42.34.26992.FBE7D236; Fri, 23 Sep 2022 18:39:11 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20220923093910epcas5p2624d93c6cb5caebb5f9203a1b8f4f5b1~Xc9YLx7H10642806428epcas5p2N; Fri, 23 Sep 2022 09:39:10 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220923093910epsmtrp2bae60d8f0d587a644ccb51b87a0ca903~Xc9YLBRyN1242312423epsmtrp2r; Fri, 23 Sep 2022 09:39:10 +0000 (GMT) X-AuditID: b6c32a49-0c7ff70000016970-32-632d7ebf4c8e Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 04.37.18644.EBE7D236; Fri, 23 Sep 2022 18:39:10 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220923093908epsmtip286d258d6baaf3a99162cb51a343e44c2~Xc9WiIe1N2720527205epsmtip26; Fri, 23 Sep 2022 09:39:08 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH for-next v8 1/5] io_uring: add io_uring_cmd_import_fixed Date: Fri, 23 Sep 2022 14:58:50 +0530 Message-Id: <20220923092854.5116-2-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220923092854.5116-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjk+LIzCtJLcpLzFFi42LZdlhTU3d/nW6ywaItshZNE/4yW6y+289m cfPATiaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06Py2dLPTat6mTz2Lyk3mP3 zQY2j74tqxg9Pm+SC2CLyrbJSE1MSS1SSM1Lzk/JzEu3VfIOjneONzUzMNQ1tLQwV1LIS8xN tVVy8QnQdcvMATpJSaEsMacUKBSQWFyspG9nU5RfWpKqkJFfXGKrlFqQklNgUqBXnJhbXJqX rpeXWmJlaGBgZApUmJCd8X/WTKaCVUIVL19/ZWpgnMvfxcjJISFgIvGl9xgriC0ksJtRYusX 7S5GLiD7E6PEy+7fzBDOZ0aJlrsvGWE6Dp5cDpXYxShxd+ZBVriq//c2snUxcnCwCWhKXJhc CtIgImAksf/TSbAaZpAVb280soPUCAt4SHxYaQdSwyKgKrGwZSIziM0rYC6x988tZohl8hIz L31nB7E5BSwkFm2+xQRRIyhxcuYTFhCbGaimeetssIMkBP6yS3w7MA+q2UVi950uNghbWOLV 8S3sELaUxOd3e6HiyRKXZp5jgrBLJB7vOQhl20u0nupnBrmTGeiX9bv0IXbxSfT+fsIEEpYQ 4JXoaBOCqFaUuDfpKSuELS7xcMYSKNtD4nbnWTZI8HQzSqz4/ZFpAqP8LCQvzELywiyEbQsY mVcxSqYWFOempxabFhjmpZbD4zU5P3cTIzhhannuYLz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/FCAumJJanZqakFqUUwWSYOTqkGJkkl /rDf/33Xvbpeuf0R/8b2RqNK6Ye8je1dyzbIZ1w6d2ae5bqgja+THadvz+jq5G6/aRGefL74 4h+B+K54/907lKX/Fn/WuSGRx3hgdrXThg17Ly132PXMI5GdOVApNvHHmsAClarpvCoZuR3J KfKR7np8Bm5mM1sTMt6GrFa8rrwg5rj5v+lb3l1Wu+igqhRx3XJ2b89eqYzFqU1pEx7P6nO9 tKtlfgSXBpNtrERQZ/vcV4x7JzAnrtyUYbXxbdCFP/M8vFZdyLjxreVMwHbFUsXkR1ZlfxN8 xR+Jb/h62SDU+m+GVhWn/cLHqQbmb2NPHCl5t2DmF543Aa5771csirl49twevVPdU67eVGIp zkg01GIuKk4EABl4Gh/lAgAA X-CMS-MailID: 20220923093910epcas5p2624d93c6cb5caebb5f9203a1b8f4f5b1 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220923093910epcas5p2624d93c6cb5caebb5f9203a1b8f4f5b1 References: <20220923092854.5116-1-joshi.k@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Anuj Gupta This is a new helper that callers can use to obtain a bvec iterator for the previously mapped buffer. This is preparatory work to enable fixed-buffer support for io_uring_cmd. Signed-off-by: Anuj Gupta Signed-off-by: Kanchan Joshi --- include/linux/io_uring.h | 8 ++++++++ io_uring/uring_cmd.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h index 58676c0a398f..1dbf51115c30 100644 --- a/include/linux/io_uring.h +++ b/include/linux/io_uring.h @@ -4,6 +4,7 @@ #include #include +#include enum io_uring_cmd_flags { IO_URING_F_COMPLETE_DEFER = 1, @@ -32,6 +33,8 @@ struct io_uring_cmd { }; #if defined(CONFIG_IO_URING) +int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, + struct iov_iter *iter, void *ioucmd); 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 *)); @@ -59,6 +62,11 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); } #else +static int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, + struct iov_iter *iter, void *ioucmd) +{ + return -EOPNOTSUPP; +} static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t ret2) { diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index f3ed61e9bd0f..6a6d69523d75 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -8,6 +8,7 @@ #include #include "io_uring.h" +#include "rsrc.h" #include "uring_cmd.h" static void io_uring_cmd_work(struct io_kiocb *req, bool *locked) @@ -129,3 +130,12 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags) return IOU_ISSUE_SKIP_COMPLETE; } + +int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, + struct iov_iter *iter, void *ioucmd) +{ + struct io_kiocb *req = cmd_to_io_kiocb(ioucmd); + + return io_import_fixed(rw, iter, req->imu, ubuf, len); +} +EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed); From patchwork Fri Sep 23 09:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12986388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BE61C6FA86 for ; Fri, 23 Sep 2022 09:42:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231754AbiIWJmW (ORCPT ); Fri, 23 Sep 2022 05:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbiIWJko (ORCPT ); Fri, 23 Sep 2022 05:40:44 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C928B12F754 for ; Fri, 23 Sep 2022 02:39:21 -0700 (PDT) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220923093920epoutp023e450ffb7cf4ceb17630e1a6331f1199~Xc9hQPP0O0758707587epoutp02k for ; Fri, 23 Sep 2022 09:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220923093920epoutp023e450ffb7cf4ceb17630e1a6331f1199~Xc9hQPP0O0758707587epoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663925960; bh=2f95MMw1JaP2a2qx6h2pgrT8vnSnYyP4Ul8WVop1exo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNmMuW+FxZa9oLjoPhVRbAv5Mrzh5GtlOznC/uCUwaObxPLh0qQf1X3twjwd/JURi zNWGZ/7OrpSjbUfBaHjDrndA1s2luxrZR60Iv3wo0Xmn2eQqXr4x6VGUc2FqQvXuSh dDpsQRrvjU7TnL1j8r9hahVS/nJBHYUnIL0EJPRc= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220923093919epcas5p44589eb00c12ab1e537feb4375df5b4fc~Xc9gxBMTY0422904229epcas5p4_; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.180]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4MYnD45cYPz4x9Pt; Fri, 23 Sep 2022 09:39:16 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 73.34.26992.2CE7D236; Fri, 23 Sep 2022 18:39:14 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220923093913epcas5p4d91766a750d6f5e87a1da0b92f6c4a2e~Xc9a4yphH0959609596epcas5p48; Fri, 23 Sep 2022 09:39:13 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220923093913epsmtrp125a3d7ed3ebdfb5432e7dd4b714f42eb~Xc9a4GpMB0923409234epsmtrp1W; Fri, 23 Sep 2022 09:39:13 +0000 (GMT) X-AuditID: b6c32a49-319fb70000016970-39-632d7ec28545 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id F5.37.18644.1CE7D236; Fri, 23 Sep 2022 18:39:13 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220923093911epsmtip2deed05ee44574274cd4d418bf7e5afdb~Xc9ZIsjTz2919729197epsmtip2E; Fri, 23 Sep 2022 09:39:11 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH for-next v8 2/5] io_uring: introduce fixed buffer support for io_uring_cmd Date: Fri, 23 Sep 2022 14:58:51 +0530 Message-Id: <20220923092854.5116-3-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220923092854.5116-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjk+LIzCtJLcpLzFFi42LZdlhTU/dQnW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IOX/5N02JpTgj 0VCLuag4EQBQMhzQ5QIAAA== X-CMS-MailID: 20220923093913epcas5p4d91766a750d6f5e87a1da0b92f6c4a2e X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220923093913epcas5p4d91766a750d6f5e87a1da0b92f6c4a2e References: <20220923092854.5116-1-joshi.k@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Anuj Gupta Add IORING_URING_CMD_FIXED flag that is to be used for sending io_uring command with previously registered buffers. User-space passes the buffer index in sqe->buf_index, same as done in read/write variants that uses fixed buffers. Signed-off-by: Anuj Gupta Signed-off-by: Kanchan Joshi --- include/linux/io_uring.h | 2 +- include/uapi/linux/io_uring.h | 9 +++++++++ io_uring/uring_cmd.c | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h index 1dbf51115c30..e10c5cc81082 100644 --- a/include/linux/io_uring.h +++ b/include/linux/io_uring.h @@ -28,7 +28,7 @@ struct io_uring_cmd { void *cookie; }; u32 cmd_op; - u32 pad; + u32 flags; u8 pdu[32]; /* available inline for free use */ }; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 92f29d9505a6..ab7458033ee3 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -56,6 +56,7 @@ struct io_uring_sqe { __u32 hardlink_flags; __u32 xattr_flags; __u32 msg_ring_flags; + __u32 uring_cmd_flags; }; __u64 user_data; /* data to be passed back at completion time */ /* pack this to avoid bogus arm OABI complaints */ @@ -219,6 +220,14 @@ enum io_uring_op { IORING_OP_LAST, }; +/* + * sqe->uring_cmd_flags + * IORING_URING_CMD_FIXED use registered buffer; pass thig flag + * along with setting sqe->buf_index. + */ +#define IORING_URING_CMD_FIXED (1U << 0) + + /* * sqe->fsync_flags */ diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 6a6d69523d75..faefa9f6f259 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -77,8 +78,21 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd); - if (sqe->rw_flags || sqe->__pad1) + if (sqe->__pad1) return -EINVAL; + + ioucmd->flags = READ_ONCE(sqe->uring_cmd_flags); + if (ioucmd->flags & IORING_URING_CMD_FIXED) { + struct io_ring_ctx *ctx = req->ctx; + u16 index; + + req->buf_index = READ_ONCE(sqe->buf_index); + if (unlikely(req->buf_index >= ctx->nr_user_bufs)) + return -EFAULT; + index = array_index_nospec(req->buf_index, ctx->nr_user_bufs); + req->imu = ctx->user_bufs[index]; + io_req_set_rsrc_node(req, ctx, 0); + } ioucmd->cmd = sqe->cmd; ioucmd->cmd_op = READ_ONCE(sqe->cmd_op); return 0; From patchwork Fri Sep 23 09:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12986389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B56E5C6FA91 for ; Fri, 23 Sep 2022 09:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231876AbiIWJmX (ORCPT ); Fri, 23 Sep 2022 05:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbiIWJko (ORCPT ); Fri, 23 Sep 2022 05:40:44 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826A8109622 for ; Fri, 23 Sep 2022 02:39:22 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220923093919epoutp01ac9a4a2288b1d4446302bfdff897b6f0~Xc9gtE8Qj2107421074epoutp01Z for ; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220923093919epoutp01ac9a4a2288b1d4446302bfdff897b6f0~Xc9gtE8Qj2107421074epoutp01Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663925959; bh=+wv6XISGnAc27o3rE7r/Fm0B0PE4UXnQUUZUaQQ4H7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEKqr+Az2MVYSLjVydyBbRKw2wZleI5+GoJhLAOToo0Dg/j1aLaEwvFc/NeF1gOmV /ftg3hU2N/PSw9IpvDnqnJ026SycVo/Q9LQKqpQK3jprOxnmnSepQXoAqHpEjIbMcz Qb5Zg5rXUfHx5CoH02DxEPD/9c+xW3DVdSc9iyFE= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20220923093919epcas5p1e33e36305ae05c5c4e89f27eb01723f6~Xc9gWNfva1518415184epcas5p1K; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.182]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4MYnD45hmrz4x9Pp; Fri, 23 Sep 2022 09:39:16 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 68.B5.39477.4CE7D236; Fri, 23 Sep 2022 18:39:16 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20220923093916epcas5p387fdd905413f6d90babecf5d14da5b67~Xc9duRmlY2720327203epcas5p34; Fri, 23 Sep 2022 09:39:16 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220923093916epsmtrp16311bc2cb438514028954b269d8a3f97~Xc9dsp7xm0923409234epsmtrp1e; Fri, 23 Sep 2022 09:39:16 +0000 (GMT) X-AuditID: b6c32a4a-007ff70000019a35-91-632d7ec40c7b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 97.37.18644.4CE7D236; Fri, 23 Sep 2022 18:39:16 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220923093914epsmtip23faffe90e51f735cce8bda46603e53c0~Xc9byj4JC2545425454epsmtip2L; Fri, 23 Sep 2022 09:39:14 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, Kanchan Joshi Subject: [PATCH for-next v8 3/5] nvme: refactor nvme_alloc_user_request Date: Fri, 23 Sep 2022 14:58:52 +0530 Message-Id: <20220923092854.5116-4-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220923092854.5116-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnk+LIzCtJLcpLzFFi42LZdlhTS/dInW6ywb7TOhar7/azWdw8sJPJ YuXqo0wW71rPsVgc/f+WzWLSoWuMFntvaVvMX/aU3YHD4/LZUo9NqzrZPDYvqffYfbOBzaNv yypGj8+b5ALYorJtMlITU1KLFFLzkvNTMvPSbZW8g+Od403NDAx1DS0tzJUU8hJzU22VXHwC dN0yc4CuUVIoS8wpBQoFJB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SvO6ROt1kg+2XhSxW3+1ns7h5YCeT xcrVR5ks3rWeY7E4+v8tm8WkQ9cYLfbe0raYv+wpuwOHx+WzpR6bVnWyeWxeUu+x+2YDm0ff llWMHp83yQWwRXHZpKTmZJalFunbJXBl3Pxznqmg0azic8MLtgbGX1pdjJwcEgImEq9OXGPv YuTiEBLYwSjxYt5xFoiEuETztR/sELawxMp/z6GKPjJKfD0+kbWLkYODTUBT4sLkUpAaEQEz iaWH17CA1DALzGGUuHx5D1izsIC7xO2JrcwgNouAqsTM/a+YQGxeAXOJ7v17GSEWyEvMvPQd rJ5TwEJi0eZbYDVCQDU/Lr1ghKgXlDg58wnYccxA9c1bZzNPYBSYhSQ1C0lqASPTKkbJ1ILi 3PTcYsMCo7zUcr3ixNzi0rx0veT83E2M4CDX0trBuGfVB71DjEwcjIcYJTiYlUR4Z9/RTBbi TUmsrEotyo8vKs1JLT7EKM3BoiTOe6HrZLyQQHpiSWp2ampBahFMlomDU6qBKXJV6ZFjHCkC dYsjpy/929Q950PsjlV6ymon2AVvPZVfvbxS5H3WUa7cBa2m0TvemWy2YJFPa1rcZOQgoPtb 67x8h5qHnGfiwa/5LyuqxLa+/9Oo7z6ntuRSYzPvvr2X5293Y7r/1PGepSqHjvr+DadWye/O Mtl1b3ZJaERap43DI6mKROcd/ewi89s/Kcs/3BqcW5a9ozLkZ+U1cy/9b9ISchzHs6a2G0WH 6N4PYL4vs12Vawv7jeJetVeHmj0XPlZRLI+KWRIstOX5wlTXeonUcAYxM6ZzPyvuz3/ZdVPV XO4u+6aImTYvq1tfbV/bVbz4nvRr9hL9yg9HdFbtOaPi8erNi0NvRVMETs5RYinOSDTUYi4q TgQAZP0ATOECAAA= X-CMS-MailID: 20220923093916epcas5p387fdd905413f6d90babecf5d14da5b67 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220923093916epcas5p387fdd905413f6d90babecf5d14da5b67 References: <20220923092854.5116-1-joshi.k@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Separate this out to two functions with reduced number of arguments. While at it, do bit of refactoring in nvme_add_user_metadata too. diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 548aca8b5b9f..9537991deac9 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -20,19 +20,20 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval) return (void __user *)ptrval; } -static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, - unsigned len, u32 seed, bool write) +static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, + unsigned len, u32 seed) { struct bio_integrity_payload *bip; int ret = -ENOMEM; void *buf; + struct bio *bio = req->bio; buf = kmalloc(len, GFP_KERNEL); if (!buf) goto out; ret = -EFAULT; - if (write && copy_from_user(buf, ubuf, len)) + if ((req_op(req) == REQ_OP_DRV_OUT) && copy_from_user(buf, ubuf, len)) goto out_free_meta; bip = bio_integrity_alloc(bio, GFP_KERNEL, 1); @@ -45,8 +46,10 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, bip->bip_iter.bi_sector = seed; ret = bio_integrity_add_page(bio, virt_to_page(buf), len, offset_in_page(buf)); - if (ret == len) + if (ret == len) { + req->cmd_flags |= REQ_INTEGRITY; return buf; + } ret = -ENOMEM; out_free_meta: kfree(buf); @@ -65,70 +68,67 @@ static int nvme_finish_user_metadata(struct request *req, 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, void **metap, unsigned timeout, bool vec, - blk_opf_t rq_flags, blk_mq_req_flags_t blk_flags) + struct nvme_command *cmd, blk_opf_t rq_flags, + blk_mq_req_flags_t blk_flags) { - bool write = nvme_is_write(cmd); - struct nvme_ns *ns = q->queuedata; - struct block_device *bdev = ns ? ns->disk->part0 : NULL; struct request *req; - struct bio *bio = NULL; - void *meta = NULL; - int ret; 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); - - if (timeout) - req->timeout = timeout; nvme_req(req)->flags |= NVME_REQ_USERCMD; + return req; +} - if (ubuffer && bufflen) { - if (!vec) - ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, - GFP_KERNEL); - else { - struct iovec fast_iov[UIO_FASTIOV]; - struct iovec *iov = fast_iov; - struct iov_iter iter; - - ret = import_iovec(rq_data_dir(req), ubuffer, bufflen, - UIO_FASTIOV, &iov, &iter); - if (ret < 0) - goto out; - ret = blk_rq_map_user_iov(q, req, NULL, &iter, - GFP_KERNEL); - kfree(iov); - } - if (ret) +static int nvme_map_user_request(struct request *req, void __user *ubuffer, + unsigned bufflen, void __user *meta_buffer, unsigned meta_len, + u32 meta_seed, void **metap, bool vec) +{ + struct request_queue *q = req->q; + struct nvme_ns *ns = q->queuedata; + struct block_device *bdev = ns ? ns->disk->part0 : NULL; + struct bio *bio = NULL; + void *meta = NULL; + int ret; + + if (!vec) + ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, + GFP_KERNEL); + else { + struct iovec fast_iov[UIO_FASTIOV]; + struct iovec *iov = fast_iov; + struct iov_iter iter; + + ret = import_iovec(rq_data_dir(req), ubuffer, bufflen, + UIO_FASTIOV, &iov, &iter); + if (ret < 0) goto out; - bio = req->bio; - if (bdev) - bio_set_dev(bio, bdev); - if (bdev && meta_buffer && meta_len) { - meta = nvme_add_user_metadata(bio, meta_buffer, meta_len, - meta_seed, write); - if (IS_ERR(meta)) { - ret = PTR_ERR(meta); - goto out_unmap; - } - req->cmd_flags |= REQ_INTEGRITY; - *metap = meta; + ret = blk_rq_map_user_iov(q, req, NULL, &iter, GFP_KERNEL); + kfree(iov); + } + if (ret) + goto out; + bio = req->bio; + if (bdev) + bio_set_dev(bio, bdev); + if (bdev && meta_buffer && meta_len) { + meta = nvme_add_user_metadata(req, meta_buffer, meta_len, + meta_seed); + if (IS_ERR(meta)) { + ret = PTR_ERR(meta); + goto out_unmap; } + *metap = meta; } - return req; + return ret; out_unmap: if (bio) blk_rq_unmap_user(bio); out: - blk_mq_free_request(req); - return ERR_PTR(ret); + return ret; } static int nvme_submit_user_cmd(struct request_queue *q, @@ -141,13 +141,19 @@ static int nvme_submit_user_cmd(struct request_queue *q, struct bio *bio; int ret; - req = nvme_alloc_user_request(q, cmd, ubuffer, bufflen, meta_buffer, - meta_len, meta_seed, &meta, timeout, vec, 0, 0); + req = nvme_alloc_user_request(q, cmd, 0, 0); if (IS_ERR(req)) return PTR_ERR(req); - bio = req->bio; + req->timeout = timeout; + if (ubuffer && bufflen) { + ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer, + meta_len, meta_seed, &meta, vec); + if (ret) + goto out; + } + bio = req->bio; ret = nvme_execute_passthru_rq(req); if (result) @@ -157,6 +163,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, meta_len, ret); if (bio) blk_rq_unmap_user(bio); +out: blk_mq_free_request(req); return ret; } @@ -418,6 +425,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, blk_opf_t rq_flags = 0; blk_mq_req_flags_t blk_flags = 0; void *meta = NULL; + int ret; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -457,13 +465,18 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, rq_flags |= REQ_POLLED; retry: - req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(d.addr), - d.data_len, nvme_to_user_ptr(d.metadata), - d.metadata_len, 0, &meta, d.timeout_ms ? - msecs_to_jiffies(d.timeout_ms) : 0, vec, rq_flags, - blk_flags); + req = nvme_alloc_user_request(q, &c, rq_flags, blk_flags); if (IS_ERR(req)) return PTR_ERR(req); + req->timeout = d.timeout_ms ? msecs_to_jiffies(d.timeout_ms) : 0; + + if (d.addr && d.data_len) { + ret = nvme_map_user_request(req, nvme_to_user_ptr(d.addr), + d.data_len, nvme_to_user_ptr(d.metadata), + d.metadata_len, 0, &meta, vec); + if (ret) + goto out_err; + } req->end_io = nvme_uring_cmd_end_io; req->end_io_data = ioucmd; @@ -486,6 +499,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, blk_execute_rq_nowait(req, false); return -EIOCBQUEUED; +out_err: + blk_mq_free_request(req); + return ret; } static bool is_ctrl_ioctl(unsigned int cmd) From patchwork Fri Sep 23 09:28:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12986391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0CDBC6FA93 for ; Fri, 23 Sep 2022 09:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbiIWJm0 (ORCPT ); Fri, 23 Sep 2022 05:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbiIWJkp (ORCPT ); Fri, 23 Sep 2022 05:40:45 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7E39130BF1 for ; Fri, 23 Sep 2022 02:39:25 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220923093924epoutp036e7609c0ac62be3767e95551a3c6c182~Xc9lJvHq-2876528765epoutp03R for ; Fri, 23 Sep 2022 09:39:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220923093924epoutp036e7609c0ac62be3767e95551a3c6c182~Xc9lJvHq-2876528765epoutp03R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663925964; bh=ONWjb8pj4oI1GKHd8OT2dD1nbK8wwvhuhUNQrEIxjyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbkxbeSYXHOmgPMIPi55SqZ2QEci/jZDmC7o4v+PT638CZYcgPS9G/q1ART40a6xi chCbL7fc26DTeH0LvsDwQNOE8inDlL871YKMWvaP8ES1Btu05mF41r6rUw3VROnpkE Bsx3gPj5Zeit82lTuywxsKzeX2ZRcaYFwbUWOWHk= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20220923093923epcas5p11296e5e2f9d8d67fdabec642bc824d08~Xc9j97ed_1642216422epcas5p1R; Fri, 23 Sep 2022 09:39:23 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.175]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4MYnD775nbz4x9Px; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 6A.B1.56352.7CE7D236; Fri, 23 Sep 2022 18:39:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20220923093919epcas5p3d019fa1db990101478b8d6673ac0eaa6~Xc9gnKs1e3163431634epcas5p3a; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220923093919epsmtrp2de633a6b235faa6f39e7ac3052b9e932~Xc9gmL5Nl1234812348epsmtrp2B; Fri, 23 Sep 2022 09:39:19 +0000 (GMT) X-AuditID: b6c32a4b-383ff7000001dc20-eb-632d7ec7f0a7 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id EE.FC.14392.7CE7D236; Fri, 23 Sep 2022 18:39:19 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220923093917epsmtip2335f5313b422d05c042b329f3d1477e8~Xc9fFAO-X2705727057epsmtip29; Fri, 23 Sep 2022 09:39:17 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, Kanchan Joshi , Anuj Gupta Subject: [PATCH for-next v8 4/5] block: add helper to map bvec iterator for passthrough Date: Fri, 23 Sep 2022 14:58:53 +0530 Message-Id: <20220923092854.5116-5-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220923092854.5116-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjk+LIzCtJLcpLzFFi42LZdlhTQ/d4nW6ywa1DFhZNE/4yW6y+289m cfPATiaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06Py2dLPTat6mTz2Lyk3mP3 zQY2j74tqxg9Pm+SC2CLyrbJSE1MSS1SSM1Lzk/JzEu3VfIOjneONzUzMNQ1tLQwV1LIS8xN tVVy8QnQdcvMATpJSaEsMacUKBSQWFyspG9nU5RfWpKqkJFfXGKrlFqQklNgUqBXnJhbXJqX rpeXWmJlaGBgZApUmJCdMeVlM1PBWvWKaQdfsDcwLpHvYuTkkBAwkVhw6x0riC0ksJtR4utC ri5GLiD7E6NEz/kJTBDON0aJzu/32WE6tjfMYoZI7GWU2PThLgtE+2dGicubYrsYOTjYBDQl LkwuBQmLCBhJ7P90khWknhlkw+q/b8HWCQtESizs+8wEYrMIqEqc33OcGcTmFTCXeHp2AT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kYODTUBT4sLk UpAaEQEziaWH17CA1DALHGSUON/0jQUkISwQLnH88A4mEJtFQFXi/J7jzCA2r4C5xNOzC5gh FshLzLz0HWwZp4CFxKLNt8DqhYBqflx6wQhRLyhxcuYTsJnMQPXNW2czT2AUmIUkNQtJagEj 0ypGydSC4tz03GLDAsO81HK94sTc4tK8dL3k/NxNjOBw19Lcwbh91Qe9Q4xMHIyHGCU4mJVE eGff0UwW4k1JrKxKLcqPLyrNSS0+xCjNwaIkznuh62S8kEB6YklqdmpqQWoRTJaJg1OqgWmS R81W02MJK/5dYvOJnMvV5+l0k9XdY+kvjZjl2t7LM5c575C6NjXX9Jr/rVrvU2vlbTR1m8O2 TU7K4yldO/+EFU/K7VVMVkKCKeal2m5MDvdeBzBt9dhyivNl12ULhodW5/I2MRW0Zci+O13f npnx7/Lvj6rWX9f3sbefjf35PWT6a2n2Za0M3ic+uX3ZKcOrwy4RpWXT/8x/v/XcStl3XhK7 j3REGmRn5+9dquMxLTbZX5TV8cvSI2FyG68t4jA+d9XywTrtLac/r/lVv+1qlGeXsPTfEx9W bYpL+bosxjTxe02s9veSrKe1d7ZyL5VM5FkZGzt90XamlMS90cr1Kw1fJR0v/nLN/7xVrhJL cUaioRZzUXEiABrJlgbmAgAA X-CMS-MailID: 20220923093919epcas5p3d019fa1db990101478b8d6673ac0eaa6 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220923093919epcas5p3d019fa1db990101478b8d6673ac0eaa6 References: <20220923092854.5116-1-joshi.k@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add blk_rq_map_user_bvec which maps the bvec iterator into a bio and places that into the request. This helper will be used in nvme for uring-passthrough with fixed-buffer. While at it, create another helper bio_map_get to reduce the code duplication. Signed-off-by: Kanchan Joshi Signed-off-by: Anuj Gupta --- block/blk-map.c | 111 +++++++++++++++++++++++++++++++++++++---- include/linux/blk-mq.h | 1 + 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 7693f8e3c454..d6265d49b15b 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -241,17 +241,10 @@ static void bio_map_put(struct bio *bio) } } -static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, +static struct bio *bio_map_get(struct request *rq, unsigned int nr_vecs, gfp_t gfp_mask) { - unsigned int max_sectors = queue_max_hw_sectors(rq->q); - unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS); struct bio *bio; - int ret; - int j; - - if (!iov_iter_count(iter)) - return -EINVAL; if (rq->cmd_flags & REQ_POLLED) { blk_opf_t opf = rq->cmd_flags | REQ_ALLOC_CACHE; @@ -259,13 +252,31 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, bio = bio_alloc_bioset(NULL, nr_vecs, opf, gfp_mask, &fs_bio_set); if (!bio) - return -ENOMEM; + return NULL; } else { bio = bio_kmalloc(nr_vecs, gfp_mask); if (!bio) - return -ENOMEM; + return NULL; bio_init(bio, NULL, bio->bi_inline_vecs, nr_vecs, req_op(rq)); } + return bio; +} + +static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, + gfp_t gfp_mask) +{ + unsigned int max_sectors = queue_max_hw_sectors(rq->q); + unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS); + struct bio *bio; + int ret; + int j; + + if (!iov_iter_count(iter)) + return -EINVAL; + + bio = bio_map_get(rq, nr_vecs, gfp_mask); + if (bio == NULL) + return -ENOMEM; while (iov_iter_count(iter)) { struct page **pages, *stack_pages[UIO_FASTIOV]; @@ -611,6 +622,86 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq, } EXPORT_SYMBOL(blk_rq_map_user); +/* Prepare bio for passthrough IO given an existing bvec iter */ +int blk_rq_map_user_bvec(struct request *rq, struct iov_iter *iter) +{ + struct request_queue *q = rq->q; + size_t nr_iter, nr_segs, i; + struct bio *bio = NULL; + struct bio_vec *bv, *bvecs, *bvprvp = NULL; + struct queue_limits *lim = &q->limits; + unsigned int nsegs = 0, bytes = 0; + bool copy = false; + int ret; + unsigned long align = q->dma_pad_mask | queue_dma_alignment(q); + + /* see if we need to copy pages due to any weird situation */ + if (blk_queue_may_bounce(q)) + copy = true; + else if (iov_iter_alignment(iter) & align) + copy = true; + + if (copy) { + do { + ret = bio_copy_user_iov(rq, NULL, iter, GFP_KERNEL); + if (ret) { + blk_rq_unmap_user(bio); + rq->bio = NULL; + break; + } + if (!bio) + bio = rq->bio; + } while (iov_iter_count(iter)); + + return ret; + } + /* common (non-copy) case handling */ + nr_iter = iov_iter_count(iter); + nr_segs = iter->nr_segs; + + if (!nr_iter || (nr_iter >> SECTOR_SHIFT) > queue_max_hw_sectors(q)) + return -EINVAL; + if (nr_segs > queue_max_segments(q)) + return -EINVAL; + + /* no iovecs to alloc, as we already have a BVEC iterator */ + bio = bio_map_get(rq, 0, GFP_KERNEL); + if (bio == NULL) + return -ENOMEM; + + bio_iov_bvec_set(bio, iter); + blk_rq_bio_prep(rq, bio, nr_segs); + + /* loop to perform a bunch of sanity checks */ + bvecs = (struct bio_vec *)iter->bvec; + for (i = 0; i < nr_segs; i++) { + bv = &bvecs[i]; + /* + * If the queue doesn't support SG gaps and adding this + * offset would create a gap, disallow it. + */ + if (bvprvp && bvec_gap_to_prev(lim, bvprvp, bv->bv_offset)) + goto put_bio; + + /* check full condition */ + if (nsegs >= nr_segs || bytes > UINT_MAX - bv->bv_len) + goto put_bio; + if (bytes + bv->bv_len > nr_iter) + goto put_bio; + if (bv->bv_offset + bv->bv_len > PAGE_SIZE) + goto put_bio; + + nsegs++; + bytes += bv->bv_len; + bvprvp = bv; + } + return 0; +put_bio: + bio_map_put(bio); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(blk_rq_map_user_bvec); + /** * blk_rq_unmap_user - unmap a request with user data * @bio: start of bio list diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 00a15808c137..1a9ae17e49be 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -977,6 +977,7 @@ struct rq_map_data { bool from_user; }; +int blk_rq_map_user_bvec(struct request *rq, struct iov_iter *iter); int blk_rq_map_user(struct request_queue *, struct request *, struct rq_map_data *, void __user *, unsigned long, gfp_t); int blk_rq_map_user_iov(struct request_queue *, struct request *, From patchwork Fri Sep 23 09:28:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12986392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70FEBECAAD8 for ; Fri, 23 Sep 2022 09:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231838AbiIWJm1 (ORCPT ); Fri, 23 Sep 2022 05:42:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231819AbiIWJkq (ORCPT ); Fri, 23 Sep 2022 05:40:46 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01356C38 for ; Fri, 23 Sep 2022 02:39:28 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220923093927epoutp023285d1a2fd8b06938274e25fc09ebf34~Xc9oC86lV0967509675epoutp02k for ; Fri, 23 Sep 2022 09:39:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220923093927epoutp023285d1a2fd8b06938274e25fc09ebf34~Xc9oC86lV0967509675epoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663925967; bh=uEbCqf/3/kIIaWvtuL4qPxWr9CHf3MDamuEGmk0zZZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XkWUI0K/JW40PJ5otFzQ5KU4KAkw4Z/24yLJ+n7zlgxf/S6u9/FjoBO+3YpGxL9IJ DtoXhTlXAJxBvJH6gOx3BZ650mbEzmxav8E7+ukPXVUEMnnUy7luthcGB+IPOUgSFD Dh0/motGMUXkIrdye9OPoqmyGt9AWwWKILwR8cQw= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220923093927epcas5p47affb341ee557ba0ce3e17b7614b8d58~Xc9nn2iy30959609596epcas5p4M; Fri, 23 Sep 2022 09:39:27 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.181]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4MYnDD2wn8z4x9Q1; Fri, 23 Sep 2022 09:39:24 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0E.B5.39477.CCE7D236; Fri, 23 Sep 2022 18:39:24 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20220923093924epcas5p1e1723a3937cb3331c77e55bd1a785e57~Xc9kyfmUH1084110841epcas5p1I; Fri, 23 Sep 2022 09:39:24 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220923093924epsmtrp2e167e498a3f7e874623eb5580b477445~Xc9kxwzQ61242312423epsmtrp27; Fri, 23 Sep 2022 09:39:24 +0000 (GMT) X-AuditID: b6c32a4a-007ff70000019a35-ad-632d7eccee18 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 89.37.18644.BCE7D236; Fri, 23 Sep 2022 18:39:23 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220923093921epsmtip2e025e3a47044e60cae35a5009e6eb30b~Xc9iyekxE2705227052epsmtip2a; Fri, 23 Sep 2022 09:39:21 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, Kanchan Joshi Subject: [PATCH for-next v8 5/5] nvme: wire up fixed buffer support for nvme passthrough Date: Fri, 23 Sep 2022 14:58:54 +0530 Message-Id: <20220923092854.5116-6-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220923092854.5116-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupik+LIzCtJLcpLzFFi42LZdlhTQ/dMnW6ywZelohar7/azWdw8sJPJ YuXqo0wW71rPsVgc/f+WzWLSoWuMFntvaVvMX/aU3YHD4/LZUo9NqzrZPDYvqffYfbOBzaNv yypGj8+b5ALYorJtMlITU1KLFFLzkvNTMvPSbZW8g+Od403NDAx1DS0tzJUU8hJzU22VXHwC dN0yc4CuUVIoS8wpBQoFJBYXK+nb2RTll5akKmTkF5fYKqUWpOQUmBToFSfmFpfmpevlpZZY GRoYGJkCFSZkZ6zdfoypYKFyRePiL2wNjLdkuhg5OSQETCTuHF/C2MXIxSEksJtRYsnOPSwQ zidGiU/btzJBOJ8ZJU6cfswI0zJx0npmiMQuRommw9uZ4apOf28GauHgYBPQlLgwuRSkQUTA SGL/p5OsIDXMAjMYJVZ3vGYHSQgLREm8mfCUCcRmEVCV+LXrNiuIzStgLvF+yiw2iG3yEjMv fQer5xSwkFi0+RYTRI2gxMmZT1hAbGagmuats5kh6n+yS8x+7w5hu0h8f7SGCcIWlnh1fAs7 hC0l8fndXqj5yRKXZp6Dq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cuYTsNuYgeqbt85mnsAoMAtJahaS1AJGplWMkqkF xbnpucWGBUZ5qeV6xYm5xaV56XrJ+bmbGMEhrqW1g3HPqg96hxiZOBgPMUpwMCuJ8M6+o5ks xJuSWFmVWpQfX1Sak1p8iFGag0VJnPdC18l4IYH0xJLU7NTUgtQimCwTB6dUAxNTyRHl31Nm LXO8WvhzQthW7YVigdMUC8szX0y+2+sZ9sH53BuGQDWN7W9N3ea0n1nDPnXW0ZWdTzK4Nx71 2bIkmolTyM66d4bnYoEb3Xe8lnDmSL417HkVumTyBKHn6hkyvAxMsjKHAlN0dn049fFTmsk3 1suW2Rull6XlpQjZ+bHx2nNde1fNVMjncTT/wIWGE1Fqm4xfn3hp6HHm3YMLNqsYvAM7u1bE Ttl16tbNX8o/QhVS24/d4LZcdGDX8c0f9XnObvv+0Kf09JP/m6Sedy67cU0xoPs1tz7DPKcb E43vd+j6hm803967mu/3QsH/f5gD0r4LWrsyS7/747Dh6rM7LzcoF4XmqQhsXW6hxFKckWio xVxUnAgACarZSOACAAA= X-CMS-MailID: 20220923093924epcas5p1e1723a3937cb3331c77e55bd1a785e57 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220923093924epcas5p1e1723a3937cb3331c77e55bd1a785e57 References: <20220923092854.5116-1-joshi.k@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org if io_uring sends passthrough command with IORING_URING_CMD_FIXED flag, use the pre-registered buffer to form the bio. While at it, modify nvme_submit_user_cmd to take ubuffer as plain integer argument, and do away with nvme_to_user_ptr conversion in callers. Signed-off-by: Kanchan Joshi --- drivers/nvme/host/ioctl.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 9537991deac9..0464a89c8f5a 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -81,9 +81,10 @@ static struct request *nvme_alloc_user_request(struct request_queue *q, return req; } -static int nvme_map_user_request(struct request *req, void __user *ubuffer, +static int nvme_map_user_request(struct request *req, u64 ubuffer, unsigned bufflen, void __user *meta_buffer, unsigned meta_len, - u32 meta_seed, void **metap, bool vec) + u32 meta_seed, void **metap, struct io_uring_cmd *ioucmd, + bool vec) { struct request_queue *q = req->q; struct nvme_ns *ns = q->queuedata; @@ -91,17 +92,29 @@ static int nvme_map_user_request(struct request *req, void __user *ubuffer, struct bio *bio = NULL; void *meta = NULL; int ret; + bool fixedbufs = ioucmd && (ioucmd->flags & IORING_URING_CMD_FIXED); if (!vec) - ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, - GFP_KERNEL); + if (!fixedbufs) + ret = blk_rq_map_user(q, req, NULL, + nvme_to_user_ptr(ubuffer), bufflen, + GFP_KERNEL); + else { + struct iov_iter iter; + + ret = io_uring_cmd_import_fixed(ubuffer, bufflen, + rq_data_dir(req), &iter, ioucmd); + if (ret < 0) + goto out; + ret = blk_rq_map_user_bvec(req, &iter); + } else { struct iovec fast_iov[UIO_FASTIOV]; struct iovec *iov = fast_iov; struct iov_iter iter; - ret = import_iovec(rq_data_dir(req), ubuffer, bufflen, - UIO_FASTIOV, &iov, &iter); + ret = import_iovec(rq_data_dir(req), nvme_to_user_ptr(ubuffer), + bufflen, UIO_FASTIOV, &iov, &iter); if (ret < 0) goto out; ret = blk_rq_map_user_iov(q, req, NULL, &iter, GFP_KERNEL); @@ -132,7 +145,7 @@ static int nvme_map_user_request(struct request *req, void __user *ubuffer, } static int nvme_submit_user_cmd(struct request_queue *q, - struct nvme_command *cmd, void __user *ubuffer, + struct nvme_command *cmd, u64 ubuffer, unsigned bufflen, void __user *meta_buffer, unsigned meta_len, u32 meta_seed, u64 *result, unsigned timeout, bool vec) { @@ -148,7 +161,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, req->timeout = timeout; if (ubuffer && bufflen) { ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer, - meta_len, meta_seed, &meta, vec); + meta_len, meta_seed, &meta, NULL, vec); if (ret) goto out; } @@ -227,7 +240,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) c.rw.appmask = cpu_to_le16(io.appmask); return nvme_submit_user_cmd(ns->queue, &c, - nvme_to_user_ptr(io.addr), length, + io.addr, length, metadata, meta_len, lower_32_bits(io.slba), NULL, 0, false); } @@ -281,7 +294,7 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns, timeout = msecs_to_jiffies(cmd.timeout_ms); status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c, - nvme_to_user_ptr(cmd.addr), cmd.data_len, + cmd.addr, cmd.data_len, nvme_to_user_ptr(cmd.metadata), cmd.metadata_len, 0, &result, timeout, false); @@ -327,7 +340,7 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns, timeout = msecs_to_jiffies(cmd.timeout_ms); status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c, - nvme_to_user_ptr(cmd.addr), cmd.data_len, + cmd.addr, cmd.data_len, nvme_to_user_ptr(cmd.metadata), cmd.metadata_len, 0, &cmd.result, timeout, vec); @@ -471,9 +484,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, req->timeout = d.timeout_ms ? msecs_to_jiffies(d.timeout_ms) : 0; if (d.addr && d.data_len) { - ret = nvme_map_user_request(req, nvme_to_user_ptr(d.addr), + ret = nvme_map_user_request(req, d.addr, d.data_len, nvme_to_user_ptr(d.metadata), - d.metadata_len, 0, &meta, vec); + d.metadata_len, 0, &meta, ioucmd, vec); if (ret) goto out_err; }