Messages in this thread | | | Date | Fri, 25 Feb 2022 12:20:46 +0100 | From | Peter Zijlstra <> | Subject | Re: [PATCH v2 16/39] x86/bpf: Add ENDBR instructions to prologue and trampoline |
| |
On Thu, Feb 24, 2022 at 03:37:31PM -0800, Josh Poimboeuf wrote: > On Thu, Feb 24, 2022 at 03:51:54PM +0100, Peter Zijlstra wrote: > > @@ -339,9 +350,18 @@ static int __bpf_arch_text_poke(void *ip > > u8 *prog; > > int ret; > > > > +#ifdef CONFIG_X86_KERNEL_IBT > > + if (is_endbr(*(u32 *)ip)) > > + ip += 4; > > +#endif > > + > > memcpy(old_insn, nop_insn, X86_PATCH_SIZE); > > if (old_addr) { > > prog = old_insn; > > +#ifdef CONFIG_X86_KERNEL_IBT > > + if (is_endbr(*(u32 *)old_addr)) > > + old_addr += 4; > > +#endif > > ret = t == BPF_MOD_CALL ? > > emit_call(&prog, old_addr, ip) : > > emit_jump(&prog, old_addr, ip); > > @@ -352,6 +372,10 @@ static int __bpf_arch_text_poke(void *ip > > memcpy(new_insn, nop_insn, X86_PATCH_SIZE); > > if (new_addr) { > > prog = new_insn; > > +#ifdef CONFIG_X86_KERNEL_IBT > > + if (is_endbr(*(u32 *)new_addr)) > > + new_addr += 4; > > +#endif > > All the above ifdef-itis should be able to be removed since is_endbr() > returns false for !IBT.
So I've been pondering a skip_endbr() function for all these sites.
I just couldn't decide making it a 'function' and having a signature like:
ip = skip_endbr(ip);
or making it macro magic and it reading:
skip_endbr(ip);
Which is why I've not cleaned it up yet. This being C(ish) I suppose the former is less confusing, so let me go do that.
| |