Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp416385ybg; Sun, 26 Jul 2020 08:38:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrviSQmv7545/YcpAER+N6Ij0HQA2ZUVq3Sk/SmgkIxzWILJWSLbXsPLxKoG6BoeUoWs+q X-Received: by 2002:a50:afa2:: with SMTP id h31mr17816258edd.303.1595777887503; Sun, 26 Jul 2020 08:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595777887; cv=none; d=google.com; s=arc-20160816; b=z5yBzwOwOqEzoI8Jiq/Fx4AfHTlj7MlFH1X+QPwdxFwmNIOonoMqy6GdkUQotCgtM7 +74NO61Dyr8zi/kmdSfOvIEyJGjXsdwt4N7Og6LOulaS72sOFRAtSLhu8lfWTSsiQPL0 anbAVrRTV1XLiD1Pwy0YX+hVJzIqR7rTWrD7hTghnwUeDwCRpMwHW6PvDPKlK+m3bUNU lToK0uXT+Ain5SL0eks6ymXbO5BHQVX6lOSQOrttYLXzHv3lMsYcxSVEpQhKdTf5Zntn 4JPBsd3tWTNTDW771rEnHPXCY3nIiogj0Lw0NGKVIlzpDmAjYcCgfCUEXoryTX147K+7 sg/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=7Wfbz+IFAhoTjke2xNNyAAxYi/OBdy6P9zGeGGLKTXg=; b=RwFUQH1S6P8+Z4KdQL/rls4pebX+D7zluagsvhPphQthE4IPL5wcmNtJvDV6KI0JHo L5ePqZurWApNujsEfbo1nIljE4HX99kO4Tvyk8/yOBNX93rNBGrc4Je7+9iCgPJvAeQg Y4+ZlrVN48ispMrC8xLO8KSX75q2qR5krXtwa4Rff21MVglJSumxD5XSMTNRsfSEQJrr UHemjnwNBXAwyqIsre7u6vdHaysH7Sza4u2PjxotODSG2EYighKVy2XBt/yi1d/XdnO4 kOC3mOxD91o6M9juW+yx3v87p1fStj9clidErHKbX38elYu7psFnSuPpeJxg0Dascjax USQA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si4293755edp.515.2020.07.26.08.37.46; Sun, 26 Jul 2020 08:38:07 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727904AbgGZPfM (ORCPT + 99 others); Sun, 26 Jul 2020 11:35:12 -0400 Received: from mga03.intel.com ([134.134.136.65]:17603 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727855AbgGZPfH (ORCPT ); Sun, 26 Jul 2020 11:35:07 -0400 IronPort-SDR: uyKBXohLEyv+7InQII9j3Kpaq0f3x5AKEfLZ/cOyWNwtQwMgK/DqIVSHHUSCeLpGiqKevrrBTY Yr+GsH0GfZEg== X-IronPort-AV: E=McAfee;i="6000,8403,9694"; a="150890992" X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="150890992" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2020 08:35:07 -0700 IronPort-SDR: Z8CnUrrSVY8gtpW3lPiqMRbUxCMUL0thMvOJ9Y8U2fRLIYbK0jtQhWB5ObL4ak3Oynj1cyoABQ gYXqofWx7kmA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="303177635" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga002.jf.intel.com with ESMTP; 26 Jul 2020 08:35:05 -0700 From: Like Xu To: Paolo Bonzini , Vitaly Kuznetsov , Jim Mattson , kvm@vger.kernel.org Cc: Sean Christopherson , Wanpeng Li , Joerg Roedel , linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v13 09/10] KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES Date: Sun, 26 Jul 2020 23:32:28 +0800 Message-Id: <20200726153229.27149-11-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200726153229.27149-1-like.xu@linux.intel.com> References: <20200726153229.27149-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Userspace could enable guest LBR feature when the exactly supported LBR format value is initialized to the MSR_IA32_PERF_CAPABILITIES and the LBR is also compatible with vPMU version and host cpu model. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- arch/x86/kvm/vmx/vmx.c | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index f17ab6cf152e..5829f4e9a7e0 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -378,7 +378,14 @@ static inline u64 vmx_get_perf_capabilities(void) * Since counters are virtualized, KVM would support full * width counting unconditionally, even if the host lacks it. */ - return PMU_CAP_FW_WRITES; + u64 perf_cap = PMU_CAP_FW_WRITES; + + if (boot_cpu_has(X86_FEATURE_PDCM)) + rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); + + perf_cap |= perf_cap & PMU_CAP_LBR_FMT; + + return perf_cap; } static inline u64 vmx_supported_debugctl(void) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b72fbbef56fa..6d8b1d98ae1d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2251,6 +2251,16 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if ((data >> 32) != 0) return 1; goto find_shared_msr; + case MSR_IA32_PERF_CAPABILITIES: + if (data & PMU_CAP_LBR_FMT) { + if ((data & PMU_CAP_LBR_FMT) != + (vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT)) + return 1; + if (!intel_pmu_lbr_is_compatible(vcpu)) + return 1; + } + ret = kvm_set_msr_common(vcpu, msr_info); + break; default: find_shared_msr: -- 2.21.3