]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nvme-pci: don't allocate dma_vec for IOVA mappings
authorChristoph Hellwig <hch@lst.de>
Fri, 11 Jul 2025 11:22:50 +0000 (13:22 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 11 Jul 2025 13:46:15 +0000 (07:46 -0600)
Not only do IOVA mappings no need the separate dma_vec tracking, it
also won't free it and thus leak the allocations.

Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping")
Reported-by: Klara Modin <klarasmodin@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Klara Modin <klarasmodin@gmail.com>
Link: https://lore.kernel.org/r/20250711112250.633269-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/host/pci.c

index e236a9091a2e13ade56a00f90a9c045988fcd30d..9055741fffd99f80a11f7d38f8fb398e96db3526 100644 (file)
@@ -745,7 +745,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev,
                return true;
        if (!blk_rq_dma_map_iter_next(req, dma_dev, &iod->dma_state, iter))
                return false;
-       if (dma_need_unmap(dma_dev)) {
+       if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) {
                iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr;
                iod->dma_vecs[iod->nr_dma_vecs].len = iter->len;
                iod->nr_dma_vecs++;
@@ -763,7 +763,7 @@ static blk_status_t nvme_pci_setup_data_prp(struct request *req,
        unsigned int prp_len, i;
        __le64 *prp_list;
 
-       if (dma_need_unmap(nvmeq->dev->dev)) {
+       if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(nvmeq->dev->dev)) {
                iod->dma_vecs = mempool_alloc(nvmeq->dev->dmavec_mempool,
                                GFP_ATOMIC);
                if (!iod->dma_vecs)