aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/intel.c
diff options
context:
space:
mode:
authorKyle Huey <me@kylehuey.com>2017-03-20 04:16:26 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-03-20 11:10:34 -0400
commite9ea1e7f53b852147cbd568b0568c7ad97ec21a3 (patch)
treefd7046c239c106887b0928cdcf55913eff19c798 /arch/x86/kernel/cpu/intel.c
parent90218ac77d0582eaf2d0872d8d900cbd5bf1f205 (diff)
x86/arch_prctl: Add ARCH_[GET|SET]_CPUID
Intel supports faulting on the CPUID instruction beginning with Ivy Bridge. When enabled, the processor will fault on attempts to execute the CPUID instruction with CPL>0. Exposing this feature to userspace will allow a ptracer to trap and emulate the CPUID instruction. When supported, this feature is controlled by toggling bit 0 of MSR_MISC_FEATURES_ENABLES. It is documented in detail in Section 2.3.2 of https://bugzilla.kernel.org/attachment.cgi?id=243991 Implement a new pair of arch_prctls, available on both x86-32 and x86-64. ARCH_GET_CPUID: Returns the current CPUID state, either 0 if CPUID faulting is enabled (and thus the CPUID instruction is not available) or 1 if CPUID faulting is not enabled. ARCH_SET_CPUID: Set the CPUID state to the second argument. If cpuid_enabled is 0 CPUID faulting will be activated, otherwise it will be deactivated. Returns ENODEV if CPUID faulting is not supported on this system. The state of the CPUID faulting flag is propagated across forks, but reset upon exec. Signed-off-by: Kyle Huey <khuey@kylehuey.com> Cc: Grzegorz Andrejczuk <grzegorz.andrejczuk@intel.com> Cc: kvm@vger.kernel.org Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: linux-kselftest@vger.kernel.org Cc: Nadav Amit <nadav.amit@gmail.com> Cc: Robert O'Callahan <robert@ocallahan.org> Cc: Richard Weinberger <richard@nod.at> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: Len Brown <len.brown@intel.com> Cc: Shuah Khan <shuah@kernel.org> Cc: user-mode-linux-devel@lists.sourceforge.net Cc: Jeff Dike <jdike@addtoit.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: user-mode-linux-user@lists.sourceforge.net Cc: David Matlack <dmatlack@google.com> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Dmitry Safonov <dsafonov@virtuozzo.com> Cc: linux-fsdevel@vger.kernel.org Cc: Paolo Bonzini <pbonzini@redhat.com> Link: http://lkml.kernel.org/r/20170320081628.18952-9-khuey@kylehuey.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/cpu/intel.c')
-rw-r--r--arch/x86/kernel/cpu/intel.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index a07f8295c9ed..dfa90a3a5145 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -90,16 +90,12 @@ static void probe_xeon_phi_r3mwait(struct cpuinfo_x86 *c)
90 return; 90 return;
91 } 91 }
92 92
93 if (ring3mwait_disabled) { 93 if (ring3mwait_disabled)
94 msr_clear_bit(MSR_MISC_FEATURES_ENABLES,
95 MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT);
96 return; 94 return;
97 }
98
99 msr_set_bit(MSR_MISC_FEATURES_ENABLES,
100 MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT);
101 95
102 set_cpu_cap(c, X86_FEATURE_RING3MWAIT); 96 set_cpu_cap(c, X86_FEATURE_RING3MWAIT);
97 this_cpu_or(msr_misc_features_shadow,
98 1UL << MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT);
103 99
104 if (c == &boot_cpu_data) 100 if (c == &boot_cpu_data)
105 ELF_HWCAP2 |= HWCAP2_RING3MWAIT; 101 ELF_HWCAP2 |= HWCAP2_RING3MWAIT;
@@ -505,9 +501,15 @@ static void init_intel_misc_features(struct cpuinfo_x86 *c)
505 if (rdmsrl_safe(MSR_MISC_FEATURES_ENABLES, &msr)) 501 if (rdmsrl_safe(MSR_MISC_FEATURES_ENABLES, &msr))
506 return; 502 return;
507 503
508 /* Check features and update capabilities */ 504 /* Clear all MISC features */
505 this_cpu_write(msr_misc_features_shadow, 0);
506
507 /* Check features and update capabilities and shadow control bits */
509 init_cpuid_fault(c); 508 init_cpuid_fault(c);
510 probe_xeon_phi_r3mwait(c); 509 probe_xeon_phi_r3mwait(c);
510
511 msr = this_cpu_read(msr_misc_features_shadow);
512 wrmsrl(MSR_MISC_FEATURES_ENABLES, msr);
511} 513}
512 514
513static void init_intel(struct cpuinfo_x86 *c) 515static void init_intel(struct cpuinfo_x86 *c)