Intel IOMMU updates for v6.14
Subsystems (2)
Lu Baolu
maintainerHi Joerg,
The following changes have been queued for v6.14-rc1. They are about new features and code refactoring, including:
- Remove domain_alloc_paging()
- Remove capability audit code
- Draining PRQ in sva unbind path when FPD bit set
- Link cache tags of same iommu unit together
These patches are based on v6.13-rc6. The complete patches are also available at:
https://github.com/LuBaolu/intel-iommu/commits/vtd-update-for-v6.14
Please consider them for iommu next.
Best regards,
baolu
Jason Gunthorpe (1):
iommu/vt-d: Remove domain_alloc_paging()
Kees Bakker (1):
iommu/vt-d: Avoid use of NULL after WARN_ON_ONCE
Lu Baolu (2):
iommu/vt-d: Remove iommu cap audit
iommu/vt-d: Draining PRQ in sva unbind path when FPD bit set
Zhenzhong Duan (1):
iommu/vt-d: Link cache tags of same iommu unit together
drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/cache.c | 11 +- drivers/iommu/intel/cap_audit.c | 217 ---------------------------- drivers/iommu/intel/cap_audit.h | 131 ----------------- drivers/iommu/intel/iommu.c | 32 +--- drivers/iommu/intel/irq_remapping.c | 8 - drivers/iommu/intel/pasid.c | 22 ++- drivers/iommu/intel/pasid.h | 6 + 8 files changed, 42 insertions(+), 387 deletions(-) delete mode 100644 drivers/iommu/intel/cap_audit.c delete mode 100644 drivers/iommu/intel/cap_audit.h
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 1/5 iommu/vt-d: Avoid use of NULL after WARN_ON_ONCE
From: Kees Bakker <[email protected]>
There is a WARN_ON_ONCE to catch an unlikely situation when domain_remove_dev_pasid can't find the pasid. In case it nevertheless happens we must avoid using a NULL pointer.
--- drivers/iommu/intel/iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +4 -3
@@ -4090,13 +4090,14 @@ void domain_remove_dev_pasid(struct iommu_domain *domain,break ; } } -WARN_ON_ONCE (!dev_pasid);spin_unlock_irqrestore (&dmar_domain->lock, flags);cache_tag_unassign_domain (dmar_domain, dev, pasid);domain_detach_iommu (dmar_domain, iommu); -intel_iommu_debugfs_remove_dev_pasid (dev_pasid); -kfree (dev_pasid); +if (!WARN_ON_ONCE (!dev_pasid)) { +intel_iommu_debugfs_remove_dev_pasid (dev_pasid); +kfree (dev_pasid); + } } static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 2/5 iommu/vt-d: Remove domain_alloc_paging()
In reply to Lu BaoluFrom: Jason Gunthorpe <[email protected]>
This is duplicated by intel_iommu_domain_alloc_paging_flags(), just remove it.
--- drivers/iommu/intel/iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)
drivers/iommu/intel/iommu.c +0 -16
@@ -4446,21 +4446,6 @@ static struct iommu_domain identity_domain = { }, }; -static struct iommu_domain *intel_iommu_domain_alloc_paging (struct device *dev) -{ -struct device_domain_info *info =dev_iommu_priv_get (dev); -struct intel_iommu *iommu = info->iommu; -struct dmar_domain *dmar_domain; -bool first_stage; - - first_stage =first_level_by_default (iommu); - dmar_domain =paging_domain_alloc (dev, first_stage); -if (IS_ERR (dmar_domain)) -return ERR_CAST (dmar_domain); - -return &dmar_domain->domain; -} -const struct iommu_ops intel_iommu_ops = { .blocked_domain = &blocking_domain, .release_domain = &blocking_domain,
@@ -4469,7 +4454,6 @@ const struct iommu_ops intel_iommu_ops = { .hw_info = intel_iommu_hw_info, .domain_alloc_paging_flags = intel_iommu_domain_alloc_paging_flags, .domain_alloc_sva = intel_svm_domain_alloc, - .domain_alloc_paging = intel_iommu_domain_alloc_paging, .domain_alloc_nested = intel_iommu_domain_alloc_nested, .probe_device = intel_iommu_probe_device, .release_device = intel_iommu_release_device,
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 3/5 iommu/vt-d: Remove iommu cap audit
In reply to Lu BaoluThe capability audit code was introduced by commit <ad3d19029979> "iommu/vt-d: Audit IOMMU Capabilities and add helper functions", aiming to verify the consistency of capabilities across all IOMMUs for supported features.
Nowadays, all the kAPIs of the iommu subsystem have evolved to be device oriented, in preparation for supporting heterogeneous IOMMU architectures. There is no longer a need to require capability consistence among IOMMUs for any feature.
Remove the iommu cap audit code to make the driver align with the design in the iommu core.
--- drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/cap_audit.c | 217 ---------------------------- drivers/iommu/intel/cap_audit.h | 131 ----------------- drivers/iommu/intel/iommu.c | 9 -- drivers/iommu/intel/irq_remapping.c | 8 - 5 files changed, 1 insertion(+), 366 deletions(-) delete mode 100644 drivers/iommu/intel/cap_audit.c delete mode 100644 drivers/iommu/intel/cap_audit.h
drivers/iommu/intel/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DMAR_TABLE) += dmar.o obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o nested.o cache.o prq.o -obj-$(CONFIG_DMAR_TABLE) += trace.o cap_audit.o +obj-$(CONFIG_DMAR_TABLE) += trace.o obj-$(CONFIG_DMAR_PERF) += perf.o obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o obj-$(CONFIG_INTEL_IOMMU_SVM) += svm.o
drivers/iommu/intel/cap_audit.c deleted +0 -217
217 lines not on this page · raw message
drivers/iommu/intel/cap_audit.h deleted +0 -131
131 lines not on this page · raw message
drivers/iommu/intel/iommu.c +0 -9
@@ -29,7 +29,6 @@#include "../irq_remapping.h" #include "../iommu-pages.h" #include "pasid.h" -#include "cap_audit.h" #include "perfmon.h" #define ROOT_SIZE VTD_PAGE_SIZE
@@ -2118,10 +2117,6 @@ static int __init init_dmars(void)struct intel_iommu *iommu;int ret; - ret =intel_cap_audit (CAP_AUDIT_STATIC_DMAR ,NULL ); -if (ret) - goto free_iommu; -for_each_iommu (iommu, drhd) {if (drhd->ignored) {iommu_disable_translation (iommu);
@@ -2617,10 +2612,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)struct intel_iommu *iommu = dmaru->iommu;int ret; - ret =intel_cap_audit (CAP_AUDIT_HOTPLUG_DMAR , iommu); -if (ret) - goto out; -/* * Disable translation if already enabled prior to OS handover. */
drivers/iommu/intel/irq_remapping.c +0 -8
@@ -24,7 +24,6 @@#include "iommu.h" #include "../irq_remapping.h" #include "../iommu-pages.h" -#include "cap_audit.h" enum irq_mode {IRQ_REMAPPING ,
@@ -727,9 +726,6 @@ static int __init intel_prepare_irq_remapping(void)if (dmar_table_init () <0 )return -ENODEV ; -if (intel_cap_audit (CAP_AUDIT_STATIC_IRQR ,NULL )) -return -ENODEV ; -if (!dmar_ir_support ())return -ENODEV ;
@@ -1534,10 +1530,6 @@ static int dmar_ir_add(struct dmar_drhd_unit *dmaru, struct intel_iommu *iommu)int ret;int eim =x2apic_enabled (); - ret =intel_cap_audit (CAP_AUDIT_HOTPLUG_IRQR , iommu); -if (ret) -return ret; -if (eim && !ecap_eim_support (iommu->ecap)) {pr_info ("DRHD %Lx: EIM not supported by DRHD, ecap %Lx\n" , iommu->reg_phys, iommu->ecap);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 4/5 iommu/vt-d: Draining PRQ in sva unbind path when FPD bit set
In reply to Lu BaoluWhen a device uses a PASID for SVA (Shared Virtual Address), it's possible that the PASID entry is marked as non-present and FPD bit set before the device flushes all ongoing DMA requests and removes the SVA domain. This can occur when an exception happens and the process terminates before the device driver stops DMA and calls the iommu driver to unbind the PASID.
There's no need to drain the PRQ in the mm release path. Instead, the PRQ will be drained in the SVA unbind path. But in such case, intel_pasid_tear_down_entry() only checks the presence of the pasid entry and returns directly.
Add the code to clear the FPD bit and drain the PRQ.
--- drivers/iommu/intel/pasid.c | 22 +++++++++++++++++++++- drivers/iommu/intel/pasid.h | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-)
drivers/iommu/intel/pasid.c +21 -1
@@ -244,11 +244,31 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,spin_lock (&iommu->lock); pte =intel_pasid_get_entry (dev, pasid); -if (WARN_ON (!pte) || !pasid_pte_is_present (pte)) { +if (WARN_ON (!pte)) {spin_unlock (&iommu->lock);return ; } +if (!pasid_pte_is_present (pte)) { +if (!pasid_pte_is_fault_disabled (pte)) { +WARN_ON (READ_ONCE (pte->val[0 ]) !=0 ); +spin_unlock (&iommu->lock); +return ; + } + +/* +* When a PASID is used for SVA by a device, it's possible +* that the pasid entry is non-present with the Fault +* Processing Disabled bit set. Clear the pasid entry and +* drain the PRQ for the PASID before return. +*/ +pasid_clear_entry (pte); +spin_unlock (&iommu->lock); +intel_iommu_drain_pasid_prq (dev, pasid); + +return ; + } + did =pasid_get_domain_id (pte); pgtt =pasid_pte_get_pgtt (pte);intel_pasid_clear_entry (dev, pasid, fault_ignore);
drivers/iommu/intel/pasid.h +6 -0
@@ -73,6 +73,12 @@ static inline bool pasid_pte_is_present(struct pasid_entry *pte)return READ_ONCE (pte->val[0 ]) &PASID_PTE_PRESENT ; } +/* Get FPD(Fault Processing Disable) bit of a PASID table entry */ +static inline bool pasid_pte_is_fault_disabled (struct pasid_entry *pte) +{ +return READ_ONCE (pte->val[0 ]) &PASID_PTE_FPD ; +} +/* Get PGTT field of a PASID table entry */ static inline u16 pasid_pte_get_pgtt (struct pasid_entry *pte) {
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 5/5 iommu/vt-d: Link cache tags of same iommu unit together
In reply to Lu BaoluFrom: Zhenzhong Duan <[email protected]>
Cache tag invalidation requests for a domain are accumulated until a different iommu unit is found when traversing the cache_tags linked list. But cache tags of same iommu unit can be distributed in the linked list, this make batched flush less efficient. E.g., one device backed by iommu0 is attached to a domain in between two devices attaching backed by iommu1.
Group cache tags together for same iommu unit in cache_tag_assign() to maximize the performance of batched flush.
--- drivers/iommu/intel/cache.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/intel/cache.c +10 -1
@@ -47,6 +47,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu = info->iommu;struct cache_tag *tag, *temp; +struct list_head *prev;unsigned long flags; tag =kzalloc (sizeof (*tag),GFP_KERNEL );
@@ -65,6 +66,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did, tag->dev = iommu->iommu.dev;spin_lock_irqsave (&domain->cache_lock, flags); + prev = &domain->cache_tags;list_for_each_entry (temp, &domain->cache_tags, node) {if (cache_tage_match (temp, did, iommu, dev, pasid, type)) { temp->users++;
@@ -73,8 +75,15 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,trace_cache_tag_assign (temp);return 0 ; } +if (temp->iommu == iommu) + prev = &temp->node; } -list_add_tail (&tag->node, &domain->cache_tags); +/* +* Link cache tags of same iommu unit together, so corresponding +* flush ops can be batched for iommu unit. +*/ +list_add (&tag->node, prev); +spin_unlock_irqrestore (&domain->cache_lock, flags);trace_cache_tag_assign (tag);
Signature · 1 line
2.43.0
Quoted 10 lines · Lu Baolu
Hi Joerg,
The following changes have been queued for v6.14-rc1. They are about new features and code refactoring, including:
- Remove
domain_alloc_paging()
- Remove capability audit code
- Draining PRQ in sva unbind path when FPD bit set
- Link cache tags of same iommu unit together
Quoted 6 lines
These patches are based on v6.13-rc6. The complete patches are also available at:
https://github.com/LuBaolu/intel-iommu/commits/vtd-update-for-v6.14
Please consider them for iommu next.
Applied, thanks.