From patchwork Fri Sep 9 10:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12971473 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 01009ECAAD3 for ; Fri, 9 Sep 2022 10:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbiIIKbu (ORCPT ); Fri, 9 Sep 2022 06:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbiIIKbs (ORCPT ); Fri, 9 Sep 2022 06:31:48 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24E8B49B5E for ; Fri, 9 Sep 2022 03:31:43 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220909103140epoutp031243c6b2750297315e4e3bcd0a6a1dee~TKpOb9Rcf1780517805epoutp03p for ; Fri, 9 Sep 2022 10:31:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220909103140epoutp031243c6b2750297315e4e3bcd0a6a1dee~TKpOb9Rcf1780517805epoutp03p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662719500; bh=6HR7pDfEWCQApaFHaY1z8P5ClzoEBjIEJhDVePj5Z8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Op1vqTEOQ3+FmH6OUxYfYFXzocDXCwNpPHKAAXJrh5EPhTpNVPdd+ppJfOoo8UW+H xjtyWwA6rGvFzjqABvWG8U+Iw1P3djvttdiXwWP2t50GhK00bpiqD+ChnC9uVBm03p 1HxVkrVreI3TLeaV1BeCnPbgF9loya3KszXYEC2U= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20220909103140epcas5p2371303ab561b508bde5501e32d028c26~TKpNxjnUM0262302623epcas5p29; Fri, 9 Sep 2022 10:31:40 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.174]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4MPC2x4W2pz4x9Pr; Fri, 9 Sep 2022 10:31:37 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 70.E6.54060.8061B136; Fri, 9 Sep 2022 19:31:36 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20220909103136epcas5p38ea3a933e90d9f9d7451848dc3a60829~TKpJ8Miwn0111801118epcas5p3F; Fri, 9 Sep 2022 10:31:36 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220909103136epsmtrp26702fdbfbf713f153a92cc867912fca9~TKpJ7UWau1218912189epsmtrp2J; Fri, 9 Sep 2022 10:31:36 +0000 (GMT) X-AuditID: b6c32a4b-be1ff7000000d32c-7d-631b160811f8 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 22.61.14392.7061B136; Fri, 9 Sep 2022 19:31:35 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220909103134epsmtip177a23b114855293c91cfba5ac5b52f46~TKpIIYZwN1204612046epsmtip1Y; Fri, 9 Sep 2022 10:31:34 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, asml.silence@gmail.com 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 v7 1/5] io_uring: add io_uring_cmd_import_fixed Date: Fri, 9 Sep 2022 15:51:32 +0530 Message-Id: <20220909102136.3020-2-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909102136.3020-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFJsWRmVeSWpSXmKPExsWy7bCmli6HmHSywd5rchZNE/4yW8xZtY3R YvXdfjaLmwd2MlmsXH2UyeJd6zkWi6P/37JZTDp0jdFi7y1ti/nLnrI7cHnsnHWX3ePy2VKP Tas62Tw2L6n32H2zgc2jb8sqRo/Pm+QC2KOybTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwM dQ0tLcyVFPISc1NtlVx8AnTdMnOAjlNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CqlFqTk FJgU6BUn5haX5qXr5aWWWBkaGBiZAhUmZGf8nzWTqWCVUMXL11+ZGhjn8ncxcnJICJhIXOxa x97FyMUhJLCbUWLFpaOsEM4nRolZuz4yQjjfGCX2nehig2m5ffw7E0RiL6PE8r6/UP2fGSU2 Xr8E1M/BwSagKXFhcilIg4iAl8T92+/BxjKD7Hh7o5EdJCEs4CGxaOMxFhCbRUBVonXBFSYQ m1fAXOLMvL9MENvkJWZe+g5WzylgITH58zV2iBpBiZMzn4D1MgPVNG+dzQyyQEKglUPi+tlf jBDNLhIbn72CsoUlXh3fwg5hS0l8frcX6p1kiUszz0EtK5F4vOcglG0v0XqqnxnkGWagZ9bv 0ofYxSfR+/sJE0hYQoBXoqNNCKJaUeLepKesELa4xMMZS6BsD4lfS5exQMKnm1Hi66efTBMY 5WcheWEWkhdmIWxbwMi8ilEytaA4Nz212LTA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omslkoV4UxIrq1KL8uOLSnNSiw8xSnOwKInzXug6GS8kkJ5YkpqdmlqQWgSTZeLg lGpgSjNhj5qd/LMydte76I+x88oEBNwe+c2/05trtHBrsH7V8RXsqy7+rJbazD954cPG6mRh E7f7t2a8ZG/Y9DlnUcfXvX5dc3/pf4u+x6Ry1tJq97LUxVdmF5znW6b98mtvgco8eflJxgls jxIsLxpdFatslpIRKef3Pnnstty6mrCVUc+Y45a01N8xqGlvzq6slk1RyDxwQTLf7jPbpPXH qm+bXZC95msXUFBXpWXwd6vbhl//37jv3hVoGXHmr8PE9orXRd/Pdqmp+JYVnBSzuzxp/Y57 D152OMxftUqu8EO20N7ttRPD9Y9Ma3Y+W6L1mEluysTE2xdzctyTr/9id1z9U7Bj7ZlipSt8 YspblViKMxINtZiLihMBYLEBF/ACAAA= X-CMS-MailID: 20220909103136epcas5p38ea3a933e90d9f9d7451848dc3a60829 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220909103136epcas5p38ea3a933e90d9f9d7451848dc3a60829 References: <20220909102136.3020-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 9 10:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12971474 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 C156FC6FA82 for ; Fri, 9 Sep 2022 10:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiIIKby (ORCPT ); Fri, 9 Sep 2022 06:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbiIIKbx (ORCPT ); Fri, 9 Sep 2022 06:31:53 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 253E8883F4 for ; Fri, 9 Sep 2022 03:31:50 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220909103148epoutp018721678a2e23f94d37bc4c52f58d65e4~TKpVWJaOq2009220092epoutp01f for ; Fri, 9 Sep 2022 10:31:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220909103148epoutp018721678a2e23f94d37bc4c52f58d65e4~TKpVWJaOq2009220092epoutp01f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662719508; bh=Dka7Z5UEBNznU9rnZN263arRHHrQheZ74m48btxfW30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJhFOx72SSNLU3JwNLfAUMG/cLW1KHqJ9fjkta1BVXIAU6cFFoQ8yJDMNWlYlJbx2 xGLxGiEZ6pajicv3WQUGYP3C3ejR3H3r20/xc9D4E8qtcQgYrsfjZ0HVNP8qx3RKXJ Py6PsuDdZHPg6KeHFcvigo3PpviFOTuzmzoRIiDs= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20220909103147epcas5p3ca3c93059aea93d6e94f8a93d8b75a97~TKpUxq-9A0115401154epcas5p3z; Fri, 9 Sep 2022 10:31:47 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.182]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4MPC350w6Dz4x9Pt; Fri, 9 Sep 2022 10:31:45 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D8.DB.59633.D061B136; Fri, 9 Sep 2022 19:31:41 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20220909103140epcas5p36689726422eb68e6fdc1d39019a4a8ba~TKpOXl-Tg0115401154epcas5p3t; Fri, 9 Sep 2022 10:31:40 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220909103140epsmtrp10cbe43d34e34eda09f4f9937a1be9067~TKpOW1iFy1097010970epsmtrp1I; Fri, 9 Sep 2022 10:31:40 +0000 (GMT) X-AuditID: b6c32a49-dfdff7000000e8f1-a3-631b160d52f6 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id AB.B1.18644.C061B136; Fri, 9 Sep 2022 19:31:40 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220909103139epsmtip121b3208ae6a042f2e54c7e62b02f37d1~TKpM5TZXh1205712057epsmtip1W; Fri, 9 Sep 2022 10:31:39 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, asml.silence@gmail.com 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 v7 2/5] io_uring: introduce fixed buffer support for io_uring_cmd Date: Fri, 9 Sep 2022 15:51:33 +0530 Message-Id: <20220909102136.3020-3-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909102136.3020-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOJsWRm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WzXOLWO6MiVr9PlielMiWy5ldwhmRJ57WpkqdCuyKxY++uirBOe/xf03zv3+KfvBwo3 Kx4MV2Ipzkg01GIuKk4EAFoXtrzvAgAA X-CMS-MailID: 20220909103140epcas5p36689726422eb68e6fdc1d39019a4a8ba X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220909103140epcas5p36689726422eb68e6fdc1d39019a4a8ba References: <20220909102136.3020-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 972b179bc07a..f94f377f2ae6 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 */ @@ -218,6 +219,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 9 10:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12971475 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 9A3B8ECAAA1 for ; Fri, 9 Sep 2022 10:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbiIIKb4 (ORCPT ); Fri, 9 Sep 2022 06:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbiIIKbx (ORCPT ); Fri, 9 Sep 2022 06:31:53 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8E0F5C7D for ; Fri, 9 Sep 2022 03:31:49 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220909103147epoutp03a469023082e62ebe99f825cad7a18edc~TKpUwe-Md2027820278epoutp03c for ; Fri, 9 Sep 2022 10:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220909103147epoutp03a469023082e62ebe99f825cad7a18edc~TKpUwe-Md2027820278epoutp03c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662719507; bh=iwCntG/buA6//VKqNuXAbWrgGiDaWC0bADFiQoNYs8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RdrwQGAhjWRcs22CXHxot5tGPYA8fgBohq32j0Pox2B0u93NoHTU3numwTv2mD8CP sHW4v5WMvdYv17WW3l6B1O6u7Cf5dWfoJQ9ewXsdnXlzLYVgMWxGYjE4u6xSICjn2x xPKteFh3t8V/hOLhcBuDfjcMfa7zx7C9DrmBBbH4= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220909103147epcas5p4e37f6ea1b82217bbe6fc03bc6ba37dd1~TKpUVTjED2796827968epcas5p4P; Fri, 9 Sep 2022 10:31:47 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.179]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4MPC342YmCz4x9Pr; Fri, 9 Sep 2022 10:31:44 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id FE.AA.53458.0161B136; Fri, 9 Sep 2022 19:31:44 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20220909103143epcas5p2eda60190cd23b79fb8f48596af3e1524~TKpRLuilw0262302623epcas5p2G; Fri, 9 Sep 2022 10:31:43 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220909103143epsmtrp14a446390ad00524c8bb9ed4deabd9867~TKpRKxZvl1097010970epsmtrp1K; Fri, 9 Sep 2022 10:31:43 +0000 (GMT) X-AuditID: b6c32a4a-caffb7000000d0d2-7a-631b16103a7f Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 8C.B1.18644.F061B136; Fri, 9 Sep 2022 19:31:43 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220909103142epsmtip16b732d9bcf4129c4673f669599b95ed7~TKpP1-Gnv1204612046epsmtip1Z; Fri, 9 Sep 2022 10:31:42 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, asml.silence@gmail.com 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 v7 3/5] nvme: refactor nvme_alloc_user_request Date: Fri, 9 Sep 2022 15:51:34 +0530 Message-Id: <20220909102136.3020-4-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909102136.3020-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKJsWRmVeSWpSXmKPExsWy7bCmlq6AmHSyweElLBZzVm1jtFh9t5/N 4uaBnUwWK1cfZbJ413qOxeLo/7dsFpMOXWO02HtL22L+sqfsDpweO2fdZfe4fLbUY9OqTjaP zUvqPXbfbGDz6NuyitHj8ya5APaobJuM1MS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luKMREMt5qLiRADoF8acKAQAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsWy7bCSnC6/mHSywcmNOhZzVm1jtFh9t5/N 4uaBnUwWK1cfZbJ413qOxeLo/7dsFpMOXWO02HtL22L+sqfsDpweO2fdZfe4fLbUY9OqTjaP zUvqPXbfbGDz6NuyitHj8ya5APYoLpuU1JzMstQifbsErozlm4+xFUzUrVi74iN7A+Nf5S5G Tg4JAROJ7XNnsncxcnEICexglHh97BUzREJcovnaD3YIW1hi5b/nUEUfGSU+vF3L0sXIwcEm oClxYXIpSI2IQIDEwcbLYDXMAnMYJS5f3gPWLCzgLjH9TwMbiM0ioCrxrXUvWJxXwFzi5O03 bBAL5CVmXvoOFucUsJCY/PkamC0EVPN65ycWiHpBiZMzn4DZzED1zVtnM09gFJiFJDULSWoB I9MqRsnUguLc9NxiwwKjvNRyveLE3OLSvHS95PzcTYzgwNfS2sG4Z9UHvUOMTByMhxglOJiV RHhF10okC/GmJFZWpRblxxeV5qQWH2KU5mBREue90HUyXkggPbEkNTs1tSC1CCbLxMEp1cBU L6O9TeKTdtk/05vzf7XYlEs0qd6I4e9i8ZA6prnCTM5KNtMrY/7Dgp/HxJX0PnEIPn3KI/Er 8lSnmWj3u0vRx1eaMk887jenw/bgMvGMr9VPc6Oa3zNIfVn987/Tockh5zt3Hpzy7t7n9Fnq GX8dVaP5jnw2X/dXevkFDmstR3UZyUtRzvIBPCGl4kWRqv+skq27GNZJCFZE8r9csXmZz6rZ W184yqicb1ILWGy8Zqrnj3MNXQu4Oj4EFQV93WM/zXzm/2nL/7ZzdfxRzXpkrZhzuJv/Zv2+ H/9sJmt8VLaS6rxWv7rCwqxnW18mc4fT9NgtLBoWn7gXLfEU/r56aYg15yJf0+W8Pre3KCqx FGckGmoxFxUnAgCGjsA36wIAAA== X-CMS-MailID: 20220909103143epcas5p2eda60190cd23b79fb8f48596af3e1524 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220909103143epcas5p2eda60190cd23b79fb8f48596af3e1524 References: <20220909102136.3020-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. diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 548aca8b5b9f..cb2fa4db50dd 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -65,18 +65,10 @@ 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, + struct nvme_command *cmd, unsigned timeout, 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)) @@ -86,49 +78,61 @@ static struct request *nvme_alloc_user_request(struct request_queue *q, 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 (!ubuffer || !bufflen) + return 0; + + 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); + } + bio = req->bio; + if (ret) + goto out_unmap; + 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, req_op(req) == REQ_OP_DRV_OUT); + if (IS_ERR(meta)) { + ret = PTR_ERR(meta); + goto out_unmap; } + req->cmd_flags |= REQ_INTEGRITY; + *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 +145,16 @@ 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, timeout, 0, 0); if (IS_ERR(req)) return PTR_ERR(req); - bio = req->bio; + 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 +164,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 +426,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 +466,17 @@ 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, + d.timeout_ms ? msecs_to_jiffies(d.timeout_ms) : 0, + rq_flags, blk_flags); if (IS_ERR(req)) return PTR_ERR(req); + + 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 9 10:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12971476 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 8C811ECAAA1 for ; Fri, 9 Sep 2022 10:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbiIIKcB (ORCPT ); Fri, 9 Sep 2022 06:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbiIIKb4 (ORCPT ); Fri, 9 Sep 2022 06:31:56 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0961B7D79E for ; Fri, 9 Sep 2022 03:31:53 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220909103152epoutp029eef06f7026018568e16c2a29f8e1d17~TKpY8hbsU1691116911epoutp02P for ; Fri, 9 Sep 2022 10:31:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220909103152epoutp029eef06f7026018568e16c2a29f8e1d17~TKpY8hbsU1691116911epoutp02P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662719512; bh=hepCkLsLawcUW6NPOu6/Vf5Idoa6NAsOreUa0e5m0PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ddutFD1Yfz1DR1yND3horf0XCZGiQSlzKI5TLhximJiS9EAksY9fUYtFQs5RXarnv lWfsfHry6KstsvmUJnWq517gYJAonaxoaEPhWzfllqC1FA5xMxOL7EB446F8jIxKwI p3kAHR3HbK2USYgpcB8ssNdbrOHpuWmRX6IB8Tyk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20220909103151epcas5p11c4bfec887a9c1c56f3870954935e776~TKpYiMDZD0657806578epcas5p1B; Fri, 9 Sep 2022 10:31:51 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.177]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4MPC391478z4x9Px; Fri, 9 Sep 2022 10:31:49 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 2B.DB.59633.3161B136; Fri, 9 Sep 2022 19:31:47 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20220909103147epcas5p2a83ec151333bcb1d2abb8c7536789bfd~TKpUeiPhJ0487204872epcas5p24; Fri, 9 Sep 2022 10:31:47 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220909103147epsmtrp251d15f3adaaef49f00bb220fdd1bfb82~TKpUbpCPC1218912189epsmtrp2T; Fri, 9 Sep 2022 10:31:47 +0000 (GMT) X-AuditID: b6c32a49-dfdff7000000e8f1-b3-631b1613a845 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id DD.B1.18644.3161B136; Fri, 9 Sep 2022 19:31:47 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220909103145epsmtip1bdea779def076df2f0443c6d2a1f1062~TKpSgLoFj3150731507epsmtip1V; Fri, 9 Sep 2022 10:31:45 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, asml.silence@gmail.com 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 v7 4/5] block: add helper to map bvec iterator for passthrough Date: Fri, 9 Sep 2022 15:51:35 +0530 Message-Id: <20220909102136.3020-5-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909102136.3020-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFJsWRmVeSWpSXmKPExsWy7bCmlq6wmHSywZI1+hZNE/4yW8xZtY3R YvXdfjaLmwd2MlmsXH2UyeJd6zkWi6P/37JZTDp0jdFi7y1ti/nLnrI7cHnsnHWX3ePy2VKP Tas62Tw2L6n32H2zgc2jb8sqRo/Pm+QC2KOybTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwM dQ0tLcyVFPISc1NtlVx8AnTdMnOAjlNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CqlFqTk FJgU6BUn5haX5qXr5aWWWBkaGBiZAhUmZGdMXDOTreCaUsX6fdtYGxgfSXcxcnJICJhIzLh3 k6mLkYtDSGA3o8SkVw1sEM4nRommtbugnM+MEo2Xl7PAtHxv72OESOxilLhz6jcrXNXVmZuA hnFwsAloSlyYXArSICLgJXH/9nuwGmaQHav/vmUFSQgLREp8efoJbCqLgKrE89/nmEFsXgFz iR0vvzBDbJOXmHnpOzuIzSlgITH58zV2iBpBiZMzn4D1MgPVNG+dzQyyQEKgk0PiwaJ/UM0u ErdmvIY6W1ji1fEt7BC2lMTnd3vZIOxkiUszzzFB2CUSj/cchLLtJVpP9TODPMMM9Mz6XfoQ u/gken8/AftRQoBXoqNNCKJaUeLepKesELa4xMMZS6BsD4k1c65AA6ubUeLi0xssExjlZyF5 YRaSF2YhbFvAyLyKUTK1oDg3PbXYtMAwL7UcHrPJ+bmbGMGJVMtzB+PdBx/0DjEycTAeYpTg YFYS4RVdK5EsxJuSWFmVWpQfX1Sak1p8iNEUGMYTmaVEk/OBqTyvJN7QxNLAxMzMzMTS2MxQ SZx3ijZjspBAemJJanZqakFqEUwfEwenVAPTREO3SvV1eRod/3tfqOW9CGhbJOsbfyDt1N1t FqG2ryZW5blX84htyCi0n6cxM8zv/vn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QjbnDsuMzRvXU5G91T7Cs/pRysKnLPYJjpq+TSueHNucMuTp3n thtv/GUjcH1ZnO83K87NH9fM7H1yTXyOy0bnqF6zP8xcOlsNm1lmS8bOqrPiuMn46bjWYxbn eNH+s3cWyrGz2fccXSTdazYjt8o8NTMhJaC8crKtidjO4mMiNqJzSvv9fVSaOGZKxUvJdiXc 2SzkaaDEUpyRaKjFXFScCAA2MWDc8AIAAA== X-CMS-MailID: 20220909103147epcas5p2a83ec151333bcb1d2abb8c7536789bfd X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220909103147epcas5p2a83ec151333bcb1d2abb8c7536789bfd References: <20220909102136.3020-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 | 87 +++++++++++++++++++++++++++++++++++++----- include/linux/blk-mq.h | 1 + 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 7693f8e3c454..5dcfa112f240 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,62 @@ 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; + struct bio_vec *bv, *bvecs, *bvprvp = NULL; + struct queue_limits *lim = &q->limits; + unsigned int nsegs = 0, bytes = 0; + + 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 out_err; + + /* check full condition */ + if (nsegs >= nr_segs || bytes > UINT_MAX - bv->bv_len) + goto out_err; + + if (bytes + bv->bv_len <= nr_iter && + bv->bv_offset + bv->bv_len <= PAGE_SIZE) { + nsegs++; + bytes += bv->bv_len; + } else + goto out_err; + bvprvp = bv; + } + return 0; +out_err: + 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 b43c81d91892..83bef362f0f9 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -970,6 +970,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 9 10:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12971477 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 3F282ECAAD3 for ; Fri, 9 Sep 2022 10:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230471AbiIIKcR (ORCPT ); Fri, 9 Sep 2022 06:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbiIIKcG (ORCPT ); Fri, 9 Sep 2022 06:32:06 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE22D121693 for ; Fri, 9 Sep 2022 03:32:03 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220909103202epoutp0496d2a6c8db61172bd87a6c356e9a6179~TKpiXuFhz1589715897epoutp042 for ; Fri, 9 Sep 2022 10:32:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220909103202epoutp0496d2a6c8db61172bd87a6c356e9a6179~TKpiXuFhz1589715897epoutp042 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662719522; bh=PVB0MUD8yijKhOA6MHwkPqGB3DJlypXxBlTGsU/XaIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q+W8iH1XcSJjExKHDB0kqWJ4itLNdaGzkMy7FMz7QT0y7nZC3f93MFpiZ3lHyB/Tc N8MTrtz+ZDo1TEMud5iRRavyMunB3uRzQvC45s88O45vGK6/718uol1hx+GeFCphuV s86S2V59iAOz4v0BTZ4wwD39V7jUhL1wVn0EjVkk= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20220909103201epcas5p2f5098fb079af197e68324af10e88e95e~TKph2p2fj3133831338epcas5p2b; Fri, 9 Sep 2022 10:32:01 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.180]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4MPC3M1zc8z4x9Pw; Fri, 9 Sep 2022 10:31:59 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id E0.F6.54060.7161B136; Fri, 9 Sep 2022 19:31:51 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20220909103151epcas5p1e25127c3053ba21e8f8418a701878973~TKpX-x5m92206722067epcas5p1O; Fri, 9 Sep 2022 10:31:51 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220909103151epsmtrp18ef8995fae6916182ea9b1190aa20435~TKpX6XEb61097010970epsmtrp1O; Fri, 9 Sep 2022 10:31:51 +0000 (GMT) X-AuditID: b6c32a4b-be1ff7000000d32c-ae-631b1617f45d Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F5.61.14392.6161B136; Fri, 9 Sep 2022 19:31:50 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220909103149epsmtip180e659fe86a3184108a4f787572f3a49~TKpWaiDRA1205012050epsmtip1P; Fri, 9 Sep 2022 10:31:49 +0000 (GMT) From: Kanchan Joshi To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, asml.silence@gmail.com 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 v7 5/5] nvme: wire up fixed buffer support for nvme passthrough Date: Fri, 9 Sep 2022 15:51:36 +0530 Message-Id: <20220909102136.3020-6-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909102136.3020-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCJsWRmVeSWpSXmKPExsWy7bCmuq64mHSywZxmGYs5q7YxWqy+289m cfPATiaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06PnbPusntcPlvqsWlVJ5vH 5iX1HrtvNrB59G1ZxejxeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5 kkJeYm6qrZKLT4CuW2YO0F1KCmWJOaVAoYDE4mIlfTub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SXmKPExsWy7bCSnK6YmHSywcdGG4s5q7YxWqy+289m cfPATiaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06PnbPusntcPlvqsWlVJ5vH 5iX1HrtvNrB59G1ZxejxeZNcAHsUl01Kak5mWWqRvl0CV8a7x01MBXOUK3qaDjE2MF6W6WLk 5JAQMJE4eGgKexcjF4eQwG5GiV39n9kgEuISzdd+sEPYwhIr/z2HKvrIKDF/8RXWLkYODjYB TYkLk0tBakQEAiQONl4Gq2EWmMMocfnyHrBmYYEIiRNtL1lAbBYBVYltj06A9fIKmEtcfhsP MV9eYual72DlnAIWEpM/XwOzhYBKXu/8BNbKKyAocXLmEzCbGai+eets5gmMArOQpGYhSS1g ZFrFKJlaUJybnltsWGCYl1quV5yYW1yal66XnJ+7iREc9lqaOxi3r/qgd4iRiYPxEKMEB7OS CK/oWolkId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwXuk7GCwmkJ5akZqemFqQWwWSZODilGphO qHZfTXpa3WyduVayafUWT06lQxMepVVxPzyd7NyprlLn0lf3+eTGU6rtjpsM72bpt055zCX/ 4tDBKrUNoqF2p2++SKnaU7TrxeRbKZ86LZ6sPGW5M1shKDnQ7btOY6enyI21E+94f7x8JClg s6+P2o9zrp99Wp8VlRZv2Bina1dV9+fZtuwtWxcEl/Rrah86OTXcpEVpS6f0nRmy/6Zbvrzp G3VS9XveNpmD/3wC5v2y2x+depm/ruvSlwnnVxy7In/ugOF+zc+p32r3229rmtG4+0PexxqX +Swedj2SPrMuHghmERGqPJ8bfGdX9/JC9dKLZ0Tv+65b9bH9nU7l6wLpKO3P6ftn7nKzDlFQ YinOSDTUYi4qTgQAK7USGeoCAAA= X-CMS-MailID: 20220909103151epcas5p1e25127c3053ba21e8f8418a701878973 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220909103151epcas5p1e25127c3053ba21e8f8418a701878973 References: <20220909102136.3020-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 | 40 ++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index cb2fa4db50dd..e47ef12ce047 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,20 +92,33 @@ 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 (!ubuffer || !bufflen) return 0; if (!vec) - ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, - GFP_KERNEL); + if (fixedbufs) { + 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 { + ret = blk_rq_map_user(q, req, NULL, + nvme_to_user_ptr(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); + 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); @@ -136,7 +150,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) { @@ -150,7 +164,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, return PTR_ERR(req); 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; @@ -228,7 +242,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); } @@ -282,7 +296,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); @@ -328,7 +342,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); @@ -472,9 +486,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, if (IS_ERR(req)) return PTR_ERR(req); - 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; req->end_io = nvme_uring_cmd_end_io;