]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
x86/alternative: Try inline spectre_v2=retpoline,amd
authorPeter Zijlstra <peterz@infradead.org>
Tue, 26 Oct 2021 12:01:44 +0000 (14:01 +0200)
committerPaolo Pisati <paolo.pisati@canonical.com>
Wed, 13 Apr 2022 14:44:34 +0000 (16:44 +0200)
commitbbc7848b7871de60289cc219adab120e9f664a4c
tree723201d2385a2397a45aa47ba4ad7a6c472afb6e
parentd97c5899e5494eb410771f66c3348d0048121eb2
x86/alternative: Try inline spectre_v2=retpoline,amd

BugLink: https://bugs.launchpad.net/bugs/1967579
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
(backported from commit bbe2df3f6b6da7848398d55b1311d58a16ec21e4)
[cascardo: RETPOLINE_AMD was renamed to RETPOLINE_LFENCE]
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
arch/x86/kernel/alternative.c