diff options
author | Julien Thierry <julien.thierry@arm.com> | 2018-10-19 10:36:30 +0100 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2018-11-02 14:17:13 +0000 |
commit | 29f4ec311fca8a13cb8360d18fb91de2d1c2c20f (patch) | |
tree | b9045a7ccd69163aa38de6a21bac504d8d177338 | |
parent | 66ba0baea8743e6ac7142367ca58bd76b6f79c7b (diff) | |
download | kvmtool-29f4ec311fca8a13cb8360d18fb91de2d1c2c20f.tar.gz |
kvm: Do not pause already paused vcpus
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>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | kvm-cpu.c | 4 | ||||
-rw-r--r-- | kvm.c | 5 |
2 files changed, 5 insertions, 4 deletions
@@ -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]; @@ -519,7 +521,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++; @@ -543,5 +545,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); } |