Received: by 10.213.65.68 with SMTP id h4csp1466422imn; Sun, 8 Apr 2018 04:19:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx487npNtv3XQfvftXNwjqcrn1gKOwCaghUlQpcEZlmiRkEdX0BWZaDIqjj3xWAK9OBJLZ9Jm X-Received: by 10.98.150.75 with SMTP id c72mr25864530pfe.62.1523186375005; Sun, 08 Apr 2018 04:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523186374; cv=none; d=google.com; s=arc-20160816; b=sARL+OLaJFTHekOvZw5R0/r3SAfpDjc1G+D5q4+OoKlUWqvCa2MQHdyrmQpQHuISie zEdovEs2gb3HI0srlbs2a4t6wUiT371tBxqS8htKRGeNebbuOrXpKNl4w+Ywsik2ScUY DUEyKdSLoaXSnlEETRtIG2Z7uFaL6tAbTilm7bb+ro3pEqFHUXYvj1ykmVwaE93OoUPq rj43RVsRdTyVtvba8TR4yRX6Dr5zNb5JqKzQzwd8i+BLFSLVFvm5+1YrMoDhuypft2vM Z+Brha9OLo4RDA3K72Qlk6tWLXM8AvXmM8emKZrpA8vMVIbRzEugzUwOJ3rIdebu5Dl6 H1BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=t3Wn4fiyfU2xJxWcdKn2Q1gbQXbFgZEY6ukMNKr+7fo=; b=T8p/7ItRkAtVYafrwXv/fTbCSbc4K/81vEcnQapeiI1yk0n3zwA7BAXH8uxBP7ip93 fbce0Ov8xEy+CaFFA/3ulLQlEk0ISznAwDDA37kj58PTt3fCEHxbMIRXFG/q/bsb7cKl mJR+KTl16EuM+UKNKOrosxuPiGlT+eYNY3LeOA+0c3m8IPfnEOnxZiyM+V6XrJU36TBb NB9IRQMJIli2suWEkkRGpOF309aGYzvZlzyqELyMUAIw3LFbGhyLZiFu/gjHBO2A8RDb B5TwRihBc7JLNTixVf/eA52sycPZSdWZXz5eEtBQAzINSUb0c+8sGQXD7iCiDoxDwYwn /HgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si8852372pfe.306.2018.04.08.04.18.45; Sun, 08 Apr 2018 04:19:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752804AbeDHJfn (ORCPT + 99 others); Sun, 8 Apr 2018 05:35:43 -0400 Received: from zxshcas2.zhaoxin.com ([180.169.121.92]:22139 "EHLO ZXSHCAS2.zhaoxin.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752701AbeDHJfm (ORCPT ); Sun, 8 Apr 2018 05:35:42 -0400 Received: from zxbjmbx3.zhaoxin.com (10.29.252.165) by ZXSHCAS2.zhaoxin.com (10.28.252.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1261.35; Sun, 8 Apr 2018 17:35:38 +0800 Received: from timguo-System-Product-Name.zhaoxin.com (10.29.8.54) by zxbjmbx3.zhaoxin.com (10.29.252.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1261.35; Sun, 8 Apr 2018 17:35:37 +0800 From: David Wang To: , , , , , , CC: , , , , , , David Wang Subject: [PATCH] x86/Centaur: show more HW features in /proc/cpuinfo Date: Sun, 8 Apr 2018 17:35:34 +0800 Message-ID: <1523180134-5650-1-git-send-email-davidwang@zhaoxin.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.29.8.54] X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx3.zhaoxin.com (10.29.252.165) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We add this patch to show correct HW features(arch_perfmon, tpr_shadow, vnmi, flexpriority, ept and vpid) when user execute "cat /proc/cpuinfo". Signed-off-by: David Wang --- arch/x86/kernel/cpu/centaur.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index e5ec0f1..969fb8f 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -112,6 +112,44 @@ static void early_init_centaur(struct cpuinfo_x86 *c) } } +static void centaur_detect_vmx_virtcap(struct cpuinfo_x86 *c) +{ +#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000 +#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000 +#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000 +#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001 +#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002 +#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020 + + u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2; + + clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW); + clear_cpu_cap(c, X86_FEATURE_VNMI); + clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY); + clear_cpu_cap(c, X86_FEATURE_EPT); + clear_cpu_cap(c, X86_FEATURE_VPID); + + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high); + msr_ctl = vmx_msr_high | vmx_msr_low; + + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW) + set_cpu_cap(c, X86_FEATURE_TPR_SHADOW); + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI) + set_cpu_cap(c, X86_FEATURE_VNMI); + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) { + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, + vmx_msr_low, vmx_msr_high); + msr_ctl2 = vmx_msr_high | vmx_msr_low; + if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) && + (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)) + set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY); + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT) + set_cpu_cap(c, X86_FEATURE_EPT); + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID) + set_cpu_cap(c, X86_FEATURE_VPID); + } +} + static void init_centaur(struct cpuinfo_x86 *c) { #ifdef CONFIG_X86_32 @@ -128,6 +166,14 @@ static void init_centaur(struct cpuinfo_x86 *c) clear_cpu_cap(c, 0*32+31); #endif early_init_centaur(c); + + if (c->cpuid_level > 9) { + unsigned eax = cpuid_eax(10); + /* Check for version and the number of counters */ + if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1)) + set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); + } + switch (c->x86) { #ifdef CONFIG_X86_32 case 5: @@ -199,6 +245,9 @@ static void init_centaur(struct cpuinfo_x86 *c) #ifdef CONFIG_X86_64 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); #endif + + if (cpu_has(c, X86_FEATURE_VMX)) + centaur_detect_vmx_virtcap(c); } #ifdef CONFIG_X86_32 -- 1.9.1