History

Merge branch 'tip/perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace into perf/core

Ingo Molnar committed 15 years ago

Commit 40bcea72 parents 492f73a 14a8fd726 files · +1663 −1003Browse files

Showing the changes to kernel/trace (7 of 26 files). Show all

Unified · Split

7 files
  1. kernel/trace/ftrace.c +74 −21
  2. kernel/trace/trace.c +79 −13
  3. kernel/trace/trace.h +34 −16
  4. kernel/trace/trace_entries.h +2 −1
  5. kernel/trace/trace_functions_graph.c +1 −1
  6. kernel/trace/trace_kprobe.c +223 −95
  7. kernel/trace/trace_output.c +6 −5
kernel/trace/ftrace.c+74−21
@@ -88,6 +88,7 @@ static struct ftrace_ops ftrace_list_end __read_mostly = { · 87 unmodified lines
8888 static struct ftrace_ops *ftrace_global_list __read_mostly = &ftrace_list_end;
8989 static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end;
9090 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
91+static ftrace_func_t __ftrace_trace_function_delay __read_mostly = ftrace_stub;
9192 ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub;
9293 ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub;
9394 static struct ftrace_ops global_ops;
@@ -146,9 +147,11 @@ void clear_ftrace_function(void) · 52 unmodified lines
146147 {
147148 ftrace_trace_function = ftrace_stub;
148149 __ftrace_trace_function = ftrace_stub;
150+ __ftrace_trace_function_delay = ftrace_stub;
149151 ftrace_pid_function = ftrace_stub;
150152 }
151153
154+#undef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
152155 #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
153156 /*
154157 * For those archs that do not test ftrace_trace_stop in their
@@ -207,8 +210,13 @@ static void update_ftrace_function(void) · 52 unmodified lines
207210
208211 #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
209212 ftrace_trace_function = func;
213+#else
214+#ifdef CONFIG_DYNAMIC_FTRACE
215+ /* do not update till all functions have been modified */
216+ __ftrace_trace_function_delay = func;
210217 #else
211218 __ftrace_trace_function = func;
219+#endif
212220 ftrace_trace_function = ftrace_test_stop_func;
213221 #endif
214222 }
@@ -1170,8 +1178,14 @@ alloc_and_copy_ftrace_hash(int size_bits, struct ftrace_hash *hash) · 955 unmodified lines
11701178 return NULL;
11711179 }
11721180
1181+static void
1182+ftrace_hash_rec_disable(struct ftrace_ops *ops, int filter_hash);
1183+static void
1184+ftrace_hash_rec_enable(struct ftrace_ops *ops, int filter_hash);
1185+
11731186 static int
1174−ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
1187+ftrace_hash_move(struct ftrace_ops *ops, int enable,
1188+ struct ftrace_hash **dst, struct ftrace_hash *src)
11751189 {
11761190 struct ftrace_func_entry *entry;
11771191 struct hlist_node *tp, *tn;
@@ -1181,8 +1195,15 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) · 3 unmodified lines
11811195 unsigned long key;
11821196 int size = src->count;
11831197 int bits = 0;
1198+ int ret;
11841199 int i;
11851200
1201+ /*
1202+ * Remove the current set, update the hash and add
1203+ * them back.
1204+ */
1205+ ftrace_hash_rec_disable(ops, enable);
1206+
11861207 /*
11871208 * If the new source is empty, just free dst and assign it
11881209 * the empty_hash.
@@ -1203,9 +1224,10 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) · 14 unmodified lines
12031224 if (bits > FTRACE_HASH_MAX_BITS)
12041225 bits = FTRACE_HASH_MAX_BITS;
12051226
1227+ ret = -ENOMEM;
12061228 new_hash = alloc_ftrace_hash(bits);
12071229 if (!new_hash)
1208− return -ENOMEM;
1230+ goto out;
12091231
12101232 size = 1 << src->size_bits;
12111233 for (i = 0; i < size; i++) {
@@ -1224,7 +1246,16 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src) · 12 unmodified lines
12241246 rcu_assign_pointer(*dst, new_hash);
12251247 free_ftrace_hash_rcu(old_hash);
12261248
1227− return 0;
1249+ ret = 0;
1250+ out:
1251+ /*
1252+ * Enable regardless of ret:
1253+ * On success, we enable the new hash.
1254+ * On failure, we re-enable the original hash.
1255+ */
1256+ ftrace_hash_rec_enable(ops, enable);
1257+
1258+ return ret;
12281259 }
12291260
12301261 /*
@@ -1584,6 +1615,12 @@ static int __ftrace_modify_code(void *data) · 353 unmodified lines
15841615 {
15851616 int *command = data;
15861617
1618+ /*
1619+ * Do not call function tracer while we update the code.
1620+ * We are in stop machine, no worrying about races.
1621+ */
1622+ function_trace_stop++;
1623+
15871624 if (*command & FTRACE_ENABLE_CALLS)
15881625 ftrace_replace_code(1);
15891626 else if (*command & FTRACE_DISABLE_CALLS)
@@ -1597,6 +1634,18 @@ static int __ftrace_modify_code(void *data) · 7 unmodified lines
15971634 else if (*command & FTRACE_STOP_FUNC_RET)
15981635 ftrace_disable_ftrace_graph_caller();
15991636
1637+#ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
1638+ /*
1639+ * For archs that call ftrace_test_stop_func(), we must
1640+ * wait till after we update all the function callers
1641+ * before we update the callback. This keeps different
1642+ * ops that record different functions from corrupting
1643+ * each other.
1644+ */
1645+ __ftrace_trace_function = __ftrace_trace_function_delay;
1646+#endif
1647+ function_trace_stop--;
1648+
16001649 return 0;
16011650 }
16021651
@@ -2865,7 +2914,11 @@ ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len, · 1262 unmodified lines
28652914 ftrace_match_records(hash, buf, len);
28662915
28672916 mutex_lock(&ftrace_lock);
2868− ret = ftrace_hash_move(orig_hash, hash);
2917+ ret = ftrace_hash_move(ops, enable, orig_hash, hash);
2918+ if (!ret && ops->flags & FTRACE_OPS_FL_ENABLED
2919+ && ftrace_enabled)
2920+ ftrace_run_update_code(FTRACE_ENABLE_CALLS);
2921+
28692922 mutex_unlock(&ftrace_lock);
28702923
28712924 mutex_unlock(&ftrace_regex_lock);
@@ -3048,18 +3101,12 @@ ftrace_regex_release(struct inode *inode, struct file *file) · 176 unmodified lines
30483101 orig_hash = &iter->ops->notrace_hash;
30493102
30503103 mutex_lock(&ftrace_lock);
3051− /*
3052− * Remove the current set, update the hash and add
3053− * them back.
3054− */
3055− ftrace_hash_rec_disable(iter->ops, filter_hash);
3056− ret = ftrace_hash_move(orig_hash, iter->hash);
3057− if (!ret) {
3058− ftrace_hash_rec_enable(iter->ops, filter_hash);
3059− if (iter->ops->flags & FTRACE_OPS_FL_ENABLED
3060− && ftrace_enabled)
3061− ftrace_run_update_code(FTRACE_ENABLE_CALLS);
3062− }
3104+ ret = ftrace_hash_move(iter->ops, filter_hash,
3105+ orig_hash, iter->hash);
3106+ if (!ret && (iter->ops->flags & FTRACE_OPS_FL_ENABLED)
3107+ && ftrace_enabled)
3108+ ftrace_run_update_code(FTRACE_ENABLE_CALLS);
3109+
30633110 mutex_unlock(&ftrace_lock);
30643111 }
30653112 free_ftrace_hash(iter->hash);
@@ -3338,7 +3385,7 @@ static int ftrace_process_locs(struct module *mod, · 272 unmodified lines
33383385 {
33393386 unsigned long *p;
33403387 unsigned long addr;
3341− unsigned long flags;
3388+ unsigned long flags = 0; /* Shut up gcc */
33423389
33433390 mutex_lock(&ftrace_lock);
33443391 p = start;
@@ -3356,12 +3403,18 @@ static int ftrace_process_locs(struct module *mod, · 11 unmodified lines
33563403 }
33573404
33583405 /*
3359− * Disable interrupts to prevent interrupts from executing
3360− * code that is being modified.
3406+ * We only need to disable interrupts on start up
3407+ * because we are modifying code that an interrupt
3408+ * may execute, and the modification is not atomic.
3409+ * But for modules, nothing runs the code we modify
3410+ * until we are finished with it, and there's no
3411+ * reason to cause large interrupt latencies while we do it.
33613412 */
3362− local_irq_save(flags);
3413+ if (!mod)
3414+ local_irq_save(flags);
33633415 ftrace_update_code(mod);
3364− local_irq_restore(flags);
3416+ if (!mod)
3417+ local_irq_restore(flags);
33653418 mutex_unlock(&ftrace_lock);
33663419
33673420 return 0;
kernel/trace/trace.c+79−13
@@ -1248,6 +1248,15 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data, · 1247 unmodified lines
12481248 }
12491249
12501250 #ifdef CONFIG_STACKTRACE
1251+
1252+#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
1253+struct ftrace_stack {
1254+ unsigned long calls[FTRACE_STACK_MAX_ENTRIES];
1255+};
1256+
1257+static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);
1258+static DEFINE_PER_CPU(int, ftrace_stack_reserve);
1259+
12511260 static void __ftrace_trace_stack(struct ring_buffer *buffer,
12521261 unsigned long flags,
12531262 int skip, int pc, struct pt_regs *regs)
@@ -1256,25 +1265,77 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer, · 2 unmodified lines
12561265 struct ring_buffer_event *event;
12571266 struct stack_entry *entry;
12581267 struct stack_trace trace;
1268+ int use_stack;
1269+ int size = FTRACE_STACK_ENTRIES;
1270+
1271+ trace.nr_entries = 0;
1272+ trace.skip = skip;
1273+
1274+ /*
1275+ * Since events can happen in NMIs there's no safe way to
1276+ * use the per cpu ftrace_stacks. We reserve it and if an interrupt
1277+ * or NMI comes in, it will just have to use the default
1278+ * FTRACE_STACK_SIZE.
1279+ */
1280+ preempt_disable_notrace();
1281+
1282+ use_stack = ++__get_cpu_var(ftrace_stack_reserve);
1283+ /*
1284+ * We don't need any atomic variables, just a barrier.
1285+ * If an interrupt comes in, we don't care, because it would
1286+ * have exited and put the counter back to what we want.
1287+ * We just need a barrier to keep gcc from moving things
1288+ * around.
1289+ */
1290+ barrier();
1291+ if (use_stack == 1) {
1292+ trace.entries = &__get_cpu_var(ftrace_stack).calls[0];
1293+ trace.max_entries = FTRACE_STACK_MAX_ENTRIES;
1294+
1295+ if (regs)
1296+ save_stack_trace_regs(regs, &trace);
1297+ else
1298+ save_stack_trace(&trace);
1299+
1300+ if (trace.nr_entries > size)
1301+ size = trace.nr_entries;
1302+ } else
1303+ /* From now on, use_stack is a boolean */
1304+ use_stack = 0;
1305+
1306+ size *= sizeof(unsigned long);
12591307
12601308 event = trace_buffer_lock_reserve(buffer, TRACE_STACK,
1261− sizeof(*entry), flags, pc);
1309+ sizeof(*entry) + size, flags, pc);
12621310 if (!event)
1263− return;
1264− entry = ring_buffer_event_data(event);
1265− memset(&entry->caller, 0, sizeof(entry->caller));
1311+ goto out;
1312+ entry = ring_buffer_event_data(event);
12661313
1267− trace.nr_entries = 0;
1268− trace.max_entries = FTRACE_STACK_ENTRIES;
1269− trace.skip = skip;
1270− trace.entries = entry->caller;
1314+ memset(&entry->caller, 0, size);
1315+
1316+ if (use_stack)
1317+ memcpy(&entry->caller, trace.entries,
1318+ trace.nr_entries * sizeof(unsigned long));
1319+ else {
1320+ trace.max_entries = FTRACE_STACK_ENTRIES;
1321+ trace.entries = entry->caller;
1322+ if (regs)
1323+ save_stack_trace_regs(regs, &trace);
1324+ else
1325+ save_stack_trace(&trace);
1326+ }
1327+
1328+ entry->size = trace.nr_entries;
12711329
1272− if (regs)
1273− save_stack_trace_regs(regs, &trace);
1274− else
1275− save_stack_trace(&trace);
12761330 if (!filter_check_discard(call, entry, buffer, event))
12771331 ring_buffer_unlock_commit(buffer, event);
1332+
1333+ out:
1334+ /* Again, don't let gcc optimize things here */
1335+ barrier();
1336+ __get_cpu_var(ftrace_stack_reserve)--;
1337+ preempt_enable_notrace();
1338+
12781339 }
12791340
12801341 void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
@@ -1562,7 +1623,12 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, · 281 unmodified lines
15621623
15631624 ftrace_enable_cpu();
15641625
1565− return event ? ring_buffer_event_data(event) : NULL;
1626+ if (event) {
1627+ iter->ent_size = ring_buffer_event_length(event);
1628+ return ring_buffer_event_data(event);
1629+ }
1630+ iter->ent_size = 0;
1631+ return NULL;
15661632 }
15671633
15681634 static struct trace_entry *
kernel/trace/trace.h+34−16
@@ -278,6 +278,29 @@ struct tracer { · 277 unmodified lines
278278 };
279279
280280
281+/* Only current can touch trace_recursion */
282+#define trace_recursion_inc() do { (current)->trace_recursion++; } while (0)
283+#define trace_recursion_dec() do { (current)->trace_recursion--; } while (0)
284+
285+/* Ring buffer has the 10 LSB bits to count */
286+#define trace_recursion_buffer() ((current)->trace_recursion & 0x3ff)
287+
288+/* for function tracing recursion */
289+#define TRACE_INTERNAL_BIT (1<<11)
290+#define TRACE_GLOBAL_BIT (1<<12)
291+/*
292+ * Abuse of the trace_recursion.
293+ * As we need a way to maintain state if we are tracing the function
294+ * graph in irq because we want to trace a particular function that
295+ * was called in irq context but we have irq tracing off. Since this
296+ * can only be modified by current, we can reuse trace_recursion.
297+ */
298+#define TRACE_IRQ_BIT (1<<13)
299+
300+#define trace_recursion_set(bit) do { (current)->trace_recursion |= (bit); } while (0)
301+#define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(bit); } while (0)
302+#define trace_recursion_test(bit) ((current)->trace_recursion & (bit))
303+
281304 #define TRACE_PIPE_ALL_CPU -1
282305
283306 int tracer_init(struct tracer *t, struct trace_array *tr);
@@ -516,8 +539,18 @@ static inline int ftrace_graph_addr(unsigned long addr) · 232 unmodified lines
516539 return 1;
517540
518541 for (i = 0; i < ftrace_graph_count; i++) {
519− if (addr == ftrace_graph_funcs[i])
542+ if (addr == ftrace_graph_funcs[i]) {
543+ /*
544+ * If no irqs are to be traced, but a set_graph_function
545+ * is set, and called by an interrupt handler, we still
546+ * want to trace it.
547+ */
548+ if (in_irq())
549+ trace_recursion_set(TRACE_IRQ_BIT);
550+ else
551+ trace_recursion_clear(TRACE_IRQ_BIT);
520552 return 1;
553+ }
521554 }
522555
523556 return 0;
@@ -795,19 +828,4 @@ extern const char *__stop___trace_bprintk_fmt[]; · 271 unmodified lines
795828 FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
796829 #include "trace_entries.h"
797830
798−/* Only current can touch trace_recursion */
799−#define trace_recursion_inc() do { (current)->trace_recursion++; } while (0)
800−#define trace_recursion_dec() do { (current)->trace_recursion--; } while (0)
801−
802−/* Ring buffer has the 10 LSB bits to count */
803−#define trace_recursion_buffer() ((current)->trace_recursion & 0x3ff)
804−
805−/* for function tracing recursion */
806−#define TRACE_INTERNAL_BIT (1<<11)
807−#define TRACE_GLOBAL_BIT (1<<12)
808−
809−#define trace_recursion_set(bit) do { (current)->trace_recursion |= (bit); } while (0)
810−#define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(bit); } while (0)
811−#define trace_recursion_test(bit) ((current)->trace_recursion & (bit))
812−
813831 #endif /* _LINUX_KERNEL_TRACE_H */
kernel/trace/trace_entries.h+2−1
@@ -161,7 +161,8 @@ FTRACE_ENTRY(kernel_stack, stack_entry, · 160 unmodified lines
161161 TRACE_STACK,
162162
163163 F_STRUCT(
164− __array( unsigned long, caller, FTRACE_STACK_ENTRIES )
164+ __field( int, size )
165+ __dynamic_array(unsigned long, caller )
165166 ),
166167
167168 F_printk("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
kernel/trace/trace_functions_graph.c+1−1
@@ -227,7 +227,7 @@ int __trace_graph_entry(struct trace_array *tr, · 226 unmodified lines
227227
228228 static inline int ftrace_graph_ignore_irqs(void)
229229 {
230− if (!ftrace_graph_skip_irqs)
230+ if (!ftrace_graph_skip_irqs || trace_recursion_test(TRACE_IRQ_BIT))
231231 return 0;
232232
233233 return in_irq();
kernel/trace/trace_kprobe.c+223−95
@@ -343,6 +343,14 @@ DEFINE_BASIC_FETCH_FUNCS(deref) · 342 unmodified lines
343343 DEFINE_FETCH_deref(string)
344344 DEFINE_FETCH_deref(string_size)
345345
346+static __kprobes void update_deref_fetch_param(struct deref_fetch_param *data)
347+{
348+ if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
349+ update_deref_fetch_param(data->orig.data);
350+ else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn))
351+ update_symbol_cache(data->orig.data);
352+}
353+
346354 static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data)
347355 {
348356 if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
@@ -376,6 +384,19 @@ DEFINE_BASIC_FETCH_FUNCS(bitfield) · 27 unmodified lines
376384 #define fetch_bitfield_string NULL
377385 #define fetch_bitfield_string_size NULL
378386
387+static __kprobes void
388+update_bitfield_fetch_param(struct bitfield_fetch_param *data)
389+{
390+ /*
391+ * Don't check the bitfield itself, because this must be the
392+ * last fetch function.
393+ */
394+ if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
395+ update_deref_fetch_param(data->orig.data);
396+ else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn))
397+ update_symbol_cache(data->orig.data);
398+}
399+
379400 static __kprobes void
380401 free_bitfield_fetch_param(struct bitfield_fetch_param *data)
381402 {
@@ -389,6 +410,7 @@ free_bitfield_fetch_param(struct bitfield_fetch_param *data) · 7 unmodified lines
389410 free_symbol_cache(data->orig.data);
390411 kfree(data);
391412 }
413+
392414 /* Default (unsigned long) fetch type */
393415 #define __DEFAULT_FETCH_TYPE(t) u##t
394416 #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
@@ -536,6 +558,7 @@ struct probe_arg { · 141 unmodified lines
536558 /* Flags for trace_probe */
537559 #define TP_FLAG_TRACE 1
538560 #define TP_FLAG_PROFILE 2
561+#define TP_FLAG_REGISTERED 4
539562
540563 struct trace_probe {
541564 struct list_head list;
@@ -555,16 +578,49 @@ struct trace_probe { · 13 unmodified lines
555578 (sizeof(struct probe_arg) * (n)))
556579
557580
558−static __kprobes int probe_is_return(struct trace_probe *tp)
581+static __kprobes int trace_probe_is_return(struct trace_probe *tp)
559582 {
560583 return tp->rp.handler != NULL;
561584 }
562585
563−static __kprobes const char *probe_symbol(struct trace_probe *tp)
586+static __kprobes const char *trace_probe_symbol(struct trace_probe *tp)
564587 {
565588 return tp->symbol ? tp->symbol : "unknown";
566589 }
567590
591+static __kprobes unsigned long trace_probe_offset(struct trace_probe *tp)
592+{
593+ return tp->rp.kp.offset;
594+}
595+
596+static __kprobes bool trace_probe_is_enabled(struct trace_probe *tp)
597+{
598+ return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE));
599+}
600+
601+static __kprobes bool trace_probe_is_registered(struct trace_probe *tp)
602+{
603+ return !!(tp->flags & TP_FLAG_REGISTERED);
604+}
605+
606+static __kprobes bool trace_probe_has_gone(struct trace_probe *tp)
607+{
608+ return !!(kprobe_gone(&tp->rp.kp));
609+}
610+
611+static __kprobes bool trace_probe_within_module(struct trace_probe *tp,
612+ struct module *mod)
613+{
614+ int len = strlen(mod->name);
615+ const char *name = trace_probe_symbol(tp);
616+ return strncmp(mod->name, name, len) == 0 && name[len] == ':';
617+}
618+
619+static __kprobes bool trace_probe_is_on_module(struct trace_probe *tp)
620+{
621+ return !!strchr(trace_probe_symbol(tp), ':');
622+}
623+
568624 static int register_probe_event(struct trace_probe *tp);
569625 static void unregister_probe_event(struct trace_probe *tp);
570626
@@ -646,6 +702,16 @@ error: · 75 unmodified lines
646702 return ERR_PTR(ret);
647703 }
648704
705+static void update_probe_arg(struct probe_arg *arg)
706+{
707+ if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn))
708+ update_bitfield_fetch_param(arg->fetch.data);
709+ else if (CHECK_FETCH_FUNCS(deref, arg->fetch.fn))
710+ update_deref_fetch_param(arg->fetch.data);
711+ else if (CHECK_FETCH_FUNCS(symbol, arg->fetch.fn))
712+ update_symbol_cache(arg->fetch.data);
713+}
714+
649715 static void free_probe_arg(struct probe_arg *arg)
650716 {
651717 if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn))
@@ -671,7 +737,7 @@ static void free_trace_probe(struct trace_probe *tp) · 19 unmodified lines
671737 kfree(tp);
672738 }
673739
674−static struct trace_probe *find_probe_event(const char *event,
740+static struct trace_probe *find_trace_probe(const char *event,
675741 const char *group)
676742 {
677743 struct trace_probe *tp;
@@ -683,13 +749,96 @@ static struct trace_probe *find_probe_event(const char *event, · 5 unmodified lines
683749 return NULL;
684750 }
685751
752+/* Enable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
753+static int enable_trace_probe(struct trace_probe *tp, int flag)
754+{
755+ int ret = 0;
756+
757+ tp->flags |= flag;
758+ if (trace_probe_is_enabled(tp) && trace_probe_is_registered(tp) &&
759+ !trace_probe_has_gone(tp)) {
760+ if (trace_probe_is_return(tp))
761+ ret = enable_kretprobe(&tp->rp);
762+ else
763+ ret = enable_kprobe(&tp->rp.kp);
764+ }
765+
766+ return ret;
767+}
768+
769+/* Disable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
770+static void disable_trace_probe(struct trace_probe *tp, int flag)
771+{
772+ tp->flags &= ~flag;
773+ if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) {
774+ if (trace_probe_is_return(tp))
775+ disable_kretprobe(&tp->rp);
776+ else
777+ disable_kprobe(&tp->rp.kp);
778+ }
779+}
780+
781+/* Internal register function - just handle k*probes and flags */
782+static int __register_trace_probe(struct trace_probe *tp)
783+{
784+ int i, ret;
785+
786+ if (trace_probe_is_registered(tp))
787+ return -EINVAL;
788+
789+ for (i = 0; i < tp->nr_args; i++)
790+ update_probe_arg(&tp->args[i]);
791+
792+ /* Set/clear disabled flag according to tp->flag */
793+ if (trace_probe_is_enabled(tp))
794+ tp->rp.kp.flags &= ~KPROBE_FLAG_DISABLED;
795+ else
796+ tp->rp.kp.flags |= KPROBE_FLAG_DISABLED;
797+
798+ if (trace_probe_is_return(tp))
799+ ret = register_kretprobe(&tp->rp);
800+ else
801+ ret = register_kprobe(&tp->rp.kp);
802+
803+ if (ret == 0)
804+ tp->flags |= TP_FLAG_REGISTERED;
805+ else {
806+ pr_warning("Could not insert probe at %s+%lu: %d\n",
807+ trace_probe_symbol(tp), trace_probe_offset(tp), ret);
808+ if (ret == -ENOENT && trace_probe_is_on_module(tp)) {
809+ pr_warning("This probe might be able to register after"
810+ "target module is loaded. Continue.\n");
811+ ret = 0;
812+ } else if (ret == -EILSEQ) {
813+ pr_warning("Probing address(0x%p) is not an "
814+ "instruction boundary.\n",
815+ tp->rp.kp.addr);
816+ ret = -EINVAL;
817+ }
818+ }
819+
820+ return ret;
821+}
822+
823+/* Internal unregister function - just handle k*probes and flags */
824+static void __unregister_trace_probe(struct trace_probe *tp)
825+{
826+ if (trace_probe_is_registered(tp)) {
827+ if (trace_probe_is_return(tp))
828+ unregister_kretprobe(&tp->rp);
829+ else
830+ unregister_kprobe(&tp->rp.kp);
831+ tp->flags &= ~TP_FLAG_REGISTERED;
832+ /* Cleanup kprobe for reuse */
833+ if (tp->rp.kp.symbol_name)
834+ tp->rp.kp.addr = NULL;
835+ }
836+}
837+
686838 /* Unregister a trace_probe and probe_event: call with locking probe_lock */
687839 static void unregister_trace_probe(struct trace_probe *tp)
688840 {
689− if (probe_is_return(tp))
690− unregister_kretprobe(&tp->rp);
691− else
692− unregister_kprobe(&tp->rp.kp);
841+ __unregister_trace_probe(tp);
693842 list_del(&tp->list);
694843 unregister_probe_event(tp);
695844 }
@@ -702,41 +851,65 @@ static int register_trace_probe(struct trace_probe *tp) · 6 unmodified lines
702851
703852 mutex_lock(&probe_lock);
704853
705− /* register as an event */
706− old_tp = find_probe_event(tp->call.name, tp->call.class->system);
854+ /* Delete old (same name) event if exist */
855+ old_tp = find_trace_probe(tp->call.name, tp->call.class->system);
707856 if (old_tp) {
708− /* delete old event */
709857 unregister_trace_probe(old_tp);
710858 free_trace_probe(old_tp);
711859 }
860+
861+ /* Register new event */
712862 ret = register_probe_event(tp);
713863 if (ret) {
714864 pr_warning("Failed to register probe event(%d)\n", ret);
715865 goto end;
716866 }
717867
718− tp->rp.kp.flags |= KPROBE_FLAG_DISABLED;
719− if (probe_is_return(tp))
720− ret = register_kretprobe(&tp->rp);
721− else
722− ret = register_kprobe(&tp->rp.kp);
723−
724− if (ret) {
725− pr_warning("Could not insert probe(%d)\n", ret);
726− if (ret == -EILSEQ) {
727− pr_warning("Probing address(0x%p) is not an "
728− "instruction boundary.\n",
729− tp->rp.kp.addr);
730− ret = -EINVAL;
731− }
868+ /* Register k*probe */
869+ ret = __register_trace_probe(tp);
870+ if (ret < 0)
732871 unregister_probe_event(tp);
733− } else
872+ else
734873 list_add_tail(&tp->list, &probe_list);
874+
735875 end:
736876 mutex_unlock(&probe_lock);
737877 return ret;
738878 }
739879
880+/* Module notifier call back, checking event on the module */
881+static int trace_probe_module_callback(struct notifier_block *nb,
882+ unsigned long val, void *data)
883+{
884+ struct module *mod = data;
885+ struct trace_probe *tp;
886+ int ret;
887+
888+ if (val != MODULE_STATE_COMING)
889+ return NOTIFY_DONE;
890+
891+ /* Update probes on coming module */
892+ mutex_lock(&probe_lock);
893+ list_for_each_entry(tp, &probe_list, list) {
894+ if (trace_probe_within_module(tp, mod)) {
895+ __unregister_trace_probe(tp);
896+ ret = __register_trace_probe(tp);
897+ if (ret)
898+ pr_warning("Failed to re-register probe %s on"
899+ "%s: %d\n",
900+ tp->call.name, mod->name, ret);
901+ }
902+ }
903+ mutex_unlock(&probe_lock);
904+
905+ return NOTIFY_DONE;
906+}
907+
908+static struct notifier_block trace_probe_module_nb = {
909+ .notifier_call = trace_probe_module_callback,
910+ .priority = 1 /* Invoked after kprobe module callback */
911+};
912+
740913 /* Split symbol and offset. */
741914 static int split_symbol_offset(char *symbol, unsigned long *offset)
742915 {
@@ -962,8 +1135,8 @@ static int create_trace_probe(int argc, char **argv) · 219 unmodified lines
9621135 {
9631136 /*
9641137 * Argument syntax:
965− * - Add kprobe: p[:[GRP/]EVENT] KSYM[+OFFS]|KADDR [FETCHARGS]
966− * - Add kretprobe: r[:[GRP/]EVENT] KSYM[+0] [FETCHARGS]
1138+ * - Add kprobe: p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
1139+ * - Add kretprobe: r[:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
9671140 * Fetch args:
9681141 * $retval : fetch return value
9691142 * $stack : fetch stack address
@@ -1025,7 +1198,7 @@ static int create_trace_probe(int argc, char **argv) · 55 unmodified lines
10251198 return -EINVAL;
10261199 }
10271200 mutex_lock(&probe_lock);
1028− tp = find_probe_event(event, group);
1201+ tp = find_trace_probe(event, group);
10291202 if (!tp) {
10301203 mutex_unlock(&probe_lock);
10311204 pr_info("Event %s/%s doesn't exist.\n", group, event);
@@ -1144,7 +1317,7 @@ error: · 112 unmodified lines
11441317 return ret;
11451318 }
11461319
1147−static void cleanup_all_probes(void)
1320+static void release_all_trace_probes(void)
11481321 {
11491322 struct trace_probe *tp;
11501323
@@ -1158,7 +1331,6 @@ static void cleanup_all_probes(void) · 7 unmodified lines
11581331 mutex_unlock(&probe_lock);
11591332 }
11601333
1161−
11621334 /* Probes listing interfaces */
11631335 static void *probes_seq_start(struct seq_file *m, loff_t *pos)
11641336 {
@@ -1181,15 +1353,16 @@ static int probes_seq_show(struct seq_file *m, void *v) · 16 unmodified lines
11811353 struct trace_probe *tp = v;
11821354 int i;
11831355
1184− seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p');
1356+ seq_printf(m, "%c", trace_probe_is_return(tp) ? 'r' : 'p');
11851357 seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name);
11861358
11871359 if (!tp->symbol)
11881360 seq_printf(m, " 0x%p", tp->rp.kp.addr);
11891361 else if (tp->rp.kp.offset)
1190− seq_printf(m, " %s+%u", probe_symbol(tp), tp->rp.kp.offset);
1362+ seq_printf(m, " %s+%u", trace_probe_symbol(tp),
1363+ tp->rp.kp.offset);
11911364 else
1192− seq_printf(m, " %s", probe_symbol(tp));
1365+ seq_printf(m, " %s", trace_probe_symbol(tp));
11931366
11941367 for (i = 0; i < tp->nr_args; i++)
11951368 seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm);
@@ -1209,7 +1382,7 @@ static int probes_open(struct inode *inode, struct file *file) · 13 unmodified lines
12091382 {
12101383 if ((file->f_mode & FMODE_WRITE) &&
12111384 (file->f_flags & O_TRUNC))
1212− cleanup_all_probes();
1385+ release_all_trace_probes();
12131386
12141387 return seq_open(file, &probes_seq_op);
12151388 }
@@ -1513,30 +1686,6 @@ partial: · 297 unmodified lines
15131686 return TRACE_TYPE_PARTIAL_LINE;
15141687 }
15151688
1516−static int probe_event_enable(struct ftrace_event_call *call)
1517−{
1518− struct trace_probe *tp = (struct trace_probe *)call->data;
1519−
1520− tp->flags |= TP_FLAG_TRACE;
1521− if (probe_is_return(tp))
1522− return enable_kretprobe(&tp->rp);
1523− else
1524− return enable_kprobe(&tp->rp.kp);
1525−}
1526−
1527−static void probe_event_disable(struct ftrace_event_call *call)
1528−{
1529− struct trace_probe *tp = (struct trace_probe *)call->data;
1530−
1531− tp->flags &= ~TP_FLAG_TRACE;
1532− if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
1533− if (probe_is_return(tp))
1534− disable_kretprobe(&tp->rp);
1535− else
1536− disable_kprobe(&tp->rp.kp);
1537− }
1538−}
1539−
15401689 #undef DEFINE_FIELD
15411690 #define DEFINE_FIELD(type, item, name, is_signed) \
15421691 do { \
@@ -1598,7 +1747,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len) · 55 unmodified lines
15981747
15991748 const char *fmt, *arg;
16001749
1601− if (!probe_is_return(tp)) {
1750+ if (!trace_probe_is_return(tp)) {
16021751 fmt = "(%lx)";
16031752 arg = "REC->" FIELD_STRING_IP;
16041753 } else {
@@ -1715,49 +1864,25 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, · 110 unmodified lines
17151864 head = this_cpu_ptr(call->perf_events);
17161865 perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head);
17171866 }
1718−
1719−static int probe_perf_enable(struct ftrace_event_call *call)
1720−{
1721− struct trace_probe *tp = (struct trace_probe *)call->data;
1722−
1723− tp->flags |= TP_FLAG_PROFILE;
1724−
1725− if (probe_is_return(tp))
1726− return enable_kretprobe(&tp->rp);
1727− else
1728− return enable_kprobe(&tp->rp.kp);
1729−}
1730−
1731−static void probe_perf_disable(struct ftrace_event_call *call)
1732−{
1733− struct trace_probe *tp = (struct trace_probe *)call->data;
1734−
1735− tp->flags &= ~TP_FLAG_PROFILE;
1736−
1737− if (!(tp->flags & TP_FLAG_TRACE)) {
1738− if (probe_is_return(tp))
1739− disable_kretprobe(&tp->rp);
1740− else
1741− disable_kprobe(&tp->rp.kp);
1742− }
1743−}
17441867 #endif /* CONFIG_PERF_EVENTS */
17451868
17461869 static __kprobes
17471870 int kprobe_register(struct ftrace_event_call *event, enum trace_reg type)
17481871 {
1872+ struct trace_probe *tp = (struct trace_probe *)event->data;
1873+
17491874 switch (type) {
17501875 case TRACE_REG_REGISTER:
1751− return probe_event_enable(event);
1876+ return enable_trace_probe(tp, TP_FLAG_TRACE);
17521877 case TRACE_REG_UNREGISTER:
1753− probe_event_disable(event);
1878+ disable_trace_probe(tp, TP_FLAG_TRACE);
17541879 return 0;
17551880
17561881 #ifdef CONFIG_PERF_EVENTS
17571882 case TRACE_REG_PERF_REGISTER:
1758− return probe_perf_enable(event);
1883+ return enable_trace_probe(tp, TP_FLAG_PROFILE);
17591884 case TRACE_REG_PERF_UNREGISTER:
1760− probe_perf_disable(event);
1885+ disable_trace_probe(tp, TP_FLAG_PROFILE);
17611886 return 0;
17621887 #endif
17631888 }
@@ -1807,7 +1932,7 @@ static int register_probe_event(struct trace_probe *tp) · 43 unmodified lines
18071932
18081933 /* Initialize ftrace_event_call */
18091934 INIT_LIST_HEAD(&call->class->fields);
1810− if (probe_is_return(tp)) {
1935+ if (trace_probe_is_return(tp)) {
18111936 call->event.funcs = &kretprobe_funcs;
18121937 call->class->define_fields = kretprobe_event_define_fields;
18131938 } else {
@@ -1846,6 +1971,9 @@ static __init int init_kprobe_trace(void) · 32 unmodified lines
18461971 struct dentry *d_tracer;
18471972 struct dentry *entry;
18481973
1974+ if (register_module_notifier(&trace_probe_module_nb))
1975+ return -EINVAL;
1976+
18491977 d_tracer = tracing_init_dentry();
18501978 if (!d_tracer)
18511979 return 0;
@@ -1899,12 +2027,12 @@ static __init int kprobe_trace_self_tests_init(void) · 47 unmodified lines
18992027 warn++;
19002028 } else {
19012029 /* Enable trace point */
1902− tp = find_probe_event("testprobe", KPROBE_EVENT_SYSTEM);
2030+ tp = find_trace_probe("testprobe", KPROBE_EVENT_SYSTEM);
19032031 if (WARN_ON_ONCE(tp == NULL)) {
19042032 pr_warning("error on getting new probe.\n");
19052033 warn++;
19062034 } else
1907− probe_event_enable(&tp->call);
2035+ enable_trace_probe(tp, TP_FLAG_TRACE);
19082036 }
19092037
19102038 ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target "
@@ -1914,12 +2042,12 @@ static __init int kprobe_trace_self_tests_init(void) · 3 unmodified lines
19142042 warn++;
19152043 } else {
19162044 /* Enable trace point */
1917− tp = find_probe_event("testprobe2", KPROBE_EVENT_SYSTEM);
2045+ tp = find_trace_probe("testprobe2", KPROBE_EVENT_SYSTEM);
19182046 if (WARN_ON_ONCE(tp == NULL)) {
19192047 pr_warning("error on getting new probe.\n");
19202048 warn++;
19212049 } else
1922− probe_event_enable(&tp->call);
2050+ enable_trace_probe(tp, TP_FLAG_TRACE);
19232051 }
19242052
19252053 if (warn)
@@ -1940,7 +2068,7 @@ static __init int kprobe_trace_self_tests_init(void) · 14 unmodified lines
19402068 }
19412069
19422070 end:
1943− cleanup_all_probes();
2071+ release_all_trace_probes();
19442072 if (warn)
19452073 pr_cont("NG: Some tests are failed. Please check them.\n");
19462074 else
kernel/trace/trace_output.c+6−5
@@ -1107,19 +1107,20 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, · 1106 unmodified lines
11071107 {
11081108 struct stack_entry *field;
11091109 struct trace_seq *s = &iter->seq;
1110− int i;
1110+ unsigned long *p;
1111+ unsigned long *end;
11111112
11121113 trace_assign_type(field, iter->ent);
1114+ end = (unsigned long *)((long)iter->ent + iter->ent_size);
11131115
11141116 if (!trace_seq_puts(s, "<stack trace>\n"))
11151117 goto partial;
1116− for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1117− if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
1118− break;
1118+
1119+ for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
11191120 if (!trace_seq_puts(s, " => "))
11201121 goto partial;
11211122
1122− if (!seq_print_ip_sym(s, field->caller[i], flags))
1123+ if (!seq_print_ip_sym(s, *p, flags))
11231124 goto partial;
11241125 if (!trace_seq_puts(s, "\n"))
11251126 goto partial;