1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __ASM_X86_XSAVE_H 3 #define __ASM_X86_XSAVE_H 4 5 #include <linux/uaccess.h> 6 #include <linux/types.h> 7 8 #include <asm/processor.h> 9 #include <asm/user.h> 10 11 /* Bit 63 of XCR0 is reserved for future expansion */ 12 #define XFEATURE_MASK_EXTEND (~(XFEATURE_MASK_FPSSE | (1ULL << 63))) 13 14 #define XSTATE_CPUID 0x0000000d 15 16 #define FXSAVE_SIZE 512 17 18 #define XSAVE_HDR_SIZE 64 19 #define XSAVE_HDR_OFFSET FXSAVE_SIZE 20 21 #define XSAVE_YMM_SIZE 256 22 #define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET) 23 24 /* All currently supported user features */ 25 #define XFEATURE_MASK_USER_SUPPORTED (XFEATURE_MASK_FP | \ 26 XFEATURE_MASK_SSE | \ 27 XFEATURE_MASK_YMM | \ 28 XFEATURE_MASK_OPMASK | \ 29 XFEATURE_MASK_ZMM_Hi256 | \ 30 XFEATURE_MASK_Hi16_ZMM | \ 31 XFEATURE_MASK_PKRU | \ 32 XFEATURE_MASK_BNDREGS | \ 33 XFEATURE_MASK_BNDCSR) 34 35 /* All currently supported supervisor features */ 36 #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (0) 37 38 /* 39 * Unsupported supervisor features. When a supervisor feature in this mask is 40 * supported in the future, move it to the supported supervisor feature mask. 41 */ 42 #define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) 43 44 /* All supervisor states including supported and unsupported states. */ 45 #define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED | \ 46 XFEATURE_MASK_SUPERVISOR_UNSUPPORTED) 47 48 #ifdef CONFIG_X86_64 49 #define REX_PREFIX "0x48, " 50 #else 51 #define REX_PREFIX 52 #endif 53 54 extern u64 xfeatures_mask_all; 55 56 static inline u64 xfeatures_mask_supervisor(void) 57 { 58 return xfeatures_mask_all & XFEATURE_MASK_SUPERVISOR_SUPPORTED; 59 } 60 61 static inline u64 xfeatures_mask_user(void) 62 { 63 return xfeatures_mask_all & XFEATURE_MASK_USER_SUPPORTED; 64 } 65 66 extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS]; 67 68 extern void __init update_regset_xstate_info(unsigned int size, 69 u64 xstate_mask); 70 71 void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr); 72 const void *get_xsave_field_ptr(int xfeature_nr); 73 int using_compacted_format(void); 74 int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int offset, unsigned int size); 75 int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int offset, unsigned int size); 76 int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf); 77 int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf); 78 void copy_supervisor_to_kernel(struct xregs_state *xsave); 79 80 /* Validate an xstate header supplied by userspace (ptrace or sigreturn) */ 81 int validate_user_xstate_header(const struct xstate_header *hdr); 82 83 #endif 84