public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] intel-iommu: Default to non-coherent for domains unattached to iommus
@ 2011-11-11 22:49 Alex Williamson
  2011-11-12  0:17 ` Chris Wright
  2011-11-12  0:37 ` David Woodhouse
  0 siblings, 2 replies; 17+ messages in thread
From: Alex Williamson @ 2011-11-11 22:49 UTC (permalink / raw)
  To: dwmw2; +Cc: iommu, linux-pci, linux-kernel, chrisw, ddutile, alex.williamson

domain_update_iommu_coherency() currently default to setting domains
as coherent when the domain is not attached to any iommus.  This
allows for a window in domain_context_mapping_one() where such a
domain can update context entries non-coherenty, and only after
update the domain capability to clear iommu_coherency.

This can be seen using KVM device assignment on VT-d systems that
do not support coherency in the ecap register.  When a device is
added to a guest, a domain is created (iommu_coherency = 0), the
device is attached, and ranges are mapped.  If we then hot unplug
the device, the coherency is updated and set to the default (1)
since no iommus are attached to the domain.  A subsequenct attach
of a device makes use of the same dmar domain (now marked coherent)
updates context entries with cohrency enabled, and only disables
coherency as the last step in the process.

To fix this, switch domain_update_iommu_coherency() to use the
safer, non-coherent default for domains not attached to iommus.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Donald Dutile <ddutile@redhat.com>
Acked-by: Donald Dutile <ddutile@redhat.com>
---

 drivers/iommu/intel-iommu.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index c0c7820..6b9d8c1 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -560,7 +560,9 @@ static void domain_update_iommu_coherency(struct dmar_domain *domain)
 {
 	int i;
 
-	domain->iommu_coherency = 1;
+	i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus);
+
+	domain->iommu_coherency = i < g_num_of_iommus ? 1 : 0;
 
 	for_each_set_bit(i, &domain->iommu_bmp, g_num_of_iommus) {
 		if (!ecap_coherent(g_iommus[i]->ecap)) {


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2011-11-15  5:55 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-11 22:49 [PATCH] intel-iommu: Default to non-coherent for domains unattached to iommus Alex Williamson
2011-11-12  0:17 ` Chris Wright
2011-11-12  0:37 ` David Woodhouse
2011-11-12  0:45   ` Chris Wright
2011-11-12  0:47     ` Chris Wright
2011-11-12  0:51     ` David Woodhouse
2011-11-12  0:58       ` Chris Wright
2011-11-12  1:03         ` David Woodhouse
2011-11-12  0:46   ` Roland Dreier
2011-11-12  0:51     ` Chris Wright
2011-11-12  0:55       ` David Woodhouse
2011-11-12  1:08         ` Chris Wright
2011-11-12  1:20           ` David Woodhouse
2011-11-15  7:12             ` cody
2011-11-15  4:54               ` Chris Wright
2011-11-15  5:55                 ` Kai Huang
2011-11-12  1:30           ` Roland Dreier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox