.. | .. |
---|
2 | 2 | #ifndef __ASM_X86_XSAVE_H |
---|
3 | 3 | #define __ASM_X86_XSAVE_H |
---|
4 | 4 | |
---|
5 | | -#include <linux/types.h> |
---|
6 | | -#include <asm/processor.h> |
---|
7 | 5 | #include <linux/uaccess.h> |
---|
| 6 | +#include <linux/types.h> |
---|
| 7 | + |
---|
| 8 | +#include <asm/processor.h> |
---|
| 9 | +#include <asm/user.h> |
---|
8 | 10 | |
---|
9 | 11 | /* Bit 63 of XCR0 is reserved for future expansion */ |
---|
10 | 12 | #define XFEATURE_MASK_EXTEND (~(XFEATURE_MASK_FPSSE | (1ULL << 63))) |
---|
.. | .. |
---|
19 | 21 | #define XSAVE_YMM_SIZE 256 |
---|
20 | 22 | #define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET) |
---|
21 | 23 | |
---|
22 | | -/* Supervisor features */ |
---|
23 | | -#define XFEATURE_MASK_SUPERVISOR (XFEATURE_MASK_PT) |
---|
| 24 | +#define XSAVE_ALIGNMENT 64 |
---|
24 | 25 | |
---|
25 | | -/* All currently supported features */ |
---|
26 | | -#define XCNTXT_MASK (XFEATURE_MASK_FP | \ |
---|
27 | | - XFEATURE_MASK_SSE | \ |
---|
28 | | - XFEATURE_MASK_YMM | \ |
---|
29 | | - XFEATURE_MASK_OPMASK | \ |
---|
30 | | - XFEATURE_MASK_ZMM_Hi256 | \ |
---|
31 | | - XFEATURE_MASK_Hi16_ZMM | \ |
---|
32 | | - XFEATURE_MASK_PKRU | \ |
---|
33 | | - XFEATURE_MASK_BNDREGS | \ |
---|
34 | | - XFEATURE_MASK_BNDCSR) |
---|
| 26 | +/* All currently supported user features */ |
---|
| 27 | +#define XFEATURE_MASK_USER_SUPPORTED (XFEATURE_MASK_FP | \ |
---|
| 28 | + XFEATURE_MASK_SSE | \ |
---|
| 29 | + XFEATURE_MASK_YMM | \ |
---|
| 30 | + XFEATURE_MASK_OPMASK | \ |
---|
| 31 | + XFEATURE_MASK_ZMM_Hi256 | \ |
---|
| 32 | + XFEATURE_MASK_Hi16_ZMM | \ |
---|
| 33 | + XFEATURE_MASK_PKRU | \ |
---|
| 34 | + XFEATURE_MASK_BNDREGS | \ |
---|
| 35 | + XFEATURE_MASK_BNDCSR) |
---|
| 36 | + |
---|
| 37 | +/* All currently supported supervisor features */ |
---|
| 38 | +#define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID) |
---|
| 39 | + |
---|
| 40 | +/* |
---|
| 41 | + * A supervisor state component may not always contain valuable information, |
---|
| 42 | + * and its size may be huge. Saving/restoring such supervisor state components |
---|
| 43 | + * at each context switch can cause high CPU and space overhead, which should |
---|
| 44 | + * be avoided. Such supervisor state components should only be saved/restored |
---|
| 45 | + * on demand. The on-demand dynamic supervisor features are set in this mask. |
---|
| 46 | + * |
---|
| 47 | + * Unlike the existing supported supervisor features, a dynamic supervisor |
---|
| 48 | + * feature does not allocate a buffer in task->fpu, and the corresponding |
---|
| 49 | + * supervisor state component cannot be saved/restored at each context switch. |
---|
| 50 | + * |
---|
| 51 | + * To support a dynamic supervisor feature, a developer should follow the |
---|
| 52 | + * dos and don'ts as below: |
---|
| 53 | + * - Do dynamically allocate a buffer for the supervisor state component. |
---|
| 54 | + * - Do manually invoke the XSAVES/XRSTORS instruction to save/restore the |
---|
| 55 | + * state component to/from the buffer. |
---|
| 56 | + * - Don't set the bit corresponding to the dynamic supervisor feature in |
---|
| 57 | + * IA32_XSS at run time, since it has been set at boot time. |
---|
| 58 | + */ |
---|
| 59 | +#define XFEATURE_MASK_DYNAMIC (XFEATURE_MASK_LBR) |
---|
| 60 | + |
---|
| 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 | + |
---|
| 67 | +/* All supervisor states including supported and unsupported states. */ |
---|
| 68 | +#define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED | \ |
---|
| 69 | + XFEATURE_MASK_DYNAMIC | \ |
---|
| 70 | + XFEATURE_MASK_SUPERVISOR_UNSUPPORTED) |
---|
35 | 71 | |
---|
36 | 72 | #ifdef CONFIG_X86_64 |
---|
37 | 73 | #define REX_PREFIX "0x48, " |
---|
.. | .. |
---|
39 | 75 | #define REX_PREFIX |
---|
40 | 76 | #endif |
---|
41 | 77 | |
---|
42 | | -extern u64 xfeatures_mask; |
---|
| 78 | +extern u64 xfeatures_mask_all; |
---|
| 79 | + |
---|
| 80 | +static inline u64 xfeatures_mask_supervisor(void) |
---|
| 81 | +{ |
---|
| 82 | + return xfeatures_mask_all & XFEATURE_MASK_SUPERVISOR_SUPPORTED; |
---|
| 83 | +} |
---|
| 84 | + |
---|
| 85 | +static inline u64 xfeatures_mask_user(void) |
---|
| 86 | +{ |
---|
| 87 | + return xfeatures_mask_all & XFEATURE_MASK_USER_SUPPORTED; |
---|
| 88 | +} |
---|
| 89 | + |
---|
| 90 | +static inline u64 xfeatures_mask_dynamic(void) |
---|
| 91 | +{ |
---|
| 92 | + if (!boot_cpu_has(X86_FEATURE_ARCH_LBR)) |
---|
| 93 | + return XFEATURE_MASK_DYNAMIC & ~XFEATURE_MASK_LBR; |
---|
| 94 | + |
---|
| 95 | + return XFEATURE_MASK_DYNAMIC; |
---|
| 96 | +} |
---|
| 97 | + |
---|
43 | 98 | extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS]; |
---|
44 | 99 | |
---|
45 | 100 | extern void __init update_regset_xstate_info(unsigned int size, |
---|
46 | 101 | u64 xstate_mask); |
---|
47 | 102 | |
---|
48 | | -void fpu__xstate_clear_all_cpu_caps(void); |
---|
49 | | -void *get_xsave_addr(struct xregs_state *xsave, int xstate); |
---|
50 | | -const void *get_xsave_field_ptr(int xstate_field); |
---|
| 103 | +void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr); |
---|
| 104 | +const void *get_xsave_field_ptr(int xfeature_nr); |
---|
51 | 105 | int using_compacted_format(void); |
---|
52 | | -int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int offset, unsigned int size); |
---|
53 | | -int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int offset, unsigned int size); |
---|
| 106 | +int xfeature_size(int xfeature_nr); |
---|
| 107 | +struct membuf; |
---|
| 108 | +void copy_xstate_to_kernel(struct membuf to, struct xregs_state *xsave); |
---|
54 | 109 | int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf); |
---|
55 | 110 | int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf); |
---|
| 111 | +void copy_supervisor_to_kernel(struct xregs_state *xsave); |
---|
| 112 | +void copy_dynamic_supervisor_to_kernel(struct xregs_state *xstate, u64 mask); |
---|
| 113 | +void copy_kernel_to_dynamic_supervisor(struct xregs_state *xstate, u64 mask); |
---|
| 114 | + |
---|
56 | 115 | |
---|
57 | 116 | /* Validate an xstate header supplied by userspace (ptrace or sigreturn) */ |
---|
58 | | -extern int validate_xstate_header(const struct xstate_header *hdr); |
---|
| 117 | +int validate_user_xstate_header(const struct xstate_header *hdr); |
---|
59 | 118 | |
---|
60 | 119 | #endif |
---|