Skip to content

Commit 151bf23

Browse files
yang-weijianghansendc
authored andcommitted
x86/fpu/xstate: Introduce "guest-only" supervisor xfeature set
In preparation for upcoming CET virtualization support, the CET supervisor state will be added as a "guest-only" feature, since it is required only by KVM (i.e., guest FPUs). Establish the infrastructure for "guest-only" features. Define a new XFEATURE_MASK_GUEST_SUPERVISOR mask to specify features that are enabled by default in guest FPUs but not in host FPUs. Specifically, for any bit in this set, permission is granted and XSAVE space is allocated during vCPU creation. Non-guest FPUs cannot enable guest-only features, even dynamically, and no XSAVE space will be allocated for them. The mask is currently empty, but this will be changed by a subsequent patch. Co-developed-by: Chao Gao <[email protected]> Signed-off-by: Chao Gao <[email protected]> Signed-off-by: Yang Weijiang <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Rick Edgecombe <[email protected]> Reviewed-by: John Allen <[email protected]> Link: https://lore.kernel.org/all/20250522151031.426788-6-chao.gao%40intel.com
1 parent fafb29e commit 151bf23

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,9 @@ struct fpu_state_config {
592592
* @default_size:
593593
*
594594
* The default size of the register state buffer. Includes all
595-
* supported features except independent managed features and
596-
* features which have to be requested by user space before usage.
595+
* supported features except independent managed features,
596+
* guest-only features and features which have to be requested by
597+
* user space before usage.
597598
*/
598599
unsigned int default_size;
599600

@@ -609,8 +610,8 @@ struct fpu_state_config {
609610
* @default_features:
610611
*
611612
* The default supported features bitmap. Does not include
612-
* independent managed features and features which have to
613-
* be requested by user space before usage.
613+
* independent managed features, guest-only features and features
614+
* which have to be requested by user space before usage.
614615
*/
615616
u64 default_features;
616617
/*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@
4646
/* Features which are dynamically enabled for a process on request */
4747
#define XFEATURE_MASK_USER_DYNAMIC XFEATURE_MASK_XTILE_DATA
4848

49+
/* Supervisor features which are enabled only in guest FPUs */
50+
#define XFEATURE_MASK_GUEST_SUPERVISOR 0
51+
4952
/* All currently supported supervisor features */
5053
#define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \
51-
XFEATURE_MASK_CET_USER)
54+
XFEATURE_MASK_CET_USER | \
55+
XFEATURE_MASK_GUEST_SUPERVISOR)
5256

5357
/*
5458
* A supervisor state component may not always contain valuable information,

arch/x86/kernel/fpu/xstate.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,11 @@ static void __init fpu__init_disable_system_xstate(unsigned int legacy_size)
779779

780780
static u64 __init host_default_mask(void)
781781
{
782-
/* Exclude dynamic features, which require userspace opt-in. */
783-
return ~(u64)XFEATURE_MASK_USER_DYNAMIC;
782+
/*
783+
* Exclude dynamic features (require userspace opt-in) and features
784+
* that are supported only for KVM guests.
785+
*/
786+
return ~((u64)XFEATURE_MASK_USER_DYNAMIC | XFEATURE_MASK_GUEST_SUPERVISOR);
784787
}
785788

786789
static u64 __init guest_default_mask(void)

0 commit comments

Comments
 (0)