Re: [PATCH 15/23] x86/fpu: Add sanity checks for XFD

From: Thomas Gleixner
Date: Mon Oct 25 2021 - 14:13:19 EST


On Mon, Oct 25 2021 at 11:33, Mika Penttilä wrote:
> On 22.10.2021 1.55, Chang S. Bae wrote:
>> +#ifdef CONFIG_X86_DEBUG_FPU
>> +/*
>> + * Ensure that a subsequent XSAVE* or XRSTOR* instruction with RFBM=@mask
>> + * can safely operate on the @fpstate buffer.
>> + */
>> +static bool xstate_op_valid(struct fpstate *fpstate, u64 mask, bool rstor)
>> +{
>> + u64 xfd = __this_cpu_read(xfd_state);
>> +
>> + if (fpstate->xfd == xfd)
>> + return true;
>> +
>> + /* For current's fpstate the XFD state must be correct. */
>> + if (fpstate->xfd == current->thread.fpu.fpstate->xfd)
>> + return false;
>> +
> Should this return true or is the comment confusing?

Comment might be confusing. The logic here is:

If fpstate->xfd equal xfd then it's valid.

So the next check is whether fpstate is the same as current's
fpstate. If that's the case then the result is invalid because for
current's fpstate the first condition should be true. But if it is not
true then the state is not valid.

Thanks,

tglx