spec_ctrl.txt 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ===================
  2. Speculation Control
  3. ===================
  4. Quite some CPUs have speculation-related misfeatures which are in
  5. fact vulnerabilities causing data leaks in various forms even across
  6. privilege domains.
  7. The kernel provides mitigation for such vulnerabilities in various
  8. forms. Some of these mitigations are compile-time configurable and some
  9. can be supplied on the kernel command line.
  10. There is also a class of mitigations which are very expensive, but they can
  11. be restricted to a certain set of processes or tasks in controlled
  12. environments. The mechanism to control these mitigations is via
  13. :manpage:`prctl(2)`.
  14. There are two prctl options which are related to this:
  15. * PR_GET_SPECULATION_CTRL
  16. * PR_SET_SPECULATION_CTRL
  17. PR_GET_SPECULATION_CTRL
  18. -----------------------
  19. PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature
  20. which is selected with arg2 of prctl(2). The return value uses bits 0-3 with
  21. the following meaning:
  22. ==== ===================== ===================================================
  23. Bit Define Description
  24. ==== ===================== ===================================================
  25. 0 PR_SPEC_PRCTL Mitigation can be controlled per task by
  26. PR_SET_SPECULATION_CTRL.
  27. 1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
  28. disabled.
  29. 2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
  30. enabled.
  31. 3 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A
  32. subsequent prctl(..., PR_SPEC_ENABLE) will fail.
  33. ==== ===================== ===================================================
  34. If all bits are 0 the CPU is not affected by the speculation misfeature.
  35. If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is
  36. available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation
  37. misfeature will fail.
  38. PR_SET_SPECULATION_CTRL
  39. -----------------------
  40. PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which
  41. is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand
  42. in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or
  43. PR_SPEC_FORCE_DISABLE.
  44. Common error codes
  45. ------------------
  46. ======= =================================================================
  47. Value Meaning
  48. ======= =================================================================
  49. EINVAL The prctl is not implemented by the architecture or unused
  50. prctl(2) arguments are not 0.
  51. ENODEV arg2 is selecting a not supported speculation misfeature.
  52. ======= =================================================================
  53. PR_SET_SPECULATION_CTRL error codes
  54. -----------------------------------
  55. ======= =================================================================
  56. Value Meaning
  57. ======= =================================================================
  58. 0 Success
  59. ERANGE arg3 is incorrect, i.e. it's neither PR_SPEC_ENABLE nor
  60. PR_SPEC_DISABLE nor PR_SPEC_FORCE_DISABLE.
  61. ENXIO Control of the selected speculation misfeature is not possible.
  62. See PR_GET_SPECULATION_CTRL.
  63. EPERM Speculation was disabled with PR_SPEC_FORCE_DISABLE and caller
  64. tried to enable it again.
  65. ======= =================================================================
  66. Speculation misfeature controls
  67. -------------------------------
  68. - PR_SPEC_STORE_BYPASS: Speculative Store Bypass
  69. Invocations:
  70. * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, 0, 0, 0);
  71. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);
  72. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
  73. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);