Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 257092
b: refs/heads/master
c: a0e3e70
h: refs/heads/master
v: v3
  • Loading branch information
Robert Richter committed Jun 15, 2011
1 parent 2581407 commit 481faa8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 211 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5f307491f3a0c8551cedf5d90d660d656e0d56ec
refs/heads/master: a0e3e70243f5b270bc3eca718f0a9fa5e6b8262e
4 changes: 0 additions & 4 deletions trunk/arch/mips/include/asm/stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
extern int raw_show_trace;
extern unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
unsigned long pc, unsigned long *ra);
extern unsigned long unwind_stack_by_address(unsigned long stack_page,
unsigned long *sp,
unsigned long pc,
unsigned long *ra);
#else
#define raw_show_trace 1
static inline unsigned long unwind_stack(struct task_struct *task,
Expand Down
19 changes: 5 additions & 14 deletions trunk/arch/mips/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,18 @@ unsigned long thread_saved_pc(struct task_struct *tsk)


#ifdef CONFIG_KALLSYMS
/* generic stack unwinding function */
unsigned long notrace unwind_stack_by_address(unsigned long stack_page,
unsigned long *sp,
unsigned long pc,
unsigned long *ra)
/* used by show_backtrace() */
unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
unsigned long pc, unsigned long *ra)
{
unsigned long stack_page;
struct mips_frame_info info;
unsigned long size, ofs;
int leaf;
extern void ret_from_irq(void);
extern void ret_from_exception(void);

stack_page = (unsigned long)task_stack_page(task);
if (!stack_page)
return 0;

Expand Down Expand Up @@ -443,15 +443,6 @@ unsigned long notrace unwind_stack_by_address(unsigned long stack_page,
*ra = 0;
return __kernel_text_address(pc) ? pc : 0;
}
EXPORT_SYMBOL(unwind_stack_by_address);

/* used by show_backtrace() */
unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
unsigned long pc, unsigned long *ra)
{
unsigned long stack_page = (unsigned long)task_stack_page(task);
return unwind_stack_by_address(stack_page, sp, pc, ra);
}
#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/mips/oprofile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
oprofilefs.o oprofile_stats.o \
timer_int.o )

oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
oprofile-y := $(DRIVER_OBJS) common.o

oprofile-$(CONFIG_CPU_MIPS32) += op_model_mipsxx.o
oprofile-$(CONFIG_CPU_MIPS64) += op_model_mipsxx.o
Expand Down
175 changes: 0 additions & 175 deletions trunk/arch/mips/oprofile/backtrace.c

This file was deleted.

1 change: 0 additions & 1 deletion trunk/arch/mips/oprofile/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
ops->start = op_mips_start;
ops->stop = op_mips_stop;
ops->cpu_type = lmodel->cpu_type;
ops->backtrace = op_mips_backtrace;

printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
lmodel->cpu_type);
Expand Down
2 changes: 0 additions & 2 deletions trunk/arch/mips/oprofile/op_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ struct op_mips_model {
unsigned char num_counters;
};

void op_mips_backtrace(struct pt_regs * const regs, unsigned int depth);

#endif
56 changes: 47 additions & 9 deletions trunk/arch/x86/oprofile/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#include <linux/oprofile.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/compat.h>
#include <linux/highmem.h>

#include <asm/ptrace.h>
#include <asm/uaccess.h>
#include <asm/stacktrace.h>
#include <linux/compat.h>

static int backtrace_stack(void *data, char *name)
{
Expand All @@ -36,17 +38,53 @@ static struct stacktrace_ops backtrace_ops = {
.walk_stack = print_context_stack,
};

/* from arch/x86/kernel/cpu/perf_event.c: */

/*
* best effort, GUP based copy_from_user() that assumes IRQ or NMI context
*/
static unsigned long
copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
{
unsigned long offset, addr = (unsigned long)from;
unsigned long size, len = 0;
struct page *page;
void *map;
int ret;

do {
ret = __get_user_pages_fast(addr, 1, 0, &page);
if (!ret)
break;

offset = addr & (PAGE_SIZE - 1);
size = min(PAGE_SIZE - offset, n - len);

map = kmap_atomic(page);
memcpy(to, map+offset, size);
kunmap_atomic(map);
put_page(page);

len += size;
to += size;
addr += size;

} while (len < n);

return len;
}

#ifdef CONFIG_COMPAT
static struct stack_frame_ia32 *
dump_user_backtrace_32(struct stack_frame_ia32 *head)
{
/* Also check accessibility of one struct frame_head beyond: */
struct stack_frame_ia32 bufhead[2];
struct stack_frame_ia32 *fp;
unsigned long bytes;

/* 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)))
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
if (bytes != sizeof(bufhead))
return NULL;

fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
Expand Down Expand Up @@ -87,12 +125,12 @@ x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)

static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
{
/* Also check accessibility of one struct frame_head beyond: */
struct stack_frame bufhead[2];
unsigned long bytes;

/* Also check accessibility of one struct stack_frame beyond */
if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
return NULL;
if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
if (bytes != sizeof(bufhead))
return NULL;

oprofile_add_trace(bufhead[0].return_address);
Expand Down
14 changes: 10 additions & 4 deletions trunk/arch/x86/oprofile/nmi_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ static void nmi_cpu_start(void *dummy)
static int nmi_start(void)
{
get_online_cpus();
on_each_cpu(nmi_cpu_start, NULL, 1);
ctr_running = 1;
/* make ctr_running visible to the nmi handler: */
smp_mb();
on_each_cpu(nmi_cpu_start, NULL, 1);
put_online_cpus();
return 0;
}
Expand Down Expand Up @@ -504,15 +506,18 @@ static int nmi_setup(void)

nmi_enabled = 0;
ctr_running = 0;
barrier();
/* make variables visible to the nmi handler: */
smp_mb();
err = register_die_notifier(&profile_exceptions_nb);
if (err)
goto fail;

get_online_cpus();
register_cpu_notifier(&oprofile_cpu_nb);
on_each_cpu(nmi_cpu_setup, NULL, 1);
nmi_enabled = 1;
/* make nmi_enabled visible to the nmi handler: */
smp_mb();
on_each_cpu(nmi_cpu_setup, NULL, 1);
put_online_cpus();

return 0;
Expand All @@ -531,7 +536,8 @@ static void nmi_shutdown(void)
nmi_enabled = 0;
ctr_running = 0;
put_online_cpus();
barrier();
/* make variables visible to the nmi handler: */
smp_mb();
unregister_die_notifier(&profile_exceptions_nb);
msrs = &get_cpu_var(cpu_msrs);
model->shutdown(msrs);
Expand Down

0 comments on commit 481faa8

Please sign in to comment.