mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "hch@lst.de" <hch@lst.de>
To: Jinyoung CHOI <j-young.choi@samsung.com>
Cc: "axboe@kernel.dk" <axboe@kernel.dk>,
	"kbusch@kernel.org" <kbusch@kernel.org>,
	"hch@lst.de" <hch@lst.de>, "sagi@grimberg.me" <sagi@grimberg.me>,
	"jejb@linux.ibm.com" <jejb@linux.ibm.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"johannes.thumshirn@wdc.com" <johannes.thumshirn@wdc.com>,
	"kch@nvidia.com" <kch@nvidia.com>,
	"willy@infradead.org" <willy@infradead.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 02/14] block: bio-integrity: modify bio_integrity_add_page()
Date: Fri, 12 May 2023 15:43:23 +0200	[thread overview]
Message-ID: <20230512134323.GA32242@lst.de> (raw)
In-Reply-To: <20230510084854epcms2p756a3e1055399ead6bf539d3419c74c3e@epcms2p7>

Hi Jinyoung,

can you work a bit on the commit log and especially the subject line?

I'd word this as something like:

"Subject: bio-integrity: create multi-page bvecs in bio_integrity_add_page()

Allow bio_integrity_add_page to create multi-page bvecs, just like
the bio payloads.  This simplifies adding larger payloads, and fixes
support for non-tiny workloads with nvme, which stopped using scatterlist
for metadata a while ago"

It should probably also mentioned somewhere that you did an audit to
ensure all drivers and the core code is fine with these multi-page
segments.  If it's not, this patch should only be added after that
has been made the case.

I think the extra arguments struct is a bit overcompliated, and mostly
due to me making the existing code to weird things in the low-level
helpers.  With the "rationalize the flow in bio_add_page and friends"
series I just sent out, I think we can drop the previous patch and
simplify this one down to:

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 4533eb49166109..85d70dc723f0ed 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -118,26 +118,44 @@ void bio_integrity_free(struct bio *bio)
  * @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) {
-		printk(KERN_ERR "%s: bip_vec full\n", __func__);
+	if (((bip->bip_iter.bi_size + len) >> SECTOR_SHIFT) >
+	    queue_max_hw_sectors(q))
 		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))
-		return 0;
+	if (bip->bip_vcnt > 0) {
+		struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
+		bool same_page = false;
+
+		if (bvec_try_merge_hw_page(q, bv, page, len, offset,
+				&same_page)) {
+			bip->bip_iter.bi_size += len;
+			return len;
+		}
+
+		if (bip->bip_vcnt >=
+		    min(bip->bip_max_vcnt, queue_max_integrity_segments(q)))
+			return 0;
+
+		/*
+		 * If the queue doesn't support SG gaps and adding this segment
+		 * would create a gap, disallow it.
+		 */
+		if (bvec_gap_to_prev(&q->limits, bv, offset))
+			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;
 }
 EXPORT_SYMBOL(bio_integrity_add_page);
@@ -249,7 +267,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)
diff --git a/block/bio.c b/block/bio.c
index 79e8aa600ddbe2..050b57e09ac362 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -934,7 +934,7 @@ static bool bvec_try_merge_page(struct bio_vec *bv, struct page *page,
  * size limit.  This is not for normal read/write bios, but for passthrough
  * or Zone Append operations that we can't split.
  */
-static bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
+bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
 		struct page *page, unsigned len, unsigned offset,
 		bool *same_page)
 {
diff --git a/block/blk.h b/block/blk.h
index 45547bcf111938..1e67f738b52191 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -486,4 +486,8 @@ static inline int req_ref_read(struct request *req)
 	return atomic_read(&req->ref);
 }
 
+bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
+		struct page *page, unsigned len, unsigned offset,
+		bool *same_page);
+
 #endif /* BLK_INTERNAL_H */
-- 
2.39.2


  reply	other threads:[~2023-05-12 13:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p1>
2023-05-10  8:44 ` [PATCH v2 00/14] Change the integrity configuration method in block Jinyoung CHOI
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p6>
2023-05-10  8:46     ` [PATCH v2 01/14] block: bio: separation to reuse a part of the function Jinyoung CHOI
2023-05-10  9:00     ` [PATCH v2 13/14] block: blk-integrity: change sg-table configuration method for integrity Jinyoung CHOI
2023-05-17  2:35     ` RE:(2) [PATCH v2 12/14] block: add helper function for iteration of bip's bvec Jinyoung CHOI
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p3>
2023-05-10  8:56     ` [PATCH v2 08/14] scsi: add scsi_alloc_integrity_sgtables() for integrity process Jinyoung CHOI
2023-05-12 13:52       ` hch
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p7>
2023-05-10  8:48     ` [PATCH v2 02/14] block: bio-integrity: modify bio_integrity_add_page() Jinyoung CHOI
2023-05-12 13:43       ` hch [this message]
2023-05-10  8:51     ` [PATCH v2 04/14] block: fix not to apply bip information in blk_rq_bio_prep() Jinyoung CHOI
2023-05-12 13:47       ` hch
2023-05-10  9:01     ` [PATCH v2 14/14] block: blk-integrity: remove blk_rq_count_integrity_sg() Jinyoung CHOI
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p8>
2023-05-10  8:56     ` [PATCH v2 09/14] scsi: change to use blk_rq_nr_integrity_segments() instead of blk_rq_count_integrity_sg() Jinyoung CHOI
2023-05-10  8:58     ` [PATCH v2 10/14] block: blk-integrity: change how to find the number of integrity of bio Jinyoung CHOI
2023-05-10  8:59     ` [PATCH v2 12/14] block: add helper function for iteration of bip's bvec Jinyoung CHOI
2023-05-12 13:54       ` hch
2023-05-16 12:54     ` RE:(2) [PATCH v2 02/14] block: bio-integrity: modify bio_integrity_add_page() Jinyoung CHOI
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p2>
2023-05-10  8:53     ` [PATCH v2 06/14] block: blk-merge: fix merging two requests in ll_merge_requests_fn Jinyoung CHOI
2023-05-16 13:24     ` RE:(2) [PATCH v2 05/14] block: blk-merge: fix to add the number of integrity segments to the request twice Jinyoung CHOI
     [not found]   ` <CGME20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p5>
2023-05-10  8:50     ` [PATCH v2 03/14] block: bio-integrity: cleanup bio_integrity_prep Jinyoung CHOI
2023-05-12 13:45       ` hch
2023-05-10  8:52     ` [PATCH v2 05/14] block: blk-merge: fix to add the number of integrity segments to the request twice Jinyoung CHOI
2023-05-12 13:51       ` hch
2023-05-10  8:53     ` [PATCH v2 07/14] block: add helper function to get the number of integrity segments Jinyoung CHOI
2023-05-17  2:20     ` RE:(2) [PATCH v2 08/14] scsi: add scsi_alloc_integrity_sgtables() for integrity process Jinyoung CHOI
2023-05-10  8:59 ` [PATCH v2 11/14] nvme: rdma: change how to find the number of integrity of request Jinyoung CHOI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230512134323.GA32242@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=j-young.choi@samsung.com \
    --cc=jejb@linux.ibm.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=sagi@grimberg.me \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome