Skip to contentSkip to conversation

update v2 fix X86_64 procfs provide stack information for threads

PATCH In review Stefani Seibold 1 participant 2 messages Nov 3, 2009 – Nov 4, 2009

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

PATCH 1/1 update v2 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.

Please apply this patch!

Greetings,
Stefani

---
 arch/x86/include/asm/processor.h |    2 +-
 arch/x86/kernel/process_64.c     |    6 ++++++
 fs/compat.c                      |    2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
fs/compat.c renamed from linux-2.6.32-rc5/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 renamed from linux-2.6.32-rc5/arch/x86/include/asm/processor.h +1 -1
@@ -1000,7 +1000,7 @@
 #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. */
+extern unsigned long KSTK_ESP(struct task_struct *task);
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
arch/x86/kernel/process_64.c renamed from linux-2.6.32-rc5/arch/x86/kernel/process_64.c +6 -0
@@ -664,3 +664,9 @@
 	return do_arch_prctl(current, code, addr);
 }
 
+unsigned long KSTK_ESP(struct task_struct *task)
+{
+	return (test_tsk_thread_flag(task, TIF_IA32)) ? \
+			(task_pt_regs(task)->sp) : \
+			((task)->thread.usersp);
+}
#1 lore raw

[tip:x86/urgent] x86, fs: Fix x86 procfs stack information for threads on 64-bit

Commit-ID:  89240ba059ca468ae7a8346edf7f95082458c2fc
Gitweb:     http://git.kernel.org/tip/89240ba059ca468ae7a8346edf7f95082458c2fc
Author:     Stefani Seibold <[email protected]>
AuthorDate: Tue, 3 Nov 2009 10:22:40 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 4 Nov 2009 13:25:03 +0100

x86, fs: Fix x86 procfs stack information for threads on 64-bit

This patch fixes 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 Dobriyan).

The stack information on a x64_64 kernel always shows 0 kbyte stack usage, because of a missing implementation of the KSTK_ESP macro which always returned -1.

The new implementation now returns the right value.

Cc Americo Wang <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Al Viro <[email protected]>
Cc Andrew Morton <[email protected]>

LKML-Reference: <1257240160.4889.24.camel@wall-e>

---
 arch/x86/include/asm/processor.h |    2 +-
 arch/x86/kernel/process_64.c     |    5 +++++
 fs/compat.c                      |    2 ++
 3 files changed, 8 insertions(+), 1 deletions(-)
arch/x86/include/asm/processor.h +1 -1
index c3429e8..c978648 100644
@@ -1000,7 +1000,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
 #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. */
+extern unsigned long KSTK_ESP(struct task_struct *task);
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
arch/x86/kernel/process_64.c +5 -0
index ad535b6..eb62cbc 100644
@@ -664,3 +664,8 @@ long sys_arch_prctl(int code, unsigned long addr)
 	return do_arch_prctl(current, code, addr);
 }
 
+unsigned long KSTK_ESP(struct task_struct *task)
+{
+	return (test_tsk_thread_flag(task, TIF_IA32)) ?
+			(task_pt_regs(task)->sp) : ((task)->thread.usersp);
+}
fs/compat.c +2 -0
index d576b55..6c19040 100644
@@ -1532,6 +1532,8 @@ int compat_do_execve(char * filename,
 	if (retval < 0)
 		goto out;
 
+	current->stack_start = current->mm->start_stack;
+
 	/* execve succeeded */
 	current->fs->in_exec = 0;
 	current->in_execve = 0;