[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 6/9] cpu: atomically modify cpu->exit_request
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v2 6/9] cpu: atomically modify cpu->exit_request |
Date: |
Thu, 22 Sep 2016 11:13:13 +0100 |
ThreadSanitizer picks up potential races although we already use
barriers to ensure things are in the correct order when processing exit
requests. For now we just use the relaxed atomic_set/atomic_read semantics
to reassure tsan that we can't tear the value.
Signed-off-by: Alex Bennée <address@hidden>
---
cpu-exec.c | 8 ++++----
qom/cpu.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 9f4bd0b..113d8dc 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -192,7 +192,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;
}
@@ -497,8 +497,8 @@ static inline void cpu_handle_interrupt(CPUState *cpu,
*last_tb = NULL;
}
}
- if (unlikely(cpu->exit_request || replay_has_interrupt())) {
- cpu->exit_request = 0;
+ if (unlikely(atomic_read(&cpu->exit_request) || replay_has_interrupt())) {
+ atomic_set(&cpu->exit_request, 0);
cpu->exception_index = EXCP_INTERRUPT;
cpu_loop_exit(cpu);
}
@@ -510,7 +510,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu,
TranslationBlock *tb,
{
uintptr_t ret;
- if (unlikely(cpu->exit_request)) {
+ if (unlikely(atomic_read(&cpu->exit_request))) {
return;
}
diff --git a/qom/cpu.c b/qom/cpu.c
index f783b5a..adc8c11 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -119,10 +119,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);
}
int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
--
2.9.3
- [Qemu-devel] [PATCH v2 0/9] A couple of fixes for ThreadSanitizer, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 2/9] tcg/optimize: move default return out of if statement, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 1/9] ui/vnc-enc-tight: remove switch and have single return, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 4/9] seqlock: use atomic writes for the sequence, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 6/9] cpu: atomically modify cpu->exit_request,
Alex Bennée <=
- [Qemu-devel] [PATCH v2 3/9] new: blacklist.tsan, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 8/9] qga/command: use QEMU atomic primitives, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 5/9] qom/object: update class cache atomically, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 9/9] .travis.yml: add gcc sanitizer build, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 7/9] util/qht: atomically set b->hashes, Alex Bennée, 2016/09/22
- Re: [Qemu-devel] [PATCH v2 0/9] A couple of fixes for ThreadSanitizer, Paolo Bonzini, 2016/09/30