958e1b
From bdd21901f9f1f10de38611d3b2b36e6e3d20fbd4 Mon Sep 17 00:00:00 2001
958e1b
From: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Date: Thu, 20 Nov 2014 10:33:14 +0100
958e1b
Subject: [PATCH 2/2] hw/pci: fixed hotplug crash when using rombar=0 with
958e1b
 devices having romfile
958e1b
958e1b
Message-id: <1416479594-22022-3-git-send-email-marcel.a@redhat.com>
958e1b
Patchwork-id: 62485
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 2/2] hw/pci: fixed hotplug crash when using rombar=0 with devices having romfile
958e1b
Bugzilla: 1046007
958e1b
RH-Acked-by: Amos Kong <akong@redhat.com>
958e1b
RH-Acked-by: Eric Blake <eblake@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
958e1b
Hot-plugging a device that has a romfile (either supplied by user
958e1b
or built-in) using rombar=0 option is a user error,
958e1b
do not allow the device to be hot-plugged.
958e1b
958e1b
Reviewed-by: Eric Blake <eblake@redhat.com>
958e1b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
(cherry picked from commit db80c7b974f4ccab56bd5e8ff2248c7339b00c73)
958e1b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/pci/pci.c | 9 +++++++++
958e1b
 1 file changed, 9 insertions(+)
958e1b
958e1b
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
958e1b
index 0918f4e..18773fe 100644
958e1b
--- a/hw/pci/pci.c
958e1b
+++ b/hw/pci/pci.c
958e1b
@@ -1924,6 +1924,15 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
958e1b
          * for 0.11 compatibility.
958e1b
          */
958e1b
         int class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);
958e1b
+
958e1b
+        /*
958e1b
+         * Hot-plugged devices can't use the option ROM
958e1b
+         * if the rom bar is disabled.
958e1b
+         */
958e1b
+        if (DEVICE(pdev)->hotplugged) {
958e1b
+            return -1;
958e1b
+        }
958e1b
+
958e1b
         if (class == 0x0300) {
958e1b
             rom_add_vga(pdev->romfile);
958e1b
         } else {
958e1b
-- 
958e1b
1.8.3.1
958e1b