Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3603627pxb; Sun, 31 Jan 2021 22:48:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdfbFR1HdSx3MvUQShHP9kpzTDQPSmyvgjtw5vKRalJ++uHcwNoT3qrS4lmwx8nK0hm73R X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr16435897eju.153.1612162110792; Sun, 31 Jan 2021 22:48:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612162110; cv=none; d=google.com; s=arc-20160816; b=g6jGnA3ydmhsbB3bI9b4XxlJzbJ0MZF0jC411+ssHkFTI7cbGQ+FcL7FizBC4WC73u +ErJigcB66Efz/j+S5ENOFhp5ltFB5KnoLJCSo7Ut1LUCNQ9rZCLrFcQIxw70RaEyKwu Cg1Mtbu45iiopuhA3d+r4o9RJJCEDl1pxmqYEBE7Bb+mwOaswmpPAfTRP+8YkqFhqnRV zLv7XRWbhjJ9O6RrprZmVE+ZbzeAKawkIIl6Kmayq8Djg+KTBuwQ9hgZr2I3y4R7SSLx IJh+iManj1Wdt5bdPmS85Sa9e/JDk8P11dktHVZuMJbSw8i60uoh4ksO1w3Nnewn3HGY BvHw== 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=ZdQmqTqPeyat/qDcG6U4qxcMMH0/jivSPlKIYNyg5r4=; b=NiLu6pFLgB9Y6XWxVDM3xVNfj2wiyco44Wb3AGrCT7t15Dqj+6kLzewY2QrDgLnMzs 1/Jv5rN8K4h72Io+Lhn691gDx260wpyiT06Nf1EILAlbEWuTHwC42ArnerJ8sBWXaVKd ISsW/EOZ4HSBL4cVSb3F9OIU/scSfOlg9BtmSdHNPluLXglxQn7Cybf32DY42BXgXP3+ B/5s9hRHGZBhxnFvQs7zidHw29FZxvf8YeU/QAIiUcntARWHynWawkusMzxM/OYUdArx ukSIEX0r/cWvldNYx/RLkNjJbbpnexwuxt3UhIOVNPi/JvnsM+yCGxJyqBil31b90qYL yXDA== 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 b8si2510392eds.433.2021.01.31.22.48.06; Sun, 31 Jan 2021 22:48:30 -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 S232281AbhBAGoJ (ORCPT + 99 others); Mon, 1 Feb 2021 01:44:09 -0500 Received: from mga17.intel.com ([192.55.52.151]:9254 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhBAFZ5 (ORCPT ); Mon, 1 Feb 2021 00:25:57 -0500 IronPort-SDR: sJLq/ATtHEar+p4mTKyiXdf6/Ln5AkGcDfsK6g5awEz/Oh/qsEaESmkRVc/tmRPYuNhBveAwXt 1W4QMIuobFTQ== X-IronPort-AV: E=McAfee;i="6000,8403,9881"; a="160401854" X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="160401854" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2021 21:17:39 -0800 IronPort-SDR: qYLShahsDQnOc5eCpWaICfHY+mfxnKdCTdXP0KwuqDV+ks+zV0MhHIH9lP677H1PeqJOxOttZp sl+kPuymgD4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="390694331" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 31 Jan 2021 21:17:36 -0800 From: Like Xu To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, alex.shi@linux.alibaba.com, kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v14 10/11] KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES Date: Mon, 1 Feb 2021 13:10:38 +0800 Message-Id: <20210201051039.255478-11-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210201051039.255478-1-like.xu@linux.intel.com> References: <20210201051039.255478-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. The LBR could be enabled on the guest if host perf supports LBR (checked via x86_perf_get_lbr()) and the vcpu model is compatible with the host one. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 57b940c613ab..c49f3ee8eca8 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -374,11 +374,18 @@ static inline bool vmx_pt_mode_is_host_guest(void) static inline u64 vmx_get_perf_capabilities(void) { + u64 perf_cap; + + if (boot_cpu_has(X86_FEATURE_PDCM)) + rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); + + perf_cap &= PMU_CAP_LBR_FMT; + /* * Since counters are virtualized, KVM would support full * width counting unconditionally, even if the host lacks it. */ - return PMU_CAP_FW_WRITES; + return PMU_CAP_FW_WRITES | perf_cap; } static inline u64 vmx_supported_debugctl(void) -- 2.29.2