Re: [PATCH] x86/retpoline: Don't clobber RFLAGS during srso_safe_ret()

From: Borislav Petkov
Date: Fri Aug 11 2023 - 14:06:01 EST


On Fri, Aug 11, 2023 at 08:52:55AM -0700, Sean Christopherson wrote:
> A major motivation for doing fast emulation is to leverage the CPU to
> handle consumption and manipulation of arithmetic flags, i.e. RFLAGS is
> both an input and output to the target of the call. fastop() collects
> the RFLAGS result by pushing RFLAGS onto the stack and popping them back
> into a variable (held in RDI in this case)
>
> asm("push %[flags]; popf; " CALL_NOSPEC " ; pushf; pop %[flags]\n"

Right, and I've tested this countless times with gcc-built host and
guest.

But Nathan's case where the host is built with gcc but the guest with
clang, would trigger this. And as he confirms, that fixes it so I wonder
what is the difference in code generation to make this rFLAGS corruption
noticeable in that particular configuration.

Oh well, later when the fires are put out.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette