Re: [PATCH v3 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()

From: Vasant Hegde
Date: Thu Apr 24 2025 - 02:49:56 EST


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@xxxxxxxxxxxxxxx
> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@xxxxxxxx/
> Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Reviewed-by: Robin Murphy <robin.murphy@xxxxxxx>


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@xxxxxxx>

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