drm/edid/firmware: Add built-in edid/1280x720.bin firmware
[platform/kernel/linux-starfive.git] / kernel / kprobes.c
index 3050631..00e177d 100644 (file)
@@ -458,7 +458,7 @@ static inline int kprobe_optready(struct kprobe *p)
 }
 
 /* Return true if the kprobe is disarmed. Note: p must be on hash list */
-static inline bool kprobe_disarmed(struct kprobe *p)
+bool kprobe_disarmed(struct kprobe *p)
 {
        struct optimized_kprobe *op;
 
@@ -555,17 +555,15 @@ static void do_unoptimize_kprobes(void)
        /* See comment in do_optimize_kprobes() */
        lockdep_assert_cpus_held();
 
-       /* Unoptimization must be done anytime */
-       if (list_empty(&unoptimizing_list))
-               return;
+       if (!list_empty(&unoptimizing_list))
+               arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
 
-       arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
-       /* Loop on 'freeing_list' for disarming */
+       /* Loop on 'freeing_list' for disarming and removing from kprobe hash list */
        list_for_each_entry_safe(op, tmp, &freeing_list, list) {
                /* Switching from detour code to origin */
                op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
-               /* Disarm probes if marked disabled */
-               if (kprobe_disabled(&op->kp))
+               /* Disarm probes if marked disabled and not gone */
+               if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp))
                        arch_disarm_kprobe(&op->kp);
                if (kprobe_unused(&op->kp)) {
                        /*
@@ -662,7 +660,7 @@ void wait_for_kprobe_optimizer(void)
        mutex_unlock(&kprobe_mutex);
 }
 
-static bool optprobe_queued_unopt(struct optimized_kprobe *op)
+bool optprobe_queued_unopt(struct optimized_kprobe *op)
 {
        struct optimized_kprobe *_op;
 
@@ -797,14 +795,13 @@ static void kill_optimized_kprobe(struct kprobe *p)
        op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
 
        if (kprobe_unused(p)) {
-               /* Enqueue if it is unused */
-               list_add(&op->list, &freeing_list);
                /*
-                * Remove unused probes from the hash list. After waiting
-                * for synchronization, this probe is reclaimed.
-                * (reclaiming is done by do_free_cleaned_kprobes().)
+                * Unused kprobe is on unoptimizing or freeing list. We move it
+                * to freeing_list and let the kprobe_optimizer() remove it from
+                * the kprobe hash list and free it.
                 */
-               hlist_del_rcu(&op->kp.hlist);
+               if (optprobe_queued_unopt(op))
+                       list_move(&op->list, &freeing_list);
        }
 
        /* Don't touch the code, because it is already freed. */
@@ -2213,13 +2210,9 @@ int register_kretprobe(struct kretprobe *rp)
        rp->kp.post_handler = NULL;
 
        /* Pre-allocate memory for max kretprobe instances */
-       if (rp->maxactive <= 0) {
-#ifdef CONFIG_PREEMPTION
+       if (rp->maxactive <= 0)
                rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus());
-#else
-               rp->maxactive = num_possible_cpus();
-#endif
-       }
+
 #ifdef CONFIG_KRETPROBE_ON_RETHOOK
        rp->rh = rethook_alloc((void *)rp, kretprobe_rethook_handler);
        if (!rp->rh)
@@ -2364,6 +2357,14 @@ static void kill_kprobe(struct kprobe *p)
 
        lockdep_assert_held(&kprobe_mutex);
 
+       /*
+        * The module is going away. We should disarm the kprobe which
+        * is using ftrace, because ftrace framework is still available at
+        * 'MODULE_STATE_GOING' notification.
+        */
+       if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
+               disarm_kprobe_ftrace(p);
+
        p->flags |= KPROBE_FLAG_GONE;
        if (kprobe_aggrprobe(p)) {
                /*
@@ -2380,14 +2381,6 @@ static void kill_kprobe(struct kprobe *p)
         * the original probed function (which will be freed soon) any more.
         */
        arch_remove_kprobe(p);
-
-       /*
-        * The module is going away. We should disarm the kprobe which
-        * is using ftrace, because ftrace framework is still available at
-        * 'MODULE_STATE_GOING' notification.
-        */
-       if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
-               disarm_kprobe_ftrace(p);
 }
 
 /* Disable one kprobe */