ARM64: add __switch_to() support for kprobe 44/183344/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 27 Feb 2017 16:43:24 +0000 (19:43 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 4 Jul 2018 15:47:30 +0000 (18:47 +0300)
Change-Id: I62efddef49d7863e8e5746ef0a5928cc910a4e98
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/kprobe/arch/arm64/swap-asm/swap_kprobes.c

index 150809173114915923a935ce54700ba328e85bc5..d09079af80478e493e84c5f5df291694dea814c7 100644 (file)
@@ -287,6 +287,7 @@ static int reenter_kp_core(struct kp_core *p, struct pt_regs *regs,
 static int post_kp_core_handler(struct kp_core_ctlblk *kcb,
                                struct pt_regs *regs)
 {
+       bool put_curr = false;
        struct kp_core *cur = kp_core_running();
        struct restore_data *restore = current_restore_td();
 
@@ -299,7 +300,7 @@ static int post_kp_core_handler(struct kp_core_ctlblk *kcb,
        if (is_ss_setup(restore)) {
                regs->pc = restore->restore_addr;
                restore->restore_addr = 0;
-               kp_core_put(cur);
+               put_curr = true;
        } else {
                WARN_ON(1);
        }
@@ -312,6 +313,11 @@ static int post_kp_core_handler(struct kp_core_ctlblk *kcb,
                kp_core_running_set(NULL);
        }
 
+       if (put_curr) {
+               switch_to_bits_reset(current_kctx, SWITCH_TO_KP);
+               kp_core_put(cur);
+       }
+
        return 1;
 }
 
@@ -320,10 +326,15 @@ static enum dbg_code kprobe_handler(struct pt_regs *regs, unsigned int esr)
        struct kp_core *p, *cur;
        struct kp_core_ctlblk *kcb;
        unsigned long addr = regs->pc;
-       struct restore_data *restore = current_restore_td();
+       struct kctx *ctx = current_kctx;
+       struct restore_data *restore;
+
+       if (regs->pc == sched_addr)
+               switch_to_bits_set(ctx, SWITCH_TO_KP);
 
        kcb = kp_core_ctlblk();
        cur = kp_core_running();
+       restore = current_restore_td();
 
        rcu_read_lock();
        p = kp_core_by_addr(addr);
@@ -333,8 +344,10 @@ static enum dbg_code kprobe_handler(struct pt_regs *regs, unsigned int esr)
 
        if (p) {
                if (cur && reenter_kp_core(p, regs, kcb)) {
-                       if (!is_ss_setup(restore))
+                       if (!is_ss_setup(restore)) {
+                               switch_to_bits_reset(ctx, SWITCH_TO_KP);
                                kp_core_put(p);
+                       }
 
                        return DBG_HANDLED;
                } else if (!p->ainsn.check_condn ||
@@ -360,8 +373,10 @@ static enum dbg_code kprobe_handler(struct pt_regs *regs, unsigned int esr)
                        nop_singlestep_skip(regs);
                }
 
-               if (!is_ss_setup(restore))
+               if (!is_ss_setup(restore)) {
+                       switch_to_bits_reset(ctx, SWITCH_TO_KP);
                        kp_core_put(p);
+               }
        } else if (*(kprobe_opcode_t *)addr != BRK64_OPCODE_BP) {
                /*
                 * The breakpoint instruction was removed right