Received: from eggs.gnu.org ([2001:4830:134:3::10]:53028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZflo-0005o6-Kc for qemu-devel@nongnu.org; Wed, 09 Sep 2015 09:50:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZfln-00035K-OB for qemu-devel@nongnu.org; Wed, 09 Sep 2015 09:50:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZflm-00034n-T0 for qemu-devel@nongnu.org; Wed, 09 Sep 2015 09:50:39 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 8E7198E690 for ; Wed, 9 Sep 2015 13:50:38 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-83.ams2.redhat.com [10.36.112.83]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t89DoEhx030571 for ; Wed, 9 Sep 2015 09:50:37 -0400 From: Paolo Bonzini Date: Wed, 9 Sep 2015 15:49:44 +0200 Message-Id: <1441806613-13775-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1441806613-13775-1-git-send-email-pbonzini@redhat.com> References: <1441806613-13775-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 14/43] tcg: synchronize exit_request and tcg_current_cpu accesses List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Synchronize the remaining pair of accesses in cpu_signal. These should be necessary on Windows as well, at least in theory. Probably SuspendProcess and ResumeProcess introduce some implicit memory barrier. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- cpu-exec.c | 2 +- cpus.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index e24c640..ef9d745 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -372,7 +372,7 @@ int cpu_exec(CPUState *cpu) atomic_mb_set(&tcg_current_cpu, cpu); rcu_read_lock(); - if (unlikely(exit_request)) { + if (unlikely(atomic_mb_read(&exit_request))) { cpu->exit_request = 1; } diff --git a/cpus.c b/cpus.c index 6cebb7a..dd2fc29 100644 --- a/cpus.c +++ b/cpus.c @@ -663,11 +663,15 @@ static void cpu_handle_guest_debug(CPUState *cpu) static void cpu_signal(int sig) { - CPUState *cpu = atomic_mb_read(&tcg_current_cpu); + CPUState *cpu; + /* Ensure whatever caused the exit has reached the CPU threads before + * writing exit_request. + */ + atomic_mb_set(&exit_request, 1); + cpu = atomic_mb_read(&tcg_current_cpu); if (cpu) { cpu_exit(cpu); } - exit_request = 1; } #ifdef CONFIG_LINUX @@ -1063,7 +1067,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } /* process any pending work */ - exit_request = 1; + atomic_mb_set(&exit_request, 1); while (1) { tcg_exec_all(); @@ -1441,7 +1445,9 @@ static void tcg_exec_all(void) break; } } - exit_request = 0; + + /* Pairs with smp_wmb in qemu_cpu_kick. */ + atomic_mb_set(&exit_request, 0); } void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg) -- 2.4.3