Skip to content

Commit 8ab2280

Browse files
Fenghua Yusuryasaimadhu
authored andcommitted
x86/fpu/xstate: Define new macros for supervisor and user xstates
XCNTXT_MASK is 'all supported xfeatures' before introducing supervisor xstates. Rename it to XFEATURE_MASK_USER_SUPPORTED to make clear that these are user xstates. Replace XFEATURE_MASK_SUPERVISOR with the following: - XFEATURE_MASK_SUPERVISOR_SUPPORTED: Currently nothing. ENQCMD and Control-flow Enforcement Technology (CET) will be introduced in separate series. - XFEATURE_MASK_SUPERVISOR_UNSUPPORTED: Currently only Processor Trace. - XFEATURE_MASK_SUPERVISOR_ALL: the combination of above. Co-developed-by: Yu-cheng Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Yu-cheng Yu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Reviewed-by: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 5274e6c commit 8ab2280

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,29 @@
2121
#define XSAVE_YMM_SIZE 256
2222
#define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET)
2323

24-
/* Supervisor features */
25-
#define XFEATURE_MASK_SUPERVISOR (XFEATURE_MASK_PT)
26-
27-
/* All currently supported features */
28-
#define XCNTXT_MASK (XFEATURE_MASK_FP | \
29-
XFEATURE_MASK_SSE | \
30-
XFEATURE_MASK_YMM | \
31-
XFEATURE_MASK_OPMASK | \
32-
XFEATURE_MASK_ZMM_Hi256 | \
33-
XFEATURE_MASK_Hi16_ZMM | \
34-
XFEATURE_MASK_PKRU | \
35-
XFEATURE_MASK_BNDREGS | \
36-
XFEATURE_MASK_BNDCSR)
24+
/* All currently supported user features */
25+
#define XFEATURE_MASK_USER_SUPPORTED (XFEATURE_MASK_FP | \
26+
XFEATURE_MASK_SSE | \
27+
XFEATURE_MASK_YMM | \
28+
XFEATURE_MASK_OPMASK | \
29+
XFEATURE_MASK_ZMM_Hi256 | \
30+
XFEATURE_MASK_Hi16_ZMM | \
31+
XFEATURE_MASK_PKRU | \
32+
XFEATURE_MASK_BNDREGS | \
33+
XFEATURE_MASK_BNDCSR)
34+
35+
/* All currently supported supervisor features */
36+
#define XFEATURE_MASK_SUPERVISOR_SUPPORTED (0)
37+
38+
/*
39+
* Unsupported supervisor features. When a supervisor feature in this mask is
40+
* supported in the future, move it to the supported supervisor feature mask.
41+
*/
42+
#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT)
43+
44+
/* All supervisor states including supported and unsupported states. */
45+
#define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED | \
46+
XFEATURE_MASK_SUPERVISOR_UNSUPPORTED)
3747

3848
#ifdef CONFIG_X86_64
3949
#define REX_PREFIX "0x48, "

arch/x86/kernel/fpu/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static void __init fpu__init_system_xstate_size_legacy(void)
224224
*/
225225
u64 __init fpu__get_supported_xfeatures_mask(void)
226226
{
227-
return XCNTXT_MASK;
227+
return XFEATURE_MASK_USER_SUPPORTED |
228+
XFEATURE_MASK_SUPERVISOR_SUPPORTED;
228229
}
229230

230231
/* Legacy code to initialize eager fpu mode. */

arch/x86/kernel/fpu/xstate.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ void fpu__init_cpu_xstate(void)
208208
if (!boot_cpu_has(X86_FEATURE_XSAVE) || !xfeatures_mask)
209209
return;
210210
/*
211-
* Make it clear that XSAVES supervisor states are not yet
212-
* implemented should anyone expect it to work by changing
213-
* bits in XFEATURE_MASK_* macros and XCR0.
211+
* Unsupported supervisor xstates should not be found in
212+
* the xfeatures mask.
214213
*/
215-
WARN_ONCE((xfeatures_mask & XFEATURE_MASK_SUPERVISOR),
216-
"x86/fpu: XSAVES supervisor states are not yet implemented.\n");
214+
WARN_ONCE((xfeatures_mask & XFEATURE_MASK_SUPERVISOR_UNSUPPORTED),
215+
"x86/fpu: Found unsupported supervisor xstates.\n");
217216

218-
xfeatures_mask &= ~XFEATURE_MASK_SUPERVISOR;
217+
xfeatures_mask &= ~XFEATURE_MASK_SUPERVISOR_UNSUPPORTED;
219218

220219
cr4_set_bits(X86_CR4_OSXSAVE);
221220
xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask);
@@ -438,7 +437,7 @@ static int xfeature_uncompacted_offset(int xfeature_nr)
438437
* format. Checking a supervisor state's uncompacted offset is
439438
* an error.
440439
*/
441-
if (XFEATURE_MASK_SUPERVISOR & BIT_ULL(xfeature_nr)) {
440+
if (XFEATURE_MASK_SUPERVISOR_ALL & BIT_ULL(xfeature_nr)) {
442441
WARN_ONCE(1, "No fixed offset for xstate %d\n", xfeature_nr);
443442
return -1;
444443
}
@@ -475,7 +474,7 @@ int using_compacted_format(void)
475474
int validate_user_xstate_header(const struct xstate_header *hdr)
476475
{
477476
/* No unknown or supervisor features may be set */
478-
if (hdr->xfeatures & (~xfeatures_mask | XFEATURE_MASK_SUPERVISOR))
477+
if (hdr->xfeatures & ~(xfeatures_mask & XFEATURE_MASK_USER_SUPPORTED))
479478
return -EINVAL;
480479

481480
/* Userspace must use the uncompacted format */
@@ -768,7 +767,8 @@ void __init fpu__init_system_xstate(void)
768767
* Update info used for ptrace frames; use standard-format size and no
769768
* supervisor xstates:
770769
*/
771-
update_regset_xstate_info(fpu_user_xstate_size, xfeatures_mask & ~XFEATURE_MASK_SUPERVISOR);
770+
update_regset_xstate_info(fpu_user_xstate_size,
771+
xfeatures_mask & XFEATURE_MASK_USER_SUPPORTED);
772772

773773
fpu__init_prepare_fx_sw_frame();
774774
setup_init_fpu_buf();
@@ -996,7 +996,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int of
996996
*/
997997
memset(&header, 0, sizeof(header));
998998
header.xfeatures = xsave->header.xfeatures;
999-
header.xfeatures &= ~XFEATURE_MASK_SUPERVISOR;
999+
header.xfeatures &= XFEATURE_MASK_USER_SUPPORTED;
10001000

10011001
/*
10021002
* Copy xregs_state->header:
@@ -1080,7 +1080,7 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i
10801080
*/
10811081
memset(&header, 0, sizeof(header));
10821082
header.xfeatures = xsave->header.xfeatures;
1083-
header.xfeatures &= ~XFEATURE_MASK_SUPERVISOR;
1083+
header.xfeatures &= XFEATURE_MASK_USER_SUPPORTED;
10841084

10851085
/*
10861086
* Copy xregs_state->header:
@@ -1173,7 +1173,7 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
11731173
* The state that came in from userspace was user-state only.
11741174
* Mask all the user states out of 'xfeatures':
11751175
*/
1176-
xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR;
1176+
xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR_ALL;
11771177

11781178
/*
11791179
* Add back in the features that came in from userspace:
@@ -1229,7 +1229,7 @@ int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf)
12291229
* The state that came in from userspace was user-state only.
12301230
* Mask all the user states out of 'xfeatures':
12311231
*/
1232-
xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR;
1232+
xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR_ALL;
12331233

12341234
/*
12351235
* Add back in the features that came in from userspace:

0 commit comments

Comments
 (0)