Skip to content

Commit 7c2c893

Browse files
gaochaointelhansendc
authored andcommitted
x86/fpu: Initialize guest FPU permissions from guest defaults
Currently, fpu->guest_perm is copied from fpu->perm, which is derived from fpu_kernel_cfg.default_features. Guest defaults were introduced to differentiate the features and sizes of host and guest FPUs. Copying guest FPU permissions from the host will lead to inconsistencies between the guest default features and permissions. Initialize guest FPU permissions from guest defaults instead of host defaults. This ensures that any changes to guest default features are automatically reflected in guest permissions, which in turn guarantees that fpstate_realloc() allocates a correctly sized XSAVE buffer for guest FPUs. Suggested-by: Chang S. Bae <[email protected]> Signed-off-by: Chao Gao <[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-3-chao.gao%40intel.com
1 parent 7bc4ed7 commit 7c2c893

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/kernel/fpu/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,14 @@ void fpstate_reset(struct fpu *fpu)
562562
fpu->perm.__state_perm = fpu_kernel_cfg.default_features;
563563
fpu->perm.__state_size = fpu_kernel_cfg.default_size;
564564
fpu->perm.__user_state_size = fpu_user_cfg.default_size;
565-
/* Same defaults for guests */
566-
fpu->guest_perm = fpu->perm;
565+
566+
fpu->guest_perm.__state_perm = guest_default_cfg.features;
567+
fpu->guest_perm.__state_size = guest_default_cfg.size;
568+
/*
569+
* User features and sizes are always identical between host and
570+
* guest FPUs, which allows for common guest and userspace ABI.
571+
*/
572+
fpu->guest_perm.__user_state_size = fpu_user_cfg.default_size;
567573
}
568574

569575
static inline void fpu_inherit_perms(struct fpu *dst_fpu)

0 commit comments

Comments
 (0)