VT-d Native Shared virtual memory cleanup and fixes
v5 cover VT-d Native Shared virtual memory cleanup and fixes
Mostly extracted from nested SVA/SVM series based on review comments of v7.
https://lkml.org/lkml/2019/10/24/852
This series also adds a few important fixes for native use of SVA. Nested SVA new code will be submitted separately as a smaller set. Based on the core branch of IOMMU tree staged for v5.5, where common APIs for vSVA were applied.git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git core
Changelog:
v5 - Regrouped patch 6 and 8, added comments suggested by Joe Perches
v4 - Commit message fix
V3
- Squashed 1/10 & 2/10
- Deleted "8/10 Fix PASID cache flush" from this series
- Addressed reviews from Eric Auger and Baolu
V2
- Coding style fixes based on Baolu's input, no functional change
- Added Acked-by tags.
Thanks,
Jacob
*** BLURB HERE ***
Jacob Pan (8):
iommu/vt-d: Fix CPU and IOMMU SVM feature matching checks iommu/vt-d: Match CPU and IOMMU paging mode iommu/vt-d: Reject SVM bind for failed capability check iommu/vt-d: Avoid duplicated code for PASID setup iommu/vt-d: Fix off-by-one in PASID allocation iommu/vt-d: Replace Intel specific PASID allocator with IOASID iommu/vt-d: Avoid sending invalid page response iommu/vt-d: Misc macro clean up for SVM
drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 23 +++---- drivers/iommu/intel-pasid.c | 96 ++++++++------------------ drivers/iommu/intel-svm.c | 163 +++++++++++++++++++++++++------------------- include/linux/intel-iommu.h | 5 +- 5 files changed, 135 insertions(+), 153 deletions(-)
Signature · 1 line
2.7.4
PATCH v5 1/8 iommu/vt-d: Fix CPU and IOMMU SVM feature matching checks
Shared Virtual Memory(SVM) is based on a collective set of hardware features detected at runtime. There are requirements for matching CPU and IOMMU capabilities.
The current code checks CPU and IOMMU feature set for SVM support but the result is never stored nor used. Therefore, SVM can still be used even when these checks failed. The consequences can be:
1. CPU uses 5-level paging mode for virtual address of 57 bits, but IOMMU can only support 4-level paging mode with 48 bits address for DMA.
2. 1GB page size is used by CPU but IOMMU does not support it. VT-d unrecoverable faults may be generated.
The best solution to fix these problems is to prevent them in the first place.
This patch consolidates code for checking PASID, CPU vs. IOMMU paging mode compatibility, as well as provides specific error messages for each failed checks. On sane hardware configurations, these error message shall never appear in kernel log.
--- drivers/iommu/intel-iommu.c | 10 ++-------- drivers/iommu/intel-svm.c | 40 +++++++++++++++++++++++++++------------- include/linux/intel-iommu.h | 5 ++++- 3 files changed, 33 insertions(+), 22 deletions(-)
drivers/iommu/intel-iommu.c +2 -8
@@ -3289,10 +3289,7 @@ static int __init init_dmars(void)if (!ecap_pass_through (iommu->ecap)) hw_pass_through =0 ; -#ifdef CONFIG_INTEL_IOMMU_SVM -if (pasid_supported (iommu)) -intel_svm_init (iommu); -#endif +intel_svm_check (iommu); }/*
@@ -4471,10 +4468,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)if (ret) goto out; -#ifdef CONFIG_INTEL_IOMMU_SVM -if (pasid_supported (iommu)) -intel_svm_init (iommu); -#endif +intel_svm_check (iommu);if (dmaru->ignored) {/*
drivers/iommu/intel-svm.c +27 -13
@@ -23,19 +23,6 @@static irqreturn_t prq_event_thread (int irq,void *d); -int intel_svm_init (struct intel_iommu *iommu) -{ -if (cpu_feature_enabled (X86_FEATURE_GBPAGES ) && - !cap_fl1gp_support (iommu->cap)) -return -EINVAL ; - -if (cpu_feature_enabled (X86_FEATURE_LA57 ) && - !cap_5lp_support (iommu->cap)) -return -EINVAL ; - -return 0 ; -} -#define PRQ_ORDER 0int intel_svm_enable_prq (struct intel_iommu *iommu)
@@ -99,6 +86,33 @@ int intel_svm_finish_prq(struct intel_iommu *iommu)return 0 ; } +static inline bool intel_svm_capable (struct intel_iommu *iommu) +{ +return iommu->flags &VTD_FLAG_SVM_CAPABLE ; +} + +void intel_svm_check (struct intel_iommu *iommu) +{ +if (!pasid_supported (iommu)) +return ; + +if (cpu_feature_enabled (X86_FEATURE_GBPAGES ) && + !cap_fl1gp_support (iommu->cap)) { +pr_err ("%s SVM disabled, incompatible 1GB page capability\n" , + iommu->name); +return ; + } + +if (cpu_feature_enabled (X86_FEATURE_LA57 ) && + !cap_5lp_support (iommu->cap)) { +pr_err ("%s SVM disabled, incompatible paging mode\n" , + iommu->name); +return ; + } + + iommu->flags |=VTD_FLAG_SVM_CAPABLE ; +} +static void intel_flush_svm_range_dev (struct intel_svm *svm,struct intel_svm_dev *sdev,unsigned long address,unsigned long pages,int ih) {
include/linux/intel-iommu.h +4 -1
@@ -433,6 +433,7 @@ enum {#define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0)#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) +#define VTD_FLAG_SVM_CAPABLE (1 << 2)extern int intel_iommu_sm;
@@ -656,7 +657,7 @@ void iommu_flush_write_buffer(struct intel_iommu *iommu);int intel_iommu_enable_pasid (struct intel_iommu *iommu,struct device *dev);#ifdef CONFIG_INTEL_IOMMU_SVM -int intel_svm_init (struct intel_iommu *iommu); +extern void intel_svm_check (struct intel_iommu *iommu);extern int intel_svm_enable_prq (struct intel_iommu *iommu);extern int intel_svm_finish_prq (struct intel_iommu *iommu);
@@ -684,6 +685,8 @@ struct intel_svm { };extern struct intel_iommu *intel_svm_device_to_iommu (struct device *dev); +#else +static inline void intel_svm_check (struct intel_iommu *iommu) {}#endif #ifdef CONFIG_INTEL_IOMMU_DEBUGFS
Signature · 1 line
2.7.4
PATCH v5 2/8 iommu/vt-d: Match CPU and IOMMU paging mode
In reply to Jacob PanWhen setting up first level page tables for sharing with CPU, we need to ensure IOMMU can support no less than the levels supported by the CPU.
It is not adequate, as in the current code, to set up 5-level paging in PASID entry First Level Paging Mode(FLPM) solely based on CPU.
Currently, intel_pasid_setup_first_level() is only used by native SVM code which already checks paging mode matches. However, future use of this helper function may not be limited to native SVM.
https://lkml.org/lkml/2019/11/18/1037
interface")
--- drivers/iommu/intel-pasid.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/iommu/intel-pasid.c +10 -2
@@ -499,8 +499,16 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, }#ifdef CONFIG_X86 -if (cpu_feature_enabled (X86_FEATURE_LA57 )) -pasid_set_flpm (pte,1 ); +/* Both CPU and IOMMU paging mode need to match */ +if (cpu_feature_enabled (X86_FEATURE_LA57 )) { +if (cap_5lp_support (iommu->cap)) { +pasid_set_flpm (pte,1 ); + }else { +pr_err ("VT-d has no 5-level paging support for CPU\n" ); +pasid_clear_entry (pte); +return -EINVAL ; + } + }#endif /* CONFIG_X86 */ pasid_set_domain_id (pte, did);
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 3/8 iommu/vt-d: Reject SVM bind for failed capability check
In reply to Jacob PanAdd a check during SVM bind to ensure CPU and IOMMU hardware capabilities are met.
--- drivers/iommu/intel-svm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iommu/intel-svm.c +3 -0
@@ -238,6 +238,9 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (!iommu || dmar_disabled)return -EINVAL ; +if (!intel_svm_capable (iommu)) +return -ENOTSUPP ; +if (dev_is_pci (dev)) { pasid_max =pci_max_pasids (to_pci_dev (dev));if (pasid_max <0 )
Signature · 1 line
2.7.4
PATCH v5 4/8 iommu/vt-d: Avoid duplicated code for PASID setup
In reply to Jacob PanAfter each setup for PASID entry, related translation caches must be flushed. We can combine duplicated code into one function which is less error prone.
--- drivers/iommu/intel-pasid.c | 48 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 30 deletions(-)
drivers/iommu/intel-pasid.c +18 -30
@@ -465,6 +465,21 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu,devtlb_invalidation_with_pasid (iommu, dev, pasid); } +static void pasid_flush_caches (struct intel_iommu *iommu, +struct pasid_entry *pte, +int pasid,u16 did) +{ +if (!ecap_coherent (iommu->ecap)) +clflush_cache_range (pte,sizeof (*pte)); + +if (cap_caching_mode (iommu->cap)) { +pasid_cache_invalidation_with_pasid (iommu, did, pasid); +iotlb_invalidation_with_pasid (iommu, did, pasid); + }else { +iommu_flush_write_buffer (iommu); + } +} +/* * Set up the scalable mode pasid table entry for first only * translation type.
@@ -518,16 +533,7 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,/* Setup Present and PASID Granular Transfer Type: */ pasid_set_translation_type (pte,1 );pasid_set_present (pte); - -if (!ecap_coherent (iommu->ecap)) -clflush_cache_range (pte,sizeof (*pte)); - -if (cap_caching_mode (iommu->cap)) { -pasid_cache_invalidation_with_pasid (iommu, did, pasid); -iotlb_invalidation_with_pasid (iommu, did, pasid); - }else { -iommu_flush_write_buffer (iommu); - } +pasid_flush_caches (iommu, pte, pasid, did);return 0 ; }
@@ -591,16 +597,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,*/ pasid_set_sre (pte);pasid_set_present (pte); - -if (!ecap_coherent (iommu->ecap)) -clflush_cache_range (pte,sizeof (*pte)); - -if (cap_caching_mode (iommu->cap)) { -pasid_cache_invalidation_with_pasid (iommu, did, pasid); -iotlb_invalidation_with_pasid (iommu, did, pasid); - }else { -iommu_flush_write_buffer (iommu); - } +pasid_flush_caches (iommu, pte, pasid, did);return 0 ; }
@@ -634,16 +631,7 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,*/ pasid_set_sre (pte);pasid_set_present (pte); - -if (!ecap_coherent (iommu->ecap)) -clflush_cache_range (pte,sizeof (*pte)); - -if (cap_caching_mode (iommu->cap)) { -pasid_cache_invalidation_with_pasid (iommu, did, pasid); -iotlb_invalidation_with_pasid (iommu, did, pasid); - }else { -iommu_flush_write_buffer (iommu); - } +pasid_flush_caches (iommu, pte, pasid, did);return 0 ; }
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 5/8 iommu/vt-d: Fix off-by-one in PASID allocation
In reply to Jacob PanPASID allocator uses IDR which is exclusive for the end of the allocation range. There is no need to decrement pasid_max.
--- drivers/iommu/intel-svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-svm.c +1 -1
@@ -338,7 +338,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ ret =intel_pasid_alloc_id (svm, !!cap_caching_mode (iommu->cap), - pasid_max -1 ,GFP_KERNEL ); + pasid_max,GFP_KERNEL );if (ret <0 ) {kfree (svm);kfree (sdev);
Signature · 1 line
2.7.4
PATCH v5 6/8 iommu/vt-d: Replace Intel specific PASID allocator with IOASID
In reply to Jacob PanMake use of generic IOASID code to manage PASID allocation, free, and lookup. Replace Intel specific code.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 13 +++++++------ drivers/iommu/intel-pasid.c | 36 ------------------------------------ drivers/iommu/intel-svm.c | 36 ++++++++++++++++++++++-------------- 4 files changed, 30 insertions(+), 56 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -212,6 +212,7 @@ config INTEL_IOMMU_SVM depends on INTEL_IOMMU && X86 select PCI_PASID select MMU_NOTIFIER + select IOASID help Shared Virtual Memory (SVM) provides a facility for devices to access DMA resources through process address space by
drivers/iommu/intel-iommu.c +7 -6
@@ -5238,7 +5238,7 @@ static void auxiliary_unlink_device(struct dmar_domain *domain, domain->auxd_refcnt--;if (!domain->auxd_refcnt && domain->default_pasid >0 ) -intel_pasid_free_id (domain->default_pasid); +ioasid_free (domain->default_pasid); } static int aux_domain_add_dev(struct dmar_domain *domain,
@@ -5256,10 +5256,11 @@ static int aux_domain_add_dev(struct dmar_domain *domain,if (domain->default_pasid <=0 ) {int pasid; - pasid =intel_pasid_alloc_id (domain,PASID_MIN , -pci_max_pasids (to_pci_dev (dev)), -GFP_KERNEL ); -if (pasid <=0 ) { +/* No private data needed for the default pasid */ + pasid =ioasid_alloc (NULL ,PASID_MIN , +pci_max_pasids (to_pci_dev (dev)) -1 , +NULL ); +if (pasid ==INVALID_IOASID ) {pr_err ("Can't allocate default pasid\n" );return -ENODEV ; }
@@ -5295,7 +5296,7 @@ static int aux_domain_add_dev(struct dmar_domain *domain,spin_unlock (&iommu->lock);spin_unlock_irqrestore (&device_domain_lock, flags);if (!domain->auxd_refcnt && domain->default_pasid >0 ) -intel_pasid_free_id (domain->default_pasid); +ioasid_free (domain->default_pasid);return ret; }
drivers/iommu/intel-pasid.c +0 -36
@@ -26,42 +26,6 @@*/ static DEFINE_SPINLOCK (pasid_lock);u32 intel_pasid_max_id =PASID_MAX ; -static DEFINE_IDR (pasid_idr); - -int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp) -{ -int ret, min, max; - - min =max_t (int, start,PASID_MIN ); - max =min_t (int, end, intel_pasid_max_id); - -WARN_ON (in_interrupt ()); -idr_preload (gfp); -spin_lock (&pasid_lock); - ret =idr_alloc (&pasid_idr, ptr, min, max,GFP_ATOMIC ); -spin_unlock (&pasid_lock); -idr_preload_end (); - -return ret; -} - -void intel_pasid_free_id (int pasid) -{ -spin_lock (&pasid_lock); -idr_remove (&pasid_idr, pasid); -spin_unlock (&pasid_lock); -} - -void *intel_pasid_lookup_id (int pasid) -{ -void *p; - -spin_lock (&pasid_lock); - p =idr_find (&pasid_idr, pasid); -spin_unlock (&pasid_lock); - -return p; -}/* * Per device pasid table management:
drivers/iommu/intel-svm.c +22 -14
@@ -17,6 +17,7 @@#include <linux/dmar.h> #include <linux/interrupt.h> #include <linux/mm_types.h> +#include <linux/ioasid.h> #include <asm/page.h> #include "intel-pasid.h"
@@ -335,16 +336,15 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (pasid_max > intel_pasid_max_id) pasid_max = intel_pasid_max_id; -/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ - ret =intel_pasid_alloc_id (svm, - !!cap_caching_mode (iommu->cap), - pasid_max,GFP_KERNEL ); -if (ret <0 ) { +/* Do not use PASID 0, reserved for RID to PASID */ + svm->pasid =ioasid_alloc (NULL ,PASID_MIN , + pasid_max -1 , svm); +if (svm->pasid ==INVALID_IOASID ) {kfree (svm);kfree (sdev); + ret = -ENOSPC ; goto out; } - svm->pasid = ret; svm->notifier.ops = &intel_mmuops; svm->mm = mm; svm->flags = flags;
@@ -354,7 +354,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (mm) { ret =mmu_notifier_register (&svm->notifier, mm);if (ret) { -intel_pasid_free_id (svm->pasid); +ioasid_free (svm->pasid);kfree (svm);kfree (sdev); goto out;
@@ -370,7 +370,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (ret) {if (mm)mmu_notifier_unregister (&svm->notifier, mm); -intel_pasid_free_id (svm->pasid); +ioasid_free (svm->pasid);kfree (svm);kfree (sdev); goto out;
@@ -418,10 +418,15 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)if (!iommu) goto out; - svm =intel_pasid_lookup_id (pasid); + svm =ioasid_find (NULL , pasid,NULL );if (!svm) goto out; +if (IS_ERR (svm)) { + ret =PTR_ERR (svm); + goto out; + } +list_for_each_entry (sdev, &svm->devs, list) {if (dev == sdev->dev) { ret =0 ;
@@ -440,7 +445,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)kfree_rcu (sdev, rcu);if (list_empty (&svm->devs)) { -intel_pasid_free_id (svm->pasid); +ioasid_free (svm->pasid);if (svm->mm)mmu_notifier_unregister (&svm->notifier, svm->mm);
@@ -475,10 +480,14 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)if (!iommu) goto out; - svm =intel_pasid_lookup_id (pasid); + svm =ioasid_find (NULL , pasid,NULL );if (!svm) goto out; +if (IS_ERR (svm)) { + ret =PTR_ERR (svm); + goto out; + }/* init_mm is used in this case */ if (!svm->mm) ret =1 ;
@@ -585,13 +594,12 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (!svm || svm->pasid != req->pasid) {rcu_read_lock (); - svm =intel_pasid_lookup_id (req->pasid); + svm =ioasid_find (NULL , req->pasid,NULL );/* It *can't* go away, because the driver is not permitted * to unbind the mm while any page faults are outstanding. * So we only need RCU to protect the internal idr code. */ rcu_read_unlock (); - -if (!svm) { +if (IS_ERR_OR_NULL (svm)) {pr_err ("%s: Page request for invalid PASID %d: %08llx %08llx\n" , iommu->name, req->pasid, ((unsigned long long *)req)[0 ], ((unsigned long long *)req)[1 ]);
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 7/8 iommu/vt-d: Avoid sending invalid page response
In reply to Jacob PanPage responses should only be sent when last page in group (LPIG) or private data is present in the page request. This patch avoids sending invalid descriptors.
support")
--- drivers/iommu/intel-svm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iommu/intel-svm.c +3 -4
@@ -683,11 +683,10 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (req->priv_data_present)memcpy (&resp.qw2, req->priv_data,sizeof (req->priv_data)); + resp.qw2 =0 ; + resp.qw3 =0 ; +qi_submit_sync (&resp, iommu); } - resp.qw2 =0 ; - resp.qw3 =0 ; -qi_submit_sync (&resp, iommu); - head = (head +sizeof (*req)) &PRQ_RING_MASK ; }
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 8/8 iommu/vt-d: Misc macro clean up for SVM
In reply to Jacob PanUse combined macros for_each_svm_dev() to simplify SVM device iteration and error checking.
--- drivers/iommu/intel-svm.c | 79 +++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 40 deletions(-)
drivers/iommu/intel-svm.c +39 -40
@@ -226,6 +226,10 @@ static const struct mmu_notifier_ops intel_mmuops = {static DEFINE_MUTEX (pasid_mutex);static LIST_HEAD (global_svm_list); +#define for_each_svm_dev (sdev, svm, d) \ + list_for_each_entry((sdev), &(svm)->devs, list) \ + if ((d) != (sdev)->dev) {} else +int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops) {struct intel_iommu *iommu =intel_svm_device_to_iommu (dev);
@@ -274,15 +278,14 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ goto out; } -list_for_each_entry (sdev, &svm->devs, list) { -if (dev == sdev->dev) { -if (sdev->ops != ops) { - ret = -EBUSY ; - goto out; - } - sdev->users++; - goto success; +/* Find the matching device in svm list */ +for_each_svm_dev (sdev, svm, dev) { +if (sdev->ops != ops) { + ret = -EBUSY ; + goto out; } + sdev->users++; + goto success; }break ;
@@ -427,40 +430,36 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) goto out; } -list_for_each_entry (sdev, &svm->devs, list) { -if (dev == sdev->dev) { - ret =0 ; - sdev->users--; -if (!sdev->users) { -list_del_rcu (&sdev->list); -/* Flush the PASID cache and IOTLB for this device. -* Note that we do depend on the hardware *not* using -* the PASID any more. Just as we depend on other -* devices never using PASIDs that they have no right -* to use. We have a *shared* PASID table, because it's -* 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)) { -ioasid_free (svm->pasid); -if (svm->mm) -mmu_notifier_unregister (&svm->notifier, svm->mm); - -list_del (&svm->list); - -/* We mandate that no page faults may be outstanding -* for the PASID when intel_svm_unbind_mm() is called. -* If that is not obeyed, subtle errors will happen. -* Let's make them less subtle... */ -memset (svm,0x6b ,sizeof (*svm)); -kfree (svm); - } +for_each_svm_dev (sdev, svm, dev) { + ret =0 ; + sdev->users--; +if (!sdev->users) { +list_del_rcu (&sdev->list); +/* Flush the PASID cache and IOTLB for this device. +* Note that we do depend on the hardware *not* using +* the PASID any more. Just as we depend on other +* devices never using PASIDs that they have no right +* to use. We have a *shared* PASID table, because it's +* 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)) { +ioasid_free (svm->pasid); +if (svm->mm) +mmu_notifier_unregister (&svm->notifier, svm->mm); +list_del (&svm->list); +/* We mandate that no page faults may be outstanding +* for the PASID when intel_svm_unbind_mm() is called. +* If that is not obeyed, subtle errors will happen. +* Let's make them less subtle... */ +memset (svm,0x6b ,sizeof (*svm)); +kfree (svm); } -break ; } +break ; } out:mutex_unlock (&pasid_mutex);
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v5 8/8] iommu/vt-d: Misc macro clean up for SVM
Quoted 2 lines · Jacob Pan
Use combined macros
for_each_svm_dev()to simplify SVM device iteration and error checking.
[]
drivers/iommu/intel-svm.c
Quoted 1 line
drivers/iommu/intel-svm.c +0
-0
[]
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid)
Quoted 1 line
drivers/iommu/intel-svm.c +0
-0@@ -427,40 +430,36 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)
[]
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid) · line 436
Quoted 4 lines
drivers/iommu/intel-svm.c +4
-0+for_each_svm_dev (sdev, svm, dev) { + ret =0 ; + sdev->users--; +if (!sdev->users) {
This might be better by reducing indentation here too
if (sdev->users) break;
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid) · line 437
Quoted 1 line
drivers/iommu/intel-svm.c +1
-0+list_del_rcu (&sdev->list);
to reduce indentation 1 level below this
Quoted 29 lines
drivers/iommu/intel-svm.c +23
-1+/* Flush the PASID cache and IOTLB for this device. +* Note that we do depend on the hardware *not* using +* the PASID any more. Just as we depend on other +* devices never using PASIDs that they have no right +* to use. We have a *shared* PASID table, because it's +* 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)) { +ioasid_free (svm->pasid); +if (svm->mm) +mmu_notifier_unregister (&svm->notifier, svm->mm); +list_del (&svm->list); +/* We mandate that no page faults may be outstanding +* for the PASID when intel_svm_unbind_mm() is called. +* If that is not obeyed, subtle errors will happen. +* Let's make them less subtle... */ +memset (svm,0x6b ,sizeof (*svm)); +kfree (svm); } -break ; } +break ; } out:mutex_unlock (&pasid_mutex);
Re: [PATCH v5 8/8] iommu/vt-d: Misc macro clean up for SVM
Quoted 16 lines · On Mon, 02 Dec 2019 12:10:45 -0800 Joe Perches <[email protected]> wrote:
Quoted 2 lines · Jacob Pan
Use combined macros
for_each_svm_dev()to simplify SVM device iteration and error checking.[]
drivers/iommu/intel-svm.c
Quoted 1 line
drivers/iommu/intel-svm.c +0
-0[]
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, · line 430
Quoted 2 lines
drivers/iommu/intel-svm.c +0
-0@@ -427,40 +430,36 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)[]
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid) · line 436
Quoted 4 lines
drivers/iommu/intel-svm.c +4
-0+for_each_svm_dev (sdev, svm, dev) { + ret =0 ; + sdev->users--; +if (!sdev->users) {This might be better by reducing indentation here too
Quoted 6 lines
if (sdev->users) break;drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid) · line 437
Quoted 1 line
drivers/iommu/intel-svm.c +1
-0+list_del_rcu (&sdev->list);to reduce indentation 1 level below this
Sounds good but perhaps we can do this in a separate patch.
Quoted 36 lines
Quoted 36 lines
drivers/iommu/intel-svm.c +1
-0+/* Flush the PASID cache and IOTLB for this device.
drivers/iommu/intel-svm.c +1
-0+* Note that we do depend on the hardware *not* using
drivers/iommu/intel-svm.c +1
-0+* the PASID any more. Just as we depend on other
drivers/iommu/intel-svm.c +1
-0+* devices never using PASIDs that they have no right
drivers/iommu/intel-svm.c +1
-0+* to use. We have a *shared* PASID table, because it's
drivers/iommu/intel-svm.c +1
-0+* large and has to be physically contiguous. So it's
drivers/iommu/intel-svm.c +1
-0+* hard to be as defensive as we might like. */
drivers/iommu/intel-svm.c +1
-0+ intel_pasid_tear_down_entry(iommu, dev,
svm->pasid);drivers/iommu/intel-svm.c +7
-1+intel_flush_svm_range_dev (svm, sdev,0 , -1, 0); + kfree_rcu(sdev, rcu); + +if (list_empty (&svm->devs)) { +ioasid_free (svm->pasid); +if (svm->mm) +
mmu_notifier_unregister(&svm->notifier, svm->mm);drivers/iommu/intel-svm.c +2
-0+list_del (&svm->list); +/* We mandate that no page faults may be outstanding
drivers/iommu/intel-svm.c +1
-0+* for the PASID when
intel_svm_unbind_mm()is called.drivers/iommu/intel-svm.c +1
-0+* If that is not obeyed, subtle errors will happen.
drivers/iommu/intel-svm.c +1
-0+* Let's make them less subtle... */
drivers/iommu/intel-svm.c +1
-0+memset (svm,0x6b ,sizeof (*svm));
Quoted 9 lines
drivers/iommu/intel-svm.c int intel_svm_unbind_mm(struct device *dev, int pasid) · line 465
Quoted 8 lines
drivers/iommu/intel-svm.c +2
-1+kfree (svm); } -break ; } +break ; } out:mutex_unlock (&pasid_mutex);
[Jacob Pan]
Hi Joerg and Baolu,
Any more comments on this series? I rebased it on v5.5-rc1 without changes.
Thanks,
Jacob
Quoted 39 lines · On Mon, 2 Dec 2019 11:58:21 -0800 Jacob Pan <[email protected]>…
Mostly extracted from nested SVA/SVM series based on review comments of v7. https://lkml.org/lkml/2019/10/24/852
This series also adds a few important fixes for native use of SVA. Nested SVA new code will be submitted separately as a smaller set. Based on the core branch of IOMMU tree staged for v5.5, where common APIs for vSVA were applied.
git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.gitcoreChangelog:
v5 - Regrouped patch 6 and 8, added comments suggested by Joe
Perches v4 - Commit message fixV3
- Squashed 1/10 & 2/10
- Deleted "8/10 Fix PASID cache flush" from this series
- Addressed reviews from Eric Auger and Baolu
V2
- Coding style fixes based on Baolu's input, no functional
change
- Added Acked-by tags.Thanks,
Jacob
*** BLURB HERE ***
Jacob Pan (8):
iommu/vt-d: Fix CPU and IOMMU SVM feature matching checks iommu/vt-d: Match CPU and IOMMU paging mode iommu/vt-d: Reject SVM bind for failed capability check iommu/vt-d: Avoid duplicated code for PASID setup iommu/vt-d: Fix off-by-one in PASID allocation iommu/vt-d: Replace Intel specific PASID allocator with IOASID iommu/vt-d: Avoid sending invalid page response iommu/vt-d: Misc macro clean up for SVM
Quoted 8 lines
drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 23 +++---- drivers/iommu/intel-pasid.c | 96 ++++++++------------------ drivers/iommu/intel-svm.c | 163+++++++++++++++++++++++++-------------------
include/linux/intel-iommu.h| 5 +- 5 files changed, 135
insertions(+), 153 deletions(-)
[Jacob Pan]
Hi Jacob,
This has been queued for internal test. I will forward it to Joerg if everything goes well (probably around rc4).
Best regards,
-baolu
Quoted 63 lines · Jacob Pan
Hi Joerg and Baolu,
Any more comments on this series? I rebased it on v5.5-rc1 without changes.
Thanks,
Jacob
Quoted 39 lines · On Mon, 2 Dec 2019 11:58:21 -0800 Jacob Pan <[email protected]>…
Mostly extracted from nested SVA/SVM series based on review comments of v7. https://lkml.org/lkml/2019/10/24/852
This series also adds a few important fixes for native use of SVA. Nested SVA new code will be submitted separately as a smaller set. Based on the core branch of IOMMU tree staged for v5.5, where common APIs for vSVA were applied.
git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.gitcoreChangelog:
v5 - Regrouped patch 6 and 8, added comments suggested by Joe
Perches v4 - Commit message fixV3
- Squashed 1/10 & 2/10
- Deleted "8/10 Fix PASID cache flush" from this series
- Addressed reviews from Eric Auger and Baolu
V2
- Coding style fixes based on Baolu's input, no functional
change
- Added Acked-by tags.Thanks,
Jacob
*** BLURB HERE ***
Jacob Pan (8):
iommu/vt-d: Fix CPU and IOMMU SVM feature matching checks iommu/vt-d: Match CPU and IOMMU paging mode iommu/vt-d: Reject SVM bind for failed capability check iommu/vt-d: Avoid duplicated code for PASID setup iommu/vt-d: Fix off-by-one in PASID allocation iommu/vt-d: Replace Intel specific PASID allocator with IOASID iommu/vt-d: Avoid sending invalid page response iommu/vt-d: Misc macro clean up for SVMQuoted 8 lines
drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 23 +++---- drivers/iommu/intel-pasid.c | 96 ++++++++------------------ drivers/iommu/intel-svm.c | 163+++++++++++++++++++++++++-------------------
include/linux/intel-iommu.h| 5 +- 5 files changed, 135
insertions(+), 153 deletions(-)[Jacob Pan]
Quoted 5 lines · On Tue, 10 Dec 2019 09:14:07 +0800 Lu Baolu <[email protected]> wrote:
Hi Jacob,
This has been queued for internal test. I will forward it to Joerg if everything goes well (probably around rc4).
Thanks for the confirmation. I will send out further patches based on this series.
Quoted 67 lines
Best regards,
-baoluQuoted 63 lines · Jacob Pan
Hi Joerg and Baolu,
Any more comments on this series? I rebased it on v5.5-rc1 without changes.
Thanks,
Jacob
Quoted 39 lines · On Mon, 2 Dec 2019 11:58:21 -0800 Jacob Pan <[email protected]>…
Mostly extracted from nested SVA/SVM series based on review comments of v7. https://lkml.org/lkml/2019/10/24/852
This series also adds a few important fixes for native use of SVA. Nested SVA new code will be submitted separately as a smaller set. Based on the core branch of IOMMU tree staged for v5.5, where common APIs for vSVA were applied.
git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.gitcoreChangelog:
v5 - Regrouped patch 6 and 8, added comments suggested by
Joe Perches v4 - Commit message fixV3
- Squashed 1/10 & 2/10
- Deleted "8/10 Fix PASID cache flush" from this series
- Addressed reviews from Eric Auger and Baolu
V2
- Coding style fixes based on Baolu's input, no functional
change
- Added Acked-by tags.Thanks,
Jacob
*** BLURB HERE ***
Jacob Pan (8):
iommu/vt-d: Fix CPU and IOMMU SVM feature matching checks iommu/vt-d: Match CPU and IOMMU paging mode iommu/vt-d: Reject SVM bind for failed capability check iommu/vt-d: Avoid duplicated code for PASID setup iommu/vt-d: Fix off-by-one in PASID allocation iommu/vt-d: Replace Intel specific PASID allocator with IOASID iommu/vt-d: Avoid sending invalid page response iommu/vt-d: Misc macro clean up for SVMQuoted 8 lines
drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 23 +++---- drivers/iommu/intel-pasid.c | 96 ++++++++------------------ drivers/iommu/intel-svm.c | 163+++++++++++++++++++++++++-------------------
include/linux/intel-iommu.h| 5 +- 5 files changed, 135
insertions(+), 153 deletions(-)[Jacob Pan]
[Jacob Pan]
Quoted 8 lines · Jacob Pan
Mostly extracted from nested SVA/SVM series based on review comments of v7.
https://lkml.org/lkml/2019/10/24/852This series also adds a few important fixes for native use of SVA. Nested SVA new code will be submitted separately as a smaller set. Based on the core branch of IOMMU tree staged for v5.5, where common APIs for vSVA were applied.
git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.gitcore
Queued the whole series for v5.6.
Thanks,
-baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu