Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3599054pxb; Sun, 31 Jan 2021 22:37:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgEch96/guzcolPeU3DV8CkclH66bxfzbTJg3A75hO3EpIv4+eSmg2fe3aM1arR90973Qr X-Received: by 2002:a17:906:1359:: with SMTP id x25mr2124674ejb.25.1612161430622; Sun, 31 Jan 2021 22:37:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612161430; cv=none; d=google.com; s=arc-20160816; b=bBjC9GvYvrbRntsf/Pkmp/rPw+v8vf3mY0KirdlEp99GkL8prYXBHWheO3dSRhQ7HO 9bWDbYR8ndPJ3vtIcXnkhOFpMv1VpG2fsuaaMMa34Axni3XELN4AeoxvopYvAuZU4kiq 3YJH81x1iWc44nKvjsiumGBA9+0z289x6dn2e9eP/1/XiJ2wD3Byy8BXkkyEzq7qef3y wfiyYsxHcWSKqS/Ugb/nkaKal5R8zg/E9QtFVUMTiN2BiaJWmNNZIceYUz8dI6wz6frw Us/jPfBUzGOIj3MphEfUwaIwD5LToXXMNiOc1Xmabz80DN4shwD5enUzkusM1cE7+v5D OGqQ== 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=IZLd/kFYutBElIl5TRWajcwfLfMlFvLFgijl/WiduhHm0+ntFjjZBslqE9g3xiBvY7 iPWnb5S+ZmFYT1qSLXF9KgEFilKAG4P7sAQQ/N1UonQqJUDGV3TMHpxzwoSzafi1Shr8 7ajM6hUiIsLxA5aZddPM2rD8jj3Ir5tbBd8UDJ0dS3mOLo2JVfcyU6AxcisqW2oCCg9P 7J+9b7sXw0ZSo+zNX9RhqmIocvrnRaXarAVXDkHFJvSUGbtXluA5wF+pZjs7KIfO9AZd JRUVuSHi/ELlTwpHfAgmqxmhgiNa+tlxmsGi8VX6mCktKJQdn4JvNbPC8B2byBUNvMN+ a/pQ== 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 p18si10128123edx.541.2021.01.31.22.36.47; Sun, 31 Jan 2021 22:37:10 -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 S232169AbhBAGfZ (ORCPT + 99 others); Mon, 1 Feb 2021 01:35:25 -0500 Received: from mga14.intel.com ([192.55.52.115]:26662 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232141AbhBAGNy (ORCPT ); Mon, 1 Feb 2021 01:13:54 -0500 IronPort-SDR: nW2RFa7VddR7G/VrHHBnsxYsuZxzM/0KmVVQvhOfvII7N+JZIaWJkiejuA88PXizUl5UmFhqZn XmAO3utvprKA== X-IronPort-AV: E=McAfee;i="6000,8403,9881"; a="179860905" X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="179860905" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2021 22:08:30 -0800 IronPort-SDR: AHp9ivoOqyafW29bH/e9KW7yzwQbvjCk5Z5jwUduobXzjb+5cy3ZWW3n7qWWXhDmS9Oon6FtzQ 73WqWRDudBUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="368980436" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga008.fm.intel.com with ESMTP; 31 Jan 2021 22:08:27 -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 14:01:51 +0800 Message-Id: <20210201060152.370069-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210201060152.370069-1-like.xu@linux.intel.com> References: <20210201051039.255478-1-like.xu@linux.intel.com> <20210201060152.370069-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