Skip to content

Commit c12e13d

Browse files
yyu-intel-comsuryasaimadhu
authored andcommitted
x86/fpu/xstate: Fix last_good_offset in setup_xstate_features()
The function setup_xstate_features() uses CPUID to find each xfeature's standard-format offset and size. Since XSAVES always uses the compacted format, supervisor xstates are *NEVER* in the standard-format and their offsets are left as -1's. However, they are still being tracked as last_good_offset. Fix it by tracking only user xstate offsets. [ bp: Use xfeature_is_supervisor() and save an indentation level. Drop now unused xfeature_is_user(). ] 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 bb6d3fb commit c12e13d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ static bool xfeature_is_supervisor(int xfeature_nr)
120120
return ecx & 1;
121121
}
122122

123-
static bool xfeature_is_user(int xfeature_nr)
124-
{
125-
return !xfeature_is_supervisor(xfeature_nr);
126-
}
127-
128123
/*
129124
* When executing XSAVEOPT (or other optimized XSAVE instructions), if
130125
* a processor implementation detects that an FPU state component is still
@@ -265,21 +260,25 @@ static void __init setup_xstate_features(void)
265260

266261
cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
267262

263+
xstate_sizes[i] = eax;
264+
268265
/*
269-
* If an xfeature is supervisor state, the offset
270-
* in EBX is invalid. We leave it to -1.
266+
* If an xfeature is supervisor state, the offset in EBX is
267+
* invalid, leave it to -1.
271268
*/
272-
if (xfeature_is_user(i))
273-
xstate_offsets[i] = ebx;
269+
if (xfeature_is_supervisor(i))
270+
continue;
271+
272+
xstate_offsets[i] = ebx;
274273

275-
xstate_sizes[i] = eax;
276274
/*
277-
* In our xstate size checks, we assume that the
278-
* highest-numbered xstate feature has the
279-
* highest offset in the buffer. Ensure it does.
275+
* In our xstate size checks, we assume that the highest-numbered
276+
* xstate feature has the highest offset in the buffer. Ensure
277+
* it does.
280278
*/
281279
WARN_ONCE(last_good_offset > xstate_offsets[i],
282-
"x86/fpu: misordered xstate at %d\n", last_good_offset);
280+
"x86/fpu: misordered xstate at %d\n", last_good_offset);
281+
283282
last_good_offset = xstate_offsets[i];
284283
}
285284
}

0 commit comments

Comments
 (0)