lkml.org 
[lkml]   [2019]   [Nov]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH -v5 04/17] x86/alternatives: Add and use text_gen_insn() helper
On Tue, Nov 12, 2019 at 12:10:28PM -0500, Steven Rostedt wrote:
> On Mon, 11 Nov 2019 14:12:56 +0100
> Peter Zijlstra <peterz@infradead.org> 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().

:-)

Sure, I'll add something like:

/*
* Ensure that for JMP.d8 the displacement
* actually fits the signed byte.
*/

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

\
 
 \ /
  Last update: 2019-11-12 23:27    [W:0.068 / U:6.436 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site