All of lore.kernel.org
 help / color / mirror / Atom feed
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: [PATCHv5 8/8] nvme-pci: convert metadata mapping to dma iter
Date: Sun, 10 Aug 2025 16:27:48 +0200	[thread overview]
Message-ID: <20250810142748.GA4717@lst.de> (raw)
In-Reply-To: <20250808155826.1864803-9-kbusch@meta.com>

On Fri, Aug 08, 2025 at 08:58:26AM -0700, Keith Busch wrote:
>  
>  struct nvme_dma_vec {
> @@ -281,13 +285,14 @@ struct nvme_iod {
>  	u8 nr_descriptors;
>  
>  	unsigned int total_len;
> +	unsigned int meta_total_len;
>  	struct dma_iova_state dma_state;
> +	struct dma_iova_state meta_dma_state;
>  	void *descriptors[NVME_MAX_NR_DESCRIPTORS];
>  	struct nvme_dma_vec *dma_vecs;
>  	unsigned int nr_dma_vecs;
>  
>  	dma_addr_t meta_dma;
> -	struct sg_table meta_sgt;
>  	struct nvme_sgl_desc *meta_descriptor;

Maybe keep the meta fields together as much as we can to ensure they
are in the same cacheline(s)?

> +static void nvme_unmap_metadata(struct request *req)
> +{
> +	struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
> +	enum dma_data_direction dir = rq_dma_dir(req);
> +	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
> +	struct device *dma_dev = nvmeq->dev->dev;
> +
> +	if (iod->flags & IOD_META_MPTR) {
> +		dma_unmap_page(dma_dev, iod->meta_dma,
> +			       rq_integrity_vec(req).bv_len,
> +			       rq_dma_dir(req));
> +		return;
> +	}
> +
> +	if (!blk_rq_dma_unmap(req, dma_dev, &iod->meta_dma_state,
> +				iod->meta_total_len,
> +				iod->flags & IOD_META_P2P_BUS_ADDR)) {
> +		if (nvme_pci_cmd_use_meta_sgl(&iod->cmd))
> +			nvme_free_meta_sgls(iod, dma_dev, dir);
> +		else
> +			dma_unmap_page(dma_dev, iod->meta_dma,
> +				       iod->meta_total_len, dir);
> +	}

IOD_META_MPTR above really should be named IOD_SINGLE_META_SEGMENT as
it's all about avoiding the dma iterator, which could also create a
single segment case handled just above.

>  static blk_status_t nvme_pci_setup_meta_sgls(struct request *req)
>  {
>  	struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
> +	unsigned int entries = req->nr_integrity_segments;
>  	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
> +	struct nvme_dev *dev = nvmeq->dev;
>  	struct nvme_sgl_desc *sg_list;
> +	struct blk_dma_iter iter;
>  	dma_addr_t sgl_dma;
> +	int i = 0;
>  
> +	if (!blk_rq_integrity_dma_map_iter_start(req, dev->dev,
> +						&iod->meta_dma_state, &iter))
> +		return iter.status;
>  
> +	if (iter.p2pdma.map == PCI_P2PDMA_MAP_BUS_ADDR)
> +		iod->flags |= IOD_META_P2P_BUS_ADDR;
> +	else if (blk_rq_dma_map_coalesce(&iod->meta_dma_state))
> +		entries = 1;
> +
> +	if (entries == 1 && !(nvme_req(req)->flags & NVME_REQ_USERCMD)) {
> +		iod->cmd.common.metadata = cpu_to_le64(iter.addr);
> +		iod->meta_total_len = iter.len;
> +		iod->meta_dma = iter.addr;
> +		iod->meta_descriptor = NULL;
> +		return BLK_STS_OK;

Maybe throw in a comment explaining that we fall back to a single metadata
pointer here if we can, and why we don't for passthrough requests?


      reply	other threads:[~2025-08-10 14:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 15:58 [PATCHv5 0/8] blk dma iter for integrity metadata Keith Busch
2025-08-08 15:58 ` [PATCHv5 1/8] blk-mq-dma: introduce blk_map_iter Keith Busch
2025-08-10 14:04   ` Christoph Hellwig
2025-08-11 13:30     ` Keith Busch
2025-08-11 14:05       ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 2/8] blk-mq-dma: provide the bio_vec list being iterated Keith Busch
2025-08-10 14:07   ` Christoph Hellwig
2025-08-11 17:04     ` Keith Busch
2025-08-10 14:09   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 3/8] blk-mq-dma: require unmap caller provide p2p map type Keith Busch
2025-08-10 14:08   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 4/8] blk-mq: remove REQ_P2PDMA flag Keith Busch
2025-08-10 14:08   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 5/8] blk-mq-dma: move common dma start code to a helper Keith Busch
2025-08-10 14:10   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 6/8] blk-mq-dma: add support for mapping integrity metadata Keith Busch
2025-08-10 14:16   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 7/8] nvme-pci: create common sgl unmapping helper Keith Busch
2025-08-10 14:21   ` Christoph Hellwig
2025-08-08 15:58 ` [PATCHv5 8/8] nvme-pci: convert metadata mapping to dma iter Keith Busch
2025-08-10 14:27   ` Christoph Hellwig [this message]

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=20250810142748.GA4717@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.