Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8a48342 authored by Avi Kivity's avatar Avi Kivity
Browse files

KVM: VMX: Conditionally reload debug register 6



Only reload debug register 6 if we're running with the guest's
debug registers.  Saves around 150 cycles from the guest lightweight
exit path.

dr6 contains a couple of bits that are updated on #DB, so intercept
that unconditionally and update those bits then.

Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent 3d53c27d
Loading
Loading
Loading
Loading
+9 −5
Original line number Original line Diff line number Diff line
@@ -540,10 +540,12 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)
	eb = (1u << PF_VECTOR) | (1u << UD_VECTOR) | (1u << MC_VECTOR);
	eb = (1u << PF_VECTOR) | (1u << UD_VECTOR) | (1u << MC_VECTOR);
	if (!vcpu->fpu_active)
	if (!vcpu->fpu_active)
		eb |= 1u << NM_VECTOR;
		eb |= 1u << NM_VECTOR;
	if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
	/*
		if (vcpu->guest_debug &
	 * Unconditionally intercept #DB so we can maintain dr6 without
		    (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
	 * reading it every exit.
	 */
	eb |= 1u << DB_VECTOR;
	eb |= 1u << DB_VECTOR;
	if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
			eb |= 1u << BP_VECTOR;
			eb |= 1u << BP_VECTOR;
	}
	}
@@ -3632,6 +3634,7 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
	 */
	 */
	vmcs_writel(HOST_CR0, read_cr0());
	vmcs_writel(HOST_CR0, read_cr0());


	if (vcpu->arch.switch_db_regs)
		set_debugreg(vcpu->arch.dr6, 6);
		set_debugreg(vcpu->arch.dr6, 6);


	asm(
	asm(
@@ -3734,6 +3737,7 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
				  | (1 << VCPU_EXREG_PDPTR));
				  | (1 << VCPU_EXREG_PDPTR));
	vcpu->arch.regs_dirty = 0;
	vcpu->arch.regs_dirty = 0;


	if (vcpu->arch.switch_db_regs)
		get_debugreg(vcpu->arch.dr6, 6);
		get_debugreg(vcpu->arch.dr6, 6);


	vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
	vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);