Re: [PATCH -v5 04/17] x86/alternatives: Add and use text_gen_insn() helper

From: Steven Rostedt
Date: Tue Nov 12 2019 - 12:10:33 EST


On Mon, 11 Nov 2019 14:12:56 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> +void *text_gen_insn(u8 opcode, const void *addr, const void *dest)
> +{
> + static union text_poke_insn insn; /* text_mutex */
> + int size = 0;
> +
> + lockdep_assert_held(&text_mutex);
> +
> + insn.opcode = opcode;
> +
> +#define __CASE(insn) \
> + case insn##_INSN_OPCODE: size = insn##_INSN_SIZE; break
> +
> + switch(opcode) {
> + __CASE(INT3);
> + __CASE(CALL);
> + __CASE(JMP32);
> + __CASE(JMP8);
> + }
> +
> + if (size > 1) {
> + insn.disp = (long)dest - (long)(addr + size);
> + if (size == 2)

Could we add a comment here. It took me a little bit to figure out why
you have this BUG_ON().

-- Steve


> + BUG_ON((insn.disp >> 31) != (insn.disp >> 7));
> + }
> +
> + return &insn.text;
> +}