security_features.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Security related feature bit definitions.
  4. *
  5. * Copyright 2018, Michael Ellerman, IBM Corporation.
  6. */
  7. #ifndef _ASM_POWERPC_SECURITY_FEATURES_H
  8. #define _ASM_POWERPC_SECURITY_FEATURES_H
  9. extern u64 powerpc_security_features;
  10. extern bool rfi_flush;
  11. /* These are bit flags */
  12. enum stf_barrier_type {
  13. STF_BARRIER_NONE = 0x1,
  14. STF_BARRIER_FALLBACK = 0x2,
  15. STF_BARRIER_EIEIO = 0x4,
  16. STF_BARRIER_SYNC_ORI = 0x8,
  17. };
  18. void setup_stf_barrier(void);
  19. void do_stf_barrier_fixups(enum stf_barrier_type types);
  20. void setup_count_cache_flush(void);
  21. static inline void security_ftr_set(u64 feature)
  22. {
  23. powerpc_security_features |= feature;
  24. }
  25. static inline void security_ftr_clear(u64 feature)
  26. {
  27. powerpc_security_features &= ~feature;
  28. }
  29. static inline bool security_ftr_enabled(u64 feature)
  30. {
  31. return !!(powerpc_security_features & feature);
  32. }
  33. #ifdef CONFIG_PPC_BOOK3S_64
  34. enum stf_barrier_type stf_barrier_type_get(void);
  35. #else
  36. static inline enum stf_barrier_type stf_barrier_type_get(void) { return STF_BARRIER_NONE; }
  37. #endif
  38. // Features indicating support for Spectre/Meltdown mitigations
  39. // The L1-D cache can be flushed with ori r30,r30,0
  40. #define SEC_FTR_L1D_FLUSH_ORI30 0x0000000000000001ull
  41. // The L1-D cache can be flushed with mtspr 882,r0 (aka SPRN_TRIG2)
  42. #define SEC_FTR_L1D_FLUSH_TRIG2 0x0000000000000002ull
  43. // ori r31,r31,0 acts as a speculation barrier
  44. #define SEC_FTR_SPEC_BAR_ORI31 0x0000000000000004ull
  45. // Speculation past bctr is disabled
  46. #define SEC_FTR_BCCTRL_SERIALISED 0x0000000000000008ull
  47. // Entries in L1-D are private to a SMT thread
  48. #define SEC_FTR_L1D_THREAD_PRIV 0x0000000000000010ull
  49. // Indirect branch prediction cache disabled
  50. #define SEC_FTR_COUNT_CACHE_DISABLED 0x0000000000000020ull
  51. // bcctr 2,0,0 triggers a hardware assisted count cache flush
  52. #define SEC_FTR_BCCTR_FLUSH_ASSIST 0x0000000000000800ull
  53. // bcctr 2,0,0 triggers a hardware assisted link stack flush
  54. #define SEC_FTR_BCCTR_LINK_FLUSH_ASSIST 0x0000000000002000ull
  55. // Features indicating need for Spectre/Meltdown mitigations
  56. // The L1-D cache should be flushed on MSR[HV] 1->0 transition (hypervisor to guest)
  57. #define SEC_FTR_L1D_FLUSH_HV 0x0000000000000040ull
  58. // The L1-D cache should be flushed on MSR[PR] 0->1 transition (kernel to userspace)
  59. #define SEC_FTR_L1D_FLUSH_PR 0x0000000000000080ull
  60. // A speculation barrier should be used for bounds checks (Spectre variant 1)
  61. #define SEC_FTR_BNDS_CHK_SPEC_BAR 0x0000000000000100ull
  62. // Firmware configuration indicates user favours security over performance
  63. #define SEC_FTR_FAVOUR_SECURITY 0x0000000000000200ull
  64. // Software required to flush count cache on context switch
  65. #define SEC_FTR_FLUSH_COUNT_CACHE 0x0000000000000400ull
  66. // Software required to flush link stack on context switch
  67. #define SEC_FTR_FLUSH_LINK_STACK 0x0000000000001000ull
  68. // The L1-D cache should be flushed when entering the kernel
  69. #define SEC_FTR_L1D_FLUSH_ENTRY 0x0000000000004000ull
  70. // The L1-D cache should be flushed after user accesses from the kernel
  71. #define SEC_FTR_L1D_FLUSH_UACCESS 0x0000000000008000ull
  72. // The STF flush should be executed on privilege state switch
  73. #define SEC_FTR_STF_BARRIER 0x0000000000010000ull
  74. // Features enabled by default
  75. #define SEC_FTR_DEFAULT \
  76. (SEC_FTR_L1D_FLUSH_HV | \
  77. SEC_FTR_L1D_FLUSH_PR | \
  78. SEC_FTR_BNDS_CHK_SPEC_BAR | \
  79. SEC_FTR_L1D_FLUSH_ENTRY | \
  80. SEC_FTR_L1D_FLUSH_UACCESS | \
  81. SEC_FTR_STF_BARRIER | \
  82. SEC_FTR_FAVOUR_SECURITY)
  83. #endif /* _ASM_POWERPC_SECURITY_FEATURES_H */