* [RFC][PATCH] x86_32: Return actual stack when requesting sp from regs
@ 2012-07-13 19:44 Steven Rostedt
2012-07-18 11:41 ` Masami Hiramatsu
2012-12-09 11:32 ` [tip:x86/asm] " tip-bot for Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2012-07-13 19:44 UTC (permalink / raw)
To: LKML; +Cc: Masami Hiramatsu, Ingo Molnar, Andrew Morton, H. Peter Anvin,
stable
As x86_32 traps do not save sp when taken in kernel mode, we need to
accommodate the sp when requesting to get the register.
This affects kprobes.
Before:
# echo 'p:ftrace sys_read+4 s=%sp' > /debug/tracing/kprobe_events
# echo 1 > /debug/tracing/events/kprobes/enable
# cat trace
sshd-1345 [000] d... 489.117168: ftrace: (sys_read+0x4/0x70) s=b7e96768
sshd-1345 [000] d... 489.117191: ftrace: (sys_read+0x4/0x70) s=b7e96768
cat-1447 [000] d... 489.117392: ftrace: (sys_read+0x4/0x70) s=5a7
cat-1447 [001] d... 489.118023: ftrace: (sys_read+0x4/0x70) s=b77ad05f
less-1448 [000] d... 489.118079: ftrace: (sys_read+0x4/0x70) s=b7762e06
less-1448 [000] d... 489.118117: ftrace: (sys_read+0x4/0x70) s=b7764970
After:
sshd-1352 [000] d... 362.348016: ftrace: (sys_read+0x4/0x70) s=f3febfa8
sshd-1352 [000] d... 362.348048: ftrace: (sys_read+0x4/0x70) s=f3febfa8
bash-1355 [001] d... 362.348081: ftrace: (sys_read+0x4/0x70) s=f5075fa8
sshd-1352 [000] d... 362.348082: ftrace: (sys_read+0x4/0x70) s=f3febfa8
sshd-1352 [000] d... 362.690950: ftrace: (sys_read+0x4/0x70) s=f3febfa8
bash-1355 [001] d... 362.691033: ftrace: (sys_read+0x4/0x70) s=f5075fa8
[ I wonder if this should also go to stable? ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Index: linux-trace.git/arch/x86/include/asm/ptrace.h
===================================================================
--- linux-trace.git.orig/arch/x86/include/asm/ptrace.h
+++ linux-trace.git/arch/x86/include/asm/ptrace.h
@@ -246,6 +246,15 @@ static inline unsigned long regs_get_reg
{
if (unlikely(offset > MAX_REG_OFFSET))
return 0;
+#ifdef CONFIG_X86_32
+ /*
+ * Traps from the kernel do not save sp and ss.
+ * Use the helper function to retrieve sp.
+ */
+ if (offset == offsetof(struct pt_regs, sp) &&
+ regs->cs == __KERNEL_CS)
+ return kernel_stack_pointer(regs);
+#endif
return *(unsigned long *)((unsigned long)regs + offset);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC][PATCH] x86_32: Return actual stack when requesting sp from regs
2012-07-13 19:44 [RFC][PATCH] x86_32: Return actual stack when requesting sp from regs Steven Rostedt
@ 2012-07-18 11:41 ` Masami Hiramatsu
2012-12-09 11:32 ` [tip:x86/asm] " tip-bot for Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2012-07-18 11:41 UTC (permalink / raw)
To: Steven Rostedt; +Cc: LKML, Ingo Molnar, Andrew Morton, H. Peter Anvin, stable
(2012/07/14 4:44), Steven Rostedt wrote:
>
> As x86_32 traps do not save sp when taken in kernel mode, we need to
> accommodate the sp when requesting to get the register.
>
> This affects kprobes.
>
> Before:
>
> # echo 'p:ftrace sys_read+4 s=%sp' > /debug/tracing/kprobe_events
> # echo 1 > /debug/tracing/events/kprobes/enable
> # cat trace
> sshd-1345 [000] d... 489.117168: ftrace: (sys_read+0x4/0x70) s=b7e96768
> sshd-1345 [000] d... 489.117191: ftrace: (sys_read+0x4/0x70) s=b7e96768
> cat-1447 [000] d... 489.117392: ftrace: (sys_read+0x4/0x70) s=5a7
> cat-1447 [001] d... 489.118023: ftrace: (sys_read+0x4/0x70) s=b77ad05f
> less-1448 [000] d... 489.118079: ftrace: (sys_read+0x4/0x70) s=b7762e06
> less-1448 [000] d... 489.118117: ftrace: (sys_read+0x4/0x70) s=b7764970
>
> After:
> sshd-1352 [000] d... 362.348016: ftrace: (sys_read+0x4/0x70) s=f3febfa8
> sshd-1352 [000] d... 362.348048: ftrace: (sys_read+0x4/0x70) s=f3febfa8
> bash-1355 [001] d... 362.348081: ftrace: (sys_read+0x4/0x70) s=f5075fa8
> sshd-1352 [000] d... 362.348082: ftrace: (sys_read+0x4/0x70) s=f3febfa8
> sshd-1352 [000] d... 362.690950: ftrace: (sys_read+0x4/0x70) s=f3febfa8
> bash-1355 [001] d... 362.691033: ftrace: (sys_read+0x4/0x70) s=f5075fa8
>
> [ I wonder if this should also go to stable? ]
>
This obviously makes tracing output better on i386. Original %sp
gives nothing (or just misleading)...
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
NOTE: if someone needs to get kernel stack address from regs,
I recommend him to use kernel_stack_pointer() directly.
Thank you,
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
>
> Index: linux-trace.git/arch/x86/include/asm/ptrace.h
> ===================================================================
> --- linux-trace.git.orig/arch/x86/include/asm/ptrace.h
> +++ linux-trace.git/arch/x86/include/asm/ptrace.h
> @@ -246,6 +246,15 @@ static inline unsigned long regs_get_reg
> {
> if (unlikely(offset > MAX_REG_OFFSET))
> return 0;
> +#ifdef CONFIG_X86_32
> + /*
> + * Traps from the kernel do not save sp and ss.
> + * Use the helper function to retrieve sp.
> + */
> + if (offset == offsetof(struct pt_regs, sp) &&
> + regs->cs == __KERNEL_CS)
> + return kernel_stack_pointer(regs);
> +#endif
> return *(unsigned long *)((unsigned long)regs + offset);
> }
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:x86/asm] x86_32: Return actual stack when requesting sp from regs
2012-07-13 19:44 [RFC][PATCH] x86_32: Return actual stack when requesting sp from regs Steven Rostedt
2012-07-18 11:41 ` Masami Hiramatsu
@ 2012-12-09 11:32 ` tip-bot for Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Steven Rostedt @ 2012-12-09 11:32 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, masami.hiramatsu.pt, rostedt, tglx
Commit-ID: 6c8d8b3c69cef1330e0c5cbc2a8b9268024927a0
Gitweb: http://git.kernel.org/tip/6c8d8b3c69cef1330e0c5cbc2a8b9268024927a0
Author: Steven Rostedt <rostedt@goodmis.org>
AuthorDate: Fri, 13 Jul 2012 15:44:14 -0400
Committer: Steven Rostedt <rostedt@goodmis.org>
CommitDate: Mon, 19 Nov 2012 05:31:37 -0500
x86_32: Return actual stack when requesting sp from regs
As x86_32 traps do not save sp when taken in kernel mode, we need to
accommodate the sp when requesting to get the register.
This affects kprobes.
Before:
# echo 'p:ftrace sys_read+4 s=%sp' > /debug/tracing/kprobe_events
# echo 1 > /debug/tracing/events/kprobes/enable
# cat trace
sshd-1345 [000] d... 489.117168: ftrace: (sys_read+0x4/0x70) s=b7e96768
sshd-1345 [000] d... 489.117191: ftrace: (sys_read+0x4/0x70) s=b7e96768
cat-1447 [000] d... 489.117392: ftrace: (sys_read+0x4/0x70) s=5a7
cat-1447 [001] d... 489.118023: ftrace: (sys_read+0x4/0x70) s=b77ad05f
less-1448 [000] d... 489.118079: ftrace: (sys_read+0x4/0x70) s=b7762e06
less-1448 [000] d... 489.118117: ftrace: (sys_read+0x4/0x70) s=b7764970
After:
sshd-1352 [000] d... 362.348016: ftrace: (sys_read+0x4/0x70) s=f3febfa8
sshd-1352 [000] d... 362.348048: ftrace: (sys_read+0x4/0x70) s=f3febfa8
bash-1355 [001] d... 362.348081: ftrace: (sys_read+0x4/0x70) s=f5075fa8
sshd-1352 [000] d... 362.348082: ftrace: (sys_read+0x4/0x70) s=f3febfa8
sshd-1352 [000] d... 362.690950: ftrace: (sys_read+0x4/0x70) s=f3febfa8
bash-1355 [001] d... 362.691033: ftrace: (sys_read+0x4/0x70) s=f5075fa8
Link: http://lkml.kernel.org/r/1342208654.30075.22.camel@gandalf.stny.rr.com
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/x86/include/asm/ptrace.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
index dcfde52..2233713 100644
--- a/arch/x86/include/asm/ptrace.h
+++ b/arch/x86/include/asm/ptrace.h
@@ -246,6 +246,15 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
{
if (unlikely(offset > MAX_REG_OFFSET))
return 0;
+#ifdef CONFIG_X86_32
+ /*
+ * Traps from the kernel do not save sp and ss.
+ * Use the helper function to retrieve sp.
+ */
+ if (offset == offsetof(struct pt_regs, sp) &&
+ regs->cs == __KERNEL_CS)
+ return kernel_stack_pointer(regs);
+#endif
return *(unsigned long *)((unsigned long)regs + offset);
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-09 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-13 19:44 [RFC][PATCH] x86_32: Return actual stack when requesting sp from regs Steven Rostedt
2012-07-18 11:41 ` Masami Hiramatsu
2012-12-09 11:32 ` [tip:x86/asm] " tip-bot for Steven Rostedt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.