Skip to content

Commit aa9f168

Browse files
niklas88bjorn-helgaas
authored andcommitted
s390/pci: Support mmap() of PCI resources except for ISM devices
So far s390 does not allow mmap() of PCI resources to user-space via the usual mechanisms, though it does use it for RDMA. For the PCI sysfs resource files and /proc/bus/pci it defines neither HAVE_PCI_MMAP nor ARCH_GENERIC_PCI_MMAP_RESOURCE. For vfio-pci s390 previously relied on disabled VFIO_PCI_MMAP and now relies on setting pdev->non_mappable_bars for all devices. This is partly because access to mapped PCI resources from user-space requires special PCI load/store memory-I/O (MIO) instructions, or the special MMIO syscalls when these are not available. Still, such access is possible and useful not just for RDMA, in fact not being able to mmap() PCI resources has previously caused extra work when testing devices. One thing that doesn't work with PCI resources mapped to user-space though is the s390 specific virtual ISM device. Not only because the BAR size of 256 TiB prevents mapping the whole BAR but also because access requires use of the legacy PCI instructions which are not accessible to user-space on systems with the newer MIO PCI instructions. Now with the pdev->non_mappable_bars flag ISM can be excluded from mapping its resources while making this functionality available for all other PCI devices. To this end introduce a minimal implementation of PCI_QUIRKS and use that to set pdev->non_mappable_bars for ISM devices only. Then also set ARCH_GENERIC_PCI_MMAP_RESOURCE to take advantage of the generic implementation of pci_mmap_resource_range() enabling only the newer sysfs mmap() interface. This follows the recommendation in Documentation/PCI/sysfs-pci.rst. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 888bd83 commit aa9f168

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

arch/s390/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ config AUDIT_ARCH
4141
config NO_IOPORT_MAP
4242
def_bool y
4343

44-
config PCI_QUIRKS
45-
def_bool n
46-
4744
config ARCH_SUPPORTS_UPROBES
4845
def_bool y
4946

@@ -258,6 +255,7 @@ config S390
258255
select PCI_DOMAINS if PCI
259256
select PCI_MSI if PCI
260257
select PCI_MSI_ARCH_FALLBACKS if PCI_MSI
258+
select PCI_QUIRKS if PCI
261259
select SPARSE_IRQ
262260
select SWIOTLB
263261
select SYSCTL_EXCEPTION_TRACE

arch/s390/include/asm/pci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <asm/pci_insn.h>
1212
#include <asm/sclp.h>
1313

14+
#define ARCH_GENERIC_PCI_MMAP_RESOURCE 1
15+
#define arch_can_pci_mmap_wc() 1
16+
1417
#define PCIBIOS_MIN_IO 0x1000
1518
#define PCIBIOS_MIN_MEM 0x10000000
1619

arch/s390/pci/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_clp.o \
77
pci_event.o pci_debug.o pci_insn.o pci_mmio.o \
8-
pci_bus.o pci_kvm_hook.o pci_report.o
8+
pci_bus.o pci_kvm_hook.o pci_report.o pci_fixup.o
99
obj-$(CONFIG_PCI_IOV) += pci_iov.o
1010
obj-$(CONFIG_SYSFS) += pci_sysfs.o

arch/s390/pci/pci.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ 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;
594593

595594
zpci_map_resources(pdev);
596595

arch/s390/pci/pci_fixup.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Exceptions for specific devices,
4+
*
5+
* Copyright IBM Corp. 2025
6+
*
7+
* Author(s):
8+
* Niklas Schnelle <[email protected]>
9+
*/
10+
#include <linux/pci.h>
11+
12+
static void zpci_ism_bar_no_mmap(struct pci_dev *pdev)
13+
{
14+
/*
15+
* ISM's BAR is special. Drivers written for ISM know
16+
* how to handle this but others need to be aware of their
17+
* special nature e.g. to prevent attempts to mmap() it.
18+
*/
19+
pdev->non_mappable_bars = 1;
20+
}
21+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM,
22+
PCI_DEVICE_ID_IBM_ISM,
23+
zpci_ism_bar_no_mmap);

drivers/s390/net/ism_drv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
MODULE_DESCRIPTION("ISM driver for s390");
2121
MODULE_LICENSE("GPL");
2222

23-
#define PCI_DEVICE_ID_IBM_ISM 0x04ED
2423
#define DRV_NAME "ism"
2524

2625
static const struct pci_device_id ism_device_table[] = {

include/linux/pci_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@
518518
#define PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM 0x0251
519519
#define PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE 0x0361
520520
#define PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL 0x252
521+
#define PCI_DEVICE_ID_IBM_ISM 0x04ed
521522

522523
#define PCI_SUBVENDOR_ID_IBM 0x1014
523524
#define PCI_SUBDEVICE_ID_IBM_SATURN_SERIAL_ONE_PORT 0x03d4

0 commit comments

Comments
 (0)