Re: [PATCH v10 10/28] x86/fpu/xstate: Update the XSTATE save function to support dynamic states

From: Thomas Gleixner
Date: Fri Oct 01 2021 - 11:41:53 EST


On Wed, Aug 25 2021 at 08:53, Chang S. Bae wrote:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 74dde635df40..7c46747f6865 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9899,11 +9899,16 @@ static void kvm_save_current_fpu(struct fpu *fpu)
> * KVM does not support dynamic user states yet. Assume the buffer
> * always has the minimum size.
> */
> - if (test_thread_flag(TIF_NEED_FPU_LOAD))
> + if (test_thread_flag(TIF_NEED_FPU_LOAD)) {
> memcpy(fpu->state, current->thread.fpu.state,
> fpu_buf_cfg.min_size);

What happens with the rest of the state?

> - else
> + } else {
> + struct fpu *src_fpu = &current->thread.fpu;
> +
> + if (fpu->state_mask != src_fpu->state_mask)
> + fpu->state_mask = src_fpu->state_mask;

What guarantees that the state size of @fpu is big enough when src_fpu
has dynamic features included?

> save_fpregs_to_fpstate(fpu);

Thanks,

tglx