[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/8] Fix cpu_unlink_tb race
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH 2/8] Fix cpu_unlink_tb race |
Date: |
Fri, 25 Jun 2010 16:56:50 +0200 |
If a signal hit after the env->exit_request check but before cpu_exec
updated env->current_tb, cpu_unlink_tb called from the signal hander
will not unlink the current TB. This may leave us stuck in a guest loop
if no further unlink is invoked.
Fix this by reordering current_tb update and exit_request check,
additionally enforcing the correct order via a compiler barrier.
Signed-off-by: Jan Kiszka <address@hidden>
---
cpu-exec.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 525b3b4..5f88f3f 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -600,8 +600,9 @@ int cpu_exec(CPUState *env1)
TB, but before it is linked into a potentially
infinite loop and becomes env->current_tb. Avoid
starting execution if there is a pending interrupt. */
- if (!unlikely (env->exit_request)) {
- env->current_tb = tb;
+ env->current_tb = tb;
+ barrier();
+ if (likely(!env->exit_request)) {
tc_ptr = tb->tc_ptr;
/* execute the generated code */
#if defined(__sparc__) && !defined(CONFIG_SOLARIS)
@@ -610,7 +611,6 @@ int cpu_exec(CPUState *env1)
#define env cpu_single_env
#endif
next_tb = tcg_qemu_tb_exec(tc_ptr);
- env->current_tb = NULL;
if ((next_tb & 3) == 2) {
/* Instruction counter expired. */
int insns_left;
@@ -639,6 +639,7 @@ int cpu_exec(CPUState *env1)
}
}
}
+ env->current_tb = NULL;
/* reset soft MMU for next block (it can currently
only be set by a memory fault) */
} /* for(;;) */
--
1.7.1
- [Qemu-devel] [PATCH 0/8] Fix various IO-thread breakages, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 6/8] Drop redundant global cur_cpu variable, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 8/8] Rework debug exception processing for gdb use, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 3/8] Init qemu_system_cond, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 1/8] Introduce proper compiler barrier, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 2/8] Fix cpu_unlink_tb race,
Jan Kiszka <=
- [Qemu-devel] [PATCH 5/8] Fix qemu_wait_io_event processing in io-thread mode, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 4/8] Fix cpu_exit for tcp_cpu_exec, Jan Kiszka, 2010/06/25
- [Qemu-devel] [PATCH 7/8] Rename tcg_cpu_exec and tcg_has_work, Jan Kiszka, 2010/06/25
- [Qemu-devel] Re: [PATCH 0/8] Fix various IO-thread breakages, Paolo Bonzini, 2010/06/27
- [Qemu-devel] Re: [PATCH 0/8] Fix various IO-thread breakages, Marcelo Tosatti, 2010/06/28