Re: [PATCH] fpu: xstate: Keep xfd_state always in-sync with IA32_XFD MSR

From: Chang S. Bae
Date: Fri May 12 2023 - 13:46:49 EST


On 5/11/2023 12:11 PM, Thomas Gleixner wrote:
On Thu, May 11 2023 at 15:28, Adamos Ttofari wrote:

@@ -915,7 +921,7 @@ void fpu__resume_cpu(void)
}
if (fpu_state_size_dynamic())
- wrmsrl(MSR_IA32_XFD, current->thread.fpu.fpstate->xfd);
+ xfd_update_state(&init_fpstate);

xfd_update_state() here is not a right choice as Thomas pointed out multiple times.

On suspend per CPU xfd_state == current->thread.fpu.fpstate->xfd so it's
correct to restore the exact state which was active _before_ suspend.
xfd_state can't be out of sync in that case, no?

Indeed! But, looking around the code, writing 'xfd_state' here appears to be consistent and logical I suppose.

Every time writing the MSR in the kernel (except for the init), the value is saved in 'xfd_state'. So we don't do it on the sleep path. Then, on the wake-up path, perhaps it makes sense to restore the context with the saved.

Thanks,
Chang