Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Kernel Probes (KProbes) |
| 3 | * arch/ia64/kernel/kprobes.c |
| 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 as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | * Copyright (C) IBM Corporation, 2002, 2004 |
| 20 | * Copyright (C) Intel Corporation, 2005 |
| 21 | * |
| 22 | * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy |
| 23 | * <anil.s.keshavamurthy@intel.com> adapted from i386 |
| 24 | */ |
| 25 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 26 | #include <linux/kprobes.h> |
| 27 | #include <linux/ptrace.h> |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 28 | #include <linux/string.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/preempt.h> |
| 31 | #include <linux/moduleloader.h> |
| 32 | |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/kdebug.h> |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 35 | #include <asm/sections.h> |
Prasanna S Panchamukhi | c04c1c8 | 2006-03-26 01:38:25 -0800 | [diff] [blame] | 36 | #include <asm/uaccess.h> |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 37 | |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 38 | extern void jprobe_inst_return(void); |
| 39 | |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 40 | DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; |
| 41 | DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 42 | |
| 43 | enum instruction_type {A, I, M, F, B, L, X, u}; |
| 44 | static enum instruction_type bundle_encoding[32][3] = { |
| 45 | { M, I, I }, /* 00 */ |
| 46 | { M, I, I }, /* 01 */ |
| 47 | { M, I, I }, /* 02 */ |
| 48 | { M, I, I }, /* 03 */ |
| 49 | { M, L, X }, /* 04 */ |
| 50 | { M, L, X }, /* 05 */ |
| 51 | { u, u, u }, /* 06 */ |
| 52 | { u, u, u }, /* 07 */ |
| 53 | { M, M, I }, /* 08 */ |
| 54 | { M, M, I }, /* 09 */ |
| 55 | { M, M, I }, /* 0A */ |
| 56 | { M, M, I }, /* 0B */ |
| 57 | { M, F, I }, /* 0C */ |
| 58 | { M, F, I }, /* 0D */ |
| 59 | { M, M, F }, /* 0E */ |
| 60 | { M, M, F }, /* 0F */ |
| 61 | { M, I, B }, /* 10 */ |
| 62 | { M, I, B }, /* 11 */ |
| 63 | { M, B, B }, /* 12 */ |
| 64 | { M, B, B }, /* 13 */ |
| 65 | { u, u, u }, /* 14 */ |
| 66 | { u, u, u }, /* 15 */ |
| 67 | { B, B, B }, /* 16 */ |
| 68 | { B, B, B }, /* 17 */ |
| 69 | { M, M, B }, /* 18 */ |
| 70 | { M, M, B }, /* 19 */ |
| 71 | { u, u, u }, /* 1A */ |
| 72 | { u, u, u }, /* 1B */ |
| 73 | { M, F, B }, /* 1C */ |
| 74 | { M, F, B }, /* 1D */ |
| 75 | { u, u, u }, /* 1E */ |
| 76 | { u, u, u }, /* 1F */ |
| 77 | }; |
| 78 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 79 | /* |
| 80 | * In this function we check to see if the instruction |
| 81 | * is IP relative instruction and update the kprobe |
| 82 | * inst flag accordingly |
| 83 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 84 | static void __kprobes update_kprobe_inst_flag(uint template, uint slot, |
| 85 | uint major_opcode, |
| 86 | unsigned long kprobe_inst, |
| 87 | struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 88 | { |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 89 | p->ainsn.inst_flag = 0; |
| 90 | p->ainsn.target_br_reg = 0; |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 91 | p->ainsn.slot = slot; |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 92 | |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 93 | /* Check for Break instruction |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 94 | * Bits 37:40 Major opcode to be zero |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 95 | * Bits 27:32 X6 to be zero |
| 96 | * Bits 32:35 X3 to be zero |
| 97 | */ |
| 98 | if ((!major_opcode) && (!((kprobe_inst >> 27) & 0x1FF)) ) { |
| 99 | /* is a break instruction */ |
| 100 | p->ainsn.inst_flag |= INST_FLAG_BREAK_INST; |
| 101 | return; |
| 102 | } |
| 103 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 104 | if (bundle_encoding[template][slot] == B) { |
| 105 | switch (major_opcode) { |
| 106 | case INDIRECT_CALL_OPCODE: |
| 107 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 108 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 109 | break; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 110 | case IP_RELATIVE_PREDICT_OPCODE: |
| 111 | case IP_RELATIVE_BRANCH_OPCODE: |
| 112 | p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR; |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 113 | break; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 114 | case IP_RELATIVE_CALL_OPCODE: |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 115 | p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR; |
| 116 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
| 117 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 118 | break; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 119 | } |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 120 | } else if (bundle_encoding[template][slot] == X) { |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 121 | switch (major_opcode) { |
| 122 | case LONG_CALL_OPCODE: |
| 123 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
| 124 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | return; |
| 129 | } |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 130 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 131 | /* |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 132 | * In this function we check to see if the instruction |
| 133 | * (qp) cmpx.crel.ctype p1,p2=r2,r3 |
| 134 | * on which we are inserting kprobe is cmp instruction |
| 135 | * with ctype as unc. |
| 136 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 137 | static uint __kprobes is_cmp_ctype_unc_inst(uint template, uint slot, |
| 138 | uint major_opcode, |
| 139 | unsigned long kprobe_inst) |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 140 | { |
| 141 | cmp_inst_t cmp_inst; |
| 142 | uint ctype_unc = 0; |
| 143 | |
| 144 | if (!((bundle_encoding[template][slot] == I) || |
| 145 | (bundle_encoding[template][slot] == M))) |
| 146 | goto out; |
| 147 | |
| 148 | if (!((major_opcode == 0xC) || (major_opcode == 0xD) || |
| 149 | (major_opcode == 0xE))) |
| 150 | goto out; |
| 151 | |
| 152 | cmp_inst.l = kprobe_inst; |
| 153 | if ((cmp_inst.f.x2 == 0) || (cmp_inst.f.x2 == 1)) { |
| 154 | /* Integere compare - Register Register (A6 type)*/ |
| 155 | if ((cmp_inst.f.tb == 0) && (cmp_inst.f.ta == 0) |
| 156 | &&(cmp_inst.f.c == 1)) |
| 157 | ctype_unc = 1; |
| 158 | } else if ((cmp_inst.f.x2 == 2)||(cmp_inst.f.x2 == 3)) { |
| 159 | /* Integere compare - Immediate Register (A8 type)*/ |
| 160 | if ((cmp_inst.f.ta == 0) &&(cmp_inst.f.c == 1)) |
| 161 | ctype_unc = 1; |
| 162 | } |
| 163 | out: |
| 164 | return ctype_unc; |
| 165 | } |
| 166 | |
| 167 | /* |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 168 | * In this function we check to see if the instruction |
| 169 | * on which we are inserting kprobe is supported. |
| 170 | * Returns qp value if supported |
| 171 | * Returns -EINVAL if unsupported |
| 172 | */ |
| 173 | static int __kprobes unsupported_inst(uint template, uint slot, |
| 174 | uint major_opcode, |
| 175 | unsigned long kprobe_inst, |
| 176 | unsigned long addr) |
| 177 | { |
| 178 | int qp; |
| 179 | |
| 180 | qp = kprobe_inst & 0x3f; |
| 181 | if (is_cmp_ctype_unc_inst(template, slot, major_opcode, kprobe_inst)) { |
| 182 | if (slot == 1 && qp) { |
| 183 | printk(KERN_WARNING "Kprobes on cmp unc" |
| 184 | "instruction on slot 1 at <0x%lx>" |
| 185 | "is not supported\n", addr); |
| 186 | return -EINVAL; |
| 187 | |
| 188 | } |
| 189 | qp = 0; |
| 190 | } |
| 191 | else if (bundle_encoding[template][slot] == I) { |
| 192 | if (major_opcode == 0) { |
| 193 | /* |
| 194 | * Check for Integer speculation instruction |
| 195 | * - Bit 33-35 to be equal to 0x1 |
| 196 | */ |
| 197 | if (((kprobe_inst >> 33) & 0x7) == 1) { |
| 198 | printk(KERN_WARNING |
| 199 | "Kprobes on speculation inst at <0x%lx> not supported\n", |
| 200 | addr); |
| 201 | return -EINVAL; |
| 202 | } |
| 203 | /* |
| 204 | * IP relative mov instruction |
| 205 | * - Bit 27-35 to be equal to 0x30 |
| 206 | */ |
| 207 | if (((kprobe_inst >> 27) & 0x1FF) == 0x30) { |
| 208 | printk(KERN_WARNING |
| 209 | "Kprobes on \"mov r1=ip\" at <0x%lx> not supported\n", |
| 210 | addr); |
| 211 | return -EINVAL; |
| 212 | |
| 213 | } |
| 214 | } |
| 215 | else if ((major_opcode == 5) && !(kprobe_inst & (0xFUl << 33)) && |
| 216 | (kprobe_inst & (0x1UL << 12))) { |
| 217 | /* test bit instructions, tbit,tnat,tf |
| 218 | * bit 33-36 to be equal to 0 |
| 219 | * bit 12 to be equal to 1 |
| 220 | */ |
| 221 | if (slot == 1 && qp) { |
| 222 | printk(KERN_WARNING "Kprobes on test bit" |
| 223 | "instruction on slot at <0x%lx>" |
| 224 | "is not supported\n", addr); |
| 225 | return -EINVAL; |
| 226 | } |
| 227 | qp = 0; |
| 228 | } |
| 229 | } |
| 230 | else if (bundle_encoding[template][slot] == B) { |
| 231 | if (major_opcode == 7) { |
| 232 | /* IP-Relative Predict major code is 7 */ |
| 233 | printk(KERN_WARNING "Kprobes on IP-Relative" |
| 234 | "Predict is not supported\n"); |
| 235 | return -EINVAL; |
| 236 | } |
| 237 | else if (major_opcode == 2) { |
| 238 | /* Indirect Predict, major code is 2 |
| 239 | * bit 27-32 to be equal to 10 or 11 |
| 240 | */ |
| 241 | int x6=(kprobe_inst >> 27) & 0x3F; |
| 242 | if ((x6 == 0x10) || (x6 == 0x11)) { |
| 243 | printk(KERN_WARNING "Kprobes on" |
| 244 | "Indirect Predict is not supported\n"); |
| 245 | return -EINVAL; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | /* kernel does not use float instruction, here for safety kprobe |
| 250 | * will judge whether it is fcmp/flass/float approximation instruction |
| 251 | */ |
| 252 | else if (unlikely(bundle_encoding[template][slot] == F)) { |
| 253 | if ((major_opcode == 4 || major_opcode == 5) && |
| 254 | (kprobe_inst & (0x1 << 12))) { |
| 255 | /* fcmp/fclass unc instruction */ |
| 256 | if (slot == 1 && qp) { |
| 257 | printk(KERN_WARNING "Kprobes on fcmp/fclass " |
| 258 | "instruction on slot at <0x%lx> " |
| 259 | "is not supported\n", addr); |
| 260 | return -EINVAL; |
| 261 | |
| 262 | } |
| 263 | qp = 0; |
| 264 | } |
| 265 | if ((major_opcode == 0 || major_opcode == 1) && |
| 266 | (kprobe_inst & (0x1UL << 33))) { |
| 267 | /* float Approximation instruction */ |
| 268 | if (slot == 1 && qp) { |
| 269 | printk(KERN_WARNING "Kprobes on float Approx " |
| 270 | "instr at <0x%lx> is not supported\n", |
| 271 | addr); |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | qp = 0; |
| 275 | } |
| 276 | } |
| 277 | return qp; |
| 278 | } |
| 279 | |
| 280 | /* |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 281 | * In this function we override the bundle with |
| 282 | * the break instruction at the given slot. |
| 283 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 284 | static void __kprobes prepare_break_inst(uint template, uint slot, |
| 285 | uint major_opcode, |
| 286 | unsigned long kprobe_inst, |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 287 | struct kprobe *p, |
| 288 | int qp) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 289 | { |
| 290 | unsigned long break_inst = BREAK_INST; |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 291 | bundle_t *bundle = &p->opcode.bundle; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Copy the original kprobe_inst qualifying predicate(qp) |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 295 | * to the break instruction |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 296 | */ |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 297 | break_inst |= qp; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 298 | |
| 299 | switch (slot) { |
| 300 | case 0: |
| 301 | bundle->quad0.slot0 = break_inst; |
| 302 | break; |
| 303 | case 1: |
| 304 | bundle->quad0.slot1_p0 = break_inst; |
| 305 | bundle->quad1.slot1_p1 = break_inst >> (64-46); |
| 306 | break; |
| 307 | case 2: |
| 308 | bundle->quad1.slot2 = break_inst; |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Update the instruction flag, so that we can |
| 314 | * emulate the instruction properly after we |
| 315 | * single step on original instruction |
| 316 | */ |
| 317 | update_kprobe_inst_flag(template, slot, major_opcode, kprobe_inst, p); |
| 318 | } |
| 319 | |
Prasanna S Panchamukhi | 3ca269d | 2006-04-18 22:22:02 -0700 | [diff] [blame] | 320 | static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot, |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 321 | unsigned long *kprobe_inst, uint *major_opcode) |
| 322 | { |
| 323 | unsigned long kprobe_inst_p0, kprobe_inst_p1; |
| 324 | unsigned int template; |
| 325 | |
| 326 | template = bundle->quad0.template; |
| 327 | |
| 328 | switch (slot) { |
| 329 | case 0: |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 330 | *major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT); |
| 331 | *kprobe_inst = bundle->quad0.slot0; |
| 332 | break; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 333 | case 1: |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 334 | *major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT); |
| 335 | kprobe_inst_p0 = bundle->quad0.slot1_p0; |
| 336 | kprobe_inst_p1 = bundle->quad1.slot1_p1; |
| 337 | *kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46)); |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 338 | break; |
| 339 | case 2: |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 340 | *major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT); |
| 341 | *kprobe_inst = bundle->quad1.slot2; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 342 | break; |
| 343 | } |
| 344 | } |
| 345 | |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 346 | /* Returns non-zero if the addr is in the Interrupt Vector Table */ |
Prasanna S Panchamukhi | 3ca269d | 2006-04-18 22:22:02 -0700 | [diff] [blame] | 347 | static int __kprobes in_ivt_functions(unsigned long addr) |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 348 | { |
| 349 | return (addr >= (unsigned long)__start_ivt_text |
| 350 | && addr < (unsigned long)__end_ivt_text); |
| 351 | } |
| 352 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 353 | static int __kprobes valid_kprobe_addr(int template, int slot, |
| 354 | unsigned long addr) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 355 | { |
| 356 | if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) { |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 357 | printk(KERN_WARNING "Attempting to insert unaligned kprobe " |
| 358 | "at 0x%lx\n", addr); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 359 | return -EINVAL; |
| 360 | } |
Rusty Lynch | a528e21 | 2005-06-27 15:17:15 -0700 | [diff] [blame] | 361 | |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 362 | if (in_ivt_functions(addr)) { |
| 363 | printk(KERN_WARNING "Kprobes can't be inserted inside " |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 364 | "IVT functions at 0x%lx\n", addr); |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 365 | return -EINVAL; |
| 366 | } |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 367 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 368 | return 0; |
| 369 | } |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 370 | |
Prasanna S Panchamukhi | 3ca269d | 2006-04-18 22:22:02 -0700 | [diff] [blame] | 371 | static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 372 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 373 | kcb->prev_kprobe.kp = kprobe_running(); |
| 374 | kcb->prev_kprobe.status = kcb->kprobe_status; |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Prasanna S Panchamukhi | 3ca269d | 2006-04-18 22:22:02 -0700 | [diff] [blame] | 377 | static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb) |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 378 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 379 | __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp; |
| 380 | kcb->kprobe_status = kcb->prev_kprobe.status; |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Prasanna S Panchamukhi | 3ca269d | 2006-04-18 22:22:02 -0700 | [diff] [blame] | 383 | static void __kprobes set_current_kprobe(struct kprobe *p, |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 384 | struct kprobe_ctlblk *kcb) |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 385 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 386 | __get_cpu_var(current_kprobe) = p; |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 389 | static void kretprobe_trampoline(void) |
| 390 | { |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | * At this point the target function has been tricked into |
| 395 | * returning into our trampoline. Lookup the associated instance |
| 396 | * and then: |
| 397 | * - call the handler function |
| 398 | * - cleanup by marking the instance as unused |
| 399 | * - long jump back to the original return address |
| 400 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 401 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 402 | { |
| 403 | struct kretprobe_instance *ri = NULL; |
bibo,mao | 99219a3 | 2006-10-02 02:17:35 -0700 | [diff] [blame] | 404 | struct hlist_head *head, empty_rp; |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 405 | struct hlist_node *node, *tmp; |
Ananth N Mavinakayanahalli | 991a51d | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 406 | unsigned long flags, orig_ret_address = 0; |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 407 | unsigned long trampoline_address = |
| 408 | ((struct fnptr *)kretprobe_trampoline)->ip; |
| 409 | |
bibo,mao | 99219a3 | 2006-10-02 02:17:35 -0700 | [diff] [blame] | 410 | INIT_HLIST_HEAD(&empty_rp); |
Ananth N Mavinakayanahalli | 991a51d | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 411 | spin_lock_irqsave(&kretprobe_lock, flags); |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 412 | head = kretprobe_inst_table_head(current); |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 413 | |
| 414 | /* |
| 415 | * It is possible to have multiple instances associated with a given |
| 416 | * task either because an multiple functions in the call path |
| 417 | * have a return probe installed on them, and/or more then one return |
| 418 | * return probe was registered for a target function. |
| 419 | * |
| 420 | * We can handle this because: |
| 421 | * - instances are always inserted at the head of the list |
| 422 | * - when multiple return probes are registered for the same |
| 423 | * function, the first instance's ret_addr will point to the |
| 424 | * real return address, and all the rest will point to |
| 425 | * kretprobe_trampoline |
| 426 | */ |
| 427 | hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 428 | if (ri->task != current) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 429 | /* another task is sharing our hash bucket */ |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 430 | continue; |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 431 | |
| 432 | if (ri->rp && ri->rp->handler) |
| 433 | ri->rp->handler(ri, regs); |
| 434 | |
| 435 | orig_ret_address = (unsigned long)ri->ret_addr; |
bibo,mao | 99219a3 | 2006-10-02 02:17:35 -0700 | [diff] [blame] | 436 | recycle_rp_inst(ri, &empty_rp); |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 437 | |
| 438 | if (orig_ret_address != trampoline_address) |
| 439 | /* |
| 440 | * This is the real return address. Any other |
| 441 | * instances associated with this task are for |
| 442 | * other calls deeper on the call stack |
| 443 | */ |
| 444 | break; |
| 445 | } |
| 446 | |
| 447 | BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); |
| 448 | regs->cr_iip = orig_ret_address; |
| 449 | |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 450 | reset_current_kprobe(); |
Ananth N Mavinakayanahalli | 991a51d | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 451 | spin_unlock_irqrestore(&kretprobe_lock, flags); |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 452 | preempt_enable_no_resched(); |
| 453 | |
bibo,mao | 99219a3 | 2006-10-02 02:17:35 -0700 | [diff] [blame] | 454 | hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) { |
| 455 | hlist_del(&ri->hlist); |
| 456 | kfree(ri); |
| 457 | } |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 458 | /* |
| 459 | * By returning a non-zero value, we are telling |
| 460 | * kprobe_handler() that we don't want the post_handler |
| 461 | * to run (and have re-enabled preemption) |
| 462 | */ |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 463 | return 1; |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Ananth N Mavinakayanahalli | 991a51d | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 466 | /* Called with kretprobe_lock held */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 467 | void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, |
| 468 | struct pt_regs *regs) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 469 | { |
| 470 | struct kretprobe_instance *ri; |
| 471 | |
| 472 | if ((ri = get_free_rp_inst(rp)) != NULL) { |
| 473 | ri->rp = rp; |
| 474 | ri->task = current; |
| 475 | ri->ret_addr = (kprobe_opcode_t *)regs->b0; |
| 476 | |
| 477 | /* Replace the return addr with trampoline addr */ |
| 478 | regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip; |
| 479 | |
| 480 | add_rp_inst(ri); |
| 481 | } else { |
| 482 | rp->nmissed++; |
| 483 | } |
| 484 | } |
| 485 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 486 | int __kprobes arch_prepare_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 487 | { |
| 488 | unsigned long addr = (unsigned long) p->addr; |
| 489 | unsigned long *kprobe_addr = (unsigned long *)(addr & ~0xFULL); |
| 490 | unsigned long kprobe_inst=0; |
| 491 | unsigned int slot = addr & 0xf, template, major_opcode = 0; |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 492 | bundle_t *bundle; |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 493 | int qp; |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 494 | |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 495 | bundle = &((kprobe_opcode_t *)kprobe_addr)->bundle; |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 496 | template = bundle->quad0.template; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 497 | |
| 498 | if(valid_kprobe_addr(template, slot, addr)) |
| 499 | return -EINVAL; |
| 500 | |
| 501 | /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */ |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 502 | if (slot == 1 && bundle_encoding[template][1] == L) |
| 503 | slot++; |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 504 | |
| 505 | /* Get kprobe_inst and major_opcode from the bundle */ |
| 506 | get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode); |
| 507 | |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 508 | qp = unsupported_inst(template, slot, major_opcode, kprobe_inst, addr); |
| 509 | if (qp < 0) |
| 510 | return -EINVAL; |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 511 | |
| 512 | p->ainsn.insn = get_insn_slot(); |
| 513 | if (!p->ainsn.insn) |
| 514 | return -ENOMEM; |
| 515 | memcpy(&p->opcode, kprobe_addr, sizeof(kprobe_opcode_t)); |
| 516 | memcpy(p->ainsn.insn, kprobe_addr, sizeof(kprobe_opcode_t)); |
| 517 | |
bibo,mao | df3e0d1 | 2006-12-12 12:04:42 -0800 | [diff] [blame^] | 518 | prepare_break_inst(template, slot, major_opcode, kprobe_inst, p, qp); |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 519 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 523 | void __kprobes arch_arm_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 524 | { |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 525 | unsigned long arm_addr; |
| 526 | bundle_t *src, *dest; |
| 527 | |
| 528 | arm_addr = ((unsigned long)p->addr) & ~0xFUL; |
| 529 | dest = &((kprobe_opcode_t *)arm_addr)->bundle; |
| 530 | src = &p->opcode.bundle; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 531 | |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 532 | flush_icache_range((unsigned long)p->ainsn.insn, |
| 533 | (unsigned long)p->ainsn.insn + sizeof(kprobe_opcode_t)); |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 534 | switch (p->ainsn.slot) { |
| 535 | case 0: |
| 536 | dest->quad0.slot0 = src->quad0.slot0; |
| 537 | break; |
| 538 | case 1: |
| 539 | dest->quad1.slot1_p1 = src->quad1.slot1_p1; |
| 540 | break; |
| 541 | case 2: |
| 542 | dest->quad1.slot2 = src->quad1.slot2; |
| 543 | break; |
| 544 | } |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 545 | flush_icache_range(arm_addr, arm_addr + sizeof(kprobe_opcode_t)); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 548 | void __kprobes arch_disarm_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 549 | { |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 550 | unsigned long arm_addr; |
| 551 | bundle_t *src, *dest; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 552 | |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 553 | arm_addr = ((unsigned long)p->addr) & ~0xFUL; |
| 554 | dest = &((kprobe_opcode_t *)arm_addr)->bundle; |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 555 | /* p->ainsn.insn contains the original unaltered kprobe_opcode_t */ |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 556 | src = &p->ainsn.insn->bundle; |
| 557 | switch (p->ainsn.slot) { |
| 558 | case 0: |
| 559 | dest->quad0.slot0 = src->quad0.slot0; |
| 560 | break; |
| 561 | case 1: |
| 562 | dest->quad1.slot1_p1 = src->quad1.slot1_p1; |
| 563 | break; |
| 564 | case 2: |
| 565 | dest->quad1.slot2 = src->quad1.slot2; |
| 566 | break; |
| 567 | } |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 568 | flush_icache_range(arm_addr, arm_addr + sizeof(kprobe_opcode_t)); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 569 | } |
| 570 | |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 571 | void __kprobes arch_remove_kprobe(struct kprobe *p) |
| 572 | { |
| 573 | mutex_lock(&kprobe_mutex); |
Masami Hiramatsu | b4c6c34 | 2006-12-06 20:38:11 -0800 | [diff] [blame] | 574 | free_insn_slot(p->ainsn.insn, 0); |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 575 | mutex_unlock(&kprobe_mutex); |
| 576 | } |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 577 | /* |
| 578 | * We are resuming execution after a single step fault, so the pt_regs |
| 579 | * structure reflects the register state after we executed the instruction |
| 580 | * located in the kprobe (p->ainsn.insn.bundle). We still need to adjust |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 581 | * the ip to point back to the original stack address. To set the IP address |
| 582 | * to original stack address, handle the case where we need to fixup the |
| 583 | * relative IP address and/or fixup branch register. |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 584 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 585 | static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 586 | { |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 587 | unsigned long bundle_addr = (unsigned long) (&p->ainsn.insn->bundle); |
| 588 | unsigned long resume_addr = (unsigned long)p->addr & ~0xFULL; |
| 589 | unsigned long template; |
| 590 | int slot = ((unsigned long)p->addr & 0xf); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 591 | |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 592 | template = p->ainsn.insn->bundle.quad0.template; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 593 | |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 594 | if (slot == 1 && bundle_encoding[template][1] == L) |
| 595 | slot = 2; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 596 | |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 597 | if (p->ainsn.inst_flag) { |
| 598 | |
| 599 | if (p->ainsn.inst_flag & INST_FLAG_FIX_RELATIVE_IP_ADDR) { |
| 600 | /* Fix relative IP address */ |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 601 | regs->cr_iip = (regs->cr_iip - bundle_addr) + |
| 602 | resume_addr; |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | if (p->ainsn.inst_flag & INST_FLAG_FIX_BRANCH_REG) { |
| 606 | /* |
| 607 | * Fix target branch register, software convention is |
| 608 | * to use either b0 or b6 or b7, so just checking |
| 609 | * only those registers |
| 610 | */ |
| 611 | switch (p->ainsn.target_br_reg) { |
| 612 | case 0: |
| 613 | if ((regs->b0 == bundle_addr) || |
| 614 | (regs->b0 == bundle_addr + 0x10)) { |
| 615 | regs->b0 = (regs->b0 - bundle_addr) + |
| 616 | resume_addr; |
| 617 | } |
| 618 | break; |
| 619 | case 6: |
| 620 | if ((regs->b6 == bundle_addr) || |
| 621 | (regs->b6 == bundle_addr + 0x10)) { |
| 622 | regs->b6 = (regs->b6 - bundle_addr) + |
| 623 | resume_addr; |
| 624 | } |
| 625 | break; |
| 626 | case 7: |
| 627 | if ((regs->b7 == bundle_addr) || |
| 628 | (regs->b7 == bundle_addr + 0x10)) { |
| 629 | regs->b7 = (regs->b7 - bundle_addr) + |
| 630 | resume_addr; |
| 631 | } |
| 632 | break; |
| 633 | } /* end switch */ |
| 634 | } |
| 635 | goto turn_ss_off; |
| 636 | } |
| 637 | |
| 638 | if (slot == 2) { |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 639 | if (regs->cr_iip == bundle_addr + 0x10) { |
| 640 | regs->cr_iip = resume_addr + 0x10; |
| 641 | } |
| 642 | } else { |
| 643 | if (regs->cr_iip == bundle_addr) { |
| 644 | regs->cr_iip = resume_addr; |
| 645 | } |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 646 | } |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 647 | |
| 648 | turn_ss_off: |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 649 | /* Turn off Single Step bit */ |
| 650 | ia64_psr(regs)->ss = 0; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 653 | static void __kprobes prepare_ss(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 654 | { |
bibo mao | 214ddde | 2006-09-26 11:20:37 -0700 | [diff] [blame] | 655 | unsigned long bundle_addr = (unsigned long) &p->ainsn.insn->bundle; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 656 | unsigned long slot = (unsigned long)p->addr & 0xf; |
| 657 | |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 658 | /* single step inline if break instruction */ |
| 659 | if (p->ainsn.inst_flag == INST_FLAG_BREAK_INST) |
| 660 | regs->cr_iip = (unsigned long)p->addr & ~0xFULL; |
| 661 | else |
| 662 | regs->cr_iip = bundle_addr & ~0xFULL; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 663 | |
| 664 | if (slot > 2) |
| 665 | slot = 0; |
| 666 | |
| 667 | ia64_psr(regs)->ri = slot; |
| 668 | |
| 669 | /* turn on single stepping */ |
| 670 | ia64_psr(regs)->ss = 1; |
| 671 | } |
| 672 | |
Keshavamurthy Anil S | 661e5a3 | 2005-09-06 15:19:32 -0700 | [diff] [blame] | 673 | static int __kprobes is_ia64_break_inst(struct pt_regs *regs) |
| 674 | { |
| 675 | unsigned int slot = ia64_psr(regs)->ri; |
| 676 | unsigned int template, major_opcode; |
| 677 | unsigned long kprobe_inst; |
| 678 | unsigned long *kprobe_addr = (unsigned long *)regs->cr_iip; |
| 679 | bundle_t bundle; |
| 680 | |
| 681 | memcpy(&bundle, kprobe_addr, sizeof(bundle_t)); |
| 682 | template = bundle.quad0.template; |
| 683 | |
| 684 | /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */ |
| 685 | if (slot == 1 && bundle_encoding[template][1] == L) |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 686 | slot++; |
Keshavamurthy Anil S | 661e5a3 | 2005-09-06 15:19:32 -0700 | [diff] [blame] | 687 | |
| 688 | /* Get Kprobe probe instruction at given slot*/ |
| 689 | get_kprobe_inst(&bundle, slot, &kprobe_inst, &major_opcode); |
| 690 | |
| 691 | /* For break instruction, |
| 692 | * Bits 37:40 Major opcode to be zero |
| 693 | * Bits 27:32 X6 to be zero |
| 694 | * Bits 32:35 X3 to be zero |
| 695 | */ |
| 696 | if (major_opcode || ((kprobe_inst >> 27) & 0x1FF) ) { |
| 697 | /* Not a break instruction */ |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | /* Is a break instruction */ |
| 702 | return 1; |
| 703 | } |
| 704 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 705 | static int __kprobes pre_kprobes_handler(struct die_args *args) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 706 | { |
| 707 | struct kprobe *p; |
| 708 | int ret = 0; |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 709 | struct pt_regs *regs = args->regs; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 710 | kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs); |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 711 | struct kprobe_ctlblk *kcb; |
| 712 | |
| 713 | /* |
| 714 | * We don't want to be preempted for the entire |
| 715 | * duration of kprobe processing |
| 716 | */ |
| 717 | preempt_disable(); |
| 718 | kcb = get_kprobe_ctlblk(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 719 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 720 | /* Handle recursion cases */ |
| 721 | if (kprobe_running()) { |
| 722 | p = get_kprobe(addr); |
| 723 | if (p) { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 724 | if ((kcb->kprobe_status == KPROBE_HIT_SS) && |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 725 | (p->ainsn.inst_flag == INST_FLAG_BREAK_INST)) { |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 726 | ia64_psr(regs)->ss = 0; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 727 | goto no_kprobe; |
| 728 | } |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 729 | /* We have reentered the pre_kprobe_handler(), since |
| 730 | * another probe was hit while within the handler. |
| 731 | * We here save the original kprobes variables and |
| 732 | * just single step on the instruction of the new probe |
| 733 | * without calling any user handlers. |
| 734 | */ |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 735 | save_previous_kprobe(kcb); |
| 736 | set_current_kprobe(p, kcb); |
Keshavamurthy Anil S | bf8d5c5 | 2005-12-12 00:37:34 -0800 | [diff] [blame] | 737 | kprobes_inc_nmissed_count(p); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 738 | prepare_ss(p, regs); |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 739 | kcb->kprobe_status = KPROBE_REENTER; |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 740 | return 1; |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 741 | } else if (args->err == __IA64_BREAK_JPROBE) { |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 742 | /* |
| 743 | * jprobe instrumented function just completed |
| 744 | */ |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 745 | p = __get_cpu_var(current_kprobe); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 746 | if (p->break_handler && p->break_handler(p, regs)) { |
| 747 | goto ss_probe; |
| 748 | } |
Keshavamurthy Anil S | eb3a729 | 2006-01-11 12:17:42 -0800 | [diff] [blame] | 749 | } else if (!is_ia64_break_inst(regs)) { |
| 750 | /* The breakpoint instruction was removed by |
| 751 | * another cpu right after we hit, no further |
| 752 | * handling of this interrupt is appropriate |
| 753 | */ |
| 754 | ret = 1; |
| 755 | goto no_kprobe; |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 756 | } else { |
| 757 | /* Not our break */ |
| 758 | goto no_kprobe; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 762 | p = get_kprobe(addr); |
| 763 | if (!p) { |
Keshavamurthy Anil S | 661e5a3 | 2005-09-06 15:19:32 -0700 | [diff] [blame] | 764 | if (!is_ia64_break_inst(regs)) { |
| 765 | /* |
| 766 | * The breakpoint instruction was removed right |
| 767 | * after we hit it. Another cpu has removed |
| 768 | * either a probepoint or a debugger breakpoint |
| 769 | * at this address. In either case, no further |
| 770 | * handling of this interrupt is appropriate. |
| 771 | */ |
| 772 | ret = 1; |
| 773 | |
| 774 | } |
| 775 | |
| 776 | /* Not one of our break, let kernel handle it */ |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 777 | goto no_kprobe; |
| 778 | } |
| 779 | |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 780 | set_current_kprobe(p, kcb); |
| 781 | kcb->kprobe_status = KPROBE_HIT_ACTIVE; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 782 | |
| 783 | if (p->pre_handler && p->pre_handler(p, regs)) |
| 784 | /* |
| 785 | * Our pre-handler is specifically requesting that we just |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 786 | * do a return. This is used for both the jprobe pre-handler |
| 787 | * and the kretprobe trampoline |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 788 | */ |
| 789 | return 1; |
| 790 | |
| 791 | ss_probe: |
| 792 | prepare_ss(p, regs); |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 793 | kcb->kprobe_status = KPROBE_HIT_SS; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 794 | return 1; |
| 795 | |
| 796 | no_kprobe: |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 797 | preempt_enable_no_resched(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 798 | return ret; |
| 799 | } |
| 800 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 801 | static int __kprobes post_kprobes_handler(struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 802 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 803 | struct kprobe *cur = kprobe_running(); |
| 804 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
| 805 | |
| 806 | if (!cur) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 807 | return 0; |
| 808 | |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 809 | if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) { |
| 810 | kcb->kprobe_status = KPROBE_HIT_SSDONE; |
| 811 | cur->post_handler(cur, regs, 0); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 812 | } |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 813 | |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 814 | resume_execution(cur, regs); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 815 | |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 816 | /*Restore back the original saved kprobes variables and continue. */ |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 817 | if (kcb->kprobe_status == KPROBE_REENTER) { |
| 818 | restore_previous_kprobe(kcb); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 819 | goto out; |
| 820 | } |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 821 | reset_current_kprobe(); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 822 | |
| 823 | out: |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 824 | preempt_enable_no_resched(); |
| 825 | return 1; |
| 826 | } |
| 827 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 828 | static int __kprobes kprobes_fault_handler(struct pt_regs *regs, int trapnr) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 829 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 830 | struct kprobe *cur = kprobe_running(); |
| 831 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
| 832 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 833 | |
Prasanna S Panchamukhi | c04c1c8 | 2006-03-26 01:38:25 -0800 | [diff] [blame] | 834 | switch(kcb->kprobe_status) { |
| 835 | case KPROBE_HIT_SS: |
| 836 | case KPROBE_REENTER: |
| 837 | /* |
| 838 | * We are here because the instruction being single |
| 839 | * stepped caused a page fault. We reset the current |
| 840 | * kprobe and the instruction pointer points back to |
| 841 | * the probe address and allow the page fault handler |
| 842 | * to continue as a normal page fault. |
| 843 | */ |
| 844 | regs->cr_iip = ((unsigned long)cur->addr) & ~0xFULL; |
| 845 | ia64_psr(regs)->ri = ((unsigned long)cur->addr) & 0xf; |
| 846 | if (kcb->kprobe_status == KPROBE_REENTER) |
| 847 | restore_previous_kprobe(kcb); |
| 848 | else |
| 849 | reset_current_kprobe(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 850 | preempt_enable_no_resched(); |
Prasanna S Panchamukhi | c04c1c8 | 2006-03-26 01:38:25 -0800 | [diff] [blame] | 851 | break; |
| 852 | case KPROBE_HIT_ACTIVE: |
| 853 | case KPROBE_HIT_SSDONE: |
| 854 | /* |
| 855 | * We increment the nmissed count for accounting, |
| 856 | * we can also use npre/npostfault count for accouting |
| 857 | * these specific fault cases. |
| 858 | */ |
| 859 | kprobes_inc_nmissed_count(cur); |
| 860 | |
| 861 | /* |
| 862 | * We come here because instructions in the pre/post |
| 863 | * handler caused the page_fault, this could happen |
| 864 | * if handler tries to access user space by |
| 865 | * copy_from_user(), get_user() etc. Let the |
| 866 | * user-specified handler try to fix it first. |
| 867 | */ |
| 868 | if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr)) |
| 869 | return 1; |
Keshavamurthy Anil S | fd32cb3 | 2006-09-25 16:32:20 -0700 | [diff] [blame] | 870 | /* |
| 871 | * In case the user-specified fault handler returned |
| 872 | * zero, try to fix up. |
| 873 | */ |
| 874 | if (ia64_done_with_exception(regs)) |
| 875 | return 1; |
Prasanna S Panchamukhi | c04c1c8 | 2006-03-26 01:38:25 -0800 | [diff] [blame] | 876 | |
| 877 | /* |
| 878 | * Let ia64_do_page_fault() fix it. |
| 879 | */ |
| 880 | break; |
| 881 | default: |
| 882 | break; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 888 | int __kprobes kprobe_exceptions_notify(struct notifier_block *self, |
| 889 | unsigned long val, void *data) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 890 | { |
| 891 | struct die_args *args = (struct die_args *)data; |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame] | 892 | int ret = NOTIFY_DONE; |
| 893 | |
bibo,mao | 2326c77 | 2006-03-26 01:38:21 -0800 | [diff] [blame] | 894 | if (args->regs && user_mode(args->regs)) |
| 895 | return ret; |
| 896 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 897 | switch(val) { |
| 898 | case DIE_BREAK: |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 899 | /* err is break number from ia64_bad_break() */ |
Tony Luck | 08ed38b | 2006-11-14 09:33:38 -0800 | [diff] [blame] | 900 | if ((args->err >> 12) == (__IA64_BREAK_KPROBE >> 12) |
| 901 | || args->err == __IA64_BREAK_JPROBE |
| 902 | || args->err == 0) |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 903 | if (pre_kprobes_handler(args)) |
| 904 | ret = NOTIFY_STOP; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 905 | break; |
Keith Owens | 9138d58 | 2005-11-07 11:27:13 -0800 | [diff] [blame] | 906 | case DIE_FAULT: |
| 907 | /* err is vector number from ia64_fault() */ |
| 908 | if (args->err == 36) |
| 909 | if (post_kprobes_handler(args->regs)) |
| 910 | ret = NOTIFY_STOP; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 911 | break; |
| 912 | case DIE_PAGE_FAULT: |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 913 | /* kprobe_running() needs smp_processor_id() */ |
| 914 | preempt_disable(); |
| 915 | if (kprobe_running() && |
| 916 | kprobes_fault_handler(args->regs, args->trapnr)) |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame] | 917 | ret = NOTIFY_STOP; |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 918 | preempt_enable(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 919 | default: |
| 920 | break; |
| 921 | } |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame] | 922 | return ret; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 925 | struct param_bsp_cfm { |
| 926 | unsigned long ip; |
| 927 | unsigned long *bsp; |
| 928 | unsigned long cfm; |
| 929 | }; |
| 930 | |
| 931 | static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg) |
| 932 | { |
| 933 | unsigned long ip; |
| 934 | struct param_bsp_cfm *lp = arg; |
| 935 | |
| 936 | do { |
| 937 | unw_get_ip(info, &ip); |
| 938 | if (ip == 0) |
| 939 | break; |
| 940 | if (ip == lp->ip) { |
| 941 | unw_get_bsp(info, (unsigned long*)&lp->bsp); |
| 942 | unw_get_cfm(info, (unsigned long*)&lp->cfm); |
| 943 | return; |
| 944 | } |
| 945 | } while (unw_unwind(info) >= 0); |
Matthew Wilcox | d61b49c | 2006-10-26 12:22:32 -0600 | [diff] [blame] | 946 | lp->bsp = NULL; |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 947 | lp->cfm = 0; |
| 948 | return; |
| 949 | } |
| 950 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 951 | int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 952 | { |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 953 | struct jprobe *jp = container_of(p, struct jprobe, kp); |
| 954 | unsigned long addr = ((struct fnptr *)(jp->entry))->ip; |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 955 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 956 | struct param_bsp_cfm pa; |
| 957 | int bytes; |
| 958 | |
| 959 | /* |
| 960 | * Callee owns the argument space and could overwrite it, eg |
| 961 | * tail call optimization. So to be absolutely safe |
| 962 | * we save the argument space before transfering the control |
| 963 | * to instrumented jprobe function which runs in |
| 964 | * the process context |
| 965 | */ |
| 966 | pa.ip = regs->cr_iip; |
| 967 | unw_init_running(ia64_get_bsp_cfm, &pa); |
| 968 | bytes = (char *)ia64_rse_skip_regs(pa.bsp, pa.cfm & 0x3f) |
| 969 | - (char *)pa.bsp; |
| 970 | memcpy( kcb->jprobes_saved_stacked_regs, |
| 971 | pa.bsp, |
| 972 | bytes ); |
| 973 | kcb->bsp = pa.bsp; |
| 974 | kcb->cfm = pa.cfm; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 975 | |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 976 | /* save architectural state */ |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 977 | kcb->jprobe_saved_regs = *regs; |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 978 | |
| 979 | /* after rfi, execute the jprobe instrumented function */ |
| 980 | regs->cr_iip = addr & ~0xFULL; |
| 981 | ia64_psr(regs)->ri = addr & 0xf; |
| 982 | regs->r1 = ((struct fnptr *)(jp->entry))->gp; |
| 983 | |
| 984 | /* |
| 985 | * fix the return address to our jprobe_inst_return() function |
| 986 | * in the jprobes.S file |
| 987 | */ |
bibo,mao | 62c27be | 2006-10-02 02:17:33 -0700 | [diff] [blame] | 988 | regs->b0 = ((struct fnptr *)(jprobe_inst_return))->ip; |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 989 | |
| 990 | return 1; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 993 | int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 994 | { |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 995 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 996 | int bytes; |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 997 | |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 998 | /* restoring architectural state */ |
Ananth N Mavinakayanahalli | 8a5c4dc | 2005-11-07 01:00:09 -0800 | [diff] [blame] | 999 | *regs = kcb->jprobe_saved_regs; |
Zhang Yanmin | d3ef1f5 | 2006-01-13 14:45:21 -0800 | [diff] [blame] | 1000 | |
| 1001 | /* restoring the original argument space */ |
| 1002 | flush_register_stack(); |
| 1003 | bytes = (char *)ia64_rse_skip_regs(kcb->bsp, kcb->cfm & 0x3f) |
| 1004 | - (char *)kcb->bsp; |
| 1005 | memcpy( kcb->bsp, |
| 1006 | kcb->jprobes_saved_stacked_regs, |
| 1007 | bytes ); |
| 1008 | invalidate_stacked_regs(); |
| 1009 | |
Ananth N Mavinakayanahalli | d217d54 | 2005-11-07 01:00:14 -0800 | [diff] [blame] | 1010 | preempt_enable_no_resched(); |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 1011 | return 1; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 1012 | } |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 1013 | |
| 1014 | static struct kprobe trampoline_p = { |
| 1015 | .pre_handler = trampoline_probe_handler |
| 1016 | }; |
| 1017 | |
Rusty Lynch | 6772926 | 2005-07-05 18:54:50 -0700 | [diff] [blame] | 1018 | int __init arch_init_kprobes(void) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 1019 | { |
| 1020 | trampoline_p.addr = |
| 1021 | (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip; |
| 1022 | return register_kprobe(&trampoline_p); |
| 1023 | } |