diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2009-01-06 17:41:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 18:59:21 -0500 |
commit | 49ad2fd76c97133fb396edc24ded7fe26093a578 (patch) | |
tree | 59cf1df91ff982f16a17d56a4a76f159920c3904 /kernel | |
parent | e8386a0cb22f4a2d439384212c494ad0bda848fe (diff) |
kprobes: remove called_from argument
Remove called_from argument from kprobes which had been used for
preventing self-refering of kernel module. However, since we don't keep
module's refcount after registering kprobe any more, there is no reason to
check that.
This patch also simplifies registering/unregistering functions because we
don't need to use __builtin_return_address(0) which was passed to
called_from.
[ananth@in.ibm.com: build fix]
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/kprobes.c | 72 |
1 files changed, 14 insertions, 58 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index cb732a9aa55f..ddefb9fae0c8 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -644,8 +644,7 @@ static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p) | |||
644 | return (kprobe_opcode_t *)(((char *)addr) + p->offset); | 644 | return (kprobe_opcode_t *)(((char *)addr) + p->offset); |
645 | } | 645 | } |
646 | 646 | ||
647 | static int __kprobes __register_kprobe(struct kprobe *p, | 647 | int __kprobes register_kprobe(struct kprobe *p) |
648 | unsigned long called_from) | ||
649 | { | 648 | { |
650 | int ret = 0; | 649 | int ret = 0; |
651 | struct kprobe *old_p; | 650 | struct kprobe *old_p; |
@@ -670,19 +669,14 @@ static int __kprobes __register_kprobe(struct kprobe *p, | |||
670 | */ | 669 | */ |
671 | probed_mod = __module_text_address((unsigned long) p->addr); | 670 | probed_mod = __module_text_address((unsigned long) p->addr); |
672 | if (probed_mod) { | 671 | if (probed_mod) { |
673 | struct module *calling_mod; | ||
674 | calling_mod = __module_text_address(called_from); | ||
675 | /* | 672 | /* |
676 | * We must hold a refcount of the probed module while updating | 673 | * We must hold a refcount of the probed module while updating |
677 | * its code to prohibit unexpected unloading. | 674 | * its code to prohibit unexpected unloading. |
678 | */ | 675 | */ |
679 | if (calling_mod != probed_mod) { | 676 | if (unlikely(!try_module_get(probed_mod))) { |
680 | if (unlikely(!try_module_get(probed_mod))) { | 677 | preempt_enable(); |
681 | preempt_enable(); | 678 | return -EINVAL; |
682 | return -EINVAL; | 679 | } |
683 | } | ||
684 | } else | ||
685 | probed_mod = NULL; | ||
686 | } | 680 | } |
687 | preempt_enable(); | 681 | preempt_enable(); |
688 | 682 | ||
@@ -776,15 +770,14 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p) | |||
776 | } | 770 | } |
777 | } | 771 | } |
778 | 772 | ||
779 | static int __kprobes __register_kprobes(struct kprobe **kps, int num, | 773 | int __kprobes register_kprobes(struct kprobe **kps, int num) |
780 | unsigned long called_from) | ||
781 | { | 774 | { |
782 | int i, ret = 0; | 775 | int i, ret = 0; |
783 | 776 | ||
784 | if (num <= 0) | 777 | if (num <= 0) |
785 | return -EINVAL; | 778 | return -EINVAL; |
786 | for (i = 0; i < num; i++) { | 779 | for (i = 0; i < num; i++) { |
787 | ret = __register_kprobe(kps[i], called_from); | 780 | ret = register_kprobe(kps[i]); |
788 | if (ret < 0) { | 781 | if (ret < 0) { |
789 | if (i > 0) | 782 | if (i > 0) |
790 | unregister_kprobes(kps, i); | 783 | unregister_kprobes(kps, i); |
@@ -794,26 +787,11 @@ static int __kprobes __register_kprobes(struct kprobe **kps, int num, | |||
794 | return ret; | 787 | return ret; |
795 | } | 788 | } |
796 | 789 | ||
797 | /* | ||
798 | * Registration and unregistration functions for kprobe. | ||
799 | */ | ||
800 | int __kprobes register_kprobe(struct kprobe *p) | ||
801 | { | ||
802 | return __register_kprobes(&p, 1, | ||
803 | (unsigned long)__builtin_return_address(0)); | ||
804 | } | ||
805 | |||
806 | void __kprobes unregister_kprobe(struct kprobe *p) | 790 | void __kprobes unregister_kprobe(struct kprobe *p) |
807 | { | 791 | { |
808 | unregister_kprobes(&p, 1); | 792 | unregister_kprobes(&p, 1); |
809 | } | 793 | } |
810 | 794 | ||
811 | int __kprobes register_kprobes(struct kprobe **kps, int num) | ||
812 | { | ||
813 | return __register_kprobes(kps, num, | ||
814 | (unsigned long)__builtin_return_address(0)); | ||
815 | } | ||
816 | |||
817 | void __kprobes unregister_kprobes(struct kprobe **kps, int num) | 795 | void __kprobes unregister_kprobes(struct kprobe **kps, int num) |
818 | { | 796 | { |
819 | int i; | 797 | int i; |
@@ -842,8 +820,7 @@ unsigned long __weak arch_deref_entry_point(void *entry) | |||
842 | return (unsigned long)entry; | 820 | return (unsigned long)entry; |
843 | } | 821 | } |
844 | 822 | ||
845 | static int __kprobes __register_jprobes(struct jprobe **jps, int num, | 823 | int __kprobes register_jprobes(struct jprobe **jps, int num) |
846 | unsigned long called_from) | ||
847 | { | 824 | { |
848 | struct jprobe *jp; | 825 | struct jprobe *jp; |
849 | int ret = 0, i; | 826 | int ret = 0, i; |
@@ -861,7 +838,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num, | |||
861 | /* Todo: Verify probepoint is a function entry point */ | 838 | /* Todo: Verify probepoint is a function entry point */ |
862 | jp->kp.pre_handler = setjmp_pre_handler; | 839 | jp->kp.pre_handler = setjmp_pre_handler; |
863 | jp->kp.break_handler = longjmp_break_handler; | 840 | jp->kp.break_handler = longjmp_break_handler; |
864 | ret = __register_kprobe(&jp->kp, called_from); | 841 | ret = register_kprobe(&jp->kp); |
865 | } | 842 | } |
866 | if (ret < 0) { | 843 | if (ret < 0) { |
867 | if (i > 0) | 844 | if (i > 0) |
@@ -874,8 +851,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num, | |||
874 | 851 | ||
875 | int __kprobes register_jprobe(struct jprobe *jp) | 852 | int __kprobes register_jprobe(struct jprobe *jp) |
876 | { | 853 | { |
877 | return __register_jprobes(&jp, 1, | 854 | return register_jprobes(&jp, 1); |
878 | (unsigned long)__builtin_return_address(0)); | ||
879 | } | 855 | } |
880 | 856 | ||
881 | void __kprobes unregister_jprobe(struct jprobe *jp) | 857 | void __kprobes unregister_jprobe(struct jprobe *jp) |
@@ -883,12 +859,6 @@ void __kprobes unregister_jprobe(struct jprobe *jp) | |||
883 | unregister_jprobes(&jp, 1); | 859 | unregister_jprobes(&jp, 1); |
884 | } | 860 | } |
885 | 861 | ||
886 | int __kprobes register_jprobes(struct jprobe **jps, int num) | ||
887 | { | ||
888 | return __register_jprobes(jps, num, | ||
889 | (unsigned long)__builtin_return_address(0)); | ||
890 | } | ||
891 | |||
892 | void __kprobes unregister_jprobes(struct jprobe **jps, int num) | 862 | void __kprobes unregister_jprobes(struct jprobe **jps, int num) |
893 | { | 863 | { |
894 | int i; | 864 | int i; |
@@ -951,8 +921,7 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, | |||
951 | return 0; | 921 | return 0; |
952 | } | 922 | } |
953 | 923 | ||
954 | static int __kprobes __register_kretprobe(struct kretprobe *rp, | 924 | int __kprobes register_kretprobe(struct kretprobe *rp) |
955 | unsigned long called_from) | ||
956 | { | 925 | { |
957 | int ret = 0; | 926 | int ret = 0; |
958 | struct kretprobe_instance *inst; | 927 | struct kretprobe_instance *inst; |
@@ -998,21 +967,20 @@ static int __kprobes __register_kretprobe(struct kretprobe *rp, | |||
998 | 967 | ||
999 | rp->nmissed = 0; | 968 | rp->nmissed = 0; |
1000 | /* Establish function entry probe point */ | 969 | /* Establish function entry probe point */ |
1001 | ret = __register_kprobe(&rp->kp, called_from); | 970 | ret = register_kprobe(&rp->kp); |
1002 | if (ret != 0) | 971 | if (ret != 0) |
1003 | free_rp_inst(rp); | 972 | free_rp_inst(rp); |
1004 | return ret; | 973 | return ret; |
1005 | } | 974 | } |
1006 | 975 | ||
1007 | static int __kprobes __register_kretprobes(struct kretprobe **rps, int num, | 976 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) |
1008 | unsigned long called_from) | ||
1009 | { | 977 | { |
1010 | int ret = 0, i; | 978 | int ret = 0, i; |
1011 | 979 | ||
1012 | if (num <= 0) | 980 | if (num <= 0) |
1013 | return -EINVAL; | 981 | return -EINVAL; |
1014 | for (i = 0; i < num; i++) { | 982 | for (i = 0; i < num; i++) { |
1015 | ret = __register_kretprobe(rps[i], called_from); | 983 | ret = register_kretprobe(rps[i]); |
1016 | if (ret < 0) { | 984 | if (ret < 0) { |
1017 | if (i > 0) | 985 | if (i > 0) |
1018 | unregister_kretprobes(rps, i); | 986 | unregister_kretprobes(rps, i); |
@@ -1022,23 +990,11 @@ static int __kprobes __register_kretprobes(struct kretprobe **rps, int num, | |||
1022 | return ret; | 990 | return ret; |
1023 | } | 991 | } |
1024 | 992 | ||
1025 | int __kprobes register_kretprobe(struct kretprobe *rp) | ||
1026 | { | ||
1027 | return __register_kretprobes(&rp, 1, | ||
1028 | (unsigned long)__builtin_return_address(0)); | ||
1029 | } | ||
1030 | |||
1031 | void __kprobes unregister_kretprobe(struct kretprobe *rp) | 993 | void __kprobes unregister_kretprobe(struct kretprobe *rp) |
1032 | { | 994 | { |
1033 | unregister_kretprobes(&rp, 1); | 995 | unregister_kretprobes(&rp, 1); |
1034 | } | 996 | } |
1035 | 997 | ||
1036 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) | ||
1037 | { | ||
1038 | return __register_kretprobes(rps, num, | ||
1039 | (unsigned long)__builtin_return_address(0)); | ||
1040 | } | ||
1041 | |||
1042 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) | 998 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) |
1043 | { | 999 | { |
1044 | int i; | 1000 | int i; |