Re: [PATCH 8/8] x86/retpoline: Fix retpoline unwind

From: Peter Zijlstra
Date: Thu Apr 23 2020 - 09:00:04 EST


On Thu, Apr 23, 2020 at 02:47:25PM +0200, Peter Zijlstra wrote:
> @@ -128,10 +90,16 @@
>
> .macro CALL_NOSPEC reg:req
> #ifdef CONFIG_RETPOLINE
> - ANNOTATE_NOSPEC_ALTERNATIVE
> - ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg),\
> - __stringify(RETPOLINE_CALL %\reg), X86_FEATURE_RETPOLINE,\
> - __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_AMD
> + /*
> + * This cannot be ALTERNATIVE_2 like with JMP_NOSPEC, because ORC
> + * unwind data is alternative invariant and needs stack modifying
> + * instructions to be in the same place for all alternatives.
> + *
> + * IOW the CALL instruction must be at the same offset for all cases.
> + */
> + ALTERNATIVE "", "lfence", X86_FEATURE_RETPOLINE_AMD
> + ALTERNATIVE __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \
> + __stringify(call __x86_retpoline_\reg), X86_FEATURE_RETPOLINE
> #else
> call *%\reg
> #endif
> @@ -165,16 +133,12 @@
> * which is ensured when CONFIG_RETPOLINE is defined.
> */
> # define CALL_NOSPEC \
> - ANNOTATE_NOSPEC_ALTERNATIVE \
> - ALTERNATIVE_2( \
> - ANNOTATE_RETPOLINE_SAFE \
> - "call *%[thunk_target]\n", \
> - "call __x86_indirect_thunk_%V[thunk_target]\n", \
> - X86_FEATURE_RETPOLINE, \
> - "lfence;\n" \
> - ANNOTATE_RETPOLINE_SAFE \
> - "call *%[thunk_target]\n", \
> - X86_FEATURE_RETPOLINE_AMD)
> + ALTERNATIVE("", "lfence", X86_FEATURE_RETPOLINE_AMD) \
> + ALTERNATIVE(ANNOTATE_RETPOLINE_SAFE \
> + "call *%[thunk_target]\n", \
> + "call __x86_indirect_thunk_%V[thunk_target]\n", \
> + X86_FEATURE_RETPOLINE)
> +

Hmm, that's a bit daft; that could be a call to
__x86_retpoline_%V[thunk_target] like for the ASM version above.