]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
s390/pci: Introduce pdev->non_mappable_bars and replace VFIO_PCI_MMAP
authorNiklas Schnelle <schnelle@linux.ibm.com>
Wed, 26 Feb 2025 12:07:46 +0000 (13:07 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 21 Mar 2025 19:54:16 +0000 (14:54 -0500)
The ability to map PCI resources to user-space is controlled by global
defines. For vfio there is VFIO_PCI_MMAP which is only disabled on s390 and
controls mapping of PCI resources using vfio-pci with a fallback option via
the pread()/pwrite() interface.

For the PCI core there is ARCH_GENERIC_PCI_MMAP_RESOURCE which enables a
generic implementation for mapping PCI resources plus the newer sysfs
interface. Then there is HAVE_PCI_MMAP which can be used with custom
definitions of pci_mmap_resource_range() and the historical /proc/bus/pci
interface. Both mechanisms are all or nothing.

For s390 mapping PCI resources is possible and useful for testing and
certain applications such as QEMU's vfio-pci based user-space NVMe driver.
For certain devices, however access to PCI resources via mappings to
user-space is not possible and these must be excluded from the general PCI
resource mapping mechanisms.

Introduce pdev->non_mappable_bars to indicate that a PCI device's BARs can
not be accessed via mappings to user-space. In the future this enables
per-device restrictions of PCI resource mapping.

For now, set this flag for all PCI devices on s390 in line with the
existing, general disable of PCI resource mapping. As s390 is the only user
of the VFI_PCI_MMAP Kconfig options this can already be replaced with a
check of this new flag. Also add similar checks in the other code protected
by HAVE_PCI_MMAP respectively ARCH_GENERIC_PCI_MMAP in preparation for
enabling these for supported devices.

Link: https://lore.kernel.org/lkml/20250212132808.08dcf03c.alex.williamson@redhat.com/
Link: https://lore.kernel.org/r/20250226-vfio_pci_mmap-v7-2-c5c0f1d26efd@linux.ibm.com
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
arch/s390/pci/pci.c
drivers/pci/pci-sysfs.c
drivers/pci/proc.c
drivers/vfio/pci/Kconfig
drivers/vfio/pci/vfio_pci_core.c
include/linux/pci.h

index 88f72745fa59e16df26b1563de27594aac954a78..d14b8605a32ce1bc132dff225ac433cf3aae9265 100644 (file)
@@ -590,6 +590,7 @@ int pcibios_device_add(struct pci_dev *pdev)
        zpci_zdev_get(zdev);
        if (pdev->is_physfn)
                pdev->no_vf_scan = 1;
+       pdev->non_mappable_bars = 1;
 
        zpci_map_resources(pdev);
 
index 0e7eb2a42d88d8c21eb9b3999de9609c59410c18..7c0d30f6470bbcda04a7015c63e7e46ca59da7bd 100644 (file)
@@ -1257,6 +1257,10 @@ static int pci_create_resource_files(struct pci_dev *pdev)
        int i;
        int retval;
 
+       /* Skip devices with non-mappable BARs */
+       if (pdev->non_mappable_bars)
+               return 0;
+
        /* Expose the PCI resources from this device as files */
        for (i = 0; i < PCI_STD_NUM_BARS; i++) {
 
index f967709082d654a101039091b5493b2dec5f57b4..9348a0fb808477ca9be80a8b88bbc036565bc411 100644 (file)
@@ -251,6 +251,10 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
            security_locked_down(LOCKDOWN_PCI_ACCESS))
                return -EPERM;
 
+       /* Skip devices with non-mappable BARs */
+       if (dev->non_mappable_bars)
+               return -EINVAL;
+
        if (fpriv->mmap_state == pci_mmap_io) {
                if (!arch_can_pci_mmap_io())
                        return -EINVAL;
index bf50ffa10bdea9e52a9d01cc3d6ee4cade39a08c..c3bcb6911c538286f7985f9c5e938d587fc04b56 100644 (file)
@@ -7,10 +7,6 @@ config VFIO_PCI_CORE
        select VFIO_VIRQFD
        select IRQ_BYPASS_MANAGER
 
-config VFIO_PCI_MMAP
-       def_bool y if !S390
-       depends on VFIO_PCI_CORE
-
 config VFIO_PCI_INTX
        def_bool y if !S390
        depends on VFIO_PCI_CORE
index 586e49efb81be32ccb50ca554a60cec684c37402..c8586d47704c74cf9a5256d65bbf888db72b2f91 100644 (file)
@@ -116,7 +116,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
 
                res = &vdev->pdev->resource[bar];
 
-               if (!IS_ENABLED(CONFIG_VFIO_PCI_MMAP))
+               if (vdev->pdev->non_mappable_bars)
                        goto no_mmap;
 
                if (!(res->flags & IORESOURCE_MEM))
index f9424478a19af2e27747a64261cb8e083a7361f0..5b5ed5ec5f0a726aff75c3e962c37ac60760d7b5 100644 (file)
@@ -476,6 +476,7 @@ struct pci_dev {
        unsigned int    no_command_memory:1;    /* No PCI_COMMAND_MEMORY */
        unsigned int    rom_bar_overlap:1;      /* ROM BAR disable broken */
        unsigned int    rom_attr_enabled:1;     /* Display of ROM attribute enabled? */
+       unsigned int    non_mappable_bars:1;    /* BARs can't be mapped to user-space  */
        pci_dev_flags_t dev_flags;
        atomic_t        enable_cnt;     /* pci_enable_device has been called */