Skip to contentSkip to conversation

nvme-pci: use blk_map_iter for p2p metadata

PATCH In review Keith Busch 4 participants 4 messages Oct 21, 2025 – Oct 23, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme-pci: use blk_map_iter for p2p metadata

From: Keith Busch <[email protected]>

The dma_map_bvec helper doesn't work for p2p data, so use the same blk_map_iter method that sgl uses for this memory type.

---
 drivers/nvme/host/pci.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +8 -1
index 3c1727df1e36f..4087a665fa2dc 100644
@@ -1085,8 +1085,12 @@ static blk_status_t nvme_pci_setup_meta_sgls(struct request *req)
 	 * descriptor provides an explicit length, so we're relying on that
 	 * mechanism to catch any misunderstandings between the application and
 	 * device.
+	 *
+	 * P2P DMA also needs to use the blk_dma_iter method, so mptr setup
+	 * leverages this routine when that happens.
 	 */
-	if (entries == 1 && !(nvme_req(req)->flags & NVME_REQ_USERCMD)) {
+	if (!nvme_ctrl_meta_sgl_supported(&dev->ctrl) ||
+	    (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;
@@ -1127,6 +1131,9 @@ static blk_status_t nvme_pci_setup_meta_mptr(struct request *req)
 	struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
 	struct bio_vec bv = rq_integrity_vec(req);
 
+	if (is_pci_p2pdma_page(bv.bv_page))
+		return nvme_pci_setup_meta_sgls(req);
+
 	iod->meta_dma = dma_map_bvec(nvmeq->dev->dev, &bv, rq_dma_dir(req), 0);
 	if (dma_mapping_error(nvmeq->dev->dev, iod->meta_dma))
 		return BLK_STS_IOERR;
Signature · 1 line
2.47.3
maintainer
#3 lore raw
Quoted 3 lines · Christoph Hellwig

Although I'd still rename nvme_pci_setup_meta_sgls as in my draft as the name is a bit misleading now.

It's a good idea, folded in and pushed.