From e2b85efc82bc26a838f666c8282528ee38cf6377 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Tue, 16 Mar 2021 14:00:33 +0100
Subject: [PATCH 1/8] xen: when unplugging emulated devices skip virtio devices

Virtio devices should never be unplugged at boot time, as they are
similar to pci passthrough devices.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
 hw/i386/xen/xen_platform.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
index a64265cca0..39bbb12675 100644
--- a/hw/i386/xen/xen_platform.c
+++ b/hw/i386/xen/xen_platform.c
@@ -30,6 +30,7 @@
 #include "hw/pci/pci.h"
 #include "hw/xen/xen_common.h"
 #include "migration/vmstate.h"
+#include "hw/virtio/virtio-bus.h"
 #include "hw/xen/xen-legacy-backend.h"
 #include "trace.h"
 #include "sysemu/xen.h"
@@ -114,7 +115,8 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
     /* We have to ignore passthrough devices */
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET
-            && strcmp(d->name, "xen-pci-passthrough") != 0) {
+            && strcmp(d->name, "xen-pci-passthrough") != 0
+            && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
         object_unparent(OBJECT(d));
     }
 }
@@ -191,6 +193,11 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
         return;
     }
 
+    /* Ignore virtio devices */
+    if (qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
+        return;
+    }
+
     switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) {
     case PCI_CLASS_STORAGE_IDE:
         pci_xen_ide_unplug(DEVICE(d), aux);
-- 
2.25.1

