27 #include <linux/ptrace.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
34 #include <asm/pgtable.h>
35 #include <asm/sections.h>
36 #include <asm/uaccess.h>
86 brl = (bundle_t *) ((
u64) from & ~0xf);
87 brl->quad0.template = 0x05;
89 brl->quad0.slot1_p0 = ((rel >> 20) & 0x7fffffffff) << 2;
90 brl->quad1.slot1_p1 = (((rel >> 20) & 0x7fffffffff) << 2) >> (64 - 46);
92 brl->quad1.slot2 =
BRL_INST(rel >> 59, rel & 0xfffff);
102 unsigned long kprobe_inst,
105 p->
ainsn.inst_flag = 0;
106 p->
ainsn.target_br_reg = 0;
114 if ((!major_opcode) && (!((kprobe_inst >> 27) & 0x1FF)) ) {
120 if (bundle_encoding[
template][slot] ==
B) {
121 switch (major_opcode) {
124 p->
ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
133 p->
ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
136 }
else if (bundle_encoding[
template][slot] ==
X) {
137 switch (major_opcode) {
140 p->
ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
155 unsigned long kprobe_inst)
160 if (!((bundle_encoding[
template][slot] ==
I) ||
161 (bundle_encoding[
template][slot] ==
M)))
164 if (!((major_opcode == 0xC) || (major_opcode == 0xD) ||
165 (major_opcode == 0xE)))
168 cmp_inst.
l = kprobe_inst;
169 if ((cmp_inst.
f.x2 == 0) || (cmp_inst.
f.x2 == 1)) {
171 if ((cmp_inst.
f.tb == 0) && (cmp_inst.
f.ta == 0)
172 &&(cmp_inst.
f.c == 1))
174 }
else if ((cmp_inst.
f.x2 == 2)||(cmp_inst.
f.x2 == 3)) {
176 if ((cmp_inst.
f.ta == 0) &&(cmp_inst.
f.c == 1))
191 unsigned long kprobe_inst,
196 qp = kprobe_inst & 0x3f;
197 if (is_cmp_ctype_unc_inst(
template, slot, major_opcode, kprobe_inst)) {
198 if (slot == 1 && qp) {
200 "instruction on slot 1 at <0x%lx> "
201 "is not supported\n", addr);
207 else if (bundle_encoding[
template][slot] ==
I) {
208 if (major_opcode == 0) {
213 if (((kprobe_inst >> 33) & 0x7) == 1) {
215 "Kprobes on speculation inst at <0x%lx> not supported\n",
223 if (((kprobe_inst >> 27) & 0x1FF) == 0x30) {
225 "Kprobes on \"mov r1=ip\" at <0x%lx> not supported\n",
231 else if ((major_opcode == 5) && !(kprobe_inst & (0xFUl << 33)) &&
232 (kprobe_inst & (0x1UL << 12))) {
237 if (slot == 1 && qp) {
239 "instruction on slot at <0x%lx> "
240 "is not supported\n", addr);
246 else if (bundle_encoding[
template][slot] ==
B) {
247 if (major_opcode == 7) {
250 "Predict is not supported\n");
253 else if (major_opcode == 2) {
257 int x6=(kprobe_inst >> 27) & 0x3F;
258 if ((x6 == 0x10) || (x6 == 0x11)) {
260 "Indirect Predict is not supported\n");
268 else if (
unlikely(bundle_encoding[
template][slot] ==
F)) {
269 if ((major_opcode == 4 || major_opcode == 5) &&
270 (kprobe_inst & (0x1 << 12))) {
272 if (slot == 1 && qp) {
274 "instruction on slot at <0x%lx> "
275 "is not supported\n", addr);
281 if ((major_opcode == 0 || major_opcode == 1) &&
282 (kprobe_inst & (0x1UL << 33))) {
284 if (slot == 1 && qp) {
286 "instr at <0x%lx> is not supported\n",
302 unsigned long kprobe_inst,
307 bundle_t *bundle = &p->
opcode.bundle;
317 bundle->quad0.slot0 = break_inst;
320 bundle->quad0.slot1_p0 = break_inst;
321 bundle->quad1.slot1_p1 = break_inst >> (64-46);
324 bundle->quad1.slot2 = break_inst;
333 update_kprobe_inst_flag(
template, slot, major_opcode, kprobe_inst, p);
336 static void __kprobes get_kprobe_inst(bundle_t *bundle,
uint slot,
337 unsigned long *kprobe_inst,
uint *major_opcode)
339 unsigned long kprobe_inst_p0, kprobe_inst_p1;
340 unsigned int template;
342 template = bundle->quad0.template;
347 *kprobe_inst = bundle->quad0.slot0;
351 kprobe_inst_p0 = bundle->quad0.slot1_p0;
352 kprobe_inst_p1 = bundle->quad1.slot1_p1;
353 *kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
357 *kprobe_inst = bundle->quad1.slot2;
363 static int __kprobes in_ivt_functions(
unsigned long addr)
365 return (addr >= (
unsigned long)__start_ivt_text
366 && addr < (
unsigned long)__end_ivt_text);
369 static int __kprobes valid_kprobe_addr(
int template,
int slot,
372 if ((slot > 2) || ((bundle_encoding[
template][1] == L) && slot > 1)) {
378 if (in_ivt_functions(addr)) {
380 "IVT functions at 0x%lx\n", addr);
427 unsigned long flags, orig_ret_address = 0;
428 unsigned long trampoline_address =
453 if (orig_ret_address != trampoline_address)
462 regs->
cr_iip = orig_ret_address;
469 if (ri->
rp && ri->
rp->handler)
470 ri->
rp->handler(ri, regs);
475 if (orig_ret_address != trampoline_address)
484 kretprobe_assert(ri, orig_ret_address, trampoline_address);
486 reset_current_kprobe();
491 hlist_del(&ri->
hlist);
512 static int __kprobes __is_ia64_break_inst(bundle_t *bundle,
uint slot)
514 unsigned int major_opcode;
515 unsigned int template = bundle->quad0.template;
516 unsigned long kprobe_inst;
519 if (slot == 1 && bundle_encoding[
template][1] == L)
523 get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode);
530 if (major_opcode || ((kprobe_inst >> 27) & 0x1FF)) {
544 unsigned long bundle_addr)
546 unsigned int template = bundle->quad0.template;
550 __is_ia64_break_inst(bundle, slot))
552 }
while ((++slot) < 3);
554 if (
template >= 0x10 ||
565 unsigned long addr = (
unsigned long)p->
addr & ~0xFULL;
566 unsigned int slot = (
unsigned long)p->
addr & 0xf;
569 if (can_boost(&p->
ainsn.insn[0].bundle, slot, addr)) {
570 set_brl_inst(&p->
ainsn.insn[1].bundle, (bundle_t *)addr + 1);
575 for (; addr < (
unsigned long)p->
addr; addr++) {
584 unsigned long addr = (
unsigned long) p->
addr;
585 unsigned long *kprobe_addr = (
unsigned long *)(addr & ~0xFULL);
586 unsigned long kprobe_inst=0;
587 unsigned int slot = addr & 0xf,
template, major_opcode = 0;
592 template = bundle->quad0.template;
594 if(valid_kprobe_addr(
template, slot, addr))
598 if (slot == 1 && bundle_encoding[
template][1] ==
L)
602 get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode);
604 qp = unsupported_inst(
template, slot, major_opcode, kprobe_inst, addr);
608 p->
ainsn.insn = get_insn_slot();
614 prepare_break_inst(
template, slot, major_opcode, kprobe_inst, p, qp);
623 unsigned long arm_addr;
631 (
unsigned long)p->
ainsn.insn +
634 switch (p->
ainsn.slot) {
636 dest->quad0.slot0 = src->quad0.slot0;
639 dest->quad1.slot1_p1 = src->quad1.slot1_p1;
642 dest->quad1.slot2 = src->quad1.slot2;
650 unsigned long arm_addr;
656 src = &p->
ainsn.insn->bundle;
657 switch (p->
ainsn.slot) {
659 dest->quad0.slot0 = src->quad0.slot0;
662 dest->quad1.slot1_p1 = src->quad1.slot1_p1;
665 dest->quad1.slot2 = src->quad1.slot2;
674 free_insn_slot(p->
ainsn.insn,
689 unsigned long bundle_addr = (
unsigned long) (&p->
ainsn.insn->bundle);
690 unsigned long resume_addr = (
unsigned long)p->
addr & ~0xFULL;
691 unsigned long template;
692 int slot = ((
unsigned long)p->
addr & 0xf);
694 template = p->
ainsn.insn->bundle.quad0.template;
696 if (slot == 1 && bundle_encoding[
template][1] == L)
713 switch (p->
ainsn.target_br_reg) {
715 if ((regs->
b0 == bundle_addr) ||
716 (regs->
b0 == bundle_addr + 0x10)) {
717 regs->
b0 = (regs->
b0 - bundle_addr) +
722 if ((regs->
b6 == bundle_addr) ||
723 (regs->
b6 == bundle_addr + 0x10)) {
724 regs->
b6 = (regs->
b6 - bundle_addr) +
729 if ((regs->
b7 == bundle_addr) ||
730 (regs->
b7 == bundle_addr + 0x10)) {
731 regs->
b7 = (regs->
b7 - bundle_addr) +
741 if (regs->
cr_iip == bundle_addr + 0x10) {
742 regs->
cr_iip = resume_addr + 0x10;
745 if (regs->
cr_iip == bundle_addr) {
746 regs->
cr_iip = resume_addr;
757 unsigned long bundle_addr = (
unsigned long) &p->
ainsn.insn->bundle;
758 unsigned long slot = (
unsigned long)p->
addr & 0xf;
764 regs->
cr_iip = bundle_addr & ~0xFULL;
777 unsigned int slot =
ia64_psr(regs)->ri;
778 unsigned long *kprobe_addr = (
unsigned long *)regs->
cr_iip;
781 memcpy(&bundle, kprobe_addr,
sizeof(bundle_t));
783 return __is_ia64_break_inst(&bundle, slot);
799 kcb = get_kprobe_ctlblk();
802 if (kprobe_running()) {
816 save_previous_kprobe(kcb);
817 set_current_kprobe(p, kcb);
830 }
else if (!is_ia64_break_inst(regs)) {
845 if (!is_ia64_break_inst(regs)) {
861 set_current_kprobe(p, kcb);
873 #if !defined(CONFIG_PREEMPT)
881 reset_current_kprobe();
908 resume_execution(cur, regs);
912 restore_previous_kprobe(kcb);
915 reset_current_kprobe();
924 struct kprobe *cur = kprobe_running();
941 restore_previous_kprobe(kcb);
943 reset_current_kprobe();
947 case KPROBE_HIT_SSDONE:
968 if (ia64_done_with_exception(regs))
986 int ret = NOTIFY_DONE;
997 if (pre_kprobes_handler(args))
1002 if (args->
err == 36)
1003 if (post_kprobes_handler(args->
regs))
1024 unw_get_ip(info, &ip);
1028 unw_get_bsp(info, (
unsigned long*)&lp->
bsp);
1029 unw_get_cfm(info, (
unsigned long*)&lp->
cfm);
1040 return ((
struct fnptr *)entry)->ip;
1060 bytes = (
char *)ia64_rse_skip_regs(pa.
bsp, pa.
cfm & 0x3f)
1072 regs->
cr_iip = addr & ~0xFULL;
1100 bytes = (
char *)ia64_rse_skip_regs(kcb->
bsp, kcb->
cfm & 0x3f)
1111 static struct kprobe trampoline_p = {