blob: bca4c743de77c6d80f21f1bb4aeb0e2a188d824b [file] [log] [blame]
Chang S. Baeb1378a52018-09-18 16:08:53 -07001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_FSGSBASE_H
Ingo Molnarec3a9412018-10-08 10:41:59 +02003#define _ASM_FSGSBASE_H
Chang S. Baeb1378a52018-09-18 16:08:53 -07004
5#ifndef __ASSEMBLY__
6
7#ifdef CONFIG_X86_64
8
9#include <asm/msr-index.h>
10
Chang S. Baeb1378a52018-09-18 16:08:53 -070011/*
Ingo Molnarec3a9412018-10-08 10:41:59 +020012 * Read/write a task's FSBASE or GSBASE. This returns the value that
Chang S. Baeb1378a52018-09-18 16:08:53 -070013 * the FS/GS base would have (if the task were to be resumed). These
Ingo Molnarec3a9412018-10-08 10:41:59 +020014 * work on the current task or on a non-running (typically stopped
15 * ptrace child) task.
Chang S. Baeb1378a52018-09-18 16:08:53 -070016 */
Ingo Molnarec3a9412018-10-08 10:41:59 +020017extern unsigned long x86_fsbase_read_task(struct task_struct *task);
18extern unsigned long x86_gsbase_read_task(struct task_struct *task);
Chang S. Bae87ab4682018-11-26 11:55:24 -080019extern void x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase);
20extern void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase);
Chang S. Baeb1378a52018-09-18 16:08:53 -070021
22/* Helper functions for reading/writing FS/GS base */
23
24static inline unsigned long x86_fsbase_read_cpu(void)
25{
26 unsigned long fsbase;
27
28 rdmsrl(MSR_FS_BASE, fsbase);
Ingo Molnarec3a9412018-10-08 10:41:59 +020029
Chang S. Baeb1378a52018-09-18 16:08:53 -070030 return fsbase;
31}
32
Chang S. Baeb1378a52018-09-18 16:08:53 -070033static inline unsigned long x86_gsbase_read_cpu_inactive(void)
34{
35 unsigned long gsbase;
36
37 rdmsrl(MSR_KERNEL_GS_BASE, gsbase);
Ingo Molnarec3a9412018-10-08 10:41:59 +020038
Chang S. Baeb1378a52018-09-18 16:08:53 -070039 return gsbase;
40}
41
Chang S. Bae87ab4682018-11-26 11:55:24 -080042static inline void x86_fsbase_write_cpu(unsigned long fsbase)
43{
44 wrmsrl(MSR_FS_BASE, fsbase);
45}
46
47static inline void x86_gsbase_write_cpu_inactive(unsigned long gsbase)
48{
49 wrmsrl(MSR_KERNEL_GS_BASE, gsbase);
50}
Chang S. Baeb1378a52018-09-18 16:08:53 -070051
52#endif /* CONFIG_X86_64 */
53
54#endif /* __ASSEMBLY__ */
55
56#endif /* _ASM_FSGSBASE_H */