1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Supervisor Mode Access Prevention support
5 * Copyright (C) 2012 Intel Corporation
9 #ifndef _ASM_X86_SMAP_H
10 #define _ASM_X86_SMAP_H
13 #include <asm/cpufeatures.h>
14 #include <asm/alternative.h>
19 ALTERNATIVE "", "clac", X86_FEATURE_SMAP
22 ALTERNATIVE "", "stac", X86_FEATURE_SMAP
24 #else /* __ASSEMBLY__ */
26 static __always_inline void clac(void)
28 /* Note: a barrier is implicit in alternative() */
29 alternative("", "clac", X86_FEATURE_SMAP);
32 static __always_inline void stac(void)
34 /* Note: a barrier is implicit in alternative() */
35 alternative("", "stac", X86_FEATURE_SMAP);
38 static __always_inline unsigned long smap_save(void)
42 asm volatile ("# smap_save\n\t"
43 ALTERNATIVE("", "pushf; pop %0; " "clac" "\n\t",
45 : "=rm" (flags) : : "memory", "cc");
50 static __always_inline void smap_restore(unsigned long flags)
52 asm volatile ("# smap_restore\n\t"
53 ALTERNATIVE("", "push %0; popf\n\t",
55 : : "g" (flags) : "memory", "cc");
58 /* These macros can be used in asm() statements */
60 ALTERNATIVE("", "clac", X86_FEATURE_SMAP)
62 ALTERNATIVE("", "stac", X86_FEATURE_SMAP)
64 #endif /* __ASSEMBLY__ */
66 #endif /* _ASM_X86_SMAP_H */