linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Borislav Petkov <bp@suse.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Srivatsa S. Bhat" <srivatsa@csail.mit.edu>,
	"Matt Helsley (VMware)" <matt.helsley@gmail.com>,
	Alexey Makhalov <amakhalov@vmware.com>, Bo Gan <ganb@vmware.com>
Subject: [PATCH 4.4 17/43] x86/cpufeature: Cleanup get_cpu_cap()
Date: Mon, 16 Jul 2018 09:36:22 +0200	[thread overview]
Message-ID: <20180716073513.689921807@linuxfoundation.org> (raw)
In-Reply-To: <20180716073511.796555857@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Borislav Petkov <bp@suse.de>

commit 39c06df4dc10a41de5fe706f4378ee5f09beba73 upstream

Add an enum for the ->x86_capability array indices and cleanup
get_cpu_cap() by killing some redundant local vars.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/1449481182-27541-3-git-send-email-bp@alien8.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Srivatsa S. Bhat <srivatsa@csail.mit.edu>
Reviewed-by: Matt Helsley (VMware) <matt.helsley@gmail.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Bo Gan <ganb@vmware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

 arch/x86/include/asm/cpufeature.h |   20 ++++++++++++++++
 arch/x86/kernel/cpu/centaur.c     |    2 -
 arch/x86/kernel/cpu/common.c      |   47 +++++++++++++++++---------------------
 arch/x86/kernel/cpu/transmeta.c   |    4 +--
 4 files changed, 45 insertions(+), 28 deletions(-)

--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -299,6 +299,26 @@
 #include <asm/asm.h>
 #include <linux/bitops.h>
 
+enum cpuid_leafs
+{
+	CPUID_1_EDX		= 0,
+	CPUID_8000_0001_EDX,
+	CPUID_8086_0001_EDX,
+	CPUID_LNX_1,
+	CPUID_1_ECX,
+	CPUID_C000_0001_EDX,
+	CPUID_8000_0001_ECX,
+	CPUID_LNX_2,
+	CPUID_LNX_3,
+	CPUID_7_0_EBX,
+	CPUID_D_1_EAX,
+	CPUID_F_0_EDX,
+	CPUID_F_1_EDX,
+	CPUID_8000_0008_EBX,
+	CPUID_6_EAX,
+	CPUID_8000_000A_EDX,
+};
+
 #ifdef CONFIG_X86_FEATURE_NAMES
 extern const char * const x86_cap_flags[NCAPINTS*32];
 extern const char * const x86_power_flags[32];
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -43,7 +43,7 @@ static void init_c3(struct cpuinfo_x86 *
 		/* store Centaur Extended Feature Flags as
 		 * word 5 of the CPU capability bit array
 		 */
-		c->x86_capability[5] = cpuid_edx(0xC0000001);
+		c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001);
 	}
 #ifdef CONFIG_X86_32
 	/* Cyrix III family needs CX8 & PGE explicitly enabled. */
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -676,52 +676,47 @@ static void apply_forced_caps(struct cpu
 
 void get_cpu_cap(struct cpuinfo_x86 *c)
 {
-	u32 tfms, xlvl;
-	u32 ebx;
+	u32 eax, ebx, ecx, edx;
 
 	/* Intel-defined flags: level 0x00000001 */
 	if (c->cpuid_level >= 0x00000001) {
-		u32 capability, excap;
+		cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
 
-		cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
-		c->x86_capability[0] = capability;
-		c->x86_capability[4] = excap;
+		c->x86_capability[CPUID_1_ECX] = ecx;
+		c->x86_capability[CPUID_1_EDX] = edx;
 	}
 
 	/* Additional Intel-defined flags: level 0x00000007 */
 	if (c->cpuid_level >= 0x00000007) {
-		u32 eax, ebx, ecx, edx;
-
 		cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx);
 
-		c->x86_capability[9] = ebx;
+		c->x86_capability[CPUID_7_0_EBX] = ebx;
 
-		c->x86_capability[14] = cpuid_eax(0x00000006);
+		c->x86_capability[CPUID_6_EAX] = cpuid_eax(0x00000006);
 	}
 
 	/* Extended state features: level 0x0000000d */
 	if (c->cpuid_level >= 0x0000000d) {
-		u32 eax, ebx, ecx, edx;
-
 		cpuid_count(0x0000000d, 1, &eax, &ebx, &ecx, &edx);
 
-		c->x86_capability[10] = eax;
+		c->x86_capability[CPUID_D_1_EAX] = eax;
 	}
 
 	/* Additional Intel-defined flags: level 0x0000000F */
 	if (c->cpuid_level >= 0x0000000F) {
-		u32 eax, ebx, ecx, edx;
 
 		/* QoS sub-leaf, EAX=0Fh, ECX=0 */
 		cpuid_count(0x0000000F, 0, &eax, &ebx, &ecx, &edx);
-		c->x86_capability[11] = edx;
+		c->x86_capability[CPUID_F_0_EDX] = edx;
+
 		if (cpu_has(c, X86_FEATURE_CQM_LLC)) {
 			/* will be overridden if occupancy monitoring exists */
 			c->x86_cache_max_rmid = ebx;
 
 			/* QoS sub-leaf, EAX=0Fh, ECX=1 */
 			cpuid_count(0x0000000F, 1, &eax, &ebx, &ecx, &edx);
-			c->x86_capability[12] = edx;
+			c->x86_capability[CPUID_F_1_EDX] = edx;
+
 			if (cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC)) {
 				c->x86_cache_max_rmid = ecx;
 				c->x86_cache_occ_scale = ebx;
@@ -733,22 +728,24 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 	}
 
 	/* AMD-defined flags: level 0x80000001 */
-	xlvl = cpuid_eax(0x80000000);
-	c->extended_cpuid_level = xlvl;
+	eax = cpuid_eax(0x80000000);
+	c->extended_cpuid_level = eax;
+
+	if ((eax & 0xffff0000) == 0x80000000) {
+		if (eax >= 0x80000001) {
+			cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
 
-	if ((xlvl & 0xffff0000) == 0x80000000) {
-		if (xlvl >= 0x80000001) {
-			c->x86_capability[1] = cpuid_edx(0x80000001);
-			c->x86_capability[6] = cpuid_ecx(0x80000001);
+			c->x86_capability[CPUID_8000_0001_ECX] = ecx;
+			c->x86_capability[CPUID_8000_0001_EDX] = edx;
 		}
 	}
 
 	if (c->extended_cpuid_level >= 0x80000008) {
-		u32 eax = cpuid_eax(0x80000008);
+		cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
 
 		c->x86_virt_bits = (eax >> 8) & 0xff;
 		c->x86_phys_bits = eax & 0xff;
-		c->x86_capability[13] = cpuid_ebx(0x80000008);
+		c->x86_capability[CPUID_8000_0008_EBX] = ebx;
 	}
 #ifdef CONFIG_X86_32
 	else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
@@ -759,7 +756,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 		c->x86_power = cpuid_edx(0x80000007);
 
 	if (c->extended_cpuid_level >= 0x8000000a)
-		c->x86_capability[15] = cpuid_edx(0x8000000a);
+		c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a);
 
 	init_scattered_cpuid_features(c);
 }
--- a/arch/x86/kernel/cpu/transmeta.c
+++ b/arch/x86/kernel/cpu/transmeta.c
@@ -12,7 +12,7 @@ static void early_init_transmeta(struct
 	xlvl = cpuid_eax(0x80860000);
 	if ((xlvl & 0xffff0000) == 0x80860000) {
 		if (xlvl >= 0x80860001)
-			c->x86_capability[2] = cpuid_edx(0x80860001);
+			c->x86_capability[CPUID_8086_0001_EDX] = cpuid_edx(0x80860001);
 	}
 }
 
@@ -82,7 +82,7 @@ static void init_transmeta(struct cpuinf
 	/* Unhide possibly hidden capability flags */
 	rdmsr(0x80860004, cap_mask, uk);
 	wrmsr(0x80860004, ~0, uk);
-	c->x86_capability[0] = cpuid_edx(0x00000001);
+	c->x86_capability[CPUID_1_EDX] = cpuid_edx(0x00000001);
 	wrmsr(0x80860004, cap_mask, uk);
 
 	/* All Transmeta CPUs have a constant TSC */



  parent reply	other threads:[~2018-07-16  7:44 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16  7:36 [PATCH 4.4 00/43] 4.4.141-stable review Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 01/43] MIPS: Fix ioremap() RAM check Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 02/43] ibmasm: dont write out of bounds in read handler Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 03/43] vmw_balloon: fix inflation with batching Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 04/43] ahci: Disable LPM on Lenovo 50 series laptops with a too old BIOS Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 05/43] USB: serial: ch341: fix type promotion bug in ch341_control_in() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 06/43] USB: serial: cp210x: add another USB ID for Qivicon ZigBee stick Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 07/43] USB: serial: keyspan_pda: fix modem-status error handling Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 08/43] USB: yurex: fix out-of-bounds uaccess in read handler Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 09/43] USB: serial: mos7840: fix status-register error handling Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 10/43] usb: quirks: add delay quirks for Corsair Strafe Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 11/43] xhci: xhci-mem: off by one in xhci_stream_id_to_ring() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 12/43] HID: usbhid: add quirk for innomedia INNEX GENESIS/ATARI adapter Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 13/43] Fix up non-directory creation in SGID directories Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 14/43] tools build: fix # escaping in .cmd files for future Make Greg Kroah-Hartman
2018-07-17 12:57   ` Konstantin Khlebnikov
2018-07-17 13:10     ` Greg Kroah-Hartman
2018-07-17 13:15     ` Greg Kroah-Hartman
2018-07-17 19:51       ` Konstantin Khlebnikov
2018-07-18  8:24         ` Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 15/43] iw_cxgb4: correctly enforce the max reg_mr depth Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 16/43] x86/cpufeature: Move some of the scattered feature bits to x86_capability Greg Kroah-Hartman
2018-07-16  7:36 ` Greg Kroah-Hartman [this message]
2018-07-16  7:36 ` [PATCH 4.4 18/43] x86/cpu: Provide a config option to disable static_cpu_has Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 19/43] x86/fpu: Add an XSTATE_OP() macro Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 20/43] x86/fpu: Get rid of xstate_fault() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 21/43] x86/headers: Dont include asm/processor.h in asm/atomic.h Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 22/43] x86/cpufeature: Carve out X86_FEATURE_* Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 23/43] x86/cpufeature: Replace the old static_cpu_has() with safe variant Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 24/43] x86/cpufeature: Get rid of the non-asm goto variant Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 25/43] x86/alternatives: Add an auxilary section Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 26/43] x86/alternatives: Discard dynamic check after init Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 27/43] x86/vdso: Use static_cpu_has() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 28/43] x86/boot: Simplify kernel load address alignment check Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 29/43] x86/cpufeature: Speed up cpu_feature_enabled() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 30/43] x86/cpufeature, x86/mm/pkeys: Add protection keys related CPUID definitions Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 31/43] x86/mm/pkeys: Fix mismerge of protection keys CPUID bits Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 32/43] x86/cpu: Add detection of AMD RAS Capabilities Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 33/43] x86/cpufeature, x86/mm/pkeys: Fix broken compile-time disabling of pkeys Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 34/43] x86/cpufeature: Update cpufeaure macros Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 35/43] x86/cpufeature: Make sure DISABLED/REQUIRED macros are updated Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 36/43] x86/cpufeature: Add helper macro for mask check macros Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 37/43] uprobes/x86: Remove incorrect WARN_ON() in uprobe_init_insn() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 38/43] netfilter: nf_queue: augment nfqa_cfg_policy Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 39/43] netfilter: x_tables: initialise match/target check parameter struct Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 40/43] loop: add recursion validation to LOOP_CHANGE_FD Greg Kroah-Hartman
2018-08-22 21:43   ` Ben Hutchings
2018-07-16  7:36 ` [PATCH 4.4 41/43] PM / hibernate: Fix oops at snapshot_write() Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 42/43] RDMA/ucm: Mark UCM interface as BROKEN Greg Kroah-Hartman
2018-07-16  7:36 ` [PATCH 4.4 43/43] loop: remember whether sysfs_create_group() was done Greg Kroah-Hartman
2018-07-16 13:55 ` [PATCH 4.4 00/43] 4.4.141-stable review Nathan Chancellor
2018-07-16 16:22 ` Guenter Roeck
2018-07-17  8:06 ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180716073513.689921807@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=amakhalov@vmware.com \
    --cc=bp@suse.de \
    --cc=ganb@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.helsley@gmail.com \
    --cc=srivatsa@csail.mit.edu \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).