Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@meta.com>
Cc: linux-nvme@lists.infradead.org, hch@lst.de,
	Keith Busch <kbusch@kernel.org>,
	Leon Romanovsky <leon@kernel.org>
Subject: Re: [PATCH] nvme-pci: always use blk_map_iter for metadata
Date: Tue, 21 Oct 2025 09:19:35 +0200	[thread overview]
Message-ID: <20251021071935.GA31479@lst.de> (raw)
In-Reply-To: <20251020182444.2587155-1-kbusch@meta.com>

On Mon, Oct 20, 2025 at 11:24:44AM -0700, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
> 
> The dma_map_bvec helper doesn't work for p2p data. Rather than special
> case it, just use the same mapping logic so that the driver doesn't need
> to consider memory types.

We already consider the memory types for the data path, so treating the
metadasta path where p2p is even more unlikely sounds like the wrong
tradeoff.  If we have a single segment we just need a single
is_pci_p2pdma_page check to skip direct mapping path.  Something like
this untested patch:

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index c916176bd9f0..c8cfcc64d5ca 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1042,7 +1042,7 @@ static blk_status_t nvme_map_data(struct request *req)
 	return nvme_pci_setup_data_prp(req, &iter);
 }
 
-static blk_status_t nvme_pci_setup_meta_sgls(struct request *req)
+static blk_status_t nvme_pci_setup_meta_iter(struct request *req)
 {
 	struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
 	unsigned int entries = req->nr_integrity_segments;
@@ -1073,7 +1073,9 @@ static blk_status_t nvme_pci_setup_meta_sgls(struct request *req)
 	 * mechanism to catch any misunderstandings between the application and
 	 * device.
 	 */
-	if (entries == 1 && !(nvme_req(req)->flags & NVME_REQ_USERCMD)) {
+	if (entries == 1 &&
+	    !(nvme_req(req)->flags & NVME_REQ_USERCMD) &&
+	    nvme_ctrl_meta_sgl_supported(&dev->ctrl)) {
 		iod->cmd.common.metadata = cpu_to_le64(iter.addr);
 		iod->meta_total_len = iter.len;
 		iod->meta_dma = iter.addr;
@@ -1125,10 +1127,12 @@ static blk_status_t nvme_pci_setup_meta_mptr(struct request *req)
 static blk_status_t nvme_map_metadata(struct request *req)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
+	struct bio_vec bv = req_bvec(req);
 
-	if ((iod->cmd.common.flags & NVME_CMD_SGL_METABUF) &&
-	    nvme_pci_metadata_use_sgls(req))
-		return nvme_pci_setup_meta_sgls(req);
+	if (((iod->cmd.common.flags & NVME_CMD_SGL_METABUF) &&
+	     nvme_pci_metadata_use_sgls(req)) ||
+	    is_pci_p2pdma_page(bv.bv_page))
+		return nvme_pci_setup_meta_iter(req);
 	return nvme_pci_setup_meta_mptr(req);
 }
 


  parent reply	other threads:[~2025-10-21 15:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 18:24 [PATCH] nvme-pci: always use blk_map_iter for metadata Keith Busch
2025-10-20 23:38 ` Chaitanya Kulkarni
2025-10-21  7:19 ` Christoph Hellwig [this message]
2025-10-21 14:42   ` Keith Busch
2025-10-26  7:25     ` Leon Romanovsky
2025-10-27  7:13       ` Christoph Hellwig
2025-10-27 16:09         ` Keith Busch

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=20251021071935.GA31479@lst.de \
    --to=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=leon@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox