Skip to content

Commit 8a9365a

Browse files
committed
Merge branch 'x86-cpufeature-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 cpufeature updates from Ingo Molnar: "The main changes in this cycle were related to enable ring-3 MONITOR/MWAIT instructions support on supported CPUs, by Grzegorz Andrejczuk and Piotr Luc" * 'x86-cpufeature-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cpufeature: Move RING3MWAIT feature to avoid conflicts x86/cpufeature: Enable RING3MWAIT for Knights Mill x86/cpufeature: Enable RING3MWAIT for Knights Landing x86/cpufeature: Add RING3MWAIT to CPU features x86/elf: Add HWCAP2 to expose ring 3 MONITOR/MWAIT x86/msr: Add MSR_MISC_FEATURE_ENABLES and RING3MWAIT bit x86/cpufeature: Add AVX512_VPOPCNTDQ feature
2 parents 2891e8e + 3bba73b commit 8a9365a

File tree

9 files changed

+76
-2
lines changed

9 files changed

+76
-2
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,10 @@
35613561
rhash_entries= [KNL,NET]
35623562
Set number of hash buckets for route cache
35633563

3564+
ring3mwait=disable
3565+
[KNL] Disable ring 3 MONITOR/MWAIT feature on supported
3566+
CPUs.
3567+
35643568
ro [KNL] Mount root device read-only on boot
35653569

35663570
rodata= [KNL]

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
*
187187
* Reuse free bits when adding new feature flags!
188188
*/
189-
189+
#define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */
190190
#define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */
191191
#define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */
192192
#define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */
@@ -288,6 +288,7 @@
288288
#define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
289289
#define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */
290290
#define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */
291+
#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
291292
#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */
292293

293294
/* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */
@@ -320,5 +321,4 @@
320321
#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
321322
#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
322323
#define X86_BUG_AMD_E400 X86_BUG(13) /* CPU is among the affected by Erratum 400 */
323-
324324
#endif /* _ASM_X86_CPUFEATURES_H */

arch/x86/include/asm/elf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ extern int force_personality32;
258258

259259
#define ELF_HWCAP (boot_cpu_data.x86_capability[CPUID_1_EDX])
260260

261+
extern u32 elf_hwcap2;
262+
263+
/*
264+
* HWCAP2 supplies mask with kernel enabled CPU features, so that
265+
* the application can discover that it can safely use them.
266+
* The bits are defined in uapi/asm/hwcap2.h.
267+
*/
268+
#define ELF_HWCAP2 (elf_hwcap2)
269+
261270
/* This yields a string that ld.so will use to load implementation
262271
specific libraries for optimization. This is more specific in
263272
intent than poking at uname or /proc/cpuinfo.

arch/x86/include/asm/msr-index.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@
543543
#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT 39
544544
#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT)
545545

546+
/* MISC_FEATURE_ENABLES non-architectural features */
547+
#define MSR_MISC_FEATURE_ENABLES 0x00000140
548+
549+
#define MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT 1
550+
546551
#define MSR_IA32_TSC_DEADLINE 0x000006E0
547552

548553
/* P4/Xeon+ specific */

arch/x86/include/uapi/asm/hwcap2.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _ASM_X86_HWCAP2_H
2+
#define _ASM_X86_HWCAP2_H
3+
4+
/* MONITOR/MWAIT enabled in Ring 3 */
5+
#define HWCAP2_RING3MWAIT (1 << 0)
6+
7+
#endif

arch/x86/kernel/cpu/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <asm/desc.h>
3636
#include <asm/fpu/internal.h>
3737
#include <asm/mtrr.h>
38+
#include <asm/hwcap2.h>
3839
#include <linux/numa.h>
3940
#include <asm/asm.h>
4041
#include <asm/bugs.h>
@@ -51,6 +52,8 @@
5152

5253
#include "cpu.h"
5354

55+
u32 elf_hwcap2 __read_mostly;
56+
5457
/* all of these masks are initialized in setup_cpu_local_masks() */
5558
cpumask_var_t cpu_initialized_mask;
5659
cpumask_var_t cpu_callout_mask;

arch/x86/kernel/cpu/intel.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <asm/cpu.h>
1616
#include <asm/intel-family.h>
1717
#include <asm/microcode_intel.h>
18+
#include <asm/hwcap2.h>
19+
#include <asm/elf.h>
1820

1921
#ifdef CONFIG_X86_64
2022
#include <linux/topology.h>
@@ -62,6 +64,46 @@ void check_mpx_erratum(struct cpuinfo_x86 *c)
6264
}
6365
}
6466

67+
static bool ring3mwait_disabled __read_mostly;
68+
69+
static int __init ring3mwait_disable(char *__unused)
70+
{
71+
ring3mwait_disabled = true;
72+
return 0;
73+
}
74+
__setup("ring3mwait=disable", ring3mwait_disable);
75+
76+
static void probe_xeon_phi_r3mwait(struct cpuinfo_x86 *c)
77+
{
78+
/*
79+
* Ring 3 MONITOR/MWAIT feature cannot be detected without
80+
* cpu model and family comparison.
81+
*/
82+
if (c->x86 != 6)
83+
return;
84+
switch (c->x86_model) {
85+
case INTEL_FAM6_XEON_PHI_KNL:
86+
case INTEL_FAM6_XEON_PHI_KNM:
87+
break;
88+
default:
89+
return;
90+
}
91+
92+
if (ring3mwait_disabled) {
93+
msr_clear_bit(MSR_MISC_FEATURE_ENABLES,
94+
MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT);
95+
return;
96+
}
97+
98+
msr_set_bit(MSR_MISC_FEATURE_ENABLES,
99+
MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT);
100+
101+
set_cpu_cap(c, X86_FEATURE_RING3MWAIT);
102+
103+
if (c == &boot_cpu_data)
104+
ELF_HWCAP2 |= HWCAP2_RING3MWAIT;
105+
}
106+
65107
static void early_init_intel(struct cpuinfo_x86 *c)
66108
{
67109
u64 misc_enable;
@@ -562,6 +604,8 @@ static void init_intel(struct cpuinfo_x86 *c)
562604
detect_vmx_virtcap(c);
563605

564606
init_intel_energy_perf(c);
607+
608+
probe_xeon_phi_r3mwait(c);
565609
}
566610

567611
#ifdef CONFIG_X86_32

arch/x86/kernel/fpu/xstate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void fpu__xstate_clear_all_cpu_caps(void)
7878
setup_clear_cpu_cap(X86_FEATURE_PKU);
7979
setup_clear_cpu_cap(X86_FEATURE_AVX512_4VNNIW);
8080
setup_clear_cpu_cap(X86_FEATURE_AVX512_4FMAPS);
81+
setup_clear_cpu_cap(X86_FEATURE_AVX512_VPOPCNTDQ);
8182
}
8283

8384
/*

tools/arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
#define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
289289
#define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */
290290
#define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */
291+
#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
291292
#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */
292293

293294
/* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */

0 commit comments

Comments
 (0)