iommu/vt-d: Fixes for v6.7-rc3
Subsystems (2)
Lu Baolu
maintainerHi Joerg,
The following fixes have been queued for v6.7. They aim to:
- Do not support enforcing cache coherency for non-empty domains
- Avoid devTLB invalidation if iommu is off
- Disable PCI ATS in legacy passthrough mode
- Support non-PCI devices when clearing context
- Fix incorrect cache invalidation for mm notification
- Add MTL to quirk list to skip TE disabling
- Set variable intel_dirty_ops to static
Please consider them for the iommu/fix branch.
Best regards,
Lu Baolu
Abdul Halim, Mohd Syazwan (1):
iommu/vt-d: Add MTL to quirk list to skip TE disabling
Kunwu Chan (1):
iommu/vt-d: Set variable intel_dirty_ops to static
Lu Baolu (5):
iommu/vt-d: Support enforce_cache_coherency only for empty domains iommu/vt-d: Omit devTLB invalidation requests when TES=0 iommu/vt-d: Disable PCI ATS in legacy passthrough mode iommu/vt-d: Make context clearing consistent with context mapping iommu/vt-d: Fix incorrect cache invalidation for mm notification
drivers/iommu/intel/iommu.h | 3 +++ drivers/iommu/intel/dmar.c | 18 ++++++++++++++++++ drivers/iommu/intel/iommu.c | 18 +++++++++++------- drivers/iommu/intel/svm.c | 26 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 1/7 iommu/vt-d: Support enforce_cache_coherency only for empty domains
The enforce_cache_coherency callback ensures DMA cache coherency for devices attached to the domain.
Intel IOMMU supports enforced DMA cache coherency when the Snoop Control bit in the IOMMU's extended capability register is set. Supporting it differs between legacy and scalable modes.
In legacy mode, it's supported page-level by setting the SNP field in second-stage page-table entries. In scalable mode, it's supported in PASID-table granularity by setting the PGSNP field in PASID-table entries.
In legacy mode, mappings before attaching to a device have SNP fields cleared, while mappings after the callback have them set. This means partial DMAs are cache coherent while others are not.
One possible fix is replaying mappings and flipping SNP bits when attaching a domain to a device. But this seems to be over-engineered, given that all real use cases just attach an empty domain to a device.
To meet practical needs while reducing mode differences, only support enforce_cache_coherency on a domain without mappings if SNP field is used.
--- drivers/iommu/intel/iommu.h | 3 +++ drivers/iommu/intel/iommu.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/iommu/intel/iommu.h +3 -0
@@ -602,6 +602,9 @@ struct dmar_domain {*/ u8 dirty_tracking:1; /* Dirty tracking is enabled */ u8 nested_parent:1; /* Has other domains nested on it */ + u8 has_mappings:1; /* Has mappings configured through +* iommu_map() interface. +*/ spinlock_t lock;/* Protect device tracking lists */ struct list_head devices;/* all devices' list */
drivers/iommu/intel/iommu.c +4 -1
@@ -2207,6 +2207,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, attr |=DMA_FL_PTE_DIRTY ; } + domain->has_mappings = true; + pteval = ((phys_addr_t )phys_pfn <<VTD_PAGE_SHIFT ) | attr;while (nr_pages >0 ) {
@@ -4360,7 +4362,8 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)return true;spin_lock_irqsave (&dmar_domain->lock, flags); -if (!domain_support_force_snooping (dmar_domain)) { +if (!domain_support_force_snooping (dmar_domain) || + (!dmar_domain->use_first_level && dmar_domain->has_mappings)) {spin_unlock_irqrestore (&dmar_domain->lock, flags);return false; }
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 2/7 iommu/vt-d: Omit devTLB invalidation requests when TES=0
In reply to Lu BaoluThe latest VT-d spec indicates that when remapping hardware is disabled (TES=0 in Global Status Register), upstream ATS Invalidation Completion requests are treated as UR (Unsupported Request).
Consequently, the spec recommends in section 4.3 Handling of Device-TLB Invalidations that software refrain from submitting any Device-TLB invalidation requests when address remapping hardware is disabled.
Verify address remapping hardware is enabled prior to submitting Device- TLB invalidation requests.
--- drivers/iommu/intel/dmar.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/iommu/intel/dmar.c +18 -0
@@ -1522,6 +1522,15 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, {struct qi_desc desc; +/* +* VT-d spec, section 4.3: +* +* Software is recommended to not submit any Device-TLB invalidation +* requests while address remapping hardware is disabled. +*/ +if (!(iommu->gcmd &DMA_GCMD_TE )) +return ; +if (mask) { addr |= (1ULL << (VTD_PAGE_SHIFT + mask -1 )) -1 ; desc.qw1 =QI_DEV_IOTLB_ADDR (addr) |QI_DEV_IOTLB_SIZE ;
@@ -1587,6 +1596,15 @@ void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid,unsigned long mask =1UL << (VTD_PAGE_SHIFT + size_order -1 );struct qi_desc desc = {.qw1 =0 , .qw2 =0 , .qw3 =0 }; +/* +* VT-d spec, section 4.3: +* +* Software is recommended to not submit any Device-TLB invalidation +* requests while address remapping hardware is disabled. +*/ +if (!(iommu->gcmd &DMA_GCMD_TE )) +return ; + desc.qw0 =QI_DEV_EIOTLB_PASID (pasid) |QI_DEV_EIOTLB_SID (sid) |QI_DEV_EIOTLB_QDEP (qdep) |QI_DEIOTLB_TYPE |QI_DEV_IOTLB_PFSID (pfsid);
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 3/7 iommu/vt-d: Disable PCI ATS in legacy passthrough mode
In reply to Lu BaoluWhen IOMMU hardware operates in legacy mode, the TT field of the context entry determines the translation type, with three supported types (Section 9.3 Context Entry):
- DMA translation without device TLB support
- DMA translation with device TLB support
- Passthrough mode with translated and translation requests blocked
Device TLB support is absent when hardware is configured in passthrough mode.
Disable the PCI ATS feature when IOMMU is configured for passthrough translation type in legacy (non-scalable) mode.
--- drivers/iommu/intel/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +2 -1
@@ -2492,7 +2492,8 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,return ret; } -iommu_enable_pci_caps (info); +if (sm_supported (info->iommu) || !domain_type_is_si (info->domain)) +iommu_enable_pci_caps (info);return 0 ; }
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 4/7 iommu/vt-d: Make context clearing consistent with context mapping
In reply to Lu BaoluIn the iommu probe_device path, domain_context_mapping() allows setting up the context entry for a non-PCI device. However, in the iommu release_device path, domain_context_clear() only clears context entries for PCI devices.
Make domain_context_clear() behave consistently with domain_context_mapping() by clearing context entries for both PCI and non-PCI devices.
--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -3928,8 +3928,8 @@ static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *op*/ static void domain_context_clear (struct device_domain_info *info) { -if (!info->iommu || !info->dev || !dev_is_pci (info->dev)) -return ; +if (!dev_is_pci (info->dev)) +domain_context_clear_one (info, info->bus, info->devfn);pci_for_each_dma_alias (to_pci_dev (info->dev), &domain_context_clear_one_cb, info);
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 5/7 iommu/vt-d: Add MTL to quirk list to skip TE disabling
In reply to Lu BaoluFrom: "Abdul Halim, Mohd Syazwan" <[email protected]>
The VT-d spec requires (10.4.4 Global Command Register, TE field) that:
Hardware implementations supporting DMA draining must drain any in-flight DMA read/write requests queued within the Root-Complex before switching address translation on or off and reflecting the status of the command through the TES field in the Global Status register.
Unfortunately, some integrated graphic devices fail to do so after some kind of power state transition. As the result, the system might stuck in iommu_disable_translation(), waiting for the completion of TE transition.
Add MTL to the quirk list for those devices and skips TE disabling if the qurik hits.
--- drivers/iommu/intel/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +1 -1
@@ -5077,7 +5077,7 @@ static void quirk_igfx_skip_te_disable(struct pci_dev *dev) ver = (dev->device >>8 ) &0xff ;if (ver !=0x45 && ver !=0x46 && ver !=0x4c && ver !=0x4e && ver !=0x8a && ver !=0x98 && - ver !=0x9a && ver !=0xa7 ) + ver !=0x9a && ver !=0xa7 && ver !=0x7d )return ;if (risky_device (dev))
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 6/7 iommu/vt-d: Fix incorrect cache invalidation for mm notification
In reply to Lu BaoluCommit 6bbd42e2df8f ("mmu_notifiers: call invalidate_range() when invalidating TLBs") moved the secondary TLB invalidations into the TLB invalidation functions to ensure that all secondary TLB invalidations happen at the same time as the CPU invalidation and added a flush-all type of secondary TLB invalidation for the batched mode, where a range of [0, -1UL) is used to indicates that the range extends to the end of the address space.
However, using an end address of -1UL caused an overflow in the Intel IOMMU driver, where the end address was rounded up to the next page. As a result, both the IOTLB and device ATC were not invalidated correctly.
Add a flush all helper function and call it when the invalidation range is from 0 to -1UL, ensuring that the entire caches are invalidated correctly.
--- drivers/iommu/intel/svm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/iommu/intel/svm.c +26 -0
@@ -216,6 +216,27 @@ static void intel_flush_svm_range(struct intel_svm *svm, unsigned long address,rcu_read_unlock (); } +static void intel_flush_svm_all (struct intel_svm *svm) +{ +struct device_domain_info *info; +struct intel_svm_dev *sdev; + +rcu_read_lock (); +list_for_each_entry_rcu (sdev, &svm->devs, list) { + info =dev_iommu_priv_get (sdev->dev); + +qi_flush_piotlb (sdev->iommu, sdev->did, svm->pasid,0 ,-1UL ,0 ); +if (info->ats_enabled) { +qi_flush_dev_iotlb_pasid (sdev->iommu, sdev->sid, info->pfsid, + svm->pasid, sdev->qdep, +0 ,64 -VTD_PAGE_SHIFT ); +quirk_extra_dev_tlb_flush (info,0 ,64 -VTD_PAGE_SHIFT , + svm->pasid, sdev->qdep); + } + } +rcu_read_unlock (); +} +/* Pages have been freed at this point */ static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, struct mm_struct *mm,
@@ -223,6 +244,11 @@ static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, { struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); +if (start ==0 && end ==-1UL ) { +intel_flush_svm_all (svm); +return ; + } +intel_flush_svm_range (svm, start, (end - start +PAGE_SIZE -1 ) >>VTD_PAGE_SHIFT ,0 ); }
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH 7/7 iommu/vt-d: Set variable intel_dirty_ops to static
In reply to Lu BaoluFrom: Kunwu Chan <[email protected]>
Fix the following warning:drivers/iommu/intel/iommu.c:302:30: warning: symbol
'intel_dirty_ops' was not declared. Should it be static?
This variable is only used in its defining file, so it should be static.
--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -299,7 +299,7 @@ static int iommu_skip_te_disable;#define IDENTMAP_AZALIA 4const struct iommu_ops intel_iommu_ops; -const struct iommu_dirty_ops intel_dirty_ops; +static const struct iommu_dirty_ops intel_dirty_ops;static bool translation_pre_enabled (struct intel_iommu *iommu) {
@@ -4929,7 +4929,7 @@ static int intel_iommu_read_and_clear_dirty(struct iommu_domain *domain,return 0 ; } -const struct iommu_dirty_ops intel_dirty_ops = { +static const struct iommu_dirty_ops intel_dirty_ops = { .set_dirty_tracking = intel_iommu_set_dirty_tracking, .read_and_clear_dirty = intel_iommu_read_and_clear_dirty, };
Signature · 1 line
2.34.1
Joerg Roedel
maintainerQuoted 6 lines · Lu Baolu
Abdul Halim, Mohd Syazwan (1):
iommu/vt-d: Add MTL to quirk list to skip TE disablingKunwu Chan (1):
iommu/vt-d: Set variableintel_dirty_opsto static
Quoted 6 lines
Lu Baolu (5):
iommu/vt-d: Supportenforce_cache_coherencyonly for empty domains iommu/vt-d: Omit devTLB invalidation requests when TES=0 iommu/vt-d: Disable PCI ATS in legacy passthrough mode iommu/vt-d: Make context clearing consistent with context mapping iommu/vt-d: Fix incorrect cache invalidation for mm notification
Applied for v6.7, thanks.