lkml.org 
[lkml]   [2020]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v11 09/18] x86/fsgsbase/64: Add intrinsics for FSGSBASE instructions
    Date
    From: Andi Kleen <ak@linux.intel.com>

    [ luto: Rename the variables from FS and GS to FSBASE and GSBASE and
    make <asm/fsgsbase.h> safe to include on 32-bit kernels. ]

    Signed-off-by: Andi Kleen <ak@linux.intel.com>
    Signed-off-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    Reviewed-by: Andy Lutomirski <luto@kernel.org>
    Reviewed-by: Andi Kleen <ak@linux.intel.com>
    Reviewed-by: Tony Luck <tony.luck@intel.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Dave Hansen <dave.hansen@intel.com>
    Cc: Tony Luck <tony.luck@intel.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    ---
    arch/x86/include/asm/fsgsbase.h | 30 ++++++++++++++++++++++++++++++
    1 file changed, 30 insertions(+)

    diff --git a/arch/x86/include/asm/fsgsbase.h b/arch/x86/include/asm/fsgsbase.h
    index bca4c743de77c..fdd1177499b40 100644
    --- a/arch/x86/include/asm/fsgsbase.h
    +++ b/arch/x86/include/asm/fsgsbase.h
    @@ -19,6 +19,36 @@ extern unsigned long x86_gsbase_read_task(struct task_struct *task);
    extern void x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase);
    extern void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase);

    +/* Must be protected by X86_FEATURE_FSGSBASE check. */
    +
    +static __always_inline unsigned long rdfsbase(void)
    +{
    + unsigned long fsbase;
    +
    + asm volatile("rdfsbase %0" : "=r" (fsbase) :: "memory");
    +
    + return fsbase;
    +}
    +
    +static __always_inline unsigned long rdgsbase(void)
    +{
    + unsigned long gsbase;
    +
    + asm volatile("rdgsbase %0" : "=r" (gsbase) :: "memory");
    +
    + return gsbase;
    +}
    +
    +static __always_inline void wrfsbase(unsigned long fsbase)
    +{
    + asm volatile("wrfsbase %0" :: "r" (fsbase) : "memory");
    +}
    +
    +static __always_inline void wrgsbase(unsigned long gsbase)
    +{
    + asm volatile("wrgsbase %0" :: "r" (gsbase) : "memory");
    +}
    +
    /* Helper functions for reading/writing FS/GS base */

    static inline unsigned long x86_fsbase_read_cpu(void)
    --
    2.20.1
    \
     
     \ /
      Last update: 2020-05-09 19:38    [W:2.084 / U:0.016 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site