[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <16f499d3b04d0f56463b4b09e722f1900d21858c.camel@linux.ibm.com>
Date: Mon, 24 Feb 2025 12:41:33 +0100
From: Niklas Schnelle <schnelle@...ux.ibm.com>
To: Bjorn Helgaas <helgaas@...nel.org>, Christoph Hellwig <hch@....de>,
Alexandra Winter <wintera@...ux.ibm.com>,
Alex Williamson
<alex.williamson@...hat.com>,
Gerd Bayer <gbayer@...ux.ibm.com>,
Matthew
Rosato <mjrosato@...ux.ibm.com>,
Jason Gunthorpe <jgg@...pe.ca>,
Thorsten
Winkler <twinkler@...ux.ibm.com>,
Bjorn Helgaas <bhelgaas@...gle.com>
Cc: Julian Ruess <julianr@...ux.ibm.com>, Halil Pasic <pasic@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle
<svens@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
linux-pci@...r.kernel.org
Subject: Re: [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and
restrict mmap() of resources to mappable BARs
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@...hat.com>
> Signed-off-by: Niklas Schnelle <schnelle@...ux.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
Powered by blists - more mailing lists