Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1235900

[patch 2/2] x86/process: Unify 32bit and 64bit implementations of get_wchan()

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject [patch 2/2] x86/process: Unify 32bit and 64bit implementations of get_wchan()
Date 2015-09-30 10:40 +0200
Message-ID <qel5F-85q-23@gated-at.bofh.it> (permalink)
References <qel5D-85q-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


The stack layout and the functionality is identical. Use the 64bit
version for all of x86.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/process.c    |   55 ++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/process_32.c |   28 ---------------------
 arch/x86/kernel/process_64.c |   56 -------------------------------------------
 3 files changed, 55 insertions(+), 84 deletions(-)

Index: tip/arch/x86/kernel/process.c
===================================================================
--- tip.orig/arch/x86/kernel/process.c
+++ tip/arch/x86/kernel/process.c
@@ -506,3 +506,58 @@ unsigned long arch_randomize_brk(struct
 	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
 }
 
+/*
+ * Called from fs/proc with a reference on @p to find the function
+ * which called into schedule(). This needs to be done carefully
+ * because the task might wake up and we might look at a stack
+ * changing under us.
+ */
+unsigned long get_wchan(struct task_struct *p)
+{
+	unsigned long start, bottom, top, sp, fp, ip;
+	int count = 0;
+
+	if (!p || p == current || p->state == TASK_RUNNING)
+		return 0;
+
+	start = (unsigned long)task_stack_page(p);
+	if (!start)
+		return 0;
+
+	/*
+	 * Layout of the stack page:
+	 *
+	 * ----------- topmax = start + THREAD_SIZE - sizeof(unsigned long)
+	 * PADDING
+	 * ----------- top = topmax - TOP_OF_KERNEL_STACK_PADDING
+	 * stack
+	 * ----------- bottom = start + sizeof(thread_info)
+	 * thread_info
+	 * ----------- start
+	 *
+	 * The tasks stack pointer points at the location where the
+	 * framepointer is stored. The data on the stack is:
+	 * ... IP FP ... IP FP
+	 *
+	 * We need to read FP and IP, so we need to adjust the upper
+	 * bound by another unsigned long.
+	 */
+	top = start + THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING;
+	top -= 2 * sizeof(unsigned long);
+	bottom = start + sizeof(struct thread_info);
+
+	sp = READ_ONCE(p->thread.sp);
+	if (sp < bottom || sp > top)
+		return 0;
+
+	fp = READ_ONCE(*(unsigned long *)sp);
+	do {
+		if (fp < bottom || fp > top)
+			return 0;
+		ip = READ_ONCE(*(unsigned long *)(fp + sizeof(unsigned long)));
+		if (!in_sched_functions(ip))
+			return ip;
+		fp = READ_ONCE(*(unsigned long *)fp);
+	} while (count++ < 16 && p->state != TASK_RUNNING);
+	return 0;
+}
Index: tip/arch/x86/kernel/process_32.c
===================================================================
--- tip.orig/arch/x86/kernel/process_32.c
+++ tip/arch/x86/kernel/process_32.c
@@ -324,31 +324,3 @@ __switch_to(struct task_struct *prev_p,
 
 	return prev_p;
 }
-
-#define top_esp                (THREAD_SIZE - sizeof(unsigned long))
-#define top_ebp                (THREAD_SIZE - 2*sizeof(unsigned long))
-
-unsigned long get_wchan(struct task_struct *p)
-{
-	unsigned long bp, sp, ip;
-	unsigned long stack_page;
-	int count = 0;
-	if (!p || p == current || p->state == TASK_RUNNING)
-		return 0;
-	stack_page = (unsigned long)task_stack_page(p);
-	sp = p->thread.sp;
-	if (!stack_page || sp < stack_page || sp > top_esp+stack_page)
-		return 0;
-	/* include/asm-i386/system.h:switch_to() pushes bp last. */
-	bp = *(unsigned long *) sp;
-	do {
-		if (bp < stack_page || bp > top_ebp+stack_page)
-			return 0;
-		ip = *(unsigned long *) (bp+4);
-		if (!in_sched_functions(ip))
-			return ip;
-		bp = *(unsigned long *) bp;
-	} while (count++ < 16);
-	return 0;
-}
-
Index: tip/arch/x86/kernel/process_64.c
===================================================================
--- tip.orig/arch/x86/kernel/process_64.c
+++ tip/arch/x86/kernel/process_64.c
@@ -499,62 +499,6 @@ void set_personality_ia32(bool x32)
 }
 EXPORT_SYMBOL_GPL(set_personality_ia32);
 
-/*
- * Called from fs/proc with a reference on @p to find the function
- * which called into schedule(). This needs to be done carefully
- * because the task might wake up and we might look at a stack
- * changing under us.
- */
-unsigned long get_wchan(struct task_struct *p)
-{
-	unsigned long start, bottom, top, sp, fp, ip;
-	int count = 0;
-
-	if (!p || p == current || p->state == TASK_RUNNING)
-		return 0;
-
-	start = (unsigned long)task_stack_page(p);
-	if (!start)
-		return 0;
-
-	/*
-	 * Layout of the stack page:
-	 *
-	 * ----------- topmax = start + THREAD_SIZE - sizeof(unsigned long)
-	 * PADDING
-	 * ----------- top = topmax - TOP_OF_KERNEL_STACK_PADDING
-	 * stack
-	 * ----------- bottom = start + sizeof(thread_info)
-	 * thread_info
-	 * ----------- start
-	 *
-	 * The tasks stack pointer points at the location where the
-	 * framepointer is stored. The data on the stack is:
-	 * ... IP FP ... IP FP
-	 *
-	 * We need to read FP and IP, so we need to adjust the upper
-	 * bound by another unsigned long.
-	 */
-	top = start + THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING;
-	top -= 2 * sizeof(unsigned long);
-	bottom = start + sizeof(struct thread_info);
-
-	sp = READ_ONCE(p->thread.sp);
-	if (sp < bottom || sp > top)
-		return 0;
-
-	fp = READ_ONCE(*(unsigned long *)sp);
-	do {
-		if (fp < bottom || fp > top)
-			return 0;
-		ip = READ_ONCE(*(unsigned long *)(fp + sizeof(unsigned long)));
-		if (!in_sched_functions(ip))
-			return ip;
-		fp = READ_ONCE(*(unsigned long *)fp);
-	} while (count++ < 16 && p->state != TASK_RUNNING);
-	return 0;
-}
-
 long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
 {
 	int ret = 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[patch 0/2] x86/process: Sanitize bound checks in get_wchan() and  unify 32/64 bit Thomas Gleixner <tglx@linutronix.de> - 2015-09-30 10:40 +0200
  [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Thomas Gleixner <tglx@linutronix.de> - 2015-09-30 10:40 +0200
    [tip:x86/urgent] x86/process:   Add proper bound checks in 64bit get_wchan() tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2015-09-30 22:00 +0200
    Re: [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Sasha Levin <sasha.levin@oracle.com> - 2015-10-03 03:20 +0200
      Re: [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Andy Lutomirski <luto@amacapital.net> - 2015-10-03 03:40 +0200
      Re: [patch 1/2] x86/process: Add proper bound checks in 64bit  get_wchan() Thomas Gleixner <tglx@linutronix.de> - 2015-10-03 13:00 +0200
        Re: [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Andrey Ryabinin <ryabinin.a.a@gmail.com> - 2015-10-03 13:40 +0200
          Re: [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Dmitry Vyukov <dvyukov@google.com> - 2015-10-04 14:20 +0200
            Re: [patch 1/2] x86/process: Add proper bound checks in 64bit get_wchan() Dmitry Vyukov <dvyukov@gmail.com> - 2015-10-04 20:10 +0200
  [patch 2/2] x86/process: Unify 32bit and 64bit implementations of  get_wchan() Thomas Gleixner <tglx@linutronix.de> - 2015-09-30 10:40 +0200
    [tip:x86/urgent] x86/process:   Unify 32bit and 64bit implementations of get_wchan() tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2015-09-30 22:10 +0200
  Re: [patch 0/2] x86/process: Sanitize bound checks in get_wchan()  and unify 32/64 bit Borislav Petkov <bp@alien8.de> - 2015-09-30 11:10 +0200
    Re: [patch 0/2] x86/process: Sanitize bound checks in get_wchan() and  unify 32/64 bit Dmitry Vyukov <dvyukov@google.com> - 2015-09-30 11:20 +0200

csiph-web