lkml.org 
[lkml]   [2022]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v9 14/17] KVM: x86/vmx: Clear Arch LBREn bit before inject #DB to guest
Date
On a debug breakpoint event (#DB), IA32_LBR_CTL.LBREn is cleared.
So need to clear the bit manually before inject #DB.

Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index d1eb1e149fea..e7969884d90e 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1617,6 +1617,27 @@ static void vmx_clear_hlt(struct kvm_vcpu *vcpu)
vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
}

+static void flip_arch_lbr_ctl(struct kvm_vcpu *vcpu, bool on)
+{
+ struct lbr_desc *lbr_desc = vcpu_to_lbr_desc(vcpu);
+ struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
+
+ if (kvm_cpu_cap_has(X86_FEATURE_ARCH_LBR) &&
+ test_bit(INTEL_PMC_IDX_FIXED_VLBR, pmu->pmc_in_use) &&
+ lbr_desc->event) {
+ u64 old = vmcs_read64(GUEST_IA32_LBR_CTL);
+ u64 new;
+
+ if (on)
+ new = old | ARCH_LBR_CTL_LBREN;
+ else
+ new = old & ~ARCH_LBR_CTL_LBREN;
+
+ if (old != new)
+ vmcs_write64(GUEST_IA32_LBR_CTL, new);
+ }
+}
+
static void vmx_queue_exception(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -1652,6 +1673,9 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu)
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info);

vmx_clear_hlt(vcpu);
+
+ if (nr == DB_VECTOR)
+ flip_arch_lbr_ctl(vcpu, false);
}

static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr,
@@ -4655,6 +4679,9 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR);

vmx_clear_hlt(vcpu);
+
+ if (vcpu->arch.exception.nr == DB_VECTOR)
+ flip_arch_lbr_ctl(vcpu, false);
}

bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu)
--
2.27.0
\
 
 \ /
  Last update: 2022-02-16 11:28    [W:0.558 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site