[PATCH v5 10/11] iommu/vt-d: Add nested domain allocation
From: Yi Liu
Date: Thu Sep 21 2023 - 16:19:10 EST
From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
This adds the support for IOMMU_HWPT_TYPE_VTD_S1 type.
Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx>
---
drivers/iommu/intel/iommu.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index c93c91ed4ee2..9b10e4b1d400 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4077,19 +4077,35 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
struct iommu_domain *parent,
const struct iommu_user_data *user_data)
{
+ bool request_nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
struct iommu_domain *domain;
struct intel_iommu *iommu;
+ if (hwpt_type != IOMMU_HWPT_TYPE_DEFAULT &&
+ hwpt_type != IOMMU_HWPT_TYPE_VTD_S1)
+ return ERR_PTR(-EINVAL);
+
+ if ((hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) == !!parent)
+ return ERR_PTR(-EINVAL);
+
+ if (parent && request_nest_parent)
+ return ERR_PTR(-EINVAL);
+
iommu = device_to_iommu(dev, NULL, NULL);
if (!iommu)
return ERR_PTR(-ENODEV);
- if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap))
+ if ((parent || request_nest_parent) && !ecap_nest(iommu->ecap))
return ERR_PTR(-EOPNOTSUPP);
- domain = iommu_domain_alloc(dev->bus);
- if (!domain)
- domain = ERR_PTR(-ENOMEM);
+ if (parent) {
+ domain = intel_nested_domain_alloc(parent, user_data);
+ } else {
+ domain = iommu_domain_alloc(dev->bus);
+ if (!domain)
+ domain = ERR_PTR(-ENOMEM);
+ }
+
return domain;
}
--
2.34.1