Re: [PATCH] [v2] x86/fpu: Delay instruction pointer fixup until after warning

From: Peter Zijlstra
Date: Wed Jun 25 2025 - 04:58:00 EST


On Tue, Jun 24, 2025 at 02:01:48PM -0700, Dave Hansen wrote:
>
> Changes from v1:
> * Fix minor typos
> * Use the more generic and standard ex_handler_default(). Had the
> original code used this helper, the bug would not have been there
> in the first place.

Doesn't this here typically go under the --- with the diffstat etc?

> --
>
> From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
>
> Right now, if XRSTOR fails a console message like this is be printed:
>
> Bad FPU state detected at restore_fpregs_from_fpstate+0x9a/0x170, reinitializing FPU registers.
>
> However, the text location (...+0x9a in this case) is the instruction
> *AFTER* the XRSTOR. The highlighted instruction in the "Code:" dump
> also points one instruction late.
>
> The reason is that the "fixup" moves RIP up to pass the bad XRSTOR and
> keep on running after returning from the #GP handler. But it does this
> fixup before warning.
>
> The resulting warning output is nonsensical because it looks like the
> non-FPU-related instruction is #GP'ing.
>
> Do not fix up RIP until after printing the warning. Do this by using
> the more generic and standard ex_handler_default().
>
> Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Fixes: d5c8028b4788 ("x86/fpu: Reinitialize FPU registers if restoring FPU state fails")
> Acked-by: Alison Schofield <alison.schofield@xxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Cc: Eric Biggers <ebiggers@xxxxxxxxxx>
> Cc: Rik van Riel <riel@xxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Chang S. Bae <chang.seok.bae@xxxxxxxxx>

Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>