mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-19 00:04:18 +00:00
While the GCC and Clang compilers already define __ASSEMBLER__ automatically when compiling assembly code, __ASSEMBLY__ is a macro that only gets defined by the Makefiles in the kernel. This can be very confusing when switching between userspace and kernelspace coding, or when dealing with UAPI headers that rather should use __ASSEMBLER__ instead. So let's standardize on the __ASSEMBLER__ macro that is provided by the compilers now. This is mostly a mechanical patch (done with a simple "sed -i" statement), with some manual tweaks in <asm/frame.h>, <asm/hw_irq.h> and <asm/setup.h> that mentioned this macro in comments with some missing underscores. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: Juergen Gross <jgross@suse.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/20250314071013.1575167-38-thuth@redhat.com
86 lines
2.0 KiB
C
86 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_FSGSBASE_H
|
|
#define _ASM_FSGSBASE_H
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#include <asm/msr.h>
|
|
|
|
/*
|
|
* Read/write a task's FSBASE or GSBASE. This returns the value that
|
|
* the FS/GS base would have (if the task were to be resumed). These
|
|
* work on the current task or on a non-running (typically stopped
|
|
* ptrace child) task.
|
|
*/
|
|
extern unsigned long x86_fsbase_read_task(struct task_struct *task);
|
|
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");
|
|
}
|
|
|
|
#include <asm/cpufeature.h>
|
|
|
|
/* Helper functions for reading/writing FS/GS base */
|
|
|
|
static inline unsigned long x86_fsbase_read_cpu(void)
|
|
{
|
|
unsigned long fsbase;
|
|
|
|
if (boot_cpu_has(X86_FEATURE_FSGSBASE))
|
|
fsbase = rdfsbase();
|
|
else
|
|
rdmsrl(MSR_FS_BASE, fsbase);
|
|
|
|
return fsbase;
|
|
}
|
|
|
|
static inline void x86_fsbase_write_cpu(unsigned long fsbase)
|
|
{
|
|
if (boot_cpu_has(X86_FEATURE_FSGSBASE))
|
|
wrfsbase(fsbase);
|
|
else
|
|
wrmsrl(MSR_FS_BASE, fsbase);
|
|
}
|
|
|
|
extern unsigned long x86_gsbase_read_cpu_inactive(void);
|
|
extern void x86_gsbase_write_cpu_inactive(unsigned long gsbase);
|
|
extern unsigned long x86_fsgsbase_read_task(struct task_struct *task,
|
|
unsigned short selector);
|
|
|
|
#endif /* CONFIG_X86_64 */
|
|
|
|
#endif /* __ASSEMBLER__ */
|
|
|
|
#endif /* _ASM_FSGSBASE_H */
|