virtio-net: require that config size is initialized
PATCH 1/1 virtio-net: require that config size is initialized
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?
hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +4 -3
@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);
@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Signature · 1 line
MST
Hi,
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this config size is computed?
Quoted 39 lines · Michael S. Tsirkin
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Quoted 4 lines · KONRAD Frédéric
Hi,
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
And then this hack will break cross version migration.
Quoted 3 lines
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this
config size is computed?
OK, will you post such a patch?
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · KONRAD Frédéric
Hi,
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
And then this hack will break cross version migration.
Why?
virtio_net_set_config_size is called by each "proxy" devices no?
Quoted 6 lines
Quoted 4 lines
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this
config size is computed?OK, will you post such a patch?
The issue is as we said in the last thread, host_feature is part of the proxy.
And if we want to move it to the devices, we must have a kind of property forwarding mechanism.
Anthony said he had something about that.
Quoted 36 lines
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Quoted 11 lines · KONRAD Frédéric
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · KONRAD Frédéric
Hi,
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
And then this hack will break cross version migration.
Why?
virtio_net_set_config_sizeis called by each "proxy" devices no?
If it's called then there's no need for a default, so this patch should be fine.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this
config size is computed?OK, will you post such a patch?
The issue is as we said in the last thread,
host_featureis part of the proxy.
Maybe you could add documentation on how initialization works? If I could fiure it out I would maybe suggest some solutions.
Quoted 39 lines
And if we want to move it to the devices, we must have a kind of property forwarding mechanism.
Anthony said he had something about that.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · KONRAD Frédéric
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · KONRAD Frédéric
Hi,
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
And then this hack will break cross version migration.
Why?
virtio_net_set_config_sizeis called by each "proxy" devices no?If it's called then there's no need for a default, so this patch should be fine.
True but as I told you, we made this refactoring to be able to hot-plug VirtIODevice on a virtio-bus, so calling this function won't be possible.
But you are right this must be fixed.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this
config size is computed?OK, will you post such a patch?
The issue is as we said in the last thread,
host_featureis part of the proxy.Maybe you could add documentation on how initialization works? If I could fiure it out I would maybe suggest some solutions.
Yes, where do you think I can add this?
Quoted 40 lines
Quoted 40 lines
And if we want to move it to the devices, we must have a kind of property forwarding mechanism.
Anthony said he had something about that.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {
Quoted 9 lines · KONRAD Frédéric
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · KONRAD Frédéric
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · KONRAD Frédéric
Hi,
I think it is not a good idea, as we wanted to make VirtIODevice hot-pluggable for virtio-mmio.
And then this hack will break cross version migration.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Why?
virtio_net_set_config_sizeis called by each "proxy" devices no?If it's called then there's no need for a default, so this patch should be fine.
True but as I told you, we made this refactoring to be able to hot-plug VirtIODevice on a virtio-bus, so calling this function won't be possible.
Going in circles aren't we? If it's not called
it's a bug. If it's called default is not needed.
Quoted 6 lines
But you are right this must be fixed.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Maybe we can use a callback which is called by virtio-bus before plugging, to ensure that this
config size is computed?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
OK, will you post such a patch?
The issue is as we said in the last thread,
host_featureis part of the proxy.Maybe you could add documentation on how initialization works? If I could fiure it out I would maybe suggest some solutions.
Yes, where do you think I can add this?
Everywhere. Seriously.
Start with files. File headers should give some hint as to what's in here
* VirtioBus
in virtio-bus.h and virtio-bus.c is not helpful. How about
VirtioBus - a bus that drives from Newcastle to Edinburgh each Tuesday at noon. Drives back on Wednesdays mostly empty. It serves as a parent class for all the small taxi cars in both of these towns.
or some such.
Go over the interfaces and document what they do.
I mean more than just repeat the name:
/* Destroy the VirtIODevice */ void virtio_bus_destroy_device(VirtioBusState *bus)
is not really helpful.
/* Destroy a device. Assumes you don't have valuables in there. Calls 911 automatically. */
same for
/* Plug the VirtIODevice */
int virtio_bus_plug_device(VirtIODevice *vdev)
did you mean
/* Plug the device so the content does not spill. This way you can take put it on the bus. You must use a corkscrew to unplug it later. */
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
And if we want to move it to the devices, we must have a kind of property forwarding mechanism.
Anthony said he had something about that.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
All buses do this, and if they don't they get subtle bugs related to cross version migration. Let's add an assert to catch these bugs early.
Signed-off-by Michael S. Tsirkin <[email protected]>---
Just a cleanup so not 1.5 material.
Seems to work fine here - any opinions?hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/net/virtio-net.c +4
-3@@ -1282,6 +1282,8 @@ static int virtio_net_device_init(VirtIODevice *vdev)DeviceState *qdev =DEVICE (vdev);VirtIONet *n =VIRTIO_NET (vdev); +/* Verify that config size has been initialized */ +assert (n->config_size != (size_t )-1 );virtio_init (VIRTIO_DEVICE (n),"virtio-net" ,VIRTIO_ID_NET , n->config_size);@@ -1386,10 +1388,9 @@ static void virtio_net_instance_init(Object *obj)VirtIONet *n =VIRTIO_NET (obj);/* -* The default config_size is sizeof(struct virtio_net_config). -* Can be overriden with virtio_net_set_config_size. +* The config_size must be set later with virtio_net_set_config_size. */ - n->config_size =sizeof (struct virtio_net_config ); + n->config_size = (size_t )-1 ; }static Property virtio_net_properties[] = {