]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Fix 'kill -3' hangs
authorPekka Enberg <penberg@kernel.org>
Sun, 8 May 2011 09:56:04 +0000 (12:56 +0300)
committerPekka Enberg <penberg@kernel.org>
Sun, 8 May 2011 09:56:04 +0000 (12:56 +0300)
Ingo Molnar reported that 'kill -3' didn't work on his machine:

  * Ingo Molnar <mingo@elte.hu> wrote:

  > This is really cumbersome to debug - is there some good way to get to the RIP
  > that the guest is hanging in? If kvm would print that out to the host console
  > (even if it's just the raw RIP initially) on a kill -3 that would help
  > enormously.

  Looks like the code should be doing that already - but the ioctl(KVM_GET_SREGS)
  hangs:

    [pid   748] ioctl(6, KVM_GET_SREGS

Avi Kivity pointed out that it's not safe to call KVM_GET_SREGS (or other vcpu
related ioctls) from other threads:

  > is it not OK to call KVM_GET_SREGS from other threads than the one
  > that's doing KVM_RUN?

  From Documentation/kvm/api.txt:

   - vcpu ioctls: These query and set attributes that control the operation
     of a single virtual cpu.

     Only run vcpu ioctls from the same thread that was used to create the
     vcpu.

Fix that up by using pthread_kill() to force the threads that are doing KVM_RUN
to do the register dumps.

Reported: Ingo Molnar <mingo@elte.hu>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm-run.c

index eb50b6a9636b32fcabd6eb12417005e0e564aca5..58e297781348b0933e49651eb9c725a83e7fa352 100644 (file)
@@ -127,6 +127,18 @@ static const struct option options[] = {
        OPT_END()
 };
 
+static void handle_sigusr1(int sig)
+{
+       struct kvm_cpu *cpu = current_kvm_cpu;
+
+       if (!cpu)
+               return;
+
+       kvm_cpu__show_registers(cpu);
+       kvm_cpu__show_code(cpu);
+       kvm_cpu__show_page_tables(cpu);
+}
+
 static void handle_sigquit(int sig)
 {
        int i;
@@ -134,9 +146,10 @@ static void handle_sigquit(int sig)
        for (i = 0; i < nrcpus; i++) {
                struct kvm_cpu *cpu = kvm_cpus[i];
 
-               kvm_cpu__show_registers(cpu);
-               kvm_cpu__show_code(cpu);
-               kvm_cpu__show_page_tables(cpu);
+               if (!cpu)
+                       continue;
+
+               pthread_kill(cpu->thread, SIGUSR1);
        }
 
        serial8250__inject_sysrq(kvm);
@@ -332,6 +345,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
        signal(SIGALRM, handle_sigalrm);
        signal(SIGQUIT, handle_sigquit);
+       signal(SIGUSR1, handle_sigusr1);
 
        while (argc != 0) {
                argc = parse_options(argc, argv, options, run_usage,