Synchronize the remaining pair of accesses in cpu_signal. The wrongly-ordered accesses in cpu_signal are currently not an issue on Windows because they execute atomically between SuspendProcess and ResumeProcess. Only cpu_exec can be split (and the newly introduced atomic_mb_read would be needed on Windows too, but the compiler must not be doing strange optimizations).
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- 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 2128bf1..b337506 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -409,7 +409,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 ec8168c..783ef00 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 @@ -1074,7 +1078,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(); @@ -1453,7 +1457,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