diff options
Diffstat (limited to 'arch/arc')
| -rw-r--r-- | arch/arc/include/asm/processor.h | 14 | ||||
| -rw-r--r-- | arch/arc/include/asm/stacktrace.h | 37 | ||||
| -rw-r--r-- | arch/arc/kernel/process.c | 23 | ||||
| -rw-r--r-- | arch/arc/kernel/signal.c | 24 | ||||
| -rw-r--r-- | arch/arc/kernel/stacktrace.c | 21 | ||||
| -rw-r--r-- | arch/arc/kernel/unaligned.c | 2 | ||||
| -rw-r--r-- | arch/arc/mm/fault.c | 12 |
7 files changed, 91 insertions, 42 deletions
diff --git a/arch/arc/include/asm/processor.h b/arch/arc/include/asm/processor.h index 4e547296831d..52312cb5dbe2 100644 --- a/arch/arc/include/asm/processor.h +++ b/arch/arc/include/asm/processor.h | |||
| @@ -47,9 +47,6 @@ struct thread_struct { | |||
| 47 | /* Forward declaration, a strange C thing */ | 47 | /* Forward declaration, a strange C thing */ |
| 48 | struct task_struct; | 48 | struct task_struct; |
| 49 | 49 | ||
| 50 | /* Return saved PC of a blocked thread */ | ||
| 51 | unsigned long thread_saved_pc(struct task_struct *t); | ||
| 52 | |||
| 53 | #define task_pt_regs(p) \ | 50 | #define task_pt_regs(p) \ |
| 54 | ((struct pt_regs *)(THREAD_SIZE + (void *)task_stack_page(p)) - 1) | 51 | ((struct pt_regs *)(THREAD_SIZE + (void *)task_stack_page(p)) - 1) |
| 55 | 52 | ||
| @@ -72,18 +69,21 @@ unsigned long thread_saved_pc(struct task_struct *t); | |||
| 72 | #define release_segments(mm) do { } while (0) | 69 | #define release_segments(mm) do { } while (0) |
| 73 | 70 | ||
| 74 | #define KSTK_EIP(tsk) (task_pt_regs(tsk)->ret) | 71 | #define KSTK_EIP(tsk) (task_pt_regs(tsk)->ret) |
| 72 | #define KSTK_ESP(tsk) (task_pt_regs(tsk)->sp) | ||
| 75 | 73 | ||
| 76 | /* | 74 | /* |
| 77 | * Where abouts of Task's sp, fp, blink when it was last seen in kernel mode. | 75 | * Where abouts of Task's sp, fp, blink when it was last seen in kernel mode. |
| 78 | * Look in process.c for details of kernel stack layout | 76 | * Look in process.c for details of kernel stack layout |
| 79 | */ | 77 | */ |
| 80 | #define KSTK_ESP(tsk) (tsk->thread.ksp) | 78 | #define TSK_K_ESP(tsk) (tsk->thread.ksp) |
| 81 | 79 | ||
| 82 | #define KSTK_REG(tsk, off) (*((unsigned int *)(KSTK_ESP(tsk) + \ | 80 | #define TSK_K_REG(tsk, off) (*((unsigned int *)(TSK_K_ESP(tsk) + \ |
| 83 | sizeof(struct callee_regs) + off))) | 81 | sizeof(struct callee_regs) + off))) |
| 84 | 82 | ||
| 85 | #define KSTK_BLINK(tsk) KSTK_REG(tsk, 4) | 83 | #define TSK_K_BLINK(tsk) TSK_K_REG(tsk, 4) |
| 86 | #define KSTK_FP(tsk) KSTK_REG(tsk, 0) | 84 | #define TSK_K_FP(tsk) TSK_K_REG(tsk, 0) |
| 85 | |||
| 86 | #define thread_saved_pc(tsk) TSK_K_BLINK(tsk) | ||
| 87 | 87 | ||
| 88 | extern void start_thread(struct pt_regs * regs, unsigned long pc, | 88 | extern void start_thread(struct pt_regs * regs, unsigned long pc, |
| 89 | unsigned long usp); | 89 | unsigned long usp); |
diff --git a/arch/arc/include/asm/stacktrace.h b/arch/arc/include/asm/stacktrace.h new file mode 100644 index 000000000000..b29b6064ea14 --- /dev/null +++ b/arch/arc/include/asm/stacktrace.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) | ||
| 3 | * Copyright (C) 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License version 2 as | ||
| 7 | * published by the Free Software Foundation. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #ifndef __ASM_STACKTRACE_H | ||
| 11 | #define __ASM_STACKTRACE_H | ||
| 12 | |||
| 13 | #include <linux/sched.h> | ||
| 14 | |||
| 15 | /** | ||
| 16 | * arc_unwind_core - Unwind the kernel mode stack for an execution context | ||
| 17 | * @tsk: NULL for current task, specific task otherwise | ||
| 18 | * @regs: pt_regs used to seed the unwinder {SP, FP, BLINK, PC} | ||
| 19 | * If NULL, use pt_regs of @tsk (if !NULL) otherwise | ||
| 20 | * use the current values of {SP, FP, BLINK, PC} | ||
| 21 | * @consumer_fn: Callback invoked for each frame unwound | ||
| 22 | * Returns 0 to continue unwinding, -1 to stop | ||
| 23 | * @arg: Arg to callback | ||
| 24 | * | ||
| 25 | * Returns the address of first function in stack | ||
| 26 | * | ||
| 27 | * Semantics: | ||
| 28 | * - synchronous unwinding (e.g. dump_stack): @tsk NULL, @regs NULL | ||
| 29 | * - Asynchronous unwinding of sleeping task: @tsk !NULL, @regs NULL | ||
| 30 | * - Asynchronous unwinding of intr/excp etc: @tsk !NULL, @regs !NULL | ||
| 31 | */ | ||
| 32 | notrace noinline unsigned int arc_unwind_core( | ||
| 33 | struct task_struct *tsk, struct pt_regs *regs, | ||
| 34 | int (*consumer_fn) (unsigned int, void *), | ||
| 35 | void *arg); | ||
| 36 | |||
| 37 | #endif /* __ASM_STACKTRACE_H */ | ||
diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c index fdd89715d2d3..98c00a2d4dd9 100644 --- a/arch/arc/kernel/process.c +++ b/arch/arc/kernel/process.c | |||
| @@ -192,29 +192,6 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) | |||
| 192 | return 0; | 192 | return 0; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | /* | ||
| 196 | * API: expected by schedular Code: If thread is sleeping where is that. | ||
| 197 | * What is this good for? it will be always the scheduler or ret_from_fork. | ||
| 198 | * So we hard code that anyways. | ||
| 199 | */ | ||
| 200 | unsigned long thread_saved_pc(struct task_struct *t) | ||
| 201 | { | ||
| 202 | struct pt_regs *regs = task_pt_regs(t); | ||
| 203 | unsigned long blink = 0; | ||
| 204 | |||
| 205 | /* | ||
| 206 | * If the thread being queried for in not itself calling this, then it | ||
| 207 | * implies it is not executing, which in turn implies it is sleeping, | ||
| 208 | * which in turn implies it got switched OUT by the schedular. | ||
| 209 | * In that case, it's kernel mode blink can reliably retrieved as per | ||
| 210 | * the picture above (right above pt_regs). | ||
| 211 | */ | ||
| 212 | if (t != current && t->state != TASK_RUNNING) | ||
| 213 | blink = *((unsigned int *)regs - 1); | ||
| 214 | |||
| 215 | return blink; | ||
| 216 | } | ||
| 217 | |||
| 218 | int elf_check_arch(const struct elf32_hdr *x) | 195 | int elf_check_arch(const struct elf32_hdr *x) |
| 219 | { | 196 | { |
| 220 | unsigned int eflags; | 197 | unsigned int eflags; |
diff --git a/arch/arc/kernel/signal.c b/arch/arc/kernel/signal.c index 114234e83caa..edda76fae83f 100644 --- a/arch/arc/kernel/signal.c +++ b/arch/arc/kernel/signal.c | |||
| @@ -67,7 +67,7 @@ stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs, | |||
| 67 | sigset_t *set) | 67 | sigset_t *set) |
| 68 | { | 68 | { |
| 69 | int err; | 69 | int err; |
| 70 | err = __copy_to_user(&(sf->uc.uc_mcontext.regs), regs, | 70 | err = __copy_to_user(&(sf->uc.uc_mcontext.regs.scratch), regs, |
| 71 | sizeof(sf->uc.uc_mcontext.regs.scratch)); | 71 | sizeof(sf->uc.uc_mcontext.regs.scratch)); |
| 72 | err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t)); | 72 | err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t)); |
| 73 | 73 | ||
| @@ -83,7 +83,7 @@ static int restore_usr_regs(struct pt_regs *regs, struct rt_sigframe __user *sf) | |||
| 83 | if (!err) | 83 | if (!err) |
| 84 | set_current_blocked(&set); | 84 | set_current_blocked(&set); |
| 85 | 85 | ||
| 86 | err |= __copy_from_user(regs, &(sf->uc.uc_mcontext.regs), | 86 | err |= __copy_from_user(regs, &(sf->uc.uc_mcontext.regs.scratch), |
| 87 | sizeof(sf->uc.uc_mcontext.regs.scratch)); | 87 | sizeof(sf->uc.uc_mcontext.regs.scratch)); |
| 88 | 88 | ||
| 89 | return err; | 89 | return err; |
| @@ -131,6 +131,15 @@ SYSCALL_DEFINE0(rt_sigreturn) | |||
| 131 | /* Don't restart from sigreturn */ | 131 | /* Don't restart from sigreturn */ |
| 132 | syscall_wont_restart(regs); | 132 | syscall_wont_restart(regs); |
| 133 | 133 | ||
| 134 | /* | ||
| 135 | * Ensure that sigreturn always returns to user mode (in case the | ||
| 136 | * regs saved on user stack got fudged between save and sigreturn) | ||
| 137 | * Otherwise it is easy to panic the kernel with a custom | ||
| 138 | * signal handler and/or restorer which clobberes the status32/ret | ||
| 139 | * to return to a bogus location in kernel mode. | ||
| 140 | */ | ||
| 141 | regs->status32 |= STATUS_U_MASK; | ||
| 142 | |||
| 134 | return regs->r0; | 143 | return regs->r0; |
| 135 | 144 | ||
| 136 | badframe: | 145 | badframe: |
| @@ -229,8 +238,11 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) | |||
| 229 | 238 | ||
| 230 | /* | 239 | /* |
| 231 | * handler returns using sigreturn stub provided already by userpsace | 240 | * handler returns using sigreturn stub provided already by userpsace |
| 241 | * If not, nuke the process right away | ||
| 232 | */ | 242 | */ |
| 233 | BUG_ON(!(ksig->ka.sa.sa_flags & SA_RESTORER)); | 243 | if(!(ksig->ka.sa.sa_flags & SA_RESTORER)) |
| 244 | return 1; | ||
| 245 | |||
| 234 | regs->blink = (unsigned long)ksig->ka.sa.sa_restorer; | 246 | regs->blink = (unsigned long)ksig->ka.sa.sa_restorer; |
| 235 | 247 | ||
| 236 | /* User Stack for signal handler will be above the frame just carved */ | 248 | /* User Stack for signal handler will be above the frame just carved */ |
| @@ -296,12 +308,12 @@ static void | |||
| 296 | handle_signal(struct ksignal *ksig, struct pt_regs *regs) | 308 | handle_signal(struct ksignal *ksig, struct pt_regs *regs) |
| 297 | { | 309 | { |
| 298 | sigset_t *oldset = sigmask_to_save(); | 310 | sigset_t *oldset = sigmask_to_save(); |
| 299 | int ret; | 311 | int failed; |
| 300 | 312 | ||
| 301 | /* Set up the stack frame */ | 313 | /* Set up the stack frame */ |
| 302 | ret = setup_rt_frame(ksig, oldset, regs); | 314 | failed = setup_rt_frame(ksig, oldset, regs); |
| 303 | 315 | ||
| 304 | signal_setup_done(ret, ksig, 0); | 316 | signal_setup_done(failed, ksig, 0); |
| 305 | } | 317 | } |
| 306 | 318 | ||
| 307 | void do_signal(struct pt_regs *regs) | 319 | void do_signal(struct pt_regs *regs) |
diff --git a/arch/arc/kernel/stacktrace.c b/arch/arc/kernel/stacktrace.c index 9ce47cfe2303..92320d6f737c 100644 --- a/arch/arc/kernel/stacktrace.c +++ b/arch/arc/kernel/stacktrace.c | |||
| @@ -43,6 +43,10 @@ static void seed_unwind_frame_info(struct task_struct *tsk, | |||
| 43 | struct pt_regs *regs, | 43 | struct pt_regs *regs, |
| 44 | struct unwind_frame_info *frame_info) | 44 | struct unwind_frame_info *frame_info) |
| 45 | { | 45 | { |
| 46 | /* | ||
| 47 | * synchronous unwinding (e.g. dump_stack) | ||
| 48 | * - uses current values of SP and friends | ||
| 49 | */ | ||
| 46 | if (tsk == NULL && regs == NULL) { | 50 | if (tsk == NULL && regs == NULL) { |
| 47 | unsigned long fp, sp, blink, ret; | 51 | unsigned long fp, sp, blink, ret; |
| 48 | frame_info->task = current; | 52 | frame_info->task = current; |
| @@ -61,12 +65,17 @@ static void seed_unwind_frame_info(struct task_struct *tsk, | |||
| 61 | frame_info->regs.r63 = ret; | 65 | frame_info->regs.r63 = ret; |
| 62 | frame_info->call_frame = 0; | 66 | frame_info->call_frame = 0; |
| 63 | } else if (regs == NULL) { | 67 | } else if (regs == NULL) { |
| 68 | /* | ||
| 69 | * Asynchronous unwinding of sleeping task | ||
| 70 | * - Gets SP etc from task's pt_regs (saved bottom of kernel | ||
| 71 | * mode stack of task) | ||
| 72 | */ | ||
| 64 | 73 | ||
| 65 | frame_info->task = tsk; | 74 | frame_info->task = tsk; |
| 66 | 75 | ||
| 67 | frame_info->regs.r27 = KSTK_FP(tsk); | 76 | frame_info->regs.r27 = TSK_K_FP(tsk); |
| 68 | frame_info->regs.r28 = KSTK_ESP(tsk); | 77 | frame_info->regs.r28 = TSK_K_ESP(tsk); |
| 69 | frame_info->regs.r31 = KSTK_BLINK(tsk); | 78 | frame_info->regs.r31 = TSK_K_BLINK(tsk); |
| 70 | frame_info->regs.r63 = (unsigned int)__switch_to; | 79 | frame_info->regs.r63 = (unsigned int)__switch_to; |
| 71 | 80 | ||
| 72 | /* In the prologue of __switch_to, first FP is saved on stack | 81 | /* In the prologue of __switch_to, first FP is saved on stack |
| @@ -83,6 +92,10 @@ static void seed_unwind_frame_info(struct task_struct *tsk, | |||
| 83 | frame_info->call_frame = 0; | 92 | frame_info->call_frame = 0; |
| 84 | 93 | ||
| 85 | } else { | 94 | } else { |
| 95 | /* | ||
| 96 | * Asynchronous unwinding of intr/exception | ||
| 97 | * - Just uses the pt_regs passed | ||
| 98 | */ | ||
| 86 | frame_info->task = tsk; | 99 | frame_info->task = tsk; |
| 87 | 100 | ||
| 88 | frame_info->regs.r27 = regs->fp; | 101 | frame_info->regs.r27 = regs->fp; |
| @@ -95,7 +108,7 @@ static void seed_unwind_frame_info(struct task_struct *tsk, | |||
| 95 | 108 | ||
| 96 | #endif | 109 | #endif |
| 97 | 110 | ||
| 98 | static noinline unsigned int | 111 | notrace noinline unsigned int |
| 99 | arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs, | 112 | arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs, |
| 100 | int (*consumer_fn) (unsigned int, void *), void *arg) | 113 | int (*consumer_fn) (unsigned int, void *), void *arg) |
| 101 | { | 114 | { |
diff --git a/arch/arc/kernel/unaligned.c b/arch/arc/kernel/unaligned.c index 7ff5b5c183bb..74db59b6f392 100644 --- a/arch/arc/kernel/unaligned.c +++ b/arch/arc/kernel/unaligned.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | */ | 12 | */ |
| 13 | 13 | ||
| 14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
| 15 | #include <linux/perf_event.h> | ||
| 15 | #include <linux/ptrace.h> | 16 | #include <linux/ptrace.h> |
| 16 | #include <linux/uaccess.h> | 17 | #include <linux/uaccess.h> |
| 17 | #include <asm/disasm.h> | 18 | #include <asm/disasm.h> |
| @@ -253,6 +254,7 @@ int misaligned_fixup(unsigned long address, struct pt_regs *regs, | |||
| 253 | } | 254 | } |
| 254 | } | 255 | } |
| 255 | 256 | ||
| 257 | perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, address); | ||
| 256 | return 0; | 258 | return 0; |
| 257 | 259 | ||
| 258 | fault: | 260 | fault: |
diff --git a/arch/arc/mm/fault.c b/arch/arc/mm/fault.c index 563cb27e37f5..6a2e006cbcce 100644 --- a/arch/arc/mm/fault.c +++ b/arch/arc/mm/fault.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <linux/ptrace.h> | 14 | #include <linux/ptrace.h> |
| 15 | #include <linux/uaccess.h> | 15 | #include <linux/uaccess.h> |
| 16 | #include <linux/kdebug.h> | 16 | #include <linux/kdebug.h> |
| 17 | #include <linux/perf_event.h> | ||
| 17 | #include <asm/pgalloc.h> | 18 | #include <asm/pgalloc.h> |
| 18 | #include <asm/mmu.h> | 19 | #include <asm/mmu.h> |
| 19 | 20 | ||
| @@ -139,13 +140,20 @@ good_area: | |||
| 139 | return; | 140 | return; |
| 140 | } | 141 | } |
| 141 | 142 | ||
| 143 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); | ||
| 144 | |||
| 142 | if (likely(!(fault & VM_FAULT_ERROR))) { | 145 | if (likely(!(fault & VM_FAULT_ERROR))) { |
| 143 | if (flags & FAULT_FLAG_ALLOW_RETRY) { | 146 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
| 144 | /* To avoid updating stats twice for retry case */ | 147 | /* To avoid updating stats twice for retry case */ |
| 145 | if (fault & VM_FAULT_MAJOR) | 148 | if (fault & VM_FAULT_MAJOR) { |
| 146 | tsk->maj_flt++; | 149 | tsk->maj_flt++; |
| 147 | else | 150 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, |
| 151 | regs, address); | ||
| 152 | } else { | ||
| 148 | tsk->min_flt++; | 153 | tsk->min_flt++; |
| 154 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, | ||
| 155 | regs, address); | ||
| 156 | } | ||
| 149 | 157 | ||
| 150 | if (fault & VM_FAULT_RETRY) { | 158 | if (fault & VM_FAULT_RETRY) { |
| 151 | flags &= ~FAULT_FLAG_ALLOW_RETRY; | 159 | flags &= ~FAULT_FLAG_ALLOW_RETRY; |
