Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4547569pxj; Tue, 22 Jun 2021 02:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcptsWiXx7Qv/UfWaJurFw+7317lMxOMy2ajWkjltcKLxBrUn4U1NmWx0hKIZASCd/wnhw X-Received: by 2002:a17:907:9622:: with SMTP id gb34mr3098832ejc.401.1624355248103; Tue, 22 Jun 2021 02:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624355248; cv=none; d=google.com; s=arc-20160816; b=UBLib42UvlKLW4gU8oArirIEbi8ysD2VQum35X5UUW2T2H8Pj2UMpsDO18LZC3MT1O 0E+xNDu8ptM9ftFblsl+gZs+0W/xcBfSP9NliIlB5IajLJtx46CIpw00nwMDm8lD5Sju urONbx3B9h03eovA7twXLB2+ZuAHxvsT7+7HTfLZD32IiTTl6oLXZ8+n2r4dEMr/0t71 CNOha0+1zLH4SWd8BUVmDQGUormWTNXap9P7IGazdnCZsaS6FkzRugMENRnXtAzqwMRw 5UIPEEsNwMzua8s7Qunov7wR72J7xnfCPZwB86ZGvyx63aX8m3JiF3Lu2F3mTs4WY24x qyfA== 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=5d0swedJj1NDADb4QpqmvoL5Ku/N7u2siNQhH6WXhqc=; b=IC7KqiG5ag6PTWzGW+5VxR0DzDfGcr6XARlGuqh2WxCtke/H7a05D7WpAgpi9S9Zb2 VLvArotEd4GQhLCsOl3uYQPD4j8P2MgCrsB7+Nm3Tckg/hwR5PgNIUXXgP92jp8F7Hzt 9GR8TawIft+G+1NRusHLnEgLb5ZMOAdY4u6k8yUwIDaXW4ghoNM+vVigrCBXHPK3sBKI stVcrTiXNrSv0gcxyIwZSPYcO7BXHEfj4szU1Qyhscp1fma4f/YKbvITLoj1Cdd5ci6x hbUqFk1AiGKsLXAYoVq4QNeyUrPqcGBXPutl+wLy89Y81QbcDh/+tufVH8S8Ny0h39iD i1Wg== 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 ci10si13563051ejc.752.2021.06.22.02.47.05; Tue, 22 Jun 2021 02:47:28 -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 S230454AbhFVJr5 (ORCPT + 99 others); Tue, 22 Jun 2021 05:47:57 -0400 Received: from mga11.intel.com ([192.55.52.93]:45213 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbhFVJrh (ORCPT ); Tue, 22 Jun 2021 05:47:37 -0400 IronPort-SDR: iKzp/IOd5jfEAOYiYhVFNSpEzf44p/Np+JrM2QUJyxnJSrUlG5U+TZORsljABLdyvgnYugk6BH hnukfusSUkUQ== X-IronPort-AV: E=McAfee;i="6200,9189,10022"; a="204013217" X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="204013217" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:44:37 -0700 IronPort-SDR: 7MFMKrbVC1suIh0pHWVxqDq05HGB6FNn3qi9vLteA74+8oLgEFQBX0XKZJ4vBsV/AA/YvjOxNw kp+PgN24Vo+g== X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="641600366" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:44:33 -0700 From: Zhu Lingshan To: peterz@infradead.org, pbonzini@redhat.com Cc: bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, weijiang.yang@intel.com, kan.liang@linux.intel.com, ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, like.xu.linux@gmail.com, Like Xu , Luwei Kang , Zhu Lingshan Subject: [PATCH V7 18/18] KVM: x86/pmu: Expose CPUIDs feature bits PDCM, DS, DTES64 Date: Tue, 22 Jun 2021 17:43:06 +0800 Message-Id: <20210622094306.8336-19-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210622094306.8336-1-lingshan.zhu@intel.com> References: <20210622094306.8336-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu The CPUID features PDCM, DS and DTES64 are required for PEBS feature. KVM would expose CPUID feature PDCM, DS and DTES64 to guest when PEBS is supported in the KVM on the Ice Lake server platforms. Originally-by: Andi Kleen Co-developed-by: Kan Liang Signed-off-by: Kan Liang Co-developed-by: Luwei Kang Signed-off-by: Luwei Kang Signed-off-by: Like Xu Signed-off-by: Zhu Lingshan --- arch/x86/kvm/vmx/capabilities.h | 26 ++++++++++++++++++-------- arch/x86/kvm/vmx/vmx.c | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index aa0e7872fcc9..921be9c2bad4 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -5,6 +5,7 @@ #include #include "lapic.h" +#include "pmu.h" extern bool __read_mostly enable_vpid; extern bool __read_mostly flexpriority_enabled; @@ -377,20 +378,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 vmx_pebs_supported(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 boot_cpu_has(X86_FEATURE_PEBS) && kvm_pmu_cap.pebs_vmx; +} +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 (vmx_pebs_supported()) + perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK; + + 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 bfc004482b34..19e1cb5296bd 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2310,6 +2310,17 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (!cpuid_model_is_consistent(vcpu)) return 1; } + if (data & PERF_CAP_PEBS_FORMAT) { + if ((data & PERF_CAP_PEBS_MASK) != + (vmx_get_perf_capabilities() & PERF_CAP_PEBS_MASK)) + return 1; + if (!guest_cpuid_has(vcpu, X86_FEATURE_DS)) + return 1; + if (!guest_cpuid_has(vcpu, X86_FEATURE_DTES64)) + return 1; + if (!cpuid_model_is_consistent(vcpu)) + return 1; + } ret = kvm_set_msr_common(vcpu, msr_info); break; @@ -7304,6 +7315,10 @@ static __init void vmx_set_cpu_caps(void) kvm_cpu_cap_clear(X86_FEATURE_INVPCID); if (vmx_pt_mode_is_host_guest()) kvm_cpu_cap_check_and_set(X86_FEATURE_INTEL_PT); + if (vmx_pebs_supported()) { + kvm_cpu_cap_check_and_set(X86_FEATURE_DS); + kvm_cpu_cap_check_and_set(X86_FEATURE_DTES64); + } if (!enable_sgx) { kvm_cpu_cap_clear(X86_FEATURE_SGX); -- 2.27.0