* [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it
@ 2025-02-14 13:10 Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling Niklas Schnelle
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-14 13:10 UTC (permalink / raw)
To: Bjorn Helgaas, Christoph Hellwig, Alexandra Winter,
Alex Williamson, Gerd Bayer, Matthew Rosato, Jason Gunthorpe,
Thorsten Winkler, Bjorn Helgaas
Cc: Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci, Niklas Schnelle
With the introduction of memory I/O (MIO) instructions enbaled in commit
71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s390
gained support for direct user-space access to mapped PCI resources.
Even without those however user-space can access mapped PCI resources
via the s390 specific MMIO syscalls. There is thus nothing fundamentally
preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space
drivers to access PCI resources without going through the pread()
interface. To actually enable VFIO_PCI_MMAP a few issues need fixing
however.
Firstly the s390 MMIO syscalls do not cause a page fault when
follow_pte() fails due to the page not being present. This breaks
vfio-pci's mmap() handling which lazily maps on first access.
Secondly on s390 there is a virtual PCI device called ISM which has
a few oddities. For one it claims to have a 256 TiB PCI BAR (not a typo)
which leads to any attempt to mmap() it fail with the following message:
vmap allocation for size 281474976714752 failed: use vmalloc=<size> to increase size
Even if one tried to map this BAR only partially the mapping would not
be usable on systems with MIO support enabled. So just block mapping
BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve this
by keeping the vfio-pci mmap() blocking behavior around for this
specific device via a PCI quirk and new pdev->non_mappable_bars
flag.
As noted by Alex Williamson With mmap() enabled in vfio-pci it makes
sense to also enable HAVE_PCI_MMAP with the same restriction for pdev->
non_mappable_bars. So this is added in patch 3 and I tested this with
another small test program.
Note:
For your convenience the code is also available in the tagged
b4/vfio_pci_mmap branch on my git.kernel.org site below:
https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/
Thanks,
Niklas
Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6beff969.camel@linux.ibm.com/
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
Changes in v6:
- Add a patch to also enable PCI resource mmap() via sysfs and proc
exlcluding pdev->non_mappable_bars devices (Alex Williamson)
- Added Acks
- Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0-633ca5e056da@linux.ibm.com
Changes in v5:
- Instead of relying on the existing pdev->non_compliant_bars introduce
a new pdev->non_mappable_bars flag. This replaces the VFIO_PCI_MMAP
Kconfig option and makes it per-device. This is necessary to not break
upcoming vfio-pci use of ISM devices (Julian Ruess)
- Squash the removal of VFIO_PCI_MMAP into the second commit as this
is now where its only use goes away.
- Switch to using follow_pfnmap_start() in MMIO syscall page fault
handling to match upstream changes
- Dropped R-b's because the changes are significant
- Link to v4: https://lore.kernel.org/r/20240626-vfio_pci_mmap-v4-0-7f038870f022@linux.ibm.com
Changes in v4:
- Overhauled and split up patch 2 which caused errors on ppc due to
unexported __kernel_io_end. Replaced it with a minimal s390 PCI fixup
harness to set pdev->non_compliant_bars for ISM plus ignoring devices
with this flag in vfio-pci. Idea for using PCI quirks came from
Christoph Hellwig, thanks. Dropped R-bs for patch 2 accordingly.
- Rebased on v6.10-rc5 which includes the vfio-pci mmap fault handler
fix to the issue I stumbled over independently in v3
- Link to v3: https://lore.kernel.org/r/20240529-vfio_pci_mmap-v3-0-cd217d019218@linux.ibm.com
Changes in v3:
- Rebased on v6.10-rc1 requiring change to follow_pte() call
- Use current->mm for fixup_user_fault() as seems more common
- Collected new trailers
- Link to v2: https://lore.kernel.org/r/20240523-vfio_pci_mmap-v2-0-0dc6c139a4f1@linux.ibm.com
Changes in v2:
- Changed last patch to remove VFIO_PCI_MMAP instead of just enabling it
for s390 as it is unconditionally true with s390 supporting PCI resource mmap() (Jason)
- Collected R-bs from Jason
- Link to v1: https://lore.kernel.org/r/20240521-vfio_pci_mmap-v1-0-2f6315e0054e@linux.ibm.com
---
Niklas Schnelle (3):
s390/pci: Fix s390_mmio_read/write syscall page fault handling
PCI: s390: Support mmap() of BARs and replace VFIO_PCI_MMAP by a device flag
PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs
arch/s390/Kconfig | 4 +---
arch/s390/include/asm/pci.h | 4 ++++
arch/s390/pci/Makefile | 2 +-
arch/s390/pci/pci_fixup.c | 23 +++++++++++++++++++++++
arch/s390/pci/pci_mmio.c | 18 +++++++++++++-----
drivers/pci/pci-sysfs.c | 4 ++++
drivers/pci/proc.c | 4 ++++
drivers/s390/net/ism_drv.c | 1 -
drivers/vfio/pci/Kconfig | 4 ----
drivers/vfio/pci/vfio_pci_core.c | 2 +-
include/linux/pci.h | 1 +
include/linux/pci_ids.h | 1 +
12 files changed, 53 insertions(+), 15 deletions(-)
---
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
change-id: 20240503-vfio_pci_mmap-1549e3d02ca7
Best regards,
--
Niklas Schnelle
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling
2025-02-14 13:10 [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Niklas Schnelle
@ 2025-02-14 13:10 ` Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 2/3] PCI: s390: Support mmap() of BARs and replace VFIO_PCI_MMAP by a device flag Niklas Schnelle
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-14 13:10 UTC (permalink / raw)
To: Bjorn Helgaas, Christoph Hellwig, Alexandra Winter,
Alex Williamson, Gerd Bayer, Matthew Rosato, Jason Gunthorpe,
Thorsten Winkler, Bjorn Helgaas
Cc: Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci, Niklas Schnelle
The s390 MMIO syscalls when using the classic PCI instructions do not
cause a page fault when follow_pfnmap_start() fails due to the page not
being present. Besides being a general deficiency this breaks vfio-pci's
mmap() handling once VFIO_PCI_MMAP gets enabled as this lazily maps on
first access. Fix this by following a failed follow_pfnmap_start() with
fixup_user_page() and retrying the follow_pfnmap_start(). Also fix
a VM_READ vs VM_WRITE mixup in the read syscall.
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
arch/s390/pci/pci_mmio.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/arch/s390/pci/pci_mmio.c b/arch/s390/pci/pci_mmio.c
index 46f99dc164ade4ca10f170cd66bdb648f92aa904..1997d9b7965df3b9b6019c7537028cd29d52fc13 100644
--- a/arch/s390/pci/pci_mmio.c
+++ b/arch/s390/pci/pci_mmio.c
@@ -175,8 +175,12 @@ SYSCALL_DEFINE3(s390_pci_mmio_write, unsigned long, mmio_addr,
args.address = mmio_addr;
args.vma = vma;
ret = follow_pfnmap_start(&args);
- if (ret)
- goto out_unlock_mmap;
+ if (ret) {
+ fixup_user_fault(current->mm, mmio_addr, FAULT_FLAG_WRITE, NULL);
+ ret = follow_pfnmap_start(&args);
+ if (ret)
+ goto out_unlock_mmap;
+ }
io_addr = (void __iomem *)((args.pfn << PAGE_SHIFT) |
(mmio_addr & ~PAGE_MASK));
@@ -315,14 +319,18 @@ SYSCALL_DEFINE3(s390_pci_mmio_read, unsigned long, mmio_addr,
if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
goto out_unlock_mmap;
ret = -EACCES;
- if (!(vma->vm_flags & VM_WRITE))
+ if (!(vma->vm_flags & VM_READ))
goto out_unlock_mmap;
args.vma = vma;
args.address = mmio_addr;
ret = follow_pfnmap_start(&args);
- if (ret)
- goto out_unlock_mmap;
+ if (ret) {
+ fixup_user_fault(current->mm, mmio_addr, 0, NULL);
+ ret = follow_pfnmap_start(&args);
+ if (ret)
+ goto out_unlock_mmap;
+ }
io_addr = (void __iomem *)((args.pfn << PAGE_SHIFT) |
(mmio_addr & ~PAGE_MASK));
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 2/3] PCI: s390: Support mmap() of BARs and replace VFIO_PCI_MMAP by a device flag
2025-02-14 13:10 [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling Niklas Schnelle
@ 2025-02-14 13:10 ` Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs Niklas Schnelle
2025-02-24 20:53 ` [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Bjorn Helgaas
3 siblings, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-14 13:10 UTC (permalink / raw)
To: Bjorn Helgaas, Christoph Hellwig, Alexandra Winter,
Alex Williamson, Gerd Bayer, Matthew Rosato, Jason Gunthorpe,
Thorsten Winkler, Bjorn Helgaas
Cc: Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci, Niklas Schnelle
On s390 there is a virtual PCI device called ISM which has a few
peculiarities. For one, it presents a 256 TiB PCI BAR whose size leads
to any attempt to ioremap() the whole BAR failing. This is problematic
since mapping the whole BAR is the default behavior of for example
vfio-pci in combination with QEMU and VFIO_PCI_MMAP enabled.
Even if one tried to map this BAR only partially, the mapping would not
be usable without extra precautions on systems with MIO support enabled.
This is because of another oddity, in that this virtual PCI device does
not support the newer memory I/O (MIO) PCI instructions and legacy PCI
instructions are not accessible through writeq()/readq() when MIO is in
use.
In short the ISM device's BAR is not accessible through memory mappings.
Indicate this by introducing a new non_mappable_bars flag for the ISM
device and set it using a PCI quirk. Use this flag instead of the
VFIO_PCI_MMAP Kconfig option to block mapping with vfio-pci. This was
the only use of the Kconfig option so remove it.
As s390x has no PCI quirk handling add basic support modeled after x86's
arch/x86/pci/fixup.c and move the ISM device's PCI ID to the common
header to make it accessible. Also enable CONFIG_PCI_QUIRKS whenever
CONFIG_PCI is enabled.
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
arch/s390/Kconfig | 4 +---
arch/s390/pci/Makefile | 2 +-
arch/s390/pci/pci_fixup.c | 23 +++++++++++++++++++++++
drivers/s390/net/ism_drv.c | 1 -
drivers/vfio/pci/Kconfig | 4 ----
drivers/vfio/pci/vfio_pci_core.c | 2 +-
include/linux/pci.h | 1 +
include/linux/pci_ids.h | 1 +
8 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 9c9ec08d78c71b4d227beeafab1b82d6434cb5c7..e48741e001476f765e8aba0037a1b386df393683 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -41,9 +41,6 @@ config AUDIT_ARCH
config NO_IOPORT_MAP
def_bool y
-config PCI_QUIRKS
- def_bool n
-
config ARCH_SUPPORTS_UPROBES
def_bool y
@@ -258,6 +255,7 @@ config S390
select PCI_DOMAINS if PCI
select PCI_MSI if PCI
select PCI_MSI_ARCH_FALLBACKS if PCI_MSI
+ select PCI_QUIRKS if PCI
select SPARSE_IRQ
select SWIOTLB
select SYSCTL_EXCEPTION_TRACE
diff --git a/arch/s390/pci/Makefile b/arch/s390/pci/Makefile
index df73c5182990ad3ae4ed5a785953011feb9a093c..1810e0944a4ed9d31261788f0f6eb341e5316546 100644
--- a/arch/s390/pci/Makefile
+++ b/arch/s390/pci/Makefile
@@ -5,6 +5,6 @@
obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_clp.o \
pci_event.o pci_debug.o pci_insn.o pci_mmio.o \
- pci_bus.o pci_kvm_hook.o pci_report.o
+ pci_bus.o pci_kvm_hook.o pci_report.o pci_fixup.o
obj-$(CONFIG_PCI_IOV) += pci_iov.o
obj-$(CONFIG_SYSFS) += pci_sysfs.o
diff --git a/arch/s390/pci/pci_fixup.c b/arch/s390/pci/pci_fixup.c
new file mode 100644
index 0000000000000000000000000000000000000000..35688b645098329f082d0c40cc8c59231c390eaa
--- /dev/null
+++ b/arch/s390/pci/pci_fixup.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Exceptions for specific devices,
+ *
+ * Copyright IBM Corp. 2025
+ *
+ * Author(s):
+ * Niklas Schnelle <schnelle@linux.ibm.com>
+ */
+#include <linux/pci.h>
+
+static void zpci_ism_bar_no_mmap(struct pci_dev *pdev)
+{
+ /*
+ * ISM's BAR is special. Drivers written for ISM know
+ * how to handle this but others need to be aware of their
+ * special nature e.g. to prevent attempts to mmap() it.
+ */
+ pdev->non_mappable_bars = 1;
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM,
+ PCI_DEVICE_ID_IBM_ISM,
+ zpci_ism_bar_no_mmap);
diff --git a/drivers/s390/net/ism_drv.c b/drivers/s390/net/ism_drv.c
index e36e3ea165d3b2b01d68e53634676cb8c2c40220..d32633ed9fa80c1764724f493b363bfd6cb4f9cf 100644
--- a/drivers/s390/net/ism_drv.c
+++ b/drivers/s390/net/ism_drv.c
@@ -20,7 +20,6 @@
MODULE_DESCRIPTION("ISM driver for s390");
MODULE_LICENSE("GPL");
-#define PCI_DEVICE_ID_IBM_ISM 0x04ED
#define DRV_NAME "ism"
static const struct pci_device_id ism_device_table[] = {
diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
index bf50ffa10bdea9e52a9d01cc3d6ee4cade39a08c..c3bcb6911c538286f7985f9c5e938d587fc04b56 100644
--- a/drivers/vfio/pci/Kconfig
+++ b/drivers/vfio/pci/Kconfig
@@ -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
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 586e49efb81be32ccb50ca554a60cec684c37402..c8586d47704c74cf9a5256d65bbf888db72b2f91 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -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))
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 47b31ad724fa5bf7abd7c3dc572947551b0f2148..7192b9d78d7e337ce6144190325458fe3c0f1696 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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 */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index de5deb1a0118fcf56570d461cbe7a501d4bd0da3..e0cdc290dff5cef39ba491d49008c4153b9b9136 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -518,6 +518,7 @@
#define PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM 0x0251
#define PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE 0x0361
#define PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL 0x252
+#define PCI_DEVICE_ID_IBM_ISM 0x04ed
#define PCI_SUBVENDOR_ID_IBM 0x1014
#define PCI_SUBDEVICE_ID_IBM_SATURN_SERIAL_ONE_PORT 0x03d4
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs
2025-02-14 13:10 [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 2/3] PCI: s390: Support mmap() of BARs and replace VFIO_PCI_MMAP by a device flag Niklas Schnelle
@ 2025-02-14 13:10 ` Niklas Schnelle
2025-02-24 11:41 ` Niklas Schnelle
2025-02-24 20:53 ` [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Bjorn Helgaas
3 siblings, 1 reply; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-14 13:10 UTC (permalink / raw)
To: Bjorn Helgaas, Christoph Hellwig, Alexandra Winter,
Alex Williamson, Gerd Bayer, Matthew Rosato, Jason Gunthorpe,
Thorsten Winkler, Bjorn Helgaas
Cc: Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci, Niklas Schnelle
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 --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;
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs
2025-02-14 13:10 ` [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs Niklas Schnelle
@ 2025-02-24 11:41 ` Niklas Schnelle
0 siblings, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-24 11:41 UTC (permalink / raw)
To: Bjorn Helgaas, Christoph Hellwig, Alexandra Winter,
Alex Williamson, Gerd Bayer, Matthew Rosato, Jason Gunthorpe,
Thorsten Winkler, Bjorn Helgaas
Cc: Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci
On Fri, 2025-02-14 at 14:10 +0100, Niklas Schnelle wrote:
> 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 --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;
>
Gentle ping
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it
2025-02-14 13:10 [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Niklas Schnelle
` (2 preceding siblings ...)
2025-02-14 13:10 ` [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs Niklas Schnelle
@ 2025-02-24 20:53 ` Bjorn Helgaas
2025-02-25 8:59 ` Niklas Schnelle
3 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2025-02-24 20:53 UTC (permalink / raw)
To: Niklas Schnelle
Cc: Christoph Hellwig, Alexandra Winter, Alex Williamson, Gerd Bayer,
Matthew Rosato, Jason Gunthorpe, Thorsten Winkler, Bjorn Helgaas,
Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci
On Fri, Feb 14, 2025 at 02:10:51PM +0100, Niklas Schnelle wrote:
> With the introduction of memory I/O (MIO) instructions enbaled in commit
> 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s390
> gained support for direct user-space access to mapped PCI resources.
> Even without those however user-space can access mapped PCI resources
> via the s390 specific MMIO syscalls. There is thus nothing fundamentally
> preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space
> drivers to access PCI resources without going through the pread()
> interface. To actually enable VFIO_PCI_MMAP a few issues need fixing
> however.
>
> Firstly the s390 MMIO syscalls do not cause a page fault when
> follow_pte() fails due to the page not being present. This breaks
> vfio-pci's mmap() handling which lazily maps on first access.
>
> Secondly on s390 there is a virtual PCI device called ISM which has
> a few oddities. For one it claims to have a 256 TiB PCI BAR (not a typo)
> which leads to any attempt to mmap() it fail with the following message:
>
> vmap allocation for size 281474976714752 failed: use vmalloc=<size> to increase size
>
> Even if one tried to map this BAR only partially the mapping would not
> be usable on systems with MIO support enabled. So just block mapping
> BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve this
> by keeping the vfio-pci mmap() blocking behavior around for this
> specific device via a PCI quirk and new pdev->non_mappable_bars
> flag.
>
> As noted by Alex Williamson With mmap() enabled in vfio-pci it makes
> sense to also enable HAVE_PCI_MMAP with the same restriction for pdev->
> non_mappable_bars. So this is added in patch 3 and I tested this with
> another small test program.
>
> Note:
> For your convenience the code is also available in the tagged
> b4/vfio_pci_mmap branch on my git.kernel.org site below:
> https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/
>
> Thanks,
> Niklas
>
> Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6beff969.camel@linux.ibm.com/
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> ---
> Changes in v6:
> - Add a patch to also enable PCI resource mmap() via sysfs and proc
> exlcluding pdev->non_mappable_bars devices (Alex Williamson)
> - Added Acks
> - Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0-633ca5e056da@linux.ibm.com
I think the series would be more readable if patch 2/3 included all
the core changes (adding pci_dev.non_mappable_bars, the 3/3
pci-sysfs.c and proc.c changes to test it, and I suppose the similar
vfio_pci_core.c change), and we moved all the s390 content from 2/3 to
3/3.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it
2025-02-24 20:53 ` [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Bjorn Helgaas
@ 2025-02-25 8:59 ` Niklas Schnelle
2025-02-25 20:35 ` Bjorn Helgaas
0 siblings, 1 reply; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-25 8:59 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Christoph Hellwig, Alexandra Winter, Alex Williamson, Gerd Bayer,
Matthew Rosato, Jason Gunthorpe, Thorsten Winkler, Bjorn Helgaas,
Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci
On Mon, 2025-02-24 at 14:53 -0600, Bjorn Helgaas wrote:
> On Fri, Feb 14, 2025 at 02:10:51PM +0100, Niklas Schnelle wrote:
> > With the introduction of memory I/O (MIO) instructions enbaled in commit
> > 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s390
> > gained support for direct user-space access to mapped PCI resources.
> > Even without those however user-space can access mapped PCI resources
> > via the s390 specific MMIO syscalls. There is thus nothing fundamentally
> > preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space
> > drivers to access PCI resources without going through the pread()
> > interface. To actually enable VFIO_PCI_MMAP a few issues need fixing
> > however.
> >
> > Firstly the s390 MMIO syscalls do not cause a page fault when
> > follow_pte() fails due to the page not being present. This breaks
> > vfio-pci's mmap() handling which lazily maps on first access.
> >
> > Secondly on s390 there is a virtual PCI device called ISM which has
> > a few oddities. For one it claims to have a 256 TiB PCI BAR (not a typo)
> > which leads to any attempt to mmap() it fail with the following message:
> >
> > vmap allocation for size 281474976714752 failed: use vmalloc=<size> to increase size
> >
> > Even if one tried to map this BAR only partially the mapping would not
> > be usable on systems with MIO support enabled. So just block mapping
> > BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve this
> > by keeping the vfio-pci mmap() blocking behavior around for this
> > specific device via a PCI quirk and new pdev->non_mappable_bars
> > flag.
> >
> > As noted by Alex Williamson With mmap() enabled in vfio-pci it makes
> > sense to also enable HAVE_PCI_MMAP with the same restriction for pdev->
> > non_mappable_bars. So this is added in patch 3 and I tested this with
> > another small test program.
> >
> > Note:
> > For your convenience the code is also available in the tagged
> > b4/vfio_pci_mmap branch on my git.kernel.org site below:
> > https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/
> >
> > Thanks,
> > Niklas
> >
> > Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6beff969.camel@linux.ibm.com/
> > Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> > ---
> > Changes in v6:
> > - Add a patch to also enable PCI resource mmap() via sysfs and proc
> > exlcluding pdev->non_mappable_bars devices (Alex Williamson)
> > - Added Acks
> > - Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0-633ca5e056da@linux.ibm.com
>
> I think the series would be more readable if patch 2/3 included all
> the core changes (adding pci_dev.non_mappable_bars, the 3/3
> pci-sysfs.c and proc.c changes to test it, and I suppose the similar
> vfio_pci_core.c change), and we moved all the s390 content from 2/3 to
> 3/3.
Maybe we could do the following:
1/3: As is
2/3: Introduces pdev->non_mappable_bars and the checks in vfio and
proc.c/pci-sysfs.c. To make the flag handle the vfio case with
VFIO_PCI_MMAP gone, a one-line change in s390 will set pdev-
>non_mappable_bars = 1 for all PCI devices.
3/3: Changes setting pdev->non_mappable_bars = 1 in s390 to only the
ISM device using the quirk handling and adds HAVE_PCI_MMAP.
Thanks,
Niklas
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it
2025-02-25 8:59 ` Niklas Schnelle
@ 2025-02-25 20:35 ` Bjorn Helgaas
2025-02-26 8:28 ` Niklas Schnelle
0 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2025-02-25 20:35 UTC (permalink / raw)
To: Niklas Schnelle
Cc: Christoph Hellwig, Alexandra Winter, Alex Williamson, Gerd Bayer,
Matthew Rosato, Jason Gunthorpe, Thorsten Winkler, Bjorn Helgaas,
Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci
On Tue, Feb 25, 2025 at 09:59:13AM +0100, Niklas Schnelle wrote:
> On Mon, 2025-02-24 at 14:53 -0600, Bjorn Helgaas wrote:
> > On Fri, Feb 14, 2025 at 02:10:51PM +0100, Niklas Schnelle wrote:
> > > With the introduction of memory I/O (MIO) instructions enbaled in commit
> > > 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s390
> > > gained support for direct user-space access to mapped PCI resources.
> > > Even without those however user-space can access mapped PCI resources
> > > via the s390 specific MMIO syscalls. There is thus nothing fundamentally
> > > preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space
> > > drivers to access PCI resources without going through the pread()
> > > interface. To actually enable VFIO_PCI_MMAP a few issues need fixing
> > > however.
> > >
> > > Firstly the s390 MMIO syscalls do not cause a page fault when
> > > follow_pte() fails due to the page not being present. This breaks
> > > vfio-pci's mmap() handling which lazily maps on first access.
> > >
> > > Secondly on s390 there is a virtual PCI device called ISM which has
> > > a few oddities. For one it claims to have a 256 TiB PCI BAR (not a typo)
> > > which leads to any attempt to mmap() it fail with the following message:
> > >
> > > vmap allocation for size 281474976714752 failed: use vmalloc=<size> to increase size
> > >
> > > Even if one tried to map this BAR only partially the mapping would not
> > > be usable on systems with MIO support enabled. So just block mapping
> > > BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve this
> > > by keeping the vfio-pci mmap() blocking behavior around for this
> > > specific device via a PCI quirk and new pdev->non_mappable_bars
> > > flag.
> > >
> > > As noted by Alex Williamson With mmap() enabled in vfio-pci it makes
> > > sense to also enable HAVE_PCI_MMAP with the same restriction for pdev->
> > > non_mappable_bars. So this is added in patch 3 and I tested this with
> > > another small test program.
> > >
> > > Note:
> > > For your convenience the code is also available in the tagged
> > > b4/vfio_pci_mmap branch on my git.kernel.org site below:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/
> > >
> > > Thanks,
> > > Niklas
> > >
> > > Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6beff969.camel@linux.ibm.com/
> > > Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> > > ---
> > > Changes in v6:
> > > - Add a patch to also enable PCI resource mmap() via sysfs and proc
> > > exlcluding pdev->non_mappable_bars devices (Alex Williamson)
> > > - Added Acks
> > > - Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0-633ca5e056da@linux.ibm.com
> >
> > I think the series would be more readable if patch 2/3 included all
> > the core changes (adding pci_dev.non_mappable_bars, the 3/3
> > pci-sysfs.c and proc.c changes to test it, and I suppose the similar
> > vfio_pci_core.c change), and we moved all the s390 content from 2/3 to
> > 3/3.
>
> Maybe we could do the following:
>
> 1/3: As is
>
> 2/3: Introduces pdev->non_mappable_bars and the checks in vfio and
> proc.c/pci-sysfs.c. To make the flag handle the vfio case with
> VFIO_PCI_MMAP gone, a one-line change in s390 will set pdev-
> >non_mappable_bars = 1 for all PCI devices.
What if you moved the vfio_pci_core.c change to patch 3? Then I think
patch 2 would do nothing at all (since there's nothing that sets
non_mappable_bars), and all the s390 stuff would be in patch 3?
Not sure if that's possible, but I think it's a little confusing to
have the s390 changes split across patch 2 and 3.
> 3/3: Changes setting pdev->non_mappable_bars = 1 in s390 to only the
> ISM device using the quirk handling and adds HAVE_PCI_MMAP.
>
> Thanks,
> Niklas
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it
2025-02-25 20:35 ` Bjorn Helgaas
@ 2025-02-26 8:28 ` Niklas Schnelle
0 siblings, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2025-02-26 8:28 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Christoph Hellwig, Alexandra Winter, Alex Williamson, Gerd Bayer,
Matthew Rosato, Jason Gunthorpe, Thorsten Winkler, Bjorn Helgaas,
Julian Ruess, Halil Pasic, Christian Borntraeger, Sven Schnelle,
Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
linux-s390, linux-kernel, kvm, linux-pci
On Tue, 2025-02-25 at 14:35 -0600, Bjorn Helgaas wrote:
> On Tue, Feb 25, 2025 at 09:59:13AM +0100, Niklas Schnelle wrote:
> > On Mon, 2025-02-24 at 14:53 -0600, Bjorn Helgaas wrote:
> > > On Fri, Feb 14, 2025 at 02:10:51PM +0100, Niklas Schnelle wrote:
> > > > With the introduction of memory I/O (MIO) instructions enbaled in commit
> > > > 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s390
> > > > gained support for direct user-space access to mapped PCI resources.
> > > > Even without those however user-space can access mapped PCI resources
> > > > via the s390 specific MMIO syscalls. There is thus nothing fundamentally
> > > > preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space
> > > > drivers to access PCI resources without going through the pread()
> > > > interface. To actually enable VFIO_PCI_MMAP a few issues need fixing
> > > > however.
> > > >
> > > > Firstly the s390 MMIO syscalls do not cause a page fault when
> > > > follow_pte() fails due to the page not being present. This breaks
> > > > vfio-pci's mmap() handling which lazily maps on first access.
> > > >
> > > > Secondly on s390 there is a virtual PCI device called ISM which has
> > > > a few oddities. For one it claims to have a 256 TiB PCI BAR (not a typo)
> > > > which leads to any attempt to mmap() it fail with the following message:
> > > >
> > > > vmap allocation for size 281474976714752 failed: use vmalloc=<size> to increase size
> > > >
> > > > Even if one tried to map this BAR only partially the mapping would not
> > > > be usable on systems with MIO support enabled. So just block mapping
> > > > BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve this
> > > > by keeping the vfio-pci mmap() blocking behavior around for this
> > > > specific device via a PCI quirk and new pdev->non_mappable_bars
> > > > flag.
> > > >
> > > > As noted by Alex Williamson With mmap() enabled in vfio-pci it makes
> > > > sense to also enable HAVE_PCI_MMAP with the same restriction for pdev->
> > > > non_mappable_bars. So this is added in patch 3 and I tested this with
> > > > another small test program.
> > > >
> > > > Note:
> > > > For your convenience the code is also available in the tagged
> > > > b4/vfio_pci_mmap branch on my git.kernel.org site below:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/
> > > >
> > > > Thanks,
> > > > Niklas
> > > >
> > > > Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6beff969.camel@linux.ibm.com/
> > > > Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> > > > ---
> > > > Changes in v6:
> > > > - Add a patch to also enable PCI resource mmap() via sysfs and proc
> > > > exlcluding pdev->non_mappable_bars devices (Alex Williamson)
> > > > - Added Acks
> > > > - Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0-633ca5e056da@linux.ibm.com
> > >
> > > I think the series would be more readable if patch 2/3 included all
> > > the core changes (adding pci_dev.non_mappable_bars, the 3/3
> > > pci-sysfs.c and proc.c changes to test it, and I suppose the similar
> > > vfio_pci_core.c change), and we moved all the s390 content from 2/3 to
> > > 3/3.
> >
> > Maybe we could do the following:
> >
> > 1/3: As is
> >
> > 2/3: Introduces pdev->non_mappable_bars and the checks in vfio and
> > proc.c/pci-sysfs.c. To make the flag handle the vfio case with
> > VFIO_PCI_MMAP gone, a one-line change in s390 will set pdev-
> > > non_mappable_bars = 1 for all PCI devices.
>
> What if you moved the vfio_pci_core.c change to patch 3? Then I think
> patch 2 would do nothing at all (since there's nothing that sets
> non_mappable_bars), and all the s390 stuff would be in patch 3?
>
> Not sure if that's possible, but I think it's a little confusing to
> have the s390 changes split across patch 2 and 3.
I'm not really a fan of having a completely unused flag, even in an
intermediate commit. I've edited the commits yesterday and with this
approach the s390 specific part of 2/3 really is just the below hunk:
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 88f72745fa59..d14b8605a32c 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -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);
That added line then gets deleted again in 3/3. I think this makes it
pretty logical, with patch 2/3 we set it for all PCI devices giving the
existing behavior and by pdev->non_mappable_bars replacing the "y if
S390" of VFIO_PCI_MMAP, then 3/3 narrows it down to just the ISM
device.
Thanks,
Niklas
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-02-26 8:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 13:10 [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 2/3] PCI: s390: Support mmap() of BARs and replace VFIO_PCI_MMAP by a device flag Niklas Schnelle
2025-02-14 13:10 ` [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs Niklas Schnelle
2025-02-24 11:41 ` Niklas Schnelle
2025-02-24 20:53 ` [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it Bjorn Helgaas
2025-02-25 8:59 ` Niklas Schnelle
2025-02-25 20:35 ` Bjorn Helgaas
2025-02-26 8:28 ` Niklas Schnelle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox