Skip to content

Commit 888bd83

Browse files
niklas88bjorn-helgaas
authored andcommitted
s390/pci: Introduce pdev->non_mappable_bars and replace VFIO_PCI_MMAP
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/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 41a0926 commit 888bd83

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

arch/s390/pci/pci.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ int pcibios_device_add(struct pci_dev *pdev)
590590
zpci_zdev_get(zdev);
591591
if (pdev->is_physfn)
592592
pdev->no_vf_scan = 1;
593+
pdev->non_mappable_bars = 1;
593594

594595
zpci_map_resources(pdev);
595596

drivers/pci/pci-sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,10 @@ static int pci_create_resource_files(struct pci_dev *pdev)
12571257
int i;
12581258
int retval;
12591259

1260+
/* Skip devices with non-mappable BARs */
1261+
if (pdev->non_mappable_bars)
1262+
return 0;
1263+
12601264
/* Expose the PCI resources from this device as files */
12611265
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
12621266

drivers/pci/proc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
251251
security_locked_down(LOCKDOWN_PCI_ACCESS))
252252
return -EPERM;
253253

254+
/* Skip devices with non-mappable BARs */
255+
if (dev->non_mappable_bars)
256+
return -EINVAL;
257+
254258
if (fpriv->mmap_state == pci_mmap_io) {
255259
if (!arch_can_pci_mmap_io())
256260
return -EINVAL;

drivers/vfio/pci/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ config VFIO_PCI_CORE
77
select VFIO_VIRQFD
88
select IRQ_BYPASS_MANAGER
99

10-
config VFIO_PCI_MMAP
11-
def_bool y if !S390
12-
depends on VFIO_PCI_CORE
13-
1410
config VFIO_PCI_INTX
1511
def_bool y if !S390
1612
depends on VFIO_PCI_CORE

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
116116

117117
res = &vdev->pdev->resource[bar];
118118

119-
if (!IS_ENABLED(CONFIG_VFIO_PCI_MMAP))
119+
if (vdev->pdev->non_mappable_bars)
120120
goto no_mmap;
121121

122122
if (!(res->flags & IORESOURCE_MEM))

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ struct pci_dev {
476476
unsigned int no_command_memory:1; /* No PCI_COMMAND_MEMORY */
477477
unsigned int rom_bar_overlap:1; /* ROM BAR disable broken */
478478
unsigned int rom_attr_enabled:1; /* Display of ROM attribute enabled? */
479+
unsigned int non_mappable_bars:1; /* BARs can't be mapped to user-space */
479480
pci_dev_flags_t dev_flags;
480481
atomic_t enable_cnt; /* pci_enable_device has been called */
481482

0 commit comments

Comments
 (0)