Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp63669pxb; Tue, 2 Feb 2021 23:01:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCsT69fbghhaR2dNA+fM3B2Lg9qicbeXfJmDEo4heuFUEXgvwQlOblOobzqO0WS23KYKCx X-Received: by 2002:a17:907:9810:: with SMTP id ji16mr1743571ejc.394.1612335667500; Tue, 02 Feb 2021 23:01:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612335667; cv=none; d=google.com; s=arc-20160816; b=e8m9cXJHehtW4CXsOrpCG9hoJl/nAsQmZSEY7OdGc72uf5W8MOLAnAMJft2rCITSnD 64XygZdn3J59KHa57wmT4CJKsGYlO1COU3og6/Fp/vcJ2944qZOkGTt4s7KoLdwVjJ48 GF1++CKTiZ1mMyXLmztUbFkVTxyr45A4Dfntnqzir6aDiwG7Zmvi0G89xQXwenfsHv4P bAk5qDc/tGhV81O7c/z9XQhpi5mfp9IA9DiZqW4evVjVHwZPyHRcpEqzyFZF58h0wav6 LwarnN116pCYHbVtlk5VdDPGD8zM9ioxH2JRn3DWnSfKvnoXT2SJaDunYdzhNQioJVNi ZTDw== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=VXzSrQBQ7lDNRNwAr56zory578JT1X8YztMJQmSCNtA=; b=rwIocdzAo0gHkl/1gxpMJVsQex+T/4OH3FbjL4qC4cfbqGJH4NtO3bPHFwsmK+ahBa lDzpcW9ClThngeZBTsB4LBqTHYWFDUPc29bCriVdGYrODvog+Bv6G+Bky4maCU27oAoF Mgumh4fvmM2RGoLzGR1xWv4lANhpKqc9TI6Yrj7LBz0nrGfrKRUHk5baY6L6XYeThqXl cgGhE9s4nTFYUc5a7ywqLVAV90AEro5uSKr7GokbPlTAGId40JWfZfE8G+gLZcyhwEAg qAT0alF0ckO6anQbVcTlywzF+GOcZK8ENlGeHRgRPV1aIlGReFZ1GUwLklYcrNViK7As HLBA== 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 cy17si676535edb.193.2021.02.02.23.00.42; Tue, 02 Feb 2021 23:01: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 S231778AbhBCG6v (ORCPT + 99 others); Wed, 3 Feb 2021 01:58:51 -0500 Received: from mga09.intel.com ([134.134.136.24]:46077 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbhBCG6t (ORCPT ); Wed, 3 Feb 2021 01:58:49 -0500 IronPort-SDR: LKHcjCk+MCJOvNtZ5Ana8J3Ine1IkrgSWZnOOmdLa9Wo5Q6rIkeBZ2wQcSdP4s+6LswureBZWf Pm2Ed3Gwj8LA== X-IronPort-AV: E=McAfee;i="6000,8403,9883"; a="181141693" X-IronPort-AV: E=Sophos;i="5.79,397,1602572400"; d="scan'208";a="181141693" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2021 22:57:02 -0800 IronPort-SDR: yOYFXDoNims9sTqJO4yYV6ttQ36oBupccKAADmqXcJlbXrJY+OxBeeDTAfwotfwrqyU/ADOYoQ iCMOiQxyy+8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,397,1602572400"; d="scan'208";a="433239012" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga001.jf.intel.com with ESMTP; 02 Feb 2021 22:56:59 -0800 From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: vmx/pmu: Add VMCS fields check before exposing LBR_FMT Date: Wed, 3 Feb 2021 14:50:27 +0800 Message-Id: <20210203065027.314622-1-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before KVM exposes guest LBR_FMT perf capabilities, it needs to check whether VMCS has GUEST_IA32_DEBUGCTL guest status field and vmx switch support on IA32_DEBUGCTL MSR (including VM_EXIT_SAVE_DEBUG_CONTROLS and VM_ENTRY_LOAD_DEBUG_CONTROLS). It helps nested LBR enablement. 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 d1d77985e889..ac3af06953a8 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -378,6 +378,12 @@ static inline bool vmx_pt_mode_is_host_guest(void) return pt_mode == PT_MODE_HOST_GUEST; } +static inline bool cpu_has_vmx_lbr(void) +{ + return (vmcs_config.vmexit_ctrl & VM_EXIT_SAVE_DEBUG_CONTROLS) && + (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_DEBUG_CONTROLS); +} + static inline u64 vmx_get_perf_capabilities(void) { u64 perf_cap = 0; @@ -385,7 +391,8 @@ static inline u64 vmx_get_perf_capabilities(void) if (boot_cpu_has(X86_FEATURE_PDCM)) rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); - perf_cap &= PMU_CAP_LBR_FMT; + if (cpu_has_vmx_lbr()) + perf_cap &= PMU_CAP_LBR_FMT; /* * Since counters are virtualized, KVM would support full -- 2.29.2