smap.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Supervisor Mode Access Prevention support
  3. *
  4. * Copyright (C) 2012 Intel Corporation
  5. * Author: H. Peter Anvin <hpa@linux.intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. */
  12. #ifndef _ASM_X86_SMAP_H
  13. #define _ASM_X86_SMAP_H
  14. #include <linux/stringify.h>
  15. #include <asm/nops.h>
  16. #include <asm/cpufeatures.h>
  17. /* "Raw" instruction opcodes */
  18. #define __ASM_CLAC .byte 0x0f,0x01,0xca
  19. #define __ASM_STAC .byte 0x0f,0x01,0xcb
  20. #ifdef __ASSEMBLY__
  21. #include <asm/alternative-asm.h>
  22. #ifdef CONFIG_X86_SMAP
  23. #define ASM_CLAC \
  24. ALTERNATIVE "", __stringify(__ASM_CLAC), X86_FEATURE_SMAP
  25. #define ASM_STAC \
  26. ALTERNATIVE "", __stringify(__ASM_STAC), X86_FEATURE_SMAP
  27. #else /* CONFIG_X86_SMAP */
  28. #define ASM_CLAC
  29. #define ASM_STAC
  30. #endif /* CONFIG_X86_SMAP */
  31. #else /* __ASSEMBLY__ */
  32. #include <asm/alternative.h>
  33. #ifdef CONFIG_X86_SMAP
  34. static __always_inline void clac(void)
  35. {
  36. /* Note: a barrier is implicit in alternative() */
  37. alternative("", __stringify(__ASM_CLAC), X86_FEATURE_SMAP);
  38. }
  39. static __always_inline void stac(void)
  40. {
  41. /* Note: a barrier is implicit in alternative() */
  42. alternative("", __stringify(__ASM_STAC), X86_FEATURE_SMAP);
  43. }
  44. /* These macros can be used in asm() statements */
  45. #define ASM_CLAC \
  46. ALTERNATIVE("", __stringify(__ASM_CLAC), X86_FEATURE_SMAP)
  47. #define ASM_STAC \
  48. ALTERNATIVE("", __stringify(__ASM_STAC), X86_FEATURE_SMAP)
  49. #else /* CONFIG_X86_SMAP */
  50. static inline void clac(void) { }
  51. static inline void stac(void) { }
  52. #define ASM_CLAC
  53. #define ASM_STAC
  54. #endif /* CONFIG_X86_SMAP */
  55. #endif /* __ASSEMBLY__ */
  56. #endif /* _ASM_X86_SMAP_H */