1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _ASM_X86_GSSEG_H
3 #define _ASM_X86_GSSEG_H
5 #include <linux/types.h>
8 #include <asm/cpufeature.h>
9 #include <asm/alternative.h>
10 #include <asm/processor.h>
15 extern asmlinkage void asm_load_gs_index(u16 selector);
17 /* Replace with "lkgs %di" once binutils support LKGS instruction */
18 #define LKGS_DI _ASM_BYTES(0xf2,0x0f,0x00,0xf7)
20 static inline void native_lkgs(unsigned int selector)
23 asm_inline volatile("1: " LKGS_DI
24 _ASM_EXTABLE_TYPE_REG(1b, 1b, EX_TYPE_ZERO_REG, %k[sel])
28 static inline void native_load_gs_index(unsigned int selector)
30 if (cpu_feature_enabled(X86_FEATURE_LKGS)) {
31 native_lkgs(selector);
35 local_irq_save(flags);
36 asm_load_gs_index(selector);
37 local_irq_restore(flags);
41 #endif /* CONFIG_X86_64 */
43 static inline void __init lkgs_init(void)
45 #ifdef CONFIG_PARAVIRT_XXL
47 if (cpu_feature_enabled(X86_FEATURE_LKGS))
48 pv_ops.cpu.load_gs_index = native_lkgs;
53 #ifndef CONFIG_PARAVIRT_XXL
55 static inline void load_gs_index(unsigned int selector)
58 native_load_gs_index(selector);
60 loadsegment(gs, selector);
64 #endif /* CONFIG_PARAVIRT_XXL */
66 #endif /* _ASM_X86_GSSEG_H */