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

tracing/probe: Add trace flag access APIs for trace_probe

Add trace_probe_test/set/clear_flag() functions for accessing
trace_probe.flag field.
This flags field should not be accessed directly.

Link: http://lkml.kernel.org/r/155931585683.28323.314290023236905988.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)
747774d6 b5f935ee

+41 -23
+10 -10
kernel/trace/trace_kprobe.c
··· 298 298 if (ret) 299 299 return ret; 300 300 } else 301 - tk->tp.flags |= TP_FLAG_PROFILE; 301 + trace_probe_set_flag(&tk->tp, TP_FLAG_PROFILE); 302 302 303 303 if (enabled) 304 304 return 0; ··· 308 308 if (file) 309 309 trace_probe_remove_file(&tk->tp, file); 310 310 else 311 - tk->tp.flags &= ~TP_FLAG_PROFILE; 311 + trace_probe_clear_flag(&tk->tp, TP_FLAG_PROFILE); 312 312 } 313 313 314 314 return ret; ··· 329 329 return -ENOENT; 330 330 if (!trace_probe_has_single_file(tp)) 331 331 goto out; 332 - tp->flags &= ~TP_FLAG_TRACE; 332 + trace_probe_clear_flag(tp, TP_FLAG_TRACE); 333 333 } else 334 - tp->flags &= ~TP_FLAG_PROFILE; 334 + trace_probe_clear_flag(tp, TP_FLAG_PROFILE); 335 335 336 336 if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) { 337 337 if (trace_kprobe_is_return(tk)) ··· 408 408 ret = register_kprobe(&tk->rp.kp); 409 409 410 410 if (ret == 0) 411 - tk->tp.flags |= TP_FLAG_REGISTERED; 411 + trace_probe_set_flag(&tk->tp, TP_FLAG_REGISTERED); 412 412 return ret; 413 413 } 414 414 ··· 420 420 unregister_kretprobe(&tk->rp); 421 421 else 422 422 unregister_kprobe(&tk->rp.kp); 423 - tk->tp.flags &= ~TP_FLAG_REGISTERED; 423 + trace_probe_clear_flag(&tk->tp, TP_FLAG_REGISTERED); 424 424 /* Cleanup kprobe for reuse */ 425 425 if (tk->rp.kp.symbol_name) 426 426 tk->rp.kp.addr = NULL; ··· 1313 1313 1314 1314 raw_cpu_inc(*tk->nhit); 1315 1315 1316 - if (tk->tp.flags & TP_FLAG_TRACE) 1316 + if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE)) 1317 1317 kprobe_trace_func(tk, regs); 1318 1318 #ifdef CONFIG_PERF_EVENTS 1319 - if (tk->tp.flags & TP_FLAG_PROFILE) 1319 + if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE)) 1320 1320 ret = kprobe_perf_func(tk, regs); 1321 1321 #endif 1322 1322 return ret; ··· 1330 1330 1331 1331 raw_cpu_inc(*tk->nhit); 1332 1332 1333 - if (tk->tp.flags & TP_FLAG_TRACE) 1333 + if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE)) 1334 1334 kretprobe_trace_func(tk, ri, regs); 1335 1335 #ifdef CONFIG_PERF_EVENTS 1336 - if (tk->tp.flags & TP_FLAG_PROFILE) 1336 + if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE)) 1337 1337 kretprobe_perf_func(tk, ri, regs); 1338 1338 #endif 1339 1339 return 0; /* We don't tweek kernel, so just return 0 */
+2 -2
kernel/trace/trace_probe.c
··· 948 948 link->file = file; 949 949 INIT_LIST_HEAD(&link->list); 950 950 list_add_tail_rcu(&link->list, &tp->files); 951 - tp->flags |= TP_FLAG_TRACE; 951 + trace_probe_set_flag(tp, TP_FLAG_TRACE); 952 952 return 0; 953 953 } 954 954 ··· 979 979 kfree(link); 980 980 981 981 if (list_empty(&tp->files)) 982 - tp->flags &= ~TP_FLAG_TRACE; 982 + trace_probe_clear_flag(tp, TP_FLAG_TRACE); 983 983 984 984 return 0; 985 985 }
+20 -2
kernel/trace/trace_probe.h
··· 238 238 struct list_head list; 239 239 }; 240 240 241 + static inline bool trace_probe_test_flag(struct trace_probe *tp, 242 + unsigned int flag) 243 + { 244 + return !!(tp->flags & flag); 245 + } 246 + 247 + static inline void trace_probe_set_flag(struct trace_probe *tp, 248 + unsigned int flag) 249 + { 250 + tp->flags |= flag; 251 + } 252 + 253 + static inline void trace_probe_clear_flag(struct trace_probe *tp, 254 + unsigned int flag) 255 + { 256 + tp->flags &= ~flag; 257 + } 258 + 241 259 static inline bool trace_probe_is_enabled(struct trace_probe *tp) 242 260 { 243 - return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE)); 261 + return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE); 244 262 } 245 263 246 264 static inline bool trace_probe_is_registered(struct trace_probe *tp) 247 265 { 248 - return !!(tp->flags & TP_FLAG_REGISTERED); 266 + return trace_probe_test_flag(tp, TP_FLAG_REGISTERED); 249 267 } 250 268 251 269 static inline int trace_probe_unregister_event_call(struct trace_probe *tp)
+9 -9
kernel/trace/trace_uprobe.c
··· 927 927 int ret; 928 928 929 929 if (file) { 930 - if (tu->tp.flags & TP_FLAG_PROFILE) 930 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) 931 931 return -EINTR; 932 932 933 933 ret = trace_probe_add_file(&tu->tp, file); 934 934 if (ret < 0) 935 935 return ret; 936 936 } else { 937 - if (tu->tp.flags & TP_FLAG_TRACE) 937 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) 938 938 return -EINTR; 939 939 940 - tu->tp.flags |= TP_FLAG_PROFILE; 940 + trace_probe_set_flag(&tu->tp, TP_FLAG_PROFILE); 941 941 } 942 942 943 943 WARN_ON(!uprobe_filter_is_empty(&tu->filter)); ··· 970 970 if (file) 971 971 trace_probe_remove_file(&tu->tp, file); 972 972 else 973 - tu->tp.flags &= ~TP_FLAG_PROFILE; 973 + trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE); 974 974 975 975 return ret; 976 976 } ··· 988 988 if (trace_probe_is_enabled(&tu->tp)) 989 989 return; 990 990 } else 991 - tu->tp.flags &= ~TP_FLAG_PROFILE; 991 + trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE); 992 992 993 993 WARN_ON(!uprobe_filter_is_empty(&tu->filter)); 994 994 ··· 1266 1266 ucb = uprobe_buffer_get(); 1267 1267 store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); 1268 1268 1269 - if (tu->tp.flags & TP_FLAG_TRACE) 1269 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) 1270 1270 ret |= uprobe_trace_func(tu, regs, ucb, dsize); 1271 1271 1272 1272 #ifdef CONFIG_PERF_EVENTS 1273 - if (tu->tp.flags & TP_FLAG_PROFILE) 1273 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) 1274 1274 ret |= uprobe_perf_func(tu, regs, ucb, dsize); 1275 1275 #endif 1276 1276 uprobe_buffer_put(ucb); ··· 1301 1301 ucb = uprobe_buffer_get(); 1302 1302 store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); 1303 1303 1304 - if (tu->tp.flags & TP_FLAG_TRACE) 1304 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) 1305 1305 uretprobe_trace_func(tu, func, regs, ucb, dsize); 1306 1306 1307 1307 #ifdef CONFIG_PERF_EVENTS 1308 - if (tu->tp.flags & TP_FLAG_PROFILE) 1308 + if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) 1309 1309 uretprobe_perf_func(tu, func, regs, ucb, dsize); 1310 1310 #endif 1311 1311 uprobe_buffer_put(ucb);