Skip to content

Commit fafb29e

Browse files
gaochaointelhansendc
authored andcommitted
x86/fpu: Remove xfd argument from __fpstate_reset()
The initial values for fpstate::xfd differ between guest and host fpstates. Currently, the initial values are passed as an argument to __fpstate_reset(). But, __fpstate_reset() already assigns different default features and sizes based on the type of fpstates (i.e., guest or host). So, handle fpstate::xfd in a similar way to highlight the differences in the initial xfd value between guest and host fpstates Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Chao Gao <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: John Allen <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Link: https://lore.kernel.org/all/20250522151031.426788-5-chao.gao%40intel.com
1 parent 509e880 commit fafb29e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/x86/kernel/fpu/core.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void fpu_reset_from_exception_fixup(void)
218218
}
219219

220220
#if IS_ENABLED(CONFIG_KVM)
221-
static void __fpstate_reset(struct fpstate *fpstate, u64 xfd);
221+
static void __fpstate_reset(struct fpstate *fpstate);
222222

223223
static void fpu_lock_guest_permissions(void)
224224
{
@@ -253,8 +253,7 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu)
253253
fpstate->is_valloc = true;
254254
fpstate->is_guest = true;
255255

256-
/* Leave xfd to 0 (the reset value defined by spec) */
257-
__fpstate_reset(fpstate, 0);
256+
__fpstate_reset(fpstate);
258257
fpstate_init_user(fpstate);
259258

260259
gfpu->fpstate = fpstate;
@@ -545,33 +544,37 @@ void fpstate_init_user(struct fpstate *fpstate)
545544
fpstate_init_fstate(fpstate);
546545
}
547546

548-
static void __fpstate_reset(struct fpstate *fpstate, u64 xfd)
547+
static void __fpstate_reset(struct fpstate *fpstate)
549548
{
550549
/*
551550
* Supervisor features (and thus sizes) may diverge between guest
552551
* FPUs and host FPUs, as some supervisor features are supported
553552
* for guests despite not being utilized by the host. User
554553
* features and sizes are always identical, which allows for
555554
* common guest and userspace ABI.
555+
*
556+
* For the host, set XFD to the kernel's desired initialization
557+
* value. For guests, set XFD to its architectural RESET value.
556558
*/
557559
if (fpstate->is_guest) {
558560
fpstate->size = guest_default_cfg.size;
559561
fpstate->xfeatures = guest_default_cfg.features;
562+
fpstate->xfd = 0;
560563
} else {
561564
fpstate->size = fpu_kernel_cfg.default_size;
562565
fpstate->xfeatures = fpu_kernel_cfg.default_features;
566+
fpstate->xfd = init_fpstate.xfd;
563567
}
564568

565569
fpstate->user_size = fpu_user_cfg.default_size;
566570
fpstate->user_xfeatures = fpu_user_cfg.default_features;
567-
fpstate->xfd = xfd;
568571
}
569572

570573
void fpstate_reset(struct fpu *fpu)
571574
{
572575
/* Set the fpstate pointer to the default fpstate */
573576
fpu->fpstate = &fpu->__fpstate;
574-
__fpstate_reset(fpu->fpstate, init_fpstate.xfd);
577+
__fpstate_reset(fpu->fpstate);
575578

576579
/* Initialize the permission related info in fpu */
577580
fpu->perm.__state_perm = fpu_kernel_cfg.default_features;

0 commit comments

Comments
 (0)