From patchwork Wed May 3 10:06:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 13230008 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 240CDC77B75 for ; Wed, 3 May 2023 10:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjECKGs (ORCPT ); Wed, 3 May 2023 06:06:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjECKGq (ORCPT ); Wed, 3 May 2023 06:06:46 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EF311A5 for ; Wed, 3 May 2023 03:06:43 -0700 (PDT) Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230503100641epoutp043fb5288211a65e8d58d5787d80e0fcac~bmiyBQbmY1521015210epoutp04h for ; Wed, 3 May 2023 10:06:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230503100641epoutp043fb5288211a65e8d58d5787d80e0fcac~bmiyBQbmY1521015210epoutp04h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1683108401; bh=1WhTIW3VLo5qDfXJ/0YEchijZafqk1XB4OYfht1gpEI=; h=Subject:Reply-To:From:To:In-Reply-To:Date:References:From; b=DcUF9wb+SnzJEz0OCAcXzgBVuPqyetKe4JbMFY8vPe4dDVOcwtWFXmfvjWgTT0fD+ 0n0DnSrhmk1irqyipV8Cpy2JUMtQcg1kF8K4FjTH7hlJ3PjqOrZmj+mx0WY5HjyrY0 ZqP/BT9TUKFeYa6pOcJ8Z/bjUdJtAxb8oseVE8Ac= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20230503100640epcas2p4a916461813c8ba6adefad44e524d4480~bmixIQo-G2064220642epcas2p4I; Wed, 3 May 2023 10:06:40 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.36.91]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4QBCKD1frvz4x9Py; Wed, 3 May 2023 10:06:40 +0000 (GMT) X-AuditID: b6c32a47-c29ff70000002007-a2-645232306dac Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 06.6D.08199.03232546; Wed, 3 May 2023 19:06:40 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH 03/15] block: bio-integrity: modify bio_integrity_add_page() Reply-To: j-young.choi@samsung.com Sender: Jinyoung CHOI From: Jinyoung CHOI To: Jinyoung CHOI , "axboe@kernel.dk" , "kbusch@kernel.org" , "hch@lst.de" , "sagi@grimberg.me" , "martin.petersen@oracle.com" , "kch@nvidia.com" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: <20230503094912epcms2p4bef206eab1c41a92eba2583a69c74323@epcms2p4> X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20230503100639epcms2p5069df7346cfce6db9718b9adf7cc3718@epcms2p5> Date: Wed, 03 May 2023 19:06:39 +0900 X-CMS-MailID: 20230503100639epcms2p5069df7346cfce6db9718b9adf7cc3718 X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-CPGSPASS: Y X-CPGSPASS: Y X-Brightmail-Tracker: H4sIAAAAAAAAA+NgF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ZP4qovjrZXAjohNYY17LtQtPB/0eIlJwMRf2atOcE+r2Wdv NvupfNzPg2EuF46ft1KesFLndGXbD2Gbf64/NE7xzC1NirliaheifyQhdIfsyq3vhHoCHJ9z XDnOrtKx1X5b/TeLjqAlj8rd85etex+zS02JpTgj0VCLuag4EQDrnXkoMQQAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230503094912epcms2p4bef206eab1c41a92eba2583a69c74323 References: <20230503094912epcms2p4bef206eab1c41a92eba2583a69c74323@epcms2p4> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Considering the constraints of hardware, the physically continuous pages were to be composed of one bio_vec. Previously, bio_vec was created separately for each page entering the parameter. Cc: Christoph Hellwig Cc: Martin K. Petersen Fixes: 783b94bd9250 ("nvme-pci: do not build a scatterlist to map metadata") Signed-off-by: Jinyoung Choi --- block/bio-integrity.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 06b6a2c178d2..74cf9933c285 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -176,25 +176,45 @@ static bool bip_try_merge_hw_seg(struct request_queue *q, * @len: number of bytes of integrity metadata in page * @offset: start offset within page * - * Description: Attach a page containing integrity metadata to bio. + * Add a page containing integrity metadata to a bio while respecting + * the hardware max_sectors, max_segment and gap limitations. */ int bio_integrity_add_page(struct bio *bio, struct page *page, unsigned int len, unsigned int offset) { + struct request_queue *q = bdev_get_queue(bio->bi_bdev); struct bio_integrity_payload *bip = bio_integrity(bio); - if (bip->bip_vcnt >= bip->bip_max_vcnt) { + if (((bip->bip_iter.bi_size + len) >> 9) > queue_max_hw_sectors(q)) + return 0; + + if (bip->bip_vcnt > 0) { + struct bio_vec *bv; + bool same_page = false; + + if (bip_try_merge_hw_seg(q, bip, page, len, offset, &same_page)) + return len; + + /* + * If the queue doesn't support SG gaps and adding this segment + * would create a gap, disallow it. + */ + bv = &bip->bip_vec[bip->bip_vcnt - 1]; + if (bvec_gap_to_prev(&q->limits, bv, offset)) + return 0; + } + + if (bip_full(bip, len)) { printk(KERN_ERR "%s: bip_vec full\n", __func__); return 0; } - if (bip->bip_vcnt && - bvec_gap_to_prev(&bdev_get_queue(bio->bi_bdev)->limits, - &bip->bip_vec[bip->bip_vcnt - 1], offset)) + if (bip->bip_vcnt >= queue_max_integrity_segments(q)) return 0; bvec_set_page(&bip->bip_vec[bip->bip_vcnt], page, len, offset); bip->bip_vcnt++; + bip->bip_iter.bi_size += len; return len; } @@ -307,7 +327,6 @@ bool bio_integrity_prep(struct bio *bio) } bip->bip_flags |= BIP_BLOCK_INTEGRITY; - bip->bip_iter.bi_size = len; bip_set_seed(bip, bio->bi_iter.bi_sector); if (bi->flags & BLK_INTEGRITY_IP_CHECKSUM) @@ -316,7 +335,6 @@ bool bio_integrity_prep(struct bio *bio) /* Map it */ offset = offset_in_page(buf); for (i = 0 ; i < nr_pages ; i++) { - int ret; bytes = PAGE_SIZE - offset; if (len <= 0) @@ -325,18 +343,13 @@ bool bio_integrity_prep(struct bio *bio) if (bytes > len) bytes = len; - ret = bio_integrity_add_page(bio, virt_to_page(buf), - bytes, offset); - - if (ret == 0) { + if (bio_integrity_add_page(bio, virt_to_page(buf), + bytes, offset) < bytes) { printk(KERN_ERR "could not attach integrity payload\n"); status = BLK_STS_RESOURCE; goto err_end_io; } - if (ret < bytes) - break; - buf += bytes; len -= bytes; offset = 0;