Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
On 2020/3/24 23:31, Jacob Pan wrote: On Sat, 21 Mar 2020 09:32:45 +0800 Lu Baolu wrote: On 2020/3/21 0:20, Jacob Pan wrote: On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu wrote: On 2020/3/20 12:32, Jacob Pan wrote: IOTLB flush already included in the PASID tear down process. There is no need to flush again. It seems that intel_pasid_tear_down_entry() doesn't flush the pasid based device TLB? I saw this code in intel_pasid_tear_down_entry(). Isn't the last line flush the devtlb? Not in guest of course since the passdown tlb flush is inclusive. pasid_cache_invalidation_with_pasid(iommu, did, pasid); iotlb_invalidation_with_pasid(iommu, did, pasid); /* Device IOTLB doesn't need to be flushed in caching mode. */ if (!cap_caching_mode(iommu->cap)) devtlb_invalidation_with_pasid(iommu, dev, pasid); But devtlb_invalidation_with_pasid() doesn't do the right thing, it flushes the device tlb, instead of pasid-based device tlb. Hmm, you are right. But the function name is misleading, pasid argument is not used, is there a reason why? This is used for PASID based device IOTLB flush, right? Yes. I will fix and put your patch after it. Best regards, baolu ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
On Sat, 21 Mar 2020 09:32:45 +0800 Lu Baolu wrote: > On 2020/3/21 0:20, Jacob Pan wrote: > > On Fri, 20 Mar 2020 21:45:26 +0800 > > Lu Baolu wrote: > > > >> On 2020/3/20 12:32, Jacob Pan wrote: > >>> IOTLB flush already included in the PASID tear down process. There > >>> is no need to flush again. > >> > >> It seems that intel_pasid_tear_down_entry() doesn't flush the pasid > >> based device TLB? > >> > > I saw this code in intel_pasid_tear_down_entry(). Isn't the last > > line flush the devtlb? Not in guest of course since the passdown > > tlb flush is inclusive. > > > > pasid_cache_invalidation_with_pasid(iommu, did, pasid); > > iotlb_invalidation_with_pasid(iommu, did, pasid); > > > > /* Device IOTLB doesn't need to be flushed in caching mode. > > */ if (!cap_caching_mode(iommu->cap)) > > devtlb_invalidation_with_pasid(iommu, dev, pasid); > > > > But devtlb_invalidation_with_pasid() doesn't do the right thing, it > flushes the device tlb, instead of pasid-based device tlb. > Hmm, you are right. But the function name is misleading, pasid argument is not used, is there a reason why? This is used for PASID based device IOTLB flush, right? > static void > devtlb_invalidation_with_pasid(struct intel_iommu *iommu, > struct device *dev, int pasid) > { > struct device_domain_info *info; > u16 sid, qdep, pfsid; > > info = dev->archdata.iommu; > if (!info || !info->ats_enabled) > return; > > sid = info->bus << 8 | info->devfn; > qdep = info->ats_qdep; > pfsid = info->pfsid; > > qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - > VTD_PAGE_SHIFT); > } > > Best regards, > baolu > > >> Best regards, > >> baolu > >> > >>> > >>> Cc: Lu Baolu > >>> Signed-off-by: Jacob Pan > >>> --- > >>>drivers/iommu/intel-svm.c | 6 ++ > >>>1 file changed, 2 insertions(+), 4 deletions(-) > >>> > >>> diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c > >>> index 8f42d717d8d7..1483f1845762 100644 > >>> --- a/drivers/iommu/intel-svm.c > >>> +++ b/drivers/iommu/intel-svm.c > >>> @@ -268,10 +268,9 @@ static void intel_mm_release(struct > >>> mmu_notifier *mn, struct mm_struct *mm) > >>>* *has* to handle gracefully without affecting other > >>> processes. */ > >>> rcu_read_lock(); > >>> - list_for_each_entry_rcu(sdev, >devs, list) { > >>> + list_for_each_entry_rcu(sdev, >devs, list) > >>> intel_pasid_tear_down_entry(svm->iommu, > >>> sdev->dev, svm->pasid); > >>> - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); > >>> - } > >>> + > >>> rcu_read_unlock(); > >>> > >>>} > >>> @@ -731,7 +730,6 @@ int intel_svm_unbind_mm(struct device *dev, > >>> int pasid) > >>>* large and has to be physically > >>> contiguous. So it's > >>>* hard to be as defensive as we might > >>> like. */ intel_pasid_tear_down_entry(iommu, dev, svm->pasid); > >>> - intel_flush_svm_range_dev(svm, sdev, 0, > >>> -1, 0); kfree_rcu(sdev, rcu); > >>> > >>> if (list_empty(>devs)) { > >>> > > > > [Jacob Pan] > > [Jacob Pan] ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
On 2020/3/21 0:20, Jacob Pan wrote: On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu wrote: On 2020/3/20 12:32, Jacob Pan wrote: IOTLB flush already included in the PASID tear down process. There is no need to flush again. It seems that intel_pasid_tear_down_entry() doesn't flush the pasid based device TLB? I saw this code in intel_pasid_tear_down_entry(). Isn't the last line flush the devtlb? Not in guest of course since the passdown tlb flush is inclusive. pasid_cache_invalidation_with_pasid(iommu, did, pasid); iotlb_invalidation_with_pasid(iommu, did, pasid); /* Device IOTLB doesn't need to be flushed in caching mode. */ if (!cap_caching_mode(iommu->cap)) devtlb_invalidation_with_pasid(iommu, dev, pasid); But devtlb_invalidation_with_pasid() doesn't do the right thing, it flushes the device tlb, instead of pasid-based device tlb. static void devtlb_invalidation_with_pasid(struct intel_iommu *iommu, struct device *dev, int pasid) { struct device_domain_info *info; u16 sid, qdep, pfsid; info = dev->archdata.iommu; if (!info || !info->ats_enabled) return; sid = info->bus << 8 | info->devfn; qdep = info->ats_qdep; pfsid = info->pfsid; qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT); } Best regards, baolu Best regards, baolu Cc: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel-svm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index 8f42d717d8d7..1483f1845762 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting other processes. */ rcu_read_lock(); - list_for_each_entry_rcu(sdev, >devs, list) { + list_for_each_entry_rcu(sdev, >devs, list) intel_pasid_tear_down_entry(svm->iommu, sdev->dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); - } + rcu_read_unlock(); } @@ -731,7 +730,6 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) * large and has to be physically contiguous. So it's * hard to be as defensive as we might like. */ intel_pasid_tear_down_entry(iommu, dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); kfree_rcu(sdev, rcu); if (list_empty(>devs)) { [Jacob Pan] ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu wrote: > On 2020/3/20 12:32, Jacob Pan wrote: > > IOTLB flush already included in the PASID tear down process. There > > is no need to flush again. > > It seems that intel_pasid_tear_down_entry() doesn't flush the pasid > based device TLB? > I saw this code in intel_pasid_tear_down_entry(). Isn't the last line flush the devtlb? Not in guest of course since the passdown tlb flush is inclusive. pasid_cache_invalidation_with_pasid(iommu, did, pasid); iotlb_invalidation_with_pasid(iommu, did, pasid); /* Device IOTLB doesn't need to be flushed in caching mode. */ if (!cap_caching_mode(iommu->cap)) devtlb_invalidation_with_pasid(iommu, dev, pasid); > Best regards, > baolu > > > > > Cc: Lu Baolu > > Signed-off-by: Jacob Pan > > --- > > drivers/iommu/intel-svm.c | 6 ++ > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c > > index 8f42d717d8d7..1483f1845762 100644 > > --- a/drivers/iommu/intel-svm.c > > +++ b/drivers/iommu/intel-svm.c > > @@ -268,10 +268,9 @@ static void intel_mm_release(struct > > mmu_notifier *mn, struct mm_struct *mm) > > * *has* to handle gracefully without affecting other > > processes. */ > > rcu_read_lock(); > > - list_for_each_entry_rcu(sdev, >devs, list) { > > + list_for_each_entry_rcu(sdev, >devs, list) > > intel_pasid_tear_down_entry(svm->iommu, > > sdev->dev, svm->pasid); > > - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); > > - } > > + > > rcu_read_unlock(); > > > > } > > @@ -731,7 +730,6 @@ int intel_svm_unbind_mm(struct device *dev, int > > pasid) > > * large and has to be physically > > contiguous. So it's > > * hard to be as defensive as we might > > like. */ intel_pasid_tear_down_entry(iommu, dev, svm->pasid); > > - intel_flush_svm_range_dev(svm, sdev, 0, > > -1, 0); kfree_rcu(sdev, rcu); > > > > if (list_empty(>devs)) { > > [Jacob Pan] ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
On 2020/3/20 12:32, Jacob Pan wrote: IOTLB flush already included in the PASID tear down process. There is no need to flush again. It seems that intel_pasid_tear_down_entry() doesn't flush the pasid based device TLB? Best regards, baolu Cc: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel-svm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index 8f42d717d8d7..1483f1845762 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting other processes. */ rcu_read_lock(); - list_for_each_entry_rcu(sdev, >devs, list) { + list_for_each_entry_rcu(sdev, >devs, list) intel_pasid_tear_down_entry(svm->iommu, sdev->dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); - } + rcu_read_unlock(); } @@ -731,7 +730,6 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) * large and has to be physically contiguous. So it's * hard to be as defensive as we might like. */ intel_pasid_tear_down_entry(iommu, dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); kfree_rcu(sdev, rcu); if (list_empty(>devs)) { ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
IOTLB flush already included in the PASID tear down process. There is no need to flush again. Cc: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel-svm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c index 8f42d717d8d7..1483f1845762 100644 --- a/drivers/iommu/intel-svm.c +++ b/drivers/iommu/intel-svm.c @@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting other processes. */ rcu_read_lock(); - list_for_each_entry_rcu(sdev, >devs, list) { + list_for_each_entry_rcu(sdev, >devs, list) intel_pasid_tear_down_entry(svm->iommu, sdev->dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); - } + rcu_read_unlock(); } @@ -731,7 +730,6 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) * large and has to be physically contiguous. So it's * hard to be as defensive as we might like. */ intel_pasid_tear_down_entry(iommu, dev, svm->pasid); - intel_flush_svm_range_dev(svm, sdev, 0, -1, 0); kfree_rcu(sdev, rcu); if (list_empty(>devs)) { -- 2.7.4 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu