From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
hch@lst.de, axboe@kernel.dk, joshi.k@samsung.com,
Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCHv7 7/9] blk-integrity: use iterator for mapping sg
Date: Wed, 13 Aug 2025 17:55:46 +0200 [thread overview]
Message-ID: <20250813155546.GA14275@lst.de> (raw)
In-Reply-To: <20250813153153.3260897-8-kbusch@meta.com>
On Wed, Aug 13, 2025 at 08:31:51AM -0700, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> Modify blk_rq_map_integrity_sg to use the blk-mq mapping iterator. This
> produces more efficient code and converges the integrity mapping
> implementations to reduce future maintenance burdens.
>
> The function implementation moves from blk-integrity.c to blk-mq-dma.c
> in order to use the types and functions private to that file.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> block/blk-integrity.c | 58 -------------------------------------------
> block/blk-mq-dma.c | 45 +++++++++++++++++++++++++++++++++
> 2 files changed, 45 insertions(+), 58 deletions(-)
>
> diff --git a/block/blk-integrity.c b/block/blk-integrity.c
> index 056b8948369d5..dd97b27366e0e 100644
> --- a/block/blk-integrity.c
> +++ b/block/blk-integrity.c
> @@ -122,64 +122,6 @@ int blk_get_meta_cap(struct block_device *bdev, unsigned int cmd,
> NULL);
> }
>
> -/**
> - * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist
> - * @rq: request to map
> - * @sglist: target scatterlist
> - *
> - * 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() or
> - * rq->nr_integrity_segments.
> - */
> -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;
> - if (sg->length + iv.bv_len > queue_max_segment_size(q))
> - goto new_segment;
> -
> - sg->length += iv.bv_len;
> - } else {
> -new_segment:
> - if (!sg)
> - sg = sglist;
> - else {
> - sg_unmark_end(sg);
> - sg = sg_next(sg);
> - }
> -
> - sg_set_page(sg, iv.bv_page, iv.bv_len, iv.bv_offset);
> - segments++;
> - }
> -
> - prev = 1;
> - ivprv = iv;
> - }
> -
> - 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 > rq->nr_integrity_segments);
> - BUG_ON(segments > queue_max_integrity_segments(q));
> - return segments;
> -}
> -EXPORT_SYMBOL(blk_rq_map_integrity_sg);
> -
> int blk_rq_integrity_map_user(struct request *rq, void __user *ubuf,
> ssize_t bytes)
> {
> diff --git a/block/blk-mq-dma.c b/block/blk-mq-dma.c
> index 60a244a129c3c..660b5e200ccf6 100644
> --- a/block/blk-mq-dma.c
> +++ b/block/blk-mq-dma.c
> @@ -379,4 +379,49 @@ bool blk_rq_integrity_dma_map_iter_next(struct request *req,
> return blk_dma_map_direct(req, dma_dev, iter, &vec);
> }
> EXPORT_SYMBOL_GPL(blk_rq_integrity_dma_map_iter_next);
> +
> +/**
> + * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist
> + * @rq: request to map
> + * @sglist: target scatterlist
> + *
> + * 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() or
> + * rq->nr_integrity_segments.
> + */
> +int blk_rq_map_integrity_sg(struct request *rq, struct scatterlist *sglist)
> +{
> + struct request_queue *q = rq->q;
> + struct scatterlist *sg = NULL;
> + struct bio *bio = rq->bio;
> + unsigned int segments = 0;
> + struct phys_vec vec;
> +
> + struct blk_map_iter iter = {
The empty line above is a bit odd.
Otherwise this looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
next prev parent reply other threads:[~2025-08-13 15:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 15:31 [PATCHv7 0/9] blk dma iter for integrity metadata Keith Busch
2025-08-13 15:31 ` [PATCHv7 1/9] blk-mq-dma: create blk_map_iter type Keith Busch
2025-08-14 10:17 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 2/9] blk-mq-dma: provide the bio_vec array being iterated Keith Busch
2025-08-14 10:17 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 3/9] blk-mq-dma: require unmap caller provide p2p map type Keith Busch
2025-08-13 15:53 ` Christoph Hellwig
2025-08-14 10:18 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 4/9] blk-mq: remove REQ_P2PDMA flag Keith Busch
2025-08-13 15:53 ` Christoph Hellwig
2025-08-14 10:19 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 5/9] blk-mq-dma: move common dma start code to a helper Keith Busch
2025-08-13 15:53 ` Christoph Hellwig
2025-08-14 10:19 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 6/9] blk-mq-dma: add scatter-less integrity data DMA mapping Keith Busch
2025-08-13 15:55 ` Christoph Hellwig
2025-08-14 10:36 ` Kanchan Joshi
2025-08-13 15:31 ` [PATCHv7 7/9] blk-integrity: use iterator for mapping sg Keith Busch
2025-08-13 15:55 ` Christoph Hellwig [this message]
2025-08-13 16:53 ` Martin K. Petersen
2025-08-13 15:31 ` [PATCHv7 8/9] nvme-pci: create common sgl unmapping helper Keith Busch
2025-08-13 15:56 ` Christoph Hellwig
2025-08-13 15:31 ` [PATCHv7 9/9] nvme-pci: convert metadata mapping to dma iter Keith Busch
2025-08-13 16:57 ` [PATCHv7 0/9] blk dma iter for integrity metadata Martin K. Petersen
2025-08-25 7:55 ` Christoph Hellwig
2025-08-25 13:47 ` Jens Axboe
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=20250813155546.GA14275@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.