public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] vfio/pci: Introduce vfio_pci driver for ISM devices
@ 2026-02-12 14:02 Julian Ruess
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Julian Ruess @ 2026-02-12 14:02 UTC (permalink / raw)
  To: schnelle, wintera, ts, oberpar, gbayer, Alex Williamson,
	Jason Gunthorpe, Yishai Hadas, Shameer Kolothum, Kevin Tian
  Cc: mjrosato, alifm, raspl, hca, agordeev, gor, julianr, kvm,
	linux-kernel, linux-s390, linux-pci

Hi all,

This series adds a vfio_pci variant driver for the s390-specific
Internal Shared Memory (ISM) devices used for inter-VM communication
including SMC-D.

This is a prerequisite for an in-development open-source user space
driver stack that will allow to use ISM devices to provide remote
console and block device functionality. This stack will be part of
s390-tools.

This driver would also allow QEMU to mediate access to an ISM device,
enabling a form of PCI pass‑through even for guests whose hardware
cannot directly execute PCI accesses, such as nested guests.

On s390, kernel primitives such as ioread() and iowrite() are switched
over from function handle based PCI load/stores instructions to PCI
memory-I/O (MIO) loads/stores when these are available and not
explicitly disabled. Since these instructions cannot be used with ISM
devices, ensure that classic function handle-based PCI instructions are
used instead.

The driver is still required even when MIO instructions are disabled, as
the ISM device relies on the PCI store‑block (PCISTB) instruction to
perform write operations.

Thank you,
Julian

Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
---
Julian Ruess (3):
      vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
      vfio/ism: Implement vfio_pci driver for ISM devices
      MAINTAINERS: add VFIO ISM PCI DRIVER section

 MAINTAINERS                        |   6 +
 drivers/vfio/pci/Kconfig           |   2 +
 drivers/vfio/pci/Makefile          |   2 +
 drivers/vfio/pci/ism/Kconfig       |  11 ++
 drivers/vfio/pci/ism/Makefile      |   3 +
 drivers/vfio/pci/ism/main.c        | 227 +++++++++++++++++++++++++++++++++++++
 drivers/vfio/pci/vfio_pci_config.c |   1 +
 drivers/vfio/pci/vfio_pci_core.c   |   4 +-
 include/linux/vfio_pci_core.h      |   2 +-
 9 files changed, 255 insertions(+), 3 deletions(-)
---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20250227-vfio_pci_ism-0ccc2e472247

Best regards,
-- 
Julian Ruess <julianr@linux.ibm.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
  2026-02-12 14:02 [PATCH 0/3] vfio/pci: Introduce vfio_pci driver for ISM devices Julian Ruess
@ 2026-02-12 14:02 ` Julian Ruess
  2026-02-12 14:17   ` Jason Gunthorpe
                     ` (3 more replies)
  2026-02-12 14:02 ` [PATCH 2/3] vfio/ism: Implement vfio_pci driver for ISM devices Julian Ruess
  2026-02-12 14:02 ` [PATCH 3/3] MAINTAINERS: add VFIO ISM PCI DRIVER section Julian Ruess
  2 siblings, 4 replies; 8+ messages in thread
From: Julian Ruess @ 2026-02-12 14:02 UTC (permalink / raw)
  To: schnelle, wintera, ts, oberpar, gbayer, Alex Williamson,
	Jason Gunthorpe, Yishai Hadas, Shameer Kolothum, Kevin Tian
  Cc: mjrosato, alifm, raspl, hca, agordeev, gor, julianr, kvm,
	linux-kernel, linux-s390, linux-pci

Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
the ISM device on s390. This bar is never mapped.

Acked-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 4 ++--
 include/linux/vfio_pci_core.h    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 3a11e6f450f70105f17a3a621520c195d99e0671..3d70bf6668c7a69c4b46674195954d1ada662006 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1647,7 +1647,7 @@ static unsigned long vma_to_pfn(struct vm_area_struct *vma)
 	u64 pgoff;
 
 	pgoff = vma->vm_pgoff &
-		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
+		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
 
 	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
 }
@@ -1751,7 +1751,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
 	phys_len = PAGE_ALIGN(pci_resource_len(pdev, index));
 	req_len = vma->vm_end - vma->vm_start;
 	pgoff = vma->vm_pgoff &
-		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
+		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
 	req_start = pgoff << PAGE_SHIFT;
 
 	if (req_start + req_len > phys_len)
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 1ac86896875cf5c9b5cc8ef25fae8bbd4394de05..12781707f086a330161990dc3579ec0d75887da8 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -20,7 +20,7 @@
 #ifndef VFIO_PCI_CORE_H
 #define VFIO_PCI_CORE_H
 
-#define VFIO_PCI_OFFSET_SHIFT   40
+#define VFIO_PCI_OFFSET_SHIFT   48
 #define VFIO_PCI_OFFSET_TO_INDEX(off)	(off >> VFIO_PCI_OFFSET_SHIFT)
 #define VFIO_PCI_INDEX_TO_OFFSET(index)	((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
 #define VFIO_PCI_OFFSET_MASK	(((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] vfio/ism: Implement vfio_pci driver for ISM devices
  2026-02-12 14:02 [PATCH 0/3] vfio/pci: Introduce vfio_pci driver for ISM devices Julian Ruess
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
@ 2026-02-12 14:02 ` Julian Ruess
  2026-02-12 14:02 ` [PATCH 3/3] MAINTAINERS: add VFIO ISM PCI DRIVER section Julian Ruess
  2 siblings, 0 replies; 8+ messages in thread
From: Julian Ruess @ 2026-02-12 14:02 UTC (permalink / raw)
  To: schnelle, wintera, ts, oberpar, gbayer, Alex Williamson,
	Jason Gunthorpe, Yishai Hadas, Shameer Kolothum, Kevin Tian
  Cc: mjrosato, alifm, raspl, hca, agordeev, gor, julianr, kvm,
	linux-kernel, linux-s390, linux-pci

Add a vfio_pci variant driver for the s390-specific Internal Shared
Memory (ISM) devices used for inter-VM communication.

This enables the development of vfio-pci-based user space drivers for
ISM devices.

On s390, kernel primitives such as ioread() and iowrite() are switched
over from function handle based PCI load/stores instructions to PCI
memory-I/O (MIO) loads/stores when these are available and not
explicitly disabled. Since these instructions cannot be used with ISM
devices, ensure that classic function handle-based PCI instructions are
used instead.

The driver is still required even when MIO instructions are disabled, as
the ISM device relies on the PCI store block (PCISTB) instruction to
perform write operations.

Stores are not fragmented, therefore one ioctl corresponds to exactly
one PCISTB instruction. User space must ensure to not write more than
4096 bytes at once to an ISM BAR which is the maximum payload of the
PCISTB instruction

Export vfio_pci_config_rw() for config space accesses that do not rely
on s390 MIO instructions.

Acked-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
---
 drivers/vfio/pci/Kconfig           |   2 +
 drivers/vfio/pci/Makefile          |   2 +
 drivers/vfio/pci/ism/Kconfig       |  11 ++
 drivers/vfio/pci/ism/Makefile      |   3 +
 drivers/vfio/pci/ism/main.c        | 227 +++++++++++++++++++++++++++++++++++++
 drivers/vfio/pci/vfio_pci_config.c |   1 +
 6 files changed, 246 insertions(+)

diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
index 1e82b44bda1a0a544e1add7f4b06edecf35aaf81..296bf01e185ecacc388ebc69e92706c99e47c814 100644
--- a/drivers/vfio/pci/Kconfig
+++ b/drivers/vfio/pci/Kconfig
@@ -60,6 +60,8 @@ config VFIO_PCI_DMABUF
 
 source "drivers/vfio/pci/mlx5/Kconfig"
 
+source "drivers/vfio/pci/ism/Kconfig"
+
 source "drivers/vfio/pci/hisilicon/Kconfig"
 
 source "drivers/vfio/pci/pds/Kconfig"
diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile
index e0a0757dd1d2b0bc69b7e4d79441d5cacf4e1cd8..6138f1bf241df04e7419f196b404abdf9b194050 100644
--- a/drivers/vfio/pci/Makefile
+++ b/drivers/vfio/pci/Makefile
@@ -11,6 +11,8 @@ obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
 
 obj-$(CONFIG_MLX5_VFIO_PCI)           += mlx5/
 
+obj-$(CONFIG_ISM_VFIO_PCI)           += ism/
+
 obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/
 
 obj-$(CONFIG_PDS_VFIO_PCI) += pds/
diff --git a/drivers/vfio/pci/ism/Kconfig b/drivers/vfio/pci/ism/Kconfig
new file mode 100644
index 0000000000000000000000000000000000000000..2db6c9327980827bf617afb9a82b1d1928868d42
--- /dev/null
+++ b/drivers/vfio/pci/ism/Kconfig
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+config ISM_VFIO_PCI
+	tristate "VFIO support for ISM devices"
+	depends on ISM
+	select VFIO_PCI_CORE
+	help
+	  This provides user space support for
+	  IBM Internal Shared Memory (ISM) Adapter devices
+	  using the VFIO framework.
+
+	  If you don't know what to do here, say N.
diff --git a/drivers/vfio/pci/ism/Makefile b/drivers/vfio/pci/ism/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..32cc3c66dd11395da85a2b6f05b3d97036ed8a35
--- /dev/null
+++ b/drivers/vfio/pci/ism/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ISM_VFIO_PCI) += ism-vfio-pci.o
+ism-vfio-pci-y := main.o
diff --git a/drivers/vfio/pci/ism/main.c b/drivers/vfio/pci/ism/main.c
new file mode 100644
index 0000000000000000000000000000000000000000..99f27682ec16ec855ae12ff87059dbb1bc18c586
--- /dev/null
+++ b/drivers/vfio/pci/ism/main.c
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * vfio-ISM driver for s390
+ *
+ * Copyright IBM Corp. 2026
+ */
+
+#include "../vfio_pci_priv.h"
+
+struct ism_vfio_pci_core_device {
+	struct vfio_pci_core_device core_device;
+};
+
+static int ism_pci_open_device(struct vfio_device *core_vdev)
+{
+	struct ism_vfio_pci_core_device *mvdev = container_of(
+		core_vdev, struct ism_vfio_pci_core_device, core_device.vdev);
+	struct vfio_pci_core_device *vdev = &mvdev->core_device;
+	int ret;
+
+	ret = vfio_pci_core_enable(vdev);
+	if (ret)
+		return ret;
+
+	vfio_pci_core_finish_enable(vdev);
+	return 0;
+}
+
+static ssize_t ism_vfio_pci_do_io_r(struct vfio_pci_core_device *vdev,
+				    char __user *buf, loff_t off, size_t count,
+				    int bar)
+{
+	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+	ssize_t ret, done = 0;
+	u64 req, length, tmp;
+
+	while (count) {
+		if (count >= 8 && IS_ALIGNED(off, 8))
+			length = 8;
+		else if (count >= 4 && IS_ALIGNED(off, 4))
+			length = 4;
+		else if (count >= 2 && IS_ALIGNED(off, 2))
+			length = 2;
+		else
+			length = 1;
+		req = ZPCI_CREATE_REQ(READ_ONCE(zdev->fh), bar, length);
+		/* use pcilg to prevent using MIO instructions */
+		ret = __zpci_load(&tmp, req, off);
+		if (ret)
+			return ret;
+		if (copy_to_user(buf, &tmp, length))
+			return -EFAULT;
+		count -= length;
+		done += length;
+		off += length;
+		buf += length;
+	}
+	return done;
+}
+
+static ssize_t ism_vfio_pci_do_io_w(struct vfio_pci_core_device *vdev,
+				    char __user *buf, loff_t off, size_t count,
+				    int bar)
+{
+	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+	void *data __free(kfree) = NULL;
+	ssize_t ret;
+	u64 req;
+
+	if (count > ZPCI_BOUNDARY_SIZE)
+		return -EINVAL;
+	data = kzalloc(ZPCI_BOUNDARY_SIZE, GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	if (copy_from_user(data, buf, count))
+		return -EFAULT;
+	req = ZPCI_CREATE_REQ(READ_ONCE(zdev->fh), bar, count);
+	ret = __zpci_store_block(data, req, off);
+	if (ret)
+		return ret;
+	return count;
+}
+
+static ssize_t ism_vfio_pci_bar_rw(struct vfio_pci_core_device *vdev,
+				   char __user *buf, size_t count, loff_t *ppos,
+				   bool iswrite)
+{
+	int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
+	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
+	resource_size_t end;
+	ssize_t done = 0;
+
+	if (pci_resource_start(vdev->pdev, bar))
+		end = pci_resource_len(vdev->pdev, bar);
+	else
+		return -EINVAL;
+
+	if (pos >= end)
+		return -EINVAL;
+
+	count = min(count, (size_t)(end - pos));
+
+	if (iswrite)
+		done = ism_vfio_pci_do_io_w(vdev, buf, pos, count, bar);
+	else
+		done = ism_vfio_pci_do_io_r(vdev, buf, pos, count, bar);
+
+	if (done >= 0)
+		*ppos += done;
+
+	return done;
+}
+
+static ssize_t ism_vfio_pci_rw(struct vfio_device *core_vdev, char __user *buf,
+			       size_t count, loff_t *ppos, bool iswrite)
+{
+	unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
+	struct vfio_pci_core_device *vdev;
+	int ret;
+
+	vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);
+
+	if (!count)
+		return 0;
+
+	switch (index) {
+	case VFIO_PCI_CONFIG_REGION_INDEX:
+		ret = vfio_pci_config_rw(vdev, buf, count, ppos, iswrite);
+		break;
+
+	case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
+		ret = ism_vfio_pci_bar_rw(vdev, buf, count, ppos, iswrite);
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	return ret;
+}
+
+static ssize_t ism_vfio_pci_read(struct vfio_device *core_vdev,
+				 char __user *buf, size_t count, loff_t *ppos)
+{
+	return ism_vfio_pci_rw(core_vdev, buf, count, ppos, false);
+}
+
+static ssize_t ism_vfio_pci_write(struct vfio_device *core_vdev,
+				  const char __user *buf, size_t count,
+				  loff_t *ppos)
+{
+	return ism_vfio_pci_rw(core_vdev, (char __user *)buf, count, ppos,
+			       true);
+}
+
+static const struct vfio_device_ops ism_pci_ops = {
+	.name = "ism-vfio-pci",
+	.init = vfio_pci_core_init_dev,
+	.release = vfio_pci_core_release_dev,
+	.open_device = ism_pci_open_device,
+	.close_device = vfio_pci_core_close_device,
+	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
+	.device_feature = vfio_pci_core_ioctl_feature,
+	.read = ism_vfio_pci_read,
+	.write = ism_vfio_pci_write,
+	.request = vfio_pci_core_request,
+	.match = vfio_pci_core_match,
+	.match_token_uuid = vfio_pci_core_match_token_uuid,
+	.bind_iommufd = vfio_iommufd_physical_bind,
+	.unbind_iommufd = vfio_iommufd_physical_unbind,
+	.attach_ioas = vfio_iommufd_physical_attach_ioas,
+	.detach_ioas = vfio_iommufd_physical_detach_ioas,
+
+};
+
+static int ism_vfio_pci_probe(struct pci_dev *pdev,
+			      const struct pci_device_id *id)
+{
+	struct ism_vfio_pci_core_device *ivpcd;
+	int ret;
+
+	ivpcd = vfio_alloc_device(ism_vfio_pci_core_device, core_device.vdev,
+				  &pdev->dev, &ism_pci_ops);
+	if (IS_ERR(ivpcd))
+		return PTR_ERR(ivpcd);
+
+	dev_set_drvdata(&pdev->dev, &ivpcd->core_device);
+	ret = vfio_pci_core_register_device(&ivpcd->core_device);
+	if (ret)
+		vfio_put_device(&ivpcd->core_device.vdev);
+	return ret;
+}
+
+static void ism_vfio_pci_remove(struct pci_dev *pdev)
+{
+	struct vfio_pci_core_device *core_device;
+	struct ism_vfio_pci_core_device *ivpcd;
+
+	core_device = dev_get_drvdata(&pdev->dev);
+	ivpcd = container_of(core_device, struct ism_vfio_pci_core_device,
+			     core_device);
+
+	vfio_pci_core_unregister_device(&ivpcd->core_device);
+	vfio_put_device(&ivpcd->core_device.vdev);
+}
+
+static const struct pci_device_id ism_device_table[] = {
+	{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_IBM,
+					  PCI_DEVICE_ID_IBM_ISM) },
+	{}
+};
+MODULE_DEVICE_TABLE(pci, ism_device_table);
+
+static struct pci_driver ism_vfio_pci_driver = {
+	.name = KBUILD_MODNAME,
+	.id_table = ism_device_table,
+	.probe = ism_vfio_pci_probe,
+	.remove = ism_vfio_pci_remove,
+	.driver_managed_dma = true,
+};
+
+module_pci_driver(ism_vfio_pci_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("vfio-pci variant driver for the IBM Internal Shared Memory (ISM) device");
+MODULE_AUTHOR("IBM Corporation");
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index dc4e510e6e1bf4753e1d9005e0054399a639ea12..c7341a2d072b058965135a3d225894d74379e12e 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -1995,6 +1995,7 @@ ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 
 	return done;
 }
+EXPORT_SYMBOL(vfio_pci_config_rw);
 
 /**
  * vfio_pci_core_range_intersect_range() - Determine overlap between a buffer

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] MAINTAINERS: add VFIO ISM PCI DRIVER section
  2026-02-12 14:02 [PATCH 0/3] vfio/pci: Introduce vfio_pci driver for ISM devices Julian Ruess
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
  2026-02-12 14:02 ` [PATCH 2/3] vfio/ism: Implement vfio_pci driver for ISM devices Julian Ruess
@ 2026-02-12 14:02 ` Julian Ruess
  2 siblings, 0 replies; 8+ messages in thread
From: Julian Ruess @ 2026-02-12 14:02 UTC (permalink / raw)
  To: schnelle, wintera, ts, oberpar, gbayer, Alex Williamson,
	Jason Gunthorpe, Yishai Hadas, Shameer Kolothum, Kevin Tian
  Cc: mjrosato, alifm, raspl, hca, agordeev, gor, julianr, kvm,
	linux-kernel, linux-s390, linux-pci

ism_vfio_pci is a new kernel component that allows
to use the ISM device from userspace. Add myself
as a maintainer.

Acked-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e087673237636268346979ddc270f8cf0905c722..e9d025ea396e71102463a50b2934827175356da2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27393,6 +27393,12 @@ L:	kvm@vger.kernel.org
 S:	Maintained
 F:	drivers/vfio/pci/hisilicon/
 
+VFIO ISM PCI DRIVER
+M:	Julian Ruess <julianr@linux.ibm.com>
+L:	kvm@vger.kernel.org
+S:	Maintained
+F:	drivers/vfio/pci/ism/
+
 VFIO MEDIATED DEVICE DRIVERS
 M:	Kirti Wankhede <kwankhede@nvidia.com>
 L:	kvm@vger.kernel.org

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
@ 2026-02-12 14:17   ` Jason Gunthorpe
  2026-02-12 15:26   ` Alex Williamson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jason Gunthorpe @ 2026-02-12 14:17 UTC (permalink / raw)
  To: Julian Ruess
  Cc: schnelle, wintera, ts, oberpar, gbayer, Alex Williamson,
	Yishai Hadas, Shameer Kolothum, Kevin Tian, mjrosato, alifm,
	raspl, hca, agordeev, gor, kvm, linux-kernel, linux-s390,
	linux-pci

On Thu, Feb 12, 2026 at 03:02:15PM +0100, Julian Ruess wrote:
> Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
> VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
> the ISM device on s390. This bar is never mapped.

Woah, this is dangerous, the size was selected to fit within a pgoff
of a 32bit system.. Does this entirely break vfio on 32 bit?

Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
  2026-02-12 14:17   ` Jason Gunthorpe
@ 2026-02-12 15:26   ` Alex Williamson
  2026-02-12 22:46   ` kernel test robot
  2026-02-12 22:46   ` kernel test robot
  3 siblings, 0 replies; 8+ messages in thread
From: Alex Williamson @ 2026-02-12 15:26 UTC (permalink / raw)
  To: Julian Ruess
  Cc: schnelle, wintera, ts, oberpar, gbayer, Jason Gunthorpe,
	Yishai Hadas, Shameer Kolothum, Kevin Tian, mjrosato, alifm,
	raspl, hca, agordeev, gor, kvm, linux-kernel, linux-s390,
	linux-pci

On Thu, 12 Feb 2026 15:02:15 +0100
Julian Ruess <julianr@linux.ibm.com> wrote:

> Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
> VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
> the ISM device on s390. This bar is never mapped.

Why does the entirety of vfio-pci need to adapt to the BAR requirements
of this device?  There's a variant driver included here that implements
its own read/write handlers and doesn't support mmap, so you're already
halfway there to implement your own region offsets independent of the
conventions of the rest of vfio-pci.  Thanks,

Alex
 
> Acked-by: Alexandra Winter <wintera@linux.ibm.com>
> Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 4 ++--
>  include/linux/vfio_pci_core.h    | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 3a11e6f450f70105f17a3a621520c195d99e0671..3d70bf6668c7a69c4b46674195954d1ada662006 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1647,7 +1647,7 @@ static unsigned long vma_to_pfn(struct vm_area_struct *vma)
>  	u64 pgoff;
>  
>  	pgoff = vma->vm_pgoff &
> -		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
> +		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
>  
>  	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
>  }
> @@ -1751,7 +1751,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
>  	phys_len = PAGE_ALIGN(pci_resource_len(pdev, index));
>  	req_len = vma->vm_end - vma->vm_start;
>  	pgoff = vma->vm_pgoff &
> -		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
> +		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
>  	req_start = pgoff << PAGE_SHIFT;
>  
>  	if (req_start + req_len > phys_len)
> diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
> index 1ac86896875cf5c9b5cc8ef25fae8bbd4394de05..12781707f086a330161990dc3579ec0d75887da8 100644
> --- a/include/linux/vfio_pci_core.h
> +++ b/include/linux/vfio_pci_core.h
> @@ -20,7 +20,7 @@
>  #ifndef VFIO_PCI_CORE_H
>  #define VFIO_PCI_CORE_H
>  
> -#define VFIO_PCI_OFFSET_SHIFT   40
> +#define VFIO_PCI_OFFSET_SHIFT   48
>  #define VFIO_PCI_OFFSET_TO_INDEX(off)	(off >> VFIO_PCI_OFFSET_SHIFT)
>  #define VFIO_PCI_INDEX_TO_OFFSET(index)	((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
>  #define VFIO_PCI_OFFSET_MASK	(((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
  2026-02-12 14:17   ` Jason Gunthorpe
  2026-02-12 15:26   ` Alex Williamson
@ 2026-02-12 22:46   ` kernel test robot
  2026-02-12 22:46   ` kernel test robot
  3 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2026-02-12 22:46 UTC (permalink / raw)
  To: Julian Ruess, schnelle, wintera, ts, oberpar, gbayer,
	Alex Williamson, Jason Gunthorpe, Yishai Hadas, Shameer Kolothum,
	Kevin Tian
  Cc: oe-kbuild-all, mjrosato, alifm, raspl, hca, agordeev, gor,
	julianr, kvm, linux-kernel, linux-s390, linux-pci

Hi Julian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b]

url:    https://github.com/intel-lab-lkp/linux/commits/Julian-Ruess/vfio-pci-Set-VFIO_PCI_OFFSET_SHIFT-to-48/20260212-220938
base:   05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
patch link:    https://lore.kernel.org/r/20260212-vfio_pci_ism-v1-1-333262ade074%40linux.ibm.com
patch subject: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
config: riscv-randconfig-001-20260213 (https://download.01.org/0day-ci/archive/20260213/202602130659.urh1Dx2i-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260213/202602130659.urh1Dx2i-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602130659.urh1Dx2i-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/vfio/pci/nvgrace-gpu/main.c: In function 'addr_to_pgoff':
>> drivers/vfio/pci/nvgrace-gpu/main.c:196:22: warning: left shift count >= width of type [-Wshift-count-overflow]
     196 |                 ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                      ^~
   drivers/vfio/pci/nvgrace-gpu/main.c: In function 'nvgrace_gpu_mmap':
   drivers/vfio/pci/nvgrace-gpu/main.c:272:22: warning: left shift count >= width of type [-Wshift-count-overflow]
     272 |                 ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                      ^~


vim +196 drivers/vfio/pci/nvgrace-gpu/main.c

a23b10608d4203 Ankit Agrawal 2025-11-27  191  
9db65489b87298 Ankit Agrawal 2025-11-27  192  static unsigned long addr_to_pgoff(struct vm_area_struct *vma,
9db65489b87298 Ankit Agrawal 2025-11-27  193  				   unsigned long addr)
9db65489b87298 Ankit Agrawal 2025-11-27  194  {
9db65489b87298 Ankit Agrawal 2025-11-27  195  	u64 pgoff = vma->vm_pgoff &
9db65489b87298 Ankit Agrawal 2025-11-27 @196  		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
9db65489b87298 Ankit Agrawal 2025-11-27  197  
9db65489b87298 Ankit Agrawal 2025-11-27  198  	return ((addr - vma->vm_start) >> PAGE_SHIFT) + pgoff;
9db65489b87298 Ankit Agrawal 2025-11-27  199  }
9db65489b87298 Ankit Agrawal 2025-11-27  200  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
  2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
                     ` (2 preceding siblings ...)
  2026-02-12 22:46   ` kernel test robot
@ 2026-02-12 22:46   ` kernel test robot
  3 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2026-02-12 22:46 UTC (permalink / raw)
  To: Julian Ruess, schnelle, wintera, ts, oberpar, gbayer,
	Alex Williamson, Jason Gunthorpe, Yishai Hadas, Shameer Kolothum,
	Kevin Tian
  Cc: llvm, oe-kbuild-all, mjrosato, alifm, raspl, hca, agordeev, gor,
	julianr, kvm, linux-kernel, linux-s390, linux-pci

Hi Julian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b]

url:    https://github.com/intel-lab-lkp/linux/commits/Julian-Ruess/vfio-pci-Set-VFIO_PCI_OFFSET_SHIFT-to-48/20260212-220938
base:   05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
patch link:    https://lore.kernel.org/r/20260212-vfio_pci_ism-v1-1-333262ade074%40linux.ibm.com
patch subject: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
config: powerpc-randconfig-002-20260213 (https://download.01.org/0day-ci/archive/20260213/202602130603.5vXcHBPj-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260213/202602130603.5vXcHBPj-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602130603.5vXcHBPj-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/vfio/pci/vfio_pci_core.c:1646:28: warning: shift count >= width of type [-Wshift-count-overflow]
    1646 |         int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
         |                                   ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1650:9: warning: shift count >= width of type [-Wshift-count-overflow]
    1650 |                 ((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                       ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1701:22: warning: shift count >= width of type [-Wshift-count-overflow]
    1701 |                             vma->vm_pgoff >>
         |                                           ^
    1702 |                                 (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT),
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:244:9: note: expanded from macro 'dev_dbg_ratelimited'
     244 |                                   ##__VA_ARGS__);                       \
         |                                     ^~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1729:24: warning: shift count >= width of type [-Wshift-count-overflow]
    1729 |         index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
         |                               ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1754:9: warning: shift count >= width of type [-Wshift-count-overflow]
    1754 |                 ((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                       ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   5 warnings generated.


vim +1646 drivers/vfio/pci/vfio_pci_core.c

abafbc551fdded drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-22  1642  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1643  static unsigned long vma_to_pfn(struct vm_area_struct *vma)
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1644  {
536475109c8284 drivers/vfio/pci/vfio_pci_core.c Max Gurtovoy    2021-08-26  1645  	struct vfio_pci_core_device *vdev = vma->vm_private_data;
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29 @1646  	int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1647  	u64 pgoff;
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1648  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1649  	pgoff = vma->vm_pgoff &
c298baab91b6e3 drivers/vfio/pci/vfio_pci_core.c Julian Ruess    2026-02-12  1650  		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1651  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1652  	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1653  }
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1654  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-02-12 22:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 14:02 [PATCH 0/3] vfio/pci: Introduce vfio_pci driver for ISM devices Julian Ruess
2026-02-12 14:02 ` [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48 Julian Ruess
2026-02-12 14:17   ` Jason Gunthorpe
2026-02-12 15:26   ` Alex Williamson
2026-02-12 22:46   ` kernel test robot
2026-02-12 22:46   ` kernel test robot
2026-02-12 14:02 ` [PATCH 2/3] vfio/ism: Implement vfio_pci driver for ISM devices Julian Ruess
2026-02-12 14:02 ` [PATCH 3/3] MAINTAINERS: add VFIO ISM PCI DRIVER section Julian Ruess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox