Skip to contentSkip to conversation

Add guest debug support for kvm booke

PATCH New Liu Yu 1 participant 1 message Jul 25, 2009

Subsystems (2)
lore
Share & tools
lore

Liu Yu

author
#0 lore raw

PATCH 1/1 Add guest debug support for kvm booke

---
 arch/powerpc/include/asm/kvm.h      |   20 +++++
 arch/powerpc/include/asm/kvm_host.h |   18 +++++
 arch/powerpc/include/asm/kvm_ppc.h  |    5 +
 arch/powerpc/kvm/booke.c            |  140 ++++++++++++++++++++++++++++++++++-
 arch/powerpc/kvm/e500.c             |    8 --
 arch/powerpc/kvm/powerpc.c          |    8 ++-
 6 files changed, 186 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm.h +20 -0
index bb2de6a..55d029f 100644
@@ -22,6 +22,9 @@
 
 #include <linux/types.h>
 
+/* Select powerpc specific features in <linux/kvm.h> */
+#define __KVM_HAVE_GUEST_DEBUG
+
 struct kvm_regs {
 	__u64 pc;
 	__u64 cr;
@@ -53,10 +56,27 @@ struct kvm_fpu {
 };
 
 struct kvm_debug_exit_arch {
+	__u32 exception;
+	__u32 pc;
+	__u32 status;
 };
 
+#define KVM_INST_GUESTGDB               0x44000022
+
+#define KVM_GUESTDBG_USE_SW_BP          0x00010000
+#define KVM_GUESTDBG_USE_HW_BP          0x00020000
+
+#define KVMPPC_DEBUG_NOTYPE             0x0
+#define KVMPPC_DEBUG_BREAKPOINT         0x1
+#define KVMPPC_DEBUG_WATCH_ACCESS       0x2
+#define KVMPPC_DEBUG_WATCH_WRITE        0x3
+
 /* for KVM_SET_GUEST_DEBUG */
 struct kvm_guest_debug_arch {
+	struct {
+		__u32 addr;
+		__u32 type;
+	} bp[6];
 };
 
 #endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/include/asm/kvm_host.h +18 -0
index 3625424..5bed55a 100644
@@ -108,9 +108,22 @@ struct kvmppc_exit_timing {
 struct kvm_arch {
 };
 
+struct kvmppc_debug_reg {
+	u32 dbcr0;
+	u32 iac[0];
+	u32 iac1;
+	u32 iac2;
+	u32 iac3;
+	u32 iac4;
+	u32 dac[0];
+	u32 dac1;
+	u32 dac2;
+};
+
 struct kvm_vcpu_arch {
 	u32 host_stack;
 	u32 host_pid;
+	u32 host_msr;
 
 	u64 fpr[32];
 	ulong gpr[32];
@@ -159,6 +172,10 @@ struct kvm_vcpu_arch {
 	u32 dbcr1;
 	u32 dbsr;
 
+	struct kvmppc_debug_reg dbg_reg;
+	struct kvmppc_debug_reg host_dbg_reg;
+	bool has_load_host_dbg;
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	struct kvmppc_exit_timing timing_exit;
 	struct kvmppc_exit_timing timing_last_enter;
@@ -186,6 +203,7 @@ struct kvm_vcpu_arch {
 
 	struct timer_list dec_timer;
 	unsigned long pending_exceptions;
+	struct kvm_guest_debug_arch dbg;
 };
 
 #endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/include/asm/kvm_ppc.h +5 -0
index 2c6ee34..4f3656b 100644
@@ -89,6 +89,11 @@ extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
 extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs);
 extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt);
 
+extern void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu);
+extern void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu);
+extern int kvmppc_core_set_guest_debug(struct kvm_vcpu *vcpu,
+                                       struct kvm_guest_debug *dbg);
+
 extern int kvmppc_booke_init(void);
 extern void kvmppc_booke_exit(void);
 
arch/powerpc/kvm/booke.c +136 -4

172 lines not on this page · raw message

arch/powerpc/kvm/e500.c +0 -8
index c075d94..bdb2870 100644
@@ -24,14 +24,6 @@
 #include "booke.h"
 #include "e500_tlb.h"
 
-void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
-{
-}
-
-void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
-{
-}
-
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 	kvmppc_e500_tlb_load(vcpu, cpu);
arch/powerpc/kvm/powerpc.c +7 -1
index 9057335..02d73e7 100644
@@ -221,18 +221,24 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
 
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+	if (unlikely(vcpu->guest_debug & KVM_GUESTDBG_ENABLE))
+		kvmppc_core_load_guest_debugstate(vcpu);
+
 	kvmppc_core_vcpu_load(vcpu, cpu);
 }
 
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
+	if (unlikely(vcpu->guest_debug & KVM_GUESTDBG_ENABLE))
+		kvmppc_core_load_host_debugstate(vcpu);
+
 	kvmppc_core_vcpu_put(vcpu);
 }
 
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
                                         struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+	return kvmppc_core_set_guest_debug(vcpu, dbg);
 }
 
 static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu,
Signature · 1 line
1.5.4