Skip to contentSkip to conversation

nvme: Use pci_iomap instead of ioremap

PATCH In review Pankaj Raghav 4 participants 9 messages Jan 21, 2022 – Jan 27, 2022 1 message not in the archive NVMe

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20220121143539eucas1p20202376f83b0b499143c18b1434ff000@eucas1p2.samsung.com

#1 lore raw

PATCH 1/1 nvme: Use pci_iomap instead of ioremap

Use the better checked pci_iomap instead of ioremap.

---
 drivers/nvme/host/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/pci.c +1 -1
index d8585df2c2fd..6c8aad9ff7db 100644
@@ -1800,7 +1800,7 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned long size)
 		return -ENOMEM;
 	if (dev->bar)
 		iounmap(dev->bar);
-	dev->bar = ioremap(pci_resource_start(pdev, 0), size);
+	dev->bar = pci_iomap(pdev, 0, size);
 	if (!dev->bar) {
 		dev->bar_mapped_size = 0;
 		return -ENOMEM;
Signature · 1 line
2.25.1
#2 lore raw

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

maintainer
#3 lore raw
Quoted 2 lines · Christoph Hellwig

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

It looks like the action pci_iomap() uses is based on the pci_resource_flags(), and should call the same "ioremap()" function we currently use.

The one problem I see with this, though, is that pci_iomap() will automatically clamp the mapped length to the resource's length, which may be shorter than the potential doorbell registers that the driver thinks it's getting.

#4 lore raw
Quoted 7 lines · Keith Busch
Quoted 2 lines · Christoph Hellwig

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

It looks like the action pci_iomap() uses is based on the pci_resource_flags(), and should call the same "ioremap()" function we currently use.

Yes. But the rule is: use ioremap when you use read*/write*, and use pci_iomap when using ioread/iowrite. But they should never be mixed.

#5 lore raw
In reply to Keith Busch
Quoted 5 lines · Keith Busch

On Wed, Jan 26, 2022 at 05:33:06PM +0100, Christoph Hellwig wrote:
The one problem I see with this, though, is that pci_iomap() will automatically clamp the mapped length to the resource's length, which may be shorter than the potential doorbell registers that the driver thinks it's getting.

The current implementation disallow the size to be greater than the pci_resource_len(pdev, 0).

if (size > pci_resource_len(pdev, 0))

    return -ENOMEM;

So, clamping shouldn't be an issue when we use pci_iomap.

Signature · 2 lines
Regards,
Pankaj
#6 lore raw
In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

Is it because of ioread/iowrite has a conditional check everytime we do a read/write with IO_COND? Or is there any other reason?

--
Pankaj

#7 lore raw
Quoted 5 lines · Pankaj Raghav
Quoted 2 lines · Christoph Hellwig

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

Is it because of ioread/iowrite has a conditional check everytime we do a read/write with IO_COND? Or is there any other reason?

Yes, ioread* and iowrite* are more expensive. And nvme doesn't support port I/O anyway so there is no point.

#8 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Pankaj Raghav
Quoted 2 lines · Christoph Hellwig

pci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.

Is it because of ioread/iowrite has a conditional check everytime we do a read/write with IO_COND? Or is there any other reason?

Yes, ioread* and iowrite* are more expensive. And nvme doesn't support port I/O anyway so there is no point.

Ok.

ioremap has a comment to prefer pci_iomap if the area we are trying to map is a PCI BAR. Does it makes sense then to have a comment in the nvme pci driver as to why ioremap is preferred over pci_iomap?

Signature · 2 lines
Regards,
Pankaj
#9 lore raw
Quoted 3 lines · Pankaj Raghav

ioremap has a comment to prefer pci_iomap if the area we are trying to map is a PCI BAR. Does it makes sense then to have a comment in the nvme pci driver as to why ioremap is preferred over pci_iomap?

I don't think that comment is correct. pci_iomap is not a replacement for ioremap, but an interface that helps drivers that need to transparently deal with MMIO and Port I/O - something that is mostly of historic interest these days.