x86/alternative: Try inline spectre_v2=retpoline,amd
authorPeter Zijlstra <peterz@infradead.org>
Tue, 26 Oct 2021 12:01:44 +0000 (14:01 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 28 Oct 2021 21:25:28 +0000 (23:25 +0200)
commitbbe2df3f6b6da7848398d55b1311d58a16ec21e4
tree2abeeafd8f025733e94cf8e6a0e96bfd2ea5d004
parent2f0cbb2a8e5bbf101e9de118fc0eb168111a5e1e
x86/alternative: Try inline spectre_v2=retpoline,amd

Try and replace retpoline thunk calls with:

  LFENCE
  CALL    *%\reg

for spectre_v2=retpoline,amd.

Specifically, the sequence above is 5 bytes for the low 8 registers,
but 6 bytes for the high 8 registers. This means that unless the
compilers prefix stuff the call with higher registers this replacement
will fail.

Luckily GCC strongly favours RAX for the indirect calls and most (95%+
for defconfig-x86_64) will be converted. OTOH clang strongly favours
R11 and almost nothing gets converted.

Note: it will also generate a correct replacement for the Jcc.d32
case, except unless the compilers start to prefix stuff that, it'll
never fit. Specifically:

  Jncc.d8 1f
  LFENCE
  JMP     *%\reg
1:

is 7-8 bytes long, where the original instruction in unpadded form is
only 6 bytes.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20211026120310.359986601@infradead.org
arch/x86/kernel/alternative.c