From: Lu Baolu <baolu.lu@linux.intel.com>
The VT-d spec requires to use PASID-based-IOTLB invalidation descriptor
to invalidate IOTLB and the paging-structure caches for a first-stage
page table. Add a generic helper to do this.
RID2PASID is used if the domain has been attached to a physical device,
otherwise real PASIDs that the domain has been attached to will be used.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
drivers/iommu/intel/iommu.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index ddff43def3ab..40685cbfaf0e 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1467,6 +1467,24 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
spin_unlock_irqrestore(&domain->lock, flags);
}
+/*
+ * The VT-d spec requires to use PASID-based-IOTLB Invalidation to
+ * invalidate IOTLB and the paging-structure-caches for a first-stage
+ * page table.
+ */
+static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
+ struct dmar_domain *domain, u64 addr,
+ unsigned long npages, bool ih)
+{
+ u16 did = domain_id_iommu(domain, iommu);
+ unsigned long flags;
+
+ spin_lock_irqsave(&domain->lock, flags);
+ if (!list_empty(&domain->devices))
+ qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, npages, ih);
+ spin_unlock_irqrestore(&domain->lock, flags);
+}
+
static void iommu_flush_iotlb_psi(struct intel_iommu *iommu,
struct dmar_domain *domain,
unsigned long pfn, unsigned int pages,
@@ -1484,7 +1502,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu,
ih = 1 << 6;
if (domain->use_first_level) {
- qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr, pages, ih);
+ domain_flush_pasid_iotlb(iommu, domain, addr, pages, ih);
} else {
unsigned long bitmask = aligned_pages - 1;
@@ -1554,7 +1572,7 @@ static void intel_flush_iotlb_all(struct iommu_domain *domain)
u16 did = domain_id_iommu(dmar_domain, iommu);
if (dmar_domain->use_first_level)
- qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, 0, -1, 0);
+ domain_flush_pasid_iotlb(iommu, dmar_domain, 0, -1, 0);
else
iommu->flush.flush_iotlb(iommu, did, 0, 0,
DMA_TLB_DSI_FLUSH);
--
2.25.1
> From: Jacob Pan <jacob.jun.pan@linux.intel.com> > Sent: Thursday, July 13, 2023 12:34 AM > > From: Lu Baolu <baolu.lu@linux.intel.com> > > The VT-d spec requires to use PASID-based-IOTLB invalidation descriptor > to invalidate IOTLB and the paging-structure caches for a first-stage > page table. Add a generic helper to do this. > > RID2PASID is used if the domain has been attached to a physical device, > otherwise real PASIDs that the domain has been attached to will be used. this should mention that 'real' PASID attach is not handled in this patch. Otherwise it's confusing to connect this description to the new helper. > > Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> > Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> > --- > drivers/iommu/intel/iommu.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index ddff43def3ab..40685cbfaf0e 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -1467,6 +1467,24 @@ static void iommu_flush_dev_iotlb(struct > dmar_domain *domain, > spin_unlock_irqrestore(&domain->lock, flags); > } > > +/* > + * The VT-d spec requires to use PASID-based-IOTLB Invalidation to > + * invalidate IOTLB and the paging-structure-caches for a first-stage > + * page table. > + */ this comment is better placed in the calling point. This function has nothing explicitly connected to first-stage. with that fixed, Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> From: Jacob Pan <jacob.jun.pan@linux.intel.com>
> Sent: Thursday, July 13, 2023 12:34 AM
> +static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
> + struct dmar_domain *domain, u64 addr,
> + unsigned long npages, bool ih)
> +{
> + u16 did = domain_id_iommu(domain, iommu);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&domain->lock, flags);
> + if (!list_empty(&domain->devices))
> + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr,
> npages, ih);
> + spin_unlock_irqrestore(&domain->lock, flags);
btw I gave a comment before that the check of list_empty() changes
the semantics instead of just creating a helper.
If it's the right thing to do please split it into a separate fix patch.
On 2023/7/13 15:52, Tian, Kevin wrote:
>> From: Jacob Pan <jacob.jun.pan@linux.intel.com>
>> Sent: Thursday, July 13, 2023 12:34 AM
>> +static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
>> + struct dmar_domain *domain, u64 addr,
>> + unsigned long npages, bool ih)
>> +{
>> + u16 did = domain_id_iommu(domain, iommu);
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&domain->lock, flags);
>> + if (!list_empty(&domain->devices))
>> + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr,
>> npages, ih);
>> + spin_unlock_irqrestore(&domain->lock, flags);
>
> btw I gave a comment before that the check of list_empty() changes
> the semantics instead of just creating a helper.
>
> If it's the right thing to do please split it into a separate fix patch.
Perhaps move it into patch 6?
Best regards,
baolu
> From: Baolu Lu <baolu.lu@linux.intel.com>
> Sent: Friday, July 14, 2023 11:37 AM
>
> On 2023/7/13 15:52, Tian, Kevin wrote:
> >> From: Jacob Pan <jacob.jun.pan@linux.intel.com>
> >> Sent: Thursday, July 13, 2023 12:34 AM
> >> +static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
> >> + struct dmar_domain *domain, u64 addr,
> >> + unsigned long npages, bool ih)
> >> +{
> >> + u16 did = domain_id_iommu(domain, iommu);
> >> + unsigned long flags;
> >> +
> >> + spin_lock_irqsave(&domain->lock, flags);
> >> + if (!list_empty(&domain->devices))
> >> + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr,
> >> npages, ih);
> >> + spin_unlock_irqrestore(&domain->lock, flags);
> >
> > btw I gave a comment before that the check of list_empty() changes
> > the semantics instead of just creating a helper.
> >
> > If it's the right thing to do please split it into a separate fix patch.
>
> Perhaps move it into patch 6?
>
I still prefer to putting it in a separate patch since it changes the
behavior in existing path. It's not really about dev_pasid which
patch6 is trying to support.
On 2023/7/14 11:51, Tian, Kevin wrote:
>> From: Baolu Lu <baolu.lu@linux.intel.com>
>> Sent: Friday, July 14, 2023 11:37 AM
>>
>> On 2023/7/13 15:52, Tian, Kevin wrote:
>>>> From: Jacob Pan <jacob.jun.pan@linux.intel.com>
>>>> Sent: Thursday, July 13, 2023 12:34 AM
>>>> +static void domain_flush_pasid_iotlb(struct intel_iommu *iommu,
>>>> + struct dmar_domain *domain, u64 addr,
>>>> + unsigned long npages, bool ih)
>>>> +{
>>>> + u16 did = domain_id_iommu(domain, iommu);
>>>> + unsigned long flags;
>>>> +
>>>> + spin_lock_irqsave(&domain->lock, flags);
>>>> + if (!list_empty(&domain->devices))
>>>> + qi_flush_piotlb(iommu, did, IOMMU_NO_PASID, addr,
>>>> npages, ih);
>>>> + spin_unlock_irqrestore(&domain->lock, flags);
>>>
>>> btw I gave a comment before that the check of list_empty() changes
>>> the semantics instead of just creating a helper.
>>>
>>> If it's the right thing to do please split it into a separate fix patch.
>>
>> Perhaps move it into patch 6?
>>
>
> I still prefer to putting it in a separate patch since it changes the
> behavior in existing path. It's not really about dev_pasid which
> patch6 is trying to support.
Okay, that will also be fine to me.
Best regards,
baolu
© 2016 - 2026 Red Hat, Inc.