[PATCH v2] KVM: x86: Only clear %dr6 if really neccessary

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

 



Change efdab992: "KVM: x86: fix escape of guest dr6 to the host"
has negative effects if Linux runs as the L1 guest in a nested
VM setup:

Each call to kvm_arch_vcpu_put causes an additional L1->L0 exit due
to the %dr6 write even if neither L1 nor L2 uses debug registers.
As the current hardware value of %dr6 is already in vcpu->arch.dr6
we can avoid the debug register write if all non-reserved bits have
their default value.

Update the comment and reformat it while there.

Signed-off-by: Christian Ehrhardt <lk@xxxxxxx>
---
 arch/x86/kvm/x86.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ca717737347e..fcca60adc037 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3185,11 +3185,13 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 	kvm_x86_ops->vcpu_put(vcpu);
 	vcpu->arch.last_host_tsc = rdtsc();
 	/*
-	 * If userspace has set any breakpoints or watchpoints, dr6 is restored
-	 * on every vmexit, but if not, we might have a stale dr6 from the
-	 * guest. do_debug expects dr6 to be cleared after it runs, do the same.
+	 * If userspace has set any breakpoints or watchpoints, dr6 is
+	 * restored on every vmexit, but if not, we might have a stale
+	 * dr6 from the guest. Thus reset the hardware value of dr6 to
+	 * its reset value. Avoid the debug register write if possible.
 	 */
-	set_debugreg(0, 6);
+	if (vcpu->arch.dr6 != DR6_INIT)
+		set_debugreg(DR6_INIT, 6);
 }
 
 static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu,
-- 
2.17.1




[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