All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: riku.voipio@iki.fi, imammedo@redhat.com
Cc: qemu-devel@nongnu.org, David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [RFC 1/2] linux-user: Don't leak cpus on thread exit
Date: Thu, 14 Jul 2016 17:57:04 +1000	[thread overview]
Message-ID: <1468483025-1084-2-git-send-email-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <1468483025-1084-1-git-send-email-david@gibson.dropbear.id.au>

Currently linux-user does not correctly clean up CPU instances properly
when running a threaded binary.

On thread exit, do_syscall() removes the thread's CPU from the cpus list
and calls object_unref().  However, the CPU still is still referenced from
the QOM tree.  To correctly clean up we need to object_unparent() to remove
the CPU from the QOM tree, then object_unref() to release the final
reference we're holding.

Once this is done, the explicit remove from the cpus list is no longer
necessary, since that's done automatically in the CPU unrealize path.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 linux-user/syscall.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

I believe most full system targets also "leak" cpus in the same way,
except that since they don't support cpu hot unplug the cpus never
would have been disposed anyway.  I'll look into fixing that another
time.

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8bf6205..dd91791 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6823,10 +6823,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         if (CPU_NEXT(first_cpu)) {
             TaskState *ts;
 
-            cpu_list_lock();
-            /* Remove the CPU from the list.  */
-            QTAILQ_REMOVE(&cpus, cpu, node);
-            cpu_list_unlock();
+            object_unparent(OBJECT(cpu)); /* Remove from QOM */
             ts = cpu->opaque;
             if (ts->child_tidptr) {
                 put_user_u32(0, ts->child_tidptr);
@@ -6834,7 +6831,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                           NULL, NULL, 0);
             }
             thread_cpu = NULL;
-            object_unref(OBJECT(cpu));
+            object_unref(OBJECT(cpu)); /* Remove the last ref we're holding */
             g_free(ts);
             rcu_unregister_thread();
             pthread_exit(NULL);
-- 
2.7.4

  reply	other threads:[~2016-07-14  7:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14  7:57 [Qemu-devel] [RFC 0/2] Fix some bugs in usermode cpu tracking David Gibson
2016-07-14  7:57 ` David Gibson [this message]
2016-07-14  9:52   ` [Qemu-devel] [RFC 1/2] linux-user: Don't leak cpus on thread exit Peter Maydell
2016-07-14 12:02     ` David Gibson
2016-07-14 13:05       ` Igor Mammedov
2016-07-15  2:53         ` David Gibson
2016-07-14  7:57 ` [Qemu-devel] [RFC 2/2] linux-user: Fix cpu_index generation David Gibson
2016-07-14  9:54   ` Peter Maydell
2016-07-14 10:20     ` Bharata B Rao
2016-07-14 11:59       ` David Gibson
2016-07-15 22:11         ` Greg Kurz
2016-07-18  1:17           ` David Gibson
2016-07-18  7:25             ` Igor Mammedov
2016-07-18  9:58               ` David Gibson
2016-07-18  8:52             ` Greg Kurz
2016-07-18  9:50               ` David Gibson

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=1468483025-1084-2-git-send-email-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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.