2023-07-24 23:31:39

by Jacob Pan

[permalink] [raw]
Subject: [PATCH v11 6/8] iommu/vt-d: Prepare for set_dev_pasid callback

From: Lu Baolu <[email protected]>

The domain_flush_pasid_iotlb() helper function is used to flush the IOTLB
entries for a given PASID. Previously, this function assumed that
RID2PASID was only used for the first-level DMA translation. However, with
the introduction of the set_dev_pasid callback, this assumption is no
longer valid.

Add a check before using the RID2PASID for PASID invalidation. This check
ensures that the domain has been attached to a physical device before
using RID2PASID.

Signed-off-by: Lu Baolu <[email protected]>
Signed-off-by: Jacob Pan <[email protected]>
---
drivers/iommu/intel/iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index bdde38a5e43a..4a41aca6a2ba 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1475,7 +1475,8 @@ static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
unsigned long flags;

spin_lock_irqsave(&domain->lock, flags);
- qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih);
+ if (!list_empty(&domain->devices))
+ qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih);
spin_unlock_irqrestore(&domain->lock, flags);
}

--
2.25.1



2023-07-27 06:41:04

by Tian, Kevin

[permalink] [raw]
Subject: RE: [PATCH v11 6/8] iommu/vt-d: Prepare for set_dev_pasid callback

> From: Jacob Pan <[email protected]>
> Sent: Tuesday, July 25, 2023 6:26 AM
>
> From: Lu Baolu <[email protected]>
>
> The domain_flush_pasid_iotlb() helper function is used to flush the IOTLB
> entries for a given PASID. Previously, this function assumed that
> RID2PASID was only used for the first-level DMA translation. However, with
> the introduction of the set_dev_pasid callback, this assumption is no
> longer valid.
>
> Add a check before using the RID2PASID for PASID invalidation. This check
> ensures that the domain has been attached to a physical device before
> using RID2PASID.
>
> Signed-off-by: Lu Baolu <[email protected]>
> Signed-off-by: Jacob Pan <[email protected]>

Reviewed-by: Kevin Tian <[email protected]>