remove unused #include <version.h>'s
[safe/jmp/linux-2.6] / arch / ia64 / kernel / kprobes.c
index 4d592ee..f07688d 100644 (file)
@@ -29,9 +29,9 @@
 #include <linux/slab.h>
 #include <linux/preempt.h>
 #include <linux/moduleloader.h>
+#include <linux/kdebug.h>
 
 #include <asm/pgtable.h>
-#include <asm/kdebug.h>
 #include <asm/sections.h>
 #include <asm/uaccess.h>
 
@@ -40,6 +40,8 @@ extern void jprobe_inst_return(void);
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
+struct kretprobe_blackpoint kretprobe_blacklist[] = {{NULL, NULL}};
+
 enum instruction_type {A, I, M, F, B, L, X, u};
 static enum instruction_type bundle_encoding[32][3] = {
   { M, I, I },                         /* 00 */
@@ -76,6 +78,20 @@ static enum instruction_type bundle_encoding[32][3] = {
   { u, u, u },                         /* 1F */
 };
 
+/* Insert a long branch code */
+static void __kprobes set_brl_inst(void *from, void *to)
+{
+       s64 rel = ((s64) to - (s64) from) >> 4;
+       bundle_t *brl;
+       brl = (bundle_t *) ((u64) from & ~0xf);
+       brl->quad0.template = 0x05;     /* [MLX](stop) */
+       brl->quad0.slot0 = NOP_M_INST;  /* nop.m 0x0 */
+       brl->quad0.slot1_p0 = ((rel >> 20) & 0x7fffffffff) << 2;
+       brl->quad1.slot1_p1 = (((rel >> 20) & 0x7fffffffff) << 2) >> (64 - 46);
+       /* brl.cond.sptk.many.clr rel<<4 (qp=0) */
+       brl->quad1.slot2 = BRL_INST(rel >> 59, rel & 0xfffff);
+}
+
 /*
  * In this function we check to see if the instruction
  * is IP relative instruction and update the kprobe
@@ -88,6 +104,7 @@ static void __kprobes update_kprobe_inst_flag(uint template, uint  slot,
 {
        p->ainsn.inst_flag = 0;
        p->ainsn.target_br_reg = 0;
+       p->ainsn.slot = slot;
 
        /* Check for Break instruction
         * Bits 37:40 Major opcode to be zero
@@ -129,8 +146,44 @@ static void __kprobes update_kprobe_inst_flag(uint template, uint  slot,
 
 /*
  * In this function we check to see if the instruction
+ * (qp) cmpx.crel.ctype p1,p2=r2,r3
+ * on which we are inserting kprobe is cmp instruction
+ * with ctype as unc.
+ */
+static uint __kprobes is_cmp_ctype_unc_inst(uint template, uint slot,
+                                           uint major_opcode,
+                                           unsigned long kprobe_inst)
+{
+       cmp_inst_t cmp_inst;
+       uint ctype_unc = 0;
+
+       if (!((bundle_encoding[template][slot] == I) ||
+               (bundle_encoding[template][slot] == M)))
+               goto out;
+
+       if (!((major_opcode == 0xC) || (major_opcode == 0xD) ||
+               (major_opcode == 0xE)))
+               goto out;
+
+       cmp_inst.l = kprobe_inst;
+       if ((cmp_inst.f.x2 == 0) || (cmp_inst.f.x2 == 1)) {
+               /* Integer compare - Register Register (A6 type)*/
+               if ((cmp_inst.f.tb == 0) && (cmp_inst.f.ta == 0)
+                               &&(cmp_inst.f.c == 1))
+                       ctype_unc = 1;
+       } else if ((cmp_inst.f.x2 == 2)||(cmp_inst.f.x2 == 3)) {
+               /* Integer compare - Immediate Register (A8 type)*/
+               if ((cmp_inst.f.ta == 0) &&(cmp_inst.f.c == 1))
+                       ctype_unc = 1;
+       }
+out:
+       return ctype_unc;
+}
+
+/*
+ * In this function we check to see if the instruction
  * on which we are inserting kprobe is supported.
- * Returns 0 if supported
+ * Returns qp value if supported
  * Returns -EINVAL if unsupported
  */
 static int __kprobes unsupported_inst(uint template, uint  slot,
@@ -138,9 +191,21 @@ static int __kprobes unsupported_inst(uint template, uint  slot,
                                      unsigned long kprobe_inst,
                                      unsigned long addr)
 {
-       if (bundle_encoding[template][slot] == I) {
-               switch (major_opcode) {
-                       case 0x0: //I_UNIT_MISC_OPCODE:
+       int qp;
+
+       qp = kprobe_inst & 0x3f;
+       if (is_cmp_ctype_unc_inst(template, slot, major_opcode, kprobe_inst)) {
+               if (slot == 1 && qp)  {
+                       printk(KERN_WARNING "Kprobes on cmp unc "
+                                       "instruction on slot 1 at <0x%lx> "
+                                       "is not supported\n", addr);
+                       return -EINVAL;
+
+               }
+               qp = 0;
+       }
+       else if (bundle_encoding[template][slot] == I) {
+               if (major_opcode == 0) {
                        /*
                         * Check for Integer speculation instruction
                         * - Bit 33-35 to be equal to 0x1
@@ -148,10 +213,9 @@ static int __kprobes unsupported_inst(uint template, uint  slot,
                        if (((kprobe_inst >> 33) & 0x7) == 1) {
                                printk(KERN_WARNING
                                        "Kprobes on speculation inst at <0x%lx> not supported\n",
-                                       addr);
+                                               addr);
                                return -EINVAL;
                        }
-
                        /*
                         * IP relative mov instruction
                         *  - Bit 27-35 to be equal to 0x30
@@ -159,50 +223,74 @@ static int __kprobes unsupported_inst(uint template, uint  slot,
                        if (((kprobe_inst >> 27) & 0x1FF) == 0x30) {
                                printk(KERN_WARNING
                                        "Kprobes on \"mov r1=ip\" at <0x%lx> not supported\n",
-                                       addr);
+                                               addr);
                                return -EINVAL;
 
                        }
                }
+               else if ((major_opcode == 5) && !(kprobe_inst & (0xFUl << 33)) &&
+                               (kprobe_inst & (0x1UL << 12))) {
+                       /* test bit instructions, tbit,tnat,tf
+                        * bit 33-36 to be equal to 0
+                        * bit 12 to be equal to 1
+                        */
+                       if (slot == 1 && qp) {
+                               printk(KERN_WARNING "Kprobes on test bit "
+                                               "instruction on slot at <0x%lx> "
+                                               "is not supported\n", addr);
+                               return -EINVAL;
+                       }
+                       qp = 0;
+               }
        }
-       return 0;
-}
-
-
-/*
- * In this function we check to see if the instruction
- * (qp) cmpx.crel.ctype p1,p2=r2,r3
- * on which we are inserting kprobe is cmp instruction
- * with ctype as unc.
- */
-static uint __kprobes is_cmp_ctype_unc_inst(uint template, uint slot,
-                                           uint major_opcode,
-                                           unsigned long kprobe_inst)
-{
-       cmp_inst_t cmp_inst;
-       uint ctype_unc = 0;
-
-       if (!((bundle_encoding[template][slot] == I) ||
-               (bundle_encoding[template][slot] == M)))
-               goto out;
-
-       if (!((major_opcode == 0xC) || (major_opcode == 0xD) ||
-               (major_opcode == 0xE)))
-               goto out;
+       else if (bundle_encoding[template][slot] == B) {
+               if (major_opcode == 7) {
+                       /* IP-Relative Predict major code is 7 */
+                       printk(KERN_WARNING "Kprobes on IP-Relative"
+                                       "Predict is not supported\n");
+                       return -EINVAL;
+               }
+               else if (major_opcode == 2) {
+                       /* Indirect Predict, major code is 2
+                        * bit 27-32 to be equal to 10 or 11
+                        */
+                       int x6=(kprobe_inst >> 27) & 0x3F;
+                       if ((x6 == 0x10) || (x6 == 0x11)) {
+                               printk(KERN_WARNING "Kprobes on "
+                                       "Indirect Predict is not supported\n");
+                               return -EINVAL;
+                       }
+               }
+       }
+       /* kernel does not use float instruction, here for safety kprobe
+        * will judge whether it is fcmp/flass/float approximation instruction
+        */
+       else if (unlikely(bundle_encoding[template][slot] == F)) {
+               if ((major_opcode == 4 || major_opcode == 5) &&
+                               (kprobe_inst  & (0x1 << 12))) {
+                       /* fcmp/fclass unc instruction */
+                       if (slot == 1 && qp) {
+                               printk(KERN_WARNING "Kprobes on fcmp/fclass "
+                                       "instruction on slot at <0x%lx> "
+                                       "is not supported\n", addr);
+                               return -EINVAL;
 
-       cmp_inst.l = kprobe_inst;
-       if ((cmp_inst.f.x2 == 0) || (cmp_inst.f.x2 == 1)) {
-               /* Integere compare - Register Register (A6 type)*/
-               if ((cmp_inst.f.tb == 0) && (cmp_inst.f.ta == 0)
-                               &&(cmp_inst.f.c == 1))
-                       ctype_unc = 1;
-       } else if ((cmp_inst.f.x2 == 2)||(cmp_inst.f.x2 == 3)) {
-               /* Integere compare - Immediate Register (A8 type)*/
-               if ((cmp_inst.f.ta == 0) &&(cmp_inst.f.c == 1))
-                       ctype_unc = 1;
+                       }
+                       qp = 0;
+               }
+               if ((major_opcode == 0 || major_opcode == 1) &&
+                       (kprobe_inst & (0x1UL << 33))) {
+                       /* float Approximation instruction */
+                       if (slot == 1 && qp) {
+                               printk(KERN_WARNING "Kprobes on float Approx "
+                                       "instr at <0x%lx> is not supported\n",
+                                               addr);
+                               return -EINVAL;
+                       }
+                       qp = 0;
+               }
        }
-out:
-       return ctype_unc;
+       return qp;
 }
 
 /*
@@ -212,20 +300,17 @@ out:
 static void __kprobes prepare_break_inst(uint template, uint  slot,
                                         uint major_opcode,
                                         unsigned long kprobe_inst,
-                                        struct kprobe *p)
+                                        struct kprobe *p,
+                                        int qp)
 {
        unsigned long break_inst = BREAK_INST;
        bundle_t *bundle = &p->opcode.bundle;
 
        /*
         * Copy the original kprobe_inst qualifying predicate(qp)
-        * to the break instruction iff !is_cmp_ctype_unc_inst
-        * because for cmp instruction with ctype equal to unc,
-        * which is a special instruction always needs to be
-        * executed regradless of qp
+        * to the break instruction
         */
-       if (!is_cmp_ctype_unc_inst(template, slot, major_opcode, kprobe_inst))
-               break_inst |= (0x3f & kprobe_inst);
+       break_inst |= qp;
 
        switch (slot) {
          case 0:
@@ -296,25 +381,24 @@ static int __kprobes valid_kprobe_addr(int template, int slot,
                return -EINVAL;
        }
 
-       if (slot == 1 && bundle_encoding[template][1] != L) {
-               printk(KERN_WARNING "Inserting kprobes on slot #1 "
-                      "is not supported\n");
-               return -EINVAL;
-       }
-
        return 0;
 }
 
 static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
-       kcb->prev_kprobe.kp = kprobe_running();
-       kcb->prev_kprobe.status = kcb->kprobe_status;
+       unsigned int i;
+       i = atomic_add_return(1, &kcb->prev_kprobe_index);
+       kcb->prev_kprobe[i-1].kp = kprobe_running();
+       kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
 }
 
 static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
-       __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
-       kcb->kprobe_status = kcb->prev_kprobe.status;
+       unsigned int i;
+       i = atomic_read(&kcb->prev_kprobe_index);
+       __get_cpu_var(current_kprobe) = kcb->prev_kprobe[i-1].kp;
+       kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
+       atomic_sub(1, &kcb->prev_kprobe_index);
 }
 
 static void __kprobes set_current_kprobe(struct kprobe *p,
@@ -345,8 +429,7 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
                ((struct fnptr *)kretprobe_trampoline)->ip;
 
        INIT_HLIST_HEAD(&empty_rp);
-       spin_lock_irqsave(&kretprobe_lock, flags);
-       head = kretprobe_inst_table_head(current);
+       kretprobe_hash_lock(current, &head, &flags);
 
        /*
         * It is possible to have multiple instances associated with a given
@@ -366,6 +449,23 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
                        /* another task is sharing our hash bucket */
                        continue;
 
+               orig_ret_address = (unsigned long)ri->ret_addr;
+               if (orig_ret_address != trampoline_address)
+                       /*
+                        * This is the real return address. Any other
+                        * instances associated with this task are for
+                        * other calls deeper on the call stack
+                        */
+                       break;
+       }
+
+       regs->cr_iip = orig_ret_address;
+
+       hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
+               if (ri->task != current)
+                       /* another task is sharing our hash bucket */
+                       continue;
+
                if (ri->rp && ri->rp->handler)
                        ri->rp->handler(ri, regs);
 
@@ -381,11 +481,10 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
                        break;
        }
 
-       BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
-       regs->cr_iip = orig_ret_address;
+       kretprobe_assert(ri, orig_ret_address, trampoline_address);
 
        reset_current_kprobe();
-       spin_unlock_irqrestore(&kretprobe_lock, flags);
+       kretprobe_hash_unlock(current, &flags);
        preempt_enable_no_resched();
 
        hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
@@ -400,23 +499,83 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
        return 1;
 }
 
-/* Called with kretprobe_lock held */
-void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
+void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
                                      struct pt_regs *regs)
 {
-       struct kretprobe_instance *ri;
+       ri->ret_addr = (kprobe_opcode_t *)regs->b0;
 
-       if ((ri = get_free_rp_inst(rp)) != NULL) {
-               ri->rp = rp;
-               ri->task = current;
-               ri->ret_addr = (kprobe_opcode_t *)regs->b0;
+       /* Replace the return addr with trampoline addr */
+       regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
+}
 
-               /* Replace the return addr with trampoline addr */
-               regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
+/* Check the instruction in the slot is break */
+static int __kprobes __is_ia64_break_inst(bundle_t *bundle, uint slot)
+{
+       unsigned int major_opcode;
+       unsigned int template = bundle->quad0.template;
+       unsigned long kprobe_inst;
 
-               add_rp_inst(ri);
-       } else {
-               rp->nmissed++;
+       /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */
+       if (slot == 1 && bundle_encoding[template][1] == L)
+               slot++;
+
+       /* Get Kprobe probe instruction at given slot*/
+       get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode);
+
+       /* For break instruction,
+        * Bits 37:40 Major opcode to be zero
+        * Bits 27:32 X6 to be zero
+        * Bits 32:35 X3 to be zero
+        */
+       if (major_opcode || ((kprobe_inst >> 27) & 0x1FF)) {
+               /* Not a break instruction */
+               return 0;
+       }
+
+       /* Is a break instruction */
+       return 1;
+}
+
+/*
+ * In this function, we check whether the target bundle modifies IP or
+ * it triggers an exception. If so, it cannot be boostable.
+ */
+static int __kprobes can_boost(bundle_t *bundle, uint slot,
+                              unsigned long bundle_addr)
+{
+       unsigned int template = bundle->quad0.template;
+
+       do {
+               if (search_exception_tables(bundle_addr + slot) ||
+                   __is_ia64_break_inst(bundle, slot))
+                       return 0;       /* exception may occur in this bundle*/
+       } while ((++slot) < 3);
+       template &= 0x1e;
+       if (template >= 0x10 /* including B unit */ ||
+           template == 0x04 /* including X unit */ ||
+           template == 0x06) /* undefined */
+               return 0;
+
+       return 1;
+}
+
+/* Prepare long jump bundle and disables other boosters if need */
+static void __kprobes prepare_booster(struct kprobe *p)
+{
+       unsigned long addr = (unsigned long)p->addr & ~0xFULL;
+       unsigned int slot = (unsigned long)p->addr & 0xf;
+       struct kprobe *other_kp;
+
+       if (can_boost(&p->ainsn.insn[0].bundle, slot, addr)) {
+               set_brl_inst(&p->ainsn.insn[1].bundle, (bundle_t *)addr + 1);
+               p->ainsn.inst_flag |= INST_FLAG_BOOSTABLE;
+       }
+
+       /* disables boosters in previous slots */
+       for (; addr < (unsigned long)p->addr; addr++) {
+               other_kp = get_kprobe((void *)addr);
+               if (other_kp)
+                       other_kp->ainsn.inst_flag &= ~INST_FLAG_BOOSTABLE;
        }
 }
 
@@ -427,6 +586,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
        unsigned long kprobe_inst=0;
        unsigned int slot = addr & 0xf, template, major_opcode = 0;
        bundle_t *bundle;
+       int qp;
 
        bundle = &((kprobe_opcode_t *)kprobe_addr)->bundle;
        template = bundle->quad0.template;
@@ -441,9 +601,9 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
        /* Get kprobe_inst and major_opcode from the bundle */
        get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode);
 
-       if (unsupported_inst(template, slot, major_opcode, kprobe_inst, addr))
-                       return -EINVAL;
-
+       qp = unsupported_inst(template, slot, major_opcode, kprobe_inst, addr);
+       if (qp < 0)
+               return -EINVAL;
 
        p->ainsn.insn = get_insn_slot();
        if (!p->ainsn.insn)
@@ -451,43 +611,73 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
        memcpy(&p->opcode, kprobe_addr, sizeof(kprobe_opcode_t));
        memcpy(p->ainsn.insn, kprobe_addr, sizeof(kprobe_opcode_t));
 
-       prepare_break_inst(template, slot, major_opcode, kprobe_inst, p);
+       prepare_break_inst(template, slot, major_opcode, kprobe_inst, p, qp);
+
+       prepare_booster(p);
 
        return 0;
 }
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
-       unsigned long addr = (unsigned long)p->addr;
-       unsigned long arm_addr = addr & ~0xFULL;
+       unsigned long arm_addr;
+       bundle_t *src, *dest;
+
+       arm_addr = ((unsigned long)p->addr) & ~0xFUL;
+       dest = &((kprobe_opcode_t *)arm_addr)->bundle;
+       src = &p->opcode.bundle;
 
        flush_icache_range((unsigned long)p->ainsn.insn,
-                       (unsigned long)p->ainsn.insn + sizeof(kprobe_opcode_t));
-       memcpy((char *)arm_addr, &p->opcode, sizeof(kprobe_opcode_t));
+                          (unsigned long)p->ainsn.insn +
+                          sizeof(kprobe_opcode_t) * MAX_INSN_SIZE);
+
+       switch (p->ainsn.slot) {
+               case 0:
+                       dest->quad0.slot0 = src->quad0.slot0;
+                       break;
+               case 1:
+                       dest->quad1.slot1_p1 = src->quad1.slot1_p1;
+                       break;
+               case 2:
+                       dest->quad1.slot2 = src->quad1.slot2;
+                       break;
+       }
        flush_icache_range(arm_addr, arm_addr + sizeof(kprobe_opcode_t));
 }
 
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
-       unsigned long addr = (unsigned long)p->addr;
-       unsigned long arm_addr = addr & ~0xFULL;
+       unsigned long arm_addr;
+       bundle_t *src, *dest;
 
+       arm_addr = ((unsigned long)p->addr) & ~0xFUL;
+       dest = &((kprobe_opcode_t *)arm_addr)->bundle;
        /* p->ainsn.insn contains the original unaltered kprobe_opcode_t */
-       memcpy((char *) arm_addr, (char *) p->ainsn.insn,
-                                        sizeof(kprobe_opcode_t));
+       src = &p->ainsn.insn->bundle;
+       switch (p->ainsn.slot) {
+               case 0:
+                       dest->quad0.slot0 = src->quad0.slot0;
+                       break;
+               case 1:
+                       dest->quad1.slot1_p1 = src->quad1.slot1_p1;
+                       break;
+               case 2:
+                       dest->quad1.slot2 = src->quad1.slot2;
+                       break;
+       }
        flush_icache_range(arm_addr, arm_addr + sizeof(kprobe_opcode_t));
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
        mutex_lock(&kprobe_mutex);
-       free_insn_slot(p->ainsn.insn, 0);
+       free_insn_slot(p->ainsn.insn, p->ainsn.inst_flag & INST_FLAG_BOOSTABLE);
        mutex_unlock(&kprobe_mutex);
 }
 /*
  * We are resuming execution after a single step fault, so the pt_regs
  * structure reflects the register state after we executed the instruction
- * located in the kprobe (p->ainsn.insn.bundle).  We still need to adjust
+ * located in the kprobe (p->ainsn.insn->bundle).  We still need to adjust
  * the ip to point back to the original stack address. To set the IP address
  * to original stack address, handle the case where we need to fixup the
  * relative IP address and/or fixup branch register.
@@ -504,7 +694,7 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
        if (slot == 1 && bundle_encoding[template][1] == L)
                slot = 2;
 
-       if (p->ainsn.inst_flag) {
+       if (p->ainsn.inst_flag & ~INST_FLAG_BOOSTABLE) {
 
                if (p->ainsn.inst_flag & INST_FLAG_FIX_RELATIVE_IP_ADDR) {
                        /* Fix relative IP address */
@@ -583,33 +773,12 @@ static void __kprobes prepare_ss(struct kprobe *p, struct pt_regs *regs)
 static int __kprobes is_ia64_break_inst(struct pt_regs *regs)
 {
        unsigned int slot = ia64_psr(regs)->ri;
-       unsigned int template, major_opcode;
-       unsigned long kprobe_inst;
        unsigned long *kprobe_addr = (unsigned long *)regs->cr_iip;
        bundle_t bundle;
 
        memcpy(&bundle, kprobe_addr, sizeof(bundle_t));
-       template = bundle.quad0.template;
-
-       /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */
-       if (slot == 1 && bundle_encoding[template][1] == L)
-               slot++;
-
-       /* Get Kprobe probe instruction at given slot*/
-       get_kprobe_inst(&bundle, slot, &kprobe_inst, &major_opcode);
-
-       /* For break instruction,
-        * Bits 37:40 Major opcode to be zero
-        * Bits 27:32 X6 to be zero
-        * Bits 32:35 X3 to be zero
-        */
-       if (major_opcode || ((kprobe_inst >> 27) & 0x1FF) ) {
-               /* Not a break instruction */
-               return 0;
-       }
 
-       /* Is a break instruction */
-       return 1;
+       return __is_ia64_break_inst(&bundle, slot);
 }
 
 static int __kprobes pre_kprobes_handler(struct die_args *args)
@@ -699,6 +868,19 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
                return 1;
 
 ss_probe:
+#if !defined(CONFIG_PREEMPT) || defined(CONFIG_PM)
+       if (p->ainsn.inst_flag == INST_FLAG_BOOSTABLE && !p->post_handler) {
+               /* Boost up -- we can execute copied instructions directly */
+               ia64_psr(regs)->ri = p->ainsn.slot;
+               regs->cr_iip = (unsigned long)&p->ainsn.insn->bundle & ~0xFULL;
+               /* turn single stepping off */
+               ia64_psr(regs)->ss = 0;
+
+               reset_current_kprobe();
+               preempt_enable_no_resched();
+               return 1;
+       }
+#endif
        prepare_ss(p, regs);
        kcb->kprobe_status = KPROBE_HIT_SS;
        return 1;
@@ -735,7 +917,7 @@ out:
        return 1;
 }
 
-static int __kprobes kprobes_fault_handler(struct pt_regs *regs, int trapnr)
+int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
 {
        struct kprobe *cur = kprobe_running();
        struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -807,7 +989,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
        switch(val) {
        case DIE_BREAK:
                /* err is break number from ia64_bad_break() */
-               if (args->err == 0x80200 || args->err == 0x80300 || args->err == 0)
+               if ((args->err >> 12) == (__IA64_BREAK_KPROBE >> 12)
+                       || args->err == __IA64_BREAK_JPROBE
+                       || args->err == 0)
                        if (pre_kprobes_handler(args))
                                ret = NOTIFY_STOP;
                break;
@@ -817,13 +1001,6 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
                        if (post_kprobes_handler(args->regs))
                                ret = NOTIFY_STOP;
                break;
-       case DIE_PAGE_FAULT:
-               /* kprobe_running() needs smp_processor_id() */
-               preempt_disable();
-               if (kprobe_running() &&
-                       kprobes_fault_handler(args->regs, args->trapnr))
-                       ret = NOTIFY_STOP;
-               preempt_enable();
        default:
                break;
        }
@@ -851,15 +1028,20 @@ static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
                        return;
                }
        } while (unw_unwind(info) >= 0);
-       lp->bsp = 0;
+       lp->bsp = NULL;
        lp->cfm = 0;
        return;
 }
 
+unsigned long arch_deref_entry_point(void *entry)
+{
+       return ((struct fnptr *)entry)->ip;
+}
+
 int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
 {
        struct jprobe *jp = container_of(p, struct jprobe, kp);
-       unsigned long addr = ((struct fnptr *)(jp->entry))->ip;
+       unsigned long addr = arch_deref_entry_point(jp->entry);
        struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
        struct param_bsp_cfm pa;
        int bytes;
@@ -867,7 +1049,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
        /*
         * Callee owns the argument space and could overwrite it, eg
         * tail call optimization. So to be absolutely safe
-        * we save the argument space before transfering the control
+        * we save the argument space before transferring the control
         * to instrumented jprobe function which runs in
         * the process context
         */
@@ -898,6 +1080,11 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
        return 1;
 }
 
+/* ia64 does not need this */
+void __kprobes jprobe_return(void)
+{
+}
+
 int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 {
        struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -929,3 +1116,12 @@ int __init arch_init_kprobes(void)
                (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
        return register_kprobe(&trampoline_p);
 }
+
+int __kprobes arch_trampoline_kprobe(struct kprobe *p)
+{
+       if (p->addr ==
+               (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
+               return 1;
+
+       return 0;
+}