@@ -425,14 +425,21 @@ static inline TranslationBlock *tb_find(CPUState *cpu,
return tb;
}
-static inline bool cpu_handle_halt(CPUState *cpu)
+static inline bool cpu_handle_halt_locked(CPUState *cpu)
{
- if (cpu->halted) {
+ g_assert(cpu_mutex_locked(cpu));
+
+ if (cpu_halted(cpu)) {
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
&& replay_interrupt()) {
X86CPU *x86_cpu = X86_CPU(cpu);
+
+ /* prevent deadlock; cpu_mutex must be acquired _after_ the BQL */
+ cpu_mutex_unlock(cpu);
qemu_mutex_lock_iothread();
+ cpu_mutex_lock(cpu);
+
apic_poll_irq(x86_cpu->apic_state);
cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL);
qemu_mutex_unlock_iothread();
@@ -442,12 +449,22 @@ static inline bool cpu_handle_halt(CPUState *cpu)
return true;
}
- cpu->halted = 0;
+ cpu_halted_set(cpu, 0);
}
return false;
}
+static inline bool cpu_handle_halt(CPUState *cpu)
+{
+ bool ret;
+
+ cpu_mutex_lock(cpu);
+ ret = cpu_handle_halt_locked(cpu);
+ cpu_mutex_unlock(cpu);
+ return ret;
+}
+
static inline void cpu_handle_debug_exception(CPUState *cpu)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
@@ -546,7 +563,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
} else if (interrupt_request & CPU_INTERRUPT_HALT) {
replay_interrupt();
cpu->interrupt_request &= ~CPU_INTERRUPT_HALT;
- cpu->halted = 1;
+ cpu_halted_set(cpu, 1);
cpu->exception_index = EXCP_HLT;
qemu_mutex_unlock_iothread();
return true;