Re: [patch 00/38] x86/retbleed: Call depth tracking mitigation

Sami Tolvanen
2022-07-22T15:38:31Z

On Fri, Jul 22, 2022 at 12:23:30PM +0200, Peter Zijlstra wrote:
> and things are 'good' again, except for functions that don't get a kcfi
> preamble, those are unaligned...

One way to fix this would be to just emit an empty KCFI preamble for
non-address-taken functions when patchable-function-prefix > 0, so all
the functions end up with the same alignment.

Note that Clang doesn't keep the function entry aligned with
-fpatchable-function-entry=N,M, where M>0. It generates .p2align 4,
0x90 before the nops, but if you want to maintain alignment for the
entry, you just have to tell it to generate the correct number of
prefix nops.

> I couldn't find where the patchable-function-prefix nops are generated
> to fix this up :/

It's all in AsmPrinter::emitFunctionHeader, look for emitNops.

> Also; could you perhaps add a switch to supress ENDBR for functions with
> a kCFI preamble ?

I'm planning to do that in a follow-up patch. I would rather not add
features that are not critical to the initial patch to avoid further
delays in getting the compiler changes accepted.

Sami