Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753849AbcKHULJ (ORCPT ); Tue, 8 Nov 2016 15:11:09 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:56052 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750908AbcKHULG (ORCPT ); Tue, 8 Nov 2016 15:11:06 -0500 Date: Tue, 8 Nov 2016 21:06:31 +0100 (CET) From: Thomas Gleixner To: Kyle Huey cc: "Robert O'Callahan" , Andy Lutomirski , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Paolo Bonzini , =?ISO-8859-2?Q?Radim_Kr=E8m=E1=F8?= , Jeff Dike , Richard Weinberger , Alexander Viro , Shuah Khan , Dave Hansen , Borislav Petkov , Peter Zijlstra , Boris Ostrovsky , Len Brown , "Rafael J. Wysocki" , Dmitry Safonov , David Matlack , linux-kernel@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v10 6/7] x86/arch_prctl: Add ARCH_[GET|SET]_CPUID In-Reply-To: <20161108183956.4521-7-khuey@kylehuey.com> Message-ID: References: <20161108183956.4521-1-khuey@kylehuey.com> <20161108183956.4521-7-khuey@kylehuey.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2213 Lines: 68 On Tue, 8 Nov 2016, Kyle Huey wrote: > 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 > http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/virtualization-technology-flexmigration-application-note.pdf See previous mail. > +DECLARE_PER_CPU(u64, msr_misc_features_enables_shadow); > + > diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c > index 97a340d..7d364e4 100644 > --- a/arch/x86/kernel/cpu/scattered.c > +++ b/arch/x86/kernel/cpu/scattered.c > @@ -71,9 +71,14 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) > } > > for (mb = msr_bits; mb->feature; mb++) { > if (rdmsrl_safe(mb->msr, &msrval)) > continue; > if (msrval & (1ULL << mb->bit)) > set_cpu_cap(c, mb->feature); > } > + > + if (cpu_has(c, X86_FEATURE_CPUID_FAULT)) { > + rdmsrl(MSR_MISC_FEATURES_ENABLES, msrval); > + this_cpu_write(msr_misc_features_enables_shadow, msrval); > + } I'm not really happy about this placement. There is more stuff coming up which affects that MSR, so we should have a central place to handle it. The most obvious is here: > +DEFINE_PER_CPU(u64, msr_misc_features_enables_shadow); void msr_misc_features_enable_init(struct cpuinfo_x86 *c) { u64 val; if (rdmsrl_safe(MSR_MISC_FEATURES_ENABLES, val)) return; this_cpu_write(msr_misc_features_enables_shadow, val); } The upcoming ring3 mwait stuff can add its magic to tweak that MSR into this function. Stick the call at the end of init_scattered_cpuid_features() for now. I still need to figure out a proper place for it. > +static int set_cpuid_mode(struct task_struct *task, unsigned long val) > +{ > + /* Only disable_cpuid() if it is supported on this hardware. */ That comment makes no sense. > + if (!static_cpu_has(X86_FEATURE_CPUID_FAULT)) > + return -ENODEV; Thanks, tglx