[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e6a808167d61bc254aea397cbe75622e02e9d703.1744692494.git.nicolinc@nvidia.com>
Date: Mon, 14 Apr 2025 21:57:46 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <will@...nel.org>, <robin.murphy@....com>, <jgg@...dia.com>
CC: <joro@...tes.org>, <kevin.tian@...el.com>, <praan@...gle.com>,
<nathan@...nel.org>, <yi.l.liu@...el.com>, <peterz@...radead.org>,
<mshavit@...gle.com>, <jsnitsel@...hat.com>, <smostafa@...gle.com>,
<jeff.johnson@....qualcomm.com>, <zhangzekun11@...wei.com>,
<linux-arm-kernel@...ts.infradead.org>, <iommu@...ts.linux.dev>,
<linux-kernel@...r.kernel.org>, <shameerali.kolothum.thodi@...wei.com>
Subject: [PATCH v2 11/11] iommu/arm-smmu-v3: Allow to share S2 nest_parent domain across vSMMUs
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@...dia.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
Powered by blists - more mailing lists