Commit 49a91d61 authored by Yu-cheng Yu's avatar Yu-cheng Yu Committed by Borislav Petkov

x86/fpu/xstate: Fix XSAVES offsets in setup_xstate_comp()

In setup_xstate_comp(), each XSAVES component offset starts from the
end of its preceding component plus alignment. A disabled feature does
not take space and its offset should be set to the end of its preceding
one with no alignment. However, in this case, alignment is incorrectly
added to the offset, which can cause the next component to have a wrong
offset.

This problem has not been visible because currently there is no xfeature
requiring alignment.

Fix it by tracking the next starting offset only from enabled
xfeatures. To make it clear, also change the function name to
setup_xstate_comp_offsets().

 [ bp: Fix a typo in the comment above it, while at it. ]
Signed-off-by: default avatarYu-cheng Yu <yu-cheng.yu@intel.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Link: https://lkml.kernel.org/r/20200109211452.27369-3-yu-cheng.yu@intel.com
parent c12e13dc
...@@ -337,11 +337,11 @@ static int xfeature_is_aligned(int xfeature_nr) ...@@ -337,11 +337,11 @@ static int xfeature_is_aligned(int xfeature_nr)
/* /*
* This function sets up offsets and sizes of all extended states in * This function sets up offsets and sizes of all extended states in
* xsave area. This supports both standard format and compacted format * xsave area. This supports both standard format and compacted format
* of the xsave aread. * of the xsave area.
*/ */
static void __init setup_xstate_comp(void) static void __init setup_xstate_comp_offsets(void)
{ {
unsigned int xstate_comp_sizes[XFEATURE_MAX]; unsigned int next_offset;
int i; int i;
/* /*
...@@ -355,31 +355,23 @@ static void __init setup_xstate_comp(void) ...@@ -355,31 +355,23 @@ static void __init setup_xstate_comp(void)
if (!boot_cpu_has(X86_FEATURE_XSAVES)) { if (!boot_cpu_has(X86_FEATURE_XSAVES)) {
for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
if (xfeature_enabled(i)) { if (xfeature_enabled(i))
xstate_comp_offsets[i] = xstate_offsets[i]; xstate_comp_offsets[i] = xstate_offsets[i];
xstate_comp_sizes[i] = xstate_sizes[i];
}
} }
return; return;
} }
xstate_comp_offsets[FIRST_EXTENDED_XFEATURE] = next_offset = FXSAVE_SIZE + XSAVE_HDR_SIZE;
FXSAVE_SIZE + XSAVE_HDR_SIZE;
for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
if (xfeature_enabled(i)) if (!xfeature_enabled(i))
xstate_comp_sizes[i] = xstate_sizes[i]; continue;
else
xstate_comp_sizes[i] = 0;
if (i > FIRST_EXTENDED_XFEATURE) { if (xfeature_is_aligned(i))
xstate_comp_offsets[i] = xstate_comp_offsets[i-1] next_offset = ALIGN(next_offset, 64);
+ xstate_comp_sizes[i-1];
if (xfeature_is_aligned(i)) xstate_comp_offsets[i] = next_offset;
xstate_comp_offsets[i] = next_offset += xstate_sizes[i];
ALIGN(xstate_comp_offsets[i], 64);
}
} }
} }
...@@ -773,7 +765,7 @@ void __init fpu__init_system_xstate(void) ...@@ -773,7 +765,7 @@ void __init fpu__init_system_xstate(void)
fpu__init_prepare_fx_sw_frame(); fpu__init_prepare_fx_sw_frame();
setup_init_fpu_buf(); setup_init_fpu_buf();
setup_xstate_comp(); setup_xstate_comp_offsets();
print_xstate_offset_size(); print_xstate_offset_size();
pr_info("x86/fpu: Enabled xstate features 0x%llx, context size is %d bytes, using '%s' format.\n", pr_info("x86/fpu: Enabled xstate features 0x%llx, context size is %d bytes, using '%s' format.\n",
......
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