Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp16571pxb; Thu, 7 Jan 2021 17:50:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxV1A9gDyyc6ys6UwdtLm+UaBCEKxniEP+Qi0sYtPOUzo7snZvA/CRPY2GZCMAuxx191dy X-Received: by 2002:a05:6402:2041:: with SMTP id bc1mr3557900edb.369.1610070607394; Thu, 07 Jan 2021 17:50:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610070607; cv=none; d=google.com; s=arc-20160816; b=GHuWDFreOW5NlwMdrlyjIAOMvLl5cYEXR4aHzrQey2wySCDFhe7lF2thUNa6/fn4hr ugdk61TBBQ9jpBnd8txul0L4vdIxB8NWC+pLlNPz6xb1uMtKTtQYfJ9JrzncRiuBmjQ/ LyqRXSWBJmz7s3OGZsqWIu3CXC3mdCokAG+VGyUVqJ29pGb5Z7JIe3rN0v2on4OoyRzc hFQp5yb255Sj8X1ghW0WtAhHNZvwwi/zU4233Fg3ipp4uuNfMRfMZu0BtACn06jsuqLL IlRFzb8Lf4NJubcdH1Vd2qqvW9ofnCQSS1wXydsqeY8L0Ds2Wu4LWY6XYJFXaX/IEgUa pJaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=ajlRvk4BvLrPEaYoG/TYlePHLwiicDX+OEP7+UYd470=; b=CkhhBeRxYqkn2foCoYcmsTGLXHJ+OzCLC1haCqmG5ZRwMoPFI45jvvepwCE3sNy7Uc IVsjz0/XUwAWmbrBhhQyciQAHeSeWe4EEyHG9nbZHObKmD5WewlfK0l82XZUVp4NxCVW MeTV9FuV5dLXe+wnmt1ZMfaoPVbxEUhTZhUiGxoDZ8HbBkLyG+BYEW+z/zx2XYLRFc6S vABWgHnyE9ICYOxDYFmHT0AJfwS5OVcFzdXGJCm8CJe2Ypfrn4Oi1QwoT68P7GOep0sT ELmEWhjXuBVX6gym2VJ1XfFulwwoikMnVWMSnv8QiKs6eb4gfWoq/6OqRcRetIzfRU+J AtNg== 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 s16si2932365edx.443.2021.01.07.17.49.43; Thu, 07 Jan 2021 17:50:07 -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; 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 S1729851AbhAHBsv (ORCPT + 99 others); Thu, 7 Jan 2021 20:48:51 -0500 Received: from mga09.intel.com ([134.134.136.24]:27993 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729812AbhAHBsu (ORCPT ); Thu, 7 Jan 2021 20:48:50 -0500 IronPort-SDR: 20Vdu/vy4m9VA6Tctampu6SReWGA2QpCM4dwhzSXrEVnn0soVuzskGiBAMPs8uDHNhtmTW8sBI BoJHP1y0RY9g== X-IronPort-AV: E=McAfee;i="6000,8403,9857"; a="177672417" X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="177672417" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2021 17:43:36 -0800 IronPort-SDR: LGdBUy/sA20YhsVQnQ9FVtTRo9nJ1gDTszFOByGxIuO7C374Mf/kGd890dfV4g5bOzaMpXOCmS IrGFlpGqTZ3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="379938111" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 07 Jan 2021 17:43:32 -0800 From: Like Xu To: Paolo Bonzini , 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 Subject: [RESEND v13 09/10] KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES Date: Fri, 8 Jan 2021 09:37:03 +0800 Message-Id: <20210108013704.134985-10-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210108013704.134985-1-like.xu@linux.intel.com> References: <20210108013704.134985-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andi Kleen --- arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- arch/x86/kvm/vmx/vmx.c | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 57b940c613ab..a9a7c4d1b634 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 ad3b079f6700..9cb5b1e4fc27 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2229,6 +2229,13 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_PERF_CAPABILITIES: if (data && !vcpu_to_pmu(vcpu)->version) return 1; + 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; -- 2.29.2