Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3876362pxb; Tue, 26 Jan 2021 07:02:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxL5M76q/4f1zvJvrMRX65HgMmn3oxgbvnjUBbiE5yC476HR/KNX2CuUv/TvO9jKUmJ1SO2 X-Received: by 2002:a17:906:eb46:: with SMTP id mc6mr3798109ejb.184.1611673346566; Tue, 26 Jan 2021 07:02:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611673346; cv=none; d=google.com; s=arc-20160816; b=G2sc3JPFw8AUT5I8LE5jjiZiRVR52ZsuKGHU39zo97uM/5gUz1CTwrX0nPtS9itJU+ Z9Emi7IBNSXwdhjtkT/wLB7FBXfv1tkkFE/VFwSl/bf/nZnrE7IlNjlxo7g4QN4hrHCd KMAJwd2rN3pihfli72o1B9AgeoGWGI7/dF2cvTiBNlbGVm44pEKLZ4OGW1ejYFVSI9kZ sFM/rHR4JcwDwtEJHq7+31nzwzAUMLnAXZ4gR3+sxbi8oQUbFEo7JsErMoD6rczBYdLP 81gHpjxCmUH8yedpJGTmdP/sihpcfGbzZa917/1fgxvUHDLu7N7/n+gsP5oIuOfSLvpS xbmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=PcrXNhlDKomMCLfJNYybeh+OpNdfCtsOzQcjyLVp37M=; b=I7Bzmg+vNYJxJi9oO9jnyigjVgbUrD/wD6tFg7gIaYC58x4ank3HGrLwoqZPubVmAL 1HiV/1mPaBSywF26y6rZnpI3Xzj4KDAr4Q/TuV1ewCILRU7eTeP75Fo09XRJL0yMUDOt zlpAY1Mx9WAd1nxxFXEUrPauDRWw/mz8+uP/HM3vX3IHDftctLiefPxwRM4ZmShipP0f jB/2u5U7ZeY8CfX1Ai81avZCbTLxCLSI61FUintvn82cL5JyaGnY6MtotzA7QRwrQyCj aBiNeJgBM/jgLEH6qJXyld7QK73+IhnzjYAwxJjJGfjlHn4hdRzZYpLEZi300zgsmiIq 1isA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="fUkPCU/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si8966481edd.231.2021.01.26.07.02.00; Tue, 26 Jan 2021 07:02:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="fUkPCU/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390883AbhAZO4K (ORCPT + 99 others); Tue, 26 Jan 2021 09:56:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39437 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391040AbhAZJel (ORCPT ); Tue, 26 Jan 2021 04:34:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611653594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PcrXNhlDKomMCLfJNYybeh+OpNdfCtsOzQcjyLVp37M=; b=fUkPCU/7b8+O4MZ7EXbxFGCHzkfYEKP+ua9Hs0PATVq0Mz3xnuAkl938b8HXVGsd4jWgup sfaSaAyKpuX4qkO72B7J3rsW52VUefmeaBT8goGcriyZu6JE1PVNiomgDtpPywO+74IbXW QWLiXB85yf3ApzNn07T6iZI4rAg9x0U= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-GChiiOwsNMWmxCBONT9r2Q-1; Tue, 26 Jan 2021 04:33:13 -0500 X-MC-Unique: GChiiOwsNMWmxCBONT9r2Q-1 Received: by mail-ed1-f71.google.com with SMTP id ck25so9044709edb.16 for ; Tue, 26 Jan 2021 01:33:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PcrXNhlDKomMCLfJNYybeh+OpNdfCtsOzQcjyLVp37M=; b=B9mU8+rwmx91OoFcrZDqs6BwQYoGKKd/Hlme/YZ8Ok/bYBomUx73Qskxh2qHYjxae/ rdg5z2NCDP2y5DcVzpq+FI3LrLlsMk2yNPbv287/iotyxQxbDI9EESUxn3QI0hUoptY/ G/PyyB4v+dweSm9jjpwAlDDkp0ze7hqbUNzELZ2K1z6fcPpi5LDr/JODt6Y+lO9+yqGI akScIh14M/aqYpfw0QOsPyHlPR5Hr/NNtfaQGXd1rLoqB98IwJkYtEort3JdsHa9Rcu6 mK3riRhrvJ0KbQ7BMPpq5TKCCDi4JplpuW8O9cnPM44oTpKcNMmfTBLHIsdZw91pNqk4 nlEw== X-Gm-Message-State: AOAM5305j/aw2wdFGd8fFdeTDpr4tlhlaeDXc52aL5725rlqXy0rcGds JZeLOHJChg6lYcKnee+qTeZB1+hK2bWcqfNQ2okm4XpSjzdRSg2MiXeeTQaf0/qI8Tn04fcEx/T f5WziI2PY2xXSeRKp2FzDY8QYzkl82XGcplS71Wrdk/Ug+4gCERF+8whMGpb1jDD/Zex+uOEM84 v5 X-Received: by 2002:a17:907:9710:: with SMTP id jg16mr3017575ejc.286.1611653592041; Tue, 26 Jan 2021 01:33:12 -0800 (PST) X-Received: by 2002:a17:907:9710:: with SMTP id jg16mr3017552ejc.286.1611653591863; Tue, 26 Jan 2021 01:33:11 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id ke7sm9484812ejc.7.2021.01.26.01.33.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Jan 2021 01:33:11 -0800 (PST) Subject: Re: [RESEND v13 10/10] KVM: vmx/pmu: Release guest LBR event via lazy release mechanism To: Like Xu , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210108013704.134985-1-like.xu@linux.intel.com> <20210108013704.134985-11-like.xu@linux.intel.com> From: Paolo Bonzini Message-ID: <310d674c-44e7-7b46-064f-7cb88c456d0f@redhat.com> Date: Tue, 26 Jan 2021 10:33:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210108013704.134985-11-like.xu@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Reviewed-by: Andi Kleen > --- > 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