Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Schnelle <svens@linux.ibm.com>
To: Marc Zyngier <maz@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	"Joerg Roedel (AMD)" <joro@8bytes.org>,
	Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Sudeep Holla <sudeep.holla@kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Hendrik Brueckner <brueckner@linux.ibm.com>,
	Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-s390@vger.kernel.org
Subject: [PATCH 1/3] iommu: sva: allow SVA without PASID
Date: Fri,  4 Dec 2026 15:45:27 +0100	[thread overview]
Message-ID: <20261204144529.960326-2-svens@linux.ibm.com> (raw)
In-Reply-To: <20261204144529.960326-1-svens@linux.ibm.com>

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



  reply	other threads:[~2026-12-04 14:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
2026-12-04 14:45 ` Sven Schnelle [this message]
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
2026-12-04 15:28   ` Arnd Bergmann

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=20261204144529.960326-2-svens@linux.ibm.com \
    --to=svens@linux.ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=borntraeger@linux.ibm.com \
    --cc=brueckner@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sudeep.holla@kernel.org \
    --cc=will@kernel.org \
    /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