xstate.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Using XSTATE features in user space applications
  2. ================================================
  3. The x86 architecture supports floating-point extensions which are
  4. enumerated via CPUID. Applications consult CPUID and use XGETBV to
  5. evaluate which features have been enabled by the kernel XCR0.
  6. Up to AVX-512 and PKRU states, these features are automatically enabled by
  7. the kernel if available. Features like AMX TILE_DATA (XSTATE component 18)
  8. are enabled by XCR0 as well, but the first use of related instruction is
  9. trapped by the kernel because by default the required large XSTATE buffers
  10. are not allocated automatically.
  11. Using dynamically enabled XSTATE features in user space applications
  12. --------------------------------------------------------------------
  13. The kernel provides an arch_prctl(2) based mechanism for applications to
  14. request the usage of such features. The arch_prctl(2) options related to
  15. this are:
  16. -ARCH_GET_XCOMP_SUPP
  17. arch_prctl(ARCH_GET_XCOMP_SUPP, &features);
  18. ARCH_GET_XCOMP_SUPP stores the supported features in userspace storage of
  19. type uint64_t. The second argument is a pointer to that storage.
  20. -ARCH_GET_XCOMP_PERM
  21. arch_prctl(ARCH_GET_XCOMP_PERM, &features);
  22. ARCH_GET_XCOMP_PERM stores the features for which the userspace process
  23. has permission in userspace storage of type uint64_t. The second argument
  24. is a pointer to that storage.
  25. -ARCH_REQ_XCOMP_PERM
  26. arch_prctl(ARCH_REQ_XCOMP_PERM, feature_nr);
  27. ARCH_REQ_XCOMP_PERM allows to request permission for a dynamically enabled
  28. feature or a feature set. A feature set can be mapped to a facility, e.g.
  29. AMX, and can require one or more XSTATE components to be enabled.
  30. The feature argument is the number of the highest XSTATE component which
  31. is required for a facility to work.
  32. When requesting permission for a feature, the kernel checks the
  33. availability. The kernel ensures that sigaltstacks in the process's tasks
  34. are large enough to accommodate the resulting large signal frame. It
  35. enforces this both during ARCH_REQ_XCOMP_SUPP and during any subsequent
  36. sigaltstack(2) calls. If an installed sigaltstack is smaller than the
  37. resulting sigframe size, ARCH_REQ_XCOMP_SUPP results in -ENOSUPP. Also,
  38. sigaltstack(2) results in -ENOMEM if the requested altstack is too small
  39. for the permitted features.
  40. Permission, when granted, is valid per process. Permissions are inherited
  41. on fork(2) and cleared on exec(3).
  42. The first use of an instruction related to a dynamically enabled feature is
  43. trapped by the kernel. The trap handler checks whether the process has
  44. permission to use the feature. If the process has no permission then the
  45. kernel sends SIGILL to the application. If the process has permission then
  46. the handler allocates a larger xstate buffer for the task so the large
  47. state can be context switched. In the unlikely cases that the allocation
  48. fails, the kernel sends SIGSEGV.
  49. Dynamic features in signal frames
  50. ---------------------------------
  51. Dynamcally enabled features are not written to the signal frame upon signal
  52. entry if the feature is in its initial configuration. This differs from
  53. non-dynamic features which are always written regardless of their
  54. configuration. Signal handlers can examine the XSAVE buffer's XSTATE_BV
  55. field to determine if a features was written.