From: Joerg R. <joe...@am...> - 2008-02-14 16:58:41
|
This patch moves the parts of the VMX guest debug code which can be reused for SVM to the generic x86 code. Signed-off-by: Joerg Roedel <joe...@am...> --- arch/x86/kvm/svm.c | 3 ++- arch/x86/kvm/vmx.c | 26 +++++--------------------- arch/x86/kvm/x86.c | 28 ++++++++++++++++++++++++++-- include/asm-x86/kvm_host.h | 3 ++- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index e1d139f..094a9c2 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -916,7 +916,8 @@ static void svm_set_segment(struct kvm_vcpu *vcpu, */ -static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg) +static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg, + unsigned long dr7) { return -EOPNOTSUPP; } diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ea5915b..423dcab 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -858,28 +858,17 @@ static void vcpu_put_rsp_rip(struct kvm_vcpu *vcpu) vmcs_writel(GUEST_RIP, vcpu->arch.rip); } -static int set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg) +static int set_guest_debug(struct kvm_vcpu *vcpu, + struct kvm_debug_guest *dbg, + unsigned long dr7) { - unsigned long dr7 = 0x400; int old_singlestep; old_singlestep = vcpu->guest_debug.singlestep; - vcpu->guest_debug.enabled = dbg->enabled; - if (vcpu->guest_debug.enabled) { - int i; - - dr7 |= 0x200; /* exact */ - for (i = 0; i < 4; ++i) { - if (!dbg->breakpoints[i].enabled) - continue; - vcpu->guest_debug.bp[i] = dbg->breakpoints[i].address; - dr7 |= 2 << (i*2); /* global enable */ - dr7 |= 0 << (i*4+16); /* execution breakpoint */ - } - + if (vcpu->guest_debug.enabled) vcpu->guest_debug.singlestep = dbg->singlestep; - } else + else vcpu->guest_debug.singlestep = 0; if (old_singlestep && !vcpu->guest_debug.singlestep) { @@ -1868,11 +1857,6 @@ static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu) { struct kvm_guest_debug *dbg = &vcpu->guest_debug; - set_debugreg(dbg->bp[0], 0); - set_debugreg(dbg->bp[1], 1); - set_debugreg(dbg->bp[2], 2); - set_debugreg(dbg->bp[3], 3); - if (dbg->singlestep) { unsigned long flags; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0c910c7..f388d5d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2530,8 +2530,16 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) vapic_enter(vcpu); preempted: - if (vcpu->guest_debug.enabled) + if (vcpu->guest_debug.enabled) { + struct kvm_guest_debug *dbg = &vcpu->guest_debug; + + set_debugreg(dbg->bp[0], 0); + set_debugreg(dbg->bp[1], 1); + set_debugreg(dbg->bp[2], 2); + set_debugreg(dbg->bp[3], 3); + kvm_x86_ops->guest_debug_pre(vcpu); + } again: r = kvm_mmu_reload(vcpu); @@ -2928,11 +2936,27 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg) { + unsigned long dr7 = 0x400; int r; vcpu_load(vcpu); - r = kvm_x86_ops->set_guest_debug(vcpu, dbg); + vcpu->guest_debug.enabled = dbg->enabled; + + if (dbg->enabled) { + int i; + + dr7 |= 0x200; /* exact */ + for (i = 0; i < 4; ++i) { + if (!dbg->breakpoints[i].enabled) + continue; + vcpu->guest_debug.bp[i] = dbg->breakpoints[i].address; + dr7 |= 2 << (i*2); /* global enable */ + dr7 |= 0 << (i*4+16); /* execution breakpoint */ + } + } + + r = kvm_x86_ops->set_guest_debug(vcpu, dbg, dr7); vcpu_put(vcpu); diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h index da61255..43d0630 100644 --- a/include/asm-x86/kvm_host.h +++ b/include/asm-x86/kvm_host.h @@ -348,7 +348,8 @@ struct kvm_x86_ops { void (*vcpu_decache)(struct kvm_vcpu *vcpu); int (*set_guest_debug)(struct kvm_vcpu *vcpu, - struct kvm_debug_guest *dbg); + struct kvm_debug_guest *dbg, + unsigned long dr7); void (*guest_debug_pre)(struct kvm_vcpu *vcpu); int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata); int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); -- 1.5.3.7 |