Skip to contentSkip to conversation

fix X86_64 procfs provide stack information for threads

PATCH In review Stefani Seibold 3 participants 5 messages Nov 2, 2009 – Nov 3, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix X86_64 procfs provide stack information for threads

This patch fix two issues in the procfs stack information on X86_64 linux.

The 32 bit loader compat_do_execve did not store stack start (this was figured out by alexey).

The stack information on a X64_64 kernel always show 0 kbyte stack usage, because of a miss implemented KSTK_ESP macro which always return -1. The new implementation returns now the right value.

The patch is against 2.6.32-rc5-git5.

Andrew would you so kind to apply this patch?

Greetings,
Stefani

---
 arch/x86/include/asm/processor.h |    9 ++++++++-
 arch/x86/kernel/process_64.c     |    8 ++++++++
 fs/compat.c                      |    2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)
fs/compat.c +2 -0
@@ -1532,6 +1532,8 @@
 	if (retval < 0)
 		goto out;
 
+	current->stack_start = current->mm->start_stack;
+
 	/* execve succeeded */
 	current->fs->in_exec = 0;
 	current->in_execve = 0;
arch/x86/include/asm/processor.h +8 -1
@@ -29,6 +29,7 @@
 #include <linux/threads.h>
 #include <linux/math64.h>
 #include <linux/init.h>
+//#include <linux/sched.h>
 
 /*
  * Default implementation of macro that returns current
@@ -1000,7 +1001,13 @@
 #define thread_saved_pc(t)	(*(unsigned long *)((t)->thread.sp - 8))
 
 #define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.sp0 - 1)
-#define KSTK_ESP(tsk)		-1 /* sorry. doesn't work for syscall. */
+
+#ifdef CONFIG_IA32_EMULATION
+extern unsigned long KSTK_ESP(struct task_struct *task);
+#else
+#define KSTK_ESP(task)		((task)->thread.usersp)
+#endif
+
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
arch/x86/kernel/process_64.c +8 -0
@@ -664,3 +669,11 @@
 	return do_arch_prctl(current, code, addr);
 }
 
+#ifdef CONFIG_IA32_EMULATION
+unsigned long KSTK_ESP(struct task_struct *task)
+{
+	return (test_tsk_thread_flag(task, TIF_IA32)) ? \
+			(task_pt_regs(task)->sp) : \
+			((task)->thread.usersp);
+}
+#endif
Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · Stefani Seibold

This patch fix two issues in the procfs stack information on X86_64 linux.

The 32 bit loader compat_do_execve did not store stack start (this was figured out by alexey).

The stack information on a X64_64 kernel always show 0 kbyte stack usage, because of a miss implemented KSTK_ESP macro which always return -1. The new implementation returns now the right value.

The patch is against 2.6.32-rc5-git5.

Andrew would you so kind to apply this patch?

Greetings,
Stefani

---

arch/x86/include/asm/processor.h |    9 ++++++++-
arch/x86/kernel/process_64.c     |    8 ++++++++
fs/compat.c                      |    2 ++
3 files changed, 18 insertions(+), 1 deletion(-)
fs/compat.c +2 -0
@@ -1532,6 +1532,8 @@
 	if (retval < 0)
 		goto out;
 
+	current->stack_start = current->mm->start_stack;
+
 	/* execve succeeded */
 	current->fs->in_exec = 0;
 	current->in_execve = 0;

arch/x86/include/asm/processor.h line 32

Quoted 4 lines
arch/x86/include/asm/processor.h +1 -0
@@ -29,6 +29,7 @@
 #include <linux/threads.h>
 #include <linux/math64.h>
 #include <linux/init.h>
+//#include <linux/sched.h>

Hey, what is this? :)

Except this, this patch looks fine for me:

Quoted 39 lines
arch/x86/include/asm/processor.h +7 -1
 /*
 * Default implementation of macro that returns current
@@ -1000,7 +1001,13 @@
 #define thread_saved_pc(t)	(*(unsigned long *)((t)->thread.sp - 8))
 
 #define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.sp0 - 1)
-#define KSTK_ESP(tsk)		-1 /* sorry. doesn't work for syscall. */
+
+#ifdef CONFIG_IA32_EMULATION
+extern unsigned long KSTK_ESP(struct task_struct *task);
+#else
+#define KSTK_ESP(task)		((task)->thread.usersp)
+#endif
+
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
arch/x86/kernel/process_64.c +8 -1
@@ -664,3 +669,11 @@
 	return do_arch_prctl(current, code, addr);
 }
 
+#ifdef CONFIG_IA32_EMULATION
+unsigned long KSTK_ESP(struct task_struct *task)
+{
+	return (test_tsk_thread_flag(task, TIF_IA32)) ? \
+			(task_pt_regs(task)->sp) : \
+			((task)->thread.usersp);
+}
+#endif
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Live like a child, think like the god.
#2 lore raw

Am Dienstag, den 03.11.2009, 13:58 +0800 schrieb Américo Wang:

Quoted 11 lines · Stefani Seibold

arch/x86/include/asm/processor.h line 32

Quoted 7 lines
arch/x86/include/asm/processor.h +1 -0
@@ -29,6 +29,7 @@
 #include <linux/threads.h>
 #include <linux/math64.h>
 #include <linux/init.h>
+//#include <linux/sched.h>

Hey, what is this? :)

Garbage :-( I will resend the patch without!

Quoted 3 lines

Except this, this patch looks fine for me:

#3 lore raw
In reply to Stefani Seibold
Quoted 2 lines · Stefani Seibold

The 32 bit loader compat_do_execve did not store stack start (this was figured out by alexey).

yeah, but let's not mix it since these are two different issues and KSTK_ESP should go through Ingo.

#4 lore raw

Am Dienstag, den 03.11.2009, 12:06 +0300 schrieb Alexey Dobriyan:

Quoted 6 lines · Stefani Seibold
Quoted 2 lines

The 32 bit loader compat_do_execve did not store stack start (this was figured out by alexey).

yeah, but let's not mix it since these are two different issues and KSTK_ESP should go through Ingo.

Ingo has contacted me... He has some complains about the #ifdef, so i remove it. I will put you on the list.