dexcr.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * POWER Dynamic Execution Control Facility (DEXCR)
  4. *
  5. * This header file contains helper functions and macros
  6. * required for all the DEXCR related test cases.
  7. */
  8. #ifndef _SELFTESTS_POWERPC_DEXCR_DEXCR_H
  9. #define _SELFTESTS_POWERPC_DEXCR_DEXCR_H
  10. #include <stdbool.h>
  11. #include <sys/prctl.h>
  12. #include <sys/types.h>
  13. #include "reg.h"
  14. #define DEXCR_PR_BIT(aspect) __MASK(63 - (32 + (aspect)))
  15. #define DEXCR_PR_SBHE DEXCR_PR_BIT(0)
  16. #define DEXCR_PR_IBRTPD DEXCR_PR_BIT(3)
  17. #define DEXCR_PR_SRAPD DEXCR_PR_BIT(4)
  18. #define DEXCR_PR_NPHIE DEXCR_PR_BIT(5)
  19. #define PPC_RAW_HASH_ARGS(b, i, a) \
  20. ((((i) >> 3) & 0x1F) << 21 | (a) << 16 | (b) << 11 | (((i) >> 8) & 0x1))
  21. #define PPC_RAW_HASHST(b, i, a) \
  22. str(.long (0x7C0005A4 | PPC_RAW_HASH_ARGS(b, i, a));)
  23. #define PPC_RAW_HASHCHK(b, i, a) \
  24. str(.long (0x7C0005E4 | PPC_RAW_HASH_ARGS(b, i, a));)
  25. struct dexcr_aspect {
  26. const char *name; /* Short display name */
  27. const char *opt; /* Option name for chdexcr */
  28. const char *desc; /* Expanded aspect meaning */
  29. unsigned int index; /* Aspect bit index in DEXCR */
  30. unsigned long prctl; /* 'which' value for get/set prctl */
  31. };
  32. static const struct dexcr_aspect aspects[] = {
  33. {
  34. .name = "SBHE",
  35. .opt = "sbhe",
  36. .desc = "Speculative branch hint enable",
  37. .index = 0,
  38. .prctl = PR_PPC_DEXCR_SBHE,
  39. },
  40. {
  41. .name = "IBRTPD",
  42. .opt = "ibrtpd",
  43. .desc = "Indirect branch recurrent target prediction disable",
  44. .index = 3,
  45. .prctl = PR_PPC_DEXCR_IBRTPD,
  46. },
  47. {
  48. .name = "SRAPD",
  49. .opt = "srapd",
  50. .desc = "Subroutine return address prediction disable",
  51. .index = 4,
  52. .prctl = PR_PPC_DEXCR_SRAPD,
  53. },
  54. {
  55. .name = "NPHIE",
  56. .opt = "nphie",
  57. .desc = "Non-privileged hash instruction enable",
  58. .index = 5,
  59. .prctl = PR_PPC_DEXCR_NPHIE,
  60. },
  61. {
  62. .name = "PHIE",
  63. .opt = "phie",
  64. .desc = "Privileged hash instruction enable",
  65. .index = 6,
  66. .prctl = -1,
  67. },
  68. };
  69. bool dexcr_exists(void);
  70. bool pr_dexcr_aspect_supported(unsigned long which);
  71. bool pr_dexcr_aspect_editable(unsigned long which);
  72. int pr_get_dexcr(unsigned long pr_aspect);
  73. int pr_set_dexcr(unsigned long pr_aspect, unsigned long ctrl);
  74. unsigned int pr_which_to_aspect(unsigned long which);
  75. bool hashchk_triggers(void);
  76. enum dexcr_source {
  77. DEXCR, /* Userspace DEXCR value */
  78. HDEXCR, /* Hypervisor enforced DEXCR value */
  79. EFFECTIVE, /* Bitwise OR of UDEXCR and ENFORCED DEXCR bits */
  80. };
  81. unsigned int get_dexcr(enum dexcr_source source);
  82. void await_child_success(pid_t pid);
  83. void hashst(unsigned long lr, void *sp);
  84. void hashchk(unsigned long lr, void *sp);
  85. void do_bad_hashchk(void);
  86. #endif /* _SELFTESTS_POWERPC_DEXCR_DEXCR_H */