]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/fpu/xstate: Introduce "guest-only" supervisor xfeature set
authorYang Weijiang <weijiang.yang@intel.com>
Thu, 22 May 2025 15:10:08 +0000 (08:10 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Tue, 24 Jun 2025 20:46:32 +0000 (13:46 -0700)
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 <chao.gao@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Reviewed-by: John Allen <john.allen@amd.com>
Link: https://lore.kernel.org/all/20250522151031.426788-6-chao.gao%40intel.com
arch/x86/include/asm/fpu/types.h
arch/x86/include/asm/fpu/xstate.h
arch/x86/kernel/fpu/xstate.c

index abd193a1a52e9e705aac2b7cf92976b891c88c42..54ba567258d68aa160859e3bf0a677277f864bb8 100644 (file)
@@ -592,8 +592,9 @@ struct fpu_state_config {
         * @default_size:
         *
         * The default size of the register state buffer. Includes all
-        * supported features except independent managed features and
-        * features which have to be requested by user space before usage.
+        * supported features except independent managed features,
+        * guest-only features and features which have to be requested by
+        * user space before usage.
         */
        unsigned int            default_size;
 
@@ -609,8 +610,8 @@ struct fpu_state_config {
         * @default_features:
         *
         * The default supported features bitmap. Does not include
-        * independent managed features and features which have to
-        * be requested by user space before usage.
+        * independent managed features, guest-only features and features
+        * which have to be requested by user space before usage.
         */
        u64 default_features;
        /*
index b308a76afbb7cfdfe2f4d7ed3cf442f471eda5cc..a3cd25453f94177d5f2c1e6511d7a8fa41af9a62 100644 (file)
 /* Features which are dynamically enabled for a process on request */
 #define XFEATURE_MASK_USER_DYNAMIC     XFEATURE_MASK_XTILE_DATA
 
+/* Supervisor features which are enabled only in guest FPUs */
+#define XFEATURE_MASK_GUEST_SUPERVISOR 0
+
 /* All currently supported supervisor features */
 #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \
-                                           XFEATURE_MASK_CET_USER)
+                                           XFEATURE_MASK_CET_USER | \
+                                           XFEATURE_MASK_GUEST_SUPERVISOR)
 
 /*
  * A supervisor state component may not always contain valuable information,
index 7c5f9f1e0700185d174c6496c1cf0b3acaaa9ad4..d94a5f4f205d130794cf8288a36d1a6da88055cd 100644 (file)
@@ -779,8 +779,11 @@ static void __init fpu__init_disable_system_xstate(unsigned int legacy_size)
 
 static u64 __init host_default_mask(void)
 {
-       /* Exclude dynamic features, which require userspace opt-in. */
-       return ~(u64)XFEATURE_MASK_USER_DYNAMIC;
+       /*
+        * Exclude dynamic features (require userspace opt-in) and features
+        * that are supported only for KVM guests.
+        */
+       return ~((u64)XFEATURE_MASK_USER_DYNAMIC | XFEATURE_MASK_GUEST_SUPERVISOR);
 }
 
 static u64 __init guest_default_mask(void)