Commit 29f4ec31 authored by Julien Thierry's avatar Julien Thierry Committed by Will Deacon
Browse files

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: default avatarJulien Thierry <julien.thierry@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 66ba0bae
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment