Re: [PATCH 4/9] x86/alternative: Implement .retpoline_sites support

From: Peter Zijlstra
Date: Tue Oct 19 2021 - 06:02:33 EST


On Tue, Oct 19, 2021 at 11:40:56AM +0200, Peter Zijlstra wrote:
> On Mon, Oct 18, 2021 at 11:06:35PM +0000, Alexander Lobakin wrote:

> > WARN in patch_retpoline:408: addr pcibios_scan_specific_bus+0x196/0x200, op 0xe8, reg 0xb88ca
> > WARN in patch_retpoline:408: addr xen_pv_teardown_msi_irqs+0x8d/0x120, op 0xe8, reg 0xb88ca
> > WARN in patch_retpoline:408: addr __mptcp_sockopt_sync+0x7e/0x200, op 0xe8, reg 0xb88ca
> > [...]
> > (thousands of them, but op == 0xe8 && reg == 0xb88ca are always the same)
> >
> > I know this reg calculation is about to be replaced, but anyway ;)
>
> Well, I was sorta hoping to keep that with something like:
>
> https://lkml.kernel.org/r/YWgA+vbWCdGLZhq5@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> Anyway, let me try and reproduce.

Using: make O=defconfig CC=clang-13 -j80 -s

( is actually defconfig+kvm_guest.config,
and clang-13 from debian/testing )

on https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=objtool/core

It seems to 'just' work:

spectre_v2=retpoline,amd:

gets me two very sad and lonely replacements:

[] SMP alternatives: retpoline at: 0xffffffff82e764b4 (ffffffff82e764b4) len: 5 to: __x86_indirect_thunk_rbx+0x0/0x20
[] SMP alternatives: ffffffff82e764b4: orig: e8 07 d3 18 ff
[] SMP alternatives: ffffffff82e764b4: repl: 0f ae e8 ff d3

[] SMP alternatives: retpoline at: 0xffffffff82e76f39 (ffffffff82e76f39) len: 5 to: __x86_indirect_thunk_rdi+0x0/0x20
[] SMP alternatives: ffffffff82e76f39: orig: e8 02 c9 18 ff
[] SMP alternatives: ffffffff82e76f39: repl: 0f ae e8 ff d7

The rest is R11 and therefore doesn't actaully fit.

For spectre_v2=off everything gets replaced, and that also seems happy.

[] SMP alternatives: retpoline at: pm_check_save_msr+0x24/0x30 (ffffffff81d2ef24) len: 5 to: __x86_indirect_thunk_r11+0x0/0x20
[] SMP alternatives: ffffffff82603eb0: [3:5) optimized NOPs: 41 ff d3 66 90
[] SMP alternatives: ffffffff81d2ef24: orig: e8 97 49 2d 00
[] SMP alternatives: ffffffff81d2ef24: repl: 41 ff d3 66 90