[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 7/8] iommu: Don't crash if machine is not PC_MACHINE
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 7/8] iommu: Don't crash if machine is not PC_MACHINE |
Date: |
Tue, 9 May 2017 16:15:46 +0300 |
From: Eduardo Habkost <address@hidden>
Currently it's possible to crash QEMU using "-device *-iommu" and
"-machine none":
$ qemu-system-x86_64 -machine none -device amd-iommu
qemu/hw/i386/amd_iommu.c:1140:amdvi_realize: Object 0x55627dafbc90 is not an
instance of type generic-pc-machine
Aborted (core dumped)
$ qemu-system-x86_64 -machine none -device intel-iommu
qemu/hw/i386/intel_iommu.c:2972:vtd_realize: Object 0x56292ec0bc90 is not an
instance of type generic-pc-machine
Aborted (core dumped)
Fix amd-iommu and intel-iommu to ensure the current machine is really a
TYPE_PC_MACHINE instance at their realize methods.
Resulting error messages:
$ qemu-system-x86_64 -machine none -device amd-iommu
qemu-system-x86_64: -device amd-iommu: Machine-type 'none' not supported by
amd-iommu
$ qemu-system-x86_64 -machine none -device intel-iommu
qemu-system-x86_64: -device intel-iommu: Machine-type 'none' not supported by
intel-iommu
Signed-off-by: Eduardo Habkost <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/i386/amd_iommu.c | 15 ++++++++++++++-
hw/i386/intel_iommu.c | 14 ++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index f86a40a..516ebae 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -21,6 +21,7 @@
*/
#include "qemu/osdep.h"
#include "hw/i386/amd_iommu.h"
+#include "qapi/error.h"
#include "qemu/error-report.h"
#include "trace.h"
@@ -1137,7 +1138,19 @@ static void amdvi_realize(DeviceState *dev, Error **err)
int ret = 0;
AMDVIState *s = AMD_IOMMU_DEVICE(dev);
X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
- PCIBus *bus = PC_MACHINE(qdev_get_machine())->bus;
+ MachineState *ms = MACHINE(qdev_get_machine());
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+ PCMachineState *pcms =
+ PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));
+ PCIBus *bus;
+
+ if (!pcms) {
+ error_setg(err, "Machine-type '%s' not supported by amd-iommu",
+ mc->name);
+ return;
+ }
+
+ bus = pcms->bus;
s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,
amdvi_uint64_equal, g_free, g_free);
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 02f047c..a12b176 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2969,11 +2969,21 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error
**errp)
static void vtd_realize(DeviceState *dev, Error **errp)
{
- PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
- PCIBus *bus = pcms->bus;
+ MachineState *ms = MACHINE(qdev_get_machine());
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+ PCMachineState *pcms =
+ PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));
+ PCIBus *bus;
IntelIOMMUState *s = INTEL_IOMMU_DEVICE(dev);
X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
+ if (!pcms) {
+ error_setg(errp, "Machine-type '%s' not supported by intel-iommu",
+ mc->name);
+ return;
+ }
+
+ bus = pcms->bus;
VTD_DPRINTF(GENERAL, "");
x86_iommu->type = TYPE_INTEL;
--
MST
- [Qemu-devel] [PULL 0/8] pci, virtio, vhost: fixes, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 1/8] hw/acpi-defs: replace leading X with x_ in FADT field names, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 2/8] hw/arm/virt: generate 64-bit addressable ACPI objects, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 3/8] hw/virtio: fix vhost user fails to startup when MQ, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 5/8] pc/fwcfg: unbreak migration from qemu-2.5 and qemu-2.6 during firmware boot, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 4/8] libvhost-user: fix crash when rings aren't ready, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 7/8] iommu: Don't crash if machine is not PC_MACHINE,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 6/8] pc: add 2.10 machine type, Michael S. Tsirkin, 2017/05/09
- [Qemu-devel] [PULL 8/8] ACPI: don't call acpi_pcihp_device_plug_cb on xen, Michael S. Tsirkin, 2017/05/09
- Re: [Qemu-devel] [PULL 0/8] pci, virtio, vhost: fixes, no-reply, 2017/05/09
- Re: [Qemu-devel] [PULL 0/8] pci, virtio, vhost: fixes, Stefan Hajnoczi, 2017/05/10