Skip to contentSkip to conversation

nvme-pci: set the DMA mask earlier

PATCH In review Christoph Hellwig 3 participants 3 messages Feb 13, 2023 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme-pci: set the DMA mask earlier

Set the DMA mask before calling dma_addressing_limited, which depends on it.

Note that this stop checking the return value of dma_set_mask_and_coherent as this function can only fail for masks < 32-bit.

Fixes 3f30a79c2e2c ("nvme-pci: set constant paramters in nvme_pci_alloc_ctrl")
---
 drivers/nvme/host/pci.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/nvme/host/pci.c +5 -7
index c734934c407ccf..e2a8b330ba518a 100644
@@ -2509,18 +2509,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)
 {
 	int result = -ENOMEM;
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
-	int dma_address_bits = 64;
 
 	if (pci_enable_device_mem(pdev))
 		return result;
 
 	pci_set_master(pdev);
 
-	if (dev->ctrl.quirks & NVME_QUIRK_DMA_ADDRESS_BITS_48)
-		dma_address_bits = 48;
-	if (dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(dma_address_bits)))
-		goto disable;
-
 	if (readl(dev->bar + NVME_REG_CSTS) == -1) {
 		result = -ENODEV;
 		goto disable;
@@ -2998,7 +2992,11 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,
 			     quirks);
 	if (ret)
 		goto out_put_device;
-	
+
+	if (dev->ctrl.quirks & NVME_QUIRK_DMA_ADDRESS_BITS_48)
+		dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
+	else
+		dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
 	dma_set_min_align_mask(&pdev->dev, NVME_CTRL_PAGE_SIZE - 1);
 	dma_set_max_seg_size(&pdev->dev, 0xffffffff);
 
Signature · 1 line
2.39.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Set the DMA mask before calling dma_addressing_limited, which depends on it.

Note that this stop checking the return value of dma_set_mask_and_coherent as this function can only fail for masks < 32-bit.

Looks good:

Signature · 1 line
Jens Axboe