From patchwork Fri Sep 30 06:27:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anuj Gupta X-Patchwork-Id: 12994983 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 19B3EC433FE for ; Fri, 30 Sep 2022 06:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbiI3GpP (ORCPT ); Fri, 30 Sep 2022 02:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbiI3GpK (ORCPT ); Fri, 30 Sep 2022 02:45:10 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E50C28735 for ; Thu, 29 Sep 2022 23:44:56 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220930064454epoutp03e021b238e4a7778598cae478eba7455c~ZkGOKNMKC2850328503epoutp03R for ; Fri, 30 Sep 2022 06:44:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220930064454epoutp03e021b238e4a7778598cae478eba7455c~ZkGOKNMKC2850328503epoutp03R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1664520294; bh=tDC98zhUChsoFxyax6OGBO2ZGu3ypq6Y8ZQCxc+Plfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZL+No5DInG82hyUQlmn9tGqHZ8aMqYn84o3M/jWlv9aUaRDh2I9SEaJr93S8jiXgr /Hf31PtkgZ3axZA+jBoL7Pd3T+Vx8/oakA5LBURR7feL7iEpehrtRyMchJGv3HBtjT PPuJE46zObixyEDYi+QOBOQr/WjTk/HW10QZqD4Q= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20220930064453epcas5p30182b25ffd0a63d0d2c10c1a766c6605~ZkGNsxaas2067520675epcas5p3j; Fri, 30 Sep 2022 06:44:53 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.181]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4Mf11Z6kncz4x9QK; Fri, 30 Sep 2022 06:44:50 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id C9.CD.39477.F5096336; Fri, 30 Sep 2022 15:44:47 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220930063831epcas5p4b6a8559dedd39ef423a0b9a317163969~ZkApTi86I2025120251epcas5p4H; Fri, 30 Sep 2022 06:38:31 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220930063831epsmtrp1de3393fe7c03723a16fede328b3bd0c3~ZkApSranM2641426414epsmtrp14; Fri, 30 Sep 2022 06:38:31 +0000 (GMT) X-AuditID: b6c32a4a-259fb70000019a35-bb-6336905f0964 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 76.69.14392.7EE86336; Fri, 30 Sep 2022 15:38:31 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220930063829epsmtip215b19387b98af7ff187f06f2ff8ba3c2~ZkAnvK22K1483614836epsmtip2P; Fri, 30 Sep 2022 06:38:29 +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, Kanchan Joshi , Anuj Gupta Subject: [PATCH for-next v12 10/12] block: extend functionality to map bvec iterator Date: Fri, 30 Sep 2022 11:57:47 +0530 Message-Id: <20220930062749.152261-11-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+NgFprHJsWRmVeSWpSXmKPExsWy7bCmum78BLNkg5NvzC2aJvxltlh9t5/N 4uaBnUwWK1cfZbJ413qOxeLo/7dsFpMOXWO02HtL22L+sqfsFt3Xd7A5cHlcPlvqsWlVJ5vH 5iX1HrtvNrB59G1ZxejxeZNcAFtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5 kkJeYm6qrZKLT4CuW2YO0F1KCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKTAr3i xNzi0rx0vbzUEitDAwMjU6DChOyMvxuLC37KVJz6eYG9gfGzWBcjJ4eEgInEgy932LoYuTiE BHYzSlw9/4AJwvnEKLHrzVl2COcbo8Tev3vZYVoal6wEs4UE9jJKbHrDAmF/ZpS4Nd8LxGYT UJc48ryVEcQWETCS2P/pJCvIIGaBm4wSzcf2Aa3g4BAWCJP4M0MSpIZFQFXi1aeNrCA2r4C1 xMKNOxkhdslLzLz0nR2knBMo3rwoB6JEUOLkzCdga5mBSpq3zmYGGS8h0MghMevoQSaIXheJ A5PfQM0Rlnh1fAvU/VISL/vboOx0iR+Xn0LVF4CcBlVvL9F6qp8ZZC+zgKbE+l36EGFZiamn 1jFB7OWT6P39BKqVV2LHPBhbSaJ95RwoW0Ji77kGKNtDomHKcmhI9zFKzPg5k3ECo8IsJP/M QvLPLITVCxiZVzFKphYU56anFpsWGOWllsOjODk/dxMjOK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Rmp6YWpBbBZJk4OKUamNTD HQ+tLOorz7Xgsdr4SWuiumfODO5/xjLmPL++qE1xWf8+rHLbql+zMyr+X/VeNZ83sc08ZJWI 3Sq23nyJV2YGSTfLfNOPtE5yEsibknKIwaxrWsE7lpAL9aeFne4mSK0/GWMWt2ft0bi507a9 NL/85xjXW+vt3J1fPvqXZKytl9kScmnB9YLGMJc3l0NbF0gGTv5ts2HN6u2SSWeqd386H2A+ VVL1xoHJS/1bHxmdnTLRfH6IsubE3q91EydNe2BzTLiC8TXjliUCWrJqCxTcin9fz37Q+fDf lLPaE+YxfFITtnhW9CvLjHXmgX3+MRcCrEU5mZQLXQpXRwXfqZxqzsp7ZdqpZ9NtnQ7ZH1Vi Kc5INNRiLipOBADTsuvS6gIAAA== X-CMS-MailID: 20220930063831epcas5p4b6a8559dedd39ef423a0b9a317163969 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220930063831epcas5p4b6a8559dedd39ef423a0b9a317163969 References: <20220930062749.152261-1-anuj20.g@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Kanchan Joshi Extend blk_rq_map_user_iov so that it can handle bvec iterator, using the new blk_rq_map_user_bvec function. It maps the pages from bvec iterator into a bio and place the bio into request. This helper will be used by nvme for uring-passthrough path when IO is done using pre-mapped buffers. Signed-off-by: Kanchan Joshi Signed-off-by: Anuj Gupta Suggested-by: Christoph Hellwig --- block/blk-map.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index d6ea377394a9..34735626b00f 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -548,6 +548,62 @@ int blk_rq_append_bio(struct request *rq, struct bio *bio) } EXPORT_SYMBOL(blk_rq_append_bio); +/* Prepare bio for passthrough IO given ITER_BVEC iter */ +static int blk_rq_map_user_bvec(struct request *rq, const struct iov_iter *iter) +{ + struct request_queue *q = rq->q; + size_t nr_iter = iov_iter_count(iter); + size_t nr_segs = iter->nr_segs; + struct bio_vec *bvecs, *bvprvp = NULL; + struct queue_limits *lim = &q->limits; + unsigned int nsegs = 0, bytes = 0; + struct bio *bio; + size_t i; + + 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 = blk_rq_map_bio_alloc(rq, 0, GFP_KERNEL); + if (bio == NULL) + return -ENOMEM; + + bio_iov_bvec_set(bio, (struct iov_iter *)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++) { + struct bio_vec *bv = &bvecs[i]; + + /* + * If the queue doesn't support SG gaps and adding this + * offset would create a gap, fallback to copy. + */ + if (bvprvp && bvec_gap_to_prev(lim, bvprvp, bv->bv_offset)) { + blk_mq_map_bio_put(bio); + return -EREMOTEIO; + } + /* check full condition */ + if (nsegs >= nr_segs || bytes > UINT_MAX - bv->bv_len) + goto put_bio; + if (bytes + bv->bv_len > nr_iter) + goto put_bio; + if (bv->bv_offset + bv->bv_len > PAGE_SIZE) + goto put_bio; + + nsegs++; + bytes += bv->bv_len; + bvprvp = bv; + } + return 0; +put_bio: + blk_mq_map_bio_put(bio); + return -EINVAL; +} + /** * blk_rq_map_user_iov - map user data to a request, for passthrough requests * @q: request queue where request should be inserted @@ -567,24 +623,35 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, struct rq_map_data *map_data, const struct iov_iter *iter, gfp_t gfp_mask) { - bool copy = false; + bool copy = false, map_bvec = false; unsigned long align = q->dma_pad_mask | queue_dma_alignment(q); struct bio *bio = NULL; struct iov_iter i; int ret = -EINVAL; - if (!iter_is_iovec(iter)) - goto fail; - if (map_data) copy = true; else if (blk_queue_may_bounce(q)) copy = true; else if (iov_iter_alignment(iter) & align) copy = true; + else if (iov_iter_is_bvec(iter)) + map_bvec = true; + else if (!iter_is_iovec(iter)) + copy = true; else if (queue_virt_boundary(q)) copy = queue_virt_boundary(q) & iov_iter_gap_alignment(iter); + if (map_bvec) { + ret = blk_rq_map_user_bvec(rq, iter); + if (!ret) + return 0; + if (ret != -EREMOTEIO) + goto fail; + /* fall back to copying the data on limits mismatches */ + copy = true; + } + i = *iter; do { if (copy)