Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757721AbcCUSOw (ORCPT ); Mon, 21 Mar 2016 14:14:52 -0400 Received: from mail-ob0-f170.google.com ([209.85.214.170]:34841 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757696AbcCUSOv (ORCPT ); Mon, 21 Mar 2016 14:14:51 -0400 MIME-Version: 1.0 In-Reply-To: <1458576969-13309-2-git-send-email-andi@firstfloor.org> References: <1458576969-13309-1-git-send-email-andi@firstfloor.org> <1458576969-13309-2-git-send-email-andi@firstfloor.org> From: Andy Lutomirski Date: Mon, 21 Mar 2016 11:14:30 -0700 Message-ID: Subject: Re: [PATCH 1/9] x86: Add intrinsics/macros for new rd/wr fs/gs base instructions To: Andi Kleen Cc: X86 ML , "linux-kernel@vger.kernel.org" , Andi Kleen Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1845 Lines: 65 On Mon, Mar 21, 2016 at 9:16 AM, Andi Kleen wrote: > From: Andi Kleen > > Add C intrinsics and assembler macros for the new rd/wr fs/gs base > instructions and for swapgs. > > Very straight forward. Used in followon patch. > > For assembler only a few standard registers used by entry_64.S > are defined. > > v2: Use __always_inline > Signed-off-by: Andi Kleen > --- > arch/x86/include/asm/fsgs.h | 54 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 54 insertions(+) > create mode 100644 arch/x86/include/asm/fsgs.h > > diff --git a/arch/x86/include/asm/fsgs.h b/arch/x86/include/asm/fsgs.h > new file mode 100644 > index 0000000..8a9f900 > --- /dev/null > +++ b/arch/x86/include/asm/fsgs.h > @@ -0,0 +1,54 @@ > +#ifndef _ASM_FSGS_H > +#define _ASM_FSGS_H 1 > + > +#ifndef __ASSEMBLY__ > + > +static __always_inline void swapgs(void) > +{ > + asm volatile("swapgs" ::: "memory"); > +} > + > +/* Must be protected by X86_FEATURE_FSGSBASE check. */ > + > +static __always_inline unsigned long rdgsbase(void) > +{ > + unsigned long gs; > + asm volatile(".byte 0xf3,0x48,0x0f,0xae,0xc8 # rdgsbaseq %%rax" > + : "=a" (gs) > + :: "memory"); > + return gs; > +} > + > +static __always_inline unsigned long rdfsbase(void) > +{ > + unsigned long fs; > + asm volatile(".byte 0xf3,0x48,0x0f,0xae,0xc0 # rdfsbaseq %%rax" > + : "=a" (fs) > + :: "memory"); > + return fs; > +} > + > +static __always_inline void wrgsbase(unsigned long gs) > +{ > + asm volatile(".byte 0xf3,0x48,0x0f,0xae,0xd8 # wrgsbaseq %%rax" > + :: "a" (gs) > + : "memory"); > +} > + "unsigned long gsbase", perhaps? --Andy