Re: [PATCH v3 07/10] x86/fpu/xstate: Initialize guest fpstate with fpu_guest_config
From: Dave Hansen
Date: Fri Mar 07 2025 - 13:41:36 EST
On 3/7/25 08:41, Chao Gao wrote:
> From: Yang Weijiang <weijiang.yang@xxxxxxxxx>
>
> Use fpu_guest_cfg to initialize the guest fpstate and the guest FPU pseduo
> container.
>
> The user_* fields remain unchanged for compatibility with KVM uAPIs.
>
> Inline the logic of __fpstate_reset() to directly utilize fpu_guest_cfg.
Why? Seriously, why? Why would you just inline it? Could you please
revisit the moment when you decided to do this? Please go back to that
moment and try to unlearn whatever propensity you have for taking this path.
There are two choices: make the existing function work for guests, or
add a new guest-only reset function.
Just an an example:
static void __fpstate_reset(struct fpstate *fpstate,
struct fpu_state_config *kernel_cfg,
u64 xfd)
{
/* Initialize sizes and feature masks */
fpstate->size = kernel_cfg->default_size;
fpstate->xfeatures = kernel_cfg->default_features;
/* Some comment about why user states don't vary */
fpstate->user_size = fpu_user_cfg.default_size;
fpstate->user_xfeatures = fpu_user_cfg.default_features;
fpstate->xfd = xfd;
}
Then you have two call sites:
__fpstate_reset(fpstate, &fpu_guest_cfg, 0);
and
__fpstate_reset(fpu->fpstate, &fpu_kernel_cfg,
init_fpstate.xfd);
What does this tell you?
It clearly lays out that to reset an fpstate, you need a specific kernel
config. That kernel config is (can be) different for guests.
Refactoring the code as you go along is not optional. It's a requirement.