Skip to contentSkip to conversation

virtio-pci: Improve device plugging whith legacy backends

PATCH In review Maxime Coquelin 4 participants 13 messages Sep 9, 2016 – Sep 12, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover virtio-pci: Improve device plugging whith legacy backends

This series makes device plugging more robust, to avoid guest to be confused when the backend doesn't support VIRTIO_F_VERSION_1.

The problem is seen with Linux guests running mainline kernels, when backend doesn't support the feature:
virtio_net virtio0: virtio: device uses modern interface but does not have VIRTIO_F_VERSION_1. When it happens, the modern device probe returns -EINVAL, whereas its caller expects -ENODEV being returned to switch to legacy device probing.

We need to make QEMU more robust to ensure the guest won't be confused, so this series exposes modern interface only when backend support it.

It has been tested with vhost-net and vhost-user backends in client and server modes.

Changes since v1:
-----------------
- Make the backend feature check function specialized to only VIRTIO_1

Maxime Coquelin (2):
virtio: Add function to check whether backend supports VIRTIO_1
virtio-pci: Disable modern interface if backend without
VIRTIO_F_VERSION_1

 hw/virtio/virtio-pci.c     | 15 +++++++++++++++
 hw/virtio/virtio-pci.h     |  5 +++++
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 4 files changed, 34 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 virtio: Add function to check whether backend supports VIRTIO_1

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +13 -0
index 74c085c..8b30b69 100644
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;
+
+    virtio_add_feature(&feature, VIRTIO_F_VERSION_1);
+
+    assert(k->get_features != NULL);
+    feature = k->get_features(vdev, feature, errp);
+
+    return virtio_has_feature(feature, VIRTIO_F_VERSION_1);
+}
+
 static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
include/hw/virtio/virtio.h +1 -0
index d2490c1..3a31754 100644
@@ -235,6 +235,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
Signature · 1 line
2.7.4
Reviewed-by on v2 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

Quoted 19 lines · Maxime Coquelin

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1488

Quoted 8 lines
hw/virtio/virtio.c +5 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;
+

I would set "feature = 0" even if doesn't really matter. Anyway:

Thanks,
Marcel

Quoted 24 lines
hw/virtio/virtio.c +8 -0
+    virtio_add_feature(&feature, VIRTIO_F_VERSION_1);
+
+    assert(k->get_features != NULL);
+    feature = k->get_features(vdev, feature, errp);
+
+    return virtio_has_feature(feature, VIRTIO_F_VERSION_1);
+}
+
 static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
include/hw/virtio/virtio.h +1 -0
index d2490c1..3a31754 100644
@@ -235,6 +235,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

Quoted 32 lines · Marcel Apfelbaum
Quoted 19 lines · Maxime Coquelin

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1488

Quoted 8 lines
hw/virtio/virtio.c +5 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;
+

I would set "feature = 0" even if doesn't really matter. Anyway:

Quoted 4 lines

Thanks,
Marcel

why wouldn't it matter? Looks like an uninitialized variable to me.

Quoted 24 lines
Quoted 24 lines
hw/virtio/virtio.c +8 -0
+    virtio_add_feature(&feature, VIRTIO_F_VERSION_1);
+
+    assert(k->get_features != NULL);
+    feature = k->get_features(vdev, feature, errp);
+
+    return virtio_has_feature(feature, VIRTIO_F_VERSION_1);
+}
+
 static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
include/hw/virtio/virtio.h +1 -0
index d2490c1..3a31754 100644
@@ -235,6 +235,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

Quoted 33 lines · Michael S. Tsirkin
Quoted 32 lines · Marcel Apfelbaum
Quoted 19 lines · Maxime Coquelin

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1488

Quoted 8 lines
hw/virtio/virtio.c +5 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;
+

I would set "feature = 0" even if doesn't really matter. Anyway:

Quoted 6 lines
Quoted 4 lines

Thanks,
Marcel

why wouldn't it matter? Looks like an uninitialized variable to me.

Oh yes, you are right, it should be initialized.
Just wait confirmation from Michael on the RFC before sending a v3.

Thanks,
Maxime

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
hw/virtio/virtio.c +8 -0
+    virtio_add_feature(&feature, VIRTIO_F_VERSION_1);
+
+    assert(k->get_features != NULL);
+    feature = k->get_features(vdev, feature, errp);
+
+    return virtio_has_feature(feature, VIRTIO_F_VERSION_1);
+}
+
 static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
include/hw/virtio/virtio.h +1 -0
index d2490c1..3a31754 100644
@@ -235,6 +235,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

In reply to Michael S. Tsirkin
Quoted 33 lines · Michael S. Tsirkin
Quoted 32 lines · Marcel Apfelbaum
Quoted 19 lines · Maxime Coquelin

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1488

Quoted 8 lines
hw/virtio/virtio.c +5 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;
+

I would set "feature = 0" even if doesn't really matter. Anyway:

Quoted 6 lines
Quoted 4 lines

Thanks,
Marcel

why wouldn't it matter? Looks like an uninitialized variable to me.

because it adds a flag, then it checks only if this specific flag is negotiated, but uninitialized variables are never a good idea.

Thanks,
Marcel

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
hw/virtio/virtio.c +8 -0
+    virtio_add_feature(&feature, VIRTIO_F_VERSION_1);
+
+    assert(k->get_features != NULL);
+    feature = k->get_features(vdev, feature, errp);
+
+    return virtio_has_feature(feature, VIRTIO_F_VERSION_1);
+}
+
 static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
include/hw/virtio/virtio.h +1 -0
index d2490c1..3a31754 100644
@@ -235,6 +235,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
Reviewed-by on v2 1/2
#6 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

In reply to Maxime Coquelin
Quoted 3 lines · On Fri, 9 Sep 2016 15:10:06 +0200 Maxime Coquelin…

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

s/negociation/negotiation/

Quoted 16 lines
Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1487

Quoted 7 lines
hw/virtio/virtio.c +4 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;

As others had requested, I'd prefer setting this to 0 as well.

With that changed:

#7 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

Quoted 35 lines · Cornelia Huck
Quoted 3 lines · On Fri, 9 Sep 2016 15:10:06 +0200 Maxime Coquelin…

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

s/negociation/negotiation/

Quoted 16 lines
Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1487

Quoted 7 lines
hw/virtio/virtio.c +4 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;

As others had requested, I'd prefer setting this to 0 as well.

Quoted 3 lines

With that changed:

Thanks Cornelia,
Note that if everyone agree to have patch adding pre_plugged, this series will not be needed anymore.

Regards,
Maxime

#8 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio: Add function to check whether backend supports VIRTIO_1

Quoted 40 lines · Maxime Coquelin
Quoted 37 lines · Cornelia Huck
Quoted 3 lines · On Fri, 9 Sep 2016 15:10:06 +0200 Maxime Coquelin…

This patch adds virtio_test_backend_virtio_1() function to check whether backend supports VIRTIO_F_VERSION_1 before the negociation takes place.

s/negociation/negotiation/

Quoted 16 lines
Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c         | 13 +++++++++++++
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 14 insertions(+)
hw/virtio/virtio.c +0 -0
index 74c085c..8b30b69 100644

hw/virtio/virtio.c void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size) · line 1487

Quoted 7 lines
hw/virtio/virtio.c +4 -0
@@ -1481,6 +1481,19 @@ void virtio_vmstate_save(QEMUFile *f, void *opaque, size_t size)
     virtio_save(VIRTIO_DEVICE(opaque), f);
 }
 
+bool virtio_test_backend_virtio_1(VirtIODevice *vdev, Error **errp)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t feature;

As others had requested, I'd prefer setting this to 0 as well.

With that changed:

Quoted 7 lines
Quoted 1 line

Thanks Cornelia,
Note that if everyone agree to have patch adding pre_plugged, this series will not be needed anymore.

Regards,
Maxime

Yes - that one needs testing for ccw and mmio.

Signature · 1 line
MST
#9 lore raw

PATCH v2 2/2 virtio-pci: Disable modern interface if backend without VIRTIO_F_VERSION_1

In reply to Maxime Coquelin

This patch makes pci devices plugging more robust, by not confusing guest with modern interface when the backend doesn't support VIRTIO_F_VERSION_1.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 15 +++++++++++++++
 hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 20 insertions(+)
hw/virtio/virtio-pci.c +15 -0
index 755f921..9e88d7b 100644
@@ -1581,6 +1581,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
     uint32_t size;
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
 
+    /*
+     * Virtio capabilities present without
+     * VIRTIO_F_VERSION_1 confuses guests
+     */
+    if (!virtio_test_backend_virtio_1(vdev, errp)) {
+        virtio_pci_disable_modern(proxy);
+    }
+
+    legacy = virtio_pci_legacy(proxy);
+    modern = virtio_pci_modern(proxy);
+    if (!legacy && !modern) {
+        error_setg(errp, "PCI device is neither legacy nor modern.");
+        return;
+    }
+
     config = proxy->pci_dev.config;
     if (proxy->class_code) {
         pci_config_set_class(config, proxy->class_code);
hw/virtio/virtio-pci.h +5 -0
index 25fbf8a..4e976b3 100644
@@ -172,6 +172,11 @@ static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
     proxy->disable_legacy = ON_OFF_AUTO_ON;
 }
 
+static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
+{
+    proxy->disable_modern = true;
+}
+
 /*
  * virtio-scsi-pci: This extends VirtioPCIProxy.
  */
Signature · 1 line
2.7.4
#10 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] virtio-pci: Disable modern interface if backend without VIRTIO_F_VERSION_1

Quoted 22 lines · Maxime Coquelin

This patch makes pci devices plugging more robust, by not confusing guest with modern interface when the backend doesn't support VIRTIO_F_VERSION_1.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 15 +++++++++++++++
 hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 20 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f921..9e88d7b 100644
@@ -1581,6 +1581,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
     uint32_t size;
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
 

hw/virtio/virtio-pci.c static void virtio_pci_device_plugged(DeviceState *d, Error **errp) · line 1593

Quoted 10 lines
hw/virtio/virtio-pci.c +10 -0
+    /*
+     * Virtio capabilities present without
+     * VIRTIO_F_VERSION_1 confuses guests
+     */
+    if (!virtio_test_backend_virtio_1(vdev, errp)) {
+        virtio_pci_disable_modern(proxy);
+    }
+
+    legacy = virtio_pci_legacy(proxy);
+    modern = virtio_pci_modern(proxy);

I think the first initialization of the
legacy/modern variables is not necessary anymore.

Other than that it looks good to me.

Thanks,
Marcel

Quoted 25 lines
hw/virtio/virtio-pci.c +5 -0
+    if (!legacy && !modern) {
+        error_setg(errp, "PCI device is neither legacy nor modern.");
+        return;
+    }
+
     config = proxy->pci_dev.config;
     if (proxy->class_code) {
         pci_config_set_class(config, proxy->class_code);
hw/virtio/virtio-pci.h +5 -0
index 25fbf8a..4e976b3 100644
@@ -172,6 +172,11 @@ static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
     proxy->disable_legacy = ON_OFF_AUTO_ON;
 }
 
+static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
+{
+    proxy->disable_modern = true;
+}
+
 /*
  * virtio-scsi-pci: This extends VirtioPCIProxy.
  */
#11 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] virtio-pci: Disable modern interface if backend without VIRTIO_F_VERSION_1

In reply to Maxime Coquelin
Quoted 27 lines · Maxime Coquelin

This patch makes pci devices plugging more robust, by not confusing guest with modern interface when the backend doesn't support VIRTIO_F_VERSION_1.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 15 +++++++++++++++
 hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 20 insertions(+)
hw/virtio/virtio-pci.c +5 -0
index 755f921..9e88d7b 100644
@@ -1581,6 +1581,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
     uint32_t size;
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
 
+    /*
+     * Virtio capabilities present without
+     * VIRTIO_F_VERSION_1 confuses guests
+     */
+    if (!virtio_test_backend_virtio_1(vdev, errp)) {

hw/virtio/virtio-pci.c static void virtio_pci_device_plugged(DeviceState *d, Error **errp) · line 1598

Quoted 10 lines
hw/virtio/virtio-pci.c +10 -0
+        virtio_pci_disable_modern(proxy);
+    }
+
+    legacy = virtio_pci_legacy(proxy);
+    modern = virtio_pci_modern(proxy);
+    if (!legacy && !modern) {
+        error_setg(errp, "PCI device is neither legacy nor modern.");
+        return;
+    }
+

How does this interact with
virtio-pci: error out when both legacy and modern modes are disabled
?
If it's the same, I'd rather pick that one and apply your
change on top.

Quoted 21 lines
hw/virtio/virtio-pci.c +0 -0
     config = proxy->pci_dev.config;
     if (proxy->class_code) {
         pci_config_set_class(config, proxy->class_code);
hw/virtio/virtio-pci.h +5 -0
index 25fbf8a..4e976b3 100644
@@ -172,6 +172,11 @@ static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
     proxy->disable_legacy = ON_OFF_AUTO_ON;
 }
 
+static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
+{
+    proxy->disable_modern = true;
+}
+
 /*
  * virtio-scsi-pci: This extends VirtioPCIProxy.
  */
Signature · 1 line
2.7.4
#12 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] virtio-pci: Disable modern interface if backend without VIRTIO_F_VERSION_1

Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Maxime Coquelin

This patch makes pci devices plugging more robust, by not confusing guest with modern interface when the backend doesn't support VIRTIO_F_VERSION_1.

Cc Cornelia Huck <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 15 +++++++++++++++
 hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 20 insertions(+)
hw/virtio/virtio-pci.c +13 -0
index 755f921..9e88d7b 100644
@@ -1581,6 +1581,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
     uint32_t size;
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
 
+    /*
+     * Virtio capabilities present without
+     * VIRTIO_F_VERSION_1 confuses guests
+     */
+    if (!virtio_test_backend_virtio_1(vdev, errp)) {
+        virtio_pci_disable_modern(proxy);
+    }
+
+    legacy = virtio_pci_legacy(proxy);
+    modern = virtio_pci_modern(proxy);
+    if (!legacy && !modern) {
+        error_setg(errp, "PCI device is neither legacy nor modern.");
+        return;
Quoted 8 lines

hw/virtio/virtio-pci.c static void virtio_pci_device_plugged(DeviceState *d, Error **errp) · line 1598

Quoted 2 lines
hw/virtio/virtio-pci.c +2 -0
+    }
+

How does this interact with
virtio-pci: error out when both legacy and modern modes are disabled
?
If it's the same, I'd rather pick that one and apply your
change on top.

Not exactly, since with my patch modern can be disabled after realize callback has been called.

But I will base my next revision on top of Greg's patch, and use the same pattern as he did use.

Thanks,
Maxime