Re: [PATCH 01/25] x86: Make SMAP 64-bit only

From: Peter Zijlstra
Date: Thu Mar 21 2019 - 17:04:08 EST


On Thu, Mar 21, 2019 at 11:18:05AM -0700, hpa@xxxxxxxxx wrote:
> On March 21, 2019 10:25:05 AM PDT, Denys Vlasenko <dvlasenk@xxxxxxxxxx> wrote:

> >I did not see evidence of this. In my testing,
> >POPF is always ~20 cycles, even if popped flags are identical to
> >current state of flags.
>
> I think you will find that if you change system flags it is much slower.

So with all the patches in this series applied, only x86_32 will suffer
this, and I don't think anybody still considers that a performance
critical platform.

That said, we could do something terrible like:

--- a/arch/x86/entry/entry_32.S
+++ b/arch/x86/entry/entry_32.S
@@ -673,7 +673,8 @@ ENTRY(__switch_to_asm)
#endif

/* restore callee-saved registers */
- popfl
+ ALTERNATIVE "popl %esi", \
+ "popfl", X86_FEATURE_SMAP
popl %esi
popl %edi
popl %ebx

And then you only pay the POPF penalty when you run a 32bit kernel on a
SMAP enabled CPU, and we have a very good solution in that code: run a
64bit kernel.