Skip to contentSkip to conversation

iommu/vt-d: Support asynchronous IOMMU nested capabilities

PATCH Superseded Lu Baolu 2 participants 5 messages May 12, 2021 – May 13, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Support asynchronous IOMMU nested capabilities

Current VT-d implementation supports nested translation only if all underlying IOMMUs support the nested capability. This is unnecessary as the upper layer is allowed to create different containers and set them with different type of iommu backend. The IOMMU driver needs to guarantee that devices attached to a nested mode iommu_domain should support nested capabilility.

---
 drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +19 -2
index f1742da42478..1cd4840e6f9f 100644
@@ -4755,6 +4755,13 @@ static int prepare_domain_attach_device(struct iommu_domain *domain,
 	if (!iommu)
 		return -ENODEV;
 
+	if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) &&
+	    !ecap_nest(iommu->ecap)) {
+		dev_err(dev, "%s: iommu not support nested translation\n",
+			iommu->name);
+		return -EINVAL;
+	}
+
 	/* check if this iommu agaw is sufficient for max mapped address */
 	addr_width = agaw_to_width(iommu->agaw);
 	if (addr_width > cap_mgaw(iommu->cap))
@@ -5451,11 +5458,21 @@ static int
 intel_iommu_enable_nesting(struct iommu_domain *domain)
 {
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	bool has_nesting = false;
 	unsigned long flags;
-	int ret = -ENODEV;
+	int ret = -EINVAL;
+
+	for_each_active_iommu(iommu, drhd)
+		if (ecap_nest(iommu->ecap))
+			has_nesting = true;
+
+	if (!has_nesting)
+		return -ENODEV;
 
 	spin_lock_irqsave(&device_domain_lock, flags);
-	if (nested_mode_support() && list_empty(&dmar_domain->devices)) {
+	if (list_empty(&dmar_domain->devices)) {
 		dmar_domain->flags |= DOMAIN_FLAG_NESTING_MODE;
 		dmar_domain->flags &= ~DOMAIN_FLAG_USE_FIRST_LEVEL;
 		ret = 0;
Signature · 6 lines
2.25.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#1 lore raw
Quoted 9 lines

From: Lu Baolu <[email protected]>
Sent: Wednesday, May 12, 2021 3:04 PM

Current VT-d implementation supports nested translation only if all underlying IOMMUs support the nested capability. This is unnecessary as the upper layer is allowed to create different containers and set them with different type of iommu backend. The IOMMU driver needs to guarantee that devices attached to a nested mode iommu_domain should support nested capabilility.

so the consistency check is now applied only to the IOMMUs that are spanned by a given iommu_domain?

Quoted 32 lines
---
 drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +7 -0
index f1742da42478..1cd4840e6f9f 100644
@@ -4755,6 +4755,13 @@ static int prepare_domain_attach_device(struct
 iommu_domain *domain,
 	if (!iommu)
 		return -ENODEV;
 
+	if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) &&
+	    !ecap_nest(iommu->ecap)) {
+		dev_err(dev, "%s: iommu not support nested translation\n",
+			iommu->name);
+		return -EINVAL;
+	}
+
 	/* check if this iommu agaw is sufficient for max mapped address */
 	addr_width = agaw_to_width(iommu->agaw);
drivers/iommu/intel/iommu.c +3 -0
 	if (addr_width > cap_mgaw(iommu->cap))
@@ -5451,11 +5458,21 @@ static int
 intel_iommu_enable_nesting(struct iommu_domain *domain)
 {
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	bool has_nesting = false;

drivers/iommu/intel/iommu.c static int · line 5472

Quoted 10 lines
drivers/iommu/intel/iommu.c +8 -1
 	unsigned long flags;
-	int ret = -ENODEV;
+	int ret = -EINVAL;
+
+	for_each_active_iommu(iommu, drhd)
+		if (ecap_nest(iommu->ecap))
+			has_nesting = true;
+
+	if (!has_nesting)
+		return -ENODEV;

Isn't above still doing global consistency check?

Quoted 10 lines
drivers/iommu/intel/iommu.c +1 -2
 	spin_lock_irqsave(&device_domain_lock, flags);
-	if (nested_mode_support() && list_empty(&dmar_domain->devices))
 {
+	if (list_empty(&dmar_domain->devices)) {
 		dmar_domain->flags |= DOMAIN_FLAG_NESTING_MODE;
 		dmar_domain->flags &= ~DOMAIN_FLAG_USE_FIRST_LEVEL;
 		ret = 0;
--

2.25.1

author maintainer
#2 lore raw

Hi Kevin,

Quoted 10 lines · Kevin
Quoted 9 lines

From: Lu Baolu <[email protected]>
Sent: Wednesday, May 12, 2021 3:04 PM

Current VT-d implementation supports nested translation only if all underlying IOMMUs support the nested capability. This is unnecessary as the upper layer is allowed to create different containers and set them with different type of iommu backend. The IOMMU driver needs to guarantee that devices attached to a nested mode iommu_domain should support nested capabilility.

Quoted 2 lines

so the consistency check is now applied only to the IOMMUs that are spanned by a given iommu_domain?

Yes.

Quoted 37 lines
Quoted 37 lines
---
  drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +7 -0
index f1742da42478..1cd4840e6f9f 100644
@@ -4755,6 +4755,13 @@ static int prepare_domain_attach_device(struct
 iommu_domain *domain,
  	if (!iommu)
  		return -ENODEV;
 
+	if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) &&
+	    !ecap_nest(iommu->ecap)) {
+		dev_err(dev, "%s: iommu not support nested translation\n",
+			iommu->name);
+		return -EINVAL;
+	}
+
  	/* check if this iommu agaw is sufficient for max mapped address */
  	addr_width = agaw_to_width(iommu->agaw);

if (addr_width > cap_mgaw(iommu->cap))

drivers/iommu/intel/iommu.c +5 -1
@@ -5451,11 +5458,21 @@ static int
  intel_iommu_enable_nesting(struct iommu_domain *domain)
  {
  	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	bool has_nesting = false;
  	unsigned long flags;
-	int ret = -ENODEV;
+	int ret = -EINVAL;
+
Quoted 8 lines

drivers/iommu/intel/iommu.c static int · line 5472

Quoted 6 lines
drivers/iommu/intel/iommu.c +6 -0
+	for_each_active_iommu(iommu, drhd)
+		if (ecap_nest(iommu->ecap))
+			has_nesting = true;
+
+	if (!has_nesting)
+		return -ENODEV;

Isn't above still doing global consistency check?

The logic is if nested mode is globally unsupported, return false.

Quoted 12 lines
Quoted 11 lines
drivers/iommu/intel/iommu.c +1 -2
  	spin_lock_irqsave(&device_domain_lock, flags);
-	if (nested_mode_support() && list_empty(&dmar_domain->devices))
 {
+	if (list_empty(&dmar_domain->devices)) {
  		dmar_domain->flags |= DOMAIN_FLAG_NESTING_MODE;
  		dmar_domain->flags &= ~DOMAIN_FLAG_USE_FIRST_LEVEL;
  		ret = 0;
--

2.25.1

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#3 lore raw
Quoted 68 lines

From: Lu Baolu
Sent: Wednesday, May 12, 2021 7:31 PM

Hi Kevin,

Quoted 10 lines · Kevin
Quoted 9 lines

From: Lu Baolu <[email protected]>
Sent: Wednesday, May 12, 2021 3:04 PM

Current VT-d implementation supports nested translation only if all underlying IOMMUs support the nested capability. This is unnecessary as the upper layer is allowed to create different containers and set them with different type of iommu backend. The IOMMU driver needs to guarantee that devices attached to a nested mode iommu_domain should support nested capabilility.

Quoted 2 lines

so the consistency check is now applied only to the IOMMUs that are spanned by a given iommu_domain?

Yes.

Quoted 7 lines
Quoted 7 lines
---
  drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)
Quoted 5 lines

drivers/iommu/intel/iommu.c static int

Quoted 5 lines
drivers/iommu/intel/iommu.c +0 -0
index f1742da42478..1cd4840e6f9f 100644
@@ -4755,6 +4755,13 @@ static int

prepare_domain_attach_device(struct

Quoted 25 lines
Quoted 25 lines
drivers/iommu/intel/iommu.c +7 -0
 iommu_domain *domain,
  	if (!iommu)
  		return -ENODEV;
 
+	if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) &&
+	    !ecap_nest(iommu->ecap)) {
+		dev_err(dev, "%s: iommu not support nested translation\n",
+			iommu->name);
+		return -EINVAL;
+	}
+
  	/* check if this iommu agaw is sufficient for max mapped address */
  	addr_width = agaw_to_width(iommu->agaw);

if (addr_width > cap_mgaw(iommu->cap))

drivers/iommu/intel/iommu.c +5 -1
@@ -5451,11 +5458,21 @@ static int
  intel_iommu_enable_nesting(struct iommu_domain *domain)
  {
  	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	bool has_nesting = false;
  	unsigned long flags;
-	int ret = -ENODEV;
+	int ret = -EINVAL;
+
Quoted 8 lines

drivers/iommu/intel/iommu.c static int · line 5472

Quoted 6 lines
drivers/iommu/intel/iommu.c +6 -0
+	for_each_active_iommu(iommu, drhd)
+		if (ecap_nest(iommu->ecap))
+			has_nesting = true;
+
+	if (!has_nesting)
+		return -ENODEV;

Isn't above still doing global consistency check?

Quoted 1 line

The logic is if nested mode is globally unsupported, return false.

why is this check required? anyway you already have the check when prepare device attachment, and only at that point you have accurate info for which iommu to be checked. This check looks meaningless as even if some IOMMUs support nesting it doesn't mean the IOMMU relevant to this domain support it.

Quoted 14 lines
Quoted 13 lines
Quoted 11 lines
drivers/iommu/intel/iommu.c +1 -2
  	spin_lock_irqsave(&device_domain_lock, flags);
-	if (nested_mode_support() && list_empty(&dmar_domain->devices))
 {
+	if (list_empty(&dmar_domain->devices)) {
  		dmar_domain->flags |= DOMAIN_FLAG_NESTING_MODE;
  		dmar_domain->flags &= ~DOMAIN_FLAG_USE_FIRST_LEVEL;
  		ret = 0;
--
Quoted 1 line

2.25.1

Quoted 6 lines

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author maintainer
#4 lore raw
Quoted 62 lines · Kevin
Quoted 62 lines

From: Lu Baolu
Sent: Wednesday, May 12, 2021 7:31 PM

Hi Kevin,

Quoted 11 lines · Kevin
Quoted 9 lines

From: Lu Baolu<[email protected]>
Sent: Wednesday, May 12, 2021 3:04 PM

Current VT-d implementation supports nested translation only if all underlying IOMMUs support the nested capability. This is unnecessary as the upper layer is allowed to create different containers and set them with different type of iommu backend. The IOMMU driver needs to guarantee that devices attached to a nested mode iommu_domain should support nested capabilility.

so the consistency check is now applied only to the IOMMUs that are spanned by a given iommu_domain?

Yes.

Quoted 10 lines

drivers/iommu/intel/iommu.c static int

Quoted 10 lines
---
   drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++--
   1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +0 -0
index f1742da42478..1cd4840e6f9f 100644
@@ -4755,6 +4755,13 @@ static int

prepare_domain_attach_device(struct

Quoted 32 lines
Quoted 21 lines
drivers/iommu/intel/iommu.c +7 -0
 iommu_domain *domain,
   	if (!iommu)
   		return -ENODEV;
 
+	if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) &&
+	    !ecap_nest(iommu->ecap)) {
+		dev_err(dev, "%s: iommu not support nested translation\n",
+			iommu->name);
+		return -EINVAL;
+	}
+
   	/* check if this iommu agaw is sufficient for max mapped address */
   	addr_width = agaw_to_width(iommu->agaw);
   	if (addr_width > cap_mgaw(iommu->cap))
drivers/iommu/intel/iommu.c +3 -0
@@ -5451,11 +5458,21 @@ static int
   intel_iommu_enable_nesting(struct iommu_domain *domain)
   {
   	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	bool has_nesting = false;

drivers/iommu/intel/iommu.c static int · line 5472

Quoted 10 lines
drivers/iommu/intel/iommu.c +8 -1
   	unsigned long flags;
-	int ret = -ENODEV;
+	int ret = -EINVAL;
+
+	for_each_active_iommu(iommu, drhd)
+		if (ecap_nest(iommu->ecap))
+			has_nesting = true;
+
+	if (!has_nesting)
+		return -ENODEV;

Isn't above still doing global consistency check?

Quoted 7 lines
Quoted 1 line

The logic is if nested mode is globally unsupported, return false.

why is this check required? anyway you already have the check when prepare device attachment, and only at that point you have accurate info for which iommu to be checked. This check looks meaningless as even if some IOMMUs support nesting it doesn't mean the IOMMU relevant to this domain support it.

Get you. It's really unnecessary. I will drop this check in the new version.

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu