Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_X86_XSAVE_H
0003 #define __ASM_X86_XSAVE_H
0004 
0005 #include <linux/uaccess.h>
0006 #include <linux/types.h>
0007 
0008 #include <asm/processor.h>
0009 #include <asm/fpu/api.h>
0010 #include <asm/user.h>
0011 
0012 /* Bit 63 of XCR0 is reserved for future expansion */
0013 #define XFEATURE_MASK_EXTEND    (~(XFEATURE_MASK_FPSSE | (1ULL << 63)))
0014 
0015 #define XSTATE_CPUID        0x0000000d
0016 
0017 #define TILE_CPUID      0x0000001d
0018 
0019 #define FXSAVE_SIZE 512
0020 
0021 #define XSAVE_HDR_SIZE      64
0022 #define XSAVE_HDR_OFFSET    FXSAVE_SIZE
0023 
0024 #define XSAVE_YMM_SIZE      256
0025 #define XSAVE_YMM_OFFSET    (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET)
0026 
0027 #define XSAVE_ALIGNMENT     64
0028 
0029 /* All currently supported user features */
0030 #define XFEATURE_MASK_USER_SUPPORTED (XFEATURE_MASK_FP | \
0031                       XFEATURE_MASK_SSE | \
0032                       XFEATURE_MASK_YMM | \
0033                       XFEATURE_MASK_OPMASK | \
0034                       XFEATURE_MASK_ZMM_Hi256 | \
0035                       XFEATURE_MASK_Hi16_ZMM     | \
0036                       XFEATURE_MASK_PKRU | \
0037                       XFEATURE_MASK_BNDREGS | \
0038                       XFEATURE_MASK_BNDCSR | \
0039                       XFEATURE_MASK_XTILE)
0040 
0041 /*
0042  * Features which are restored when returning to user space.
0043  * PKRU is not restored on return to user space because PKRU
0044  * is switched eagerly in switch_to() and flush_thread()
0045  */
0046 #define XFEATURE_MASK_USER_RESTORE  \
0047     (XFEATURE_MASK_USER_SUPPORTED & ~XFEATURE_MASK_PKRU)
0048 
0049 /* Features which are dynamically enabled for a process on request */
0050 #define XFEATURE_MASK_USER_DYNAMIC  XFEATURE_MASK_XTILE_DATA
0051 
0052 /* All currently supported supervisor features */
0053 #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID)
0054 
0055 /*
0056  * A supervisor state component may not always contain valuable information,
0057  * and its size may be huge. Saving/restoring such supervisor state components
0058  * at each context switch can cause high CPU and space overhead, which should
0059  * be avoided. Such supervisor state components should only be saved/restored
0060  * on demand. The on-demand supervisor features are set in this mask.
0061  *
0062  * Unlike the existing supported supervisor features, an independent supervisor
0063  * feature does not allocate a buffer in task->fpu, and the corresponding
0064  * supervisor state component cannot be saved/restored at each context switch.
0065  *
0066  * To support an independent supervisor feature, a developer should follow the
0067  * dos and don'ts as below:
0068  * - Do dynamically allocate a buffer for the supervisor state component.
0069  * - Do manually invoke the XSAVES/XRSTORS instruction to save/restore the
0070  *   state component to/from the buffer.
0071  * - Don't set the bit corresponding to the independent supervisor feature in
0072  *   IA32_XSS at run time, since it has been set at boot time.
0073  */
0074 #define XFEATURE_MASK_INDEPENDENT (XFEATURE_MASK_LBR)
0075 
0076 /*
0077  * Unsupported supervisor features. When a supervisor feature in this mask is
0078  * supported in the future, move it to the supported supervisor feature mask.
0079  */
0080 #define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT)
0081 
0082 /* All supervisor states including supported and unsupported states. */
0083 #define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED | \
0084                       XFEATURE_MASK_INDEPENDENT | \
0085                       XFEATURE_MASK_SUPERVISOR_UNSUPPORTED)
0086 
0087 /*
0088  * The feature mask required to restore FPU state:
0089  * - All user states which are not eagerly switched in switch_to()/exec()
0090  * - The suporvisor states
0091  */
0092 #define XFEATURE_MASK_FPSTATE   (XFEATURE_MASK_USER_RESTORE | \
0093                  XFEATURE_MASK_SUPERVISOR_SUPPORTED)
0094 
0095 /*
0096  * Features in this mask have space allocated in the signal frame, but may not
0097  * have that space initialized when the feature is in its init state.
0098  */
0099 #define XFEATURE_MASK_SIGFRAME_INITOPT  (XFEATURE_MASK_XTILE | \
0100                      XFEATURE_MASK_USER_DYNAMIC)
0101 
0102 extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
0103 
0104 extern void __init update_regset_xstate_info(unsigned int size,
0105                          u64 xstate_mask);
0106 
0107 int xfeature_size(int xfeature_nr);
0108 
0109 void xsaves(struct xregs_state *xsave, u64 mask);
0110 void xrstors(struct xregs_state *xsave, u64 mask);
0111 
0112 int xfd_enable_feature(u64 xfd_err);
0113 
0114 #ifdef CONFIG_X86_64
0115 DECLARE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
0116 #endif
0117 
0118 #ifdef CONFIG_X86_64
0119 DECLARE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
0120 
0121 static __always_inline __pure bool fpu_state_size_dynamic(void)
0122 {
0123     return static_branch_unlikely(&__fpu_state_size_dynamic);
0124 }
0125 #else
0126 static __always_inline __pure bool fpu_state_size_dynamic(void)
0127 {
0128     return false;
0129 }
0130 #endif
0131 
0132 #endif