Re: [patch 1/3] x86/fpu: Prevent FPU state corruption

Borislav Petkov
2022-05-02T13:16:30Z

On Sun, May 01, 2022 at 09:31:43PM +0200, Thomas Gleixner wrote:
> The latter is checking whether some other context already uses FPU in the
> kernel, but if that's not the case then it allows FPU to be used
> unconditionally even if the calling context interupted a fpregs_lock()

Unknown word [interupted] in commit message.
Suggestions: ['interrupted', ...

> /*
> * Can we use the FPU in kernel mode with the
> * whole "kernel_fpu_begin/end()" sequence?

While at it, drop the "we": "Can the FPU be used in kernel mode... "

> - *
> - * It's always ok in process context (ie "not interrupt")
> - * but it is sometimes ok even from an irq.
> */
> bool irq_fpu_usable(void)
> {
> - return !in_interrupt() ||
> - interrupted_user_mode() ||
> - interrupted_kernel_fpu_idle();
> + if (WARN_ON_ONCE(in_nmi()))
> + return false;
> +
> + /* In kernel FPU usage already active? */
> + if (this_cpu_read(in_kernel_fpu))
> + return false;
> +
> + /*
> + * When not in NMI or hard interrupt context, FPU can be used:

"... can be used in:"

> + *
> + * - Task context is safe except from within fpregs_lock()'ed
> + * critical regions.
> + *
> + * - Soft interrupt processing context which cannot happen
> + * while in a fpregs_lock()'ed critical region.

But those are only nitpicks. With those fixed:

Reviewed-by: Borislav Petkov <bp@suse.de>

Thx.

--
Regards/Gruss,
Boris.