virtio-pci: fix virtio-net child refcount in transports
PATCH 1/1 virtio-pci: fix virtio-net child refcount in transports
From: Gonglei <[email protected]>
object_initialize() leaves the object with a refcount of 1. object_property_add_child() adds its own reference which is dropped again when the property is deleted.
The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
---
Stefan had post virtio-blk in commit c5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.
--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/virtio-pci.c +1 -0
@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object *obj)VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET );object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = {
Signature · 1 line
1.7.12.4
Hi,
CC'ing Stefan and qemu-stable@ for more attention. :)
Best regards,
-Gonglei
Quoted 43 lines
-----Original Message-----
From: Gonglei (Arei)
Sent: Thursday, September 04, 2014 7:42 PM
To: [email protected]
Cc: [email protected]; Huangweidong (C); Gonglei (Arei)
Subject: [PATCH] virtio-pci: fix virtio-net child refcount in transportsFrom: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +1
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object *obj)VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET );object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +object_unref (OBJECT (&dev->vdev)); }static const TypeInfo
virtio_net_pci_info= {
--
1.7.12.4
Quoted 6 lines · On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.
Quoted 7 lines
The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>
Aren't other virtio devices affected? what about virtio-scsi?
Quoted 22 lines
---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +1
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object *obj)VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET );object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = {Signature · 1 line
1.7.12.4
Hi,
Quoted 13 lines
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports
Quoted 9 lines · On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Quoted 7 lines
Quoted 4 lines
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>Aren't other virtio devices affected? what about virtio-scsi?
Maybe, but I haven't tested other virtio devices TBH. :)
Best regards,
-Gonglei
Quoted 24 lines
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object
Quoted 12 lines
---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +0
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object*obj)
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj)
Quoted 3 lines
hw/virtio/virtio-pci.c +0
-0VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET ); object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev),NULL);
Quoted 7 lines
hw/virtio/virtio-pci.c +1
-1+object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = { --1.7.12.4
Quoted 25 lines · On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +0
-0
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj) · line 1462
Quoted 7 lines
hw/virtio/virtio-pci.c +1
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object *obj)VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET );object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = {
You just copied my commit but didn't consider all the work I did before to make virtio-blk safe. Similar work is necessary for virtio-net.
Before it is okay to finalize the virtio-net (dev->vdev) object, you need to audit virtio-pci and virtio-net to make sure all resources and qdev properties are freed once and only once.
In the case of virtio-net, the qdev properties are duplicated so both virtio-net-pci and virtio-net point qdev properties at the same fields in virtio-net. For example, the "tx" string property will be double-freed with your patch.
You can use the alias properties that I introduced to avoid duplicating qdev properties for virtio-net.
Stefan
Hi,
Quoted 37 lines
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object
Quoted 25 lines · On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +0
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object*obj)
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj)
Quoted 3 lines
hw/virtio/virtio-pci.c +0
-0VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET ); object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev),NULL);
Quoted 3 lines
hw/virtio/virtio-pci.c +1
-0+object_unref (OBJECT (&dev->vdev)); }
Quoted 6 lines
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj) · line 1462
Quoted 1 line
hw/virtio/virtio-pci.c +0
-0static const TypeInfo virtio_net_pci_info = {You just copied my commit but didn't consider all the work I did before to make virtio-blk safe. Similar work is necessary for virtio-net.
Before it is okay to finalize the virtio-net (
dev->vdev) object,
Sorry? In my case the virtio-net object will not be finalized at present because its obj->ref is non-1 when we hot-unplug a virtio-net-pci device.
Quoted 3 lines
you need to audit virtio-pci and virtio-net to make sure all resources and qdev properties are freed once and only once.
Yes, indeed.
Quoted 5 lines
In the case of virtio-net, the qdev properties are duplicated so both virtio-net-pci and virtio-net point qdev properties at the same fields in virtio-net. For example, the "tx" string property will be double-freed with your patch.
OK. Got it!
Quoted 4 lines
You can use the alias properties that I introduced to avoid duplicating qdev properties for virtio-net.
Stefan
OK, Thanks for your point and suggestion! I will rework it more carefully next week.
Best regards,
-Gonglei
Quoted 41 lines · Gonglei
Hi,
Quoted 39 lines
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object
Quoted 25 lines · On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/virtio-pci.c +0
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object*obj)
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj)
Quoted 3 lines
hw/virtio/virtio-pci.c +0
-0VirtIONetPCI *dev =VIRTIO_NET_PCI (obj);object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_NET ); object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev),NULL);
Quoted 4 lines
hw/virtio/virtio-pci.c +1
-0+object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = {
Quoted 7 lines
Quoted 4 lines
You just copied my commit but didn't consider all the work I did before to make virtio-blk safe. Similar work is necessary for virtio-net.
Before it is okay to finalize the virtio-net (
dev->vdev) object,Sorry? In my case the virtio-net object will not be finalized at present because its
obj->refis non-1 when we hot-unplug a virtio-net-pci device.
"Before" refers to making virtio-pci/virtio-net fixes first and then object_unref() second. It does not mean "previously" here.
Quoted 51 lines
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports
Quoted 6 lines · Gonglei
Hi,
Quoted 4 lines
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports
On Thu, Sep 04, 2014 at 07:41:32PM +0800, [email protected]
Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 20 lines
From: Gonglei <[email protected]>
object_initialize()leaves the object with a refcount of 1.object_property_add_child()adds its own reference which is dropped again when the property is deleted.The upshot of this is that we always have a refcount >= 1. Upon hot unplug the virtio-net child is not finalized!
Drop our reference after the child property has been added to the parent.
Signed-off-by Gonglei <[email protected]>---
Stefan had post virtio-blk in commitc5d49db4, but virtio-net has the same problem. Maybe the other virtio devices have too.--- hw/virtio/virtio-pci.c | 1 + 1 file changed, 1 insertion(+)Quoted 8 lines
Quoted 8 lines
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object
Quoted 5 lines
hw/virtio/virtio-pci.c +0
-0@@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object*obj)
Quoted 2 lines
hw/virtio/virtio-pci.c +0
-0VirtIONetPCI *dev =VIRTIO_NET_PCI (obj); object_initialize(&dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_NET);Quoted 1 line
Quoted 1 line
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object · line 1458
Quoted 1 line
hw/virtio/virtio-pci.c +0
-0object_property_add_child(obj, "virtio-backend",
OBJECT(&dev->vdev),Quoted 9 lines
Quoted 9 lines
NULL);
hw/virtio/virtio-pci.c static void virtio_net_pci_instance_init(Object *obj) · line 1462
Quoted 4 lines
hw/virtio/virtio-pci.c +1
-0+object_unref (OBJECT (&dev->vdev)); }static const TypeInfo virtio_net_pci_info = {You just copied my commit but didn't consider all the work I did before to make virtio-blk safe. Similar work is necessary for virtio-net.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Before it is okay to finalize the virtio-net (
dev->vdev) object,Sorry? In my case the virtio-net object will not be finalized at present because its
obj->refis non-1 when we hot-unplug a virtio-net-pci device."Before" refers to making virtio-pci/virtio-net fixes first and then
object_unref()second. It does not mean "previously" here.
OK. Thanks. :)
Best regards,
-Gonglei