@@ -148,10 +148,8 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
kvm_cpu__enable_singlestep(cpu);
while (cpu->is_running) {
- if (cpu->paused) {
+ if (cpu->paused)
kvm__notify_paused();
- cpu->paused = 0;
- }
if (cpu->needs_nmi) {
kvm_cpu__arch_nmi(cpu);
@@ -63,6 +63,8 @@ extern struct kvm_ext kvm_req_ext[];
static char kvm_dir[PATH_MAX];
+extern __thread struct kvm_cpu *current_kvm_cpu;
+
static int set_dir(const char *fmt, va_list args)
{
char tmp[PATH_MAX];
@@ -521,7 +523,7 @@ void kvm__pause(struct kvm *kvm)
if (pause_event < 0)
die("Failed creating pause notification event");
for (i = 0; i < kvm->nrcpus; i++) {
- if (kvm->cpus[i]->is_running)
+ if (kvm->cpus[i]->is_running && kvm->cpus[i]->paused == 0)
pthread_kill(kvm->cpus[i]->thread, SIGKVMPAUSE);
else
paused_vcpus++;
@@ -545,5 +547,6 @@ void kvm__notify_paused(void)
die("Failed notifying of paused VCPU.");
mutex_lock(&pause_lock);
+ current_kvm_cpu->paused = 0;
mutex_unlock(&pause_lock);
}
With the following sequence: kvm__pause(); kvm__continue(); kvm__pause(); There is a chance that not all paused threads have been resumed, and the second kvm__pause will attempt to pause them again. Since the paused thread is waiting to own the pause_lock, it won't write its second pause notification. kvm__pause will be waiting for that notification while owning pause_lock, so... deadlock. Simple solution is not to try to pause thread that had not the chance to resume. Signed-off-by: Julien Thierry <julien.thierry@arm.com> --- kvm-cpu.c | 4 +--- kvm.c | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-)