xref: /openbmc/linux/arch/x86/include/asm/fsgsbase.h (revision b1378a56)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_FSGSBASE_H
3 #define _ASM_FSGSBASE_H 1
4 
5 #ifndef __ASSEMBLY__
6 
7 #ifdef CONFIG_X86_64
8 
9 #include <asm/msr-index.h>
10 
11 unsigned long x86_fsgsbase_read_task(struct task_struct *task,
12 				     unsigned short selector);
13 
14 /*
15  * Read/write a task's fsbase or gsbase. This returns the value that
16  * the FS/GS base would have (if the task were to be resumed). These
17  * work on current or on a different non-running task.
18  */
19 unsigned long x86_fsbase_read_task(struct task_struct *task);
20 unsigned long x86_gsbase_read_task(struct task_struct *task);
21 int x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase);
22 int x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase);
23 
24 /* Helper functions for reading/writing FS/GS base */
25 
26 static inline unsigned long x86_fsbase_read_cpu(void)
27 {
28 	unsigned long fsbase;
29 
30 	rdmsrl(MSR_FS_BASE, fsbase);
31 	return fsbase;
32 }
33 
34 void x86_fsbase_write_cpu(unsigned long fsbase);
35 
36 static inline unsigned long x86_gsbase_read_cpu_inactive(void)
37 {
38 	unsigned long gsbase;
39 
40 	rdmsrl(MSR_KERNEL_GS_BASE, gsbase);
41 	return gsbase;
42 }
43 
44 void x86_gsbase_write_cpu_inactive(unsigned long gsbase);
45 
46 #endif /* CONFIG_X86_64 */
47 
48 #endif /* __ASSEMBLY__ */
49 
50 #endif /* _ASM_FSGSBASE_H */
51