Misc bug fixes for VT-d SVM
cover Misc bug fixes for VT-d SVM
Just a few bug fixes while testing Intel SVM code.
Jacob Pan (3):
iommu/vt-d: Remove redundant IOTLB flush
iommu/vt-d: Fix mm reference leak
iommu/vt-d: Add build dependency on IOASID
drivers/iommu/Kconfig | 1 + drivers/iommu/intel-svm.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
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.
--- drivers/iommu/intel-svm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iommu/intel-svm.c +2 -4
@@ -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, &svm->devs, list) { +list_for_each_entry_rcu (sdev, &svm->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 (&svm->devs)) {
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
Quoted 2 lines · Jacob Pan
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
Quoted 33 lines
Cc Lu Baolu <[email protected]>Signed-off-by Jacob Pan <[email protected]>--- drivers/iommu/intel-svm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/iommu/intel-svm.c +2
-4@@ -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, &svm->devs, list) { +list_for_each_entry_rcu (sdev, &svm->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 (&svm->devs)) {
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
Quoted 7 lines · On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu <[email protected]> wrote:
Quoted 2 lines · Jacob Pan
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);
Quoted 38 lines
Best regards,
baoluQuoted 35 lines
Cc Lu Baolu <[email protected]>Signed-off-by Jacob Pan <[email protected]>--- drivers/iommu/intel-svm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/iommu/intel-svm.c +0
-0@@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting otherprocesses. */
rcu_read_lock();drivers/iommu/intel-svm.c +1
-1-list_for_each_entry_rcu (sdev, &svm->devs, list) { +list_for_each_entry_rcu (sdev, &svm->devs, list) intel_pasid_tear_down_entry(svm->iommu,
sdev->dev,svm->pasid);drivers/iommu/intel-svm.c +1
-2-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 physicallycontiguous. So it's
* hard to be as defensive as we might
like. */intel_pasid_tear_down_entry(iommu, dev, svm->pasid);drivers/iommu/intel-svm.c +0
-2-intel_flush_svm_range_dev (svm, sdev,0 , -1 ,0 );kfree_rcu (sdev, rcu);
Quoted 2 lines
Quoted 2 lines
if (list_empty(&svm->devs)) {
[Jacob Pan]
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
Quoted 14 lines · Jacob Pan
Quoted 7 lines · On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu <[email protected]> wrote:
Quoted 2 lines · Jacob Pan
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.
Quoted 7 lines
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
Quoted 43 lines
Quoted 38 lines
Best regards,
baoluQuoted 35 lines
Cc Lu Baolu <[email protected]>Signed-off-by Jacob Pan <[email protected]>--- drivers/iommu/intel-svm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/iommu/intel-svm.c +0
-0@@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting otherprocesses. */
rcu_read_lock();drivers/iommu/intel-svm.c +1
-1-list_for_each_entry_rcu (sdev, &svm->devs, list) { +list_for_each_entry_rcu (sdev, &svm->devs, list) intel_pasid_tear_down_entry(svm->iommu,
sdev->dev,svm->pasid);drivers/iommu/intel-svm.c +1
-2-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 physicallycontiguous. So it's
* hard to be as defensive as we might
like. */intel_pasid_tear_down_entry(iommu, dev, svm->pasid);drivers/iommu/intel-svm.c +0
-2-intel_flush_svm_range_dev (svm, sdev,0 , -1 ,0 );kfree_rcu (sdev, rcu);Quoted 2 lines
Quoted 2 lines
if (list_empty(&svm->devs)) {[Jacob Pan]
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
Quoted 18 lines · On Sat, 21 Mar 2020 09:32:45 +0800 Lu Baolu <[email protected]> wrote:
Quoted 17 lines · Jacob Pan
Quoted 7 lines · On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu <[email protected]> wrote:
Quoted 2 lines · Jacob Pan
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);
Quoted 8 lines
Quoted 4 lines
/* 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?
Quoted 16 lines
static void
devtlb_invalidation_with_pasid(structintel_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 -
Quoted 49 lines
VTD_PAGE_SHIFT);
}Best regards,
baoluQuoted 43 lines
Quoted 38 lines
Best regards,
baoluQuoted 35 lines
Cc Lu Baolu <[email protected]>Signed-off-by Jacob Pan <[email protected]>--- drivers/iommu/intel-svm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/iommu/intel-svm.c +0
-0@@ -268,10 +268,9 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * *has* to handle gracefully without affecting otherprocesses. */
rcu_read_lock();drivers/iommu/intel-svm.c +1
-1-list_for_each_entry_rcu (sdev, &svm->devs, list) { +list_for_each_entry_rcu (sdev, &svm->devs, list) intel_pasid_tear_down_entry(svm->iommu,
sdev->dev,svm->pasid);drivers/iommu/intel-svm.c +1
-2-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 physicallycontiguous. So it's
* hard to be as defensive as we might
like. */intel_pasid_tear_down_entry(iommu, dev, svm->pasid);drivers/iommu/intel-svm.c +0
-2-intel_flush_svm_range_dev (svm, sdev,0 , -1 ,0 );kfree_rcu (sdev, rcu);Quoted 2 lines
Quoted 2 lines
if (list_empty(&svm->devs)) {[Jacob Pan]
[Jacob Pan]
Re: [PATCH 1/3] iommu/vt-d: Remove redundant IOTLB flush
Quoted 24 lines · Jacob Pan
Quoted 21 lines · On Sat, 21 Mar 2020 09:32:45 +0800 Lu Baolu<[email protected]> wrote:
Quoted 20 lines · Jacob Pan
Quoted 6 lines · On Fri, 20 Mar 2020 21:45:26 +0800 Lu Baolu<[email protected]> wrote:
Quoted 2 lines · Jacob Pan
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);
Quoted 7 lines
Quoted 3 lines
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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/3 iommu/vt-d: Fix mm reference leak
In reply to Jacob PanMove canonical address check before mmget_not_zero() to avoid mm reference leak.
address is canonical.")
--- drivers/iommu/intel-svm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/intel-svm.c +4 -3
@@ -861,14 +861,15 @@ static irqreturn_t prq_event_thread(int irq, void *d)* any faults on kernel addresses. */ if (!svm->mm) goto bad_req; -/* If the mm is already defunct, don't handle faults. */ -if (!mmget_not_zero (svm->mm)) - goto bad_req;/* If address is not canonical, return invalid response */ if (!is_canonical_address (address)) goto bad_req; +/* If the mm is already defunct, don't handle faults. */ +if (!mmget_not_zero (svm->mm)) + goto bad_req; +down_read (&svm->mm->mmap_sem); vma =find_extend_vma (svm->mm, address);if (!vma || address < vma->vm_start)
Signature · 1 line
2.7.4
Re: [PATCH 2/3] iommu/vt-d: Fix mm reference leak
Quoted 7 lines · Jacob Pan
Move canonical address check before
mmget_not_zero()to avoid mm reference leak.Fixes 9d8c3af31607 ("iommu/vt-d: IOMMU Page Request needs to check ifaddress is canonical.")
Signed-off-by Jacob Pan <[email protected]>
Best regards,
baolu
Quoted 28 lines
--- drivers/iommu/intel-svm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/iommu/intel-svm.c +4
-3@@ -861,14 +861,15 @@ static irqreturn_t prq_event_thread(int irq, void *d)* any faults on kernel addresses. */ if (!svm->mm) goto bad_req; -/* If the mm is already defunct, don't handle faults. */ -if (!mmget_not_zero (svm->mm)) - goto bad_req;/* If address is not canonical, return invalid response */ if (!is_canonical_address (address)) goto bad_req; +/* If the mm is already defunct, don't handle faults. */ +if (!mmget_not_zero (svm->mm)) + goto bad_req; +down_read (&svm->mm->mmap_sem); vma =find_extend_vma (svm->mm, address);if (!vma || address < vma->vm_start)
PATCH 3/3 iommu/vt-d: Add build dependency on IOASID
In reply to Jacob PanIOASID code is needed by VT-d scalable mode for PASID allocation. Add explicit dependency such that IOASID is built-in whenever Intel IOMMU is enabled.
Otherwise, aux domain code will fail when IOMMU is built-in and IOASID is compiled as a module.
--- drivers/iommu/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/Kconfig +1 -0
@@ -188,6 +188,7 @@ config INTEL_IOMMU select NEED_DMA_MAP_STATE select DMAR_TABLE select SWIOTLB + select IOASID help DMA remapping (DMAR) devices support enables independent address translations for Direct Memory Access (DMA) from devices.
Signature · 1 line
2.7.4
Re: [PATCH 3/3] iommu/vt-d: Add build dependency on IOASID
Quoted 7 lines · Jacob Pan
IOASID code is needed by VT-d scalable mode for PASID allocation. Add explicit dependency such that IOASID is built-in whenever Intel IOMMU is enabled.
Otherwise, aux domain code will fail when IOMMU is built-in and IOASID is compiled as a module.Signed-off-by Jacob Pan <[email protected]>
Best regards,
baolu
Quoted 17 lines
--- drivers/iommu/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/iommu/Kconfig +1
-0@@ -188,6 +188,7 @@ config INTEL_IOMMU select NEED_DMA_MAP_STATE select DMAR_TABLE select SWIOTLB + select IOASID help DMA remapping (DMAR) devices support enables independent address translations for Direct Memory Access (DMA) from devices.
Quoted 2 lines · Jacob Pan
iommu/vt-d: Fix mm reference leak
iommu/vt-d: Add build dependency on IOASID
Applied these two, thanks.