Skip to contentSkip to conversation

iommu/vt-d: Assign owner to the static identity domain

PATCH In review Lu Baolu 3 participants 4 messages Apr 22, 2025 – Apr 23, 2025

Subsystems (3)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Assign owner to the static identity domain

The idxd driver attaches the default domain to a PASID of the device to perform kernel DMA using that PASID. The domain is attached to the device's PASID through iommu_attach_device_pasid(), which checks if the domain->owner matches the iommu_ops retrieved from the device. If they do not match, it returns a failure.

        if (ops != domain->owner || pasid == IOMMU_NO_PASID)
                return -EINVAL;

The static identity domain implemented by the intel iommu driver doesn't specify the domain owner. Therefore, kernel DMA with PASID doesn't work for the idxd driver if the device translation mode is set to passthrough.

Fix this by specifying the domain owner for the static identity domain.

Fixes 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
---
 drivers/iommu/intel/iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/intel/iommu.c +1 -0
index cb0b993bebb4..63c9c97ccf69 100644
@@ -4385,6 +4385,7 @@ static struct iommu_domain identity_domain = {
 		.attach_dev	= identity_domain_attach_dev,
 		.set_dev_pasid	= identity_domain_set_dev_pasid,
 	},
+	.owner = &intel_iommu_ops,
 };
 
 const struct iommu_ops intel_iommu_ops = {
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Lu Baolu

The idxd driver attaches the default domain to a PASID of the device to perform kernel DMA using that PASID. The domain is attached to the device's PASID through iommu_attach_device_pasid(), which checks if the domain->owner matches the iommu_ops retrieved from the device. If they do not match, it returns a failure.

        if (ops != domain->owner || pasid == IOMMU_NO_PASID)
                return -EINVAL;

The static identity domain implemented by the intel iommu driver doesn't specify the domain owner. Therefore, kernel DMA with PASID doesn't work for the idxd driver if the device translation mode is set to passthrough.

Quoted 6 lines

Fix this by specifying the domain owner for the static identity domain.

Fixes 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
Quoted 16 lines
---
 drivers/iommu/intel/iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/intel/iommu.c +1 -0
index cb0b993bebb4..63c9c97ccf69 100644
@@ -4385,6 +4385,7 @@ static struct iommu_domain identity_domain = {
 		.attach_dev	= identity_domain_attach_dev,
 		.set_dev_pasid	= identity_domain_set_dev_pasid,
 	},
+	.owner = &intel_iommu_ops,
 };
 
 const struct iommu_ops intel_iommu_ops = {
#2 lore raw
In reply to Lu Baolu

drivers/iommu/intel/iommu.c static struct iommu_domain identity_domain = { · line 4389

Quoted 10 lines · Lu Baolu
drivers/iommu/intel/iommu.c +1 -0
index cb0b993bebb4..63c9c97ccf69 100644
@@ -4385,6 +4385,7 @@ static struct iommu_domain identity_domain = {
 		.attach_dev	= identity_domain_attach_dev,
 		.set_dev_pasid	= identity_domain_set_dev_pasid,
 	},
+	.owner = &intel_iommu_ops,
 };

Is this a systemic mistake in all the static domains in all the drivers?

Maybe a bigger check is a more complete fix:

static bool iommu_domain_compatible(struct device *dev,
struct iommu_domain *domain)

{
	const struct iommu_ops *ops = dev_iommu_ops(dev);

	if (domain->owner == ops)
		return true;

	/* For static domains owner isn't set */
	if (ops->blocked_domain == domain || ops->identity_domain == domain)
		return true;
	return false;
}

Jason

author maintainer
#3 lore raw
Quoted 15 lines · Jason Gunthorpe

drivers/iommu/intel/iommu.c static struct iommu_domain identity_domain = { · line 4389

Quoted 10 lines · Lu Baolu
drivers/iommu/intel/iommu.c +1 -0
index cb0b993bebb4..63c9c97ccf69 100644
@@ -4385,6 +4385,7 @@ static struct iommu_domain identity_domain = {
  		.attach_dev	= identity_domain_attach_dev,
  		.set_dev_pasid	= identity_domain_set_dev_pasid,
  	},
+	.owner = &intel_iommu_ops,
  };

Is this a systemic mistake in all the static domains in all the drivers?

Yes. The owner field is not set for all static domains.

Quoted 4 lines

Maybe a bigger check is a more complete fix:

static bool iommu_domain_compatible(struct device *dev,
struct iommu_domain *domain)

Quoted 11 lines
{
	const struct iommu_ops *ops = dev_iommu_ops(dev);

	if (domain->owner == ops)
		return true;

	/* For static domains owner isn't set */
	if (ops->blocked_domain == domain || ops->identity_domain == domain)
		return true;
	return false;
}

That's better. I will post a v2 accordingly.

Quoted 1 line

Jason

Thanks,
baolu