2005-04-16 22:20:36 +00:00
|
|
|
/**
|
|
|
|
* @file common.c
|
|
|
|
*
|
|
|
|
* @remark Copyright 2004 Oprofile Authors
|
2010-04-30 10:36:54 +00:00
|
|
|
* @remark Copyright 2010 ARM Ltd.
|
2005-04-16 22:20:36 +00:00
|
|
|
* @remark Read the file COPYING
|
|
|
|
*
|
|
|
|
* @author Zwane Mwaikambo
|
2010-04-30 10:36:54 +00:00
|
|
|
* @author Will Deacon [move to perf]
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
#include <linux/cpumask.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
2010-04-30 10:36:54 +00:00
|
|
|
#include <linux/mutex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/oprofile.h>
|
2010-04-30 10:36:54 +00:00
|
|
|
#include <linux/perf_event.h>
|
2010-04-30 10:38:39 +00:00
|
|
|
#include <linux/platform_device.h>
|
2006-03-16 11:32:51 +00:00
|
|
|
#include <linux/slab.h>
|
2010-04-30 10:36:54 +00:00
|
|
|
#include <asm/stacktrace.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
|
|
|
#include <asm/perf_event.h>
|
|
|
|
#include <asm/ptrace.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
#ifdef CONFIG_HW_PERF_EVENTS
|
2012-07-06 14:45:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* OProfile has a curious naming scheme for the ARM PMUs, but they are
|
|
|
|
* part of the user ABI so we need to map from the perf PMU name for
|
|
|
|
* supported PMUs.
|
|
|
|
*/
|
|
|
|
static struct op_perf_name {
|
|
|
|
char *perf_name;
|
|
|
|
char *op_name;
|
|
|
|
} op_perf_name_map[] = {
|
2012-12-19 16:33:24 +00:00
|
|
|
{ "armv5_xscale1", "arm/xscale1" },
|
|
|
|
{ "armv5_xscale2", "arm/xscale2" },
|
|
|
|
{ "armv6_1136", "arm/armv6" },
|
|
|
|
{ "armv6_1156", "arm/armv6" },
|
|
|
|
{ "armv6_1176", "arm/armv6" },
|
|
|
|
{ "armv6_11mpcore", "arm/mpcore" },
|
|
|
|
{ "armv7_cortex_a8", "arm/armv7" },
|
|
|
|
{ "armv7_cortex_a9", "arm/armv7-ca9" },
|
2012-07-06 14:45:00 +00:00
|
|
|
};
|
|
|
|
|
2010-10-08 20:42:17 +00:00
|
|
|
char *op_name_from_perf_id(void)
|
2010-04-30 10:36:54 +00:00
|
|
|
{
|
2012-07-06 14:45:00 +00:00
|
|
|
int i;
|
|
|
|
struct op_perf_name names;
|
|
|
|
const char *perf_name = perf_pmu_name();
|
2010-10-08 20:42:17 +00:00
|
|
|
|
2012-07-06 14:45:00 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(op_perf_name_map); ++i) {
|
|
|
|
names = op_perf_name_map[i];
|
|
|
|
if (!strcmp(names.perf_name, perf_name))
|
|
|
|
return names.op_name;
|
2010-04-30 10:36:54 +00:00
|
|
|
}
|
2012-07-06 14:45:00 +00:00
|
|
|
|
|
|
|
return NULL;
|
2010-04-30 10:36:54 +00:00
|
|
|
}
|
2011-01-20 18:57:19 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
static int report_trace(struct stackframe *frame, void *d)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-04-30 10:36:54 +00:00
|
|
|
unsigned int *depth = d;
|
2005-10-28 13:56:04 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
if (*depth) {
|
|
|
|
oprofile_add_trace(frame->pc);
|
|
|
|
(*depth)--;
|
|
|
|
}
|
2007-02-27 11:09:33 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
return *depth == 0;
|
|
|
|
}
|
2005-10-28 13:56:04 +00:00
|
|
|
|
2010-04-30 10:36:54 +00: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));
|
2006-12-19 12:41:22 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
static struct frame_tail* user_backtrace(struct frame_tail *tail)
|
|
|
|
{
|
|
|
|
struct frame_tail buftail[2];
|
2006-12-19 14:17:46 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
/* Also check accessibility of one struct frame_tail beyond */
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 02:57:57 +00:00
|
|
|
if (!access_ok(tail, sizeof(buftail)))
|
2010-04-30 10:36:54 +00:00
|
|
|
return NULL;
|
|
|
|
if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
|
|
|
|
return NULL;
|
2008-08-12 18:07:39 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
oprofile_add_trace(buftail[0].lr);
|
2005-10-28 13:56:04 +00:00
|
|
|
|
2010-04-30 10:36:54 +00:00
|
|
|
/* frame pointers should strictly progress back up the stack
|
|
|
|
* (towards higher addresses) */
|
2011-02-09 10:35:12 +00:00
|
|
|
if (tail + 1 >= buftail[0].fp)
|
2010-04-30 10:36:54 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buftail[0].fp-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
|
|
|
struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
|
|
|
|
|
|
|
|
if (!user_mode(regs)) {
|
|
|
|
struct stackframe frame;
|
2014-06-03 18:51:32 +00:00
|
|
|
arm_get_current_stackframe(regs, &frame);
|
2010-04-30 10:36:54 +00:00
|
|
|
walk_stackframe(&frame, report_trace, &depth);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (depth-- && tail && !((unsigned long) tail & 3))
|
|
|
|
tail = user_backtrace(tail);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:35:29 +00:00
|
|
|
int __init oprofile_arch_init(struct oprofile_operations *ops)
|
|
|
|
{
|
2011-01-20 18:57:19 +00:00
|
|
|
/* provide backtrace support also in timer mode: */
|
2010-09-27 19:35:29 +00:00
|
|
|
ops->backtrace = arm_backtrace;
|
|
|
|
|
|
|
|
return oprofile_perf_init(ops);
|
|
|
|
}
|
|
|
|
|
2011-12-22 15:15:40 +00:00
|
|
|
void oprofile_arch_exit(void)
|
2010-09-27 19:35:29 +00:00
|
|
|
{
|
|
|
|
oprofile_perf_exit();
|
|
|
|
}
|