Stephen Rothwell | bbeb3f4 | 2005-09-27 13:51:59 +1000 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_KPROBES_H |
| 2 | #define _ASM_POWERPC_KPROBES_H |
Luis R. Rodriguez | 7d134b2 | 2017-02-27 14:26:56 -0800 | [diff] [blame] | 3 | |
| 4 | #include <asm-generic/kprobes.h> |
| 5 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 6 | #ifdef __KERNEL__ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 7 | /* |
| 8 | * Kernel Probes (KProbes) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | * Copyright (C) IBM Corporation, 2002, 2004 |
| 25 | * |
| 26 | * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel |
| 27 | * Probes initial implementation ( includes suggestions from |
| 28 | * Rusty Russell). |
| 29 | * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli |
| 30 | * <ananth@in.ibm.com> |
| 31 | */ |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/ptrace.h> |
Ananth N Mavinakayanahalli | 0dc036c | 2005-11-07 01:00:10 -0800 | [diff] [blame] | 34 | #include <linux/percpu.h> |
Naveen N. Rao | 3017646 | 2017-02-08 14:27:31 +0530 | [diff] [blame] | 35 | #include <linux/module.h> |
Ananth N Mavinakayanahalli | 7118e7e | 2012-08-23 21:26:02 +0000 | [diff] [blame] | 36 | #include <asm/probes.h> |
Anton Blanchard | 47f86b4 | 2014-04-03 16:08:38 +1100 | [diff] [blame] | 37 | #include <asm/code-patching.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 38 | |
Naveen N. Rao | 6cc89ba | 2016-11-21 22:36:41 +0530 | [diff] [blame] | 39 | #ifdef CONFIG_KPROBES |
Anil S Keshavamurthy | 2d14e39 | 2006-01-09 20:52:41 -0800 | [diff] [blame] | 40 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
| 41 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 42 | struct pt_regs; |
Ananth N Mavinakayanahalli | 0498b63 | 2006-01-09 20:52:46 -0800 | [diff] [blame] | 43 | struct kprobe; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 44 | |
Ananth N Mavinakayanahalli | 28e1e58 | 2012-09-05 22:17:04 +0000 | [diff] [blame] | 45 | typedef ppc_opcode_t kprobe_opcode_t; |
Anju T | 51c9c08 | 2017-02-08 15:20:51 +0530 | [diff] [blame] | 46 | |
| 47 | extern kprobe_opcode_t optinsn_slot; |
| 48 | |
| 49 | /* Optinsn template address */ |
| 50 | extern kprobe_opcode_t optprobe_template_entry[]; |
| 51 | extern kprobe_opcode_t optprobe_template_op_address[]; |
| 52 | extern kprobe_opcode_t optprobe_template_call_handler[]; |
| 53 | extern kprobe_opcode_t optprobe_template_insn[]; |
| 54 | extern kprobe_opcode_t optprobe_template_call_emulate[]; |
| 55 | extern kprobe_opcode_t optprobe_template_ret[]; |
| 56 | extern kprobe_opcode_t optprobe_template_end[]; |
| 57 | |
| 58 | /* Fixed instruction size for powerpc */ |
| 59 | #define MAX_INSN_SIZE 1 |
| 60 | #define MAX_OPTIMIZED_LENGTH sizeof(kprobe_opcode_t) /* 4 bytes */ |
| 61 | #define MAX_OPTINSN_SIZE (optprobe_template_end - optprobe_template_entry) |
| 62 | #define RELATIVEJUMP_SIZE sizeof(kprobe_opcode_t) /* 4 bytes */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 63 | |
bibo, mao | a9ad965 | 2006-07-30 03:03:26 -0700 | [diff] [blame] | 64 | #define flush_insn_slot(p) do { } while (0) |
Masami Hiramatsu | f438d91 | 2007-10-16 01:27:49 -0700 | [diff] [blame] | 65 | #define kretprobe_blacklist_size 0 |
Anil S Keshavamurthy | e6f47f9 | 2006-06-26 00:25:29 -0700 | [diff] [blame] | 66 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 67 | void kretprobe_trampoline(void); |
Ananth N Mavinakayanahalli | 0498b63 | 2006-01-09 20:52:46 -0800 | [diff] [blame] | 68 | extern void arch_remove_kprobe(struct kprobe *p); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 69 | |
| 70 | /* Architecture specific copy of original instruction */ |
| 71 | struct arch_specific_insn { |
| 72 | /* copy of original instruction */ |
| 73 | kprobe_opcode_t *insn; |
Ananth N Mavinakayanahalli | e6349a95 | 2007-04-18 15:57:51 +1000 | [diff] [blame] | 74 | /* |
| 75 | * Set in kprobes code, initially to 0. If the instruction can be |
| 76 | * eumulated, this is set to 1, if not, to -1. |
| 77 | */ |
| 78 | int boostable; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 79 | }; |
| 80 | |
Ananth N Mavinakayanahalli | 0dc036c | 2005-11-07 01:00:10 -0800 | [diff] [blame] | 81 | struct prev_kprobe { |
| 82 | struct kprobe *kp; |
| 83 | unsigned long status; |
| 84 | unsigned long saved_msr; |
| 85 | }; |
| 86 | |
| 87 | /* per-cpu kprobe control block */ |
| 88 | struct kprobe_ctlblk { |
| 89 | unsigned long kprobe_status; |
| 90 | unsigned long kprobe_saved_msr; |
| 91 | struct pt_regs jprobe_saved_regs; |
| 92 | struct prev_kprobe prev_kprobe; |
| 93 | }; |
| 94 | |
Anju T | 51c9c08 | 2017-02-08 15:20:51 +0530 | [diff] [blame] | 95 | struct arch_optimized_insn { |
| 96 | kprobe_opcode_t copied_insn[1]; |
| 97 | /* detour buffer */ |
| 98 | kprobe_opcode_t *insn; |
| 99 | }; |
| 100 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 101 | extern int kprobe_exceptions_notify(struct notifier_block *self, |
Anil S Keshavamurthy | 41dead4 | 2006-01-09 20:52:42 -0800 | [diff] [blame] | 102 | unsigned long val, void *data); |
Christoph Hellwig | 9f90b99 | 2007-04-30 11:56:46 +0100 | [diff] [blame] | 103 | extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr); |
Naveen N. Rao | 6cc89ba | 2016-11-21 22:36:41 +0530 | [diff] [blame] | 104 | extern int kprobe_handler(struct pt_regs *regs); |
| 105 | extern int kprobe_post_handler(struct pt_regs *regs); |
Naveen N. Rao | ead514d | 2017-04-19 18:22:26 +0530 | [diff] [blame] | 106 | #ifdef CONFIG_KPROBES_ON_FTRACE |
Naveen N. Rao | bf3a912 | 2017-09-22 14:40:45 +0530 | [diff] [blame] | 107 | extern int __is_active_jprobe(unsigned long addr); |
Naveen N. Rao | ead514d | 2017-04-19 18:22:26 +0530 | [diff] [blame] | 108 | extern int skip_singlestep(struct kprobe *p, struct pt_regs *regs, |
| 109 | struct kprobe_ctlblk *kcb); |
| 110 | #else |
| 111 | static inline int skip_singlestep(struct kprobe *p, struct pt_regs *regs, |
| 112 | struct kprobe_ctlblk *kcb) |
| 113 | { |
| 114 | return 0; |
| 115 | } |
| 116 | #endif |
Naveen N. Rao | 6cc89ba | 2016-11-21 22:36:41 +0530 | [diff] [blame] | 117 | #else |
| 118 | static inline int kprobe_handler(struct pt_regs *regs) { return 0; } |
| 119 | static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; } |
| 120 | #endif /* CONFIG_KPROBES */ |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 121 | #endif /* __KERNEL__ */ |
Stephen Rothwell | bbeb3f4 | 2005-09-27 13:51:59 +1000 | [diff] [blame] | 122 | #endif /* _ASM_POWERPC_KPROBES_H */ |