Re: [RFC][PATCH 1/2] x86/retpoline: Simplify retpolines

From: Peter Zijlstra
Date: Mon Feb 22 2021 - 06:37:36 EST


On Thu, Feb 18, 2021 at 05:59:39PM +0100, Peter Zijlstra wrote:
> Currently out retpolines consist of 2 symbols,
> __x86_indirect_thunk_\reg, which is the compiler target, and
> __x86_retpoline_\reg, which is the actual retpoline. Both are
> consecutive in code and aligned such that for any one register they
> both live in the same cacheline:
>
> 0000000000000000 <__x86_indirect_thunk_rax>:
> 0: ff e0 jmpq *%rax
> 2: 90 nop
> 3: 90 nop
> 4: 90 nop
>
> 0000000000000005 <__x86_retpoline_rax>:
> 5: e8 07 00 00 00 callq 11 <__x86_retpoline_rax+0xc>
> a: f3 90 pause
> c: 0f ae e8 lfence
> f: eb f9 jmp a <__x86_retpoline_rax+0x5>
> 11: 48 89 04 24 mov %rax,(%rsp)
> 15: c3 retq
> 16: 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:0x0(%rax,%rax,1)
>
> The thunk is an alternative_2, where one option is a jmp to the
> retpoline.

So the reason I originally did that was because objtool could not deal
with alternatives with stack ops. But we've recently fixed that.