[PATCH RFC] iommu/arm-smmu: allow per-impl capability override and prot masking

Bibek Kumar Patro bibek.patro at oss.qualcomm.com
Tue Dec 1 07:56:33 PST 2026


An SMMU can expose non-coherent translation interfaces while cache
coherency is managed outside the IOMMU driver. Such instances do not set
ARM_SMMU_FEAT_COHERENT_WALK, causing arm_smmu_capable() to reject
IOMMU_CAP_CACHE_COHERENCY and preventing VFIO and iommufd binding.

iommufd also sets IOMMU_CACHE for its mappings. On a non-coherent
interconnect, io-pgtable translates this into Normal WB-RA-WA,
Inner-Shareable attributes that request snoops the interconnect cannot
provide.

Add implementation hooks for overriding capability queries and masking
unsupported protection flags. Apply the protection mask only when
ARM_SMMU_FEAT_COHERENT_WALK is absent, preserving the existing behavior
for coherent instances.

Wire the hooks into qcom_smmu_500_impl and mask IOMMU_CACHE for
non-coherent instances. Export arm_smmu_capable() for use as the default
fallback.

Signed-off-by: Prakash Gupta <prakash.gupta at oss.qualcomm.com>
Signed-off-by: Bibek Kumar Patro <bibek.patro at oss.qualcomm.com>
---
On QCOM devices that are not DMA-coherent: the interconnect between 
the device and memory does not keep CPU caches and device-visible memory
consistent. Such a device can still support valid IOMMU translation
and isolation, but the current VFIO/iommufd capability check requires
IOMMU_CAP_CACHE_COHERENCY, which these devices cannot report, so they
fail to bind. This is not specific to any one userspace framework;
any userspace driver capable of performing the required cache
maintenance faces the same restriction.

                  USERSPACE  (setup, one-time)
    +---------------------------------------------------+
    |              Userspace device driver              |
    +---------------------------------------------------+
        Discover / request              Request DMA
        non-coherent mode                mapping
             |                              |
             +--------------+   +-----------+
                            |   |
                   ioctl(VFIO / iommufd)
  -------------------------|----- USER / KERNEL --------
                            v
      +-------------------------------------------------+
      | VFIO / iommufd device binding                   |
      |  - authorize userspace-managed coherency (*)    |
      |  - pin pages, build DMA mapping                 |
      +-------------------------------------------------+
                            |
                 Programs translation and
                 access permissions
                            v
                      +--------------+
                      |     SMMU     |
                      |  IOVA -> PA  |
                      +--------------+

      (*) Only required when the device is not DMA-coherent;
          coherent devices bind without this step.

              USERSPACE  (steady state, per operation)
    +---------------------------------------------------+
    |              Userspace device driver              |
    +---------------------------------------------------+
        CPU load/store +              (DMA proceeds using
        DC CVAC / DC CIVAC             the mapping built
        - no further ioctl             above)
             |                              |
             v                              v
      +----------------+          +----------------------+
      |  CPU / CPU     |          |  Device -> SMMU ->   |
      |  cache         |          |  memory (translated  |
      |                |          |  DMA access)         |
      +-------+--------+          +----------+-----------+
              |                              |
              +---------------+--------------+
                              |
                              v
                  +-------------------------+
                  |  Memory / interconnect  |
                  +-------------------------+

Where coherency needs to be applied:

 - Before the device reads CPU-written data (including descriptor
   fields), the CPU must clean those cache lines, ordered ahead of
   publishing ownership (e.g. before a doorbell write).
 - Before the CPU reads device-written data or status/descriptor
   updates, it must invalidate its stale cache lines over that
   region.
 - Cache-line-shared objects cannot be blindly cleaned or
   invalidated while a neighbor on the same line is device-owned.

How coherent DMA handles this inherently:

A DMA-coherent device sits on an interconnect that snoops CPU caches,
so hardware keeps the CPU-cache and device-visible views consistent
without software cache maintenance. "dma-coherent" in firmware
describes this hardware property; it does not create it, and
declaring it on hardware that lacks it suppresses required
maintenance and causes stale reads. Coherent DMA still needs memory
barriers around ownership handoff - only the cache clean/invalidate
step becomes unnecessary.

IOMMU_CACHE is a separate, page-table-level attribute: it tells the
IOMMU what memory type and shareability to encode in a mapping, not
whether the device's DMA is cache-coherent. It must not be set on an
interconnect that cannot honor those attributes, regardless of
whether the device is DMA-coherent.

Existing alternatives fall short of a native, isolated userspace
driver:

 - AF_XDP: DMA sync stays in the kernel driver path; no native
   userspace driver with direct device access.
 - Generic UIO: MMIO/interrupt access only, no VFIO/iommufd-style
   IOVA mapping and isolation ABI.
 - VFIO no-IOMMU and out-of-tree non-cacheable remapping both drop
   IOMMU isolation or rely on an unsuitable production ABI:
   (https://github.com/nxp-qoriq/dpdk-extras/tree/main/linux/kpage_ncache)

VFIO/iommufd is not merely a conduit to the SMMU. It is the only
kernel mechanism giving userspace an isolated, pinned DMA mapping,
it owns the IOMMU_CAP_CACHE_COHERENCY check that blocks binding
today, and it sets the IOMMU page-table memory-type attributes for
the mapping - a kernel-only operation independent of what userspace
later does for its own cache lines. Any per-device opt-in
authorization has to live in VFIO/iommufd's binding lifecycle for
the same reason: it is the only place that decides whether the
device is exposed to userspace at all.

This proposal -
1. Keeps IOMMU page-table-walk coherency kernel-owned, unrelated to
   device DMA coherency.
2. Targets the VFIO/iommufd binding check, which requires
   cache-coherent DMA operation even for a device that supports valid
   translated, isolated DMA. Removing the check alone is insufficient,
   since the kernel must still mask mapping attributes (such as
   IOMMU_CACHE) that the interconnect cannot honor.
3. Needs a handshake so the kernel confirms and authorizes userspace
   coherency handling per device, instead of silently assuming
   coherence.

The attached patch implements only the SMMU side of point 2 above:
the capability override and IOMMU_CACHE masking. It does not
implement the opt-in handshake of point 3, or any userspace-side
cache maintenance (the CPU/cache path shown above) - that remains the
userspace driver's responsibility once authorized, as illustrated
by the examples below. This RFC is asking for direction on that
handshake before it is written.

We are seeking feedback on an explicit, per-device opt-in model:
1. No change for devices/drivers using coherent DMA.
2. VFIO/iommufd exposes whether a device needs userspace-managed
   coherency.
3. Userspace explicitly requests and is authorized for that mode
   before binding.
4. Without authorization, today's behavior and failure mode are
   unchanged.
5. Once authorized, the userspace driver owns all DMA-buffer and
   descriptor cache maintenance for that device.

Two examples of the userspace-side mechanism (neither implements
this opt-in contract, and this RFC is not DPDK-specific):
 - DPDK stmmac PMD, ARM64 DC CVAC/DC CIVAC at ownership transitions,
   under review:
   https://lore.kernel.org/all/20261114145539.2470711-1-pkiran@qti.qualcomm.com/
 - enetfec (DPDK + UIO) cache maintenance:
   https://mails.dpdk.org/archives/dev/2025-October/325443.html

To conclude, the intended outcome is not a general coherency bypass.
It is a narrowly scoped, explicit, per-device contract that preserves
IOMMU translation and isolation while allowing an authorized userspace
driver to manage DMA-buffer coherency on hardware that cannot provide
coherent DMA transactions.
---
 drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 16 ++++++++++++++++
 drivers/iommu/arm/arm-smmu/arm-smmu.c      | 18 +++++++++++++++++-
 drivers/iommu/arm/arm-smmu/arm-smmu.h      | 24 ++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
index 795e8ec7e8fa..264f554ea7d3 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
@@ -608,6 +608,20 @@ static int qcom_sdm845_smmu500_reset(struct arm_smmu_device *smmu)
 	return ret;
 }
 
+static bool qcom_smmu_500_capable(struct device *dev, enum iommu_cap cap)
+{
+	struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
+
+	switch (cap) {
+	case IOMMU_CAP_CACHE_COHERENCY:
+		if (!(cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK))
+			return true;
+		fallthrough;
+	default:
+		return arm_smmu_capable_default(dev, cap);
+	}
+}
+
 static const struct arm_smmu_impl qcom_smmu_v2_impl = {
 	.init_context = qcom_smmu_init_context,
 	.cfg_probe = qcom_smmu_cfg_probe,
@@ -623,6 +637,8 @@ static const struct arm_smmu_impl qcom_smmu_500_impl = {
 	.reset = arm_mmu500_reset,
 	.write_s2cr = qcom_smmu_write_s2cr,
 	.tlb_sync = qcom_smmu_tlb_sync,
+	.capable = qcom_smmu_500_capable,
+	.prot_mask = IOMMU_CACHE,
 #ifdef CONFIG_ARM_SMMU_QCOM_DEBUG
 	.context_fault = qcom_smmu_context_fault,
 	.context_fault_needs_threaded_irq = true,
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index 798ab2ed5369..324a9e729112 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1271,6 +1271,11 @@ static int arm_smmu_map_pages(struct iommu_domain *domain, unsigned long iova,
 	if (!ops)
 		return -ENODEV;
 
+	/* Non-coherent walkers cannot safely use cacheable page-table attributes. */
+	if (smmu->impl && smmu->impl->prot_mask &&
+	    !(smmu->features & ARM_SMMU_FEAT_COHERENT_WALK))
+		prot &= ~smmu->impl->prot_mask;
+
 	arm_smmu_rpm_get(smmu);
 	ret = ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, gfp, mapped);
 	arm_smmu_rpm_put(smmu);
@@ -1394,7 +1399,7 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
 	return ops->iova_to_phys(ops, iova);
 }
 
-static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
+bool arm_smmu_capable_default(struct device *dev, enum iommu_cap cap)
 {
 	struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
 
@@ -1416,6 +1421,17 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
 	}
 }
 
+bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
+{
+	struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
+
+	if (cfg->smmu->impl && cfg->smmu->impl->capable)
+		return cfg->smmu->impl->capable(dev, cap);
+
+	return arm_smmu_capable_default(dev, cap);
+}
+EXPORT_SYMBOL_GPL(arm_smmu_capable);
+
 static
 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h
index 26d2e33cd328..edeb08fb33cf 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.h
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h
@@ -455,8 +455,32 @@ struct arm_smmu_impl {
 	void (*write_s2cr)(struct arm_smmu_device *smmu, int idx);
 	void (*write_sctlr)(struct arm_smmu_device *smmu, int idx, u32 reg);
 	void (*probe_finalize)(struct arm_smmu_device *smmu, struct device *dev);
+	/**
+	 * @capable: Per-implementation override for iommu_cap queries.
+	 *
+	 * When set, arm_smmu_capable() calls this hook instead of the
+	 * default COHERENT_WALK / DEV_DMA_COHERENT feature check. The
+	 * hook receives the full arm_smmu_master_cfg so it can inspect
+	 * smmu->features (e.g. ARM_SMMU_FEAT_COHERENT_WALK) to decide
+	 * whether to override or delegate back to arm_smmu_capable().
+	 */
+	bool (*capable)(struct device *dev, enum iommu_cap cap);
+	/**
+	 * @prot_mask: IOMMU_* protection bits to clear in
+	 * arm_smmu_map_pages() before the flags reach io-pgtable.
+	 *
+	 * Applied only when ARM_SMMU_FEAT_COHERENT_WALK is absent on the
+	 * SMMU instance, so coherent platforms that share the same impl
+	 * are not affected. Non-coherent instances set IOMMU_CACHE here
+	 * to prevent arm_lpae_prot_to_pte() from selecting WB+IS
+	 * attributes on an interconnect that cannot honour them.
+	 */
+	int prot_mask;
 };
 
+bool arm_smmu_capable(struct device *dev, enum iommu_cap cap);
+bool arm_smmu_capable_default(struct device *dev, enum iommu_cap cap);
+
 #define INVALID_SMENDX			-1
 #define cfg_smendx(cfg, fw, i) \
 	(i >= fw->num_ids ? INVALID_SMENDX : cfg->smendx[i])

---
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
change-id: 20261201-vfio_non_coherent-7ad5a9908d1e

Best regards,
--  
Bibek Kumar Patro <bibek.patro at oss.qualcomm.com>




More information about the linux-arm-kernel mailing list