public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: kprobes remove fix_riprel #ifdef
@ 2007-12-24  3:28 Harvey Harrison
  2007-12-30  6:37 ` Masami Hiramatsu
  0 siblings, 1 reply; 6+ messages in thread
From: Harvey Harrison @ 2007-12-24  3:28 UTC (permalink / raw)
  To: Ingo Molnar, Masami Hiramatsu; +Cc: LKML, H. Peter Anvin, Thomas Gleixner

Move #ifdef around function definiton into the function and
unconditionally return on X86_32.  Saves an ifdef from the
one callsite.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Ingo, Masami, final leftovers from some unsent kprobes unification work.

Net reduction of one #ifdef section.

 arch/x86/kernel/kprobes.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index b1804e4..1ac532e 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -263,15 +263,16 @@ static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
 	return 0;
 }
 
-#ifdef CONFIG_X86_64
 /*
  * Adjust the displacement if the instruction uses the %rip-relative
  * addressing mode.
  * If it does, Return the address of the 32-bit displacement word.
  * If not, return null.
+ * Only applicable to X86_64
  */
 static void __kprobes fix_riprel(struct kprobe *p)
 {
+#ifdef CONFIG_X86_64
 	u8 *insn = p->ainsn.insn;
 	s64 disp;
 	int need_modrm;
@@ -335,15 +336,17 @@ static void __kprobes fix_riprel(struct kprobe *p)
 			*(s32 *)insn = (s32) disp;
 		}
 	}
-}
+#else
+	return;
 #endif
+}
 
 static void __kprobes arch_copy_kprobe(struct kprobe *p)
 {
 	memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
-#ifdef CONFIG_X86_64
+
 	fix_riprel(p);
-#endif
+
 	if (can_boost(p->addr))
 		p->ainsn.boostable = 0;
 	else
-- 
1.5.4.rc0.1143.g1a8a




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86: kprobes remove fix_riprel #ifdef
  2007-12-24  3:28 [PATCH] x86: kprobes remove fix_riprel #ifdef Harvey Harrison
@ 2007-12-30  6:37 ` Masami Hiramatsu
  2007-12-30 13:23   ` Ingo Molnar
  0 siblings, 1 reply; 6+ messages in thread
From: Masami Hiramatsu @ 2007-12-30  6:37 UTC (permalink / raw)
  To: Harvey Harrison, Ananth N Mavinakayanahalli, Jim Keniston
  Cc: Ingo Molnar, LKML, H. Peter Anvin, Thomas Gleixner

Hello Harvey,

A similar idea was already nack-ed by Ananth.
http://sources.redhat.com/ml/systemtap/2007-q4/msg00468.html
And I agree his thought.

Especially, "riprel" does not exist on x86_32, so fix_riprel()
is meaningless on it.
Thus, I think it would better be ifdef'd in call-site.

Harvey Harrison wrote:
> Move #ifdef around function definiton into the function and
> unconditionally return on X86_32.  Saves an ifdef from the
> one callsite.
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
> Ingo, Masami, final leftovers from some unsent kprobes unification work.
> 
> Net reduction of one #ifdef section.
> 
>  arch/x86/kernel/kprobes.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
> index b1804e4..1ac532e 100644
> --- a/arch/x86/kernel/kprobes.c
> +++ b/arch/x86/kernel/kprobes.c
> @@ -263,15 +263,16 @@ static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_X86_64
>  /*
>   * Adjust the displacement if the instruction uses the %rip-relative
>   * addressing mode.
>   * If it does, Return the address of the 32-bit displacement word.
>   * If not, return null.
> + * Only applicable to X86_64
>   */
>  static void __kprobes fix_riprel(struct kprobe *p)
>  {
> +#ifdef CONFIG_X86_64
>  	u8 *insn = p->ainsn.insn;
>  	s64 disp;
>  	int need_modrm;
> @@ -335,15 +336,17 @@ static void __kprobes fix_riprel(struct kprobe *p)
>  			*(s32 *)insn = (s32) disp;
>  		}
>  	}
> -}
> +#else
> +	return;
>  #endif
> +}
>  
>  static void __kprobes arch_copy_kprobe(struct kprobe *p)
>  {
>  	memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
> -#ifdef CONFIG_X86_64
> +
>  	fix_riprel(p);
> -#endif
> +
>  	if (can_boost(p->addr))
>  		p->ainsn.boostable = 0;
>  	else

-- 
Masami Hiramatsu

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

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86: kprobes remove fix_riprel #ifdef
  2007-12-30  6:37 ` Masami Hiramatsu
@ 2007-12-30 13:23   ` Ingo Molnar
  2007-12-30 14:52     ` Masami Hiramatsu
  0 siblings, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2007-12-30 13:23 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Harvey Harrison, Ananth N Mavinakayanahalli, Jim Keniston, LKML,
	H. Peter Anvin, Thomas Gleixner


* Masami Hiramatsu <mhiramat@redhat.com> wrote:

> Hello Harvey,
> 
> A similar idea was already nack-ed by Ananth.
> http://sources.redhat.com/ml/systemtap/2007-q4/msg00468.html
> And I agree his thought.
> 
> Especially, "riprel" does not exist on x86_32, so fix_riprel()
> is meaningless on it.
> Thus, I think it would better be ifdef'd in call-site.

but we regularly do this in generic code: we add calls that are NOPs on 
some architectures. For example flush_cache_page() makes no sense on the 
x86 architecture. So i'm inclined to apply Harvey's cleanup - less
#ifdef complexity in higher-level code is very much favored, even
if "riprel" is a NOP concept on 32-bit.

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86: kprobes remove fix_riprel #ifdef
  2007-12-30 13:23   ` Ingo Molnar
@ 2007-12-30 14:52     ` Masami Hiramatsu
  2007-12-30 15:45       ` Ingo Molnar
  0 siblings, 1 reply; 6+ messages in thread
From: Masami Hiramatsu @ 2007-12-30 14:52 UTC (permalink / raw)
  To: Ingo Molnar, Ananth N Mavinakayanahalli
  Cc: Harvey Harrison, Jim Keniston, LKML, H. Peter Anvin,
	Thomas Gleixner

Hello Ingo,

Ingo Molnar wrote:
> * Masami Hiramatsu <mhiramat@redhat.com> wrote:
> 
>> Hello Harvey,
>>
>> A similar idea was already nack-ed by Ananth.
>> http://sources.redhat.com/ml/systemtap/2007-q4/msg00468.html
>> And I agree his thought.
>>
>> Especially, "riprel" does not exist on x86_32, so fix_riprel()
>> is meaningless on it.
>> Thus, I think it would better be ifdef'd in call-site.
> 
> but we regularly do this in generic code: we add calls that are NOPs on 
> some architectures. For example flush_cache_page() makes no sense on the 
> x86 architecture.

Indeed.
By the way, flush_cache_page() is defined as a do-while(0) on x86.
Would it better to define fix_riprel() as a do-while(0) on x86-32?
I think this obviously indicates that function has no effect.

> So i'm inclined to apply Harvey's cleanup - less
> #ifdef complexity in higher-level code is very much favored, even
> if "riprel" is a NOP concept on 32-bit.

OK, I agree about that fix_riprel() which is ifdef'd twice is too much ifdef'd.
Reducing ifdef is good to me.

Thanks,
> 
> 	Ingo

-- 
Masami Hiramatsu

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

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86: kprobes remove fix_riprel #ifdef
  2007-12-30 14:52     ` Masami Hiramatsu
@ 2007-12-30 15:45       ` Ingo Molnar
  2007-12-30 20:04         ` Masami Hiramatsu
  0 siblings, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2007-12-30 15:45 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ananth N Mavinakayanahalli, Harvey Harrison, Jim Keniston, LKML,
	H. Peter Anvin, Thomas Gleixner


* Masami Hiramatsu <mhiramat@redhat.com> wrote:

> Indeed.
> By the way, flush_cache_page() is defined as a do-while(0) on x86.
> Would it better to define fix_riprel() as a do-while(0) on x86-32?
> I think this obviously indicates that function has no effect.

NOPs should always be an inline. flush_cache_page()'s macro use is 
historic - feel free to send cleanup patches against cacheflush.h.

or even better, since most architectures dont need explicit 
cache-flushes, provide an asm-generic/cache_flush-nop.h file that is
#include-ed by asm-x86/cacheflush.h. (and by other architectures)

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86: kprobes remove fix_riprel #ifdef
  2007-12-30 15:45       ` Ingo Molnar
@ 2007-12-30 20:04         ` Masami Hiramatsu
  0 siblings, 0 replies; 6+ messages in thread
From: Masami Hiramatsu @ 2007-12-30 20:04 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Ananth N Mavinakayanahalli, Harvey Harrison, Jim Keniston, LKML,
	H. Peter Anvin, Thomas Gleixner

Ingo Molnar wrote:
> * Masami Hiramatsu <mhiramat@redhat.com> wrote:
> 
>> Indeed.
>> By the way, flush_cache_page() is defined as a do-while(0) on x86.
>> Would it better to define fix_riprel() as a do-while(0) on x86-32?
>> I think this obviously indicates that function has no effect.
> 
> NOPs should always be an inline. flush_cache_page()'s macro use is 
> historic - feel free to send cleanup patches against cacheflush.h.

OK, in that case, harvey's patch is good to me.

> or even better, since most architectures dont need explicit 
> cache-flushes, provide an asm-generic/cache_flush-nop.h file that is
> #include-ed by asm-x86/cacheflush.h. (and by other architectures)
> 
> 	Ingo

Thanks,

-- 
Masami Hiramatsu

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

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-12-30 20:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-24  3:28 [PATCH] x86: kprobes remove fix_riprel #ifdef Harvey Harrison
2007-12-30  6:37 ` Masami Hiramatsu
2007-12-30 13:23   ` Ingo Molnar
2007-12-30 14:52     ` Masami Hiramatsu
2007-12-30 15:45       ` Ingo Molnar
2007-12-30 20:04         ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox