[PATCH v2 11/11] iommu/arm-smmu-v3: Allow to share S2 nest_parent domain across vSMMUs

Nicolin Chen nicolinc at nvidia.com
Mon Apr 14 21:57:46 PDT 2025


An S2 nest_parent domain used by one vSMMU can be shared with another vSMMU
so long as the underlying stage-2 page table is compatible by the physical
SMMU instance.

There is no direct information about the page table from the master device,
but a comparison can be done between the physical SMMU that the nest_parent
domain was allocated for and the physical SMMU that the device is behind.

Replace the smmu test in arm_vsmmu_alloc() with a compatibility test, which
goes through the physical SMMU parameters that were used to decide the page
table formats.

Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>
---
 .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     | 21 ++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index 5d05f8a78215..f654e665739a 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -501,6 +501,25 @@ static const struct iommufd_viommu_ops arm_vsmmu_ops = {
 	.cache_invalidate = arm_vsmmu_cache_invalidate,
 };
 
+static bool arm_smmu_s2_parent_can_share(struct arm_smmu_domain *s2_parent,
+					 struct arm_smmu_device *smmu)
+{
+	struct arm_smmu_device *s2_smmu = s2_parent->smmu;
+
+	if (s2_smmu == smmu)
+		return true;
+	if (s2_smmu->iommu.ops != smmu->iommu.ops)
+		return false;
+	if (s2_smmu->ias > smmu->ias || s2_smmu->oas > smmu->oas)
+		return false;
+	if (s2_smmu->pgsize_bitmap != smmu->pgsize_bitmap)
+		return false;
+	if ((s2_smmu->features & ARM_SMMU_FEAT_COHERENCY) !=
+	    (smmu->features & ARM_SMMU_FEAT_COHERENCY))
+		return false;
+	return true;
+}
+
 struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev,
 				       struct iommu_domain *parent,
 				       struct iommufd_ctx *ictx,
@@ -520,7 +539,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev,
 	if (!(smmu->features & ARM_SMMU_FEAT_NESTING))
 		return ERR_PTR(-EOPNOTSUPP);
 
-	if (s2_parent->smmu != master->smmu)
+	if (!arm_smmu_s2_parent_can_share(s2_parent, master->smmu))
 		return ERR_PTR(-EINVAL);
 
 	/*
-- 
2.43.0




More information about the linux-arm-kernel mailing list