From d4cb954102cee0088829b990f0f841bb4d04ad71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 26 Feb 2018 05:11:14 -0500 Subject: [PATCH] cpu: atomically modify cpu->exit_request ThreadSanitizer picks up potential races although we already use barriers to ensure things are in the correct order when processing exit requests. For true C11 defined behaviour across threads we need to use relaxed atomic_set/atomic_read semantics to reassure tsan. Backports commit 027d9a7d2911e993cdcbd21c7c35d1dd058f05bb from qemu --- qemu/cpu-exec.c | 2 +- qemu/qom/cpu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index 2143433e..b9123115 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -78,7 +78,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) /* We were asked to stop executing TBs (probably a pending * interrupt. We've now stopped, so clear the flag. */ - cpu->tcg_exit_req = 0; + atomic_set(&cpu->tcg_exit_req, 0); } return ret; } diff --git a/qemu/qom/cpu.c b/qemu/qom/cpu.c index 3ac22786..98c09587 100644 --- a/qemu/qom/cpu.c +++ b/qemu/qom/cpu.c @@ -108,10 +108,10 @@ void cpu_reset_interrupt(CPUState *cpu, int mask) void cpu_exit(CPUState *cpu) { - cpu->exit_request = 1; + atomic_set(&cpu->exit_request, 1); /* Ensure cpu_exec will see the exit request after TCG has exited. */ smp_wmb(); - cpu->tcg_exit_req = 1; + atomic_set(&cpu->tcg_exit_req, 1); } static void cpu_common_noop(CPUState *cpu)