Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c47ada30 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

x86/fpu: Harmonize FPU register state types



Use these consistent names:

    struct fregs_state           # was: i387_fsave_struct
    struct fxregs_state          # was: i387_fxsave_struct
    struct swregs_state          # was: i387_soft_struct
    struct xregs_state           # was: xsave_struct
    union  fpregs_state          # was: thread_xstate

Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 0c306bcf
Loading
Loading
Loading
Loading
+11 −11
Original line number Original line Diff line number Diff line
@@ -22,20 +22,20 @@


extern unsigned int mxcsr_feature_mask;
extern unsigned int mxcsr_feature_mask;


extern union thread_xstate init_fpstate;
extern union fpregs_state init_fpstate;


extern void fpu__init_cpu(void);
extern void fpu__init_cpu(void);
extern void fpu__init_system_xstate(void);
extern void fpu__init_system_xstate(void);
extern void fpu__init_cpu_xstate(void);
extern void fpu__init_cpu_xstate(void);
extern void fpu__init_system(struct cpuinfo_x86 *c);
extern void fpu__init_system(struct cpuinfo_x86 *c);


extern void fpstate_init(union thread_xstate *state);
extern void fpstate_init(union fpregs_state *state);
#ifdef CONFIG_MATH_EMULATION
#ifdef CONFIG_MATH_EMULATION
extern void fpstate_init_soft(struct i387_soft_struct *soft);
extern void fpstate_init_soft(struct swregs_state *soft);
#else
#else
static inline void fpstate_init_soft(struct i387_soft_struct *soft) {}
static inline void fpstate_init_soft(struct swregs_state *soft) {}
#endif
#endif
static inline void fpstate_init_fxstate(struct i387_fxsave_struct *fx)
static inline void fpstate_init_fxstate(struct fxregs_state *fx)
{
{
	fx->cwd = 0x37f;
	fx->cwd = 0x37f;
	fx->mxcsr = MXCSR_DEFAULT;
	fx->mxcsr = MXCSR_DEFAULT;
@@ -133,12 +133,12 @@ extern void fpstate_sanitize_xstate(struct fpu *fpu);
	err;								\
	err;								\
})
})


static inline int copy_fregs_to_user(struct i387_fsave_struct __user *fx)
static inline int copy_fregs_to_user(struct fregs_state __user *fx)
{
{
	return user_insn(fnsave %[fx]; fwait,  [fx] "=m" (*fx), "m" (*fx));
	return user_insn(fnsave %[fx]; fwait,  [fx] "=m" (*fx), "m" (*fx));
}
}


static inline int copy_fxregs_to_user(struct i387_fxsave_struct __user *fx)
static inline int copy_fxregs_to_user(struct fxregs_state __user *fx)
{
{
	if (config_enabled(CONFIG_X86_32))
	if (config_enabled(CONFIG_X86_32))
		return user_insn(fxsave %[fx], [fx] "=m" (*fx), "m" (*fx));
		return user_insn(fxsave %[fx], [fx] "=m" (*fx), "m" (*fx));
@@ -149,7 +149,7 @@ static inline int copy_fxregs_to_user(struct i387_fxsave_struct __user *fx)
	return user_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx));
	return user_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx));
}
}


static inline int copy_kernel_to_fxregs(struct i387_fxsave_struct *fx)
static inline int copy_kernel_to_fxregs(struct fxregs_state *fx)
{
{
	if (config_enabled(CONFIG_X86_32))
	if (config_enabled(CONFIG_X86_32))
		return check_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
		return check_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
@@ -161,7 +161,7 @@ static inline int copy_kernel_to_fxregs(struct i387_fxsave_struct *fx)
			  "m" (*fx));
			  "m" (*fx));
}
}


static inline int copy_user_to_fxregs(struct i387_fxsave_struct __user *fx)
static inline int copy_user_to_fxregs(struct fxregs_state __user *fx)
{
{
	if (config_enabled(CONFIG_X86_32))
	if (config_enabled(CONFIG_X86_32))
		return user_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
		return user_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
@@ -173,12 +173,12 @@ static inline int copy_user_to_fxregs(struct i387_fxsave_struct __user *fx)
			  "m" (*fx));
			  "m" (*fx));
}
}


static inline int copy_kernel_to_fregs(struct i387_fsave_struct *fx)
static inline int copy_kernel_to_fregs(struct fregs_state *fx)
{
{
	return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
	return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
}
}


static inline int copy_user_to_fregs(struct i387_fsave_struct __user *fx)
static inline int copy_user_to_fregs(struct fregs_state __user *fx)
{
{
	return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
	return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
}
}
+12 −12
Original line number Original line Diff line number Diff line
@@ -4,7 +4,7 @@
#ifndef _ASM_X86_FPU_H
#ifndef _ASM_X86_FPU_H
#define _ASM_X86_FPU_H
#define _ASM_X86_FPU_H


struct i387_fsave_struct {
struct fregs_state {
	u32			cwd;	/* FPU Control Word		*/
	u32			cwd;	/* FPU Control Word		*/
	u32			swd;	/* FPU Status Word		*/
	u32			swd;	/* FPU Status Word		*/
	u32			twd;	/* FPU Tag Word			*/
	u32			twd;	/* FPU Tag Word			*/
@@ -20,7 +20,7 @@ struct i387_fsave_struct {
	u32			status;
	u32			status;
};
};


struct i387_fxsave_struct {
struct fxregs_state {
	u16			cwd; /* Control Word			*/
	u16			cwd; /* Control Word			*/
	u16			swd; /* Status Word			*/
	u16			swd; /* Status Word			*/
	u16			twd; /* Tag Word			*/
	u16			twd; /* Tag Word			*/
@@ -58,7 +58,7 @@ struct i387_fxsave_struct {
/*
/*
 * Software based FPU emulation state:
 * Software based FPU emulation state:
 */
 */
struct i387_soft_struct {
struct swregs_state {
	u32			cwd;
	u32			cwd;
	u32			swd;
	u32			swd;
	u32			twd;
	u32			twd;
@@ -109,7 +109,7 @@ enum xfeature_bit {
/*
/*
 * There are 16x 256-bit AVX registers named YMM0-YMM15.
 * There are 16x 256-bit AVX registers named YMM0-YMM15.
 * The low 128 bits are aliased to the 16 SSE registers (XMM0-XMM15)
 * The low 128 bits are aliased to the 16 SSE registers (XMM0-XMM15)
 * and are stored in 'struct i387_fxsave_struct::xmm_space[]'.
 * and are stored in 'struct fxregs_state::xmm_space[]'.
 *
 *
 * The high 128 bits are stored here:
 * The high 128 bits are stored here:
 *    16x 128 bits == 256 bytes.
 *    16x 128 bits == 256 bytes.
@@ -140,8 +140,8 @@ struct xstate_header {
	u64				reserved[6];
	u64				reserved[6];
} __attribute__((packed));
} __attribute__((packed));


struct xsave_struct {
struct xregs_state {
	struct i387_fxsave_struct	i387;
	struct fxregs_state		i387;
	struct xstate_header		header;
	struct xstate_header		header;
	struct ymmh_struct		ymmh;
	struct ymmh_struct		ymmh;
	struct lwp_struct		lwp;
	struct lwp_struct		lwp;
@@ -150,11 +150,11 @@ struct xsave_struct {
	/* New processor state extensions will go here. */
	/* New processor state extensions will go here. */
} __attribute__ ((packed, aligned (64)));
} __attribute__ ((packed, aligned (64)));


union thread_xstate {
union fpregs_state {
	struct i387_fsave_struct	fsave;
	struct fregs_state		fsave;
	struct i387_fxsave_struct	fxsave;
	struct fxregs_state		fxsave;
	struct i387_soft_struct		soft;
	struct swregs_state		soft;
	struct xsave_struct		xsave;
	struct xregs_state		xsave;
};
};


struct fpu {
struct fpu {
@@ -171,7 +171,7 @@ struct fpu {
	unsigned int			last_cpu;
	unsigned int			last_cpu;


	unsigned int			fpregs_active;
	unsigned int			fpregs_active;
	union thread_xstate		state;
	union fpregs_state		state;
	/*
	/*
	 * This counter contains the number of consecutive context switches
	 * This counter contains the number of consecutive context switches
	 * during which the FPU stays used. If this is over a threshold, the
	 * during which the FPU stays used. If this is over a threshold, the
+8 −8
Original line number Original line Diff line number Diff line
@@ -58,7 +58,7 @@ extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask);
 * This function is called only during boot time when x86 caps are not set
 * This function is called only during boot time when x86 caps are not set
 * up and alternative can not be used yet.
 * up and alternative can not be used yet.
 */
 */
static inline int copy_xregs_to_kernel_booting(struct xsave_struct *fx)
static inline int copy_xregs_to_kernel_booting(struct xregs_state *fx)
{
{
	u64 mask = -1;
	u64 mask = -1;
	u32 lmask = mask;
	u32 lmask = mask;
@@ -86,7 +86,7 @@ static inline int copy_xregs_to_kernel_booting(struct xsave_struct *fx)
 * This function is called only during boot time when x86 caps are not set
 * This function is called only during boot time when x86 caps are not set
 * up and alternative can not be used yet.
 * up and alternative can not be used yet.
 */
 */
static inline int copy_kernel_to_xregs_booting(struct xsave_struct *fx, u64 mask)
static inline int copy_kernel_to_xregs_booting(struct xregs_state *fx, u64 mask)
{
{
	u32 lmask = mask;
	u32 lmask = mask;
	u32 hmask = mask >> 32;
	u32 hmask = mask >> 32;
@@ -112,7 +112,7 @@ static inline int copy_kernel_to_xregs_booting(struct xsave_struct *fx, u64 mask
/*
/*
 * Save processor xstate to xsave area.
 * Save processor xstate to xsave area.
 */
 */
static inline int copy_xregs_to_kernel(struct xsave_struct *fx)
static inline int copy_xregs_to_kernel(struct xregs_state *fx)
{
{
	u64 mask = -1;
	u64 mask = -1;
	u32 lmask = mask;
	u32 lmask = mask;
@@ -151,7 +151,7 @@ static inline int copy_xregs_to_kernel(struct xsave_struct *fx)
/*
/*
 * Restore processor xstate from xsave area.
 * Restore processor xstate from xsave area.
 */
 */
static inline int copy_kernel_to_xregs(struct xsave_struct *fx, u64 mask)
static inline int copy_kernel_to_xregs(struct xregs_state *fx, u64 mask)
{
{
	int err = 0;
	int err = 0;
	u32 lmask = mask;
	u32 lmask = mask;
@@ -186,7 +186,7 @@ static inline int copy_kernel_to_xregs(struct xsave_struct *fx, u64 mask)
 * backward compatibility for old applications which don't understand
 * backward compatibility for old applications which don't understand
 * compacted format of xsave area.
 * compacted format of xsave area.
 */
 */
static inline int copy_xregs_to_user(struct xsave_struct __user *buf)
static inline int copy_xregs_to_user(struct xregs_state __user *buf)
{
{
	int err;
	int err;


@@ -210,10 +210,10 @@ static inline int copy_xregs_to_user(struct xsave_struct __user *buf)
/*
/*
 * Restore xstate from user space xsave area.
 * Restore xstate from user space xsave area.
 */
 */
static inline int copy_user_to_xregs(struct xsave_struct __user *buf, u64 mask)
static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)
{
{
	int err = 0;
	int err = 0;
	struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
	struct xregs_state *xstate = ((__force struct xregs_state *)buf);
	u32 lmask = mask;
	u32 lmask = mask;
	u32 hmask = mask >> 32;
	u32 hmask = mask >> 32;


@@ -226,7 +226,7 @@ static inline int copy_user_to_xregs(struct xsave_struct __user *buf, u64 mask)
	return err;
	return err;
}
}


void *get_xsave_addr(struct xsave_struct *xsave, int xstate);
void *get_xsave_addr(struct xregs_state *xsave, int xstate);
void setup_xstate_comp(void);
void setup_xstate_comp(void);


#endif
#endif
+4 −4
Original line number Original line Diff line number Diff line
@@ -60,8 +60,8 @@


#ifdef CONFIG_X86_INTEL_MPX
#ifdef CONFIG_X86_INTEL_MPX
siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
				struct xsave_struct *xsave_buf);
				struct xregs_state *xsave_buf);
int mpx_handle_bd_fault(struct xsave_struct *xsave_buf);
int mpx_handle_bd_fault(struct xregs_state *xsave_buf);
static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
{
{
	return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
	return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
@@ -78,11 +78,11 @@ void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
		      unsigned long start, unsigned long end);
		      unsigned long start, unsigned long end);
#else
#else
static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
					      struct xsave_struct *xsave_buf)
					      struct xregs_state *xsave_buf)
{
{
	return NULL;
	return NULL;
}
}
static inline int mpx_handle_bd_fault(struct xsave_struct *xsave_buf)
static inline int mpx_handle_bd_fault(struct xregs_state *xsave_buf)
{
{
	return -EINVAL;
	return -EINVAL;
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@
 * Represents the initial FPU state. It's mostly (but not completely) zeroes,
 * Represents the initial FPU state. It's mostly (but not completely) zeroes,
 * depending on the FPU hardware format:
 * depending on the FPU hardware format:
 */
 */
union thread_xstate init_fpstate __read_mostly;
union fpregs_state init_fpstate __read_mostly;


/*
/*
 * Track whether the kernel is using the FPU state
 * Track whether the kernel is using the FPU state
@@ -200,7 +200,7 @@ EXPORT_SYMBOL_GPL(fpu__save);
/*
/*
 * Legacy x87 fpstate state init:
 * Legacy x87 fpstate state init:
 */
 */
static inline void fpstate_init_fstate(struct i387_fsave_struct *fp)
static inline void fpstate_init_fstate(struct fregs_state *fp)
{
{
	fp->cwd = 0xffff037fu;
	fp->cwd = 0xffff037fu;
	fp->swd = 0xffff0000u;
	fp->swd = 0xffff0000u;
@@ -208,7 +208,7 @@ static inline void fpstate_init_fstate(struct i387_fsave_struct *fp)
	fp->fos = 0xffff0000u;
	fp->fos = 0xffff0000u;
}
}


void fpstate_init(union thread_xstate *state)
void fpstate_init(union fpregs_state *state)
{
{
	if (!cpu_has_fpu) {
	if (!cpu_has_fpu) {
		fpstate_init_soft(&state->soft);
		fpstate_init_soft(&state->soft);
Loading