From patchwork Fri Sep 30 06:27:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anuj Gupta X-Patchwork-Id: 612166 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 A321AC433F5 for ; Fri, 30 Sep 2022 06:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbiI3Gnn (ORCPT ); Fri, 30 Sep 2022 02:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbiI3Gnc (ORCPT ); Fri, 30 Sep 2022 02:43:32 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17416208570 for ; Thu, 29 Sep 2022 23:43:27 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220930064326epoutp0364b1b7ff81f471d60373ec8ca0dc9981~ZkE8Obf6O2689226892epoutp03m for ; Fri, 30 Sep 2022 06:43:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220930064326epoutp0364b1b7ff81f471d60373ec8ca0dc9981~ZkE8Obf6O2689226892epoutp03m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1664520206; bh=ThnCd0QThrZCq2pxruHyWZ5UgpjXQN5hDvf0/hIjKhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uWhKp9CV6W5kFAzcwgQlMbDvIFSMOniW336DWQGd8VSpoNpLXgZO1mqnrqaNs3T4C xpZEjwADZEnm5hiM6Hm2pPZNtOr70Jp9NBBODUWDYA0UV5iM+36H8zRF9i4HSPPeU9 kQzHFpgnlYvLbsroie79Lsm8A5PNeznpWWZ481/A= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20220930064325epcas5p3fb8eefad42a351c401392784ca151c4a~ZkE7pZWjL1801418014epcas5p38; Fri, 30 Sep 2022 06:43:25 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.180]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4Mf0zs22bJz4x9Pr; Fri, 30 Sep 2022 06:43:21 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id B7.A1.56352.90096336; Fri, 30 Sep 2022 15:43:21 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220930063811epcas5p43cce58f5e1589c3e3780ce0cfd563986~ZkAXERA8S2578525785epcas5p4B; Fri, 30 Sep 2022 06:38:11 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220930063811epsmtrp151807c3d2d197186d2db4f69bc5d057c~ZkAXDc2av2657326573epsmtrp1M; Fri, 30 Sep 2022 06:38:11 +0000 (GMT) X-AuditID: b6c32a4b-383ff7000001dc20-f5-63369009e006 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id FC.59.14392.3DE86336; Fri, 30 Sep 2022 15:38:11 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220930063810epsmtip2562009c1830622fb08678d770eb8253d~ZkAVvBefV1736317363epsmtip2T; Fri, 30 Sep 2022 06:38:10 +0000 (GMT) From: Anuj Gupta 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, linux-scsi@vger.kernel.org, Anuj Gupta Subject: [PATCH for-next v12 03/12] block: add blk_rq_map_user_io Date: Fri, 30 Sep 2022 11:57:40 +0530 Message-Id: <20220930062749.152261-4-anuj20.g@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220930062749.152261-1-anuj20.g@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNJsWRmVeSWpSXmKPExsWy7bCmhi7nBLNkgw/tPBZNE/4yW6y+289m cfPATiaLlauPMlm8az3HYjHp0DVGi723tC3mL3vKbtF9fQebA6fH5bOlHptWdbJ5bF5S77H7 ZgObR9+WVYwenzfJBbBFZdtkpCampBYppOYl56dk5qXbKnkHxzvHm5oZGOoaWlqYKynkJeam 2iq5+AToumXmAJ2kpFCWmFMKFApILC5W0rezKcovLUlVyMgvLrFVSi1IySkwKdArTswtLs1L 18tLLbEyNDAwMgUqTMjOmL+ij7mgRbhi15Y1jA2MG/m7GDk5JARMJF5fXMbWxcjFISSwm1Hi xMS7zCAJIYFPjBKNs6sgEt8YJd4t38II0zH5Uj9Ux15GiWWbljBBdHxmlLjWpg5iswmoSxx5 3grWICJgJLH/00lWkAZmgU2MEr+uHwNrEBZwlFj2uB2siEVAVaLt1Dcwm1fASmLdhC1MENvk JWZe+s7excjBwSlgLdG8KAeiRFDi5MwnLCA2M1BJ89bZzCDzJQR+skv8eXuWHaLXRaK9sQlq jrDEq+NboOJSEi/726DsdIkfl59C1RRINB/bB/WlvUTrqX5mkL3MApoS63fpQ4RlJaaeWscE sZdPovf3E6hWXokd82BsJYn2lXOgbAmJvecaoGwPiQknd7BCAq6PUeLPrmfMExgVZiH5ZxaS f2YhrF7AyLyKUTK1oDg3PbXYtMA4L7UcHsnJ+bmbGMGpVMt7B+OjBx/0DjEycTAeYpTg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STZeLglGpgclsiwLxx 6/VHmcaH9irp7Cl5Zf1pfszUhuSDnVu7CzZlbff9Z5R60zVd+Csbf8GpHzznrpnWalm9//z5 2dukpJ8lAgYmKyob6mdnblOTmTT17B3tgw1q1XnnHlzulNn53mXH9Y0y14uNsq2rmr++Mli3 oNBFzc6iwH0jx76NOmmnX/G4ilm3XAgKEpif1nPQPFHja02o66Eqnf239k7mfZw/h7NrbYTW 4wVtB/ZsX3/0t8u7TPOXTmF2806l+L6IFUxp/sF9wvC/OtNlE6+kI/nxb1LlNdvfLT/x8saH Kn1fnpcLNNir+8XD9rtdvzrnr0/xhM7WrLaZ+/7ybLtstHfqqS2G4lIbtdd3lDEUK7EUZyQa ajEXFScCAPwvTmjlAgAA X-CMS-MailID: 20220930063811epcas5p43cce58f5e1589c3e3780ce0cfd563986 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220930063811epcas5p43cce58f5e1589c3e3780ce0cfd563986 References: <20220930062749.152261-1-anuj20.g@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Create a helper blk_rq_map_user_io for mapping of vectored as well as non-vectored requests. This will help in saving dupilcation of code at few places in scsi and nvme. Signed-off-by: Anuj Gupta Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- block/blk-map.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/block/blk-map.c b/block/blk-map.c index 7693f8e3c454..0e37bbedd46c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -611,6 +611,42 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq, } EXPORT_SYMBOL(blk_rq_map_user); +int blk_rq_map_user_io(struct request *req, struct rq_map_data *map_data, + void __user *ubuf, unsigned long buf_len, gfp_t gfp_mask, + bool vec, int iov_count, bool check_iter_count, int rw) +{ + int ret = 0; + + if (vec) { + struct iovec fast_iov[UIO_FASTIOV]; + struct iovec *iov = fast_iov; + struct iov_iter iter; + + ret = import_iovec(rw, ubuf, iov_count ? iov_count : buf_len, + UIO_FASTIOV, &iov, &iter); + if (ret < 0) + return ret; + + if (iov_count) { + /* SG_IO howto says that the shorter of the two wins */ + iov_iter_truncate(&iter, buf_len); + if (check_iter_count && !iov_iter_count(&iter)) { + kfree(iov); + return -EINVAL; + } + } + + ret = blk_rq_map_user_iov(req->q, req, map_data, &iter, + gfp_mask); + kfree(iov); + } else if (buf_len) { + ret = blk_rq_map_user(req->q, req, map_data, ubuf, buf_len, + gfp_mask); + } + return ret; +} +EXPORT_SYMBOL(blk_rq_map_user_io); + /** * 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 50811d0fb143..ba18e9bdb799 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -985,6 +985,8 @@ struct rq_map_data { 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_io(struct request *, struct rq_map_data *, + void __user *, unsigned long, gfp_t, bool, int, bool, int); int blk_rq_map_user_iov(struct request_queue *, struct request *, struct rq_map_data *, const struct iov_iter *, gfp_t); int blk_rq_unmap_user(struct bio *);