Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-drm-fsl-dcu.git] / arch / s390 / kernel / kprobes.c
index ca28fb0b3790f7c966e338f546bed0b18ac192fc..a466bab6677e15f506da1fb3d8168d5792170167 100644 (file)
@@ -20,7 +20,6 @@
  * s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com>
  */
 
-#include <linux/config.h>
 #include <linux/kprobes.h>
 #include <linux/ptrace.h>
 #include <linux/preempt.h>
@@ -156,15 +155,34 @@ void __kprobes get_instruction_type(struct arch_specific_insn *ainsn)
 static int __kprobes swap_instruction(void *aref)
 {
        struct ins_replace_args *args = aref;
+       u32 *addr;
+       u32 instr;
        int err = -EFAULT;
 
+       /*
+        * Text segment is read-only, hence we use stura to bypass dynamic
+        * address translation to exchange the instruction. Since stura
+        * always operates on four bytes, but we only want to exchange two
+        * bytes do some calculations to get things right. In addition we
+        * shall not cross any page boundaries (vmalloc area!) when writing
+        * the new instruction.
+        */
+       addr = (u32 *)ALIGN((unsigned long)args->ptr, 4);
+       if ((unsigned long)args->ptr & 2)
+               instr = ((*addr) & 0xffff0000) | args->new;
+       else
+               instr = ((*addr) & 0x0000ffff) | args->new << 16;
+
        asm volatile(
-               "0: mvc  0(2,%2),0(%3)\n"
-               "1: la   %0,0\n"
+               "       lra     %1,0(%1)\n"
+               "0:     stura   %2,%1\n"
+               "1:     la      %0,0\n"
                "2:\n"
                EX_TABLE(0b,2b)
-               : "+d" (err), "=m" (*args->ptr)
-               : "a" (args->ptr), "a" (&args->new), "m" (args->new));
+               : "+d" (err)
+               : "a" (addr), "d" (instr)
+               : "memory", "cc");
+
        return err;
 }
 
@@ -201,7 +219,7 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p)
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
        mutex_lock(&kprobe_mutex);
-       free_insn_slot(p->ainsn.insn);
+       free_insn_slot(p->ainsn.insn, 0);
        mutex_unlock(&kprobe_mutex);
 }
 
@@ -357,7 +375,7 @@ no_kprobe:
  *     - When the probed function returns, this probe
  *             causes the handlers to fire
  */
-void __kprobes kretprobe_trampoline_holder(void)
+void kretprobe_trampoline_holder(void)
 {
        asm volatile(".global kretprobe_trampoline\n"
                     "kretprobe_trampoline: bcr 0,0\n");
@@ -366,14 +384,16 @@ void __kprobes kretprobe_trampoline_holder(void)
 /*
  * Called when the probe at kretprobe trampoline is hit
  */
-int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
+static int __kprobes trampoline_probe_handler(struct kprobe *p,
+                                             struct pt_regs *regs)
 {
        struct kretprobe_instance *ri = NULL;
-       struct hlist_head *head;
+       struct hlist_head *head, empty_rp;
        struct hlist_node *node, *tmp;
        unsigned long flags, orig_ret_address = 0;
        unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
 
+       INIT_HLIST_HEAD(&empty_rp);
        spin_lock_irqsave(&kretprobe_lock, flags);
        head = kretprobe_inst_table_head(current);
 
@@ -399,7 +419,7 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
                        ri->rp->handler(ri, regs);
 
                orig_ret_address = (unsigned long)ri->ret_addr;
-               recycle_rp_inst(ri);
+               recycle_rp_inst(ri, &empty_rp);
 
                if (orig_ret_address != trampoline_address) {
                        /*
@@ -417,6 +437,10 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
        spin_unlock_irqrestore(&kretprobe_lock, flags);
        preempt_enable_no_resched();
 
+       hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
+               hlist_del(&ri->hlist);
+               kfree(ri);
+       }
        /*
         * By returning a non-zero value, we are telling
         * kprobe_handler() that we don't want the post_handler