kprobes.c (d254117099d711f215e62427f55dfb8ebd5ad011) kprobes.c (201517a7f3ec497fff545a7659c6c876f89f9054)
1/*
2 * Kernel Probes (KProbes)
3 * kernel/kprobes.c
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 305 unchanged lines hidden (view full) ---

314 head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)];
315 hlist_for_each_entry_rcu(p, node, head, hlist) {
316 if (p->addr == addr)
317 return p;
318 }
319 return NULL;
320}
321
1/*
2 * Kernel Probes (KProbes)
3 * kernel/kprobes.c
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 305 unchanged lines hidden (view full) ---

314 head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)];
315 hlist_for_each_entry_rcu(p, node, head, hlist) {
316 if (p->addr == addr)
317 return p;
318 }
319 return NULL;
320}
321
322/* Arm a kprobe with text_mutex */
323static void __kprobes arm_kprobe(struct kprobe *kp)
324{
325 mutex_lock(&text_mutex);
326 arch_arm_kprobe(kp);
327 mutex_unlock(&text_mutex);
328}
329
330/* Disarm a kprobe with text_mutex */
331static void __kprobes disarm_kprobe(struct kprobe *kp)
332{
333 mutex_lock(&text_mutex);
334 arch_disarm_kprobe(kp);
335 mutex_unlock(&text_mutex);
336}
337
322/*
323 * Aggregate handlers for multiple kprobes support - these handlers
324 * take care of invoking the individual kprobe handlers on p->list
325 */
326static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs)
327{
328 struct kprobe *kp;
329

--- 203 unchanged lines hidden (view full) ---

533 list_add_rcu(&p->list, &ap->list);
534 if (p->post_handler && !ap->post_handler)
535 ap->post_handler = aggr_post_handler;
536
537 if (kprobe_disabled(ap) && !kprobe_disabled(p)) {
538 ap->flags &= ~KPROBE_FLAG_DISABLED;
539 if (!kprobes_all_disarmed)
540 /* Arm the breakpoint again. */
338/*
339 * Aggregate handlers for multiple kprobes support - these handlers
340 * take care of invoking the individual kprobe handlers on p->list
341 */
342static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs)
343{
344 struct kprobe *kp;
345

--- 203 unchanged lines hidden (view full) ---

549 list_add_rcu(&p->list, &ap->list);
550 if (p->post_handler && !ap->post_handler)
551 ap->post_handler = aggr_post_handler;
552
553 if (kprobe_disabled(ap) && !kprobe_disabled(p)) {
554 ap->flags &= ~KPROBE_FLAG_DISABLED;
555 if (!kprobes_all_disarmed)
556 /* Arm the breakpoint again. */
541 arch_arm_kprobe(ap);
557 arm_kprobe(ap);
542 }
543 return 0;
544}
545
546/*
547 * Fill in the required fields of the "manager kprobe". Replace the
548 * earlier kprobe in the hlist with the manager kprobe
549 */

--- 234 unchanged lines hidden (view full) ---

784 if (old_p == p ||
785 (old_p->pre_handler == aggr_pre_handler &&
786 list_is_singular(&old_p->list))) {
787 /*
788 * Only probe on the hash list. Disarm only if kprobes are
789 * enabled and not gone - otherwise, the breakpoint would
790 * already have been removed. We save on flushing icache.
791 */
558 }
559 return 0;
560}
561
562/*
563 * Fill in the required fields of the "manager kprobe". Replace the
564 * earlier kprobe in the hlist with the manager kprobe
565 */

--- 234 unchanged lines hidden (view full) ---

800 if (old_p == p ||
801 (old_p->pre_handler == aggr_pre_handler &&
802 list_is_singular(&old_p->list))) {
803 /*
804 * Only probe on the hash list. Disarm only if kprobes are
805 * enabled and not gone - otherwise, the breakpoint would
806 * already have been removed. We save on flushing icache.
807 */
792 if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) {
793 mutex_lock(&text_mutex);
794 arch_disarm_kprobe(p);
795 mutex_unlock(&text_mutex);
796 }
808 if (!kprobes_all_disarmed && !kprobe_disabled(old_p))
809 disarm_kprobe(p);
797 hlist_del_rcu(&old_p->hlist);
798 } else {
799 if (p->break_handler && !kprobe_gone(p))
800 old_p->break_handler = NULL;
801 if (p->post_handler && !kprobe_gone(p)) {
802 list_for_each_entry_rcu(list_p, &old_p->list, list) {
803 if ((list_p != p) && (list_p->post_handler))
804 goto noclean;
805 }
806 old_p->post_handler = NULL;
807 }
808noclean:
809 list_del_rcu(&p->list);
810 if (!kprobe_disabled(old_p)) {
811 try_to_disable_aggr_kprobe(old_p);
812 if (!kprobes_all_disarmed && kprobe_disabled(old_p))
810 hlist_del_rcu(&old_p->hlist);
811 } else {
812 if (p->break_handler && !kprobe_gone(p))
813 old_p->break_handler = NULL;
814 if (p->post_handler && !kprobe_gone(p)) {
815 list_for_each_entry_rcu(list_p, &old_p->list, list) {
816 if ((list_p != p) && (list_p->post_handler))
817 goto noclean;
818 }
819 old_p->post_handler = NULL;
820 }
821noclean:
822 list_del_rcu(&p->list);
823 if (!kprobe_disabled(old_p)) {
824 try_to_disable_aggr_kprobe(old_p);
825 if (!kprobes_all_disarmed && kprobe_disabled(old_p))
813 arch_disarm_kprobe(old_p);
826 disarm_kprobe(old_p);
814 }
815 }
816 return 0;
817}
818
819static void __kprobes __unregister_kprobe_bottom(struct kprobe *p)
820{
821 struct kprobe *old_p;

--- 537 unchanged lines hidden (view full) ---

1359 goto out;
1360
1361 kp->flags |= KPROBE_FLAG_DISABLED;
1362 if (p != kp)
1363 /* When kp != p, p is always enabled. */
1364 try_to_disable_aggr_kprobe(p);
1365
1366 if (!kprobes_all_disarmed && kprobe_disabled(p))
827 }
828 }
829 return 0;
830}
831
832static void __kprobes __unregister_kprobe_bottom(struct kprobe *p)
833{
834 struct kprobe *old_p;

--- 537 unchanged lines hidden (view full) ---

1372 goto out;
1373
1374 kp->flags |= KPROBE_FLAG_DISABLED;
1375 if (p != kp)
1376 /* When kp != p, p is always enabled. */
1377 try_to_disable_aggr_kprobe(p);
1378
1379 if (!kprobes_all_disarmed && kprobe_disabled(p))
1367 arch_disarm_kprobe(p);
1380 disarm_kprobe(p);
1368out:
1369 mutex_unlock(&kprobe_mutex);
1370 return ret;
1371}
1372EXPORT_SYMBOL_GPL(disable_kprobe);
1373
1374/* Enable one kprobe */
1375int __kprobes enable_kprobe(struct kprobe *kp)

--- 12 unchanged lines hidden (view full) ---

1388
1389 if (kprobe_gone(kp)) {
1390 /* This kprobe has gone, we couldn't enable it. */
1391 ret = -EINVAL;
1392 goto out;
1393 }
1394
1395 if (!kprobes_all_disarmed && kprobe_disabled(p))
1381out:
1382 mutex_unlock(&kprobe_mutex);
1383 return ret;
1384}
1385EXPORT_SYMBOL_GPL(disable_kprobe);
1386
1387/* Enable one kprobe */
1388int __kprobes enable_kprobe(struct kprobe *kp)

--- 12 unchanged lines hidden (view full) ---

1401
1402 if (kprobe_gone(kp)) {
1403 /* This kprobe has gone, we couldn't enable it. */
1404 ret = -EINVAL;
1405 goto out;
1406 }
1407
1408 if (!kprobes_all_disarmed && kprobe_disabled(p))
1396 arch_arm_kprobe(p);
1409 arm_kprobe(p);
1397
1398 p->flags &= ~KPROBE_FLAG_DISABLED;
1399 if (p != kp)
1400 kp->flags &= ~KPROBE_FLAG_DISABLED;
1401out:
1402 mutex_unlock(&kprobe_mutex);
1403 return ret;
1404}

--- 150 unchanged lines hidden ---
1410
1411 p->flags &= ~KPROBE_FLAG_DISABLED;
1412 if (p != kp)
1413 kp->flags &= ~KPROBE_FLAG_DISABLED;
1414out:
1415 mutex_unlock(&kprobe_mutex);
1416 return ret;
1417}

--- 150 unchanged lines hidden ---