All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings
@ 2025-07-11 11:22 Christoph Hellwig
  2025-07-11 13:46 ` Jens Axboe
  2025-07-11 13:46 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Christoph Hellwig @ 2025-07-11 11:22 UTC (permalink / raw)
  To: axboe; +Cc: kbusch, sagi, linux-nvme, linux-block, Klara Modin

Not only do IOVA mappings no need the separate dma_vec tracking, it
also won't free it and thus leak the allocations.

Fixes: 10f50d4127e2 ("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>
---
 drivers/nvme/host/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 6af184f2b73b..3290fd922efb 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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)
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings
  2025-07-11 11:22 [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings Christoph Hellwig
@ 2025-07-11 13:46 ` Jens Axboe
  2025-07-14 11:42   ` Christoph Hellwig
  2025-07-11 13:46 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2025-07-11 13:46 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux-nvme, linux-block, Klara Modin

On 7/11/25 5:22 AM, Christoph Hellwig wrote:
> Not only do IOVA mappings no need the separate dma_vec tracking, it
> also won't free it and thus leak the allocations.
> 
> Fixes: 10f50d4127e2 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping")
         ^^^^^^^^^^^^

b8b7570a7ec872f2a27b775c4f8710ca8a357adf

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings
  2025-07-11 11:22 [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings Christoph Hellwig
  2025-07-11 13:46 ` Jens Axboe
@ 2025-07-11 13:46 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-07-11 13:46 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux-nvme, linux-block, Klara Modin


On Fri, 11 Jul 2025 13:22:50 +0200, Christoph Hellwig wrote:
> Not only do IOVA mappings no need the separate dma_vec tracking, it
> also won't free it and thus leak the allocations.
> 
> 

Applied, thanks!

[1/1] nvme-pci: don't allocate dma_vec for IOVA mappings
      commit: 1bb94ff5ab4be2485884e0a46483f12629f3bb92

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings
  2025-07-11 13:46 ` Jens Axboe
@ 2025-07-14 11:42   ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2025-07-14 11:42 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Christoph Hellwig, kbusch, sagi, linux-nvme, linux-block,
	Klara Modin

On Fri, Jul 11, 2025 at 07:46:08AM -0600, Jens Axboe wrote:
> On 7/11/25 5:22 AM, Christoph Hellwig wrote:
> > Not only do IOVA mappings no need the separate dma_vec tracking, it
> > also won't free it and thus leak the allocations.
> > 
> > Fixes: 10f50d4127e2 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping")
>          ^^^^^^^^^^^^
> 
> b8b7570a7ec872f2a27b775c4f8710ca8a357adf

Ah, sorry.  That was the commit ID in my tree before I sent the original
patch out.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-14 11:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-11 11:22 [PATCH] nvme-pci: don't allocate dma_vec for IOVA mappings Christoph Hellwig
2025-07-11 13:46 ` Jens Axboe
2025-07-14 11:42   ` Christoph Hellwig
2025-07-11 13:46 ` Jens Axboe

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.