diff mbox series

[QEMU,v1,1/7] xen: when unplugging emulated devices skip virtio devices

Message ID 20231005181629.4046-2-vikram.garhwal@amd.com (mailing list archive)
State New, archived
Headers show
Series [QEMU,v1,1/7] xen: when unplugging emulated devices skip virtio devices | expand

Commit Message

Vikram Garhwal Oct. 5, 2023, 6:16 p.m. UTC
From: Juergen Gross <jgross@suse.com>

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>
Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
---
 hw/i386/xen/xen_platform.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Stefano Stabellini Oct. 9, 2023, 11:51 p.m. UTC | #1
On Thu, 5 Oct 2023, Vikram Garhwal wrote:
> From: Juergen Gross <jgross@suse.com>
> 
> 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>
> Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
> ---
>  hw/i386/xen/xen_platform.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
> index 17457ff3de..3560eaf8c8 100644
> --- a/hw/i386/xen/xen_platform.c
> +++ b/hw/i386/xen/xen_platform.c
> @@ -28,6 +28,7 @@
>  #include "hw/ide/pci.h"
>  #include "hw/pci/pci.h"
>  #include "migration/vmstate.h"
> +#include "hw/virtio/virtio-bus.h"
>  #include "net/net.h"
>  #include "trace.h"
>  #include "sysemu/xen.h"
> @@ -132,7 +133,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
> -            && !pci_device_is_passthrough(d)) {
> +            && !pci_device_is_passthrough(d)
> +            && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {

Please update the in-code comment above to say "ignore passthrough
devices and virtio devices"


>          object_unparent(OBJECT(d));
>      }
>  }
> @@ -208,6 +210,10 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
>      /* We have to ignore passthrough devices */
>      if (pci_device_is_passthrough(d))
>          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:
> -- 
> 2.17.1
>
Vikram Garhwal Oct. 10, 2023, 8:24 p.m. UTC | #2
Hi Stefano,
On Mon, Oct 09, 2023 at 04:51:53PM -0700, Stefano Stabellini wrote:
> On Thu, 5 Oct 2023, Vikram Garhwal wrote:
> > From: Juergen Gross <jgross@suse.com>
> > 
> > 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>
> > Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
> > ---
> >  hw/i386/xen/xen_platform.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
> > index 17457ff3de..3560eaf8c8 100644
> > --- a/hw/i386/xen/xen_platform.c
> > +++ b/hw/i386/xen/xen_platform.c
> > @@ -28,6 +28,7 @@
> >  #include "hw/ide/pci.h"
> >  #include "hw/pci/pci.h"
> >  #include "migration/vmstate.h"
> > +#include "hw/virtio/virtio-bus.h"
> >  #include "net/net.h"
> >  #include "trace.h"
> >  #include "sysemu/xen.h"
> > @@ -132,7 +133,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
> > -            && !pci_device_is_passthrough(d)) {
> > +            && !pci_device_is_passthrough(d)
> > +            && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
> 
> Please update the in-code comment above to say "ignore passthrough
> devices and virtio devices"
Sounds good. Will update in the code comment in v2.
> 
> 
> >          object_unparent(OBJECT(d));
> >      }
> >  }
> > @@ -208,6 +210,10 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
> >      /* We have to ignore passthrough devices */
> >      if (pci_device_is_passthrough(d))
> >          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:
> > -- 
> > 2.17.1
> >
David Woodhouse Oct. 19, 2023, 9:17 a.m. UTC | #3
On Tue, 2023-10-10 at 13:24 -0700, Vikram Garhwal wrote:
> Hi Stefano,
> On Mon, Oct 09, 2023 at 04:51:53PM -0700, Stefano Stabellini wrote:
> > On Thu, 5 Oct 2023, Vikram Garhwal wrote:
> > > From: Juergen Gross <jgross@suse.com>
> > > 
> > > 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>
> > > Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
> > > ---
> > >  hw/i386/xen/xen_platform.c | 8 +++++++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
> > > index 17457ff3de..3560eaf8c8 100644
> > > --- a/hw/i386/xen/xen_platform.c
> > > +++ b/hw/i386/xen/xen_platform.c
> > > @@ -28,6 +28,7 @@
> > >  #include "hw/ide/pci.h"
> > >  #include "hw/pci/pci.h"
> > >  #include "migration/vmstate.h"
> > > +#include "hw/virtio/virtio-bus.h"
> > >  #include "net/net.h"
> > >  #include "trace.h"
> > >  #include "sysemu/xen.h"
> > > @@ -132,7 +133,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
> > > -            && !pci_device_is_passthrough(d)) {
> > > +            && !pci_device_is_passthrough(d)
> > > +            && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
> > 
> > Please update the in-code comment above to say "ignore passthrough
> > devices and virtio devices"
>
> Sounds good. Will update in the code comment in v2.

Please could you also remove the note in docs/system/i386/xen.rst which
mentions having to dissuade the guest kernel from unplugging VirtIO
devices by adding 'xen_unplug_emul=never' to its command line?
diff mbox series

Patch

diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
index 17457ff3de..3560eaf8c8 100644
--- a/hw/i386/xen/xen_platform.c
+++ b/hw/i386/xen/xen_platform.c
@@ -28,6 +28,7 @@ 
 #include "hw/ide/pci.h"
 #include "hw/pci/pci.h"
 #include "migration/vmstate.h"
+#include "hw/virtio/virtio-bus.h"
 #include "net/net.h"
 #include "trace.h"
 #include "sysemu/xen.h"
@@ -132,7 +133,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
-            && !pci_device_is_passthrough(d)) {
+            && !pci_device_is_passthrough(d)
+            && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
         object_unparent(OBJECT(d));
     }
 }
@@ -208,6 +210,10 @@  static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
     /* We have to ignore passthrough devices */
     if (pci_device_is_passthrough(d))
         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: