From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdFuD-0006j5-VX for qemu-devel@nongnu.org; Wed, 01 Apr 2015 06:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YdFu8-0000lH-ND for qemu-devel@nongnu.org; Wed, 01 Apr 2015 06:29:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60007) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdFu8-0000ky-Ic for qemu-devel@nongnu.org; Wed, 01 Apr 2015 06:29:48 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t31ATlkf024199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 1 Apr 2015 06:29:48 -0400 Received: from donizetti.redhat.com (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t31ATbYS032332 for ; Wed, 1 Apr 2015 06:29:46 -0400 From: Paolo Bonzini Date: Wed, 1 Apr 2015 12:29:36 +0200 Message-Id: <1427884177-4928-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1427884177-4928-1-git-send-email-pbonzini@redhat.com> References: <1427884177-4928-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 4/5] rcu: do not create thread in pthread_atfork callback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org If QEMU forks after the CPU threads have been created, qemu_mutex_lock_iothread will not be able to do qemu_cpu_kick_thread. There is no solution other than assuming that forks after the CPU threads have been created will end up in an exec. Forks before the CPU threads have been created (such as -daemonize) have to call rcu_after_fork manually. Notably, the oxygen theme for GTK+ forks and shows a "No such process" error without this patch. This patch can be reverted once the iothread loses the "kick the TCG thread" magic. User-mode emulation does not use the iothread, so it can also call rcu_after_fork. Reported by: Dr. David Alan Gilbert Tested by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- include/qemu/rcu.h | 1 + linux-user/syscall.c | 1 + os-posix.c | 2 ++ util/rcu.c | 7 +++---- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 506ab58..7df1e86 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -117,6 +117,7 @@ extern void synchronize_rcu(void); */ extern void rcu_register_thread(void); extern void rcu_unregister_thread(void); +extern void rcu_after_fork(void); struct rcu_head; typedef void RCUCBFunc(struct rcu_head *head); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4bd9543..1622ad6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4572,6 +4572,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, ret = fork(); if (ret == 0) { /* Child Process. */ + rcu_after_fork(); cpu_clone_regs(env, newsp); fork_end(1); /* There is a race condition here. The parent process could diff --git a/os-posix.c b/os-posix.c index ba091f1..e4da406 100644 --- a/os-posix.c +++ b/os-posix.c @@ -39,6 +39,7 @@ #include "sysemu/sysemu.h" #include "net/slirp.h" #include "qemu-options.h" +#include "qemu/rcu.h" #ifdef CONFIG_LINUX #include @@ -247,6 +248,7 @@ void os_daemonize(void) signal(SIGTSTP, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); + rcu_after_fork(); } } diff --git a/util/rcu.c b/util/rcu.c index 27802a4..7270151 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -311,19 +311,18 @@ static void rcu_init_unlock(void) { qemu_mutex_unlock(&rcu_gp_lock); } +#endif -static void rcu_init_child(void) +void rcu_after_fork(void) { - qemu_mutex_unlock(&rcu_gp_lock); memset(®istry, 0, sizeof(registry)); rcu_init_complete(); } -#endif static void __attribute__((__constructor__)) rcu_init(void) { #ifdef CONFIG_POSIX - pthread_atfork(rcu_init_lock, rcu_init_unlock, rcu_init_child); + pthread_atfork(rcu_init_lock, rcu_init_unlock, rcu_init_unlock); #endif rcu_init_complete(); } -- 2.3.4