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

tracing: Have the reg function allow to fail

Some tracepoints have a registration function that gets enabled when the
tracepoint is enabled. There may be cases that the registraction function
must fail (for example, can't allocate enough memory). In this case, the
tracepoint should also fail to register, otherwise the user would not know
why the tracepoint is not working.

Cc: David Howells <dhowells@redhat.com>
Cc: Seiji Aguchi <seiji.aguchi@hds.com>
Cc: Anton Blanchard <anton@samba.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

+34 -20
+2 -2
arch/powerpc/include/asm/trace.h
··· 54 54 ); 55 55 56 56 #ifdef CONFIG_PPC_PSERIES 57 - extern void hcall_tracepoint_regfunc(void); 57 + extern int hcall_tracepoint_regfunc(void); 58 58 extern void hcall_tracepoint_unregfunc(void); 59 59 60 60 TRACE_EVENT_FN_COND(hcall_entry, ··· 104 104 #endif 105 105 106 106 #ifdef CONFIG_PPC_POWERNV 107 - extern void opal_tracepoint_regfunc(void); 107 + extern int opal_tracepoint_regfunc(void); 108 108 extern void opal_tracepoint_unregfunc(void); 109 109 110 110 TRACE_EVENT_FN(opal_entry,
+4 -2
arch/powerpc/platforms/powernv/opal-tracepoints.c
··· 6 6 #ifdef HAVE_JUMP_LABEL 7 7 struct static_key opal_tracepoint_key = STATIC_KEY_INIT; 8 8 9 - void opal_tracepoint_regfunc(void) 9 + int opal_tracepoint_regfunc(void) 10 10 { 11 11 static_key_slow_inc(&opal_tracepoint_key); 12 + return 0; 12 13 } 13 14 14 15 void opal_tracepoint_unregfunc(void) ··· 26 25 /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ 27 26 extern long opal_tracepoint_refcount; 28 27 29 - void opal_tracepoint_regfunc(void) 28 + int opal_tracepoint_regfunc(void) 30 29 { 31 30 opal_tracepoint_refcount++; 31 + return 0; 32 32 } 33 33 34 34 void opal_tracepoint_unregfunc(void)
+4 -2
arch/powerpc/platforms/pseries/lpar.c
··· 661 661 #ifdef HAVE_JUMP_LABEL 662 662 struct static_key hcall_tracepoint_key = STATIC_KEY_INIT; 663 663 664 - void hcall_tracepoint_regfunc(void) 664 + int hcall_tracepoint_regfunc(void) 665 665 { 666 666 static_key_slow_inc(&hcall_tracepoint_key); 667 + return 0; 667 668 } 668 669 669 670 void hcall_tracepoint_unregfunc(void) ··· 681 680 /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ 682 681 extern long hcall_tracepoint_refcount; 683 682 684 - void hcall_tracepoint_regfunc(void) 683 + int hcall_tracepoint_regfunc(void) 685 684 { 686 685 hcall_tracepoint_refcount++; 686 + return 0; 687 687 } 688 688 689 689 void hcall_tracepoint_unregfunc(void)
+1 -1
arch/x86/include/asm/trace/exceptions.h
··· 6 6 7 7 #include <linux/tracepoint.h> 8 8 9 - extern void trace_irq_vector_regfunc(void); 9 + extern int trace_irq_vector_regfunc(void); 10 10 extern void trace_irq_vector_unregfunc(void); 11 11 12 12 DECLARE_EVENT_CLASS(x86_exceptions,
+1 -1
arch/x86/include/asm/trace/irq_vectors.h
··· 6 6 7 7 #include <linux/tracepoint.h> 8 8 9 - extern void trace_irq_vector_regfunc(void); 9 + extern int trace_irq_vector_regfunc(void); 10 10 extern void trace_irq_vector_unregfunc(void); 11 11 12 12 DECLARE_EVENT_CLASS(x86_irq_vector,
+2 -1
arch/x86/kernel/tracepoint.c
··· 34 34 local_irq_restore(flags); 35 35 } 36 36 37 - void trace_irq_vector_regfunc(void) 37 + int trace_irq_vector_regfunc(void) 38 38 { 39 39 mutex_lock(&irq_vector_mutex); 40 40 if (!trace_irq_vector_refcount) { ··· 44 44 } 45 45 trace_irq_vector_refcount++; 46 46 mutex_unlock(&irq_vector_mutex); 47 + return 0; 47 48 } 48 49 49 50 void trace_irq_vector_unregfunc(void)
+2 -1
drivers/i2c/i2c-core.c
··· 77 77 static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; 78 78 static bool is_registered; 79 79 80 - void i2c_transfer_trace_reg(void) 80 + int i2c_transfer_trace_reg(void) 81 81 { 82 82 static_key_slow_inc(&i2c_trace_msg); 83 + return 0; 83 84 } 84 85 85 86 void i2c_transfer_trace_unreg(void)
+1 -1
include/linux/tracepoint-defs.h
··· 29 29 struct tracepoint { 30 30 const char *name; /* Tracepoint name */ 31 31 struct static_key key; 32 - void (*regfunc)(void); 32 + int (*regfunc)(void); 33 33 void (*unregfunc)(void); 34 34 struct tracepoint_func __rcu *funcs; 35 35 };
+1 -1
include/linux/tracepoint.h
··· 81 81 } 82 82 83 83 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS 84 - extern void syscall_regfunc(void); 84 + extern int syscall_regfunc(void); 85 85 extern void syscall_unregfunc(void); 86 86 #endif /* CONFIG_HAVE_SYSCALL_TRACEPOINTS */ 87 87
+1 -1
include/trace/events/i2c.h
··· 20 20 /* 21 21 * drivers/i2c/i2c-core.c 22 22 */ 23 - extern void i2c_transfer_trace_reg(void); 23 + extern int i2c_transfer_trace_reg(void); 24 24 extern void i2c_transfer_trace_unreg(void); 25 25 26 26 /*
+2 -1
kernel/trace/trace_benchmark.c
··· 164 164 * When the benchmark tracepoint is enabled, it calls this 165 165 * function and the thread that calls the tracepoint is created. 166 166 */ 167 - void trace_benchmark_reg(void) 167 + int trace_benchmark_reg(void) 168 168 { 169 169 bm_event_thread = kthread_run(benchmark_event_kthread, 170 170 NULL, "event_benchmark"); 171 171 WARN_ON(!bm_event_thread); 172 + return 0; 172 173 } 173 174 174 175 /*
+1 -1
kernel/trace/trace_benchmark.h
··· 6 6 7 7 #include <linux/tracepoint.h> 8 8 9 - extern void trace_benchmark_reg(void); 9 + extern int trace_benchmark_reg(void); 10 10 extern void trace_benchmark_unreg(void); 11 11 12 12 #define BENCHMARK_EVENT_STRLEN 128
+9 -3
kernel/tracepoint.c
··· 194 194 struct tracepoint_func *func, int prio) 195 195 { 196 196 struct tracepoint_func *old, *tp_funcs; 197 + int ret; 197 198 198 - if (tp->regfunc && !static_key_enabled(&tp->key)) 199 - tp->regfunc(); 199 + if (tp->regfunc && !static_key_enabled(&tp->key)) { 200 + ret = tp->regfunc(); 201 + if (ret < 0) 202 + return ret; 203 + } 200 204 201 205 tp_funcs = rcu_dereference_protected(tp->funcs, 202 206 lockdep_is_held(&tracepoints_mutex)); ··· 533 529 /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ 534 530 static int sys_tracepoint_refcount; 535 531 536 - void syscall_regfunc(void) 532 + int syscall_regfunc(void) 537 533 { 538 534 struct task_struct *p, *t; 539 535 ··· 545 541 read_unlock(&tasklist_lock); 546 542 } 547 543 sys_tracepoint_refcount++; 544 + 545 + return 0; 548 546 } 549 547 550 548 void syscall_unregfunc(void)
+2 -1
samples/trace_events/trace-events-sample.c
··· 79 79 80 80 static DEFINE_MUTEX(thread_mutex); 81 81 82 - void foo_bar_reg(void) 82 + int foo_bar_reg(void) 83 83 { 84 84 pr_info("Starting thread for foo_bar_fn\n"); 85 85 /* ··· 90 90 mutex_lock(&thread_mutex); 91 91 simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn"); 92 92 mutex_unlock(&thread_mutex); 93 + return 0; 93 94 } 94 95 95 96 void foo_bar_unreg(void)
+1 -1
samples/trace_events/trace-events-sample.h
··· 354 354 TP_printk("foo %s %d", __get_str(foo), __entry->bar) 355 355 ); 356 356 357 - void foo_bar_reg(void); 357 + int foo_bar_reg(void); 358 358 void foo_bar_unreg(void); 359 359 360 360 /*