~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/fsgsbase.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _ASM_FSGSBASE_H
  3 #define _ASM_FSGSBASE_H
  4 
  5 #ifndef __ASSEMBLY__
  6 
  7 #ifdef CONFIG_X86_64
  8 
  9 #include <asm/msr.h>
 10 
 11 /*
 12  * Read/write a task's FSBASE or GSBASE. This returns the value that
 13  * the FS/GS base would have (if the task were to be resumed). These
 14  * work on the current task or on a non-running (typically stopped
 15  * ptrace child) task.
 16  */
 17 extern unsigned long x86_fsbase_read_task(struct task_struct *task);
 18 extern unsigned long x86_gsbase_read_task(struct task_struct *task);
 19 extern void x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase);
 20 extern void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase);
 21 
 22 /* Must be protected by X86_FEATURE_FSGSBASE check. */
 23 
 24 static __always_inline unsigned long rdfsbase(void)
 25 {
 26         unsigned long fsbase;
 27 
 28         asm volatile("rdfsbase %0" : "=r" (fsbase) :: "memory");
 29 
 30         return fsbase;
 31 }
 32 
 33 static __always_inline unsigned long rdgsbase(void)
 34 {
 35         unsigned long gsbase;
 36 
 37         asm volatile("rdgsbase %0" : "=r" (gsbase) :: "memory");
 38 
 39         return gsbase;
 40 }
 41 
 42 static __always_inline void wrfsbase(unsigned long fsbase)
 43 {
 44         asm volatile("wrfsbase %0" :: "r" (fsbase) : "memory");
 45 }
 46 
 47 static __always_inline void wrgsbase(unsigned long gsbase)
 48 {
 49         asm volatile("wrgsbase %0" :: "r" (gsbase) : "memory");
 50 }
 51 
 52 #include <asm/cpufeature.h>
 53 
 54 /* Helper functions for reading/writing FS/GS base */
 55 
 56 static inline unsigned long x86_fsbase_read_cpu(void)
 57 {
 58         unsigned long fsbase;
 59 
 60         if (boot_cpu_has(X86_FEATURE_FSGSBASE))
 61                 fsbase = rdfsbase();
 62         else
 63                 rdmsrl(MSR_FS_BASE, fsbase);
 64 
 65         return fsbase;
 66 }
 67 
 68 static inline void x86_fsbase_write_cpu(unsigned long fsbase)
 69 {
 70         if (boot_cpu_has(X86_FEATURE_FSGSBASE))
 71                 wrfsbase(fsbase);
 72         else
 73                 wrmsrl(MSR_FS_BASE, fsbase);
 74 }
 75 
 76 extern unsigned long x86_gsbase_read_cpu_inactive(void);
 77 extern void x86_gsbase_write_cpu_inactive(unsigned long gsbase);
 78 extern unsigned long x86_fsgsbase_read_task(struct task_struct *task,
 79                                             unsigned short selector);
 80 
 81 #endif /* CONFIG_X86_64 */
 82 
 83 #endif /* __ASSEMBLY__ */
 84 
 85 #endif /* _ASM_FSGSBASE_H */
 86 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php