From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eh7aN-0005JO-Dm for qemu-devel@nongnu.org; Thu, 01 Feb 2018 00:39:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eh7aK-0000T3-Bc for qemu-devel@nongnu.org; Thu, 01 Feb 2018 00:38:59 -0500 Received: from spam.zju.edu.cn ([61.164.42.155]:62298 helo=zju.edu.cn) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eh7aJ-0000RB-NT for qemu-devel@nongnu.org; Thu, 01 Feb 2018 00:38:56 -0500 From: linzhecheng Date: Thu, 1 Feb 2018 13:38:43 +0800 Message-Id: <1517463523-21394-1-git-send-email-linzc@zju.edu.cn> Subject: [Qemu-devel] [PATCH] vcpu: join vcpu thread after it exiting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, crosthwaite.peter@gmail.com, rth@twiddle.net, linzhecheng , linzhecheng As we create vcpu thread with QEMU_THREAD_JOINABLE mode, we should join it after it exiting to cleanup resources. Signed-off-by: linzhecheng diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index f290f48..6ff71e4 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -282,9 +282,9 @@ err: static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) { - struct KVMParkedVcpu *cpu; + struct KVMParkedVcpu *cpu, *next_cpu; - QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) { + QLIST_FOREACH_SAFE(cpu, &s->kvm_parked_vcpus, node, *next_cpu) { if (cpu->vcpu_id == vcpu_id) { int kvm_fd; diff --git a/cpus.c b/cpus.c index 2cb0af9..1890bfe 100644 --- a/cpus.c +++ b/cpus.c @@ -1205,6 +1205,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) cpu->created = false; qemu_cond_signal(&qemu_cpu_cond); qemu_mutex_unlock_iothread(); + rcu_unregister_thread(); return NULL; } @@ -1759,6 +1760,7 @@ void cpu_remove_sync(CPUState *cpu) cpu_remove(cpu); while (cpu->created) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + qemu_thread_join(cpu->thread); } } -- 1.8.3.1