Message ID | 20200522160755.886-12-robert.foley@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add Thread Sanitizer support to QEMU | expand |
On Fri, May 22, 2020 at 12:07:47 -0400, Robert Foley wrote: > Fixed several tsan warnings. e.g. > > WARNING: ThreadSanitizer: data race (pid=35425) > Read of size 1 at 0x557cd83aee28 by thread T7: > #0 curr_cflags include/exec/exec-all.h:460:13 (qemu-system-aarch64+0x4b7f27) > #1 cpu_exec accel/tcg/cpu-exec.c:730:26 (qemu-system-aarch64+0x4b7f27) > #2 tcg_cpu_exec cpus.c:1415:11 (qemu-system-aarch64+0x45b9b6) > #3 qemu_tcg_cpu_thread_fn cpus.c:1723:17 (qemu-system-aarch64+0x45b9b6) > #4 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) > > Previous write of size 1 at 0x557cd83aee28 by thread T6: > #0 cpu_exec_step_atomic accel/tcg/cpu-exec.c:254:23 (qemu-system-aarch64+0x4b6caa) > #1 qemu_tcg_cpu_thread_fn cpus.c:1741:17 (qemu-system-aarch64+0x45baca) > #2 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) > > Location is global 'parallel_cpus' of size 1 at 0x557cd83aee28 (qemu-system-aarch64+0x000001fb3e28) > > Cc: Richard Henderson <richard.henderson@linaro.org> > Cc: Paolo Bonzini <pbonzini@redhat.com> > Signed-off-by: Robert Foley <robert.foley@linaro.org> Reviewed-by: Emilio G. Cota <cota@braap.org> E.
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d95c4848a4..4cbdef1373 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -250,7 +250,7 @@ void cpu_exec_step_atomic(CPUState *cpu) } /* Since we got here, we know that parallel_cpus must be true. */ - parallel_cpus = false; + atomic_set(¶llel_cpus, false); cc->cpu_exec_enter(cpu); /* execute the generated code */ trace_exec_tb(tb, pc); @@ -278,7 +278,7 @@ void cpu_exec_step_atomic(CPUState *cpu) * the execution. */ g_assert(cpu_in_exclusive_context(cpu)); - parallel_cpus = true; + atomic_set(¶llel_cpus, true); end_exclusive(); } diff --git a/cpus.c b/cpus.c index af44027549..c5d04486a8 100644 --- a/cpus.c +++ b/cpus.c @@ -1966,7 +1966,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) if (qemu_tcg_mttcg_enabled()) { /* create a thread per vCPU with TCG (MTTCG) */ - parallel_cpus = true; + atomic_set(¶llel_cpus, true); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 3cf88272df..3f2c0290e1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -496,7 +496,7 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb) /* current cflags for hashing/comparison */ static inline uint32_t curr_cflags(void) { - return (parallel_cpus ? CF_PARALLEL : 0) + return (atomic_read(¶llel_cpus) ? CF_PARALLEL : 0) | (use_icount ? CF_USE_ICOUNT : 0); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff..8e39c09c5d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6022,8 +6022,8 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. */ - if (!parallel_cpus) { - parallel_cpus = true; + if (!atomic_read(¶llel_cpus)) { + atomic_set(¶llel_cpus, true); tb_flush(cpu); }
Fixed several tsan warnings. e.g. WARNING: ThreadSanitizer: data race (pid=35425) Read of size 1 at 0x557cd83aee28 by thread T7: #0 curr_cflags include/exec/exec-all.h:460:13 (qemu-system-aarch64+0x4b7f27) #1 cpu_exec accel/tcg/cpu-exec.c:730:26 (qemu-system-aarch64+0x4b7f27) #2 tcg_cpu_exec cpus.c:1415:11 (qemu-system-aarch64+0x45b9b6) #3 qemu_tcg_cpu_thread_fn cpus.c:1723:17 (qemu-system-aarch64+0x45b9b6) #4 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Previous write of size 1 at 0x557cd83aee28 by thread T6: #0 cpu_exec_step_atomic accel/tcg/cpu-exec.c:254:23 (qemu-system-aarch64+0x4b6caa) #1 qemu_tcg_cpu_thread_fn cpus.c:1741:17 (qemu-system-aarch64+0x45baca) #2 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Location is global 'parallel_cpus' of size 1 at 0x557cd83aee28 (qemu-system-aarch64+0x000001fb3e28) Cc: Richard Henderson <richard.henderson@linaro.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Robert Foley <robert.foley@linaro.org> --- accel/tcg/cpu-exec.c | 4 ++-- cpus.c | 2 +- include/exec/exec-all.h | 2 +- linux-user/syscall.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)