Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH 0/3] Add arm on s390 accelerator driver
@ 2026-12-04 14:45 Sven Schnelle
  2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sven Schnelle @ 2026-12-04 14:45 UTC (permalink / raw)
  To: Marc Zyngier, Mark Rutland, Joerg Roedel (AMD), Will Deacon
  Cc: Robin Murphy, Catalin Marinas, Sudeep Holla, Ard Biesheuvel,
	linux-kernel, iommu, linux-arm-kernel, Christian Borntraeger,
	Hendrik Brueckner, Ulrich Weigand, Arnd Bergmann, linux-s390

Upcoming s390 machines will support crypto/deflate hardware acceleration
for arm64 guests. This works by providing a memory region to the guest
which can be written to via the st64bv0 instruction. In order to use this
instruction from userspace programs, a driver is needed that allows to map
the accelerator memory region via mmap(). Programs can then call
acceleration functions by writing a parameter block + function code with
st64bv0 to this memory region.

st64bv0 writes 32 bits of data taken from the ACCDATA_EL1 register together
with the other data. An additional patch is needed to make it possible to
use st64bv0 without a PASID. I agreed with Arnd that I send the patch
with this driver, as it is the use case for it.

NOTE: the patchset depends on patches 2-4 of the series from:

https://lore.kernel.org/all/20261203095703.655796-1-arnd@kernel.org/

Arnd Bergmann (1):
  iommu: sva: allow SVA without PASID

Sven Schnelle (2):
  dt-bindings: firmware: platform-accel: add yaml documentation
  drivers: firmware: add ARM on s390 accelerator driver

 .../bindings/firmware/platform-accel.yaml     |  37 ++++
 MAINTAINERS                                   |   7 +
 drivers/firmware/Kconfig                      |  10 ++
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/platform-accel.c             | 168 ++++++++++++++++++
 drivers/iommu/iommu-sva.c                     |  31 +++-
 drivers/iommu/iommu.c                         |  21 ++-
 include/linux/iommu.h                         |   8 +
 8 files changed, 275 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/firmware/platform-accel.yaml
 create mode 100644 drivers/firmware/platform-accel.c


base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
prerequisite-patch-id: 2ad19c35e53aa86d4d706692b991a5eb9d4a4dc7
prerequisite-patch-id: 334d1217dd04cccac70aafe00ce6e318e13c5afd
prerequisite-patch-id: 58d0d38039709bf5b6a592bd356257cc5cecba7e
-- 
2.56.1


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

* [PATCH 1/3] iommu: sva: allow SVA without PASID
  2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
@ 2026-12-04 14:45 ` Sven Schnelle
  2026-12-04 15:12   ` sashiko-bot
  2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
  2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
  2 siblings, 1 reply; 8+ messages in thread
From: Sven Schnelle @ 2026-12-04 14:45 UTC (permalink / raw)
  To: Marc Zyngier, Mark Rutland, Joerg Roedel (AMD), Will Deacon
  Cc: Robin Murphy, Catalin Marinas, Sudeep Holla, Ard Biesheuvel,
	linux-kernel, iommu, linux-arm-kernel, Christian Borntraeger,
	Hendrik Brueckner, Ulrich Weigand, Arnd Bergmann, linux-s390

From: Arnd Bergmann <arnd@arndb.de>

On devices that are tightly integrated with the CPU and use the regular
page tables for synchronous commands, the PASID is ignored and the
actual ASID is used in its place, on Arm CPUs this is in TTBR0_EL1.

Create a new iommu_sva_bind_device_no_iommu() interface that lets device
drivers install an iommu_mm object in an mm for such devices.

As before, multiple SVA devices can be used by the same process as long
as all of them are able to use the same PASID. When a device without
an IOMMU enables SVA, the process will still allocate a PASID that can
be used for any other devices accessed by the same process after a
successful call to iommu_sva_bind_device().

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
 drivers/iommu/iommu-sva.c | 31 ++++++++++++++++++++++++++++++-
 drivers/iommu/iommu.c     | 21 ++++++++++++++-------
 include/linux/iommu.h     |  8 ++++++++
 3 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 9827cb804363..b444f3483f6d 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -29,7 +29,7 @@ static struct iommu_mm_data *iommu_alloc_mm_data(struct mm_struct *mm, struct de
 	iommu_mm = mm->iommu_mm;
 	/* Is a PASID already associated with this mm? */
 	if (iommu_mm) {
-		if (iommu_mm->pasid >= dev->iommu->max_pasids)
+		if (dev->iommu && iommu_mm->pasid >= dev->iommu->max_pasids)
 			return ERR_PTR(-EOVERFLOW);
 		return iommu_mm;
 	}
@@ -156,6 +156,35 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 }
 EXPORT_SYMBOL_GPL(iommu_sva_bind_device);
 
+/**
+ * iommu_sva_bind_device_no_iommu() - Bind a process address space to a device without iommu
+ * @dev: the device
+ * @mm: the mm to bind, caller must hold a reference to mm_users
+ *
+ * Allow the use of shared virtual addressing on devices that transparently
+ * use the CPU's page table instead of an IOMMU. A global PASID is allocated
+ * in case the same process uses another device with an IOMMU later.
+ *
+ * The reference is held until the mm_struct is destroyed.
+ *
+ * On error, returns a negative error number, or zero on success.
+ */
+int iommu_sva_bind_device_no_iommu(struct device *dev, struct mm_struct *mm)
+{
+	struct iommu_mm_data *iommu_mm;
+
+	if (dev->iommu_group)
+		return -EINVAL;
+
+	mutex_lock(&iommu_sva_lock);
+	/* Allocate mm->pasid if necessary. */
+	iommu_mm = iommu_alloc_mm_data(mm, dev);
+	mutex_unlock(&iommu_sva_lock);
+
+	return PTR_ERR_OR_ZERO(iommu_mm);
+}
+EXPORT_SYMBOL_GPL(iommu_sva_bind_device_no_iommu);
+
 /**
  * iommu_sva_unbind_device() - Remove a bond created with iommu_sva_bind_device
  * @handle: the handle returned by iommu_sva_bind_device()
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b486b8bbd1fc..1470bb9c1ca8 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3827,17 +3827,24 @@ EXPORT_SYMBOL_GPL(iommu_detach_device_pasid);
 ioasid_t iommu_alloc_global_pasid(struct device *dev)
 {
 	int ret;
+	unsigned int max_pasid;
 
-	/* max_pasids == 0 means that the device does not support PASID */
-	if (!dev->iommu->max_pasids)
+	if (!dev->iommu) {
+		/* no IOMMU but capable of enqcmd/st64bv0: pick any PASID */
+		max_pasid = IOMMU_PASID_INVALID - 1;
+	} else if (dev->iommu->max_pasids) {
+		/*
+		 * max_pasids is set up by vendor driver based on number of
+		 * PASID bits supported but the IDA allocation is inclusive.
+		 */
+		max_pasid = dev->iommu->max_pasids - 1;
+	} else {
+		/* max_pasids == 0 means that the device does not support PASID */
 		return IOMMU_PASID_INVALID;
+	}
 
-	/*
-	 * max_pasids is set up by vendor driver based on number of PASID bits
-	 * supported but the IDA allocation is inclusive.
-	 */
 	ret = ida_alloc_range(&iommu_global_pasid_ida, IOMMU_FIRST_GLOBAL_PASID,
-			      dev->iommu->max_pasids - 1, GFP_KERNEL);
+			      max_pasid, GFP_KERNEL);
 	return ret < 0 ? IOMMU_PASID_INVALID : ret;
 }
 EXPORT_SYMBOL_GPL(iommu_alloc_global_pasid);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ef5043752a36..131595da295f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1663,6 +1663,8 @@ static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm)
 void mm_pasid_drop(struct mm_struct *mm);
 struct iommu_sva *iommu_sva_bind_device(struct device *dev,
 					struct mm_struct *mm);
+int iommu_sva_bind_device_no_iommu(struct device *dev,
+				   struct mm_struct *mm);
 void iommu_sva_unbind_device(struct iommu_sva *handle);
 u32 iommu_sva_get_pasid(struct iommu_sva *handle);
 void iommu_sva_invalidate_kva_range(unsigned long start, unsigned long end);
@@ -1673,6 +1675,12 @@ iommu_sva_bind_device(struct device *dev, struct mm_struct *mm)
 	return ERR_PTR(-ENODEV);
 }
 
+static inline int iommu_sva_bind_device_no_iommu(struct device *dev,
+				   struct mm_struct *mm)
+{
+	return -ENODEV;
+}
+
 static inline void iommu_sva_unbind_device(struct iommu_sva *handle)
 {
 }
-- 
2.56.1


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

* [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation
  2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
  2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
@ 2026-12-04 14:45 ` Sven Schnelle
  2026-12-04 15:22   ` sashiko-bot
  2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
  2 siblings, 1 reply; 8+ messages in thread
From: Sven Schnelle @ 2026-12-04 14:45 UTC (permalink / raw)
  To: Marc Zyngier, Mark Rutland, Joerg Roedel (AMD), Will Deacon
  Cc: Robin Murphy, Catalin Marinas, Sudeep Holla, Ard Biesheuvel,
	linux-kernel, iommu, linux-arm-kernel, Christian Borntraeger,
	Hendrik Brueckner, Ulrich Weigand, Arnd Bergmann, linux-s390

Add the yaml file describing platform-accel. Also add the file to
MAINTAINERS.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
 .../bindings/firmware/platform-accel.yaml     | 37 +++++++++++++++++++
 MAINTAINERS                                   |  7 ++++
 2 files changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/platform-accel.yaml

diff --git a/Documentation/devicetree/bindings/firmware/platform-accel.yaml b/Documentation/devicetree/bindings/firmware/platform-accel.yaml
new file mode 100644
index 000000000000..056a62b05a7c
--- /dev/null
+++ b/Documentation/devicetree/bindings/firmware/platform-accel.yaml
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/firmware/platform-accel.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: IBM Platform acceleration for ARM guests
+
+description:
+  A memory region available on s390 in ARM guests used to perform hardware
+  acceleration functions.
+
+maintainers:
+  - Sven Schnelle <svens@linux.ibm.com>
+
+properties:
+  compatible:
+    enum:
+      - ibm,platform-accel-v1.0-cpacf
+      - ibm,platform-accel-v1.0-dfltcc
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    platform-accel@0 {
+        compatible = "ibm,platform-accel-v1.0-cpacf";
+        reg = <0x0 0x10000>;
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 02ac35ecda70..139ef5d1ebe4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24755,6 +24755,13 @@ F:	drivers/cpuidle/cpuidle-s390.c
 F:	drivers/s390/
 F:	drivers/watchdog/diag288_wdt.c
 
+S390 ARM GUEST ACCELERATION DRIVER
+M:	Sven Schnelle <svens@linux.ibm.com>
+L:	linux-s390@vger.kernel.org
+S:	Supported
+F:	Documentation/devicetree/bindings/firmware/platform-accel.yaml
+F:	drivers/firmware/platform-accel.c
+
 S390 COMMON I/O LAYER
 M:	Vineeth Vijayan <vneethv@linux.ibm.com>
 M:	Peter Oberparleiter <oberpar@linux.ibm.com>
-- 
2.56.1


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

* [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver
  2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
  2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
  2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
@ 2026-12-04 14:45 ` Sven Schnelle
  2026-12-04 15:28   ` Arnd Bergmann
  2026-12-04 15:45   ` sashiko-bot
  2 siblings, 2 replies; 8+ messages in thread
From: Sven Schnelle @ 2026-12-04 14:45 UTC (permalink / raw)
  To: Marc Zyngier, Mark Rutland, Joerg Roedel (AMD), Will Deacon
  Cc: Robin Murphy, Catalin Marinas, Sudeep Holla, Ard Biesheuvel,
	linux-kernel, iommu, linux-arm-kernel, Christian Borntraeger,
	Hendrik Brueckner, Ulrich Weigand, Arnd Bergmann, linux-s390

s390 support for ARM guests supports hardware acceleration for
crypto and other functions. This is implemented by providing a special
memory region that can be accessed via st64bv0. To allow userspace to
utilize this functionality, add a driver to map the accelerator memory
region into the userspace process. Note that the misc device files
are created with permission 0666 so all userspace processes can use
the driver without additional configuration.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
 drivers/firmware/Kconfig          |  10 ++
 drivers/firmware/Makefile         |   1 +
 drivers/firmware/platform-accel.c | 168 ++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+)
 create mode 100644 drivers/firmware/platform-accel.c

diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 43e2e2a64594..bc90aa19b5d3 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -299,6 +299,16 @@ config TURRIS_MOX_RWTM_KEYCTL
 
 endif # TURRIS_MOX_RWTM
 
+config PLATFORM_ACCEL
+	tristate "Acceleration driver for arm64"
+	depends on ARM64
+	select IOMMU_SVA
+	help
+	  Say y here to enable the platform driver for providing a userspace
+	  device to utilize acceleration in s390 ARM KVM guests. This works by
+	  providing a misc device which can be used to mmap() the required
+	  memory region and perform functions with st64bv0 on it.
+
 source "drivers/firmware/arm_ffa/Kconfig"
 source "drivers/firmware/arm_rmm/Kconfig"
 source "drivers/firmware/broadcom/Kconfig"
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 50b338313152..c76e84872fc1 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_TH1520_AON_PROTOCOL) += thead,th1520-aon.o
 obj-$(CONFIG_TI_SCI_PROTOCOL)	+= ti_sci.o
 obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
 obj-$(CONFIG_TURRIS_MOX_RWTM)	+= turris-mox-rwtm.o
+obj-$(CONFIG_PLATFORM_ACCEL)	+= platform-accel.o
 
 obj-y				+= arm_ffa/
 obj-y				+= arm_rmm/
diff --git a/drivers/firmware/platform-accel.c b/drivers/firmware/platform-accel.c
new file mode 100644
index 000000000000..0e77a8243d03
--- /dev/null
+++ b/drivers/firmware/platform-accel.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/acpi.h>
+#include <linux/io.h>
+#include <linux/mm.h>
+#include <linux/miscdevice.h>
+#include <linux/iommu.h>
+#include <linux/cpufeature.h>
+#include <linux/pgtable.h>
+
+struct platform_accel {
+	struct platform_device *pdev;
+	resource_size_t phys_size;
+	phys_addr_t phys_base;
+	struct miscdevice misc;
+	struct mutex lock;
+	bool present;
+};
+
+static int platform_accel_mmap(struct file *filep, struct vm_area_struct *vma)
+{
+	struct miscdevice *misc = filep->private_data;
+	struct platform_accel *dev = container_of(misc, struct platform_accel, misc);
+	int ret = -ENODEV;
+
+	mutex_lock(&dev->lock);
+	if (!dev->present)
+		goto out;
+
+	ret = iommu_sva_bind_device_no_iommu(&dev->pdev->dev, current->mm);
+	if (ret)
+		goto out;
+	vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
+	ret = vm_iomap_memory(vma, dev->phys_base, dev->phys_size);
+out:
+	mutex_unlock(&dev->lock);
+	return ret;
+}
+
+static const struct file_operations platform_accel_fops = {
+	.owner = THIS_MODULE,
+	.open = nonseekable_open,
+	.mmap = platform_accel_mmap,
+};
+
+static struct platform_accel platform_accel_dev_cpacf = {
+	.misc = {
+		.name = "platform-accel-cpacf",
+		.minor = MISC_DYNAMIC_MINOR,
+		.fops = &platform_accel_fops,
+		.mode = 0666,
+	},
+	.lock = __MUTEX_INITIALIZER(platform_accel_dev_cpacf.lock),
+};
+
+static struct platform_accel platform_accel_dev_dfltcc = {
+	.misc = {
+		.name = "platform-accel-dfltcc",
+		.minor = MISC_DYNAMIC_MINOR,
+		.fops = &platform_accel_fops,
+		.mode = 0666,
+	},
+	.lock = __MUTEX_INITIALIZER(platform_accel_dev_dfltcc.lock),
+};
+
+static int platform_accel_do_platform_probe(struct platform_device *pdev)
+{
+	struct platform_accel *dev = platform_get_drvdata(pdev);
+	struct resource *r;
+	void __iomem *ret;
+
+	ret = devm_platform_get_and_ioremap_resource(pdev, 0, &r);
+	if (IS_ERR(ret))
+		return PTR_ERR(ret);
+
+	dev_info(&pdev->dev, "mmio at %pR\n", r);
+	dev->phys_base = r->start;
+	dev->phys_size = resource_size(r);
+	dev->pdev = pdev;
+	return 0;
+}
+
+static int platform_accel_probe(struct platform_device *pdev)
+{
+	struct platform_accel *dev;
+	int err;
+
+	if (!system_supports_ls64_accdata())
+		return -ENODEV;
+
+	dev = (struct platform_accel *)device_get_match_data(&pdev->dev);
+	if (!dev)
+		return -EINVAL;
+
+	mutex_lock(&dev->lock);
+	if (dev->present) {
+		err = -EBUSY;
+		goto out;
+	}
+	platform_set_drvdata(pdev, dev);
+
+	err = platform_accel_do_platform_probe(pdev);
+	if (err)
+		goto err_clear;
+
+	dev->present = true;
+	err = misc_register(&dev->misc);
+	if (err)
+		goto err_cleanup;
+	mutex_unlock(&dev->lock);
+	return 0;
+
+err_cleanup:
+	dev->present = false;
+err_clear:
+	platform_set_drvdata(pdev, NULL);
+out:
+	mutex_unlock(&dev->lock);
+	return err;
+}
+
+static void platform_accel_remove(struct platform_device *pdev)
+{
+	struct platform_accel *dev = platform_get_drvdata(pdev);
+
+	mutex_lock(&dev->lock);
+	misc_deregister(&dev->misc);
+	dev->present = false;
+	platform_set_drvdata(pdev, NULL);
+	dev->pdev = NULL;
+	mutex_unlock(&dev->lock);
+}
+
+static const struct of_device_id platform_accel_of_match[] = {
+	{ .compatible = "ibm,platform-accel-v1.0-cpacf", .data = &platform_accel_dev_cpacf },
+	{ .compatible = "ibm,platform-accel-v1.0-dfltcc", .data = &platform_accel_dev_dfltcc },
+	{},
+};
+MODULE_DEVICE_TABLE(of, platform_accel_of_match);
+
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id platform_accel_acpi_match[] = {
+	{ "IBM077A", (kernel_ulong_t)&platform_accel_dev_cpacf },
+	{ "IBM077B", (kernel_ulong_t)&platform_accel_dev_dfltcc },
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, platform_accel_acpi_match);
+#endif
+
+static struct platform_driver platform_accel_driver = {
+	.probe = platform_accel_probe,
+	.remove = platform_accel_remove,
+	.driver = {
+		.name = "platform-accel",
+		.of_match_table = platform_accel_of_match,
+#if IS_ENABLED(CONFIG_ACPI)
+		.acpi_match_table = ACPI_PTR(platform_accel_acpi_match),
+#endif
+	},
+};
+
+module_platform_driver(platform_accel_driver);
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("IBM s390 ARM acceleration platform driver");
+MODULE_LICENSE("GPL");
-- 
2.56.1


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

* Re: [PATCH 1/3] iommu: sva: allow SVA without PASID
  2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
@ 2026-12-04 15:12   ` sashiko-bot
  0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04 15:12 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] iommu: unlocked dev->iommu dereference races with
  iommu_init_device()
- [Medium] iommu/sva: IOMMU_SVA stays under IOMMU_SUPPORT without
  selecting IOMMU_API
- [Low] iommu/sva: misleading kernel-doc in
  iommu_sva_bind_device_no_iommu()
--

commit 8cca46e12185238c9aeda86bc1c45d0a7bb8e5f9
Author: Arnd Bergmann <arnd@arndb.de>

iommu: sva: allow SVA without PASID

This commit adds iommu_sva_bind_device_no_iommu() so devices without an
IOMMU can install an iommu_mm_data object and allocate a global PASID on
an mm_struct, and updates iommu_alloc_mm_data() and
iommu_alloc_global_pasid() to handle a NULL dev->iommu.

> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> index 9827cb8043635..b444f3483f6df 100644
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c

[ ... ]

> @@ -156,6 +156,35 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
>  }
>  EXPORT_SYMBOL_GPL(iommu_sva_bind_device);
>  
> +/**
> + * iommu_sva_bind_device_no_iommu() - Bind a process address space to a device without iommu
> + * @dev: the device
> + * @mm: the mm to bind, caller must hold a reference to mm_users
> + *
> + * Allow the use of shared virtual addressing on devices that transparently
> + * use the CPU's page table instead of an IOMMU. A global PASID is allocated
> + * in case the same process uses another device with an IOMMU later.
> + *
> + * The reference is held until the mm_struct is destroyed.

[Severity: Low]
Is "The reference is held until the mm_struct is destroyed" accurate?
iommu_sva_bind_device_no_iommu() takes no reference on mm or dev and
allocates no iommu_sva handle; only mm->iommu_mm and its global PASID
remain allocated until mm_pasid_drop() runs in __mmdrop().  Describing
the lifetime of mm->iommu_mm and that no explicit unbind is needed would
avoid misleading callers.

[ ... ]

> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index b486b8bbd1fcd..1470bb9c1ca89 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3827,17 +3827,24 @@ EXPORT_SYMBOL_GPL(iommu_detach_device_pasid);
>  ioasid_t iommu_alloc_global_pasid(struct device *dev)
>  {
>  	int ret;
> +	unsigned int max_pasid;
>  
> -	/* max_pasids == 0 means that the device does not support PASID */
> -	if (!dev->iommu->max_pasids)
> +	if (!dev->iommu) {
> +		/* no IOMMU but capable of enqcmd/st64bv0: pick any PASID */
> +		max_pasid = IOMMU_PASID_INVALID - 1;
> +	} else if (dev->iommu->max_pasids) {
> +		/*
> +		 * max_pasids is set up by vendor driver based on number of
> +		 * PASID bits supported but the IDA allocation is inclusive.
> +		 */
> +		max_pasid = dev->iommu->max_pasids - 1;
> +	} else {
> +		/* max_pasids == 0 means that the device does not support PASID */
>  		return IOMMU_PASID_INVALID;
> +	}

[Severity: Medium]
Can reading and dereferencing dev->iommu here without
iommu_probe_device_lock race with iommu_init_device()?

Previously, iommu_alloc_mm_data() and iommu_alloc_global_pasid() were
only reached when dev->iommu_group was non-NULL, so
__iommu_probe_device() returned early without touching dev->iommu.  When
iommu_sva_bind_device_no_iommu() runs with dev->iommu_group == NULL, a
concurrent iommu_device_register() scan via bus_iommu_probe() calls
iommu_init_device(dev), which transiently allocates dev->iommu with
max_pasids == 0 and then frees it with kfree() in dev_iommu_free() under
iommu_probe_device_lock:

CPU0                                    CPU1
iommu_sva_bind_device_no_iommu()        iommu_device_register()
  mutex_lock(&iommu_sva_lock)             ... -> __iommu_probe_device()
  iommu_alloc_mm_data()                     lock(&iommu_probe_device_lock)
    iommu_alloc_global_pasid()              iommu_init_device()
                                              dev_iommu_get(dev)
                                                dev->iommu = param
      if (!dev->iommu) /* non-NULL */
                                              dev_iommu_free(dev)
                                                dev->iommu = NULL
                                                kfree(param)
      else if (dev->iommu->max_pasids)
               <-- use-after-free

Depending on whether the compiler caches or reloads dev->iommu, this can
cause a slab use-after-free read, a NULL pointer dereference, or a
spurious -ENOSPC/-EOVERFLOW if transient max_pasids == 0 is observed
before kfree().  iommu_alloc_mm_data() has the same unlocked dev->iommu
dereference, and iommu_sva_bind_device_no_iommu() also checks
dev->iommu_group without iommu_probe_device_lock.

[ ... ]

> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index ef5043752a365..131595da295f7 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -1663,6 +1663,8 @@ static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm)
>  void mm_pasid_drop(struct mm_struct *mm);
>  struct iommu_sva *iommu_sva_bind_device(struct device *dev,
>  					struct mm_struct *mm);
> +int iommu_sva_bind_device_no_iommu(struct device *dev,
> +				   struct mm_struct *mm);

[Severity: Medium]
Does selecting IOMMU_SVA from a no-IOMMU driver break the build when
CONFIG_IOMMU_SUPPORT=n?

In drivers/iommu/Kconfig, config IOMMU_SVA stays nested inside
if IOMMU_SUPPORT and selects IOMMU_MM_DATA without selecting IOMMU_API.
When a no-IOMMU driver (such as commit "drivers: firmware: add ARM on
s390 accelerator driver") selects IOMMU_SVA with CONFIG_IOMMU_SUPPORT=n
and nothing else enabling CONFIG_IOMMU_API, Kconfig warns about the
unmet IOMMU_SUPPORT dependency and enables CONFIG_IOMMU_SVA and
CONFIG_IOMMU_MM_DATA while CONFIG_IOMMU_API stays disabled.

In that configuration, drivers/iommu/Makefile builds iommu-sva.o without
iommu.o, while struct iommu_mm_data, struct dev_iommu, and the real
iommu_alloc_global_pasid() remain inside #ifdef CONFIG_IOMMU_API in
include/linux/iommu.h, causing compilation failures in
mm_get_enqcmd_pasid() and iommu-sva.c.  Moving config IOMMU_SVA outside
if IOMMU_SUPPORT and adding select IOMMU_API (or factoring global PASID
and iommu_mm_data out of CONFIG_IOMMU_API) would prevent both the
warning and the build failure.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204144529.960326-1-svens@linux.ibm.com?part=1

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

* Re: [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation
  2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
@ 2026-12-04 15:22   ` sashiko-bot
  0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04 15:22 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: firmware: platform-accel.yaml omits ibm, vendor
  prefix
- [Low] dt-bindings: firmware: redundant subject wording and sparse
  commit message
--

commit 96caa6c7ae9ea1cedd3eb34736d8972af96b5d88
Author: Sven Schnelle <svens@linux.ibm.com>

> dt-bindings: firmware: platform-accel: add yaml documentation
>
> Add the yaml file describing platform-accel. Also add the file to
> MAINTAINERS.
>
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>

[Severity: Low]
Can the subject and commit message be expanded to follow dt-bindings
conventions and match the diff?

Documentation/devicetree/bindings/submitting-patches.rst recommends omitting
words like "yaml" and "documentation" from dt-bindings subjects since the
prefix already implies them, e.g. "dt-bindings: firmware: Add IBM platform
acceleration for ARM guests".

The body only states which files are touched without explaining the s390 ARM
guest acceleration mechanism, what cpacf and dfltcc represent, or why two
compatibles with identical properties are defined without a fallback.

It also says "add the file to MAINTAINERS", whereas the diff adds a new
section listing both the binding and drivers/firmware/platform-accel.c.

> diff --git a/Documentation/devicetree/bindings/firmware/platform-accel.yaml b/Documentation/devicetree/bindings/firmware/platform-accel.yaml
> new file mode 100644
> index 0000000000000..056a62b05a7cb
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/firmware/platform-accel.yaml
> @@ -0,0 +1,37 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/firmware/platform-accel.yaml#

[Severity: Low]
Should this binding file and its $id carry the ibm, vendor prefix?

Documentation/devicetree/bindings/writing-bindings.rst calls for naming
schemas like compatible strings (vendor,device.yaml), matching all other
files under Documentation/devicetree/bindings/firmware/.

Since this schema only describes IBM-specific compatibles
(ibm,platform-accel-v1.0-cpacf and ibm,platform-accel-v1.0-dfltcc),
consider renaming it to ibm,platform-accel.yaml and updating $id and the
MAINTAINERS F: entry.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204144529.960326-1-svens@linux.ibm.com?part=2

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

* Re: [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver
  2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
@ 2026-12-04 15:28   ` Arnd Bergmann
  2026-12-04 15:45   ` sashiko-bot
  1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2026-12-04 15:28 UTC (permalink / raw)
  To: Sven Schnelle, Marc Zyngier, Mark Rutland, Joerg Roedel,
	Will Deacon
  Cc: Robin Murphy, Catalin Marinas, Sudeep Holla, Ard Biesheuvel,
	linux-kernel, iommu, linux-arm-kernel, Christian Borntraeger,
	Hendrik Brueckner, Ulrich Weigand, linux-s390

On Fri, Dec 4, 2026, at 15:45, Sven Schnelle wrote:
> s390 support for ARM guests supports hardware acceleration for
> crypto and other functions. This is implemented by providing a special
> memory region that can be accessed via st64bv0. To allow userspace to
> utilize this functionality, add a driver to map the accelerator memory
> region into the userspace process. Note that the misc device files
> are created with permission 0666 so all userspace processes can use
> the driver without additional configuration.
>
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>

Hi Sven,

I noticed a few details:

> +config PLATFORM_ACCEL
> +	tristate "Acceleration driver for arm64"
> +	depends on ARM64
> +	select IOMMU_SVA

CONFIG_IOMMU_SVA depends on CONFIG_IOMMU_SUPPORT, so you need to
make this

      depends on IOMMU_SUPPORT

Ideally it would also be 'depends on ARM64 || COMPILE_TEST' to
give it build test coverage on other architectures, but only
if you can easily make it compile portably.

> +static int platform_accel_mmap(struct file *filep, struct 
> vm_area_struct *vma)

Lorenzo has been going through device drivers to convert the .mmap()
callback to .mmap_prepare(), see https://lore.kernel.org/all/?q=mmap_prepare
for recent patches. It's probably best to do the same thing here.

> +static int platform_accel_probe(struct platform_device *pdev)
> +{
> +	struct platform_accel *dev;
> +	int err;
> +
> +	if (!system_supports_ls64_accdata())
> +		return -ENODEV;

I think the system_supports_ls64_accdata() call is the only compile time
dependency on my "arm64: dynamically enable st64bv0 for SVA" patch,  but it's
not actually a runtime dependency as the hypervisor platform should
only provide the device if it can be used, and the failure mode should
still be fine, as userspace should probably check the hwcap as well.

If you take out this call or open-code the check for ARM64_HAS_LS64_ACCDATA,
the series can be merged independently through another tree.

> +      dev_info(&pdev->dev, "mmio at %pR\n", r);

I'd drop this from the production version, as working drivers are
supposed to be quiet.

> +#if IS_ENABLED(CONFIG_ACPI)
> +static const struct acpi_device_id platform_accel_acpi_match[] = {
> +	{ "IBM077A", (kernel_ulong_t)&platform_accel_dev_cpacf },
> +	{ "IBM077B", (kernel_ulong_t)&platform_accel_dev_dfltcc },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(acpi, platform_accel_acpi_match);
> +#endif

No need for the #if check here

> +#if IS_ENABLED(CONFIG_ACPI)
> +		.acpi_match_table = ACPI_PTR(platform_accel_acpi_match),
> +#endif

or the ACPI_PTR() here, which just duplicates the #if check.
I would just always leave the .acpi_match_table entry and waste
a few bytes of .rodata in favor of readability.

      Arnd

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

* Re: [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver
  2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
  2026-12-04 15:28   ` Arnd Bergmann
@ 2026-12-04 15:45   ` sashiko-bot
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04 15:45 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] firmware: platform-accel: AB-BA deadlock in
  platform_accel_mmap()
- [High] firmware: platform-accel: missing VM_SHARED check allows
  MAP_PRIVATE MMIO COW
- [Medium] firmware: platform-accel: missing IOMMU_SUPPORT dependency in
  Kconfig
- [Medium] firmware: platform-accel: missing CONFIG_ARM64_LS64_ACCDATA
  check
- [Medium] firmware: platform-accel: missing PAGE_SIZE alignment check
  on MMIO resource
- [Medium] firmware: platform-accel: missing VMA revocation in
  platform_accel_remove()
- [Medium] firmware: platform-accel: missing VM_DONTCOPY leaks unbound
  MMIO across fork()
- [Low] firmware: platform-accel: unused kernel ioremap in probe
--

commit 7b5f761f498fd31a0537f5d7386952caeaaf03c4
Author: Sven Schnelle <svens@linux.ibm.com>

drivers: firmware: add ARM on s390 accelerator driver

This commit adds a platform driver for arm64 s390 KVM guests that exposes
accelerator MMIO regions via misc devices so userspace can mmap() them and
use st64bv0.

> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> index 43e2e2a645945..bc90aa19b5d38 100644
> --- a/drivers/firmware/Kconfig
> +++ b/drivers/firmware/Kconfig
> @@ -299,6 +299,16 @@ config TURRIS_MOX_RWTM_KEYCTL
>  
>  endif # TURRIS_MOX_RWTM
>  
> +config PLATFORM_ACCEL
> +	tristate "Acceleration driver for arm64"
> +	depends on ARM64
> +	select IOMMU_SVA

[Severity: Medium]
Can selecting IOMMU_SVA without depending on IOMMU_SUPPORT break the build
when CONFIG_IOMMU_SUPPORT is disabled?

IOMMU_SVA lives inside "if IOMMU_SUPPORT" in drivers/iommu/Kconfig.  When
CONFIG_IOMMU_SUPPORT=n, selecting IOMMU_SVA emits an unmet dependency
warning and compiles drivers/iommu/iommu-sva.c without CONFIG_IOMMU_API,
failing on undefined struct dev_iommu fields and missing
iommu_attach_handle_get().

Adding "depends on IOMMU_SUPPORT" ensures IOMMU_API is enabled alongside
IOMMU_SVA.

[ ... ]

> diff --git a/drivers/firmware/platform-accel.c b/drivers/firmware/platform-accel.c
> new file mode 100644
> index 0000000000000..0e77a8243d038
> --- /dev/null
> +++ b/drivers/firmware/platform-accel.c

[ ... ]

> +static int platform_accel_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> +	struct miscdevice *misc = filep->private_data;
> +	struct platform_accel *dev = container_of(misc, struct platform_accel, misc);
> +	int ret = -ENODEV;
> +
> +	mutex_lock(&dev->lock);
> +	if (!dev->present)
> +		goto out;
> +
> +	ret = iommu_sva_bind_device_no_iommu(&dev->pdev->dev, current->mm);
> +	if (ret)
> +		goto out;

[Severity: High]
Can calling iommu_sva_bind_device_no_iommu() from platform_accel_mmap()
cause an ABBA deadlock between mm->mmap_lock and iommu_sva_lock?

vm_mmap_pgoff() holds current->mm->mmap_lock for writing across
f_op->mmap(), so platform_accel_mmap() acquires iommu_sva_lock inside
mm->mmap_lock.  Meanwhile, iommu_sva_bind_device() acquires iommu_sva_lock
before calling arm_smmu_sva_domain_alloc() -> mmu_notifier_register(),
which takes mmap_write_lock(mm):

CPU0                              CPU1
----                              ----
lock(&mm->mmap_lock)
                                  lock(&iommu_sva_lock)
lock(&iommu_sva_lock)
                                  lock(&mm->mmap_lock)

 *** DEADLOCK ***

CPU0: vm_mmap_pgoff() -> ... -> platform_accel_mmap()
      -> iommu_sva_bind_device_no_iommu()
CPU1: iommu_sva_bind_device() -> iommu_sva_domain_alloc()
      -> arm_smmu_sva_domain_alloc() -> mmu_notifier_register()

Binding SVA before vm_iomap_memory() also permanently allocates a global
PASID on current->mm even if vm_iomap_memory() fails with -EINVAL.
Performing SVA binding outside mmap_lock (for example in f_op->open(),
without nesting dev->lock across misc_mtx) avoids both problems.

> +	vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
> +	ret = vm_iomap_memory(vma, dev->phys_base, dev->phys_size);

[Severity: High]
Should platform_accel_mmap() reject MAP_PRIVATE mappings by checking
VM_SHARED?

Because the device is mode 0666, any unprivileged user can mmap it with
MAP_PRIVATE and write to it.  do_wp_page() -> wp_page_copy() then executes
kernel reads directly from the Device-nGnRE MMIO window in
__wp_page_copy_user(), hitting WARN_ON_ONCE(1) if normal loads fail.

wp_page_copy() also maps the newly allocated normal RAM folio with
vma->vm_page_prot (MT_DEVICE_nGnRE), creating a mismatched memory-attribute
alias with the MT_NORMAL kernel linear map on arm64.

[Severity: Medium]
Should platform_accel_mmap() set VM_DONTCOPY on vma?

Without VM_DONTCOPY, fork() copies the Device-nGnRE MMIO PTEs into the
child even though mm_pasid_init() clears child->mm->iommu_mm and
copy_thread_ls64_accdata() clears SCTLR_EL1_EnAS0.  Executing st64bv0 in
the child then traps with SIGBUS, while regular accesses still reach MMIO.

[ ... ]

> +static int platform_accel_do_platform_probe(struct platform_device *pdev)
> +{
> +	struct platform_accel *dev = platform_get_drvdata(pdev);
> +	struct resource *r;
> +	void __iomem *ret;
> +
> +	ret = devm_platform_get_and_ioremap_resource(pdev, 0, &r);
> +	if (IS_ERR(ret))
> +		return PTR_ERR(ret);

[Severity: Low]
Is the kernel ioremap mapping created by
devm_platform_get_and_ioremap_resource() needed here?

The returned pointer is never used because the driver only exposes the
physical range to userspace via vm_iomap_memory().  Using
platform_get_resource() with devm_request_mem_region() avoids allocating
unused kernel virtual address space and page-table entries.

> +	dev_info(&pdev->dev, "mmio at %pR\n", r);
> +	dev->phys_base = r->start;
> +	dev->phys_size = resource_size(r);

[Severity: Medium]
Should r->start and resource_size(r) be checked for PAGE_SIZE alignment?

If firmware provides a 4 KiB-aligned resource on a 16 KiB or 64 KiB page
arm64 kernel, __simple_ioremap_prep() silently rounds the base down and
size up to PAGE_SIZE boundaries.  That exposes adjacent physical address
space to unprivileged userspace and shifts offset 0 of the mapping.

[ ... ]

> +static int platform_accel_probe(struct platform_device *pdev)
> +{
> +	struct platform_accel *dev;
> +	int err;
> +
> +	if (!system_supports_ls64_accdata())
> +		return -ENODEV;

[Severity: Medium]
Does platform_accel_probe() still succeed when CONFIG_ARM64_LS64_ACCDATA
is disabled?

system_supports_ls64_accdata() only checks the hardware CPU capability, so
the driver still creates the misc devices when CONFIG_ARM64_LS64_ACCDATA=n.
Userspace executing st64bv0 then hits try_enable_st64bv0(), which returns
false and delivers SIGBUS.

Checking IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) here, or depending on
ARM64_LS64_ACCDATA in Kconfig, prevents exposing unusable devices.

[ ... ]

> +static void platform_accel_remove(struct platform_device *pdev)
> +{
> +	struct platform_accel *dev = platform_get_drvdata(pdev);
> +
> +	mutex_lock(&dev->lock);
> +	misc_deregister(&dev->misc);
> +	dev->present = false;
> +	platform_set_drvdata(pdev, NULL);
> +	dev->pdev = NULL;
> +	mutex_unlock(&dev->lock);
> +}

[Severity: Medium]
Can userspace retain live MMIO PTEs after platform_accel_remove() releases
the memory region?

misc_deregister() does not zap existing userspace VMAs, so after devres
releases the IORESOURCE_MEM region on unbind or hot-remove, processes with
an active mmap() keep writable VM_IO | VM_PFNMAP mappings pointing to the
released physical range.

Recording the inode mapping and calling unmap_mapping_range() during
removal (as uacce_remove() does) would revoke active mappings before
releasing the resource.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204144529.960326-1-svens@linux.ibm.com?part=3

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

end of thread, other threads:[~2026-12-04 15:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
2026-12-04 15:12   ` sashiko-bot
2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
2026-12-04 15:22   ` sashiko-bot
2026-12-04 14:45 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Sven Schnelle
2026-12-04 15:28   ` Arnd Bergmann
2026-12-04 15:45   ` sashiko-bot

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