Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kprobes: Add assertions for required lock

Add assertions for required locks instead of comment it
so that the lockdep can inspect locks automatically.

Link: https://lkml.kernel.org/r/163163039572.489837.18011973177537476885.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
57d4e317 dfc05b55

+12 -7
+12 -7
kernel/kprobes.c
··· 959 959 } 960 960 #endif /* CONFIG_SYSCTL */ 961 961 962 - /* Put a breakpoint for a probe. Must be called with 'text_mutex' locked. */ 962 + /* Put a breakpoint for a probe. */ 963 963 static void __arm_kprobe(struct kprobe *p) 964 964 { 965 965 struct kprobe *_p; 966 + 967 + lockdep_assert_held(&text_mutex); 966 968 967 969 /* Find the overlapping optimized kprobes. */ 968 970 _p = get_optimized_kprobe((unsigned long)p->addr); ··· 976 974 optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ 977 975 } 978 976 979 - /* Remove the breakpoint of a probe. Must be called with 'text_mutex' locked. */ 977 + /* Remove the breakpoint of a probe. */ 980 978 static void __disarm_kprobe(struct kprobe *p, bool reopt) 981 979 { 982 980 struct kprobe *_p; 981 + 982 + lockdep_assert_held(&text_mutex); 983 983 984 984 /* Try to unoptimize */ 985 985 unoptimize_kprobe(p, kprobes_all_disarmed); ··· 1051 1047 static int kprobe_ipmodify_enabled; 1052 1048 static int kprobe_ftrace_enabled; 1053 1049 1054 - /* Caller must lock 'kprobe_mutex' */ 1055 1050 static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, 1056 1051 int *cnt) 1057 1052 { 1058 1053 int ret = 0; 1054 + 1055 + lockdep_assert_held(&kprobe_mutex); 1059 1056 1060 1057 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); 1061 1058 if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret)) ··· 1089 1084 ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled); 1090 1085 } 1091 1086 1092 - /* Caller must lock 'kprobe_mutex'. */ 1093 1087 static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, 1094 1088 int *cnt) 1095 1089 { 1096 1090 int ret = 0; 1091 + 1092 + lockdep_assert_held(&kprobe_mutex); 1097 1093 1098 1094 if (*cnt == 1) { 1099 1095 ret = unregister_ftrace_function(ops); ··· 1139 1133 return arch_prepare_kprobe(p); 1140 1134 } 1141 1135 1142 - /* Arm a kprobe with 'text_mutex'. */ 1143 1136 static int arm_kprobe(struct kprobe *kp) 1144 1137 { 1145 1138 if (unlikely(kprobe_ftrace(kp))) ··· 1153 1148 return 0; 1154 1149 } 1155 1150 1156 - /* Disarm a kprobe with 'text_mutex'. */ 1157 1151 static int disarm_kprobe(struct kprobe *kp, bool reopt) 1158 1152 { 1159 1153 if (unlikely(kprobe_ftrace(kp))) ··· 1695 1691 return 1; 1696 1692 } 1697 1693 1698 - /* Disable one kprobe: Make sure called under 'kprobe_mutex' is locked. */ 1699 1694 static struct kprobe *__disable_kprobe(struct kprobe *p) 1700 1695 { 1701 1696 struct kprobe *orig_p; 1702 1697 int ret; 1698 + 1699 + lockdep_assert_held(&kprobe_mutex); 1703 1700 1704 1701 /* Get an original kprobe for return */ 1705 1702 orig_p = __get_valid_kprobe(p);