security_features.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 unsigned long 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. static inline void security_ftr_set(unsigned long feature)
  21. {
  22. powerpc_security_features |= feature;
  23. }
  24. static inline void security_ftr_clear(unsigned long feature)
  25. {
  26. powerpc_security_features &= ~feature;
  27. }
  28. static inline bool security_ftr_enabled(unsigned long feature)
  29. {
  30. return !!(powerpc_security_features & feature);
  31. }
  32. // Features indicating support for Spectre/Meltdown mitigations
  33. // The L1-D cache can be flushed with ori r30,r30,0
  34. #define SEC_FTR_L1D_FLUSH_ORI30 0x0000000000000001ull
  35. // The L1-D cache can be flushed with mtspr 882,r0 (aka SPRN_TRIG2)
  36. #define SEC_FTR_L1D_FLUSH_TRIG2 0x0000000000000002ull
  37. // ori r31,r31,0 acts as a speculation barrier
  38. #define SEC_FTR_SPEC_BAR_ORI31 0x0000000000000004ull
  39. // Speculation past bctr is disabled
  40. #define SEC_FTR_BCCTRL_SERIALISED 0x0000000000000008ull
  41. // Entries in L1-D are private to a SMT thread
  42. #define SEC_FTR_L1D_THREAD_PRIV 0x0000000000000010ull
  43. // Indirect branch prediction cache disabled
  44. #define SEC_FTR_COUNT_CACHE_DISABLED 0x0000000000000020ull
  45. // Features indicating need for Spectre/Meltdown mitigations
  46. // The L1-D cache should be flushed on MSR[HV] 1->0 transition (hypervisor to guest)
  47. #define SEC_FTR_L1D_FLUSH_HV 0x0000000000000040ull
  48. // The L1-D cache should be flushed on MSR[PR] 0->1 transition (kernel to userspace)
  49. #define SEC_FTR_L1D_FLUSH_PR 0x0000000000000080ull
  50. // A speculation barrier should be used for bounds checks (Spectre variant 1)
  51. #define SEC_FTR_BNDS_CHK_SPEC_BAR 0x0000000000000100ull
  52. // Firmware configuration indicates user favours security over performance
  53. #define SEC_FTR_FAVOUR_SECURITY 0x0000000000000200ull
  54. // Features enabled by default
  55. #define SEC_FTR_DEFAULT \
  56. (SEC_FTR_L1D_FLUSH_HV | \
  57. SEC_FTR_L1D_FLUSH_PR | \
  58. SEC_FTR_BNDS_CHK_SPEC_BAR | \
  59. SEC_FTR_FAVOUR_SECURITY)
  60. #endif /* _ASM_POWERPC_SECURITY_FEATURES_H */