lkml.org 
[lkml]   [2021]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RESEND v13 10/10] KVM: vmx/pmu: Release guest LBR event via lazy release mechanism
From
Date
On 08/01/21 02:37, Like Xu wrote:
> The vPMU uses GUEST_LBR_IN_USE_IDX (bit 58) in 'pmu->pmc_in_use' to
> indicate whether a guest LBR event is still needed by the vcpu. If the
> vcpu no longer accesses LBR related registers within a scheduling time
> slice, and the enable bit of LBR has been unset, vPMU will treat the
> guest LBR event as a bland event of a vPMC counter and release it
> as usual. Also, the pass-through state of LBR records msrs is cancelled.
>
> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> Reviewed-by: Andi Kleen <ak@linux.intel.com>
> ---
> arch/x86/kvm/pmu.c | 7 +++++++
> arch/x86/kvm/pmu.h | 4 ++++
> arch/x86/kvm/vmx/pmu_intel.c | 17 ++++++++++++++++-
> 3 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 405890c723a1..e7c72eea07d4 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -463,6 +463,7 @@ void kvm_pmu_cleanup(struct kvm_vcpu *vcpu)
> struct kvm_pmc *pmc = NULL;
> DECLARE_BITMAP(bitmask, X86_PMC_IDX_MAX);
> int i;
> + bool extra_cleanup = false;
>
> pmu->need_cleanup = false;
>
> @@ -474,8 +475,14 @@ void kvm_pmu_cleanup(struct kvm_vcpu *vcpu)
>
> if (pmc && pmc->perf_event && !pmc_speculative_in_use(pmc))
> pmc_stop_counter(pmc);
> +
> + if (i == INTEL_GUEST_LBR_INUSE)
> + extra_cleanup = true;
> }
>
> + if (extra_cleanup && kvm_x86_ops.pmu_ops->cleanup)
> + kvm_x86_ops.pmu_ops->cleanup(vcpu);
> +

You can call this function always, it's cleaner than hardcoding
INTEL_GUEST_LBR_INUSE.

You can also use INTEL_PMC_IDX_FIXED_VLBR directly instead of
INTEL_GUEST_LBR_INUSE.

Paolo

\
 
 \ /
  Last update: 2021-01-26 15:58    [W:0.337 / U:0.396 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site