Skip to contentSkip to conversation

Fix virtio-*(-non)-transitional crash on 2.6 machine-types

PATCH Superseded Eduardo Habkost 6 participants 16 messages Jan 10, 2019 – Jan 11, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix virtio-*(-non)-transitional crash on 2.6 machine-types

This is a second attempt to fix the crash reported by Thomas[1].

This keeps the compat property array simple, different from my first attempt[2].

This also avoids extra complexity on the device code: we don't need interface name, inheritance tricks, or devices overriding a compat property after the fact. The simple absence of the QOM properties on some device types is enough to make the compat code skip them.

While working on the fix, I stumbled upon another minor bug in object_apply_global_props(), which I fixed in patch 1/3.

This series is based on my machine-next branch, because of conflicts with compat property array cleanups that are already queued.

[1] http://mid.mail-archive.com/[email protected]
[2] http://mid.mail-archive.com/[email protected]

Eduardo Habkost (3):
qom: Don't keep error value between object_property_parse() calls
globals: Allow global properties to be optional
virtio: Make disable-legacy/disable-modern compat properties optional

 include/hw/qdev-core.h | 3 +++
 hw/core/machine.c      | 5 +++--
 qom/object.c           | 6 ++++--
 3 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#1 lore raw

PATCH v2 1/3 qom: Don't keep error value between object_property_parse() calls

When handling errp==NULL at object_apply_global_props(), we are leaving the old error value in err after printing a warning. This makes QEMU crash if two global properties generate warnings:

  $ echo device_add rtl8139 | qemu-system-x86_64 -monitor stdio -global rtl8139.xxx=yyy -global rtl8139.xxx=zzz
  warning: can't apply global rtl8139.xxx=yyy: Property '.xxx' not found
  qemu-system-x86_64: util/error.c:57: error_setv: Assertion `*errp == NULL' failed.
  Aborted (core dumped)

Fix that by making err go out of scope immediately after the warn_report_err() call.

Fixes 50545b2cc029 "qdev-props: call object_apply_global_props()"
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +1 -1
index aa6f3a2a71..4e5226ca12 100644
@@ -372,7 +372,6 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
 
 void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
 {
-    Error *err = NULL;
     int i;
 
     if (!props) {
@@ -381,6 +380,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
 
     for (i = 0; i < props->len; i++) {
         GlobalProperty *p = g_ptr_array_index(props, i);
+        Error *err = NULL;
 
         if (object_dynamic_cast(obj, p->driver) == NULL) {
             continue;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Reviewed-by on v2 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qom: Don't keep error value between object_property_parse() calls

Quoted 23 lines · Eduardo Habkost

When handling errp==NULL at object_apply_global_props(), we are leaving the old error value in err after printing a warning. This makes QEMU crash if two global properties generate warnings:

  $ echo device_add rtl8139 | qemu-system-x86_64 -monitor stdio -global rtl8139.xxx=yyy -global rtl8139.xxx=zzz
  warning: can't apply global rtl8139.xxx=yyy: Property '.xxx' not found
  qemu-system-x86_64: util/error.c:57: error_setv: Assertion `*errp == NULL' failed.
  Aborted (core dumped)

Fix that by making err go out of scope immediately after the warn_report_err() call.

Fixes 50545b2cc029 "qdev-props: call object_apply_global_props()"
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +0 -0
index aa6f3a2a71..4e5226ca12 100644

qom/object.c static void object_post_init_with_type(Object *obj, TypeImpl *ti) · line 375

Quoted 4 lines
qom/object.c +0 -1
@@ -372,7 +372,6 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
 
 void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
 {
-    Error *err = NULL;

Could also have been fixed by leaving this line at this scope,...

qom/object.c void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp · line 386

Quoted 12 lines
qom/object.c +1 -0
     int i;
 
     if (!props) {
@@ -381,6 +380,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
 
     for (i = 0; i < props->len; i++) {
         GlobalProperty *p = g_ptr_array_index(props, i);
+        Error *err = NULL;
 
         if (object_dynamic_cast(obj, p->driver) == NULL) {
             continue;

...and doing 'err = NULL;' after warn_report_err(). That is, it's not the going out of scope that fixes it per se, but the fact that you changed to resetting it to NULL on each loop invocation rather than leaving it pointing at freed memory. Whether you set to NULL by a tighter scope initializer or by an assignment doesn't matter, so no need to respin since your way works.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v2 1/3
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qom: Don't keep error value between object_property_parse() calls

In reply to Eduardo Habkost
Quoted 10 lines · Eduardo Habkost

When handling errp==NULL at object_apply_global_props(), we are leaving the old error value in err after printing a warning. This makes QEMU crash if two global properties generate warnings:

  $ echo device_add rtl8139 | qemu-system-x86_64 -monitor stdio -global rtl8139.xxx=yyy -global rtl8139.xxx=zzz
  warning: can't apply global rtl8139.xxx=yyy: Property '.xxx' not found
  qemu-system-x86_64: util/error.c:57: error_setv: Assertion `*errp == NULL' failed.
  Aborted (core dumped)
Quoted 5 lines

Fix that by making err go out of scope immediately after the warn_report_err() call.

Fixes 50545b2cc029 "qdev-props: call object_apply_global_props()"
Quoted 28 lines
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +1 -2
index aa6f3a2a71..4e5226ca12 100644
@@ -372,7 +372,6 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
 
 void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
 {
-    Error *err = NULL;
     int i;
 
     if (!props) {
@@ -381,6 +380,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
 
     for (i = 0; i < props->len; i++) {
         GlobalProperty *p = g_ptr_array_index(props, i);
+        Error *err = NULL;
 
         if (object_dynamic_cast(obj, p->driver) == NULL) {
             continue;
--

2.18.0.rc1.1.g3f1ff2140

Signature · 1 line
Marc-André Lureau
Reviewed-by on v2 1/3
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qom: Don't keep error value between object_property_parse() calls

In reply to Eduardo Habkost
Quoted 9 lines · On Thu, 10 Jan 2019 00:02:57 -0200 Eduardo Habkost <[email protected]> wrote:

When handling errp==NULL at object_apply_global_props(), we are leaving the old error value in err after printing a warning. This makes QEMU crash if two global properties generate warnings:

  $ echo device_add rtl8139 | qemu-system-x86_64 -monitor stdio -global rtl8139.xxx=yyy -global rtl8139.xxx=zzz
  warning: can't apply global rtl8139.xxx=yyy: Property '.xxx' not found
  qemu-system-x86_64: util/error.c:57: error_setv: Assertion `*errp == NULL' failed.
  Aborted (core dumped)
Quoted 8 lines

Fix that by making err go out of scope immediately after the warn_report_err() call.

Fixes 50545b2cc029 "qdev-props: call object_apply_global_props()"
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#5 lore raw

PATCH v2 2/3 globals: Allow global properties to be optional

In reply to Eduardo Habkost

Making some global properties optional will let us simplify compat code when a given property works on most (but not all) subclasses of a given type.

Device types will be able to opt out from optional compat properties by simply not registering those properties, or by making the property setter report an error.

---
Note: the "An error is fatal for non-hotplugged devices [...]" comment that appears in the diff scope is inaccurate, but I will fix that in a separate patch because I don't want this to get into the way of fixing the crash.

---
 include/hw/qdev-core.h | 3 +++
 qom/object.c           | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/qdev-core.h +3 -0
index bc014c1c9f..463e1ddb1e 100644
@@ -250,6 +250,8 @@ struct PropertyInfo {
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
+ * @optional: If set to true, errors when applying the property won't be
+ *            reported by object_apply_global_props().
  *
  * An error is fatal for non-hotplugged devices, when the global is applied.
  */
@@ -258,6 +260,7 @@ typedef struct GlobalProperty {
     const char *property;
     const char *value;
     bool used;
+    bool optional;
 } GlobalProperty;
 
 static inline void
qom/object.c +3 -1
index 4e5226ca12..226ddf0189 100644
@@ -387,7 +387,9 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
         }
         p->used = true;
         object_property_parse(obj, p->value, p->property, &err);
-        if (err != NULL) {
+        if (p->optional) {
+            error_free(err);
+        } else if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           p->driver, p->property, p->value);
             /*
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] globals: Allow global properties to be optional

Quoted 7 lines · On Thu, 10 Jan 2019 00:02:58 -0200 Eduardo Habkost <[email protected]> wrote:

Making some global properties optional will let us simplify compat code when a given property works on most (but not all) subclasses of a given type.

Device types will be able to opt out from optional compat properties by simply not registering those properties, or by making the property setter report an error.

I'm not sure whether we want to conflate "property does not exist" and "setter returns an error". I can see the value in "apply a setting if the property exists; if it doesn't exist, the setting is not applicable". But if you also allow the setter to return an error, you will not notice if you e.g. have been providing junk in the value and it errors out everywhere.

Quoted 48 lines

---
Note: the "An error is fatal for non-hotplugged devices [...]" comment that appears in the diff scope is inaccurate, but I will fix that in a separate patch because I don't want this to get into the way of fixing the crash.

---
 include/hw/qdev-core.h | 3 +++
 qom/object.c           | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/qdev-core.h +3 -0
index bc014c1c9f..463e1ddb1e 100644
@@ -250,6 +250,8 @@ struct PropertyInfo {
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
+ * @optional: If set to true, errors when applying the property won't be
+ *            reported by object_apply_global_props().
  *
  * An error is fatal for non-hotplugged devices, when the global is applied.
  */
@@ -258,6 +260,7 @@ typedef struct GlobalProperty {
     const char *property;
     const char *value;
     bool used;
+    bool optional;
 } GlobalProperty;
 
 static inline void
qom/object.c +3 -1
index 4e5226ca12..226ddf0189 100644
@@ -387,7 +387,9 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
         }
         p->used = true;
         object_property_parse(obj, p->value, p->property, &err);
-        if (err != NULL) {
+        if (p->optional) {
+            error_free(err);
+        } else if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           p->driver, p->property, p->value);
             /*
#7 lore raw

PATCH v2 3/3 virtio: Make disable-legacy/disable-modern compat properties optional

In reply to Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +3 -2
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },
 };
 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
 
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#8 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Hi

Quoted 26 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 8 lines
hw/core/machine.c +3 -2
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

Adding "optional" handling looks like it may hide some other errors.

Quoted 7 lines
hw/core/machine.c +0 -1
 };
 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
 
--

2.18.0.rc1.1.g3f1ff2140

Signature · 1 line
Marc-André Lureau
#9 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 41 lines · * Marc-André Lureau ([email protected]) wrote:

Hi

Quoted 26 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 8 lines
hw/core/machine.c +3 -2
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

Quoted 1 line

Adding "optional" handling looks like it may hide some other errors.

I think it would be OK if it only ignored the non-existent property errors (or better, tested for their existence and then skipped if they weren't there).

Dave

Quoted 11 lines
Quoted 7 lines
hw/core/machine.c +0 -1
 };
 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
 
--

2.18.0.rc1.1.g3f1ff2140

Signature · 1 line
Marc-André Lureau

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#10 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

In reply to Marc-André Lureau
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 2 lines

Adding "optional" handling looks like it may hide some other errors.

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

Signature · 1 line
Eduardo
#11 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 47 lines · Eduardo Habkost
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 1 line
Quoted 4 lines
Quoted 1 line

Adding "optional" handling looks like it may hide some other errors.

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

That's the more standard meaning of the word optional, isn't it?

Quoted 2 lines
Signature · 1 line
Eduardo
#12 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 48 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 47 lines · Eduardo Habkost
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Adding "optional" handling looks like it may hide some other errors.

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

That's the more standard meaning of the word optional, isn't it?

Well the word is a separate issue; 'optional' is probably a bad choice but that's less important than what it actually does.
I'd go for skip_if_missing which is explicit.

Dave

Quoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 
Eduardo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#13 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 51 lines · Dr. David Alan Gilbert
Quoted 50 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 49 lines · Eduardo Habkost
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 2 lines

Adding "optional" handling looks like it may hide some other errors.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

That's the more standard meaning of the word optional, isn't it?

Well the word is a separate issue; 'optional' is probably a bad choice but that's less important than what it actually does.
I'd go for skip_if_missing which is explicit.

I'm unsure about that. To me "optional" means "it can be missing" and carries the same information as "skip if missing".

What do others think?

Signature · 1 line
Eduardo
#14 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 58 lines · Eduardo Habkost
Quoted 56 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 47 lines · Eduardo Habkost
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 1 line
Quoted 4 lines
Quoted 1 line

Adding "optional" handling looks like it may hide some other errors.

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

That's the more standard meaning of the word optional, isn't it?

Quoted 8 lines
Quoted 3 lines

Well the word is a separate issue; 'optional' is probably a bad choice but that's less important than what it actually does.
I'd go for skip_if_missing which is explicit.

I'm unsure about that. To me "optional" means "it can be missing" and carries the same information as "skip if missing".

What do others think?

skip_if_missing is more explicit.

Signature · 1 line
Marc-André Lureau
#15 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] virtio: Make disable-legacy/disable-modern compat properties optional

Quoted 63 lines · On Fri, 11 Jan 2019 01:06:45 +0400 Marc-André Lureau…
Quoted 62 lines · Eduardo Habkost
Quoted 59 lines · Dr. David Alan Gilbert
Quoted 48 lines · * Michael S. Tsirkin ([email protected]) wrote:
Quoted 47 lines · Eduardo Habkost
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 27 lines · Eduardo Habkost

The disable-legacy and disable-modern properties apply only to some virtio-pci devices. Make those properties optional.

This fixes the crash introduced by commit f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices"):

  $ qemu-system-x86_64 -machine pc-i440fx-2.6 \
    -device virtio-net-pci-non-transitional
  Unexpected error in object_property_find() at qom/object.c:1092:
  qemu-system-x86_64: -device virtio-net-pci-non-transitional: can't apply \
  global virtio-pci.disable-modern=on: Property '.disable-modern' not found
  Aborted (core dumped)
Fixes f6e501a28ef9 ("virtio: Provide version-specific variants of virtio PCI devices")
---
 hw/core/machine.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/core/machine.c +0 -0
index 5530b71981..a19143aa44 100644
@@ -91,8 +91,9 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
 
Quoted 10 lines

hw/core/machine.c const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); · line 96

Quoted 7 lines
hw/core/machine.c +3 -2
 GlobalProperty hw_compat_2_6[] = {
     { "virtio-mmio", "format_transport_address", "off" },
-    { "virtio-pci", "disable-modern", "on" },
-    { "virtio-pci", "disable-legacy", "off" },
+    /* Optional because not all virtio-pci devices support legacy mode */
+    { "virtio-pci", "disable-modern", "on",  .optional = true },
+    { "virtio-pci", "disable-legacy", "off", .optional = true },  

Could the generic devices implement a specific interface instead? virtio-pci-generic?

This is the kind of complexity I wanted to avoid. We already have too many interface names for subsets of PCI and virtio devices.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Adding "optional" handling looks like it may hide some other errors.

What if we just make "optional" mean "skip if the property doesn't exist", as suggested by Cornelia and Dave?

That's the more standard meaning of the word optional, isn't it?

Well the word is a separate issue; 'optional' is probably a bad choice but that's less important than what it actually does.
I'd go for skip_if_missing which is explicit.

Quoted 6 lines
Quoted 4 lines

I'm unsure about that. To me "optional" means "it can be missing" and carries the same information as "skip if missing".

What do others think?

skip_if_missing is more explicit.

I'd slightly prefer optional, but skip_if_missing is fine.