Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp583210rwr; Wed, 3 May 2023 03:15:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7xeBvEnsSKI9z/20R2qNNy6JzSvdMHAx0JurTcbFg/RT5EYNJnYzg1pqDw/qI5j88LUejT X-Received: by 2002:a17:902:bf0c:b0:19f:87b5:1873 with SMTP id bi12-20020a170902bf0c00b0019f87b51873mr1407390plb.62.1683108926397; Wed, 03 May 2023 03:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683108926; cv=none; d=google.com; s=arc-20160816; b=G5TIXuUoNFTa2iKdycVoR2XPHLb9LlXqH9cpNqx0IJiMk3/NBCja9aYJXJg9Ifa+1m UmcyRjFDHN2Iq554PP44iUnl7SCg0sXeF2YkqJYKUcNR6rDOsl4P489wtZ9qmTndz6/2 pazYEfb1u/g45jqy9v9gl1veKzMMw8RdAaNqb5AqacYwvIX1WgqaD3sWl9NQR//TmdAH g1UI6TObZj1ISYa3OSv8VsOqFQ19WMymUaQoshOqS9g7OUZvG+H2BfShaQLaiYoorstg yS3lSMesJDSpncWKI/LJyAREIZoH/6ZvS4+R8REsCx2jTHRF2iNqd+mTz6xoxqR0aX3f 4LFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:date:message-id:in-reply-to:to:from :sender:reply-to:subject:mime-version:dkim-signature:dkim-filter; bh=zvETEJpKps7CgoP+0aNXfFiUkdNh7m7B7nh+qhAE130=; b=yeFvg5ZSAJ4Oszybuhvv9WhDFxXWg+aQGJ00hSAAgZA0q2DidRbwxiI2fU0bbg9ZZ/ OftQeKeMEJ6aX6hG+EUxzSxBM4yZxE8s42vu2GxmRDrgGmTwgE7F4DL0QAnwe6QUM+CW 6SCuQI5Q4Jx8DxFJ7zrZjZz9ZSC6Kr18xq6cgng7w4dKAQ3R8rHvvxy3+yGfzbK2LzXz IJKI2bkqidio/ltMv8RNGoF/KbbxuiEih1Z9h6P8lyUNvIJHdrmIc+7ySelxdCHUpJUQ dykWFstW2gehKfmAGu162id0SW2HNuivM2siUFq8wggjLIyfPOyv2MDxoEGTzpY2A43n mqKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=EdUw5aMy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a170902e88100b001a971d32b41si25462166plg.267.2023.05.03.03.15.10; Wed, 03 May 2023 03:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=EdUw5aMy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbjECKMQ (ORCPT + 99 others); Wed, 3 May 2023 06:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbjECKMO (ORCPT ); Wed, 3 May 2023 06:12:14 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F020F3C01 for ; Wed, 3 May 2023 03:12:12 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230503101210epoutp04c1d2dbefd7b530e0f7b29f0f044b8a39~bmnkrR4-B1848018480epoutp04j for ; Wed, 3 May 2023 10:12:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230503101210epoutp04c1d2dbefd7b530e0f7b29f0f044b8a39~bmnkrR4-B1848018480epoutp04j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1683108731; bh=zvETEJpKps7CgoP+0aNXfFiUkdNh7m7B7nh+qhAE130=; h=Subject:Reply-To:From:To:In-Reply-To:Date:References:From; b=EdUw5aMyi7rcmSIDmFkf8q0TJeS5f/+H3M5nKe1TQrTVqyjt/pDnPxG6VBQwP0dqe o+ym4JrdgBuq7uSvj1lhyrEsQKUyLQbl0WdbKlQeGnOaW/UpZcEEA83oSwV/PL0C0Y G++C3r36qCXbWsMHHsK8bEFBLCEYzJZr82wBs1FM= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230503101210epcas2p348dac10e0ac642bdfafcb7aeac0625e5~bmnj-qOF71815318153epcas2p3S; Wed, 3 May 2023 10:12:10 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.89]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4QBCRY4phbz4x9Pr; Wed, 3 May 2023 10:12:09 +0000 (GMT) X-AuditID: b6c32a46-8b7ff7000001438d-04-64523379883f Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 1E.74.17293.97332546; Wed, 3 May 2023 19:12:09 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH 06/15] block: blk-merge: fix to add the number of integrity segments to the request twice 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: <20230503101208epcms2p217be9d66b1e07c4e2ce3741e659e158f@epcms2p2> Date: Wed, 03 May 2023 19:12:08 +0900 X-CMS-MailID: 20230503101208epcms2p217be9d66b1e07c4e2ce3741e659e158f Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-CPGSPASS: Y X-CPGSPASS: Y X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHKsWRmVeSWpSXmKPExsWy7bCmqW6lcVCKQdtNRYvVd/vZLF4e0rRY ufook0Vv/1Y2i723tC0u75rDZrH8+D8mB3aPy2dLPXbfbGDz+Pj0FotH35ZVjB6fN8kFsEZl 22SkJqakFimk5iXnp2TmpdsqeQfHO8ebmhkY6hpaWpgrKeQl5qbaKrn4BOi6ZeYA3aCkUJaY UwoUCkgsLlbSt7Mpyi8tSVXIyC8usVVKLUjJKTAv0CtOzC0uzUvXy0stsTI0MDAyBSpMyM54 sH0Ga8EJtYqP02ayNjBuke9i5OSQEDCRuPqol7GLkYtDSGAHo8TqJd0sXYwcHLwCghJ/dwiD 1AgLZEv87tjMDGILCShJnFszixGkRFjAQOJWrzlImE1AT+LnkhlsILaIwGomiebnNRDjeSVm tD9lgbClJbYv38oIYnMK+Ek83nCLESKuIfFjWS8zhC0qcXP1W3YY+/2x+VA1IhKt985C1QhK PPi5GyouKXHo0Fc2kHMkBPIlNhwIhAjXSLxdfgCqRF/iWsdGqKd8JR69jQQJswioSux9vYwV osRFov1HE5jNLCAvsf3tHGaQcmYBTYn1u/QhhitLHLnFAlHBJ9Fx+C87zH8NG39jZe+Y94QJ olVNYlGTEURYRuLr4fnsExiVZiHCeBaStbMQ1i5gZF7FKJZaUJybnlpsVGAEj9bk/NxNjOCE qOW2g3HK2w96hxiZOBgPMUpwMCuJ8H4o9EsR4k1JrKxKLcqPLyrNSS0+xGgK9PBEZinR5Hxg Ss4riTc0sTQwMTMzNDcyNTBXEueVtj2ZLCSQnliSmp2aWpBaBNPHxMEp1cCk5bYpeOEal4Tl R74UfOi7KRvwQFExZlPrrBgv/tur/6ycGFsVvGJ1o2Sa+9//U+f5emc8v3zWXOftzJVP0trv MF0qyz3/bkVTjMp555JbxwTWvlulK6pxq+OlwJSbIjWBt29p2pQcmM8+a8eVxxLiU6cWpsUo 9aycpbxP5bUw13r1968+vr7+benClU/1/Gef6Jl/4aLWhos5ImWNR1WffnR9uTumKUWy2SJi ZuQLxT9P/l2OUrlWVXgxyrIgNODDrciK3TnMk9NXPeb5sehFkvCTkzltFgpX4t9rv7f6IfWO N2nDywOzGczElXd7H8s4+KTHdabqhMz5Aor3O+ZwSelZmpf/ilFe+jRCc23yDSWW4oxEQy3m ouJEAF4Mg6YRBAAA DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230503094912epcms2p4bef206eab1c41a92eba2583a69c74323 References: <20230503094912epcms2p4bef206eab1c41a92eba2583a69c74323@epcms2p4> X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org blk_integrity_merge_bio() not only performs conditional tests, but also updates the integrity segment information of request. It can be called twice when merging the bio into an existing request. bio_attempt_bio_merge() or blk_mq_sched_try_merge() blk_rq_merge_ok() blk_integrity_merge_bio() - 1 bio_attemp_{back|front}_merge() ll_{back|front}_merge_fn() ll_new_hw_segments() blk_integrity_merge_bio() - 2 The part of checking the conditions and the code to update the information of the actual request were separated. At this time, the ll_back_merge_fn was called by passth-path, so the condition check was called by all the separated functions. And after success in blk_integrity_merge_bio(), the information of the request may be wrong if it is impossible to merge due to other conditional tests. Thus, it was changed to be called immediately before merging the bio's segments. Cc: Christoph Hellwig Cc: Martin K. Petersen Signed-off-by: Jinyoung Choi --- block/blk-integrity.c | 34 +++++++++++++++++++++++++++++----- block/blk-merge.c | 9 +++++---- block/blk.h | 7 +++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index d4e9b4556d14..03a85e1f6d2e 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -184,19 +184,43 @@ bool blk_integrity_merge_rq(struct request_queue *q, struct request *req, return true; } +static inline bool blk_integrity_bypass_check(struct request *req, + struct bio *bio) +{ + return blk_integrity_rq(req) == 0 && bio_integrity(bio) == NULL; +} + +static bool __blk_integrity_mergeable(struct request_queue *q, + struct request *req, struct bio *bio) +{ + if (blk_integrity_rq(req) == 0 || bio_integrity(bio) == NULL) + return false; + + if (bio_integrity(req->bio)->bip_flags != bio_integrity(bio)->bip_flags) + return false; + + return true; +} + +bool blk_integrity_mergeable(struct request_queue *q, struct request *req, + struct bio *bio) +{ + if (blk_integrity_bypass_check(req, bio)) + return true; + + return __blk_integrity_mergeable(q, req, bio); +} + bool blk_integrity_merge_bio(struct request_queue *q, struct request *req, struct bio *bio) { int nr_integrity_segs; struct bio *next = bio->bi_next; - if (blk_integrity_rq(req) == 0 && bio_integrity(bio) == NULL) + if (blk_integrity_bypass_check(req, bio)) return true; - if (blk_integrity_rq(req) == 0 || bio_integrity(bio) == NULL) - return false; - - if (bio_integrity(req->bio)->bip_flags != bio_integrity(bio)->bip_flags) + if (!__blk_integrity_mergeable(q, req, bio)) return false; bio->bi_next = NULL; diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..8509f468d6d4 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -611,9 +611,6 @@ static inline int ll_new_hw_segment(struct request *req, struct bio *bio, if (!blk_cgroup_mergeable(req, bio)) goto no_merge; - if (blk_integrity_merge_bio(req->q, req, bio) == false) - goto no_merge; - /* discard request merge won't add new segment */ if (req_op(req) == REQ_OP_DISCARD) return 1; @@ -621,6 +618,10 @@ static inline int ll_new_hw_segment(struct request *req, struct bio *bio, if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req)) goto no_merge; + /* This will merge integrity segments */ + if (!blk_integrity_merge_bio(req->q, req, bio)) + goto no_merge; + /* * This will form the start of a new hw segment. Bump both * counters. @@ -934,7 +935,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) return false; /* only merge integrity protected bio into ditto rq */ - if (blk_integrity_merge_bio(rq->q, rq, bio) == false) + if (!blk_integrity_mergeable(rq->q, rq, bio)) return false; /* Only merge if the crypt contexts are compatible */ diff --git a/block/blk.h b/block/blk.h index 45547bcf1119..5923d2190d91 100644 --- a/block/blk.h +++ b/block/blk.h @@ -189,6 +189,8 @@ static inline bool bio_integrity_endio(struct bio *bio) bool blk_integrity_merge_rq(struct request_queue *, struct request *, struct request *); +bool blk_integrity_mergeable(struct request_queue *rq, struct request *r, + struct bio *b); bool blk_integrity_merge_bio(struct request_queue *, struct request *, struct bio *); @@ -221,6 +223,11 @@ static inline bool blk_integrity_merge_rq(struct request_queue *rq, { return true; } +static inline bool blk_integrity_mergeable(struct request_queue *rq, + struct request *r, struct bio *b) +{ + return true; +} static inline bool blk_integrity_merge_bio(struct request_queue *rq, struct request *r, struct bio *b) { -- 2.34.1