From 0394bb4ab4f39854eb061510a1494738b2c56ac8 Mon Sep 17 00:00:00 2001 From: Alex Williamson <alex.williamson@redhat.com> Date: Thu, 3 Mar 2011 19:08:01 -0300 Subject: [PATCH] device-assignment: Avoid segfault on hot-add with -no-kvm RH-Author: Alex Williamson <alex.williamson@redhat.com> Message-id: <1299179281.4177.137.camel@x201> Patchwork-id: 19395 O-Subject: [RHEL5.7 kvm PATCH] device-assignment: Avoid segfault on hot-add with -no-kvm Bugzilla: 644793 RH-Acked-by: Jiri Denemark <jdenemar@redhat.com> RH-Acked-by: Don Dutile <ddutile@redhat.com> RH-Acked-by: Michael S. Tsirkin <mst@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=644793 Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=3154901 Upstream: N/A (upstream fixed this with 420fe747, which depends on qdev) This is a RHEL5 specific patch since upstream has already fixed this via a similar assertion in the qdev path. I'm not sure the test case of running qemu-kvm with the -no-kvm option makes sense, but in this case the fix is trivial and the risk is low. Assigning devices on the commandline is already protected via a kvm_enabled() check, this just covers the hot plug case. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> --- qemu/hw/pci-hotplug.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c index d8a34c5..08ec769 100644 --- a/qemu/hw/pci-hotplug.c +++ b/qemu/hw/pci-hotplug.c @@ -32,6 +32,8 @@ #include "block_int.h" #include "virtio-blk.h" #include "device-assignment.h" +#include "kvm.h" +#include "qemu-kvm.h" #if defined(TARGET_I386) || defined(TARGET_X86_64) static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts) @@ -138,6 +140,11 @@ static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts) AssignedDevInfo *adev; PCIDevice *ret; + if (!kvm_enabled()) { + term_printf("Error: device assignment requires KVM support\n"); + return NULL; + } + adev = add_assigned_device(opts); if (adev == NULL) { term_printf ("Error adding device; check syntax\n"); -- 1.7.4.1.230.gae447