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

From: Andrew Cooper
Date: Wed Oct 13 2021 - 18:48:33 EST


On 13/10/2021 23:10, Peter Zijlstra wrote:
>> If performance of the linear lookup were a real concern then you could
>> just put rax and r11 at the beginning of the array.
> That would mean the table would have to be { __thunk, reg_idx }, which
> is even more yuck.

Yeah - it's nasty because it is a reverse lookup you need.

In both cases, it is %rax (GCC) or %r11 (Clang) and change for the other
regs, so you can construct a search which will hit on the first lookup
most of the time.

Either:

1) an array of { __thunk } with a hole for rsp.  Bias searching entry 0
or 11 first based on compiler, then a 16 step linear search.

or

2) an array of { __thunk, reg }, sorted by thunk address.  This has an
odd number of entries, so arrange the thunk generation to emit rax or
r11 as the 7th thunk, so it ends up in the middle when sorted.

~Andrew