diff mbox series

[v6,3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs

Message ID 20250214-vfio_pci_mmap-v6-3-6f300cb63a7e@linux.ibm.com (mailing list archive)
State New
Headers show
Series vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it | expand

Commit Message

Niklas Schnelle Feb. 14, 2025, 1:10 p.m. UTC
So far s390 does not select HAVE_PCI_MMAP. This is partly because access
to mapped PCI resources requires special PCI load/store instructions and
prior to commit 71ba41c9b1d9 ("s390/pci: provide support for MIO
instructions") even required use of special syscalls. This really isn't
a showstopper though and in fact lack of HAVE_PCI_MMAP has previously
caused extra work when testing and debugging PCI devices and drivers.

Another issue when looking at HAVE_PCI_MMAP however comes from the
virtual ISM devices. These present 256 TiB BARs which really can't be
accessed via a mapping to user-space.

Now, the newly added pdev->non_mappable_bars flag provides a way to
exclude devices whose BARs can't be mapped to user-space including the
s390 ISM device. So honor this flag also in the mmap() paths protected
by HAVE_PCI_MMMAP and with the ISM device thus excluded enable
HAVE_PCI_MMAP for s390.

Note that most distributions enable CONFIG_IO_STRICT_DEVMEM=y and
require unbinding drivers before resources can be mapped. This makes it
extremely unlikely that any existing programs on s390 will now suddenly
fail after succeeding to mmap() resources and then trying to access the
mapping without use of the special PCI instructions.

Link: https://lore.kernel.org/lkml/20250212132808.08dcf03c.alex.williamson@redhat.com/
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 arch/s390/include/asm/pci.h | 4 ++++
 drivers/pci/pci-sysfs.c     | 4 ++++
 drivers/pci/proc.c          | 4 ++++
 3 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
index 474e1f8d1d3c2fc5685b459cc68b67ac651ea3e9..518dd71a78c83c74dc7b29778e299d5c8cabcc59 100644
--- a/arch/s390/include/asm/pci.h
+++ b/arch/s390/include/asm/pci.h
@@ -11,6 +11,10 @@ 
 #include <asm/pci_insn.h>
 #include <asm/sclp.h>
 
+#define HAVE_PCI_MMAP			1
+#define ARCH_GENERIC_PCI_MMAP_RESOURCE	1
+#define arch_can_pci_mmap_wc()		1
+
 #define PCIBIOS_MIN_IO		0x1000
 #define PCIBIOS_MIN_MEM		0x10000000
 
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index b46ce1a2c5542cdea0a3f9df324434fdb7e8a4d2..7373eca0a4943bf896b4a177124e0d4572baec2b 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -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++) {
 
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index f967709082d654a101039091b5493b2dec5f57b4..9348a0fb808477ca9be80a8b88bbc036565bc411 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -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;