[PATCH v5 10/11] iommu/vt-d: Add nested domain allocation

Yi Liu posted 11 patches 1 year, 11 months ago
[PATCH v5 10/11] iommu/vt-d: Add nested domain allocation
Posted by Yi Liu 1 year, 11 months ago
From: Lu Baolu <baolu.lu@linux.intel.com>

This adds the support for IOMMU_HWPT_TYPE_VTD_S1 type.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 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
RE: [PATCH v5 10/11] iommu/vt-d: Add nested domain allocation
Posted by Tian, Kevin 1 year, 11 months ago
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Thursday, September 21, 2023 3:55 PM
> 
> 
> +	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);

this is probably too strict. What about intel-iommu driver supports a
IOMMU_HWPT_TYPE_VTD_S2 later for some tweak w/o nesting?

let's make the parent match specific to VTD_S1 type.

> +
> +	if (parent && request_nest_parent)
> +		return ERR_PTR(-EINVAL);

this check should be moved to iommufd?
Re: [PATCH v5 10/11] iommu/vt-d: Add nested domain allocation
Posted by Yi Liu 1 year, 11 months ago
On 2023/9/27 14:56, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Thursday, September 21, 2023 3:55 PM
>>
>>
>> +	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);
> 
> this is probably too strict. What about intel-iommu driver supports a
> IOMMU_HWPT_TYPE_VTD_S2 later for some tweak w/o nesting?

in that case, this check needs to be updated

> let's make the parent match specific to VTD_S1 type.

ok. how about below?

if ((data_type == IOMMU_HWPT_ALLOC_DATA_VTD_S1) && !parent)

>> +
>> +	if (parent && request_nest_parent)
>> +		return ERR_PTR(-EINVAL);
> 
> this check should be moved to iommufd?
> 

oops, maybe no need, iommufd_hwpt_alloc() has below check.

if (cmd->flags & IOMMU_HWPT_ALLOC_NEST_PARENT &&
     cmd->data_type != IOMMU_HWPT_ALLOC_DATA_NONE)
         return -EINVAL;

-- 
Regards,
Yi Liu