0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _ASM_X86_SMAP_H
0010 #define _ASM_X86_SMAP_H
0011
0012 #include <asm/nops.h>
0013 #include <asm/cpufeatures.h>
0014 #include <asm/alternative.h>
0015
0016
0017 #define __ASM_CLAC ".byte 0x0f,0x01,0xca"
0018 #define __ASM_STAC ".byte 0x0f,0x01,0xcb"
0019
0020 #ifdef __ASSEMBLY__
0021
0022 #define ASM_CLAC \
0023 ALTERNATIVE "", __ASM_CLAC, X86_FEATURE_SMAP
0024
0025 #define ASM_STAC \
0026 ALTERNATIVE "", __ASM_STAC, X86_FEATURE_SMAP
0027
0028 #else
0029
0030 static __always_inline void clac(void)
0031 {
0032
0033 alternative("", __ASM_CLAC, X86_FEATURE_SMAP);
0034 }
0035
0036 static __always_inline void stac(void)
0037 {
0038
0039 alternative("", __ASM_STAC, X86_FEATURE_SMAP);
0040 }
0041
0042 static __always_inline unsigned long smap_save(void)
0043 {
0044 unsigned long flags;
0045
0046 asm volatile ("# smap_save\n\t"
0047 ALTERNATIVE("", "pushf; pop %0; " __ASM_CLAC "\n\t",
0048 X86_FEATURE_SMAP)
0049 : "=rm" (flags) : : "memory", "cc");
0050
0051 return flags;
0052 }
0053
0054 static __always_inline void smap_restore(unsigned long flags)
0055 {
0056 asm volatile ("# smap_restore\n\t"
0057 ALTERNATIVE("", "push %0; popf\n\t",
0058 X86_FEATURE_SMAP)
0059 : : "g" (flags) : "memory", "cc");
0060 }
0061
0062
0063 #define ASM_CLAC \
0064 ALTERNATIVE("", __ASM_CLAC, X86_FEATURE_SMAP)
0065 #define ASM_STAC \
0066 ALTERNATIVE("", __ASM_STAC, X86_FEATURE_SMAP)
0067
0068 #endif
0069
0070 #endif