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

Sami Tolvanen
2022-07-22T00:16:28Z

On Thu, Jul 21, 2022 at 08:27:12PM +0200, Peter Zijlstra wrote:
> 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@infradead.org> 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.

That looks good to me. I updated my LLVM tree to generate this code
for the checks:

https://github.com/samitolvanen/llvm-project/commits/kcfi

Sami