Received: from eggs.gnu.org ([2001:4830:134:3::10]:52539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPsLQ-00011M-CC for qemu-devel@nongnu.org; Fri, 05 Sep 2014 08:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPsLK-00026C-Pb for qemu-devel@nongnu.org; Fri, 05 Sep 2014 08:10:24 -0400 Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:45056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPsLK-000268-Jr for qemu-devel@nongnu.org; Fri, 05 Sep 2014 08:10:18 -0400 Received: by mail-wi0-f174.google.com with SMTP id d1so704566wiv.7 for ; Fri, 05 Sep 2014 05:10:17 -0700 (PDT) Date: Fri, 5 Sep 2014 13:10:12 +0100 From: Stefan Hajnoczi Message-ID: <20140905121012.GD27649@stefanha-thinkpad.redhat.com> References: <1409830892-5056-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7DO5AaGCk89r4vaK" Content-Disposition: inline In-Reply-To: <1409830892-5056-1-git-send-email-arei.gonglei@huawei.com> Subject: Re: [Qemu-devel] [PATCH] virtio-pci: fix virtio-net child refcount in transports List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com Cc: weidong.huang@huawei.com, qemu-devel@nongnu.org, mst@redhat.com --7DO5AaGCk89r4vaK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 04, 2014 at 07:41:32PM +0800, arei.gonglei@huawei.com wrote: > From: Gonglei >=20 > 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. >=20 > The upshot of this is that we always have a refcount >=3D 1. Upon hot > unplug the virtio-net child is not finalized! >=20 > Drop our reference after the child property has been added to the > parent. >=20 > Signed-off-by: Gonglei > --- > Stefan had post virtio-blk in commit c5d49db4, but virtio-net has=20 > the same problem. Maybe the other virtio devices have too. > --- > hw/virtio/virtio-pci.c | 1 + > 1 file changed, 1 insertion(+) >=20 > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > index ddb5da1..78dcd68 100644 > --- a/hw/virtio/virtio-pci.c > +++ b/hw/virtio/virtio-pci.c > @@ -1456,6 +1456,7 @@ static void virtio_net_pci_instance_init(Object *ob= j) > VirtIONetPCI *dev =3D 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)); > } > =20 > static const TypeInfo virtio_net_pci_info =3D { 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 --7DO5AaGCk89r4vaK Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUCagkAAoJEJykq7OBq3PI5egIAJRfeMKI91n0Ownjgw0rjDBW AhqN+VjsY7/FfIo3XeCJqq1yvkgrAc1EXrG/cZBIcYrePFjNB8rtajcmtCeFuPAK s7Ouzn9MSBfizWLW0YFAJRaPmn2EIBURvLy0dIlXzC+s4jpYSfcE2Pfkz3ZdlefC 7clHswQwvbI7zQWaaWQ8w21ByN4A2h6Us2GRLvuGBN9BxaJjiGzrRM3iQeLFocqw x6/RnUzT8IC7BcVQYY4EZkqXMLvhza5VBn19xteUy4dTwQDeBtPRiXVDSgtqodWM wvU9ALhDW0sHX8H+YTSAU7zitnzeRJpnLCG53LQAyeKKb8fZ1za+2ggwjU/Rcr8= =+wuV -----END PGP SIGNATURE----- --7DO5AaGCk89r4vaK--