Re: [PATCH v3 3/6] x86/static_call: Add out-of-line static call implementation

From: Josh Poimboeuf
Date: Thu Jan 10 2019 - 11:28:20 EST


On Thu, Jan 10, 2019 at 12:16:34AM +0000, Nadav Amit wrote:
> > On Jan 9, 2019, at 2:59 PM, Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
> >
>
> <snip>
>
> > +
> > +void __ref arch_static_call_transform(void *site, void *tramp, void *func)
> > +{
> > + s32 dest_relative;
> > + unsigned char opcode;
> > + void *(*poker)(void *, const void *, size_t);
> > + void *insn = tramp;
> > +
> > + mutex_lock(&text_mutex);
> > +
> > + /*
> > + * For x86-64, a 32-bit cross-modifying write to a call destination is
> > + * safe as long as it's within a cache line.
> > + */
> > + opcode = *(unsigned char *)insn;
> > + if (opcode != 0xe8 && opcode != 0xe9) {
> > + WARN_ONCE(1, "unexpected static call insn opcode 0x%x at %pS",
> > + opcode, insn);
> > + goto done;
> > + }
> > +
> > + dest_relative = (long)(func) - (long)(insn + CALL_INSN_SIZE);
> > +
> > + poker = early_boot_irqs_disabled ? text_poke_early : text_poke;
> > + poker(insn + 1, &dest_relative, sizeof(dest_relative));
> > +
> > +done:
> > + mutex_unlock(&text_mutex);
> > +}
> > +EXPORT_SYMBOL_GPL(arch_static_call_transform);
>
> Errâ I was rewriting __jump_label_transform(), so if this code duplication can
> be avoided, this would be great.
>
> (See https://lkml.org/lkml/2018/11/14/72 )

I don't see much code duplication, because __jump_label_transform() uses
text_poke_bp(), whereas this uses text_poke().

It's true they both fall back to text_poke_early(), but I don't see any
opportunities for sharing code there, unless we decide to go back to
using breakpoints.

--
Josh