RE: [PATCH v3 18/39] x86/ibt,ftrace: Make function-graph play nice
From: David Laight
Date: Fri Mar 04 2022 - 18:08:30 EST
From: Peter Zijlstra
> Sent: 04 March 2022 19:49
>
> On Fri, Mar 04, 2022 at 09:51:54AM -0800, Josh Poimboeuf wrote:
> > On Thu, Mar 03, 2022 at 12:23:39PM +0100, Peter Zijlstra wrote:
> > > +
> > > + addq $16, %rsp
> > > + ANNOTATE_INTRA_FUNCTION_CALL
> > > + call .Ldo_rop
> > > + int3
> > > +.Ldo_rop:
> > > + mov %rdi, (%rsp)
> > > + UNWIND_HINT_FUNC
> > > + RET
> >
> > Why the int3?
>
> Speculation trap :-) Either I'm too paranoid or not paranoid enough; but
> without it it's just too close to a retpoline and it doesn't feel right.
Isn't 'jmps .' good enough for a speculation trap?
I'm sure there is a potential issue using 'int 3' because
it is a slow instruction and might take some time to abort.
I actually remember something from a very old Intel doc that
told you not to mix code and data because you didn't want to
'accidentally' execute something like 'atan'.
I can't remember the full context - but it may have been
speculatively executing code after unconditional jumps!
There were certainly bigger problems because the cpu at that
time wouldn't abort the atan - so you had to wait for it to
finish.
I suspect you do need something between the call and label.
The sequence:
call 1f
1: pop %rax
is used to get the %pc (especially on 32bit) and is detected
so that it doesn't mess up the return stack.
So you probably want to avoid a call to the next instruction.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)