From patchwork Wed May 3 10:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 13230007 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 C0FD2C77B7F for ; Wed, 3 May 2023 10:02:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbjECKC1 (ORCPT ); Wed, 3 May 2023 06:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjECKC0 (ORCPT ); Wed, 3 May 2023 06:02:26 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33EBC1B0 for ; Wed, 3 May 2023 03:02:24 -0700 (PDT) Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230503100222epoutp0487431c43ad29b0041b724710254fb27a~bmfAidJNM1123611236epoutp04R for ; Wed, 3 May 2023 10:02:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230503100222epoutp0487431c43ad29b0041b724710254fb27a~bmfAidJNM1123611236epoutp04R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1683108142; bh=o/y7pqqreOOyNd3ZbjyVH5zrhKm5j2wzOS45niAlYE4=; h=Subject:Reply-To:From:To:In-Reply-To:Date:References:From; b=qXa2dMLgA5s9fizPdZRKXZ2zfZHhrjlKptjJ0gAa0Yarx+cauEYQ7uDBJCjNxOg9S 887PELrA/+Dc/BsnFO9x4sqBi5lAu+30b7U9Dk9tIPKByk2Q4The8pnDf4jChUIAwi vDT8IMPjkIy3nTTH/8yLOKdt0yxYyaXjZ/cbCsPg= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230503100222epcas2p3cc0da536fd36757f90a1f16245acd6a4~bmfAM6Xm80396103961epcas2p3w; Wed, 3 May 2023 10:02:22 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.68]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4QBCDF3Rl4z4x9Q3; Wed, 3 May 2023 10:02:21 +0000 (GMT) X-AuditID: b6c32a45-465ff70000020cc1-ca-6452312d7a18 Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id BE.A9.03265.D2132546; Wed, 3 May 2023 19:02:21 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH 02/15] block: blk-integiry: add helper functions for bio_integrity_add_page Reply-To: j-young.choi@samsung.com Sender: Jinyoung CHOI From: Jinyoung CHOI To: Jinyoung CHOI , "axboe@kernel.dk" , "hch@lst.de" , "martin.petersen@oracle.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: <20230503100220epcms2p33e69fd7d5f04b305c621799792e8155f@epcms2p3> Date: Wed, 03 May 2023 19:02:20 +0900 X-CMS-MailID: 20230503100220epcms2p33e69fd7d5f04b305c621799792e8155f X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-CPGSPASS: Y X-CPGSPASS: Y X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHKsWRmVeSWpSXmKPExsWy7bCmua6uYVCKwZK/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GvRmBywM6PlTPZ c9fWCj2eMoXfYqvZ+dN+z64/2CUVyrsyOPHk9TsXbct6TkWmzdvveTr36V2lcAklluKMREMt 5qLiRAABKXjuEQQAAA== 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 Add functions that use the hardware limit to merge the page with integrity's bio_vec. Using the added functions, the physically continuous pages are made of one bio_vec. Previously, physically continuous pages were not created as one bio_vec, but separately created. Cc: Christoph Hellwig Cc: Martin K. Petersen Signed-off-by: Jinyoung Choi --- block/bio-integrity.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 4533eb491661..06b6a2c178d2 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -111,6 +111,64 @@ void bio_integrity_free(struct bio *bio) bio->bi_opf &= ~REQ_INTEGRITY; } +/** + * bip_full - check if the bip is full + * @bip: bip to check + * @len: length of one segment to be added + * + * Return true if @bip is full and one segment with @len bytes can't be + * added to the bip, otherwise return false + */ +static inline bool bip_full(struct bio_integrity_payload *bip, unsigned int len) +{ + if (bip->bip_vcnt >= bip->bip_max_vcnt) + return true; + if (bip->bip_iter.bi_size > UINT_MAX - len) + return true; + return false; +} + +/** + * bip_try_merge_hw_seg - try to merge a page into a segment, while + * obeying the hardware segment size limit + * @q: the target queue + * @bip: bip to check + * @page: page containing integrity metadata + * @len: number of bytes of integrity metadata in page + * @offset: start offset within page + * @same_page: return if the segment has been merged inside the same page + * + * Return true if @page is merged to @bip, otherwise return false + */ +static bool bip_try_merge_hw_seg(struct request_queue *q, + struct bio_integrity_payload *bip, + struct page *page, unsigned int len, + unsigned int offset, bool *same_page) +{ + struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1]; + unsigned long mask = queue_segment_boundary(q); + phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset; + phys_addr_t addr2 = page_to_phys(page) + offset + len - 1; + + if ((addr1 | mask) != (addr2 | mask)) + return false; + if (bv->bv_len + len > queue_max_segment_size(q)) + return false; + + if (bip->bip_vcnt > 0) { + if (bio_page_is_mergeable(bv, page, len, offset, same_page)) { + if (bip->bip_iter.bi_size > UINT_MAX - len) { + *same_page = false; + return false; + } + bv->bv_len += len; + bip->bip_iter.bi_size += len; + return true; + } + } + return false; +} + /** * bio_integrity_add_page - Attach integrity metadata * @bio: bio to update