virtio-pci: fix missing device properties
PATCH 1/1 virtio-pci: fix missing device properties
Since commit a4ee4c8baa37154 ("virtio: Helper for registering virtio device types"), virtio-gpu-pci, virtio-vga, and virtio-crypto-pci lost some properties: "ioeventfd" and "vectors". This may cause various issues, such as failing migration or invalid properties.
Since those VirtioPCI devices do not have a base name, their class are initialized with virtio_pci_generic_base_class_init(). However, if the VirtioPCIDeviceTypeInfo provided a class_init which sets dc->props, the properties were overwritten by virtio_pci_generic_class_init().
Instead, introduce an intermediary base-type to register the generic properties.
--- hw/virtio/virtio-pci.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
hw/virtio/virtio-pci.c +14 -14
@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);
@@ -1938,14 +1931,13 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name =NULL ;TypeInfo base_type_info = { .name = t->base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init, .class_size = t->class_size, - .class_init = virtio_pci_base_class_init, - .class_data = (void *)t, .abstract = true, };TypeInfo generic_type_info = {
@@ -1961,13 +1953,20 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)if (!base_type_info.name) {/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces; - base_type_info.abstract = false; - generic_type_info.name =NULL ; +/* use intermediate %s-base-type to add generic device props */ + base_name =g_strdup_printf ("%s-base-type" , t->generic_name); + base_type_info.name = base_name; + base_type_info.class_init = virtio_pci_generic_class_init; + + generic_type_info.parent = base_name; + generic_type_info.class_init = virtio_pci_base_class_init; + generic_type_info.class_data = (void *)t; +assert (!t->non_transitional_name);assert (!t->transitional_name); + }else { + base_type_info.class_init = virtio_pci_base_class_init; + base_type_info.class_data = (void *)t; }type_register (&base_type_info);
@@ -2005,6 +2004,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) };type_register (&transitional_type_info); } +g_free (base_name); }/* virtio-pci-bus */
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
Quoted 61 lines · Marc-André Lureau
Since commit
a4ee4c8baa37154("virtio: Helper for registering virtio device types"), virtio-gpu-pci, virtio-vga, and virtio-crypto-pci lost some properties: "ioeventfd" and "vectors". This may cause various issues, such as failing migration or invalid properties.Since those VirtioPCI devices do not have a base name, their class are initialized with
virtio_pci_generic_base_class_init(). However, if the VirtioPCIDeviceTypeInfo provided aclass_initwhich setsdc->props, the properties were overwritten byvirtio_pci_generic_class_init().Instead, introduce an intermediary base-type to register the generic properties.
Fixes a4ee4c8baa37154f42b4dc6a13fee79268d15238Signed-off-by Marc-André Lureau <[email protected]>--- hw/virtio/virtio-pci.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)hw/virtio/virtio-pci.c +1
-12@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);@@ -1938,14 +1931,13 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name =NULL ;TypeInfo base_type_info = { .name = t->base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init, .class_size = t->class_size, - .class_init = virtio_pci_base_class_init, - .class_data = (void *)t, .abstract = true, };TypeInfo generic_type_info = {@@ -1961,13 +1953,20 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)if (!base_type_info.name) {/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces;
hw/virtio/virtio-pci.c void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) · line 1963
Quoted 10 lines
hw/virtio/virtio-pci.c +8
-2- base_type_info.abstract = false; - generic_type_info.name =NULL ; +/* use intermediate %s-base-type to add generic device props */ + base_name =g_strdup_printf ("%s-base-type" , t->generic_name); + base_type_info.name = base_name; + base_type_info.class_init = virtio_pci_generic_class_init; + + generic_type_info.parent = base_name; + generic_type_info.class_init = virtio_pci_base_class_init; + generic_type_info.class_data = (void *)t;
Why are you using virtio_pci_generic_class_init for the base class, and virtio_pci_base_class_init for the subclass, but doing exactly the opposite when t->base_name is set?
Isn't it simpler to just initialize base_type_info.name and leave all the rest alone? Patch below.
---
hw/virtio/virtio-pci.c +6 -22
@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);
@@ -1938,8 +1931,11 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name = t->base_name ? +NULL : +g_strdup_printf ("%s-base-type" , t->generic_name);TypeInfo base_type_info = { - .name = t->base_name, + .name = t->base_name ?: base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init,
@@ -1959,21 +1955,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) }, }; -if (!base_type_info.name) { -/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces; - base_type_info.abstract = false; - generic_type_info.name =NULL ; -assert (!t->non_transitional_name); -assert (!t->transitional_name); - } -type_register (&base_type_info); -if (generic_type_info.name) { -type_register (&generic_type_info); - } +type_register (&generic_type_info);if (t->non_transitional_name) {const TypeInfo non_transitional_type_info = {
@@ -2005,6 +1988,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) };type_register (&transitional_type_info); } +g_free (base_name); }/* virtio-pci-bus */
Signature · 1 line
Eduardo
Hi
Quoted 78 lines · Eduardo Habkost
Quoted 61 lines · Marc-André Lureau
Since commit
a4ee4c8baa37154("virtio: Helper for registering virtio device types"), virtio-gpu-pci, virtio-vga, and virtio-crypto-pci lost some properties: "ioeventfd" and "vectors". This may cause various issues, such as failing migration or invalid properties.Since those VirtioPCI devices do not have a base name, their class are initialized with
virtio_pci_generic_base_class_init(). However, if the VirtioPCIDeviceTypeInfo provided aclass_initwhich setsdc->props, the properties were overwritten byvirtio_pci_generic_class_init().Instead, introduce an intermediary base-type to register the generic properties.
Fixes a4ee4c8baa37154f42b4dc6a13fee79268d15238Signed-off-by Marc-André Lureau <[email protected]>--- hw/virtio/virtio-pci.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)hw/virtio/virtio-pci.c +1
-12@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);@@ -1938,14 +1931,13 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name =NULL ;TypeInfo base_type_info = { .name = t->base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init, .class_size = t->class_size, - .class_init = virtio_pci_base_class_init, - .class_data = (void *)t, .abstract = true, };TypeInfo generic_type_info = {@@ -1961,13 +1953,20 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)if (!base_type_info.name) {/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces;hw/virtio/virtio-pci.c void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) · line 1963
Quoted 10 lines
hw/virtio/virtio-pci.c +8
-2- base_type_info.abstract = false; - generic_type_info.name =NULL ; +/* use intermediate %s-base-type to add generic device props */ + base_name =g_strdup_printf ("%s-base-type" , t->generic_name); + base_type_info.name = base_name; + base_type_info.class_init = virtio_pci_generic_class_init; + + generic_type_info.parent = base_name; + generic_type_info.class_init = virtio_pci_base_class_init; + generic_type_info.class_data = (void *)t;Why are you using
virtio_pci_generic_class_initfor the base class, andvirtio_pci_base_class_initfor the subclass, but doing exactly the opposite whent->base_nameis set?
Quoted 2 lines
Isn't it simpler to just initialize base_type_info.name and leave all the rest alone? Patch below.
That was my initial approach. But then I tested the backport on v4.0.0, you get:
hw/display/virtio-vga.c:200:virtio_vga_class_init: Object 0x56247edbc0e0 is not an instance of type virtio-vga
The problem is that the introduced base class calls the t->class_init, which expects the final class (virtio-vga, not virtio-vga-base-type).
This seems to be limited to virtio-vga, and gone in upstream since the registration changed. But I would rather have the same patch reviewed/applied.
Quoted 44 lines
Signed-off-by Eduardo Habkost <[email protected]>---
hw/virtio/virtio-pci.c +4
-14@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);@@ -1938,8 +1931,11 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name = t->base_name ? +NULL : +g_strdup_printf ("%s-base-type" , t->generic_name);TypeInfo base_type_info = { - .name = t->base_name, + .name = t->base_name ?: base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init,@@ -1959,21 +1955,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) }, }; -if (!base_type_info.name) { -/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces; - base_type_info.abstract = false;
hw/virtio/virtio-pci.c void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) · line 1959
Quoted 10 lines
hw/virtio/virtio-pci.c +1
-8- generic_type_info.name =NULL ; -assert (!t->non_transitional_name); -assert (!t->transitional_name); - } -type_register (&base_type_info); -if (generic_type_info.name) { -type_register (&generic_type_info); - } +type_register (&generic_type_info);
t->generic_name can't be NULL anymore? I thought the condition was done for a good reason.
Quoted 16 lines
hw/virtio/virtio-pci.c +1
-1if (t->non_transitional_name) {const TypeInfo non_transitional_type_info = {@@ -2005,6 +1988,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) };type_register (&transitional_type_info); } +g_free (base_name); }/* virtio-pci-bus */ --Eduardo
Signature · 1 line
Marc-André Lureau
Eduardo Habkost
Reviewed-byQuoted 84 lines · Marc-André Lureau
Hi
Quoted 78 lines · Eduardo Habkost
Quoted 61 lines · Marc-André Lureau
Since commit
a4ee4c8baa37154("virtio: Helper for registering virtio device types"), virtio-gpu-pci, virtio-vga, and virtio-crypto-pci lost some properties: "ioeventfd" and "vectors". This may cause various issues, such as failing migration or invalid properties.Since those VirtioPCI devices do not have a base name, their class are initialized with
virtio_pci_generic_base_class_init(). However, if the VirtioPCIDeviceTypeInfo provided aclass_initwhich setsdc->props, the properties were overwritten byvirtio_pci_generic_class_init().Instead, introduce an intermediary base-type to register the generic properties.
Fixes a4ee4c8baa37154f42b4dc6a13fee79268d15238Signed-off-by Marc-André Lureau <[email protected]>--- hw/virtio/virtio-pci.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)hw/virtio/virtio-pci.c +1
-12@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);@@ -1938,14 +1931,13 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name =NULL ;TypeInfo base_type_info = { .name = t->base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init, .class_size = t->class_size, - .class_init = virtio_pci_base_class_init, - .class_data = (void *)t, .abstract = true, };TypeInfo generic_type_info = {@@ -1961,13 +1953,20 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)if (!base_type_info.name) {/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces;hw/virtio/virtio-pci.c void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) · line 1963
Quoted 10 lines
hw/virtio/virtio-pci.c +8
-2- base_type_info.abstract = false; - generic_type_info.name =NULL ; +/* use intermediate %s-base-type to add generic device props */ + base_name =g_strdup_printf ("%s-base-type" , t->generic_name); + base_type_info.name = base_name; + base_type_info.class_init = virtio_pci_generic_class_init; + + generic_type_info.parent = base_name; + generic_type_info.class_init = virtio_pci_base_class_init; + generic_type_info.class_data = (void *)t;Why are you using
virtio_pci_generic_class_initfor the base class, andvirtio_pci_base_class_initfor the subclass, but doing exactly the opposite whent->base_nameis set?Quoted 2 lines
Isn't it simpler to just initialize base_type_info.name and leave all the rest alone? Patch below.
Quoted 7 lines
That was my initial approach. But then I tested the backport on v4.0.0, you get:
hw/display/virtio-vga.c:200:virtio_vga_class_init: Object
0x56247edbc0e0is not an instance of type virtio-vgaThe problem is that the introduced base class calls the
t->class_init, which expects the final class (virtio-vga, not virtio-vga-base-type).
Ouch. In this case:
This would be much easier if we could append properties to dc->props. But this would be too complex for a 4.0-stable bug fix.
Quoted 55 lines
This seems to be limited to virtio-vga, and gone in upstream since the registration changed. But I would rather have the same patch reviewed/applied.
Quoted 49 lines
Signed-off-by Eduardo Habkost <[email protected]>---
hw/virtio/virtio-pci.c +4
-19@@ -1913,13 +1913,6 @@ static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) dc->props = virtio_pci_generic_properties; } -/* Used when the generic type and the base type is the same */ -static void virtio_pci_generic_base_class_init (ObjectClass *klass,void *data) -{ -virtio_pci_base_class_init (klass, data); -virtio_pci_generic_class_init (klass,NULL ); -} -static void virtio_pci_transitional_instance_init (Object *obj) {VirtIOPCIProxy *proxy =VIRTIO_PCI (obj);@@ -1938,8 +1931,11 @@ static void virtio_pci_non_transitional_instance_init(Object *obj)void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t) { +char *base_name = t->base_name ? +NULL : +g_strdup_printf ("%s-base-type" , t->generic_name);TypeInfo base_type_info = { - .name = t->base_name, + .name = t->base_name ?: base_name, .parent = t->parent ? t->parent :TYPE_VIRTIO_PCI , .instance_size = t->instance_size, .instance_init = t->instance_init,@@ -1959,21 +1955,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) }, }; -if (!base_type_info.name) { -/* No base type -> register a single generic device type */ - base_type_info.name = t->generic_name; - base_type_info.class_init = virtio_pci_generic_base_class_init; - base_type_info.interfaces = generic_type_info.interfaces; - base_type_info.abstract = false; - generic_type_info.name =NULL ; -assert (!t->non_transitional_name); -assert (!t->transitional_name); - } -
Quoted 8 lines
hw/virtio/virtio-pci.c void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) · line 1959
Quoted 5 lines
hw/virtio/virtio-pci.c +1
-3type_register (&base_type_info); -if (generic_type_info.name) { -type_register (&generic_type_info); - } +type_register (&generic_type_info);
t->generic_namecan't be NULL anymore? I thought the condition was done for a good reason.
My mistake. I forgot generic_type_info.name could be NULL because of t->generic_name was already NULL.
Quoted 21 lines
Quoted 17 lines
hw/virtio/virtio-pci.c +1
-1if (t->non_transitional_name) {const TypeInfo non_transitional_type_info = {@@ -2005,6 +1988,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) };type_register (&transitional_type_info); } +g_free (base_name); }/* virtio-pci-bus */ --Eduardo
Signature · 1 line
Marc-André Lureau
Signature · 1 line
Eduardo