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

From: Peter Zijlstra
Date: Thu Jul 21 2022 - 14:28:10 EST


On Thu, Jul 21, 2022 at 11:06:42AM -0700, Linus Torvalds wrote:
> On Thu, Jul 21, 2022 at 10:56 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >
> > this seems to work, let me go hack the kernel..
>
> Am I missing something?
>
> Isn't this generating
>
> movl $~IMM,%r10d
> negl %r10d
> cmpl %r10d,-4(%calldest)
>
> for the sequence?
>
> That seems bogus for two reasons:
>
> (a) 'neg' is not the opposite of '~'. Did you mean 'notl' or did you mean '-'?
>
> Or am I missing something entirely?

No, you're right, I'm being daft again.

> (b) since you have that r10 use anyway, why can't you just generate the simpler
>
> movl $-IMM,%r10d
> addl -4(%calldest),%r10d
>
> instead? You only need ZF anyway.

Right, lemme see if I can wrangle llvm to generate that.

> Maybe you need to add some "r10 is clobbered" thing, I don't know.

R11,R11 are caller-saved, and since this is the actual call site, the
caller must already have saved them or marked them clobbered.