qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <sw@weilnetz.de>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Olivier Hainque <hainque@adacore.com>,
	Stefan Weil <sw@weilnetz.de>,
	qemu-devel@nongnu.org, Fabien Chouteau <chouteau@adacore.com>
Subject: [Qemu-devel] [PATCH 2/4] Ensure good ordering of memory instruction in cpu_exec
Date: Fri, 12 Apr 2013 18:34:44 +0200	[thread overview]
Message-ID: <1365784486-617-3-git-send-email-sw@weilnetz.de> (raw)
In-Reply-To: <1365784486-617-1-git-send-email-sw@weilnetz.de>

From: Olivier Hainque <hainque@adacore.com>

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 <hainque@adacore.com>
Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 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

  parent reply	other threads:[~2013-04-12 16:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 16:34 [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 1/4] Check effective suspension of TCG thread Stefan Weil
2013-04-12 16:34 ` Stefan Weil [this message]
2013-04-12 16:34 ` [Qemu-devel] [PATCH 3/4] Release SMP restriction on Windows Stefan Weil
2013-04-12 16:34 ` [Qemu-devel] [PATCH 4/4] qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32 Stefan Weil
2013-04-13 12:34 ` [Qemu-devel] [PULL 0/4] MinGW patches for QEMU Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365784486-617-3-git-send-email-sw@weilnetz.de \
    --to=sw@weilnetz.de \
    --cc=aliguori@us.ibm.com \
    --cc=chouteau@adacore.com \
    --cc=hainque@adacore.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).