public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Harvey Harrison <harvey.harrison@gmail.com>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Jim Keniston <jkenisto@us.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] x86: Introduce REX prefix helper for kprobes
Date: Sun, 30 Dec 2007 01:35:25 -0500	[thread overview]
Message-ID: <47773C2D.8070600@redhat.com> (raw)
In-Reply-To: <1198466795.6323.12.camel@brick>

Hi Harvey,

Harvey Harrison wrote:
> Fold some small ifdefs into a helper function.
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
> Masami, Ingo, I had this left in some unsent kprobes unification
> work.  Depends on your tastes, but does reduce ifdefs and is a bit
> better about self-documenting the REX prefix on X86_64.

Basically, I think it is good idea.
Could you use a macro same as the stack_addr() macro, like as below?

#defile is_REX_prefix(insn) ((insn & 0xf0) == 0x40))

This is just a bit checker, so I think a macro is better to do that.

> If I find places that could also use this I'll try to find a suitable
> header any stick a static inline there instead.  Otherwise static to
> kprobes.c is probably more appropriate for now.
> 
>  arch/x86/kernel/kprobes.c |   27 +++++++++++++++++++--------
>  1 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
> index 4e33329..b1804e4 100644
> --- a/arch/x86/kernel/kprobes.c
> +++ b/arch/x86/kernel/kprobes.c
> @@ -171,6 +171,19 @@ static void __kprobes set_jmp_op(void *from, void *to)
>  }
>  
>  /*
> + * Check for the REX prefix which can only exist on X86_64
> + * X86_32 always returns 0
> + */
> +static int __kprobes is_REX_prefix(kprobe_opcode_t *insn)
> +{
> +#ifdef CONFIG_X86_64
> +	if ((*insn & 0xf0) == 0x40)
> +		return 1;
> +#endif
> +	return 0;
> +}
> +
> +/*
>   * Returns non-zero if opcode is boostable.
>   * RIP relative instructions are adjusted at copying time in 64 bits mode
>   */
> @@ -239,14 +252,14 @@ static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
>  	case 0x9d:		/* popf/popfd */
>  		return 1;
>  	}
> -#ifdef CONFIG_X86_64
> +
>  	/*
> -	 * on 64 bit x86, 0x40-0x4f are prefixes so we need to look
> +	 * on X86_64, 0x40-0x4f are REX prefixes so we need to look
>  	 * at the next byte instead.. but of course not recurse infinitely
>  	 */
> -	if (*insn  >= 0x40 && *insn <= 0x4f)
> +	if (is_REX_prefix(insn))
>  		return is_IF_modifier(++insn);
> -#endif
> +
>  	return 0;
>  }
>  
> @@ -284,7 +297,7 @@ static void __kprobes fix_riprel(struct kprobe *p)
>  	}
>  
>  	/* Skip REX instruction prefix.  */
> -	if ((*insn & 0xf0) == 0x40)
> +	if (is_REX_prefix(insn))
>  		++insn;
>  
>  	if (*insn == 0x0f) {
> @@ -748,11 +761,9 @@ static void __kprobes resume_execution(struct kprobe *p,
>  	unsigned long orig_ip = (unsigned long)p->addr;
>  	kprobe_opcode_t *insn = p->ainsn.insn;
>  
> -#ifdef CONFIG_X86_64
>  	/*skip the REX prefix*/
> -	if (*insn >= 0x40 && *insn <= 0x4f)
> +	if (is_REX_prefix(insn))
>  		insn++;
> -#endif
>  
>  	regs->flags &= ~X86_EFLAGS_TF;
>  	switch (*insn) {

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com, masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2007-12-30  6:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-24  3:26 [PATCH] x86: Introduce REX prefix helper for kprobes Harvey Harrison
2007-12-30  6:35 ` Masami Hiramatsu [this message]
2007-12-30  7:04   ` H. Peter Anvin
2007-12-30  8:01     ` Masami Hiramatsu
2007-12-30  8:31       ` Masami Hiramatsu
2007-12-30 13:19       ` Ingo Molnar
2007-12-30 17:39     ` Harvey Harrison
2007-12-30 13:42 ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47773C2D.8070600@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=harvey.harrison@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jkenisto@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox