2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* @file backtrace.c
|
|
|
|
*
|
|
|
|
* @remark Copyright 2002 OProfile authors
|
|
|
|
* @remark Read the file COPYING
|
|
|
|
*
|
|
|
|
* @author John Levon
|
|
|
|
* @author David Smith
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2011-06-03 18:37:47 +04:00
|
|
|
#include <linux/compat.h>
|
2011-06-07 13:49:55 +04:00
|
|
|
#include <linux/uaccess.h>
|
2011-06-03 18:37:47 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/ptrace.h>
|
2007-10-19 22:35:03 +04:00
|
|
|
#include <asm/stacktrace.h>
|
2016-09-16 22:18:15 +03:00
|
|
|
#include <asm/unwind.h>
|
2007-10-19 22:35:03 +04:00
|
|
|
|
2010-09-29 18:46:47 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static struct stack_frame_ia32 *
|
|
|
|
dump_user_backtrace_32(struct stack_frame_ia32 *head)
|
|
|
|
{
|
2011-06-03 18:37:47 +04:00
|
|
|
/* Also check accessibility of one struct frame_head beyond: */
|
2010-09-29 18:46:47 +04:00
|
|
|
struct stack_frame_ia32 bufhead[2];
|
|
|
|
struct stack_frame_ia32 *fp;
|
2011-06-03 18:37:47 +04:00
|
|
|
unsigned long bytes;
|
2010-09-29 18:46:47 +04:00
|
|
|
|
2011-06-03 18:37:47 +04:00
|
|
|
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
|
2013-10-31 00:16:22 +04:00
|
|
|
if (bytes != 0)
|
2010-09-29 18:46:47 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
|
|
|
|
|
|
|
|
oprofile_add_trace(bufhead[0].return_address);
|
|
|
|
|
|
|
|
/* frame pointers should strictly progress back up the stack
|
|
|
|
* (towards higher addresses) */
|
|
|
|
if (head >= fp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
|
|
|
struct stack_frame_ia32 *head;
|
|
|
|
|
2012-02-07 01:03:09 +04:00
|
|
|
/* User process is IA32 */
|
2010-09-29 18:46:47 +04:00
|
|
|
if (!current || !test_thread_flag(TIF_IA32))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
head = (struct stack_frame_ia32 *) regs->bp;
|
|
|
|
while (depth-- && head)
|
|
|
|
head = dump_user_backtrace_32(head);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
static inline int
|
|
|
|
x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
|
2010-09-29 18:46:46 +04:00
|
|
|
static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-06-03 18:37:47 +04:00
|
|
|
/* Also check accessibility of one struct frame_head beyond: */
|
2010-09-29 18:46:46 +04:00
|
|
|
struct stack_frame bufhead[2];
|
2011-06-03 18:37:47 +04:00
|
|
|
unsigned long bytes;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-06-03 18:37:47 +04:00
|
|
|
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
|
2013-10-31 00:16:22 +04:00
|
|
|
if (bytes != 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
|
2010-09-29 18:46:46 +04:00
|
|
|
oprofile_add_trace(bufhead[0].return_address);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
[PATCH] mm: kill check_user_page_readable
check_user_page_readable is a problematic variant of follow_page. It's used
only by oprofile's i386 and arm backtrace code, at interrupt time, to
establish whether a userspace stackframe is currently readable.
This is problematic, because we want to push the page_table_lock down inside
follow_page, and later split it; whereas oprofile is doing a spin_trylock on
it (in the i386 case, forgotten in the arm case), and needs that to pin
perhaps two pages spanned by the stackframe (which might be covered by
different locks when we split).
I think oprofile is going about this in the wrong way: it doesn't need to know
the area is readable (neither i386 nor arm uses read protection of user
pages), it doesn't need to pin the memory, it should simply
__copy_from_user_inatomic, and see if that succeeds or not. Sorry, but I've
not got around to devising the sparse __user annotations for this.
Then we can eliminate check_user_page_readable, and return to a single
follow_page without the __follow_page variants.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 04:16:32 +03:00
|
|
|
/* frame pointers should strictly progress back up the stack
|
|
|
|
* (towards higher addresses) */
|
2010-09-29 18:46:46 +04:00
|
|
|
if (head >= bufhead[0].next_frame)
|
[PATCH] mm: kill check_user_page_readable
check_user_page_readable is a problematic variant of follow_page. It's used
only by oprofile's i386 and arm backtrace code, at interrupt time, to
establish whether a userspace stackframe is currently readable.
This is problematic, because we want to push the page_table_lock down inside
follow_page, and later split it; whereas oprofile is doing a spin_trylock on
it (in the i386 case, forgotten in the arm case), and needs that to pin
perhaps two pages spanned by the stackframe (which might be covered by
different locks when we split).
I think oprofile is going about this in the wrong way: it doesn't need to know
the area is readable (neither i386 nor arm uses read protection of user
pages), it doesn't need to pin the memory, it should simply
__copy_from_user_inatomic, and see if that succeeds or not. Sorry, but I've
not got around to devising the sparse __user annotations for this.
Then we can eliminate check_user_page_readable, and return to a single
follow_page without the __follow_page variants.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 04:16:32 +03:00
|
|
|
return NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-29 18:46:46 +04:00
|
|
|
return bufhead[0].next_frame;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
x86_backtrace(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
2010-09-29 18:46:46 +04:00
|
|
|
struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-03-19 04:33:33 +03:00
|
|
|
if (!user_mode(regs)) {
|
2016-09-16 22:18:15 +03:00
|
|
|
struct unwind_state state;
|
|
|
|
unsigned long addr;
|
|
|
|
|
2016-08-24 19:50:15 +03:00
|
|
|
if (!depth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
oprofile_add_trace(regs->ip);
|
2016-09-16 22:18:15 +03:00
|
|
|
|
2016-08-24 19:50:15 +03:00
|
|
|
if (!--depth)
|
|
|
|
return;
|
|
|
|
|
2016-09-16 22:18:15 +03:00
|
|
|
for (unwind_start(&state, current, regs, NULL);
|
|
|
|
!unwind_done(&state); unwind_next_frame(&state)) {
|
|
|
|
addr = unwind_get_return_address(&state);
|
|
|
|
if (!addr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
oprofile_add_trace(addr);
|
|
|
|
|
|
|
|
if (!--depth)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-29 18:46:47 +04:00
|
|
|
if (x86_backtrace_32(regs, depth))
|
|
|
|
return;
|
|
|
|
|
[PATCH] mm: kill check_user_page_readable
check_user_page_readable is a problematic variant of follow_page. It's used
only by oprofile's i386 and arm backtrace code, at interrupt time, to
establish whether a userspace stackframe is currently readable.
This is problematic, because we want to push the page_table_lock down inside
follow_page, and later split it; whereas oprofile is doing a spin_trylock on
it (in the i386 case, forgotten in the arm case), and needs that to pin
perhaps two pages spanned by the stackframe (which might be covered by
different locks when we split).
I think oprofile is going about this in the wrong way: it doesn't need to know
the area is readable (neither i386 nor arm uses read protection of user
pages), it doesn't need to pin the memory, it should simply
__copy_from_user_inatomic, and see if that succeeds or not. Sorry, but I've
not got around to devising the sparse __user annotations for this.
Then we can eliminate check_user_page_readable, and return to a single
follow_page without the __follow_page variants.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 04:16:32 +03:00
|
|
|
while (depth-- && head)
|
2006-02-14 18:19:04 +03:00
|
|
|
head = dump_user_backtrace(head);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|