xstate.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_X86_XSAVE_H
  3. #define __ASM_X86_XSAVE_H
  4. #include <linux/uaccess.h>
  5. #include <linux/types.h>
  6. #include <asm/processor.h>
  7. #include <asm/fpu/api.h>
  8. #include <asm/user.h>
  9. /* Bit 63 of XCR0 is reserved for future expansion */
  10. #define XFEATURE_MASK_EXTEND (~(XFEATURE_MASK_FPSSE | (1ULL << 63)))
  11. #define XSTATE_CPUID 0x0000000d
  12. #define TILE_CPUID 0x0000001d
  13. #define FXSAVE_SIZE 512
  14. #define XSAVE_HDR_SIZE 64
  15. #define XSAVE_HDR_OFFSET FXSAVE_SIZE
  16. #define XSAVE_YMM_SIZE 256
  17. #define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET)
  18. #define XSAVE_ALIGNMENT 64
  19. /* All currently supported user features */
  20. #define XFEATURE_MASK_USER_SUPPORTED (XFEATURE_MASK_FP | \
  21. XFEATURE_MASK_SSE | \
  22. XFEATURE_MASK_YMM | \
  23. XFEATURE_MASK_OPMASK | \
  24. XFEATURE_MASK_ZMM_Hi256 | \
  25. XFEATURE_MASK_Hi16_ZMM | \
  26. XFEATURE_MASK_PKRU | \
  27. XFEATURE_MASK_BNDREGS | \
  28. XFEATURE_MASK_BNDCSR | \
  29. XFEATURE_MASK_XTILE)
  30. /*
  31. * Features which are restored when returning to user space.
  32. * PKRU is not restored on return to user space because PKRU
  33. * is switched eagerly in switch_to() and flush_thread()
  34. */
  35. #define XFEATURE_MASK_USER_RESTORE \
  36. (XFEATURE_MASK_USER_SUPPORTED & ~XFEATURE_MASK_PKRU)
  37. /* Features which are dynamically enabled for a process on request */
  38. #define XFEATURE_MASK_USER_DYNAMIC XFEATURE_MASK_XTILE_DATA
  39. /* All currently supported supervisor features */
  40. #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID)
  41. /*
  42. * A supervisor state component may not always contain valuable information,
  43. * and its size may be huge. Saving/restoring such supervisor state components
  44. * at each context switch can cause high CPU and space overhead, which should
  45. * be avoided. Such supervisor state components should only be saved/restored
  46. * on demand. The on-demand supervisor features are set in this mask.
  47. *
  48. * Unlike the existing supported supervisor features, an independent supervisor
  49. * feature does not allocate a buffer in task->fpu, and the corresponding
  50. * supervisor state component cannot be saved/restored at each context switch.
  51. *
  52. * To support an independent supervisor feature, a developer should follow the
  53. * dos and don'ts as below:
  54. * - Do dynamically allocate a buffer for the supervisor state component.
  55. * - Do manually invoke the XSAVES/XRSTORS instruction to save/restore the
  56. * state component to/from the buffer.
  57. * - Don't set the bit corresponding to the independent supervisor feature in
  58. * IA32_XSS at run time, since it has been set at boot time.
  59. */
  60. #define XFEATURE_MASK_INDEPENDENT (XFEATURE_MASK_LBR)
  61. /*
  62. * Unsupported supervisor features. When a supervisor feature in this mask is
  63. * supported in the future, move it to the supported supervisor feature mask.
  64. */
  65. #define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT)
  66. /* All supervisor states including supported and unsupported states. */
  67. #define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED | \
  68. XFEATURE_MASK_INDEPENDENT | \
  69. XFEATURE_MASK_SUPERVISOR_UNSUPPORTED)
  70. /*
  71. * The feature mask required to restore FPU state:
  72. * - All user states which are not eagerly switched in switch_to()/exec()
  73. * - The suporvisor states
  74. */
  75. #define XFEATURE_MASK_FPSTATE (XFEATURE_MASK_USER_RESTORE | \
  76. XFEATURE_MASK_SUPERVISOR_SUPPORTED)
  77. /*
  78. * Features in this mask have space allocated in the signal frame, but may not
  79. * have that space initialized when the feature is in its init state.
  80. */
  81. #define XFEATURE_MASK_SIGFRAME_INITOPT (XFEATURE_MASK_XTILE | \
  82. XFEATURE_MASK_USER_DYNAMIC)
  83. extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
  84. extern void __init update_regset_xstate_info(unsigned int size,
  85. u64 xstate_mask);
  86. int xfeature_size(int xfeature_nr);
  87. void xsaves(struct xregs_state *xsave, u64 mask);
  88. void xrstors(struct xregs_state *xsave, u64 mask);
  89. int xfd_enable_feature(u64 xfd_err);
  90. #ifdef CONFIG_X86_64
  91. DECLARE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
  92. #endif
  93. #ifdef CONFIG_X86_64
  94. DECLARE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
  95. static __always_inline __pure bool fpu_state_size_dynamic(void)
  96. {
  97. return static_branch_unlikely(&__fpu_state_size_dynamic);
  98. }
  99. #else
  100. static __always_inline __pure bool fpu_state_size_dynamic(void)
  101. {
  102. return false;
  103. }
  104. #endif
  105. #endif