2005-04-16 16:20:36 -06: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>
|
|
|
|
#include <asm/ptrace.h>
|
[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-29 19:16:32 -06:00
|
|
|
#include <asm/uaccess.h>
|
2007-10-19 12:35:03 -06:00
|
|
|
#include <asm/stacktrace.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-19 12:35:03 -06:00
|
|
|
static void backtrace_warning_symbol(void *data, char *msg,
|
|
|
|
unsigned long symbol)
|
|
|
|
{
|
|
|
|
/* Ignore warnings */
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-19 12:35:03 -06:00
|
|
|
static void backtrace_warning(void *data, char *msg)
|
2006-02-14 08:19:04 -07:00
|
|
|
{
|
2007-10-19 12:35:03 -06:00
|
|
|
/* Ignore warnings */
|
|
|
|
}
|
2006-02-14 08:19:04 -07:00
|
|
|
|
2007-10-19 12:35:03 -06:00
|
|
|
static int backtrace_stack(void *data, char *name)
|
|
|
|
{
|
|
|
|
/* Yes, we want all stacks */
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-14 08:19:04 -07:00
|
|
|
|
2008-01-30 05:33:07 -07:00
|
|
|
static void backtrace_address(void *data, unsigned long addr, int reliable)
|
2007-10-19 12:35:03 -06:00
|
|
|
{
|
|
|
|
unsigned int *depth = data;
|
|
|
|
|
|
|
|
if ((*depth)--)
|
|
|
|
oprofile_add_trace(addr);
|
2006-02-14 08:19:04 -07:00
|
|
|
}
|
|
|
|
|
2007-10-19 12:35:03 -06:00
|
|
|
static struct stacktrace_ops backtrace_ops = {
|
|
|
|
.warning = backtrace_warning,
|
|
|
|
.warning_symbol = backtrace_warning_symbol,
|
|
|
|
.stack = backtrace_stack,
|
|
|
|
.address = backtrace_address,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct frame_head {
|
2008-01-30 05:30:56 -07:00
|
|
|
struct frame_head *bp;
|
2007-10-19 12:35:03 -06:00
|
|
|
unsigned long ret;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2008-10-16 07:01:40 -06:00
|
|
|
static struct frame_head *dump_user_backtrace(struct frame_head *head)
|
2005-04-16 16:20:36 -06: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-29 19:16:32 -06:00
|
|
|
struct frame_head bufhead[2];
|
2005-04-16 16:20:36 -06: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-29 19:16:32 -06:00
|
|
|
/* Also check accessibility of one struct frame_head beyond */
|
|
|
|
if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
|
|
|
|
return NULL;
|
|
|
|
if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
|
2005-04-16 16:20:36 -06:00
|
|
|
return NULL;
|
|
|
|
|
[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-29 19:16:32 -06:00
|
|
|
oprofile_add_trace(bufhead[0].ret);
|
2005-04-16 16:20:36 -06: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-29 19:16:32 -06:00
|
|
|
/* frame pointers should strictly progress back up the stack
|
|
|
|
* (towards higher addresses) */
|
2008-01-30 05:30:56 -07:00
|
|
|
if (head >= bufhead[0].bp)
|
[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-29 19:16:32 -06:00
|
|
|
return NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-30 05:30:56 -07:00
|
|
|
return bufhead[0].bp;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
x86_backtrace(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
2007-10-19 12:35:04 -06:00
|
|
|
struct frame_head *head = (struct frame_head *)frame_pointer(regs);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-23 01:08:44 -06:00
|
|
|
if (!user_mode_vm(regs)) {
|
2009-05-11 15:03:00 -06:00
|
|
|
unsigned long stack = kernel_stack_pointer(regs);
|
2007-10-19 12:35:03 -06:00
|
|
|
if (depth)
|
2008-01-30 05:33:07 -07:00
|
|
|
dump_trace(NULL, regs, (unsigned long *)stack, 0,
|
2007-10-19 12:35:03 -06:00
|
|
|
&backtrace_ops, &depth);
|
2005-04-16 16:20:36 -06:00
|
|
|
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-29 19:16:32 -06:00
|
|
|
while (depth-- && head)
|
2006-02-14 08:19:04 -07:00
|
|
|
head = dump_user_backtrace(head);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|