Received: by 10.192.165.156 with SMTP id m28csp1662317imm; Tue, 17 Apr 2018 03:22:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx48gcIMzEliw5GfAwxsliWsWwQCgUnUXVWrmYgxv7joqmYivIT7zsnrfEBZ61/sNhO0ERFdW X-Received: by 10.98.211.82 with SMTP id q79mr1467850pfg.45.1523960538037; Tue, 17 Apr 2018 03:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523960537; cv=none; d=google.com; s=arc-20160816; b=wdshTfZEqvGo3cBVX2hfxuhHi0qx8tQg/MxUEFr4aKQzITszgA/0Bxj2HRSSs9hBdh wqElBblFF9+zSTTQhCLSMri331ca88O5w+va6r0YGpvPM+hbSjAtrUNm2SnbsYt18Axt fotiTPpe+FvKpknw+iDIOZWFrYc8aSEYyR28yocHMvul7/RwcEG8lOl33wIuWaX2C54Q kKxKKI3vpBnxwPMdXWV/+tZNodpVhvruk6u4EKgqGEnKKODtzF+63zVh/PZTCO5CHE87 jjG4SX3Vj1wnM4KT3SgFhxjUsHZYKwcmnurONCNarQk9+MhziBQjOu/84vP8ZBJR8r2r CmYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=+48KnUxEock4Jj+TDz8UtLLrPz/QS2BfKQaKHRNFXIQ=; b=N98Zt8ziTzwz7ibblNbTVlneS8Jr7PafQ3+ZWFhzT5jus060a8RkQHmPsp8pFmqcYw hpvNPH/pZknT3/AfKHMwNa9Tx76qEk2NGU0Bku7QBtgySmsOg2D8MycfPKZVVXRk8mEc HSJNal6ycKer3nPHn+qjscFMVO/xJ3qZ9LMgyaX4w3aek/0C7yAgox8NW5YoB6r5msoG D2Wh7JLGuJuALfW3SA1ex5d+g6qOINtQBeqamZu1vSfvzmM7/e/MEpkzg3TLx2U/hEmn ttoPX53XcPS8a4fRWYYdqAmr+bqnljpB+ZBv9bOlYIiXKvmnjxreMnKRvrfIskefDm2/ SBIQ== 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 e15-v6si13757252pli.163.2018.04.17.03.22.02; Tue, 17 Apr 2018 03:22:17 -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 S1752231AbeDQKTg (ORCPT + 99 others); Tue, 17 Apr 2018 06:19:36 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:55515 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeDQKTf (ORCPT ); Tue, 17 Apr 2018 06:19:35 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f8Nhx-00049y-EM; Tue, 17 Apr 2018 12:19:29 +0200 Date: Tue, 17 Apr 2018 12:19:29 +0200 (CEST) From: Thomas Gleixner To: David Wang cc: mingo@redhat.com, hpa@zytor.com, mingo@kernel.org, grehkg@linuxfoundation.org, x86@kernel.org, linux-kernel@vger.kernel.org, brucechang@via-alliance.com, cooperyan@zhaoxin.com, qiyuanwang@zhaoxin.com, benjaminpan@viatech.com, lukelin@viacpu.com, timguo@zhaoxin.com Subject: Re: [PATCH] x86/Centaur: show more HW features in /proc/cpuinfo In-Reply-To: <1523180134-5650-1-git-send-email-davidwang@zhaoxin.com> Message-ID: References: <1523180134-5650-1-git-send-email-davidwang@zhaoxin.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 8 Apr 2018, David Wang wrote: > We add this patch to show correct HW features(arch_perfmon, tpr_shadow, > vnmi, flexpriority, ept and vpid) when user execute "cat /proc/cpuinfo". See the other mail vs. the changelog. > > 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 Please move the defines outside the function. This is horrible to read, > + > + 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); Why are you clearing the capabilities? They are cleared at boot time. > + 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); Missing newline between variable declaration and code. checkpatch.pl should have told you that. > + /* Check for version and the number of counters */ > + if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1)) Magic constants and a comment which does not explain how the check works. > + set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); Thanks, tglx