nvme: Use pci_iomap instead of ioremap
A message that is not in the archive (sent off-list or not yet received): CGME20220121143539eucas1p20202376f83b0b499143c18b1434ff000@eucas1p2.samsung.com
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
@@ -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
Christoph Hellwig
maintainerpci_iomap goes with the ioread/iowrite accessors which we absolutely do not want in nvme.
Keith Busch
maintainerQuoted 2 lines · Christoph Hellwig
pci_iomapgoes 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.
Christoph Hellwig
maintainerQuoted 7 lines · Keith Busch
Quoted 2 lines · Christoph Hellwig
pci_iomapgoes with the ioread/iowrite accessors which we absolutely do not want in nvme.It looks like the action
pci_iomap()uses is based on thepci_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.
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 thatpci_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
Quoted 2 lines · Christoph Hellwig
pci_iomapgoes 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
Christoph Hellwig
maintainerQuoted 5 lines · Pankaj Raghav
Quoted 2 lines · Christoph Hellwig
pci_iomapgoes 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.
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Pankaj Raghav
Quoted 2 lines · Christoph Hellwig
pci_iomapgoes 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
Christoph Hellwig
maintainerQuoted 3 lines · Pankaj Raghav
ioremaphas a comment to preferpci_iomapif 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 overpci_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.