Skip to content

Commit

Permalink
tcg: synchronize exit_request and tcg_current_cpu accesses
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Sep 9, 2015
1 parent ab096a7 commit aed807c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 10 additions & 4 deletions cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit aed807c

Please sign in to comment.