[Devel] (no subject)

Konstantin Khorenko khorenko at virtuozzo.com
Fri Aug 5 08:01:01 PDT 2016


<1427933438-12782-4-git-send-email-namit at cs.technion.ac.il>
Subject: [PATCH RHEL7 COMMIT] ms/KVM: x86: DR0-DR3 are not clear on reset

The commit is pushed to "branch-rh7-3.10.0-327.22.2.vz7.16.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.22.2.vz7.16.2
------>
commit a5cfd73cd42c0313d840013c22761dad2cc52d64
Author: Nadav Amit <namit at cs.technion.ac.il>
Date:   Fri Aug 5 19:01:00 2016 +0400

    ms/KVM: x86: DR0-DR3 are not clear on reset
    
    =============================
    Patchset description:
    
    kvm: fixes for debug register updates
    
    A couple of mainstream backports to fix debug register updates on vcpu
    transitions to/from guest.
    
    Supposed to fix, in particular, occasional misses of hardware breakpoints:
    https://jira.sw.ru/browse/PSBM-50488
    
    Nadav Amit (1):
      KVM: x86: DR0-DR3 are not clear on reset
    
    Paolo Bonzini (1):
      KVM: x86: fix root cause for missed hardware breakpoints
    
    ===========================
    This patch description:
    
    DR0-DR3 are not cleared as they should during reset and when they are set from
    userspace.  It appears to be caused by c77fb5fe6f03 ("KVM: x86: Allow the guest
    to run with dirty debug registers").
    
    Force their reload on these situations.
    
    Signed-off-by: Nadav Amit <namit at cs.technion.ac.il>
    Message-Id: <1427933438-12782-4-git-send-email-namit at cs.technion.ac.il>
    Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
    (cherry picked from commit ae561edeb421fbc24f97df7af8607c14009c16b2)
    Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 arch/x86/include/asm/kvm_host.h |  1 +
 arch/x86/kvm/x86.c              | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f81eafd..ca7ef31 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -338,6 +338,7 @@ struct kvm_pmu_ops;
 enum {
 	KVM_DEBUGREG_BP_ENABLED = 1,
 	KVM_DEBUGREG_WONT_EXIT = 2,
+	KVM_DEBUGREG_RELOAD = 4,
 };
 
 /* Hyper-V SynIC timer */
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 146c34a..c906f88 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -804,6 +804,17 @@ unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_get_cr8);
 
+static void kvm_update_dr0123(struct kvm_vcpu *vcpu)
+{
+	int i;
+
+	if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
+		for (i = 0; i < KVM_NR_DB_REGS; i++)
+			vcpu->arch.eff_db[i] = vcpu->arch.db[i];
+		vcpu->arch.switch_db_regs |= KVM_DEBUGREG_RELOAD;
+	}
+}
+
 static void kvm_update_dr6(struct kvm_vcpu *vcpu)
 {
 	if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
@@ -3071,6 +3082,7 @@ static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,
 		return -EINVAL;
 
 	memcpy(vcpu->arch.db, dbgregs->db, sizeof(vcpu->arch.db));
+	kvm_update_dr0123(vcpu);
 	vcpu->arch.dr6 = dbgregs->dr6;
 	kvm_update_dr6(vcpu);
 	vcpu->arch.dr7 = dbgregs->dr7;
@@ -6486,6 +6498,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		set_debugreg(vcpu->arch.eff_db[2], 2);
 		set_debugreg(vcpu->arch.eff_db[3], 3);
 		set_debugreg(vcpu->arch.dr6, 6);
+		vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD;
 	}
 
 	trace_kvm_entry(vcpu->vcpu_id);
@@ -7279,6 +7292,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu)
 	kvm_clear_exception_queue(vcpu);
 
 	memset(vcpu->arch.db, 0, sizeof(vcpu->arch.db));
+	kvm_update_dr0123(vcpu);
 	vcpu->arch.dr6 = DR6_INIT;
 	kvm_update_dr6(vcpu);
 	vcpu->arch.dr7 = DR7_FIXED_1;


More information about the Devel mailing list