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.
Generally the owner field of static domains are not set because they are already part of iommu ops. Add a helper domain_iommu_ops_compatible() that checks if a domain is compatible with the device's iommu ops. This helper explicitly allows the static blocked and identity domains associated with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031 Cc: stable@vger.kernel.org Suggested-by: Jason Gunthorpe jgg@nvidia.com Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/ Signed-off-by: Lu Baolu baolu.lu@linux.intel.com Reviewed-by: Dave Jiang dave.jiang@intel.com Reviewed-by: Robin Murphy robin.murphy@arm.com --- drivers/iommu/iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
Change log: v3: - Convert all places checking domain->owner to the new helper. v2: https://lore.kernel.org/linux-iommu/20250423021839.2189204-1-baolu.lu@linux.... - Make the solution generic for all static domains as suggested by Jason. v1: https://lore.kernel.org/linux-iommu/20250422075422.2084548-1-baolu.lu@linux....
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4f91a740c15f..b26fc3ed9f01 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2204,6 +2204,19 @@ static void *iommu_make_pasid_array_entry(struct iommu_domain *domain, return xa_tag_pointer(domain, IOMMU_PASID_ARRAY_DOMAIN); }
+static bool domain_iommu_ops_compatible(const struct iommu_ops *ops, + struct iommu_domain *domain) +{ + if (domain->owner == ops) + return true; + + /* For static domains, owner isn't set. */ + if (domain == ops->blocked_domain || domain == ops->identity_domain) + return true; + + return false; +} + static int __iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) { @@ -2214,7 +2227,8 @@ static int __iommu_attach_group(struct iommu_domain *domain, return -EBUSY;
dev = iommu_group_first_dev(group); - if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner) + if (!dev_has_iommu(dev) || + !domain_iommu_ops_compatible(dev_iommu_ops(dev), domain)) return -EINVAL;
return __iommu_group_set_domain(group, domain); @@ -3435,7 +3449,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, !ops->blocked_domain->ops->set_dev_pasid) return -EOPNOTSUPP;
- if (ops != domain->owner || pasid == IOMMU_NO_PASID) + if (!domain_iommu_ops_compatible(ops, domain) || + pasid == IOMMU_NO_PASID) return -EINVAL;
mutex_lock(&group->mutex); @@ -3511,7 +3526,7 @@ int iommu_replace_device_pasid(struct iommu_domain *domain, if (!domain->ops->set_dev_pasid) return -EOPNOTSUPP;
- if (dev_iommu_ops(dev) != domain->owner || + if (!domain_iommu_ops_compatible(dev_iommu_ops(dev), domain) || pasid == IOMMU_NO_PASID || !handle) return -EINVAL;
From: Lu Baolu baolu.lu@linux.intel.com Sent: Thursday, April 24, 2025 11:41 AM
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.
Generally the owner field of static domains are not set because they are already part of iommu ops. Add a helper domain_iommu_ops_compatible() that checks if a domain is compatible with the device's iommu ops. This helper explicitly allows the static blocked and identity domains associated with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031 Cc: stable@vger.kernel.org Suggested-by: Jason Gunthorpe jgg@nvidia.com Link: https://lore.kernel.org/linux- iommu/20250422191554.GC1213339@ziepe.ca/ Signed-off-by: Lu Baolu baolu.lu@linux.intel.com Reviewed-by: Dave Jiang dave.jiang@intel.com Reviewed-by: Robin Murphy robin.murphy@arm.com
Reviewed-by: Kevin Tian kevin.tian@intel.com
On 4/24/2025 9:11 AM, Lu Baolu wrote:
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.
Generally the owner field of static domains are not set because they are already part of iommu ops. Add a helper domain_iommu_ops_compatible() that checks if a domain is compatible with the device's iommu ops. This helper explicitly allows the static blocked and identity domains associated with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031 Cc: stable@vger.kernel.org Suggested-by: Jason Gunthorpe jgg@nvidia.com Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/ Signed-off-by: Lu Baolu baolu.lu@linux.intel.com Reviewed-by: Dave Jiang dave.jiang@intel.com Reviewed-by: Robin Murphy robin.murphy@arm.com
Thanks! We have static identity domain in AMD driver as well. Some day we may hit similar issue :-)
Patch looks good to me.
Reviewed-by: Vasant Hegde vasant.hegde@amd.com
W/ this change may be I should fix AMD driver like below. (No need to respin patch. I can send topup patch later).
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index be8761bbef0f..247b8fcb3a92 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2626,7 +2626,6 @@ void amd_iommu_init_identity_domain(void)
domain->type = IOMMU_DOMAIN_IDENTITY; domain->ops = &identity_domain_ops; - domain->owner = &amd_iommu_ops;
identity_domain.id = pdom_id_alloc();
-Vasant
On 4/24/25 14:49, Vasant Hegde wrote:
On 4/24/2025 9:11 AM, Lu Baolu wrote:
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.
Generally the owner field of static domains are not set because they are already part of iommu ops. Add a helper domain_iommu_ops_compatible() that checks if a domain is compatible with the device's iommu ops. This helper explicitly allows the static blocked and identity domains associated with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain") Closes:https://bugzilla.kernel.org/show_bug.cgi?id=220031 Cc:stable@vger.kernel.org Suggested-by: Jason Gunthorpejgg@nvidia.com Link:https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/ Signed-off-by: Lu Baolubaolu.lu@linux.intel.com Reviewed-by: Dave Jiangdave.jiang@intel.com Reviewed-by: Robin Murphyrobin.murphy@arm.com
Thanks! We have static identity domain in AMD driver as well. Some day we may hit similar issue 🙂
Patch looks good to me.
Reviewed-by: Vasant Hegdevasant.hegde@amd.com
Thank you!
W/ this change may be I should fix AMD driver like below. (No need to respin patch. I can send topup patch later).
I think that's a cleanup rather than a fix.
Thanks, baolu
On Thu, Apr 24, 2025 at 11:41:23AM +0800, Lu Baolu wrote:
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.
Generally the owner field of static domains are not set because they are already part of iommu ops. Add a helper domain_iommu_ops_compatible() that checks if a domain is compatible with the device's iommu ops. This helper explicitly allows the static blocked and identity domains associated with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031 Cc: stable@vger.kernel.org Suggested-by: Jason Gunthorpe jgg@nvidia.com Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/ Signed-off-by: Lu Baolu baolu.lu@linux.intel.com Reviewed-by: Dave Jiang dave.jiang@intel.com Reviewed-by: Robin Murphy robin.murphy@arm.com
drivers/iommu/iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
Reviewed-by: Jason Gunthorpe jgg@nvidia.com
Jason
linux-stable-mirror@lists.linaro.org