Re: [PATCH v4 2/5] x86/alternative: add indirect call patching
From: Peter Zijlstra
Date: Tue Nov 14 2023 - 07:50:57 EST
On Tue, Nov 14, 2023 at 01:37:37PM +0100, Borislav Petkov wrote:
> > +#ifdef CONFIG_X86_64
> > + /* ff 15 00 00 00 00 call *0x0(%rip) */
> > + target = *(void **)(instr + a->instrlen + *(s32 *)(instr + 2));
> > +#else
> > + /* ff 15 00 00 00 00 call *0x0 */
> > + target = *(void **)(*(s32 *)(instr + 2));
> > +#endif
> > + if (!target)
> > + target = bug;
> > +
> > + /* (BUG_func - .) + (target - BUG_func) := target - . */
> > + *(s32 *)(insn_buff + 1) += target - bug;
>
> If I squint hard enough, this looks like it is replacing one call with
> another. We have a C macro alternative_call() which does exactly that.
> Why can't you define an asm version ALTERNATIVE_CALL and use it
> instead of using adding a new flag? We have 16 possible ones in total.
This loads the function target from the pv_ops table. We can't otherwise
do this.