2005-06-28 16:01:03 -04:00
|
|
|
/*
|
|
|
|
* Arm specific backtracing code for oprofile
|
|
|
|
*
|
|
|
|
* Copyright 2005 Openedhand Ltd.
|
|
|
|
*
|
|
|
|
* Author: Richard Purdie <rpurdie@openedhand.com>
|
|
|
|
*
|
|
|
|
* Based on i386 oprofile backtrace code by John Levon, David Smith
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2008-09-06 06:35:55 -04:00
|
|
|
#include <linux/uaccess.h>
|
2005-06-28 16:01:03 -04:00
|
|
|
#include <asm/ptrace.h>
|
2009-02-11 07:07:53 -05:00
|
|
|
#include <asm/stacktrace.h>
|
2007-04-28 04:59:37 -04:00
|
|
|
|
|
|
|
static int report_trace(struct stackframe *frame, void *d)
|
|
|
|
{
|
|
|
|
unsigned int *depth = d;
|
|
|
|
|
|
|
|
if (*depth) {
|
2009-02-11 07:07:53 -05:00
|
|
|
oprofile_add_trace(frame->pc);
|
2007-04-28 04:59:37 -04:00
|
|
|
(*depth)--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *depth == 0;
|
|
|
|
}
|
2005-06-28 16:01:03 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The registers we're interested in are at the end of the variable
|
|
|
|
* length saved register structure. The fp points at the end of this
|
|
|
|
* structure so the address of this struct is:
|
|
|
|
* (struct frame_tail *)(xxx->fp)-1
|
|
|
|
*/
|
|
|
|
struct frame_tail {
|
|
|
|
struct frame_tail *fp;
|
|
|
|
unsigned long sp;
|
|
|
|
unsigned long lr;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
static struct frame_tail* user_backtrace(struct frame_tail *tail)
|
|
|
|
{
|
[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 21:16:32 -04:00
|
|
|
struct frame_tail buftail[2];
|
2005-06-28 16:01:03 -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-29 21:16:32 -04:00
|
|
|
/* Also check accessibility of one struct frame_tail beyond */
|
|
|
|
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
|
|
|
|
return NULL;
|
|
|
|
if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
|
2005-06-28 16:01:03 -04: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 21:16:32 -04:00
|
|
|
oprofile_add_trace(buftail[0].lr);
|
2005-06-28 16:01:03 -04:00
|
|
|
|
|
|
|
/* frame pointers should strictly progress back up the stack
|
|
|
|
* (towards higher addresses) */
|
[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 21:16:32 -04:00
|
|
|
if (tail >= buftail[0].fp)
|
2005-06-28 16:01:03 -04: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 21:16:32 -04:00
|
|
|
return buftail[0].fp-1;
|
2005-06-28 16:01:03 -04:00
|
|
|
}
|
|
|
|
|
2005-08-04 10:06:59 -04:00
|
|
|
void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
|
2005-06-28 16:01:03 -04:00
|
|
|
{
|
2007-04-28 04:59:37 -04:00
|
|
|
struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
|
2005-06-28 16:01:03 -04:00
|
|
|
|
|
|
|
if (!user_mode(regs)) {
|
2009-02-11 07:07:53 -05:00
|
|
|
struct stackframe frame;
|
|
|
|
frame.fp = regs->ARM_fp;
|
|
|
|
frame.sp = regs->ARM_sp;
|
|
|
|
frame.lr = regs->ARM_lr;
|
|
|
|
frame.pc = regs->ARM_pc;
|
|
|
|
walk_stackframe(&frame, report_trace, &depth);
|
2005-06-28 16:01:03 -04: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 21:16:32 -04:00
|
|
|
while (depth-- && tail && !((unsigned long) tail & 3))
|
2005-06-28 16:01:03 -04:00
|
|
|
tail = user_backtrace(tail);
|
|
|
|
}
|