From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
Christoph Hellwig <hch@lst.de>,
Alexandra Winter <wintera@linux.ibm.com>,
Alex Williamson <alex.williamson@redhat.com>,
Gerd Bayer <gbayer@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Thorsten Winkler <twinkler@linux.ibm.com>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: Julian Ruess <julianr@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v6 3/3] PCI: s390: Enable HAVE_PCI_MMAP on s390 and restrict mmap() of resources to mappable BARs
Date: Mon, 24 Feb 2025 12:41:33 +0100 [thread overview]
Message-ID: <16f499d3b04d0f56463b4b09e722f1900d21858c.camel@linux.ibm.com> (raw)
In-Reply-To: <20250214-vfio_pci_mmap-v6-3-6f300cb63a7e@linux.ibm.com>
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
next prev parent reply other threads:[~2025-02-24 11:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16f499d3b04d0f56463b4b09e722f1900d21858c.camel@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=borntraeger@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hch@lst.de \
--cc=helgaas@kernel.org \
--cc=jgg@ziepe.ca \
--cc=julianr@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=twinkler@linux.ibm.com \
--cc=wintera@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox