Received: from eggs.gnu.org ([208.118.235.92]:41598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQgwN-0006iw-99 for qemu-devel@nongnu.org; Fri, 12 Apr 2013 12:35:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQgwK-0007WD-32 for qemu-devel@nongnu.org; Fri, 12 Apr 2013 12:35:07 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:50185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQgwJ-0007UU-TX for qemu-devel@nongnu.org; Fri, 12 Apr 2013 12:35:04 -0400 From: Stefan Weil Date: Fri, 12 Apr 2013 18:34:44 +0200 Message-Id: <1365784486-617-3-git-send-email-sw@weilnetz.de> In-Reply-To: <1365784486-617-1-git-send-email-sw@weilnetz.de> References: <1365784486-617-1-git-send-email-sw@weilnetz.de> Subject: [Qemu-devel] [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Olivier Hainque , Stefan Weil , qemu-devel@nongnu.org, Fabien Chouteau From: Olivier Hainque The IO thread, when it senses cpu_single_env == 0, expects exit_request to be checked later on. A compiler scheduling constraint is not strong enough to ensure this on modern architecture. A memory fence is needed as well. Signed-off-by: Olivier Hainque Signed-off-by: Fabien Chouteau Reviewed-by: Paolo Bonzini Signed-off-by: Stefan Weil --- cpu-exec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpu-exec.c b/cpu-exec.c index e74e556..aa8fa89 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -217,6 +217,14 @@ int cpu_exec(CPUArchState *env) cpu_single_env = env; + /* As long as cpu_single_env is null, up to the assignment just above, + * requests by other threads to exit the execution loop are expected to + * be issued using the exit_request global. We must make sure that our + * evaluation of the global value is performed past the cpu_single_env + * value transition point, which requires a memory barrier as well as + * an instruction scheduling constraint on modern architectures. */ + smp_mb(); + if (unlikely(exit_request)) { cpu->exit_request = 1; } -- 1.7.10.4