[PATCH 4/4] qemu-kvm: Unbreak guest debugging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Align handling of guest debug exits to upstream by moving it completely
to the arch section. This patch accounts for changed return codes in the
exit handling code.

Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 kvm.h             |    2 --
 qemu-kvm-x86.c    |   14 +++++++++++++-
 qemu-kvm.c        |   36 ++++++------------------------------
 target-i386/kvm.c |    2 +-
 4 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/kvm.h b/kvm.h
index bda6ad7..b890b5d 100644
--- a/kvm.h
+++ b/kvm.h
@@ -147,8 +147,6 @@ QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);
 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
                                                  target_ulong pc);
 
-int kvm_handle_debug(struct kvm_debug_exit_arch *arch_info);
-
 int kvm_sw_breakpoints_active(CPUState *env);
 
 int kvm_arch_insert_sw_breakpoint(CPUState *current_env,
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 96d2fa6..d37f217 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -183,6 +183,8 @@ int kvm_enable_vapic(CPUState *env, uint64_t vapic)
 
 #endif
 
+extern CPUState *kvm_debug_cpu_requested;
+
 int kvm_arch_run(CPUState *env)
 {
     int r = 0;
@@ -198,8 +200,18 @@ int kvm_arch_run(CPUState *env)
         r = kvm_handle_tpr_access(env);
         break;
 #endif
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+    case KVM_EXIT_DEBUG:
+        DPRINTF("kvm_exit_debug\n");
+        r = kvm_handle_debug(&run->debug.arch);
+        if (r == EXCP_DEBUG) {
+            kvm_debug_cpu_requested = env;
+            env->stopped = 1;
+        }
+        break;
+#endif /* KVM_CAP_SET_GUEST_DEBUG */
     default:
-        r = 1;
+        r = -1;
         break;
     }
 
diff --git a/qemu-kvm.c b/qemu-kvm.c
index d7d50f5..7689225 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -74,7 +74,7 @@ static int qemu_system_ready;
 pthread_t io_thread;
 static int io_thread_sigfd = -1;
 
-static CPUState *kvm_debug_cpu_requested;
+CPUState *kvm_debug_cpu_requested;
 
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
 /* The list of ioperm_data */
@@ -86,20 +86,6 @@ static QLIST_HEAD(, ioperm_data) ioperm_head;
 int kvm_abi = EXPECTED_KVM_API_VERSION;
 int kvm_page_size;
 
-#ifdef KVM_CAP_SET_GUEST_DEBUG
-static int kvm_debug(CPUState *env,
-                     struct kvm_debug_exit_arch *arch_info)
-{
-    int handle = kvm_handle_debug(arch_info);
-
-    if (handle) {
-        kvm_debug_cpu_requested = env;
-        env->stopped = 1;
-    }
-    return handle;
-}
-#endif
-
 static int handle_unhandled(uint64_t reason)
 {
     fprintf(stderr, "kvm: unhandled exit %" PRIx64 "\n", reason);
@@ -453,17 +439,6 @@ int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip)
 
 #endif
 
-static int handle_debug(CPUState *env)
-{
-#ifdef KVM_CAP_SET_GUEST_DEBUG
-    struct kvm_run *run = env->kvm_run;
-
-    return kvm_debug(env, &run->debug.arch);
-#else
-    return 0;
-#endif
-}
-
 int kvm_get_regs(CPUState *env, struct kvm_regs *regs)
 {
     return kvm_vcpu_ioctl(env, KVM_GET_REGS, regs);
@@ -623,9 +598,6 @@ int kvm_run(CPUState *env)
                                 run->io.count);
             r = 0;
             break;
-        case KVM_EXIT_DEBUG:
-            r = handle_debug(env);
-            break;
         case KVM_EXIT_MMIO:
             r = handle_mmio(env);
             break;
@@ -649,11 +621,15 @@ int kvm_run(CPUState *env)
             r = kvm_handle_internal_error(env, run);
 	    break;
         default:
-            if (kvm_arch_run(env)) {
+            r = kvm_arch_run(env);
+            if (r < 0) {
                 fprintf(stderr, "unhandled vm exit: 0x%x\n", run->exit_reason);
                 kvm_show_regs(env);
                 abort();
             }
+            if (r > 0) {
+                return r;
+            }
             break;
         }
     }
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index be6a356..a3587ed 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1768,7 +1768,7 @@ void kvm_arch_remove_all_hw_breakpoints(void)
 
 static CPUWatchpoint hw_watchpoint;
 
-int kvm_handle_debug(struct kvm_debug_exit_arch *arch_info)
+static int kvm_handle_debug(struct kvm_debug_exit_arch *arch_info)
 {
     int ret = 0;
     int n;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux