]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
KVM: x86: Wire-up hardware breakpoints for guest debugging
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 15 Dec 2008 12:52:10 +0000 (13:52 +0100)
committerAvi Kivity <avi@redhat.com>
Tue, 24 Mar 2009 09:02:50 +0000 (11:02 +0200)
Add the remaining bits to make use of debug registers also for guest
debugging, thus enabling the use of hardware breakpoints and
watchpoints.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c

index 815f50e425ac31a0181bc54f8086d3ba5d893fe2..b3a7a314d55c543124639e403bd4784522d99a58 100644 (file)
@@ -958,6 +958,11 @@ static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
        } else
                vcpu->guest_debug = 0;
 
+       if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
+               svm->vmcb->save.dr7 = dbg->arch.debugreg[7];
+       else
+               svm->vmcb->save.dr7 = vcpu->arch.dr7;
+
        if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
                svm->vmcb->save.rflags |= X86_EFLAGS_TF | X86_EFLAGS_RF;
        else if (old_debug & KVM_GUESTDBG_SINGLESTEP)
index 0989776ee7b050dd3ec000056552d782e17226f5..cee81c9a6653bd06b3fa20c13da9c962b25092b5 100644 (file)
@@ -1017,6 +1017,11 @@ static int set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
        if (!(vcpu->guest_debug & KVM_GUESTDBG_ENABLE))
                vcpu->guest_debug = 0;
 
+       if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
+               vmcs_writel(GUEST_DR7, dbg->arch.debugreg[7]);
+       else
+               vmcs_writel(GUEST_DR7, vcpu->arch.dr7);
+
        flags = vmcs_readl(GUEST_RFLAGS);
        if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
                flags |= X86_EFLAGS_TF | X86_EFLAGS_RF;
index 300bc4d42abc31172f3f1da0aca862c451ac2097..2477e87b2f84251e1576977b42e367ed217e2922 100644 (file)
@@ -3861,10 +3861,22 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
                                        struct kvm_guest_debug *dbg)
 {
-       int r;
+       int i, r;
 
        vcpu_load(vcpu);
 
+       if ((dbg->control & (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP)) ==
+           (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP)) {
+               for (i = 0; i < KVM_NR_DB_REGS; ++i)
+                       vcpu->arch.eff_db[i] = dbg->arch.debugreg[i];
+               vcpu->arch.switch_db_regs =
+                       (dbg->arch.debugreg[7] & DR7_BP_EN_MASK);
+       } else {
+               for (i = 0; i < KVM_NR_DB_REGS; i++)
+                       vcpu->arch.eff_db[i] = vcpu->arch.db[i];
+               vcpu->arch.switch_db_regs = (vcpu->arch.dr7 & DR7_BP_EN_MASK);
+       }
+
        r = kvm_x86_ops->set_guest_debug(vcpu, dbg);
 
        if (dbg->control & KVM_GUESTDBG_INJECT_DB)