kprobes.c (b76e59d1fb086c2fdac5d243e09786d6581f2026) kprobes.c (f82796214a95b1ec00c2f121c1080d10f2b099a1)
1/*
2 * Kernel Probes (KProbes)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 20 unchanged lines hidden (view full) ---

29#include <linux/kprobes.h>
30#include <linux/ptrace.h>
31#include <linux/preempt.h>
32#include <linux/module.h>
33#include <linux/kdebug.h>
34#include <asm/cacheflush.h>
35#include <asm/sstep.h>
36#include <asm/uaccess.h>
1/*
2 * Kernel Probes (KProbes)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 20 unchanged lines hidden (view full) ---

29#include <linux/kprobes.h>
30#include <linux/ptrace.h>
31#include <linux/preempt.h>
32#include <linux/module.h>
33#include <linux/kdebug.h>
34#include <asm/cacheflush.h>
35#include <asm/sstep.h>
36#include <asm/uaccess.h>
37#include <asm/system.h>
37
38
39#ifdef CONFIG_BOOKE
40#define MSR_SINGLESTEP (MSR_DE)
41#else
42#define MSR_SINGLESTEP (MSR_SE)
43#endif
44
38DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
39DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
40
41struct kretprobe_blackpoint kretprobe_blacklist[] = {{NULL, NULL}};
42
43int __kprobes arch_prepare_kprobe(struct kprobe *p)
44{
45 int ret = 0;
46 kprobe_opcode_t insn = *p->addr;
47
48 if ((unsigned long)p->addr & 0x03) {
49 printk("Attempt to register kprobe at an unaligned address\n");
50 ret = -EINVAL;
51 } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) {
52 printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n");
53 ret = -EINVAL;
54 }
55
45DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
46DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
47
48struct kretprobe_blackpoint kretprobe_blacklist[] = {{NULL, NULL}};
49
50int __kprobes arch_prepare_kprobe(struct kprobe *p)
51{
52 int ret = 0;
53 kprobe_opcode_t insn = *p->addr;
54
55 if ((unsigned long)p->addr & 0x03) {
56 printk("Attempt to register kprobe at an unaligned address\n");
57 ret = -EINVAL;
58 } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) {
59 printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n");
60 ret = -EINVAL;
61 }
62
56 /* insn must be on a special executable page on ppc64 */
63 /* insn must be on a special executable page on ppc64. This is
64 * not explicitly required on ppc32 (right now), but it doesn't hurt */
57 if (!ret) {
58 p->ainsn.insn = get_insn_slot();
59 if (!p->ainsn.insn)
60 ret = -ENOMEM;
61 }
62
63 if (!ret) {
64 memcpy(p->ainsn.insn, p->addr,

--- 30 unchanged lines hidden (view full) ---

95
96static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
97{
98 /* We turn off async exceptions to ensure that the single step will
99 * be for the instruction we have the kprobe on, if we dont its
100 * possible we'd get the single step reported for an exception handler
101 * like Decrementer or External Interrupt */
102 regs->msr &= ~MSR_EE;
65 if (!ret) {
66 p->ainsn.insn = get_insn_slot();
67 if (!p->ainsn.insn)
68 ret = -ENOMEM;
69 }
70
71 if (!ret) {
72 memcpy(p->ainsn.insn, p->addr,

--- 30 unchanged lines hidden (view full) ---

103
104static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
105{
106 /* We turn off async exceptions to ensure that the single step will
107 * be for the instruction we have the kprobe on, if we dont its
108 * possible we'd get the single step reported for an exception handler
109 * like Decrementer or External Interrupt */
110 regs->msr &= ~MSR_EE;
103 regs->msr |= MSR_SE;
111 regs->msr |= MSR_SINGLESTEP;
112#ifdef CONFIG_BOOKE
113 regs->msr &= ~MSR_CE;
114 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
115#endif
104
105 /*
106 * On powerpc we should single step on the original
107 * instruction even if the probed insn is a trap
108 * variant as values in regs could play a part in
109 * if the trap is taken or not
110 */
111 regs->nip = (unsigned long)p->ainsn.insn;

--- 46 unchanged lines hidden (view full) ---

158
159 /* Check we're not actually recursing */
160 if (kprobe_running()) {
161 p = get_kprobe(addr);
162 if (p) {
163 kprobe_opcode_t insn = *p->ainsn.insn;
164 if (kcb->kprobe_status == KPROBE_HIT_SS &&
165 is_trap(insn)) {
116
117 /*
118 * On powerpc we should single step on the original
119 * instruction even if the probed insn is a trap
120 * variant as values in regs could play a part in
121 * if the trap is taken or not
122 */
123 regs->nip = (unsigned long)p->ainsn.insn;

--- 46 unchanged lines hidden (view full) ---

170
171 /* Check we're not actually recursing */
172 if (kprobe_running()) {
173 p = get_kprobe(addr);
174 if (p) {
175 kprobe_opcode_t insn = *p->ainsn.insn;
176 if (kcb->kprobe_status == KPROBE_HIT_SS &&
177 is_trap(insn)) {
166 regs->msr &= ~MSR_SE;
178 /* Turn off 'trace' bits */
179 regs->msr &= ~MSR_SINGLESTEP;
167 regs->msr |= kcb->kprobe_saved_msr;
168 goto no_kprobe;
169 }
170 /* We have reentered the kprobe_handler(), since
171 * another probe was hit while within the handler.
172 * We here save the original kprobes variables and
173 * just single step on the instruction of the new probe
174 * without calling any user handlers.

--- 224 unchanged lines hidden (view full) ---

399 goto out;
400 }
401 reset_current_kprobe();
402out:
403 preempt_enable_no_resched();
404
405 /*
406 * if somebody else is singlestepping across a probe point, msr
180 regs->msr |= kcb->kprobe_saved_msr;
181 goto no_kprobe;
182 }
183 /* We have reentered the kprobe_handler(), since
184 * another probe was hit while within the handler.
185 * We here save the original kprobes variables and
186 * just single step on the instruction of the new probe
187 * without calling any user handlers.

--- 224 unchanged lines hidden (view full) ---

412 goto out;
413 }
414 reset_current_kprobe();
415out:
416 preempt_enable_no_resched();
417
418 /*
419 * if somebody else is singlestepping across a probe point, msr
407 * will have SE set, in which case, continue the remaining processing
420 * will have DE/SE set, in which case, continue the remaining processing
408 * of do_debug, as if this is not a probe hit.
409 */
421 * of do_debug, as if this is not a probe hit.
422 */
410 if (regs->msr & MSR_SE)
423 if (regs->msr & MSR_SINGLESTEP)
411 return 0;
412
413 return 1;
414}
415
416int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
417{
418 struct kprobe *cur = kprobe_running();

--- 6 unchanged lines hidden (view full) ---

425 /*
426 * We are here because the instruction being single
427 * stepped caused a page fault. We reset the current
428 * kprobe and the nip points back to the probe address
429 * and allow the page fault handler to continue as a
430 * normal page fault.
431 */
432 regs->nip = (unsigned long)cur->addr;
424 return 0;
425
426 return 1;
427}
428
429int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
430{
431 struct kprobe *cur = kprobe_running();

--- 6 unchanged lines hidden (view full) ---

438 /*
439 * We are here because the instruction being single
440 * stepped caused a page fault. We reset the current
441 * kprobe and the nip points back to the probe address
442 * and allow the page fault handler to continue as a
443 * normal page fault.
444 */
445 regs->nip = (unsigned long)cur->addr;
433 regs->msr &= ~MSR_SE;
446 regs->msr &= ~MSR_SINGLESTEP; /* Turn off 'trace' bits */
434 regs->msr |= kcb->kprobe_saved_msr;
435 if (kcb->kprobe_status == KPROBE_REENTER)
436 restore_previous_kprobe(kcb);
437 else
438 reset_current_kprobe();
439 preempt_enable_no_resched();
440 break;
441 case KPROBE_HIT_ACTIVE:

--- 128 unchanged lines hidden ---
447 regs->msr |= kcb->kprobe_saved_msr;
448 if (kcb->kprobe_status == KPROBE_REENTER)
449 restore_previous_kprobe(kcb);
450 else
451 reset_current_kprobe();
452 preempt_enable_no_resched();
453 break;
454 case KPROBE_HIT_ACTIVE:

--- 128 unchanged lines hidden ---