Re: [PATCH v3 01/13] x86/retpoline: Add initial retpoline support

From: Alexei Starovoitov
Date: Thu Jan 04 2018 - 13:17:57 EST


On Thu, Jan 04, 2018 at 02:36:58PM +0000, David Woodhouse wrote:
> Enable the use of -mindirect-branch=thunk-extern in newer GCC, and provide
> the corresponding thunks. Provide assembler macros for invoking the thunks
> in the same way that GCC does, from native and inline assembler.
>
> This adds an X86_BUG_NO_RETPOLINE "feature" for runtime patching out
> of the thunks. This is a placeholder for now; the patches which support
> the new Intel/AMD microcode features will flesh out the precise conditions
> under which we disable the retpoline and do other things instead.
>
> [Andi Kleen: Rename the macros and add CONFIG_RETPOLINE option]
>
> Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
...
> +.macro THUNK sp reg
> + .section .text.__x86.indirect_thunk.\reg
> +
> +ENTRY(__x86.indirect_thunk.\reg)
> + CFI_STARTPROC
> + ALTERNATIVE "call 2f", __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE
> +1:
> + lfence
> + jmp 1b
> +2:
> + mov %\reg, (%\sp)
> + ret
> + CFI_ENDPROC
> +ENDPROC(__x86.indirect_thunk.\reg)

Clearly Paul's approach to retpoline without lfence is faster.
I'm guessing it wasn't shared with amazon/intel until now and
this set of patches going to adopt it, right?

Paul, could you share a link to a set of alternative gcc patches
that do retpoline similar to llvm diff ?