• Like Xu's avatar
    KVM: vmx/pmu: Pass-through LBR msrs when the guest LBR event is ACTIVE · 1b5ac322
    Like Xu authored
    In addition to DEBUGCTLMSR_LBR, any KVM trap caused by LBR msrs access
    will result in a creation of guest LBR event per-vcpu.
    
    If the guest LBR event is scheduled on with the corresponding vcpu context,
    KVM will pass-through all LBR records msrs to the guest. The LBR callstack
    mechanism implemented in the host could help save/restore the guest LBR
    records during the event context switches, which reduces a lot of overhead
    if we save/restore tens of LBR msrs (e.g. 32 LBR records entries) in the
    much more frequent VMX transitions.
    
    To avoid reclaiming LBR resources from any higher priority event on host,
    KVM would always check the exist of guest LBR event and its state before
    vm-entry as late as possible. A negative result would cancel the
    pass-through state, and it also prevents real registers accesses and
    potential data leakage. If host reclaims the LBR between two checks, the
    interception state and LBR records can be safely preserved due to native
    save/restore support from guest LBR event.
    
    The KVM emits a pr_warn() when the LBR hardware is unavailable to the
    guest LBR event. The administer is supposed to reminder users that the
    guest result may be inaccurate if someone is using LBR to record
    hypervisor on the host side.
    Suggested-by: default avatarAndi Kleen <ak@linux.intel.com>
    Co-developed-by: default avatarWei Wang <wei.w.wang@intel.com>
    Signed-off-by: default avatarWei Wang <wei.w.wang@intel.com>
    Signed-off-by: default avatarLike Xu <like.xu@linux.intel.com>
    Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
    Message-Id: <20210201051039.255478-7-like.xu@linux.intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    1b5ac322
vmx.h 14.6 KB