Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1110717pxv; Fri, 16 Jul 2021 01:41:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCz5l9SadRymqcydnZcBTTfCvPSOhQrunuN7q8hRTq6OaWwpv0p6KUI2+w+jcQNo2IJ15D X-Received: by 2002:a05:6402:1385:: with SMTP id b5mr13088031edv.276.1626424914146; Fri, 16 Jul 2021 01:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424914; cv=none; d=google.com; s=arc-20160816; b=SM70/xwLsT/ctzJaNlPYf0n896cxSoljiZpbJzTjhQ0gxMqs7N6vEoANze1x+2hFmX XuaLNQmsy8twfe3YTkWgSzuFIUhWBLSZZjMQhBq+VKCQFjBgXGMxqlsw+gRCtPTUcVG+ ZDkbEc18Ysa5mSBIorWb90L9s4I2W2F9utO7Im9J9tBdFkzywb1nTULpWwWbALgV3e44 2cN6ttHjsd8yS297vm+SKj2YKVVIvQsYdXEU7tAcrAkhcwdjwBzUIzUdtWSPzQJqK4XB Sh+DEVn5Bt/OqqDsz0z974su63OxyxdhfG3A0VJgY1nqoHosqdVqMq9dbxtLmfP/amX/ 3Xvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=rHKt6JRB4tLH03CJAZpZvKKfU29JuBtjde8mcpeMMoQ=; b=zPwsNQLbUs2NPfWwo/E0zP2jFPTEFTLiSzWOD9/BmEzT+8Jcz702jBatDZp4bd9QXY bucVPWFUETv5r6o82m5dPTRxqKtbGgHX8XGlVhBFhLMJ1iZfL71GeBE7XqLLt0+Jyb/D MphwW6NTc0e0QMkLrsvFDz4LOCFRE2JV7YvQqr92qUMKwM8Ut5Y5dw3DFHI0mweHDKVq B0VXVa5Ie2vBPMqhKyRVG/8zr1GRKWN+tea8WnNoyn6SxyXtqOPyzMZpvyWZpYYFYM6B dTLKNa4sT8Nm13/kvkk9+EJqPe5AL1OVw071eZarbeIyYImj0sSaW0vkFEYVJpeTVwQz ZatQ== 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 i11si13156211edb.471.2021.07.16.01.41.31; Fri, 16 Jul 2021 01:41:54 -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 S239008AbhGPIkQ (ORCPT + 99 others); Fri, 16 Jul 2021 04:40:16 -0400 Received: from mga09.intel.com ([134.134.136.24]:15698 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238662AbhGPIjj (ORCPT ); Fri, 16 Jul 2021 04:39:39 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10046"; a="210687334" X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="210687334" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 01:36:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="460679913" Received: from michael-optiplex-9020.sh.intel.com ([10.239.159.182]) by orsmga008.jf.intel.com with ESMTP; 16 Jul 2021 01:36:41 -0700 From: Yang Weijiang To: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, vkuznets@redhat.com, wei.w.wang@intel.com, like.xu.linux@gmail.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yang Weijiang Subject: [PATCH v6 11/12] KVM: x86/vmx: Check Arch LBR config when return perf capabilities Date: Fri, 16 Jul 2021 16:50:05 +0800 Message-Id: <1626425406-18582-12-git-send-email-weijiang.yang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1626425406-18582-1-git-send-email-weijiang.yang@intel.com> References: <1626425406-18582-1-git-send-email-weijiang.yang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Two new bit fields(VM_EXIT_CLEAR_IA32_LBR_CTL, VM_ENTRY_LOAD_IA32_LBR_CTL) are added to support guest Arch LBR. These two bits should be set in order to make Arch LBR workable in both guest and host. Co-developed-by: Like Xu Signed-off-by: Like Xu Signed-off-by: Yang Weijiang --- arch/x86/include/asm/vmx.h | 2 ++ arch/x86/kvm/vmx/capabilities.h | 25 +++++++++++++++++-------- arch/x86/kvm/vmx/vmx.c | 6 ++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index ea3be961cc8e..d9b1dffc4638 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -95,6 +95,7 @@ #define VM_EXIT_CLEAR_BNDCFGS 0x00800000 #define VM_EXIT_PT_CONCEAL_PIP 0x01000000 #define VM_EXIT_CLEAR_IA32_RTIT_CTL 0x02000000 +#define VM_EXIT_CLEAR_IA32_LBR_CTL 0x04000000 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff @@ -108,6 +109,7 @@ #define VM_ENTRY_LOAD_BNDCFGS 0x00010000 #define VM_ENTRY_PT_CONCEAL_PIP 0x00020000 #define VM_ENTRY_LOAD_IA32_RTIT_CTL 0x00040000 +#define VM_ENTRY_LOAD_IA32_LBR_CTL 0x00200000 #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index aa0e7872fcc9..b65e4087c9a9 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -377,20 +377,29 @@ static inline bool vmx_pt_mode_is_host_guest(void) return pt_mode == PT_MODE_HOST_GUEST; } -static inline u64 vmx_get_perf_capabilities(void) +static inline bool cpu_has_vmx_arch_lbr(void) { - u64 perf_cap = 0; - - if (boot_cpu_has(X86_FEATURE_PDCM)) - rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); - - perf_cap &= PMU_CAP_LBR_FMT; + return (vmcs_config.vmexit_ctrl & VM_EXIT_CLEAR_IA32_LBR_CTL) && + (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_LBR_CTL); +} +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 | perf_cap; + u64 perf_cap = PMU_CAP_FW_WRITES; + u64 host_perf_cap = 0; + + if (boot_cpu_has(X86_FEATURE_PDCM)) + rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); + + perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT; + if (boot_cpu_has(X86_FEATURE_ARCH_LBR) && !cpu_has_vmx_arch_lbr()) + 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 81d7a300fb6c..7ccb0bb4831d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2599,7 +2599,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, VM_EXIT_LOAD_IA32_EFER | VM_EXIT_CLEAR_BNDCFGS | VM_EXIT_PT_CONCEAL_PIP | - VM_EXIT_CLEAR_IA32_RTIT_CTL; + VM_EXIT_CLEAR_IA32_RTIT_CTL | + VM_EXIT_CLEAR_IA32_LBR_CTL; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_EXIT_CTLS, &_vmexit_control) < 0) return -EIO; @@ -2623,7 +2624,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, VM_ENTRY_LOAD_IA32_EFER | VM_ENTRY_LOAD_BNDCFGS | VM_ENTRY_PT_CONCEAL_PIP | - VM_ENTRY_LOAD_IA32_RTIT_CTL; + VM_ENTRY_LOAD_IA32_RTIT_CTL | + VM_ENTRY_LOAD_IA32_LBR_CTL; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_ENTRY_CTLS, &_vmentry_control) < 0) return -EIO; -- 2.21.1