Commit 3ac8d757 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Use fpstate in __copy_xstate_to_uabi_buf()

With dynamically enabled features the copy function must know the features
and the size which is valid for the task. Retrieve them from fpstate.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211013145323.181495492@linutronix.de
parent ad6ede40
...@@ -187,15 +187,15 @@ EXPORT_SYMBOL_GPL(fpu_swap_kvm_fpu); ...@@ -187,15 +187,15 @@ EXPORT_SYMBOL_GPL(fpu_swap_kvm_fpu);
void fpu_copy_fpstate_to_kvm_uabi(struct fpu *fpu, void *buf, void fpu_copy_fpstate_to_kvm_uabi(struct fpu *fpu, void *buf,
unsigned int size, u32 pkru) unsigned int size, u32 pkru)
{ {
union fpregs_state *kstate = &fpu->fpstate->regs; struct fpstate *kstate = fpu->fpstate;
union fpregs_state *ustate = buf; union fpregs_state *ustate = buf;
struct membuf mb = { .p = buf, .left = size }; struct membuf mb = { .p = buf, .left = size };
if (cpu_feature_enabled(X86_FEATURE_XSAVE)) { if (cpu_feature_enabled(X86_FEATURE_XSAVE)) {
__copy_xstate_to_uabi_buf(mb, &kstate->xsave, pkru, __copy_xstate_to_uabi_buf(mb, kstate, pkru, XSTATE_COPY_XSAVE);
XSTATE_COPY_XSAVE);
} else { } else {
memcpy(&ustate->fxsave, &kstate->fxsave, sizeof(ustate->fxsave)); memcpy(&ustate->fxsave, &kstate->regs.fxsave,
sizeof(ustate->fxsave));
/* Make it restorable on a XSAVE enabled host */ /* Make it restorable on a XSAVE enabled host */
ustate->xsave.header.xfeatures = XFEATURE_MASK_FPSSE; ustate->xsave.header.xfeatures = XFEATURE_MASK_FPSSE;
} }
......
...@@ -969,7 +969,7 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate, ...@@ -969,7 +969,7 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate,
/** /**
* __copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer * __copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer
* @to: membuf descriptor * @to: membuf descriptor
* @xsave: The xsave from which to copy * @fpstate: The fpstate buffer from which to copy
* @pkru_val: The PKRU value to store in the PKRU component * @pkru_val: The PKRU value to store in the PKRU component
* @copy_mode: The requested copy mode * @copy_mode: The requested copy mode
* *
...@@ -979,11 +979,12 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate, ...@@ -979,11 +979,12 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate,
* *
* It supports partial copy but @to.pos always starts from zero. * It supports partial copy but @to.pos always starts from zero.
*/ */
void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
u32 pkru_val, enum xstate_copy_mode copy_mode) u32 pkru_val, enum xstate_copy_mode copy_mode)
{ {
const unsigned int off_mxcsr = offsetof(struct fxregs_state, mxcsr); const unsigned int off_mxcsr = offsetof(struct fxregs_state, mxcsr);
struct xregs_state *xinit = &init_fpstate.regs.xsave; struct xregs_state *xinit = &init_fpstate.regs.xsave;
struct xregs_state *xsave = &fpstate->regs.xsave;
struct xstate_header header; struct xstate_header header;
unsigned int zerofrom; unsigned int zerofrom;
u64 mask; u64 mask;
...@@ -1003,7 +1004,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, ...@@ -1003,7 +1004,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave,
break; break;
case XSTATE_COPY_XSAVE: case XSTATE_COPY_XSAVE:
header.xfeatures &= xfeatures_mask_uabi(); header.xfeatures &= fpstate->user_xfeatures;
break; break;
} }
...@@ -1046,7 +1047,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, ...@@ -1046,7 +1047,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave,
* but there is no state to copy from in the compacted * but there is no state to copy from in the compacted
* init_fpstate. The gap tracking will zero these states. * init_fpstate. The gap tracking will zero these states.
*/ */
mask = xfeatures_mask_uabi(); mask = fpstate->user_xfeatures;
for_each_extended_xfeature(i, mask) { for_each_extended_xfeature(i, mask) {
/* /*
...@@ -1097,7 +1098,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, ...@@ -1097,7 +1098,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave,
void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk, void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk,
enum xstate_copy_mode copy_mode) enum xstate_copy_mode copy_mode)
{ {
__copy_xstate_to_uabi_buf(to, &tsk->thread.fpu.fpstate->regs.xsave, __copy_xstate_to_uabi_buf(to, tsk->thread.fpu.fpstate,
tsk->thread.pkru, copy_mode); tsk->thread.pkru, copy_mode);
} }
......
...@@ -15,7 +15,7 @@ static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask) ...@@ -15,7 +15,7 @@ static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask)
xsave->header.xcomp_bv = mask | XCOMP_BV_COMPACTED_FORMAT; xsave->header.xcomp_bv = mask | XCOMP_BV_COMPACTED_FORMAT;
} }
extern void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, extern void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
u32 pkru_val, enum xstate_copy_mode copy_mode); u32 pkru_val, enum xstate_copy_mode copy_mode);
extern void fpu__init_cpu_xstate(void); extern void fpu__init_cpu_xstate(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment