aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Thierry <julien.thierry@arm.com>2018-10-19 10:36:31 +0100
committerWill Deacon <will.deacon@arm.com>2018-11-02 14:17:13 +0000
commitfdd26ecb4bc52ac7e06455d5ea2cf5ebf7d500bc (patch)
treef6b2a2ad48bf195a184baf28e57745b5bf030eda
parent29f4ec311fca8a13cb8360d18fb91de2d1c2c20f (diff)
downloadkvmtool-fdd26ecb4bc52ac7e06455d5ea2cf5ebf7d500bc.tar.gz
kvm-cpu: Pause vCPU in signal handler
Currently, the handling a pause signal only sets a state that will be checked at the begining of the CPU run loop. At the checking point the vCPU sends the notification that it is actually paused allowing the pause requester to confirm all vCPUs are paused. Receiving the pause signal during a KVM_RUN ioctl will make KVM exit to userspace. However, there is a small window between that check on cpu->paused and the execution of KVM_RUN where the signal has been received but the vCPU does not go back through the notification and starts KVM_RUN. Since there is no guarantee the vCPU will come back to userspace, the pause requester might deadlock. Perform the pause directly from the signal handler. This relies on a vCPU thread never receiving a pause signal while being pause, but such scenario would have caused a deadlock for the pause requester anyway. Signed-off-by: Julien Thierry <julien.thierry@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--kvm-cpu.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/kvm-cpu.c b/kvm-cpu.c
index 4107841c..7dec0889 100644
--- a/kvm-cpu.c
+++ b/kvm-cpu.c
@@ -51,7 +51,19 @@ static void kvm_cpu_signal_handler(int signum)
if (current_kvm_cpu && current_kvm_cpu->is_running)
current_kvm_cpu->is_running = false;
} else if (signum == SIGKVMPAUSE) {
+ if (current_kvm_cpu->paused)
+ die("Pause signaled for already paused CPU\n");
+
+ /* pause_lock is held by kvm__pause() */
current_kvm_cpu->paused = 1;
+
+ /*
+ * This is a blocking function and uses locks. It is safe
+ * to call it for this signal as a second pause event should
+ * not be send to this thread until it acquires and releases
+ * the pause_lock.
+ */
+ kvm__notify_paused();
}
/* For SIGKVMTASK cpu->task is already set */
@@ -148,9 +160,6 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
kvm_cpu__enable_singlestep(cpu);
while (cpu->is_running) {
- if (cpu->paused)
- kvm__notify_paused();
-
if (cpu->needs_nmi) {
kvm_cpu__arch_nmi(cpu);
cpu->needs_nmi = 0;