From: Igor Mammedov <imammedo@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: QEMU <qemu-devel@nongnu.org>, Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] ivshmem: fix memory backend leak
Date: Thu, 1 Nov 2018 13:33:13 +0100 [thread overview]
Message-ID: <20181101133313.533f7834@redhat.com> (raw)
In-Reply-To: <CAJ+F1CKE56kB+RokaNBwy1zB=xEeo-UaXgqp2-poMsprzY9Osw@mail.gmail.com>
On Thu, 1 Nov 2018 15:02:04 +0400
Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> On Thu, Nov 1, 2018 at 2:53 PM Igor Mammedov <imammedo@redhat.com> wrote:
> >
> > object_new() returns a new backend with refcount == 1 and
> > then later object_property_add_child() increases refcount to 2
> > So when ivshmem is desroyed, the backend it has created isn't
> > destroyed along with it as children cleanup will bring
> > backend's refcount only to 1, which leaks backend including
> > resources it is using.
> >
> > Drop the original reference from object_new() once backend
> > is attached to its parent.
> >
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
>
> I would rather have the unref in finalize, but that is ok too.
I followed the pattern we use else where, i.e. drop reference
as soon as we set the parent (virtio-rng/cpus) within the same
scope as object_new().
There is no point in keeping reference until finalize time since
backend is kept alive as child and is destroyed well after all
nonexistent ivshmem::unrealize/finilize() are finished when generic
Object is being destroyed.
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> > ---
> > hw/misc/ivshmem.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> > index f88910e..ecfd10a 100644
> > --- a/hw/misc/ivshmem.c
> > +++ b/hw/misc/ivshmem.c
> > @@ -1279,6 +1279,7 @@ static void desugar_shm(IVShmemState *s)
> > object_property_set_bool(obj, true, "share", &error_abort);
> > object_property_add_child(OBJECT(s), "internal-shm-backend", obj,
> > &error_abort);
> > + object_unref(obj);
> > user_creatable_complete(obj, &error_abort);
> > s->hostmem = MEMORY_BACKEND(obj);
> > }
> > --
> > 2.7.4
> >
> >
>
>
next prev parent reply other threads:[~2018-11-01 12:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-01 10:44 [Qemu-devel] [PATCH] ivshmem: fix memory backend leak Igor Mammedov
2018-11-01 11:02 ` Marc-André Lureau
2018-11-01 12:33 ` Igor Mammedov [this message]
2018-11-05 15:55 ` Markus Armbruster
2018-11-01 14:27 ` Philippe Mathieu-Daudé
2018-11-01 15:22 ` Igor Mammedov
2018-11-06 12:34 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181101133313.533f7834@redhat.com \
--to=imammedo@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.