From: Keith Busch <kbusch@meta.com>
To: <axboe@kernel.dk>, <hch@lst.de>, <martin.petersen@oracle.com>,
<linux-block@vger.kernel.org>, <linux-nvme@lists.infradead.org>,
<linux-scsi@vger.kernel.org>, <sagi@grimberg.me>
Cc: Keith Busch <kbusch@kernel.org>
Subject: [PATCHv4 10/10] blk-integrity: improved sg segment mapping
Date: Wed, 11 Sep 2024 13:12:40 -0700 [thread overview]
Message-ID: <20240911201240.3982856-11-kbusch@meta.com> (raw)
In-Reply-To: <20240911201240.3982856-1-kbusch@meta.com>
From: Keith Busch <kbusch@kernel.org>
Make the integrity mapping more like data mapping, blk_rq_map_sg. Use
the request to validate the segment count, and update the callers so
they don't have to.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
block/blk-integrity.c | 15 +++++++++++----
drivers/nvme/host/rdma.c | 4 ++--
drivers/scsi/scsi_lib.c | 11 +++--------
include/linux/blk-integrity.h | 6 ++----
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 1d82b18e06f8e..549480aa2a069 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -62,19 +62,20 @@ int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio)
*
* Description: Map the integrity vectors in request into a
* scatterlist. The scatterlist must be big enough to hold all
- * elements. I.e. sized using blk_rq_count_integrity_sg().
+ * elements. I.e. sized using blk_rq_count_integrity_sg() or
+ * rq->nr_integrity_segments.
*/
-int blk_rq_map_integrity_sg(struct request_queue *q, struct bio *bio,
- struct scatterlist *sglist)
+int blk_rq_map_integrity_sg(struct request *rq, struct scatterlist *sglist)
{
struct bio_vec iv, ivprv = { NULL };
+ struct request_queue *q = rq->q;
struct scatterlist *sg = NULL;
+ struct bio *bio = rq->bio;
unsigned int segments = 0;
struct bvec_iter iter;
int prev = 0;
bio_for_each_integrity_vec(iv, bio, iter) {
-
if (prev) {
if (!biovec_phys_mergeable(q, &ivprv, &iv))
goto new_segment;
@@ -102,6 +103,12 @@ int blk_rq_map_integrity_sg(struct request_queue *q, struct bio *bio,
if (sg)
sg_mark_end(sg);
+ /*
+ * Something must have been wrong if the figured number of segment
+ * is bigger than number of req's physical integrity segments
+ */
+ BUG_ON(segments > blk_rq_nr_phys_segments(rq));
+ BUG_ON(segments > queue_max_integrity_segments(q));
return segments;
}
EXPORT_SYMBOL(blk_rq_map_integrity_sg);
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 537844ee906b3..0d6d8431208a5 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -1504,8 +1504,8 @@ static int nvme_rdma_dma_map_req(struct ib_device *ibdev, struct request *rq,
goto out_unmap_sg;
}
- req->metadata_sgl->nents = blk_rq_map_integrity_sg(rq->q,
- rq->bio, req->metadata_sgl->sg_table.sgl);
+ req->metadata_sgl->nents = blk_rq_map_integrity_sg(rq,
+ req->metadata_sgl->sg_table.sgl);
*pi_count = ib_dma_map_sg(ibdev,
req->metadata_sgl->sg_table.sgl,
req->metadata_sgl->nents,
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index fa59b54a8f4c6..16e97925606b6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1163,7 +1163,6 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd)
if (blk_integrity_rq(rq)) {
struct scsi_data_buffer *prot_sdb = cmd->prot_sdb;
- int ivecs;
if (WARN_ON_ONCE(!prot_sdb)) {
/*
@@ -1175,19 +1174,15 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd)
goto out_free_sgtables;
}
- ivecs = blk_rq_nr_integrity_segments(rq);
- if (sg_alloc_table_chained(&prot_sdb->table, ivecs,
+ if (sg_alloc_table_chained(&prot_sdb->table,
+ blk_rq_nr_integrity_segments(rq),
prot_sdb->table.sgl,
SCSI_INLINE_PROT_SG_CNT)) {
ret = BLK_STS_RESOURCE;
goto out_free_sgtables;
}
- count = blk_rq_map_integrity_sg(rq->q, rq->bio,
- prot_sdb->table.sgl);
- BUG_ON(count > ivecs);
- BUG_ON(count > queue_max_integrity_segments(rq->q));
-
+ count = blk_rq_map_integrity_sg(rq, prot_sdb->table.sgl);
cmd->prot_sdb = prot_sdb;
cmd->prot_sdb->table.nents = count;
}
diff --git a/include/linux/blk-integrity.h b/include/linux/blk-integrity.h
index 9c7029aa9c22a..6a62885a6beab 100644
--- a/include/linux/blk-integrity.h
+++ b/include/linux/blk-integrity.h
@@ -25,8 +25,7 @@ static inline bool queue_limits_stack_integrity_bdev(struct queue_limits *t,
}
#ifdef CONFIG_BLK_DEV_INTEGRITY
-int blk_rq_map_integrity_sg(struct request_queue *, struct bio *,
- struct scatterlist *);
+int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
int blk_rq_count_integrity_sg(struct request_queue *, struct bio *);
int blk_rq_integrity_map_user(struct request *rq, void __user *ubuf,
ssize_t bytes, u32 seed);
@@ -98,8 +97,7 @@ static inline int blk_rq_count_integrity_sg(struct request_queue *q,
{
return 0;
}
-static inline int blk_rq_map_integrity_sg(struct request_queue *q,
- struct bio *b,
+static inline int blk_rq_map_integrity_sg(struct request *q,
struct scatterlist *s)
{
return 0;
--
2.43.5
next prev parent reply other threads:[~2024-09-11 20:12 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 20:12 [PATCHv4 00/10] block integrity merging and counting Keith Busch
2024-09-11 20:12 ` [PATCHv4 01/10] blk-mq: unconditional nr_integrity_segments Keith Busch
2024-09-12 7:02 ` Christoph Hellwig
2024-09-13 1:47 ` Martin K. Petersen
2024-09-11 20:12 ` [PATCHv4 02/10] blk-mq: set the nr_integrity_segments from bio Keith Busch
2024-09-13 1:47 ` Martin K. Petersen
2024-09-11 20:12 ` [PATCHv4 03/10] blk-integrity: properly account for segments Keith Busch
2024-09-13 1:48 ` Martin K. Petersen
2024-09-11 20:12 ` [PATCHv4 04/10] blk-integrity: consider entire bio list for merging Keith Busch
2024-09-12 7:42 ` Christoph Hellwig
2024-09-11 20:12 ` [PATCHv4 05/10] block: provide a request helper for user integrity segments Keith Busch
2024-09-12 7:43 ` Christoph Hellwig
2024-09-13 1:50 ` Martin K. Petersen
2024-09-13 12:33 ` Kanchan Joshi
2024-09-11 20:12 ` [PATCHv4 06/10] block: provide helper for nr_integrity_segments Keith Busch
2024-09-12 7:44 ` Christoph Hellwig
2024-09-13 1:52 ` Martin K. Petersen
2024-09-13 12:35 ` Kanchan Joshi
2024-09-11 20:12 ` [PATCHv4 07/10] scsi: use request helper to get integrity segments Keith Busch
2024-09-13 1:53 ` Martin K. Petersen
2024-09-13 12:35 ` Kanchan Joshi
2024-09-11 20:12 ` [PATCHv4 08/10] nvme-rdma: " Keith Busch
2024-09-13 1:54 ` Martin K. Petersen
2024-09-13 12:37 ` Kanchan Joshi
2024-09-11 20:12 ` [PATCHv4 09/10] block: unexport blk_rq_count_integrity_sg Keith Busch
2024-09-13 1:54 ` Martin K. Petersen
2024-09-11 20:12 ` Keith Busch [this message]
2024-09-11 23:23 ` [PATCHv4 10/10] blk-integrity: improved sg segment mapping Keith Busch
2024-09-12 7:46 ` Christoph Hellwig
2024-09-12 7:47 ` Christoph Hellwig
2024-09-13 2:00 ` Martin K. Petersen
2024-09-13 3:45 ` kernel test robot
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=20240911201240.3982856-11-kbusch@meta.com \
--to=kbusch@meta.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sagi@grimberg.me \
/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;
as well as URLs for NNTP newsgroup(s).