From patchwork Thu Sep 8 18:35:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12970512 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 6E0D2C38145 for ; Thu, 8 Sep 2022 18:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbiIHSpn (ORCPT ); Thu, 8 Sep 2022 14:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbiIHSpk (ORCPT ); Thu, 8 Sep 2022 14:45:40 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2BF844F9 for ; Thu, 8 Sep 2022 11:45:37 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220908184534epoutp03e56d9086d33c0c5a9b11cd9c971a5f04~S9vKMyR9K0315103151epoutp03u for ; Thu, 8 Sep 2022 18:45:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220908184534epoutp03e56d9086d33c0c5a9b11cd9c971a5f04~S9vKMyR9K0315103151epoutp03u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662662734; bh=2CAPPezBpRudgC2/iVSQKO5OZC1ekpekq3vqFH1gTUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRaGXvV45FpQVrP7zNqxAJYXr3a8ChF3Jlp/tKwbQtf7QJ45u2OcGVaZKnwsgvp89 auJgXmA+NjYfmHank2sgT3xbnJspL7uCviPDZX2n81f9d52gG9mCHS2rLd3utaSiRL NLwY8IVkHh9XZiytk7DTEjFqCaiiTy3L+vspmw2w= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220908184533epcas5p42a5b682da9ae518321d181d89bca18d4~S9vJQozPw1434814348epcas5p4z; Thu, 8 Sep 2022 18:45:33 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.179]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4MNp3G65Sqz4x9Pq; Thu, 8 Sep 2022 18:45:30 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 59.49.54060.A483A136; Fri, 9 Sep 2022 03:45:30 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220908184530epcas5p44d67b682ee86fabbb3f3912e8fde332b~S9vGgtBJn0530505305epcas5p4l; Thu, 8 Sep 2022 18:45:30 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220908184530epsmtrp17dfdb0d12ee939ecaccfc477c79c1801~S9vGf7pel3080730807epsmtrp1b; Thu, 8 Sep 2022 18:45:30 +0000 (GMT) X-AuditID: b6c32a4b-e33fb7000000d32c-ce-631a384ac589 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 24.DD.14392.9483A136; Fri, 9 Sep 2022 03:45:29 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220908184528epsmtip25070875fc57a0e6c730b79be13990e6d~S9vFDM6w41574515745epsmtip2S; Thu, 8 Sep 2022 18:45:28 +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 v6 1/5] io_uring: add io_uring_cmd_import_fixed Date: Fri, 9 Sep 2022 00:05:07 +0530 Message-Id: <20220908183511.2253-2-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908183511.2253-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFJsWRmVeSWpSXmKPExsWy7bCmuq6XhVSywf4eA4umCX+ZLeas2sZo sfpuP5vFzQM7mSxWrj7KZPGu9RyLxdH/b9ksJh26xmix95a2xfxlT9kduDx2zrrL7nH5bKnH plWdbB6bl9R77L7ZwObRt2UVo8fnTXIB7FHZNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaG uoaWFuZKCnmJuam2Si4+AbpumTlAxykplCXmlAKFAhKLi5X07WyK8ktLUhUy8otLbJVSC1Jy CkwK9IoTc4tL89L18lJLrAwNDIxMgQoTsjO237zBXrBYqGLywvWsDYzT+bsYOTkkBEwk/k75 y9jFyMUhJLCbUWLh989sEM4nRomTWz4wQTjfGCVuX5jDBtPSeX0DVMteRomfR3pZIZzPjBId 07YAORwcbAKaEhcml4I0iAh4Sdy//R6shhlkx9sbjewgCWEBD4k5n06zgNgsAqoST9r3gMV5 BcwlHtzfzQ6xTV5i5qXvYDangIXExS8P2SBqBCVOznwC1ssMVNO8dTYzyAIJgVYOiS8f70M1 u0hsWfeACcIWlnh1fAtUXEriZX8blJ0scWnmOaiaEonHew5C2fYSraf6mUGeYQZ6Zv0ufYhd fBK9v58wgYQlBHglOtqEIKoVJe5NesoKYYtLPJyxBMr2kLh3fC00FLsZJRZdn8s0gVF+FpIX ZiF5YRbCtgWMzKsYJVMLinPTU4tNC4zzUsvhMZucn7uJEZxItb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LyQQHpiSWp2ampBahFMlomD U6qByTVexPeGvn2jsf1aG7FPUTb8X/I0OHUO++V9v+WjH8xaoyKTbvk8VlrgaFLD++X2E69s uWLw03tTAJfMi9+aPS8X9wr6pngcWOBRN9snpX+W8PmONW83Wp0KO/+1X37ytbmdR6w8smZ9 PbfMYcPZy6zbTR4EsxtzWYfus3oce/DG+i+9j8MqFykocBf/cU66fNY2tVWcWcn3+9JMk4th Os0f8k4l/RHZ6XXFZ+Zn311eq1snZG9KLbvff0eVY/2tk1tlN139HJT2LIhr0+Mle+N39V3Q m5km+P1BxvNtjPzOzHVR0ts0Gj1XJvXs9sl2dFU62PL1SB4DN2ulT25Jy7aZuqYOH5fPud4h 5nBbiaU4I9FQi7moOBEAWyGDxPACAAA= X-CMS-MailID: 20220908184530epcas5p44d67b682ee86fabbb3f3912e8fde332b X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220908184530epcas5p44d67b682ee86fabbb3f3912e8fde332b References: <20220908183511.2253-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 Reported-by: kernel test robot Reported-by: kernel test robot --- 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..202d90bc2c88 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 +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 Thu Sep 8 18:35:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12970513 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 23A03C6FA89 for ; Thu, 8 Sep 2022 18:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbiIHSpo (ORCPT ); Thu, 8 Sep 2022 14:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbiIHSpl (ORCPT ); Thu, 8 Sep 2022 14:45:41 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6C5985B8 for ; Thu, 8 Sep 2022 11:45:39 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220908184536epoutp040fc22b23118189e40a66fb801f8a4fc1~S9vMdg_4K0437804378epoutp046 for ; Thu, 8 Sep 2022 18:45:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220908184536epoutp040fc22b23118189e40a66fb801f8a4fc1~S9vMdg_4K0437804378epoutp046 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662662736; bh=oAfQIPdjrU6Y1ANjWE7k4a6Wf9Pn3fR+z3Nn3SKsL5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RgVIpK4+vh87R9y2vLobSu+pCAsGMnmNB4Aj0NcTmobvnLxTU2l3gWMWnJgbzJG41 96Z8fX9DqvPIDEXy5XG2na/k3o+IC5zpzl3n0VkgVWswBRy5GELDwDjE33kOtg0Uj/ XW0cnt9kG1VlrM/BHVyEZpUzdX1UUX8ky0qy9SDM= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20220908184535epcas5p1a455dbb3424bb46b9a996db0847718f8~S9vL6u9RU2308423084epcas5p1J; Thu, 8 Sep 2022 18:45:35 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.183]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4MNp3K2Rrpz4x9Pt; Thu, 8 Sep 2022 18:45:33 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 17.0B.53458.D483A136; Fri, 9 Sep 2022 03:45:33 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20220908184532epcas5p2ca2ab735dab24937e24e44be9f440f92~S9vJMBE9T2042720427epcas5p2_; Thu, 8 Sep 2022 18:45:32 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220908184532epsmtrp1ee73b52f6ac42af2bd24455f16c97d01~S9vJLLZz93080730807epsmtrp1d; Thu, 8 Sep 2022 18:45:32 +0000 (GMT) X-AuditID: b6c32a4a-a5bff7000000d0d2-b8-631a384dbbe5 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id D7.9E.18644.C483A136; Fri, 9 Sep 2022 03:45:32 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220908184531epsmtip2f0e83c5565e4b042b19454cd715e8b81~S9vHsX5UE2337123371epsmtip2C; Thu, 8 Sep 2022 18:45:31 +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 v6 2/5] io_uring: introduce fixed buffer support for io_uring_cmd Date: Fri, 9 Sep 2022 00:05:08 +0530 Message-Id: <20220908183511.2253-3-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908183511.2253-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOJsWRmVe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5fbCubvfz6c3MD1QG3zRMf4uLtS3IK3a336D5// vC/dKXyfrRJLcUaioRZzUXEiAFERVPPwAgAA X-CMS-MailID: 20220908184532epcas5p2ca2ab735dab24937e24e44be9f440f92 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220908184532epcas5p2ca2ab735dab24937e24e44be9f440f92 References: <20220908183511.2253-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 202d90bc2c88..81913f01bae0 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 Thu Sep 8 18:35:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12970514 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 353B7C38145 for ; Thu, 8 Sep 2022 18:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232398AbiIHSpw (ORCPT ); Thu, 8 Sep 2022 14:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232353AbiIHSpt (ORCPT ); Thu, 8 Sep 2022 14:45:49 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9A6A3D61 for ; Thu, 8 Sep 2022 11:45:41 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220908184538epoutp04f9fa980eb38be33880a8629ddf2274e5~S9vOxHZj53022030220epoutp04d for ; Thu, 8 Sep 2022 18:45:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220908184538epoutp04f9fa980eb38be33880a8629ddf2274e5~S9vOxHZj53022030220epoutp04d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662662739; bh=iwCntG/buA6//VKqNuXAbWrgGiDaWC0bADFiQoNYs8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NhNgECboZD4Qf7Y+K5MVLmDEWUipMWjqGB62G3XyhxLVa+G2jnkRYEKErKPv2BTdt qXvgWJwYnJsOuGfjGEQRpcEbZcpr56BWstmUtEYwF/+04MRCXAc/KuAYNCk7oWvfss 4SkXFNq29wHekTaQnPQ3oUVeDp+LSTqd/kMVH8xQ= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20220908184538epcas5p1b71c01e356e2dd7a0ca0daaa1cce0672~S9vOJZK622308423084epcas5p1N; Thu, 8 Sep 2022 18:45:38 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.175]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4MNp3N1qvLz4x9Pt; Thu, 8 Sep 2022 18:45:36 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 2A.49.54060.0583A136; Fri, 9 Sep 2022 03:45:36 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20220908184535epcas5p1e1f3d8b646d88079c3a7840f79e59508~S9vLonLK00840908409epcas5p1y; Thu, 8 Sep 2022 18:45:35 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220908184535epsmtrp18d7713c7a989ffbf7ac50509cd1e61ad~S9vLnymUV3080730807epsmtrp1f; Thu, 8 Sep 2022 18:45:35 +0000 (GMT) X-AuditID: b6c32a4b-e33fb7000000d32c-d4-631a38505aa4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F4.DD.14392.F483A136; Fri, 9 Sep 2022 03:45:35 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220908184534epsmtip23a1089d549cf64d4ca50d13174d1cb8a~S9vKSKsR32413824138epsmtip2a; Thu, 8 Sep 2022 18:45: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, Kanchan Joshi Subject: [PATCH for-next v6 3/5] nvme: refactor nvme_alloc_user_request Date: Fri, 9 Sep 2022 00:05:09 +0530 Message-Id: <20220908183511.2253-4-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908183511.2253-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCJsWRmVeSWpSXmKPExsWy7bCmlm6AhVSywcqH7BZzVm1jtFh9t5/N 4uaBnUwWK1cfZbJ413qOxeLo/7dsFpMOXWO02HtL22L+sqfsDpweO2fdZfe4fLbUY9OqTjaP zUvqPXbfbGDz6NuyitHj8ya5APaobJuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4Uz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ggBiQnBAAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsWy7bCSvK6/hVSywZvXMhZzVm1jtFh9t5/N 4uaBnUwWK1cfZbJ413qOxeLo/7dsFpMOXWO02HtL22L+sqfsDpweO2fdZfe4fLbUY9OqTjaP zUvqPXbfbGDz6NuyitHj8ya5APYoLpuU1JzMstQifbsErozlm4+xFUzUrVi74iN7A+Nf5S5G Tg4JAROJH7P2MYPYQgK7GSXaZgtCxMUlmq/9YIewhSVW/nsOZHMB1XxklNj/+SpTFyMHB5uA psSFyaUgNSICARIHGy+D1TALzGGUuHx5DztIjbCAu0TjIVuQGhYBVYn+E/fAdvEKmEs8mv4d ar68xMxLEDangIXExS8P2SDuMZe49mc6VL2gxMmZT1hAbGag+uats5knMArMQpKahSS1gJFp FaNkakFxbnpusWGBYV5quV5xYm5xaV66XnJ+7iZGcNBrae5g3L7qg94hRiYOxkOMEhzMSiK8 omslkoV4UxIrq1KL8uOLSnNSiw8xSnOwKInzXug6GS8kkJ5YkpqdmlqQWgSTZeLglGpgal+x 9Oa23mmRpx2LeSx59nK8TVdJKpwXYsgd6XPCKVRM+9zXh85FK/5oCvpfXX/8+XWdIuduzu1r YtmvtJis/xc6+bn37qs7W5bsjPwXeKJu+qnMHMYJjx4c318cOdt56cG2BlnBJ2/YExJruo6X 8ITt53kefXZeyL9v2jw/7OyZND9eUl5rNnNryVvTJDn/WfmPq+LTVNVnbjf4+vfZsw/524UF 3lyddtuor+nMgukfOLwt9M+0/yie63M7Slw6qnL9JYk3C3NaIxdI9goFa+x4Uvn20Qq9y+5y AmwqO0o3vpLcysw17cPhILcNR2w7lDve1k7ba2mpvkdm8alrPn8iznzrur5adPdzsdAdS5VY ijMSDbWYi4oTAUsPDlrpAgAA X-CMS-MailID: 20220908184535epcas5p1e1f3d8b646d88079c3a7840f79e59508 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220908184535epcas5p1e1f3d8b646d88079c3a7840f79e59508 References: <20220908183511.2253-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 Thu Sep 8 18:35:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12970515 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 6038BC38145 for ; Thu, 8 Sep 2022 18:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232357AbiIHSqA (ORCPT ); Thu, 8 Sep 2022 14:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbiIHSpx (ORCPT ); Thu, 8 Sep 2022 14:45:53 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91F69AFF1 for ; Thu, 8 Sep 2022 11:45:44 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220908184542epoutp03c5d7f006112b4af1e5be95e69efd3d21~S9vR4h36S3155431554epoutp03G for ; Thu, 8 Sep 2022 18:45:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220908184542epoutp03c5d7f006112b4af1e5be95e69efd3d21~S9vR4h36S3155431554epoutp03G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662662742; bh=hepCkLsLawcUW6NPOu6/Vf5Idoa6NAsOreUa0e5m0PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=izY10vJLDcmuzuO/Nrq06fndgOn0FQMREEHeHpoi5oXmHXnhgpf/a1iLn/2rqaSof bOXI8IIf1D8fP+VKBLVxg4UwDISAGyzDIANdN7df6YiQ9RkoW53r8hqi82O3NnxLcE EqYS8GBCKe/j1Jq36XFAVsauHy8qFa8hEhQel4yk= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220908184541epcas5p4d6a036bb587c01f62c7838f760f0941e~S9vRVyDm90530505305epcas5p4w; Thu, 8 Sep 2022 18:45:41 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.174]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4MNp3R1sWqz4x9Pq; Thu, 8 Sep 2022 18:45:39 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id EA.49.54060.3583A136; Fri, 9 Sep 2022 03:45:39 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20220908184538epcas5p378c450bfe07d296a9abc843efe75dfc9~S9vOnjjUs0406904069epcas5p3V; Thu, 8 Sep 2022 18:45:38 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220908184538epsmtrp1161fc4a31213ad0a138f4d6dbcc5eea9~S9vOmrjHa3080730807epsmtrp1g; Thu, 8 Sep 2022 18:45:38 +0000 (GMT) X-AuditID: b6c32a4b-be1ff7000000d32c-d9-631a3853ebb6 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 95.DD.14392.2583A136; Fri, 9 Sep 2022 03:45:38 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220908184537epsmtip220246c38dd98a5fed693dc42c22ba7cb~S9vNNIcW12337123371epsmtip2E; Thu, 8 Sep 2022 18:45:37 +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 v6 4/5] block: add helper to map bvec iterator for passthrough Date: Fri, 9 Sep 2022 00:05:10 +0530 Message-Id: <20220908183511.2253-5-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908183511.2253-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOJsWRmVeSWpSXmKPExsWy7bCmpm6whVSywbn5HBZNE/4yW8xZtY3R YvXdfjaLmwd2MlmsXH2UyeJd6zkWi6P/37JZTDp0jdFi7y1ti/nLnrI7cHnsnHWX3ePy2VKP Tas62Tw2L6n32H2zgc2jb8sqRo/Pm+QC2KOybTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwM dQ0tLcyVFPISc1NtlVx8AnTdMnOAjlNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CqlFqTk FJgU6BUn5haX5qXr5aWWWBkaGBiZAhUmZGdMXDOTreCaUsX6fdtYGxgfSXcxcnJICJhIXLz8 m62LkYtDSGA3o8Tq4++ZQRJCAp8YJdZcqO5i5ACyvzFKTIqHqZ/+vh+qfi+jxL/me+wQzmdG id3z/7KBNLAJaEpcmFwK0iAi4CVx//Z7VpAaZrAFf9+ygiSEBSIl1u/+yghiswioSlw7eJwF xOYVMJdoWNrODrFNXmLmpe9gNqeAhcTFLw/ZIGoEJU7OfAJWzwxU07x1NjPIAgmBVg6J/pW3 WSCaXSSeH7sCZQtLvDq+BWqolMTL/jYoO1ni0sxzTBB2icTjPQehbHuJ1lP9zCDPMAM9s36X PsQuPone30+YQMISArwSHW1CENWKEvcmPWWFsMUlHs5YAmV7SGzf/xoaWN2MEmsv97BPYJSf heSFWUhemIWwbQEj8ypGydSC4tz01GLTAuO81HJ4tCbn525iBKdQLe8djI8efNA7xMjEwXiI UYKDWUmEV3StRLIQb0piZVVqUX58UWlOavEhRlNgGE9klhJNzgcm8bySeEMTSwMTMzMzE0tj M0Mlcd4p2ozJQgLpiSWp2ampBalFMH1MHJxSDUy9AhI75Bw4NKovqF9hunTIKJdB4Ooz28Vq jDcOPHhQKatjELC4LaErRPn4yx+L6iPNf0wJXBhkZ7Nmucl3jleFjjVC1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1n33U3r6d8L V/1Ysuk+f1OixPqeJ+nvp2of82DNuvZZwiz+Ufrtpm+MlzLSeKbv3Tb/5y3Z0052f+qZQvnU 3Ys1VqZLydze/ey84e3pB2a+49kqN21XkCnD/al1H/VOXZw1ZdKynS9i2f9d2qivoJTS5fhF d+9pJZbijERDLeai4kQAvxxbh+8CAAA= X-CMS-MailID: 20220908184538epcas5p378c450bfe07d296a9abc843efe75dfc9 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220908184538epcas5p378c450bfe07d296a9abc843efe75dfc9 References: <20220908183511.2253-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 Thu Sep 8 18:35:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 12970516 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 3EB4EC6FA89 for ; Thu, 8 Sep 2022 18:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbiIHSqE (ORCPT ); Thu, 8 Sep 2022 14:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbiIHSp5 (ORCPT ); Thu, 8 Sep 2022 14:45:57 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4EC4D418C for ; Thu, 8 Sep 2022 11:45:47 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220908184545epoutp014132af2bd576d44abdf4ded8a9293ab2~S9vUtRby81556215562epoutp01B for ; Thu, 8 Sep 2022 18:45:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220908184545epoutp014132af2bd576d44abdf4ded8a9293ab2~S9vUtRby81556215562epoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1662662745; bh=PVB0MUD8yijKhOA6MHwkPqGB3DJlypXxBlTGsU/XaIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKTCnRhpu8DMwgiiPIUHYf26YwKqmBmSOWJ0Nks/FCY9LbeHY0XXAWPZO9YNZL7Yw +XR2hKYUbDEdUiMDenY9A/x/KxGFZnUYH+UK439CPQRpOHf25XLMClUnI9e5/OsVGe AHsq0koyhFAzexXz7tdlNBY78PV7qwEV44lzI6C0= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20220908184544epcas5p2e6820c44276f93574cce402af6b0fd21~S9vTw0Kfs2042620426epcas5p2K; Thu, 8 Sep 2022 18:45:44 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.178]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4MNp3T6kVrz4x9Pp; Thu, 8 Sep 2022 18:45:41 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id E7.0B.53458.5583A136; Fri, 9 Sep 2022 03:45:41 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20220908184541epcas5p183b54ed38849da7abdffebade9e8be6c~S9vRIgC1R0840908409epcas5p11; Thu, 8 Sep 2022 18:45:41 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220908184541epsmtrp1d1f075e671545dcc12e7c1ac36849c4e~S9vRHn3ko3080730807epsmtrp1h; Thu, 8 Sep 2022 18:45:41 +0000 (GMT) X-AuditID: b6c32a4a-a5bff7000000d0d2-c2-631a38551d70 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 46.DD.14392.5583A136; Fri, 9 Sep 2022 03:45:41 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220908184540epsmtip228f4ca907748e9213caff48c350b1241~S9vPylGvS2337123371epsmtip2F; Thu, 8 Sep 2022 18:45: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, Kanchan Joshi Subject: [PATCH for-next v6 5/5] nvme: wire up fixed buffer support for nvme passthrough Date: Fri, 9 Sep 2022 00:05:11 +0530 Message-Id: <20220908183511.2253-6-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908183511.2253-1-joshi.k@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCJsWRmVeSWpSXmKPExsWy7bCmlm6ohVSyweNmI4s5q7YxWqy+289m cfPATiaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06PnbPusntcPlvqsWlVJ5vH 5iX1HrtvNrB59G1ZxejxeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5 kkJeYm6qrZKLT4CuW2YO0F1KCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKTAr3i xNzi0rx0vbzU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iaLlauPMlm8az3HYnH0/1s2i0mHrjFa7L2lbTF/2VN2B06PnbPusntcPlvqsWlVJ5vH 5iX1HrtvNrB59G1ZxejxeZNcAHsUl01Kak5mWWqRvl0CV8a7x01MBXOUK3qaDjE2MF6W6WLk 5JAQMJE4vP4SC4gtJLCbUeLxBVeIuLhE87Uf7BC2sMTKf8+BbC6gmo+MEk8XNQA5HBxsApoS FyaXgtSICARIHGy8DFbDLDCHUeLy5T1gNcICERKnF5SBmCwCqhJvzxuClPMKmEus29EJNV5e Yual72A2p4CFxMUvD9kgzjGXuPZnOjNEvaDEyZlPwM5kBqpv3jqbeQKjwCwkqVlIUgsYmVYx SqYWFOem5xYbFhjmpZbrFSfmFpfmpesl5+duYgSHvJbmDsbtqz7oHWJk4mA8xCjBwawkwiu6 ViJZiDclsbIqtSg/vqg0J7X4EKM0B4uSOO+FrpPxQgLpiSWp2ampBalFMFkmDk6pBqa1t86/ vtl6bd+MpAWJt4K25E3XCT7BmnrwrzZPqpLUU/W0uU4G99gf2H1RPMk9M5dLI0x8TtCWtrYp uhV6gbN+8pR5HFOum2Z3IvnfdK5l5zfMuzz9YUjT9yqmS5+E5YQyKh/sdj6xNbV8SZCe4jqe S/FFycbfju0R2RH5ef6mMrbDXDtE1lT95HwicdOzNbbowTOu0G8eVYaPrz6d/5/pV0pi0ZnA 7ulV0+3FEyfM7NqzvKUr92rxtSXrOTrc5qa6b+g417eYTYT16NeT6zdcOMmr+dy5/EifxR6D h2vF3R7MEhe2e+671vWJ3uWcc95GmvoHy5OqPAvTvs7vXXw1umfVRbt/Ggv2/z/iNTldiaU4 I9FQi7moOBEABz2Cl+gCAAA= X-CMS-MailID: 20220908184541epcas5p183b54ed38849da7abdffebade9e8be6c X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220908184541epcas5p183b54ed38849da7abdffebade9e8be6c References: <20220908183511.2253-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;