Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

From: Josh Poimboeuf
Date: Wed Oct 10 2018 - 14:33:38 EST


On Wed, Oct 10, 2018 at 01:16:05PM -0500, Josh Poimboeuf wrote:
> > > +#define DEFINE_STATIC_CALL(tramp, func) \
> > > + DECLARE_STATIC_CALL(tramp, func); \
> > > + asm(".pushsection .text, \"ax\" \n" \
> > > + ".align 4 \n" \
> > > + ".globl " #tramp " \n" \
> > > + ".type " #tramp ", @function \n" \
> > > + #tramp ": \n" \
> > > + "jmp " #func " \n" \
> >
> > I think this would be nicer as an indirect call that gets patched to a
> > direct call so that the update mechanism works even before it's
> > initialized. (Currently static_branch blows up horribly if you try to
> > update one too early, and that's rather annoying IMO.)
>
> Yeah, that would be better. It would also allow trampoline function
> pointers to work, which I think you mentioned elsewhere. And then I
> shouldn't trample this code in __static_call_update() -- that was
> already kind of nasty anyway.

Re-reading your suggestion, I may have misunderstood what you're
suggesting here, but I'm thinking about doing something like what you
proposed earlier:

GLOBAL(tramp)
jmp *current_func(%rip)
ENDPROC(tramp)

That is, doing an indirect jump instead of the above direct jump, so
that any previous references to the trampoline would still work (and it
would also work during early boot).

Though it should probably be a retpoline instead of an indirect jump.

--
Josh