Received: from eggs.gnu.org ([2001:4830:134:3::10]:34387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTp-0004CP-NB for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTl-0008EN-EX for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34434) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTl-0008Dr-84 for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:37 -0400 From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:42 +0200 Message-Id: <1475859483-32234-19-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 18/39] linux-user/syscall: extend lock around cpu-list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= From: Alex Benn=C3=A9e There is a potential race if several threads exit at once. To serialise the exits extend the lock above the initial checking of the CPU list. Signed-off-by: Alex Benn=C3=A9e Message-Id: <20160930213106.20186-11-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- linux-user/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0815f30..fa559be 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7476,13 +7476,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_l= ong arg1, break; } =20 + cpu_list_lock(); + if (CPU_NEXT(first_cpu)) { TaskState *ts; =20 - cpu_list_lock(); /* Remove the CPU from the list. */ QTAILQ_REMOVE(&cpus, cpu, node); + cpu_list_unlock(); + ts =3D cpu->opaque; if (ts->child_tidptr) { put_user_u32(0, ts->child_tidptr); @@ -7495,6 +7498,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, rcu_unregister_thread(); pthread_exit(NULL); } + + cpu_list_unlock(); #ifdef TARGET_GPROF _mcleanup(); #endif --=20 2.7.4