Skip to contentSkip to conversation

virtio: link the rng backend through an alias property

PATCH Superseded Paolo Bonzini 2 participants 2 messages Oct 28, 2014 – Oct 29, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: link the rng backend through an alias property

The virtio-rng backend is currently linked twice, once in virtio-rng-pci/virtio-rng-ccw and once in virtio-rng-device. This causes a double unref of the backend when the parent device is unplugged.

To fix this, make virtio-rng-pci/virtio-rng-ccw use an alias, similar to what is already being done for the iothread link.

---
 hw/s390x/virtio-ccw.c  | 6 ++----
 hw/virtio/virtio-pci.c | 7 ++-----
 2 files changed, 4 insertions(+), 9 deletions(-)
hw/s390x/virtio-ccw.c +2 -4
index 1c0d913..ea236c9 100644
@@ -1544,10 +1544,8 @@ static void virtio_ccw_rng_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->vdev.conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
+    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
+                              "rng", &error_abort);
 }
 
 static Property virtio_ccw_rng_properties[] = {
hw/virtio/virtio-pci.c +2 -5
index 542fb9e..e490ade 100644
@@ -1525,11 +1525,8 @@ static void virtio_rng_initfn(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->vdev.conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
-
+    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng",
+                              &error_abort);
 }
 
 static const TypeInfo virtio_rng_pci_info = {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · Paolo Bonzini

The virtio-rng backend is currently linked twice, once in virtio-rng-pci/virtio-rng-ccw and once in virtio-rng-device. This causes a double unref of the backend when the parent device is unplugged.

To fix this, make virtio-rng-pci/virtio-rng-ccw use an alias, similar to what is already being done for the iothread link.

I think s390_virtio_rng should also use an alias for rng backend.

Best regards,
-Gonglei

Quoted 41 lines
---
 hw/s390x/virtio-ccw.c  | 6 ++----
 hw/virtio/virtio-pci.c | 7 ++-----
 2 files changed, 4 insertions(+), 9 deletions(-)
hw/s390x/virtio-ccw.c +2 -4
index 1c0d913..ea236c9 100644
@@ -1544,10 +1544,8 @@ static void virtio_ccw_rng_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->vdev.conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
+    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
+                              "rng", &error_abort);
 }
 
 static Property virtio_ccw_rng_properties[] = {
hw/virtio/virtio-pci.c +2 -5
index 542fb9e..e490ade 100644
@@ -1525,11 +1525,8 @@ static void virtio_rng_initfn(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->vdev.conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
-
+    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng",
+                              &error_abort);
 }
 
 static const TypeInfo virtio_rng_pci_info = {