0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _ASM_X86_FPU_API_H
0012 #define _ASM_X86_FPU_API_H
0013 #include <linux/bottom_half.h>
0014
0015 #include <asm/fpu/types.h>
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #define KFPU_387 _BITUL(0)
0027 #define KFPU_MXCSR _BITUL(1)
0028
0029 extern void kernel_fpu_begin_mask(unsigned int kfpu_mask);
0030 extern void kernel_fpu_end(void);
0031 extern bool irq_fpu_usable(void);
0032 extern void fpregs_mark_activate(void);
0033
0034
0035 static inline void kernel_fpu_begin(void)
0036 {
0037 #ifdef CONFIG_X86_64
0038
0039
0040
0041
0042 kernel_fpu_begin_mask(KFPU_MXCSR);
0043 #else
0044
0045
0046
0047
0048 kernel_fpu_begin_mask(KFPU_387 | KFPU_MXCSR);
0049 #endif
0050 }
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 static inline void fpregs_lock(void)
0070 {
0071 if (!IS_ENABLED(CONFIG_PREEMPT_RT))
0072 local_bh_disable();
0073 else
0074 preempt_disable();
0075 }
0076
0077 static inline void fpregs_unlock(void)
0078 {
0079 if (!IS_ENABLED(CONFIG_PREEMPT_RT))
0080 local_bh_enable();
0081 else
0082 preempt_enable();
0083 }
0084
0085 #ifdef CONFIG_X86_DEBUG_FPU
0086 extern void fpregs_assert_state_consistent(void);
0087 #else
0088 static inline void fpregs_assert_state_consistent(void) { }
0089 #endif
0090
0091
0092
0093
0094 extern void switch_fpu_return(void);
0095
0096
0097
0098
0099
0100
0101
0102
0103 extern int cpu_has_xfeatures(u64 xfeatures_mask, const char **feature_name);
0104
0105
0106 extern int fpu__exception_code(struct fpu *fpu, int trap_nr);
0107 extern void fpu_sync_fpstate(struct fpu *fpu);
0108 extern void fpu_reset_from_exception_fixup(void);
0109
0110
0111 extern void fpu__init_cpu(void);
0112 extern void fpu__init_system(struct cpuinfo_x86 *c);
0113 extern void fpu__init_check_bugs(void);
0114 extern void fpu__resume_cpu(void);
0115
0116 #ifdef CONFIG_MATH_EMULATION
0117 extern void fpstate_init_soft(struct swregs_state *soft);
0118 #else
0119 static inline void fpstate_init_soft(struct swregs_state *soft) {}
0120 #endif
0121
0122
0123 DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
0124
0125
0126 #ifdef CONFIG_X86_64
0127 extern void fpstate_free(struct fpu *fpu);
0128 #else
0129 static inline void fpstate_free(struct fpu *fpu) { }
0130 #endif
0131
0132
0133 extern void fpstate_clear_xstate_component(struct fpstate *fps, unsigned int xfeature);
0134
0135 extern u64 xstate_get_guest_group_perm(void);
0136
0137
0138 extern bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu);
0139 extern void fpu_free_guest_fpstate(struct fpu_guest *gfpu);
0140 extern int fpu_swap_kvm_fpstate(struct fpu_guest *gfpu, bool enter_guest);
0141 extern int fpu_enable_guest_xfd_features(struct fpu_guest *guest_fpu, u64 xfeatures);
0142
0143 #ifdef CONFIG_X86_64
0144 extern void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd);
0145 extern void fpu_sync_guest_vmexit_xfd_state(void);
0146 #else
0147 static inline void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd) { }
0148 static inline void fpu_sync_guest_vmexit_xfd_state(void) { }
0149 #endif
0150
0151 extern void fpu_copy_guest_fpstate_to_uabi(struct fpu_guest *gfpu, void *buf, unsigned int size, u32 pkru);
0152 extern int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf, u64 xcr0, u32 *vpkru);
0153
0154 static inline void fpstate_set_confidential(struct fpu_guest *gfpu)
0155 {
0156 gfpu->fpstate->is_confidential = true;
0157 }
0158
0159 static inline bool fpstate_is_confidential(struct fpu_guest *gfpu)
0160 {
0161 return gfpu->fpstate->is_confidential;
0162 }
0163
0164
0165 extern long fpu_xstate_prctl(int option, unsigned long arg2);
0166
0167 extern void fpu_idle_fpregs(void);
0168
0169 #endif