qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] intel_iommu: check misordered init when realize
@ 2017-02-24  4:29 Peter Xu
  2017-02-24  5:07 ` Pankaj Gupta
  2017-02-28 14:42 ` Marcel Apfelbaum
  0 siblings, 2 replies; 19+ messages in thread
From: Peter Xu @ 2017-02-24  4:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: yi.l.liu, Marcel Apfelbaum, Jintack Lim,
	\  Michael S . Tsirkin \ , peterx, Alex Williamson

Intel vIOMMU devices are created with "-device" parameter, while here
actually we need to make sure the dmar device be created before other
PCI devices (like vfio-pci) so that we know iommu_fn will be setup
correctly before realizations of those PCI devices (it is sensible that
PCI device fetch these info during its realization). Now this ordering
yet cannot be achieved elsewhere, and devices will be created in the
order that user specified. That might be dangerous.

Here we add one more function to detect this kind of misordering issue,
then report to guest. Currently, the only known device that is affected
by this VT-d defect is the vfio-pci typed devices. So for now we just
check against it to make sure we are safe.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/intel_iommu.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 22d8226..b723ece 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2560,6 +2560,24 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
     return true;
 }
 
+/*
+ * TODO: we should have a better way to achieve the ordering rather
+ * than this misorder check explicitly against vfio-pci. After all, no
+ * one should be blamed for this, and vfio-pci did nothing wrong.
+ */
+static bool vtd_detected_misorder_init(Error **errp)
+{
+    Object *dev = object_resolve_path_type("", "vfio-pci", NULL);
+
+    if (dev) {
+        error_setg(errp, "Please specify \"intel-iommu\" before all the rest "
+                   "of the devices.");
+        return true;
+    }
+
+    return false;
+}
+
 static void vtd_realize(DeviceState *dev, Error **errp)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
@@ -2567,6 +2585,10 @@ static void vtd_realize(DeviceState *dev, Error **errp)
     IntelIOMMUState *s = INTEL_IOMMU_DEVICE(dev);
     X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
 
+    if (vtd_detected_misorder_init(errp)) {
+        return;
+    }
+
     VTD_DPRINTF(GENERAL, "");
     x86_iommu->type = TYPE_INTEL;
 
-- 
2.7.4

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

end of thread, other threads:[~2017-03-02  3:46 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-24  4:29 [Qemu-devel] [PATCH v2] intel_iommu: check misordered init when realize Peter Xu
2017-02-24  5:07 ` Pankaj Gupta
2017-02-24  5:50   ` Peter Xu
2017-02-24  6:35     ` Pankaj Gupta
2017-02-24  7:10       ` Peter Xu
2017-02-24  8:42         ` Pankaj Gupta
2017-02-28 14:42 ` Marcel Apfelbaum
2017-03-01  2:36   ` Peter Xu
2017-03-01  3:23     ` Michael S. Tsirkin
2017-03-01  4:14       ` Jason Wang
2017-03-01  7:03         ` Marcel Apfelbaum
2017-03-01  8:43           ` Jason Wang
2017-03-01  9:05             ` Marcel Apfelbaum
2017-03-01  9:18           ` Peter Xu
2017-03-01  9:29             ` Marcel Apfelbaum
2017-03-01  9:59               ` Peter Xu
2017-03-01 12:32                 ` Marcel Apfelbaum
2017-03-02  3:45                   ` Peter Xu
2017-03-02  3:39         ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).