iommu/vt-d: Be less pessimistic about domain coherency where possible
PATCH 1/1 iommu/vt-d: Be less pessimistic about domain coherency where possible
In commit 2e12bc29 ("intel-iommu: Default to non-coherent for domains unattached to iommus") we decided to err on the side of caution and always assume that it's possible that a device will be attached which is behind a non-coherent IOMMU.
In some cases, however, that just *cannot* happen. If there *are* no IOMMUs in the system which are non-coherent, then we don't need to do it. And flushing the dcache is a *significant* performance hit.
---
In fact, even the overly cautious approach is broken because it's possible to add a coherent IOMMU, then set up some mappings and *then* add a non- coherent IOMMU.
What we really want to do is flush the dcache at the time a domain transitions from coherent to non-coherent. Except that would unfortunately involve doing wbinvd on *all* CPUs, and something vaguely equivalent on IA64 that I'm not sure even exists. Walking the page tables and manually doing a clflush_cache_range() on them all would also be theoretically possible but I'm fairly sure we don't want to do that...
drivers/iommu/intel-iommu.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +17 -4
@@ -593,18 +593,31 @@ static struct intel_iommu *domain_get_iommu(struct dmar_domain *domain)static void domain_update_iommu_coherency (struct dmar_domain *domain) { -int i; - - i =find_first_bit (domain->iommu_bmp, g_num_of_iommus); +struct dmar_drhd_unit *drhd; +struct intel_iommu *iommu; +int i, found =0 ; - domain->iommu_coherency = i < g_num_of_iommus ?1 :0 ; + domain->iommu_coherency =1 ;for_each_set_bit (i, domain->iommu_bmp, g_num_of_iommus) { + found =1 ;if (!ecap_coherent (g_iommus[i]->ecap)) { domain->iommu_coherency =0 ;break ; } } +if (found) +return ; + +/* No hardware attached; use lowest common denominator */ +rcu_read_lock (); +for_each_active_iommu (iommu, drhd) { +if (!ecap_coherent (iommu->ecap)) { + domain->iommu_coherency =0 ; +break ; + } + } +rcu_read_unlock (); }static void domain_update_iommu_snooping (struct dmar_domain *domain)
Signature · 6 lines
1.8.5.3 -- David Woodhouse Open Source Technology Centre [email protected] Intel Corporation