On Fri, Jul 9, 2021 at 2:51 AM Yang Weijiang <weijiang.yang@xxxxxxxxx> wrote: > > From: Like Xu <like.xu@xxxxxxxxxxxxxxx> > > Arch LBRs are enabled by setting MSR_ARCH_LBR_CTL.LBREn to 1. A new guest > state field named "Guest IA32_LBR_CTL" is added to enhance guest LBR usage. > When guest Arch LBR is enabled, a guest LBR event will be created like the > model-specific LBR does. Clear guest LBR enable bit on host PMI handling so > guest can see expected config. > > On processors that support Arch LBR, MSR_IA32_DEBUGCTLMSR[bit 0] has no > meaning. It can be written to 0 or 1, but reads will always return 0. > Like IA32_DEBUGCTL, IA32_ARCH_LBR_CTL msr is also reserved on INIT. I suspect you mean "preserved" rather than "reserved." > Signed-off-by: Like Xu <like.xu@xxxxxxxxxxxxxxx> > Signed-off-by: Yang Weijiang <weijiang.yang@xxxxxxxxx> > --- > arch/x86/events/intel/lbr.c | 2 -- > arch/x86/include/asm/msr-index.h | 1 + > arch/x86/include/asm/vmx.h | 2 ++ > arch/x86/kvm/vmx/pmu_intel.c | 31 ++++++++++++++++++++++++++----- > arch/x86/kvm/vmx/vmx.c | 9 +++++++++ > 5 files changed, 38 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index da68f0e74702..4500c564c63a 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -19,6 +19,11 @@ > #include "pmu.h" > > #define MSR_PMC_FULL_WIDTH_BIT (MSR_IA32_PMC0 - MSR_IA32_PERFCTR0) > +/* > + * Regardless of the Arch LBR or legacy LBR, when the LBR_EN bit 0 of the > + * corresponding control MSR is set to 1, LBR recording will be enabled. > + */ Is this comment misplaced? It doesn't seem to have anything to do with the macro being defined below. > @@ -458,6 +467,14 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > lbr_desc->records.nr = data; > lbr_desc->arch_lbr_reset = true; > return 0; > + case MSR_ARCH_LBR_CTL: > + if (data & ~KVM_ARCH_LBR_CTL_MASK) Is a static mask sufficient? Per the Intel® Architecture Instruction Set Extensions and Future Features Programming Reference, some of these bits may not be supported on all microarchitectures. See Table 7-8. CPUID Leaf 01CH Enumeration of Architectural LBR Capabilities. > + break; > + vmcs_write64(GUEST_IA32_LBR_CTL, data); > + if (intel_pmu_lbr_is_enabled(vcpu) && !lbr_desc->event && > + (data & ARCH_LBR_CTL_LBREN)) > + intel_pmu_create_guest_lbr_event(vcpu); Nothing has to be done when the LBREN bit goes from 1 to 0? > + return 0; > default: > if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) || > (pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) { Per the Intel® Architecture Instruction Set Extensions and Future Features Programming Reference, "IA32_LBR_CTL.LBREn is saved and cleared on #SMI, and restored on RSM." I don't see that happening anywhere. That manual also says, "On a warm reset...IA32_LBR_CTL.LBREn is cleared to 0, disabling LBRs." I don't see that happening either. I have a question about section 7.1.4.4 in that manual. It says, "On a debug breakpoint event (#DB), IA32_LBR_CTL.LBREn is cleared." When, exactly, does that happen? In particular, if kvm synthesizes such an event (for example, in kvm_vcpu_do_singlestep), does IA32_LBR_CTL.LBREn automatically get cleared (after loading the guest IA32_LBR_CTL value from the VMCS)? Or does kvm need to explicitly clear that bit in the VMCS before injecting the #DB?