WIP FPC-III support
[linux/fpc-iii.git] / arch / x86 / include / asm / fsgsbase.h
blob35cff5f2becf6bcbbdc34a890f29d3ba197e100d
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_FSGSBASE_H
3 #define _ASM_FSGSBASE_H
5 #ifndef __ASSEMBLY__
7 #ifdef CONFIG_X86_64
9 #include <asm/msr-index.h>
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.
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);
22 /* Must be protected by X86_FEATURE_FSGSBASE check. */
24 static __always_inline unsigned long rdfsbase(void)
26 unsigned long fsbase;
28 asm volatile("rdfsbase %0" : "=r" (fsbase) :: "memory");
30 return fsbase;
33 static __always_inline unsigned long rdgsbase(void)
35 unsigned long gsbase;
37 asm volatile("rdgsbase %0" : "=r" (gsbase) :: "memory");
39 return gsbase;
42 static __always_inline void wrfsbase(unsigned long fsbase)
44 asm volatile("wrfsbase %0" :: "r" (fsbase) : "memory");
47 static __always_inline void wrgsbase(unsigned long gsbase)
49 asm volatile("wrgsbase %0" :: "r" (gsbase) : "memory");
52 #include <asm/cpufeature.h>
54 /* Helper functions for reading/writing FS/GS base */
56 static inline unsigned long x86_fsbase_read_cpu(void)
58 unsigned long fsbase;
60 if (boot_cpu_has(X86_FEATURE_FSGSBASE))
61 fsbase = rdfsbase();
62 else
63 rdmsrl(MSR_FS_BASE, fsbase);
65 return fsbase;
68 static inline void x86_fsbase_write_cpu(unsigned long fsbase)
70 if (boot_cpu_has(X86_FEATURE_FSGSBASE))
71 wrfsbase(fsbase);
72 else
73 wrmsrl(MSR_FS_BASE, fsbase);
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);
81 #endif /* CONFIG_X86_64 */
83 #endif /* __ASSEMBLY__ */
85 #endif /* _ASM_FSGSBASE_H */