tracepoint: Fix static call function vs data state mismatch
[linux-2.6-microblaze.git] / kernel / tracepoint.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2008-2014 Mathieu Desnoyers
4  */
5 #include <linux/module.h>
6 #include <linux/mutex.h>
7 #include <linux/types.h>
8 #include <linux/jhash.h>
9 #include <linux/list.h>
10 #include <linux/rcupdate.h>
11 #include <linux/tracepoint.h>
12 #include <linux/err.h>
13 #include <linux/slab.h>
14 #include <linux/sched/signal.h>
15 #include <linux/sched/task.h>
16 #include <linux/static_key.h>
17
18 enum tp_func_state {
19         TP_FUNC_0,
20         TP_FUNC_1,
21         TP_FUNC_2,
22         TP_FUNC_N,
23 };
24
25 extern tracepoint_ptr_t __start___tracepoints_ptrs[];
26 extern tracepoint_ptr_t __stop___tracepoints_ptrs[];
27
28 DEFINE_SRCU(tracepoint_srcu);
29 EXPORT_SYMBOL_GPL(tracepoint_srcu);
30
31 /* Set to 1 to enable tracepoint debug output */
32 static const int tracepoint_debug;
33
34 #ifdef CONFIG_MODULES
35 /*
36  * Tracepoint module list mutex protects the local module list.
37  */
38 static DEFINE_MUTEX(tracepoint_module_list_mutex);
39
40 /* Local list of struct tp_module */
41 static LIST_HEAD(tracepoint_module_list);
42 #endif /* CONFIG_MODULES */
43
44 /*
45  * tracepoints_mutex protects the builtin and module tracepoints.
46  * tracepoints_mutex nests inside tracepoint_module_list_mutex.
47  */
48 static DEFINE_MUTEX(tracepoints_mutex);
49
50 static struct rcu_head *early_probes;
51 static bool ok_to_free_tracepoints;
52
53 /*
54  * Note about RCU :
55  * It is used to delay the free of multiple probes array until a quiescent
56  * state is reached.
57  */
58 struct tp_probes {
59         struct rcu_head rcu;
60         struct tracepoint_func probes[];
61 };
62
63 /* Called in removal of a func but failed to allocate a new tp_funcs */
64 static void tp_stub_func(void)
65 {
66         return;
67 }
68
69 static inline void *allocate_probes(int count)
70 {
71         struct tp_probes *p  = kmalloc(struct_size(p, probes, count),
72                                        GFP_KERNEL);
73         return p == NULL ? NULL : p->probes;
74 }
75
76 static void srcu_free_old_probes(struct rcu_head *head)
77 {
78         kfree(container_of(head, struct tp_probes, rcu));
79 }
80
81 static void rcu_free_old_probes(struct rcu_head *head)
82 {
83         call_srcu(&tracepoint_srcu, head, srcu_free_old_probes);
84 }
85
86 static __init int release_early_probes(void)
87 {
88         struct rcu_head *tmp;
89
90         ok_to_free_tracepoints = true;
91
92         while (early_probes) {
93                 tmp = early_probes;
94                 early_probes = tmp->next;
95                 call_rcu(tmp, rcu_free_old_probes);
96         }
97
98         return 0;
99 }
100
101 /* SRCU is initialized at core_initcall */
102 postcore_initcall(release_early_probes);
103
104 static inline void release_probes(struct tracepoint_func *old)
105 {
106         if (old) {
107                 struct tp_probes *tp_probes = container_of(old,
108                         struct tp_probes, probes[0]);
109
110                 /*
111                  * We can't free probes if SRCU is not initialized yet.
112                  * Postpone the freeing till after SRCU is initialized.
113                  */
114                 if (unlikely(!ok_to_free_tracepoints)) {
115                         tp_probes->rcu.next = early_probes;
116                         early_probes = &tp_probes->rcu;
117                         return;
118                 }
119
120                 /*
121                  * Tracepoint probes are protected by both sched RCU and SRCU,
122                  * by calling the SRCU callback in the sched RCU callback we
123                  * cover both cases. So let us chain the SRCU and sched RCU
124                  * callbacks to wait for both grace periods.
125                  */
126                 call_rcu(&tp_probes->rcu, rcu_free_old_probes);
127         }
128 }
129
130 static void debug_print_probes(struct tracepoint_func *funcs)
131 {
132         int i;
133
134         if (!tracepoint_debug || !funcs)
135                 return;
136
137         for (i = 0; funcs[i].func; i++)
138                 printk(KERN_DEBUG "Probe %d : %p\n", i, funcs[i].func);
139 }
140
141 static struct tracepoint_func *
142 func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func,
143          int prio)
144 {
145         struct tracepoint_func *old, *new;
146         int iter_probes;        /* Iterate over old probe array. */
147         int nr_probes = 0;      /* Counter for probes */
148         int pos = -1;           /* Insertion position into new array */
149
150         if (WARN_ON(!tp_func->func))
151                 return ERR_PTR(-EINVAL);
152
153         debug_print_probes(*funcs);
154         old = *funcs;
155         if (old) {
156                 /* (N -> N+1), (N != 0, 1) probes */
157                 for (iter_probes = 0; old[iter_probes].func; iter_probes++) {
158                         if (old[iter_probes].func == tp_stub_func)
159                                 continue;       /* Skip stub functions. */
160                         if (old[iter_probes].func == tp_func->func &&
161                             old[iter_probes].data == tp_func->data)
162                                 return ERR_PTR(-EEXIST);
163                         nr_probes++;
164                 }
165         }
166         /* + 2 : one for new probe, one for NULL func */
167         new = allocate_probes(nr_probes + 2);
168         if (new == NULL)
169                 return ERR_PTR(-ENOMEM);
170         if (old) {
171                 nr_probes = 0;
172                 for (iter_probes = 0; old[iter_probes].func; iter_probes++) {
173                         if (old[iter_probes].func == tp_stub_func)
174                                 continue;
175                         /* Insert before probes of lower priority */
176                         if (pos < 0 && old[iter_probes].prio < prio)
177                                 pos = nr_probes++;
178                         new[nr_probes++] = old[iter_probes];
179                 }
180                 if (pos < 0)
181                         pos = nr_probes++;
182                 /* nr_probes now points to the end of the new array */
183         } else {
184                 pos = 0;
185                 nr_probes = 1; /* must point at end of array */
186         }
187         new[pos] = *tp_func;
188         new[nr_probes].func = NULL;
189         *funcs = new;
190         debug_print_probes(*funcs);
191         return old;
192 }
193
194 static void *func_remove(struct tracepoint_func **funcs,
195                 struct tracepoint_func *tp_func)
196 {
197         int nr_probes = 0, nr_del = 0, i;
198         struct tracepoint_func *old, *new;
199
200         old = *funcs;
201
202         if (!old)
203                 return ERR_PTR(-ENOENT);
204
205         debug_print_probes(*funcs);
206         /* (N -> M), (N > 1, M >= 0) probes */
207         if (tp_func->func) {
208                 for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
209                         if ((old[nr_probes].func == tp_func->func &&
210                              old[nr_probes].data == tp_func->data) ||
211                             old[nr_probes].func == tp_stub_func)
212                                 nr_del++;
213                 }
214         }
215
216         /*
217          * If probe is NULL, then nr_probes = nr_del = 0, and then the
218          * entire entry will be removed.
219          */
220         if (nr_probes - nr_del == 0) {
221                 /* N -> 0, (N > 1) */
222                 *funcs = NULL;
223                 debug_print_probes(*funcs);
224                 return old;
225         } else {
226                 int j = 0;
227                 /* N -> M, (N > 1, M > 0) */
228                 /* + 1 for NULL */
229                 new = allocate_probes(nr_probes - nr_del + 1);
230                 if (new) {
231                         for (i = 0; old[i].func; i++) {
232                                 if ((old[i].func != tp_func->func ||
233                                      old[i].data != tp_func->data) &&
234                                     old[i].func != tp_stub_func)
235                                         new[j++] = old[i];
236                         }
237                         new[nr_probes - nr_del].func = NULL;
238                         *funcs = new;
239                 } else {
240                         /*
241                          * Failed to allocate, replace the old function
242                          * with calls to tp_stub_func.
243                          */
244                         for (i = 0; old[i].func; i++) {
245                                 if (old[i].func == tp_func->func &&
246                                     old[i].data == tp_func->data)
247                                         WRITE_ONCE(old[i].func, tp_stub_func);
248                         }
249                         *funcs = old;
250                 }
251         }
252         debug_print_probes(*funcs);
253         return old;
254 }
255
256 /*
257  * Count the number of functions (enum tp_func_state) in a tp_funcs array.
258  */
259 static enum tp_func_state nr_func_state(const struct tracepoint_func *tp_funcs)
260 {
261         if (!tp_funcs)
262                 return TP_FUNC_0;
263         if (!tp_funcs[1].func)
264                 return TP_FUNC_1;
265         if (!tp_funcs[2].func)
266                 return TP_FUNC_2;
267         return TP_FUNC_N;       /* 3 or more */
268 }
269
270 static void tracepoint_update_call(struct tracepoint *tp, struct tracepoint_func *tp_funcs)
271 {
272         void *func = tp->iterator;
273
274         /* Synthetic events do not have static call sites */
275         if (!tp->static_call_key)
276                 return;
277         if (nr_func_state(tp_funcs) == TP_FUNC_1)
278                 func = tp_funcs[0].func;
279         __static_call_update(tp->static_call_key, tp->static_call_tramp, func);
280 }
281
282 /*
283  * Add the probe function to a tracepoint.
284  */
285 static int tracepoint_add_func(struct tracepoint *tp,
286                                struct tracepoint_func *func, int prio,
287                                bool warn)
288 {
289         struct tracepoint_func *old, *tp_funcs;
290         int ret;
291
292         if (tp->regfunc && !static_key_enabled(&tp->key)) {
293                 ret = tp->regfunc();
294                 if (ret < 0)
295                         return ret;
296         }
297
298         tp_funcs = rcu_dereference_protected(tp->funcs,
299                         lockdep_is_held(&tracepoints_mutex));
300         old = func_add(&tp_funcs, func, prio);
301         if (IS_ERR(old)) {
302                 WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM);
303                 return PTR_ERR(old);
304         }
305
306         /*
307          * rcu_assign_pointer has as smp_store_release() which makes sure
308          * that the new probe callbacks array is consistent before setting
309          * a pointer to it.  This array is referenced by __DO_TRACE from
310          * include/linux/tracepoint.h using rcu_dereference_sched().
311          */
312         switch (nr_func_state(tp_funcs)) {
313         case TP_FUNC_1:         /* 0->1 */
314                 /* Set static call to first function */
315                 tracepoint_update_call(tp, tp_funcs);
316                 /* Both iterator and static call handle NULL tp->funcs */
317                 rcu_assign_pointer(tp->funcs, tp_funcs);
318                 static_key_enable(&tp->key);
319                 break;
320         case TP_FUNC_2:         /* 1->2 */
321                 /* Set iterator static call */
322                 tracepoint_update_call(tp, tp_funcs);
323                 /*
324                  * Iterator callback installed before updating tp->funcs.
325                  * Requires ordering between RCU assign/dereference and
326                  * static call update/call.
327                  */
328                 rcu_assign_pointer(tp->funcs, tp_funcs);
329                 break;
330         case TP_FUNC_N:         /* N->N+1 (N>1) */
331                 rcu_assign_pointer(tp->funcs, tp_funcs);
332                 break;
333         default:
334                 WARN_ON_ONCE(1);
335                 break;
336         }
337
338         release_probes(old);
339         return 0;
340 }
341
342 /*
343  * Remove a probe function from a tracepoint.
344  * Note: only waiting an RCU period after setting elem->call to the empty
345  * function insures that the original callback is not used anymore. This insured
346  * by preempt_disable around the call site.
347  */
348 static int tracepoint_remove_func(struct tracepoint *tp,
349                 struct tracepoint_func *func)
350 {
351         struct tracepoint_func *old, *tp_funcs;
352
353         tp_funcs = rcu_dereference_protected(tp->funcs,
354                         lockdep_is_held(&tracepoints_mutex));
355         old = func_remove(&tp_funcs, func);
356         if (WARN_ON_ONCE(IS_ERR(old)))
357                 return PTR_ERR(old);
358
359         if (tp_funcs == old)
360                 /* Failed allocating new tp_funcs, replaced func with stub */
361                 return 0;
362
363         switch (nr_func_state(tp_funcs)) {
364         case TP_FUNC_0:         /* 1->0 */
365                 /* Removed last function */
366                 if (tp->unregfunc && static_key_enabled(&tp->key))
367                         tp->unregfunc();
368
369                 static_key_disable(&tp->key);
370                 /* Set iterator static call */
371                 tracepoint_update_call(tp, tp_funcs);
372                 /* Both iterator and static call handle NULL tp->funcs */
373                 rcu_assign_pointer(tp->funcs, NULL);
374                 /*
375                  * Make sure new func never uses old data after a 1->0->1
376                  * transition sequence.
377                  * Considering that transition 0->1 is the common case
378                  * and don't have rcu-sync, issue rcu-sync after
379                  * transition 1->0 to break that sequence by waiting for
380                  * readers to be quiescent.
381                  */
382                 tracepoint_synchronize_unregister();
383                 break;
384         case TP_FUNC_1:         /* 2->1 */
385                 rcu_assign_pointer(tp->funcs, tp_funcs);
386                 /*
387                  * On 2->1 transition, RCU sync is needed before setting
388                  * static call to first callback, because the observer
389                  * may have loaded any prior tp->funcs after the last one
390                  * associated with an rcu-sync.
391                  */
392                 tracepoint_synchronize_unregister();
393                 /* Set static call to first function */
394                 tracepoint_update_call(tp, tp_funcs);
395                 break;
396         case TP_FUNC_2:         /* N->N-1 (N>2) */
397                 fallthrough;
398         case TP_FUNC_N:
399                 rcu_assign_pointer(tp->funcs, tp_funcs);
400                 break;
401         default:
402                 WARN_ON_ONCE(1);
403                 break;
404         }
405         release_probes(old);
406         return 0;
407 }
408
409 /**
410  * tracepoint_probe_register_prio_may_exist -  Connect a probe to a tracepoint with priority
411  * @tp: tracepoint
412  * @probe: probe handler
413  * @data: tracepoint data
414  * @prio: priority of this function over other registered functions
415  *
416  * Same as tracepoint_probe_register_prio() except that it will not warn
417  * if the tracepoint is already registered.
418  */
419 int tracepoint_probe_register_prio_may_exist(struct tracepoint *tp, void *probe,
420                                              void *data, int prio)
421 {
422         struct tracepoint_func tp_func;
423         int ret;
424
425         mutex_lock(&tracepoints_mutex);
426         tp_func.func = probe;
427         tp_func.data = data;
428         tp_func.prio = prio;
429         ret = tracepoint_add_func(tp, &tp_func, prio, false);
430         mutex_unlock(&tracepoints_mutex);
431         return ret;
432 }
433 EXPORT_SYMBOL_GPL(tracepoint_probe_register_prio_may_exist);
434
435 /**
436  * tracepoint_probe_register_prio -  Connect a probe to a tracepoint with priority
437  * @tp: tracepoint
438  * @probe: probe handler
439  * @data: tracepoint data
440  * @prio: priority of this function over other registered functions
441  *
442  * Returns 0 if ok, error value on error.
443  * Note: if @tp is within a module, the caller is responsible for
444  * unregistering the probe before the module is gone. This can be
445  * performed either with a tracepoint module going notifier, or from
446  * within module exit functions.
447  */
448 int tracepoint_probe_register_prio(struct tracepoint *tp, void *probe,
449                                    void *data, int prio)
450 {
451         struct tracepoint_func tp_func;
452         int ret;
453
454         mutex_lock(&tracepoints_mutex);
455         tp_func.func = probe;
456         tp_func.data = data;
457         tp_func.prio = prio;
458         ret = tracepoint_add_func(tp, &tp_func, prio, true);
459         mutex_unlock(&tracepoints_mutex);
460         return ret;
461 }
462 EXPORT_SYMBOL_GPL(tracepoint_probe_register_prio);
463
464 /**
465  * tracepoint_probe_register -  Connect a probe to a tracepoint
466  * @tp: tracepoint
467  * @probe: probe handler
468  * @data: tracepoint data
469  *
470  * Returns 0 if ok, error value on error.
471  * Note: if @tp is within a module, the caller is responsible for
472  * unregistering the probe before the module is gone. This can be
473  * performed either with a tracepoint module going notifier, or from
474  * within module exit functions.
475  */
476 int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data)
477 {
478         return tracepoint_probe_register_prio(tp, probe, data, TRACEPOINT_DEFAULT_PRIO);
479 }
480 EXPORT_SYMBOL_GPL(tracepoint_probe_register);
481
482 /**
483  * tracepoint_probe_unregister -  Disconnect a probe from a tracepoint
484  * @tp: tracepoint
485  * @probe: probe function pointer
486  * @data: tracepoint data
487  *
488  * Returns 0 if ok, error value on error.
489  */
490 int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data)
491 {
492         struct tracepoint_func tp_func;
493         int ret;
494
495         mutex_lock(&tracepoints_mutex);
496         tp_func.func = probe;
497         tp_func.data = data;
498         ret = tracepoint_remove_func(tp, &tp_func);
499         mutex_unlock(&tracepoints_mutex);
500         return ret;
501 }
502 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
503
504 static void for_each_tracepoint_range(
505                 tracepoint_ptr_t *begin, tracepoint_ptr_t *end,
506                 void (*fct)(struct tracepoint *tp, void *priv),
507                 void *priv)
508 {
509         tracepoint_ptr_t *iter;
510
511         if (!begin)
512                 return;
513         for (iter = begin; iter < end; iter++)
514                 fct(tracepoint_ptr_deref(iter), priv);
515 }
516
517 #ifdef CONFIG_MODULES
518 bool trace_module_has_bad_taint(struct module *mod)
519 {
520         return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP) |
521                                (1 << TAINT_UNSIGNED_MODULE));
522 }
523
524 static BLOCKING_NOTIFIER_HEAD(tracepoint_notify_list);
525
526 /**
527  * register_tracepoint_notifier - register tracepoint coming/going notifier
528  * @nb: notifier block
529  *
530  * Notifiers registered with this function are called on module
531  * coming/going with the tracepoint_module_list_mutex held.
532  * The notifier block callback should expect a "struct tp_module" data
533  * pointer.
534  */
535 int register_tracepoint_module_notifier(struct notifier_block *nb)
536 {
537         struct tp_module *tp_mod;
538         int ret;
539
540         mutex_lock(&tracepoint_module_list_mutex);
541         ret = blocking_notifier_chain_register(&tracepoint_notify_list, nb);
542         if (ret)
543                 goto end;
544         list_for_each_entry(tp_mod, &tracepoint_module_list, list)
545                 (void) nb->notifier_call(nb, MODULE_STATE_COMING, tp_mod);
546 end:
547         mutex_unlock(&tracepoint_module_list_mutex);
548         return ret;
549 }
550 EXPORT_SYMBOL_GPL(register_tracepoint_module_notifier);
551
552 /**
553  * unregister_tracepoint_notifier - unregister tracepoint coming/going notifier
554  * @nb: notifier block
555  *
556  * The notifier block callback should expect a "struct tp_module" data
557  * pointer.
558  */
559 int unregister_tracepoint_module_notifier(struct notifier_block *nb)
560 {
561         struct tp_module *tp_mod;
562         int ret;
563
564         mutex_lock(&tracepoint_module_list_mutex);
565         ret = blocking_notifier_chain_unregister(&tracepoint_notify_list, nb);
566         if (ret)
567                 goto end;
568         list_for_each_entry(tp_mod, &tracepoint_module_list, list)
569                 (void) nb->notifier_call(nb, MODULE_STATE_GOING, tp_mod);
570 end:
571         mutex_unlock(&tracepoint_module_list_mutex);
572         return ret;
573
574 }
575 EXPORT_SYMBOL_GPL(unregister_tracepoint_module_notifier);
576
577 /*
578  * Ensure the tracer unregistered the module's probes before the module
579  * teardown is performed. Prevents leaks of probe and data pointers.
580  */
581 static void tp_module_going_check_quiescent(struct tracepoint *tp, void *priv)
582 {
583         WARN_ON_ONCE(tp->funcs);
584 }
585
586 static int tracepoint_module_coming(struct module *mod)
587 {
588         struct tp_module *tp_mod;
589         int ret = 0;
590
591         if (!mod->num_tracepoints)
592                 return 0;
593
594         /*
595          * We skip modules that taint the kernel, especially those with different
596          * module headers (for forced load), to make sure we don't cause a crash.
597          * Staging, out-of-tree, and unsigned GPL modules are fine.
598          */
599         if (trace_module_has_bad_taint(mod))
600                 return 0;
601         mutex_lock(&tracepoint_module_list_mutex);
602         tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL);
603         if (!tp_mod) {
604                 ret = -ENOMEM;
605                 goto end;
606         }
607         tp_mod->mod = mod;
608         list_add_tail(&tp_mod->list, &tracepoint_module_list);
609         blocking_notifier_call_chain(&tracepoint_notify_list,
610                         MODULE_STATE_COMING, tp_mod);
611 end:
612         mutex_unlock(&tracepoint_module_list_mutex);
613         return ret;
614 }
615
616 static void tracepoint_module_going(struct module *mod)
617 {
618         struct tp_module *tp_mod;
619
620         if (!mod->num_tracepoints)
621                 return;
622
623         mutex_lock(&tracepoint_module_list_mutex);
624         list_for_each_entry(tp_mod, &tracepoint_module_list, list) {
625                 if (tp_mod->mod == mod) {
626                         blocking_notifier_call_chain(&tracepoint_notify_list,
627                                         MODULE_STATE_GOING, tp_mod);
628                         list_del(&tp_mod->list);
629                         kfree(tp_mod);
630                         /*
631                          * Called the going notifier before checking for
632                          * quiescence.
633                          */
634                         for_each_tracepoint_range(mod->tracepoints_ptrs,
635                                 mod->tracepoints_ptrs + mod->num_tracepoints,
636                                 tp_module_going_check_quiescent, NULL);
637                         break;
638                 }
639         }
640         /*
641          * In the case of modules that were tainted at "coming", we'll simply
642          * walk through the list without finding it. We cannot use the "tainted"
643          * flag on "going", in case a module taints the kernel only after being
644          * loaded.
645          */
646         mutex_unlock(&tracepoint_module_list_mutex);
647 }
648
649 static int tracepoint_module_notify(struct notifier_block *self,
650                 unsigned long val, void *data)
651 {
652         struct module *mod = data;
653         int ret = 0;
654
655         switch (val) {
656         case MODULE_STATE_COMING:
657                 ret = tracepoint_module_coming(mod);
658                 break;
659         case MODULE_STATE_LIVE:
660                 break;
661         case MODULE_STATE_GOING:
662                 tracepoint_module_going(mod);
663                 break;
664         case MODULE_STATE_UNFORMED:
665                 break;
666         }
667         return notifier_from_errno(ret);
668 }
669
670 static struct notifier_block tracepoint_module_nb = {
671         .notifier_call = tracepoint_module_notify,
672         .priority = 0,
673 };
674
675 static __init int init_tracepoints(void)
676 {
677         int ret;
678
679         ret = register_module_notifier(&tracepoint_module_nb);
680         if (ret)
681                 pr_warn("Failed to register tracepoint module enter notifier\n");
682
683         return ret;
684 }
685 __initcall(init_tracepoints);
686 #endif /* CONFIG_MODULES */
687
688 /**
689  * for_each_kernel_tracepoint - iteration on all kernel tracepoints
690  * @fct: callback
691  * @priv: private data
692  */
693 void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
694                 void *priv)
695 {
696         for_each_tracepoint_range(__start___tracepoints_ptrs,
697                 __stop___tracepoints_ptrs, fct, priv);
698 }
699 EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint);
700
701 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
702
703 /* NB: reg/unreg are called while guarded with the tracepoints_mutex */
704 static int sys_tracepoint_refcount;
705
706 int syscall_regfunc(void)
707 {
708         struct task_struct *p, *t;
709
710         if (!sys_tracepoint_refcount) {
711                 read_lock(&tasklist_lock);
712                 for_each_process_thread(p, t) {
713                         set_task_syscall_work(t, SYSCALL_TRACEPOINT);
714                 }
715                 read_unlock(&tasklist_lock);
716         }
717         sys_tracepoint_refcount++;
718
719         return 0;
720 }
721
722 void syscall_unregfunc(void)
723 {
724         struct task_struct *p, *t;
725
726         sys_tracepoint_refcount--;
727         if (!sys_tracepoint_refcount) {
728                 read_lock(&tasklist_lock);
729                 for_each_process_thread(p, t) {
730                         clear_task_syscall_work(t, SYSCALL_TRACEPOINT);
731                 }
732                 read_unlock(&tasklist_lock);
733         }
734 }
735 #endif