Skip to content

Commit c95473e

Browse files
yyu-intel-comsuryasaimadhu
authored andcommitted
x86/fpu/xstate: Update copy_kernel_to_xregs_err() for supervisor states
The function copy_kernel_to_xregs_err() uses XRSTOR which can work with standard or compacted format without supervisor xstates. However, when supervisor xstates are present, XRSTORS must be used. Fix it by using XRSTORS when supervisor state handling is enabled. I also considered if there were additional cases where XRSTOR might be mistakenly called instead of XRSTORS. There are only three XRSTOR sites in the kernel: 1. copy_kernel_to_xregs_booting(), already switches between XRSTOR and XRSTORS based on X86_FEATURE_XSAVES. 2. copy_user_to_xregs(), which *needs* XRSTOR because it is copying from userspace and must never copy supervisor state with XRSTORS. 3. copy_kernel_to_xregs_err() mistakenly used XRSTOR only. Fix it. [ bp: Massage commit message. ] Signed-off-by: Yu-cheng Yu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 5d6b6a6 commit c95473e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,10 @@ static inline int copy_kernel_to_xregs_err(struct xregs_state *xstate, u64 mask)
400400
u32 hmask = mask >> 32;
401401
int err;
402402

403-
XSTATE_OP(XRSTOR, xstate, lmask, hmask, err);
403+
if (static_cpu_has(X86_FEATURE_XSAVES))
404+
XSTATE_OP(XRSTORS, xstate, lmask, hmask, err);
405+
else
406+
XSTATE_OP(XRSTOR, xstate, lmask, hmask, err);
404407

405408
return err;
406409
}

0 commit comments

Comments
 (0)