Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752189AbcDUMRB (ORCPT ); Thu, 21 Apr 2016 08:17:01 -0400 Received: from mail.skyhub.de ([78.46.96.112]:35089 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751738AbcDUMRA (ORCPT ); Thu, 21 Apr 2016 08:17:00 -0400 Date: Thu, 21 Apr 2016 14:16:40 +0200 From: Borislav Petkov To: Andy Lutomirski Cc: x86@kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] x86/vdso: Use RDPID in preference to LSL when available Message-ID: <20160421121640.GC28821@pd.tnic> References: <2452e4bba35cf473d975a90d90533cf580a012f3.1461201316.git.luto@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2452e4bba35cf473d975a90d90533cf580a012f3.1461201316.git.luto@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2374 Lines: 60 On Wed, Apr 20, 2016 at 06:16:01PM -0700, Andy Lutomirski wrote: > Also, it's time for someone to do UMIP. I'll see if I can convince > someone in KVM land to emulate it to make it easier to test. That'll be fun - we can simply set that bit in CR4 and see who screams :-P > Changes from v1: > - Remove rdpid() from special_instructions.h. (Was a leftover -- sorry.) > > arch/x86/include/asm/cpufeatures.h | 1 + > arch/x86/include/asm/vgtod.h | 7 ++++++- > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index 7bfb6b70c745..beaf2fb601ee 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -279,6 +279,7 @@ > /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */ > #define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */ > #define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */ > +#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */ > > /* > * BUG word(s) > diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h > index e728699db774..3a01996db58f 100644 > --- a/arch/x86/include/asm/vgtod.h > +++ b/arch/x86/include/asm/vgtod.h > @@ -89,8 +89,13 @@ static inline unsigned int __getcpu(void) > * works on all CPUs. This is volatile so that it orders > * correctly wrt barrier() and to keep gcc from cleverly > * hoisting it out of the calling function. > + * > + * If RDPID is available, use it. > */ > - asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG)); > + alternative_io ("lsl %[p],%[seg]", > + ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ AFAICT, 0xf8 is correct, if I'm reading the SDM right: bits [7:6] must be 11b for opcode group 9 and RDPID is in the 11b row, bits [5:3] are ModRM.reg and they need to be 111b for RDPID (0x7 column) and the last three [2:0] select the register and they must be 000b for rAX. HOWEVER, you need to make the asm output register constraint "=a" because you're specifying rAX as a destination register for RDPID. Also, I'm wondering: should we supply that alternative in a separate inline function in special_instructions.h for wider use? I.e., something like read_cpu_num() or so... -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply.