Re: [PATCH v1] vfio/pci: Avoid mapping BARs for devices with non-mappable BARs

Matthew Rosato <[email protected]>
Newsgroups org.kernel.vger.linux-s390,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 7/29/26 2:11 PM, Farhan Ali wrote:
> vfio_pci_core_map_bars() calls pci_iomap() to set up BAR resources, but not
> all devices support having their BARs mapped by the CPU. The
> non_mappable_bars flag indicates that a PCI device's BARs cannot be
> accessed by the CPU. The ISM device on s390 is one such device. The BAR
> size for an ISM device is 256 TiB, and attempting to map the BAR will lead
> to warnings:
> 
> vmalloc_node_range for size 281474976714752 failed: Address range
> restricted to 0x2110bab00000 - 0x21903ab00000
> 
> Use pdev->non_mappable_bars to skip pci_iomap() for such devices. This flag
> is set by the PCI core at enumeration time and already serves the same
> purpose in vfio_pci_probe_mmaps().
> 
> Fixes: 05f2a68b407a ("vfio/pci: Set up BAR resources and maps in vfio_pci_core_enable()")
> Reported-by: Christian Borntraeger <[email protected]>
> Signed-off-by: Farhan Ali <[email protected]>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 3f11a9624b9c..6a184588ff23 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -554,6 +554,9 @@ static void vfio_pci_core_map_bars(struct vfio_pci_core_device *vdev)
>  
>  		vdev->barmap[bar] = IOMEM_ERR_PTR(-ENODEV);
>  
> +		if (pdev->non_mappable_bars)
> +			continue;
> +

This would work for the ISM case at least, but I wonder: should we check
vdev->bar_mmap_supported[bar] instead?

My question boils down to: do we still want messages for some of the
cases where we set vdev->bar_mmap_supported[bar] = false in
vfio_pci_probe_mmaps()?

Or should the messages only print when we probed, thought the bar could
be mmap'd (vdev->bar_mmap_supported[bar] == true), and now hit a failure?

Thanks,
Matt

>  		if (!pci_resource_len(pdev, i))
>  			continue;
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.