hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/trace/trace.c
....@@ -17,6 +17,7 @@
1717 #include <linux/stacktrace.h>
1818 #include <linux/writeback.h>
1919 #include <linux/kallsyms.h>
20
+#include <linux/security.h>
2021 #include <linux/seq_file.h>
2122 #include <linux/notifier.h>
2223 #include <linux/irqflags.h>
....@@ -44,6 +45,10 @@
4445 #include <linux/trace.h>
4546 #include <linux/sched/clock.h>
4647 #include <linux/sched/rt.h>
48
+#include <linux/fsnotify.h>
49
+#include <linux/irq_work.h>
50
+#include <linux/workqueue.h>
51
+#include <trace/hooks/ftrace_dump.h>
4752
4853 #include "trace.h"
4954 #include "trace_output.h"
....@@ -64,9 +69,20 @@
6469 static bool __read_mostly tracing_selftest_running;
6570
6671 /*
67
- * If a tracer is running, we do not want to run SELFTEST.
72
+ * If boot-time tracing including tracers/events via kernel cmdline
73
+ * is running, we do not want to run SELFTEST.
6874 */
6975 bool __read_mostly tracing_selftest_disabled;
76
+
77
+#ifdef CONFIG_FTRACE_STARTUP_TEST
78
+void __init disable_tracing_selftest(const char *reason)
79
+{
80
+ if (!tracing_selftest_disabled) {
81
+ tracing_selftest_disabled = true;
82
+ pr_info("Ftrace startup test is disabled due to %s\n", reason);
83
+ }
84
+}
85
+#endif
7086
7187 /* Pipe tracepoints to printk */
7288 struct trace_iterator *tracepoint_print_iter;
....@@ -158,7 +174,10 @@
158174 static union trace_eval_map_item *trace_eval_maps;
159175 #endif /* CONFIG_TRACE_EVAL_MAP_FILE */
160176
161
-static int tracing_set_tracer(struct trace_array *tr, const char *buf);
177
+int tracing_set_tracer(struct trace_array *tr, const char *buf);
178
+static void ftrace_trace_userstack(struct trace_array *tr,
179
+ struct trace_buffer *buffer,
180
+ unsigned int trace_ctx);
162181
163182 #define MAX_TRACER_SIZE 100
164183 static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata;
....@@ -215,7 +234,7 @@
215234 static int __init set_trace_boot_options(char *str)
216235 {
217236 strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
218
- return 0;
237
+ return 1;
219238 }
220239 __setup("trace_options=", set_trace_boot_options);
221240
....@@ -226,7 +245,7 @@
226245 {
227246 strlcpy(trace_boot_clock_buf, str, MAX_TRACER_SIZE);
228247 trace_boot_clock = trace_boot_clock_buf;
229
- return 0;
248
+ return 1;
230249 }
231250 __setup("trace_clock=", set_trace_boot_clock);
232251
....@@ -248,6 +267,145 @@
248267 do_div(nsec, 1000);
249268 return nsec;
250269 }
270
+
271
+static void
272
+trace_process_export(struct trace_export *export,
273
+ struct ring_buffer_event *event, int flag)
274
+{
275
+ struct trace_entry *entry;
276
+ unsigned int size = 0;
277
+
278
+ if (export->flags & flag) {
279
+ entry = ring_buffer_event_data(event);
280
+ size = ring_buffer_event_length(event);
281
+ export->write(export, entry, size);
282
+ }
283
+}
284
+
285
+static DEFINE_MUTEX(ftrace_export_lock);
286
+
287
+static struct trace_export __rcu *ftrace_exports_list __read_mostly;
288
+
289
+static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled);
290
+static DEFINE_STATIC_KEY_FALSE(trace_event_exports_enabled);
291
+static DEFINE_STATIC_KEY_FALSE(trace_marker_exports_enabled);
292
+
293
+static inline void ftrace_exports_enable(struct trace_export *export)
294
+{
295
+ if (export->flags & TRACE_EXPORT_FUNCTION)
296
+ static_branch_inc(&trace_function_exports_enabled);
297
+
298
+ if (export->flags & TRACE_EXPORT_EVENT)
299
+ static_branch_inc(&trace_event_exports_enabled);
300
+
301
+ if (export->flags & TRACE_EXPORT_MARKER)
302
+ static_branch_inc(&trace_marker_exports_enabled);
303
+}
304
+
305
+static inline void ftrace_exports_disable(struct trace_export *export)
306
+{
307
+ if (export->flags & TRACE_EXPORT_FUNCTION)
308
+ static_branch_dec(&trace_function_exports_enabled);
309
+
310
+ if (export->flags & TRACE_EXPORT_EVENT)
311
+ static_branch_dec(&trace_event_exports_enabled);
312
+
313
+ if (export->flags & TRACE_EXPORT_MARKER)
314
+ static_branch_dec(&trace_marker_exports_enabled);
315
+}
316
+
317
+static void ftrace_exports(struct ring_buffer_event *event, int flag)
318
+{
319
+ struct trace_export *export;
320
+
321
+ preempt_disable_notrace();
322
+
323
+ export = rcu_dereference_raw_check(ftrace_exports_list);
324
+ while (export) {
325
+ trace_process_export(export, event, flag);
326
+ export = rcu_dereference_raw_check(export->next);
327
+ }
328
+
329
+ preempt_enable_notrace();
330
+}
331
+
332
+static inline void
333
+add_trace_export(struct trace_export **list, struct trace_export *export)
334
+{
335
+ rcu_assign_pointer(export->next, *list);
336
+ /*
337
+ * We are entering export into the list but another
338
+ * CPU might be walking that list. We need to make sure
339
+ * the export->next pointer is valid before another CPU sees
340
+ * the export pointer included into the list.
341
+ */
342
+ rcu_assign_pointer(*list, export);
343
+}
344
+
345
+static inline int
346
+rm_trace_export(struct trace_export **list, struct trace_export *export)
347
+{
348
+ struct trace_export **p;
349
+
350
+ for (p = list; *p != NULL; p = &(*p)->next)
351
+ if (*p == export)
352
+ break;
353
+
354
+ if (*p != export)
355
+ return -1;
356
+
357
+ rcu_assign_pointer(*p, (*p)->next);
358
+
359
+ return 0;
360
+}
361
+
362
+static inline void
363
+add_ftrace_export(struct trace_export **list, struct trace_export *export)
364
+{
365
+ ftrace_exports_enable(export);
366
+
367
+ add_trace_export(list, export);
368
+}
369
+
370
+static inline int
371
+rm_ftrace_export(struct trace_export **list, struct trace_export *export)
372
+{
373
+ int ret;
374
+
375
+ ret = rm_trace_export(list, export);
376
+ ftrace_exports_disable(export);
377
+
378
+ return ret;
379
+}
380
+
381
+int register_ftrace_export(struct trace_export *export)
382
+{
383
+ if (WARN_ON_ONCE(!export->write))
384
+ return -1;
385
+
386
+ mutex_lock(&ftrace_export_lock);
387
+
388
+ add_ftrace_export(&ftrace_exports_list, export);
389
+
390
+ mutex_unlock(&ftrace_export_lock);
391
+
392
+ return 0;
393
+}
394
+EXPORT_SYMBOL_GPL(register_ftrace_export);
395
+
396
+int unregister_ftrace_export(struct trace_export *export)
397
+{
398
+ int ret;
399
+
400
+ mutex_lock(&ftrace_export_lock);
401
+
402
+ ret = rm_ftrace_export(&ftrace_exports_list, export);
403
+
404
+ mutex_unlock(&ftrace_export_lock);
405
+
406
+ return ret;
407
+}
408
+EXPORT_SYMBOL_GPL(unregister_ftrace_export);
251409
252410 /* trace_flags holds trace_options default values */
253411 #define TRACE_DEFAULT_FLAGS \
....@@ -299,15 +457,44 @@
299457 this_tr->ref--;
300458 }
301459
460
+/**
461
+ * trace_array_put - Decrement the reference counter for this trace array.
462
+ *
463
+ * NOTE: Use this when we no longer need the trace array returned by
464
+ * trace_array_get_by_name(). This ensures the trace array can be later
465
+ * destroyed.
466
+ *
467
+ */
302468 void trace_array_put(struct trace_array *this_tr)
303469 {
470
+ if (!this_tr)
471
+ return;
472
+
304473 mutex_lock(&trace_types_lock);
305474 __trace_array_put(this_tr);
306475 mutex_unlock(&trace_types_lock);
307476 }
477
+EXPORT_SYMBOL_GPL(trace_array_put);
478
+
479
+int tracing_check_open_get_tr(struct trace_array *tr)
480
+{
481
+ int ret;
482
+
483
+ ret = security_locked_down(LOCKDOWN_TRACEFS);
484
+ if (ret)
485
+ return ret;
486
+
487
+ if (tracing_disabled)
488
+ return -ENODEV;
489
+
490
+ if (tr && trace_array_get(tr) < 0)
491
+ return -ENODEV;
492
+
493
+ return 0;
494
+}
308495
309496 int call_filter_check_discard(struct trace_event_call *call, void *rec,
310
- struct ring_buffer *buffer,
497
+ struct trace_buffer *buffer,
311498 struct ring_buffer_event *event)
312499 {
313500 if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
....@@ -355,20 +542,26 @@
355542 * Returns false if @task should be traced.
356543 */
357544 bool
358
-trace_ignore_this_task(struct trace_pid_list *filtered_pids, struct task_struct *task)
545
+trace_ignore_this_task(struct trace_pid_list *filtered_pids,
546
+ struct trace_pid_list *filtered_no_pids,
547
+ struct task_struct *task)
359548 {
360549 /*
361
- * Return false, because if filtered_pids does not exist,
362
- * all pids are good to trace.
550
+ * If filterd_no_pids is not empty, and the task's pid is listed
551
+ * in filtered_no_pids, then return true.
552
+ * Otherwise, if filtered_pids is empty, that means we can
553
+ * trace all tasks. If it has content, then only trace pids
554
+ * within filtered_pids.
363555 */
364
- if (!filtered_pids)
365
- return false;
366556
367
- return !trace_find_filtered_pid(filtered_pids, task->pid);
557
+ return (filtered_pids &&
558
+ !trace_find_filtered_pid(filtered_pids, task->pid)) ||
559
+ (filtered_no_pids &&
560
+ trace_find_filtered_pid(filtered_no_pids, task->pid));
368561 }
369562
370563 /**
371
- * trace_pid_filter_add_remove_task - Add or remove a task from a pid_list
564
+ * trace_filter_add_remove_task - Add or remove a task from a pid_list
372565 * @pid_list: The list to modify
373566 * @self: The current task for fork or NULL for exit
374567 * @task: The task to add or remove
....@@ -572,7 +765,7 @@
572765 return read;
573766 }
574767
575
-static u64 buffer_ftrace_now(struct trace_buffer *buf, int cpu)
768
+static u64 buffer_ftrace_now(struct array_buffer *buf, int cpu)
576769 {
577770 u64 ts;
578771
....@@ -588,7 +781,7 @@
588781
589782 u64 ftrace_now(int cpu)
590783 {
591
- return buffer_ftrace_now(&global_trace.trace_buffer, cpu);
784
+ return buffer_ftrace_now(&global_trace.array_buffer, cpu);
592785 }
593786
594787 /**
....@@ -716,24 +909,24 @@
716909 #endif
717910
718911 #ifdef CONFIG_STACKTRACE
719
-static void __ftrace_trace_stack(struct ring_buffer *buffer,
720
- unsigned long flags,
721
- int skip, int pc, struct pt_regs *regs);
912
+static void __ftrace_trace_stack(struct trace_buffer *buffer,
913
+ unsigned int trace_ctx,
914
+ int skip, struct pt_regs *regs);
722915 static inline void ftrace_trace_stack(struct trace_array *tr,
723
- struct ring_buffer *buffer,
724
- unsigned long flags,
725
- int skip, int pc, struct pt_regs *regs);
916
+ struct trace_buffer *buffer,
917
+ unsigned int trace_ctx,
918
+ int skip, struct pt_regs *regs);
726919
727920 #else
728
-static inline void __ftrace_trace_stack(struct ring_buffer *buffer,
729
- unsigned long flags,
730
- int skip, int pc, struct pt_regs *regs)
921
+static inline void __ftrace_trace_stack(struct trace_buffer *buffer,
922
+ unsigned int trace_ctx,
923
+ int skip, struct pt_regs *regs)
731924 {
732925 }
733926 static inline void ftrace_trace_stack(struct trace_array *tr,
734
- struct ring_buffer *buffer,
735
- unsigned long flags,
736
- int skip, int pc, struct pt_regs *regs)
927
+ struct trace_buffer *buffer,
928
+ unsigned long trace_ctx,
929
+ int skip, struct pt_regs *regs)
737930 {
738931 }
739932
....@@ -741,33 +934,32 @@
741934
742935 static __always_inline void
743936 trace_event_setup(struct ring_buffer_event *event,
744
- int type, unsigned long flags, int pc)
937
+ int type, unsigned int trace_ctx)
745938 {
746939 struct trace_entry *ent = ring_buffer_event_data(event);
747940
748
- tracing_generic_entry_update(ent, flags, pc);
749
- ent->type = type;
941
+ tracing_generic_entry_update(ent, type, trace_ctx);
750942 }
751943
752944 static __always_inline struct ring_buffer_event *
753
-__trace_buffer_lock_reserve(struct ring_buffer *buffer,
945
+__trace_buffer_lock_reserve(struct trace_buffer *buffer,
754946 int type,
755947 unsigned long len,
756
- unsigned long flags, int pc)
948
+ unsigned int trace_ctx)
757949 {
758950 struct ring_buffer_event *event;
759951
760952 event = ring_buffer_lock_reserve(buffer, len);
761953 if (event != NULL)
762
- trace_event_setup(event, type, flags, pc);
954
+ trace_event_setup(event, type, trace_ctx);
763955
764956 return event;
765957 }
766958
767959 void tracer_tracing_on(struct trace_array *tr)
768960 {
769
- if (tr->trace_buffer.buffer)
770
- ring_buffer_record_on(tr->trace_buffer.buffer);
961
+ if (tr->array_buffer.buffer)
962
+ ring_buffer_record_on(tr->array_buffer.buffer);
771963 /*
772964 * This flag is looked at when buffers haven't been allocated
773965 * yet, or by some tracers (like irqsoff), that just want to
....@@ -795,7 +987,7 @@
795987
796988
797989 static __always_inline void
798
-__buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event)
990
+__buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *event)
799991 {
800992 __this_cpu_write(trace_taskinfo_save, true);
801993
....@@ -818,28 +1010,28 @@
8181010 int __trace_puts(unsigned long ip, const char *str, int size)
8191011 {
8201012 struct ring_buffer_event *event;
821
- struct ring_buffer *buffer;
1013
+ struct trace_buffer *buffer;
8221014 struct print_entry *entry;
823
- unsigned long irq_flags;
1015
+ unsigned int trace_ctx;
8241016 int alloc;
825
- int pc;
8261017
8271018 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
8281019 return 0;
829
-
830
- pc = preempt_count();
8311020
8321021 if (unlikely(tracing_selftest_running || tracing_disabled))
8331022 return 0;
8341023
8351024 alloc = sizeof(*entry) + size + 2; /* possible \n added */
8361025
837
- local_save_flags(irq_flags);
838
- buffer = global_trace.trace_buffer.buffer;
839
- event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc,
840
- irq_flags, pc);
841
- if (!event)
842
- return 0;
1026
+ trace_ctx = tracing_gen_ctx();
1027
+ buffer = global_trace.array_buffer.buffer;
1028
+ ring_buffer_nest_start(buffer);
1029
+ event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc,
1030
+ trace_ctx);
1031
+ if (!event) {
1032
+ size = 0;
1033
+ goto out;
1034
+ }
8431035
8441036 entry = ring_buffer_event_data(event);
8451037 entry->ip = ip;
....@@ -854,8 +1046,9 @@
8541046 entry->buf[size] = '\0';
8551047
8561048 __buffer_unlock_commit(buffer, event);
857
- ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL);
858
-
1049
+ ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL);
1050
+ out:
1051
+ ring_buffer_nest_end(buffer);
8591052 return size;
8601053 }
8611054 EXPORT_SYMBOL_GPL(__trace_puts);
....@@ -868,40 +1061,44 @@
8681061 int __trace_bputs(unsigned long ip, const char *str)
8691062 {
8701063 struct ring_buffer_event *event;
871
- struct ring_buffer *buffer;
1064
+ struct trace_buffer *buffer;
8721065 struct bputs_entry *entry;
873
- unsigned long irq_flags;
1066
+ unsigned int trace_ctx;
8741067 int size = sizeof(struct bputs_entry);
875
- int pc;
1068
+ int ret = 0;
8761069
8771070 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
8781071 return 0;
8791072
880
- pc = preempt_count();
881
-
8821073 if (unlikely(tracing_selftest_running || tracing_disabled))
8831074 return 0;
8841075
885
- local_save_flags(irq_flags);
886
- buffer = global_trace.trace_buffer.buffer;
1076
+ trace_ctx = tracing_gen_ctx();
1077
+ buffer = global_trace.array_buffer.buffer;
1078
+
1079
+ ring_buffer_nest_start(buffer);
8871080 event = __trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size,
888
- irq_flags, pc);
1081
+ trace_ctx);
8891082 if (!event)
890
- return 0;
1083
+ goto out;
8911084
8921085 entry = ring_buffer_event_data(event);
8931086 entry->ip = ip;
8941087 entry->str = str;
8951088
8961089 __buffer_unlock_commit(buffer, event);
897
- ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL);
1090
+ ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL);
8981091
899
- return 1;
1092
+ ret = 1;
1093
+ out:
1094
+ ring_buffer_nest_end(buffer);
1095
+ return ret;
9001096 }
9011097 EXPORT_SYMBOL_GPL(__trace_bputs);
9021098
9031099 #ifdef CONFIG_TRACER_SNAPSHOT
904
-void tracing_snapshot_instance(struct trace_array *tr)
1100
+static void tracing_snapshot_instance_cond(struct trace_array *tr,
1101
+ void *cond_data)
9051102 {
9061103 struct tracer *tracer = tr->current_trace;
9071104 unsigned long flags;
....@@ -927,8 +1124,13 @@
9271124 }
9281125
9291126 local_irq_save(flags);
930
- update_max_tr(tr, current, smp_processor_id());
1127
+ update_max_tr(tr, current, smp_processor_id(), cond_data);
9311128 local_irq_restore(flags);
1129
+}
1130
+
1131
+void tracing_snapshot_instance(struct trace_array *tr)
1132
+{
1133
+ tracing_snapshot_instance_cond(tr, NULL);
9321134 }
9331135
9341136 /**
....@@ -953,9 +1155,59 @@
9531155 }
9541156 EXPORT_SYMBOL_GPL(tracing_snapshot);
9551157
956
-static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
957
- struct trace_buffer *size_buf, int cpu_id);
958
-static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);
1158
+/**
1159
+ * tracing_snapshot_cond - conditionally take a snapshot of the current buffer.
1160
+ * @tr: The tracing instance to snapshot
1161
+ * @cond_data: The data to be tested conditionally, and possibly saved
1162
+ *
1163
+ * This is the same as tracing_snapshot() except that the snapshot is
1164
+ * conditional - the snapshot will only happen if the
1165
+ * cond_snapshot.update() implementation receiving the cond_data
1166
+ * returns true, which means that the trace array's cond_snapshot
1167
+ * update() operation used the cond_data to determine whether the
1168
+ * snapshot should be taken, and if it was, presumably saved it along
1169
+ * with the snapshot.
1170
+ */
1171
+void tracing_snapshot_cond(struct trace_array *tr, void *cond_data)
1172
+{
1173
+ tracing_snapshot_instance_cond(tr, cond_data);
1174
+}
1175
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond);
1176
+
1177
+/**
1178
+ * tracing_snapshot_cond_data - get the user data associated with a snapshot
1179
+ * @tr: The tracing instance
1180
+ *
1181
+ * When the user enables a conditional snapshot using
1182
+ * tracing_snapshot_cond_enable(), the user-defined cond_data is saved
1183
+ * with the snapshot. This accessor is used to retrieve it.
1184
+ *
1185
+ * Should not be called from cond_snapshot.update(), since it takes
1186
+ * the tr->max_lock lock, which the code calling
1187
+ * cond_snapshot.update() has already done.
1188
+ *
1189
+ * Returns the cond_data associated with the trace array's snapshot.
1190
+ */
1191
+void *tracing_cond_snapshot_data(struct trace_array *tr)
1192
+{
1193
+ void *cond_data = NULL;
1194
+
1195
+ local_irq_disable();
1196
+ arch_spin_lock(&tr->max_lock);
1197
+
1198
+ if (tr->cond_snapshot)
1199
+ cond_data = tr->cond_snapshot->cond_data;
1200
+
1201
+ arch_spin_unlock(&tr->max_lock);
1202
+ local_irq_enable();
1203
+
1204
+ return cond_data;
1205
+}
1206
+EXPORT_SYMBOL_GPL(tracing_cond_snapshot_data);
1207
+
1208
+static int resize_buffer_duplicate_size(struct array_buffer *trace_buf,
1209
+ struct array_buffer *size_buf, int cpu_id);
1210
+static void set_buffer_entries(struct array_buffer *buf, unsigned long val);
9591211
9601212 int tracing_alloc_snapshot_instance(struct trace_array *tr)
9611213 {
....@@ -965,7 +1217,7 @@
9651217
9661218 /* allocate spare buffer */
9671219 ret = resize_buffer_duplicate_size(&tr->max_buffer,
968
- &tr->trace_buffer, RING_BUFFER_ALL_CPUS);
1220
+ &tr->array_buffer, RING_BUFFER_ALL_CPUS);
9691221 if (ret < 0)
9701222 return ret;
9711223
....@@ -1032,12 +1284,115 @@
10321284 tracing_snapshot();
10331285 }
10341286 EXPORT_SYMBOL_GPL(tracing_snapshot_alloc);
1287
+
1288
+/**
1289
+ * tracing_snapshot_cond_enable - enable conditional snapshot for an instance
1290
+ * @tr: The tracing instance
1291
+ * @cond_data: User data to associate with the snapshot
1292
+ * @update: Implementation of the cond_snapshot update function
1293
+ *
1294
+ * Check whether the conditional snapshot for the given instance has
1295
+ * already been enabled, or if the current tracer is already using a
1296
+ * snapshot; if so, return -EBUSY, else create a cond_snapshot and
1297
+ * save the cond_data and update function inside.
1298
+ *
1299
+ * Returns 0 if successful, error otherwise.
1300
+ */
1301
+int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data,
1302
+ cond_update_fn_t update)
1303
+{
1304
+ struct cond_snapshot *cond_snapshot;
1305
+ int ret = 0;
1306
+
1307
+ cond_snapshot = kzalloc(sizeof(*cond_snapshot), GFP_KERNEL);
1308
+ if (!cond_snapshot)
1309
+ return -ENOMEM;
1310
+
1311
+ cond_snapshot->cond_data = cond_data;
1312
+ cond_snapshot->update = update;
1313
+
1314
+ mutex_lock(&trace_types_lock);
1315
+
1316
+ ret = tracing_alloc_snapshot_instance(tr);
1317
+ if (ret)
1318
+ goto fail_unlock;
1319
+
1320
+ if (tr->current_trace->use_max_tr) {
1321
+ ret = -EBUSY;
1322
+ goto fail_unlock;
1323
+ }
1324
+
1325
+ /*
1326
+ * The cond_snapshot can only change to NULL without the
1327
+ * trace_types_lock. We don't care if we race with it going
1328
+ * to NULL, but we want to make sure that it's not set to
1329
+ * something other than NULL when we get here, which we can
1330
+ * do safely with only holding the trace_types_lock and not
1331
+ * having to take the max_lock.
1332
+ */
1333
+ if (tr->cond_snapshot) {
1334
+ ret = -EBUSY;
1335
+ goto fail_unlock;
1336
+ }
1337
+
1338
+ local_irq_disable();
1339
+ arch_spin_lock(&tr->max_lock);
1340
+ tr->cond_snapshot = cond_snapshot;
1341
+ arch_spin_unlock(&tr->max_lock);
1342
+ local_irq_enable();
1343
+
1344
+ mutex_unlock(&trace_types_lock);
1345
+
1346
+ return ret;
1347
+
1348
+ fail_unlock:
1349
+ mutex_unlock(&trace_types_lock);
1350
+ kfree(cond_snapshot);
1351
+ return ret;
1352
+}
1353
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond_enable);
1354
+
1355
+/**
1356
+ * tracing_snapshot_cond_disable - disable conditional snapshot for an instance
1357
+ * @tr: The tracing instance
1358
+ *
1359
+ * Check whether the conditional snapshot for the given instance is
1360
+ * enabled; if so, free the cond_snapshot associated with it,
1361
+ * otherwise return -EINVAL.
1362
+ *
1363
+ * Returns 0 if successful, error otherwise.
1364
+ */
1365
+int tracing_snapshot_cond_disable(struct trace_array *tr)
1366
+{
1367
+ int ret = 0;
1368
+
1369
+ local_irq_disable();
1370
+ arch_spin_lock(&tr->max_lock);
1371
+
1372
+ if (!tr->cond_snapshot)
1373
+ ret = -EINVAL;
1374
+ else {
1375
+ kfree(tr->cond_snapshot);
1376
+ tr->cond_snapshot = NULL;
1377
+ }
1378
+
1379
+ arch_spin_unlock(&tr->max_lock);
1380
+ local_irq_enable();
1381
+
1382
+ return ret;
1383
+}
1384
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond_disable);
10351385 #else
10361386 void tracing_snapshot(void)
10371387 {
10381388 WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used");
10391389 }
10401390 EXPORT_SYMBOL_GPL(tracing_snapshot);
1391
+void tracing_snapshot_cond(struct trace_array *tr, void *cond_data)
1392
+{
1393
+ WARN_ONCE(1, "Snapshot feature not enabled, but internal conditional snapshot used");
1394
+}
1395
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond);
10411396 int tracing_alloc_snapshot(void)
10421397 {
10431398 WARN_ONCE(1, "Snapshot feature not enabled, but snapshot allocation used");
....@@ -1050,12 +1405,27 @@
10501405 tracing_snapshot();
10511406 }
10521407 EXPORT_SYMBOL_GPL(tracing_snapshot_alloc);
1408
+void *tracing_cond_snapshot_data(struct trace_array *tr)
1409
+{
1410
+ return NULL;
1411
+}
1412
+EXPORT_SYMBOL_GPL(tracing_cond_snapshot_data);
1413
+int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update)
1414
+{
1415
+ return -ENODEV;
1416
+}
1417
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond_enable);
1418
+int tracing_snapshot_cond_disable(struct trace_array *tr)
1419
+{
1420
+ return false;
1421
+}
1422
+EXPORT_SYMBOL_GPL(tracing_snapshot_cond_disable);
10531423 #endif /* CONFIG_TRACER_SNAPSHOT */
10541424
10551425 void tracer_tracing_off(struct trace_array *tr)
10561426 {
1057
- if (tr->trace_buffer.buffer)
1058
- ring_buffer_record_off(tr->trace_buffer.buffer);
1427
+ if (tr->array_buffer.buffer)
1428
+ ring_buffer_record_off(tr->array_buffer.buffer);
10591429 /*
10601430 * This flag is looked at when buffers haven't been allocated
10611431 * yet, or by some tracers (like irqsoff), that just want to
....@@ -1085,8 +1455,11 @@
10851455
10861456 void disable_trace_on_warning(void)
10871457 {
1088
- if (__disable_trace_on_warning)
1458
+ if (__disable_trace_on_warning) {
1459
+ trace_array_printk_buf(global_trace.array_buffer.buffer, _THIS_IP_,
1460
+ "Disabling tracing due to warning\n");
10891461 tracing_off();
1462
+ }
10901463 }
10911464
10921465 /**
....@@ -1097,8 +1470,8 @@
10971470 */
10981471 bool tracer_tracing_is_on(struct trace_array *tr)
10991472 {
1100
- if (tr->trace_buffer.buffer)
1101
- return ring_buffer_record_is_on(tr->trace_buffer.buffer);
1473
+ if (tr->array_buffer.buffer)
1474
+ return ring_buffer_record_is_on(tr->array_buffer.buffer);
11021475 return !tr->buffer_disabled;
11031476 }
11041477
....@@ -1118,10 +1491,12 @@
11181491 if (!str)
11191492 return 0;
11201493 buf_size = memparse(str, &str);
1121
- /* nr_entries can not be zero */
1122
- if (buf_size == 0)
1123
- return 0;
1124
- trace_buf_size = buf_size;
1494
+ /*
1495
+ * nr_entries can not be zero and the startup
1496
+ * tests require some buffer space. Therefore
1497
+ * ensure we have at least 4096 bytes of buffer.
1498
+ */
1499
+ trace_buf_size = max(4096UL, buf_size);
11251500 return 1;
11261501 }
11271502 __setup("trace_buf_size=", set_buf_size);
....@@ -1315,6 +1690,73 @@
13151690 }
13161691
13171692 unsigned long __read_mostly tracing_thresh;
1693
+static const struct file_operations tracing_max_lat_fops;
1694
+
1695
+#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
1696
+ defined(CONFIG_FSNOTIFY)
1697
+
1698
+static struct workqueue_struct *fsnotify_wq;
1699
+
1700
+static void latency_fsnotify_workfn(struct work_struct *work)
1701
+{
1702
+ struct trace_array *tr = container_of(work, struct trace_array,
1703
+ fsnotify_work);
1704
+ fsnotify_inode(tr->d_max_latency->d_inode, FS_MODIFY);
1705
+}
1706
+
1707
+static void latency_fsnotify_workfn_irq(struct irq_work *iwork)
1708
+{
1709
+ struct trace_array *tr = container_of(iwork, struct trace_array,
1710
+ fsnotify_irqwork);
1711
+ queue_work(fsnotify_wq, &tr->fsnotify_work);
1712
+}
1713
+
1714
+static void trace_create_maxlat_file(struct trace_array *tr,
1715
+ struct dentry *d_tracer)
1716
+{
1717
+ INIT_WORK(&tr->fsnotify_work, latency_fsnotify_workfn);
1718
+ init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
1719
+ tr->d_max_latency = trace_create_file("tracing_max_latency", 0644,
1720
+ d_tracer, &tr->max_latency,
1721
+ &tracing_max_lat_fops);
1722
+}
1723
+
1724
+__init static int latency_fsnotify_init(void)
1725
+{
1726
+ fsnotify_wq = alloc_workqueue("tr_max_lat_wq",
1727
+ WQ_UNBOUND | WQ_HIGHPRI, 0);
1728
+ if (!fsnotify_wq) {
1729
+ pr_err("Unable to allocate tr_max_lat_wq\n");
1730
+ return -ENOMEM;
1731
+ }
1732
+ return 0;
1733
+}
1734
+
1735
+late_initcall_sync(latency_fsnotify_init);
1736
+
1737
+void latency_fsnotify(struct trace_array *tr)
1738
+{
1739
+ if (!fsnotify_wq)
1740
+ return;
1741
+ /*
1742
+ * We cannot call queue_work(&tr->fsnotify_work) from here because it's
1743
+ * possible that we are called from __schedule() or do_idle(), which
1744
+ * could cause a deadlock.
1745
+ */
1746
+ irq_work_queue(&tr->fsnotify_irqwork);
1747
+}
1748
+
1749
+/*
1750
+ * (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
1751
+ * defined(CONFIG_FSNOTIFY)
1752
+ */
1753
+#else
1754
+
1755
+#define trace_create_maxlat_file(tr, d_tracer) \
1756
+ trace_create_file("tracing_max_latency", 0644, d_tracer, \
1757
+ &tr->max_latency, &tracing_max_lat_fops)
1758
+
1759
+#endif
13181760
13191761 #ifdef CONFIG_TRACER_MAX_TRACE
13201762 /*
....@@ -1325,8 +1767,8 @@
13251767 static void
13261768 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
13271769 {
1328
- struct trace_buffer *trace_buf = &tr->trace_buffer;
1329
- struct trace_buffer *max_buf = &tr->max_buffer;
1770
+ struct array_buffer *trace_buf = &tr->array_buffer;
1771
+ struct array_buffer *max_buf = &tr->max_buffer;
13301772 struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu);
13311773 struct trace_array_cpu *max_data = per_cpu_ptr(max_buf->data, cpu);
13321774
....@@ -1337,7 +1779,7 @@
13371779 max_data->critical_start = data->critical_start;
13381780 max_data->critical_end = data->critical_end;
13391781
1340
- memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
1782
+ strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
13411783 max_data->pid = tsk->pid;
13421784 /*
13431785 * If tsk == current, then use current_uid(), as that does not use
....@@ -1354,6 +1796,7 @@
13541796
13551797 /* record this tasks comm */
13561798 tracing_record_cmdline(tsk);
1799
+ latency_fsnotify(tr);
13571800 }
13581801
13591802 /**
....@@ -1361,12 +1804,14 @@
13611804 * @tr: tracer
13621805 * @tsk: the task with the latency
13631806 * @cpu: The cpu that initiated the trace.
1807
+ * @cond_data: User data associated with a conditional snapshot
13641808 *
13651809 * Flip the buffers between the @tr and the max_tr and record information
13661810 * about which task was the cause of this latency.
13671811 */
13681812 void
1369
-update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
1813
+update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
1814
+ void *cond_data)
13701815 {
13711816 if (tr->stop_count)
13721817 return;
....@@ -1381,23 +1826,29 @@
13811826
13821827 arch_spin_lock(&tr->max_lock);
13831828
1384
- /* Inherit the recordable setting from trace_buffer */
1385
- if (ring_buffer_record_is_set_on(tr->trace_buffer.buffer))
1829
+ /* Inherit the recordable setting from array_buffer */
1830
+ if (ring_buffer_record_is_set_on(tr->array_buffer.buffer))
13861831 ring_buffer_record_on(tr->max_buffer.buffer);
13871832 else
13881833 ring_buffer_record_off(tr->max_buffer.buffer);
13891834
1390
- swap(tr->trace_buffer.buffer, tr->max_buffer.buffer);
1835
+#ifdef CONFIG_TRACER_SNAPSHOT
1836
+ if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data))
1837
+ goto out_unlock;
1838
+#endif
1839
+ swap(tr->array_buffer.buffer, tr->max_buffer.buffer);
13911840
13921841 __update_max_tr(tr, tsk, cpu);
1842
+
1843
+ out_unlock:
13931844 arch_spin_unlock(&tr->max_lock);
13941845 }
13951846
13961847 /**
13971848 * update_max_tr_single - only copy one trace over, and reset the rest
1398
- * @tr - tracer
1399
- * @tsk - task with the latency
1400
- * @cpu - the cpu of the buffer to copy.
1849
+ * @tr: tracer
1850
+ * @tsk: task with the latency
1851
+ * @cpu: the cpu of the buffer to copy.
14011852 *
14021853 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
14031854 */
....@@ -1418,7 +1869,7 @@
14181869
14191870 arch_spin_lock(&tr->max_lock);
14201871
1421
- ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->trace_buffer.buffer, cpu);
1872
+ ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->array_buffer.buffer, cpu);
14221873
14231874 if (ret == -EBUSY) {
14241875 /*
....@@ -1438,13 +1889,13 @@
14381889 }
14391890 #endif /* CONFIG_TRACER_MAX_TRACE */
14401891
1441
-static int wait_on_pipe(struct trace_iterator *iter, bool full)
1892
+static int wait_on_pipe(struct trace_iterator *iter, int full)
14421893 {
14431894 /* Iterators are static, they should be filled or empty */
14441895 if (trace_buffer_iter(iter, iter->cpu_file))
14451896 return 0;
14461897
1447
- return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file,
1898
+ return ring_buffer_wait(iter->array_buffer->buffer, iter->cpu_file,
14481899 full);
14491900 }
14501901
....@@ -1495,7 +1946,7 @@
14951946 * internal tracing to verify that everything is in order.
14961947 * If we fail, we do not register this tracer.
14971948 */
1498
- tracing_reset_online_cpus(&tr->trace_buffer);
1949
+ tracing_reset_online_cpus(&tr->array_buffer);
14991950
15001951 tr->current_trace = type;
15011952
....@@ -1521,7 +1972,7 @@
15211972 return -1;
15221973 }
15231974 /* Only reset on passing, to avoid touching corrupted buffers */
1524
- tracing_reset_online_cpus(&tr->trace_buffer);
1975
+ tracing_reset_online_cpus(&tr->array_buffer);
15251976
15261977 #ifdef CONFIG_TRACER_MAX_TRACE
15271978 if (type->use_max_tr) {
....@@ -1555,6 +2006,10 @@
15552006
15562007 tracing_selftest_running = true;
15572008 list_for_each_entry_safe(p, n, &postponed_selftests, list) {
2009
+ /* This loop can take minutes when sanitizers are enabled, so
2010
+ * lets make sure we allow RCU processing.
2011
+ */
2012
+ cond_resched();
15582013 ret = run_tracer_selftest(p->type);
15592014 /* If the test fails, then warn and remove from available_tracers */
15602015 if (ret < 0) {
....@@ -1593,7 +2048,7 @@
15932048
15942049 /**
15952050 * register_tracer - register a tracer with the ftrace system.
1596
- * @type - the plugin for the tracer
2051
+ * @type: the plugin for the tracer
15972052 *
15982053 * Register a new plugin tracer.
15992054 */
....@@ -1610,6 +2065,12 @@
16102065 if (strlen(type->name) >= MAX_TRACER_SIZE) {
16112066 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
16122067 return -1;
2068
+ }
2069
+
2070
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
2071
+ pr_warn("Can not register tracer %s due to lockdown\n",
2072
+ type->name);
2073
+ return -EPERM;
16132074 }
16142075
16152076 mutex_lock(&trace_types_lock);
....@@ -1670,19 +2131,15 @@
16702131 apply_trace_boot_options();
16712132
16722133 /* disable other selftests, since this will break it. */
1673
- tracing_selftest_disabled = true;
1674
-#ifdef CONFIG_FTRACE_STARTUP_TEST
1675
- printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
1676
- type->name);
1677
-#endif
2134
+ disable_tracing_selftest("running a tracer");
16782135
16792136 out_unlock:
16802137 return ret;
16812138 }
16822139
1683
-void tracing_reset(struct trace_buffer *buf, int cpu)
2140
+static void tracing_reset_cpu(struct array_buffer *buf, int cpu)
16842141 {
1685
- struct ring_buffer *buffer = buf->buffer;
2142
+ struct trace_buffer *buffer = buf->buffer;
16862143
16872144 if (!buffer)
16882145 return;
....@@ -1690,16 +2147,15 @@
16902147 ring_buffer_record_disable(buffer);
16912148
16922149 /* Make sure all commits have finished */
1693
- synchronize_sched();
2150
+ synchronize_rcu();
16942151 ring_buffer_reset_cpu(buffer, cpu);
16952152
16962153 ring_buffer_record_enable(buffer);
16972154 }
16982155
1699
-void tracing_reset_online_cpus(struct trace_buffer *buf)
2156
+void tracing_reset_online_cpus(struct array_buffer *buf)
17002157 {
1701
- struct ring_buffer *buffer = buf->buffer;
1702
- int cpu;
2158
+ struct trace_buffer *buffer = buf->buffer;
17032159
17042160 if (!buffer)
17052161 return;
....@@ -1707,12 +2163,11 @@
17072163 ring_buffer_record_disable(buffer);
17082164
17092165 /* Make sure all commits have finished */
1710
- synchronize_sched();
2166
+ synchronize_rcu();
17112167
17122168 buf->time_start = buffer_ftrace_now(buf, buf->cpu);
17132169
1714
- for_each_online_cpu(cpu)
1715
- ring_buffer_reset_cpu(buffer, cpu);
2170
+ ring_buffer_reset_online_cpus(buffer);
17162171
17172172 ring_buffer_record_enable(buffer);
17182173 }
....@@ -1726,7 +2181,7 @@
17262181 if (!tr->clear_trace)
17272182 continue;
17282183 tr->clear_trace = false;
1729
- tracing_reset_online_cpus(&tr->trace_buffer);
2184
+ tracing_reset_online_cpus(&tr->array_buffer);
17302185 #ifdef CONFIG_TRACER_MAX_TRACE
17312186 tracing_reset_online_cpus(&tr->max_buffer);
17322187 #endif
....@@ -1744,6 +2199,11 @@
17442199
17452200 #define SAVED_CMDLINES_DEFAULT 128
17462201 #define NO_CMDLINE_MAP UINT_MAX
2202
+/*
2203
+ * Preemption must be disabled before acquiring trace_cmdline_lock.
2204
+ * The various trace_arrays' max_lock must be acquired in a context
2205
+ * where interrupt is disabled.
2206
+ */
17472207 static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;
17482208 struct saved_cmdlines_buffer {
17492209 unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
....@@ -1761,7 +2221,7 @@
17612221
17622222 static inline void set_cmdline(int idx, const char *cmdline)
17632223 {
1764
- memcpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
2224
+ strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
17652225 }
17662226
17672227 static int allocate_cmdlines_buffer(unsigned int val,
....@@ -1820,7 +2280,7 @@
18202280 */
18212281 void tracing_start(void)
18222282 {
1823
- struct ring_buffer *buffer;
2283
+ struct trace_buffer *buffer;
18242284 unsigned long flags;
18252285
18262286 if (tracing_disabled)
....@@ -1839,7 +2299,7 @@
18392299 /* Prevent the buffers from switching */
18402300 arch_spin_lock(&global_trace.max_lock);
18412301
1842
- buffer = global_trace.trace_buffer.buffer;
2302
+ buffer = global_trace.array_buffer.buffer;
18432303 if (buffer)
18442304 ring_buffer_record_enable(buffer);
18452305
....@@ -1857,7 +2317,7 @@
18572317
18582318 static void tracing_start_tr(struct trace_array *tr)
18592319 {
1860
- struct ring_buffer *buffer;
2320
+ struct trace_buffer *buffer;
18612321 unsigned long flags;
18622322
18632323 if (tracing_disabled)
....@@ -1878,7 +2338,7 @@
18782338 goto out;
18792339 }
18802340
1881
- buffer = tr->trace_buffer.buffer;
2341
+ buffer = tr->array_buffer.buffer;
18822342 if (buffer)
18832343 ring_buffer_record_enable(buffer);
18842344
....@@ -1894,7 +2354,7 @@
18942354 */
18952355 void tracing_stop(void)
18962356 {
1897
- struct ring_buffer *buffer;
2357
+ struct trace_buffer *buffer;
18982358 unsigned long flags;
18992359
19002360 raw_spin_lock_irqsave(&global_trace.start_lock, flags);
....@@ -1904,7 +2364,7 @@
19042364 /* Prevent the buffers from switching */
19052365 arch_spin_lock(&global_trace.max_lock);
19062366
1907
- buffer = global_trace.trace_buffer.buffer;
2367
+ buffer = global_trace.array_buffer.buffer;
19082368 if (buffer)
19092369 ring_buffer_record_disable(buffer);
19102370
....@@ -1922,7 +2382,7 @@
19222382
19232383 static void tracing_stop_tr(struct trace_array *tr)
19242384 {
1925
- struct ring_buffer *buffer;
2385
+ struct trace_buffer *buffer;
19262386 unsigned long flags;
19272387
19282388 /* If global, we need to also stop the max tracer */
....@@ -1933,7 +2393,7 @@
19332393 if (tr->stop_count++)
19342394 goto out;
19352395
1936
- buffer = tr->trace_buffer.buffer;
2396
+ buffer = tr->array_buffer.buffer;
19372397 if (buffer)
19382398 ring_buffer_record_disable(buffer);
19392399
....@@ -1956,7 +2416,11 @@
19562416 * the lock, but we also don't want to spin
19572417 * nor do we want to disable interrupts,
19582418 * so if we miss here, then better luck next time.
2419
+ *
2420
+ * This is called within the scheduler and wake up, so interrupts
2421
+ * had better been disabled and run queue lock been held.
19592422 */
2423
+ lockdep_assert_preemption_disabled();
19602424 if (!arch_spin_trylock(&trace_cmdline_lock))
19612425 return 0;
19622426
....@@ -2064,9 +2528,9 @@
20642528 /**
20652529 * tracing_record_taskinfo - record the task info of a task
20662530 *
2067
- * @task - task to record
2068
- * @flags - TRACE_RECORD_CMDLINE for recording comm
2069
- * - TRACE_RECORD_TGID for recording tgid
2531
+ * @task: task to record
2532
+ * @flags: TRACE_RECORD_CMDLINE for recording comm
2533
+ * TRACE_RECORD_TGID for recording tgid
20702534 */
20712535 void tracing_record_taskinfo(struct task_struct *task, int flags)
20722536 {
....@@ -2092,10 +2556,10 @@
20922556 /**
20932557 * tracing_record_taskinfo_sched_switch - record task info for sched_switch
20942558 *
2095
- * @prev - previous task during sched_switch
2096
- * @next - next task during sched_switch
2097
- * @flags - TRACE_RECORD_CMDLINE for recording comm
2098
- * TRACE_RECORD_TGID for recording tgid
2559
+ * @prev: previous task during sched_switch
2560
+ * @next: next task during sched_switch
2561
+ * @flags: TRACE_RECORD_CMDLINE for recording comm
2562
+ * TRACE_RECORD_TGID for recording tgid
20992563 */
21002564 void tracing_record_taskinfo_sched_switch(struct task_struct *prev,
21012565 struct task_struct *next, int flags)
....@@ -2144,39 +2608,52 @@
21442608 }
21452609 EXPORT_SYMBOL_GPL(trace_handle_return);
21462610
2147
-void
2148
-tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
2149
- int pc)
2611
+static unsigned short migration_disable_value(void)
21502612 {
2151
- struct task_struct *tsk = current;
2152
-
2153
- entry->preempt_count = pc & 0xff;
2154
- entry->preempt_lazy_count = preempt_lazy_count();
2155
- entry->pid = (tsk) ? tsk->pid : 0;
2156
- entry->flags =
2157
-#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
2158
- (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
2613
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT)
2614
+ return current->migration_disabled;
21592615 #else
2160
- TRACE_FLAG_IRQS_NOSUPPORT |
2616
+ return 0;
21612617 #endif
2162
- ((pc & NMI_MASK ) ? TRACE_FLAG_NMI : 0) |
2163
- ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
2164
- ((pc & SOFTIRQ_OFFSET) ? TRACE_FLAG_SOFTIRQ : 0) |
2165
- (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
2166
- (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
2167
- (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
2168
-
2169
- entry->migrate_disable = (tsk) ? __migrate_disabled(tsk) & 0xFF : 0;
21702618 }
2171
-EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
2619
+
2620
+unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
2621
+{
2622
+ unsigned int trace_flags = irqs_status;
2623
+ unsigned int pc;
2624
+
2625
+ pc = preempt_count();
2626
+
2627
+ if (pc & NMI_MASK)
2628
+ trace_flags |= TRACE_FLAG_NMI;
2629
+ if (pc & HARDIRQ_MASK)
2630
+ trace_flags |= TRACE_FLAG_HARDIRQ;
2631
+ if (in_serving_softirq())
2632
+ trace_flags |= TRACE_FLAG_SOFTIRQ;
2633
+
2634
+ if (tif_need_resched())
2635
+ trace_flags |= TRACE_FLAG_NEED_RESCHED;
2636
+ if (test_preempt_need_resched())
2637
+ trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
2638
+
2639
+#ifdef CONFIG_PREEMPT_LAZY
2640
+ if (need_resched_lazy())
2641
+ trace_flags |= TRACE_FLAG_NEED_RESCHED_LAZY;
2642
+#endif
2643
+
2644
+ return (pc & 0xff) |
2645
+ (migration_disable_value() & 0xff) << 8 |
2646
+ (preempt_lazy_count() & 0xff) << 16 |
2647
+ (trace_flags << 24);
2648
+}
21722649
21732650 struct ring_buffer_event *
2174
-trace_buffer_lock_reserve(struct ring_buffer *buffer,
2651
+trace_buffer_lock_reserve(struct trace_buffer *buffer,
21752652 int type,
21762653 unsigned long len,
2177
- unsigned long flags, int pc)
2654
+ unsigned int trace_ctx)
21782655 {
2179
- return __trace_buffer_lock_reserve(buffer, type, len, flags, pc);
2656
+ return __trace_buffer_lock_reserve(buffer, type, len, trace_ctx);
21802657 }
21812658
21822659 DEFINE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
....@@ -2221,7 +2698,7 @@
22212698
22222699 preempt_disable();
22232700 if (cpu == smp_processor_id() &&
2224
- this_cpu_read(trace_buffered_event) !=
2701
+ __this_cpu_read(trace_buffered_event) !=
22252702 per_cpu(trace_buffered_event, cpu))
22262703 WARN_ON_ONCE(1);
22272704 preempt_enable();
....@@ -2271,7 +2748,7 @@
22712748 preempt_enable();
22722749
22732750 /* Wait for all current users to finish */
2274
- synchronize_sched();
2751
+ synchronize_rcu();
22752752
22762753 for_each_tracing_cpu(cpu) {
22772754 free_page((unsigned long)per_cpu(trace_buffered_event, cpu));
....@@ -2290,18 +2767,18 @@
22902767 preempt_enable();
22912768 }
22922769
2293
-static struct ring_buffer *temp_buffer;
2770
+static struct trace_buffer *temp_buffer;
22942771
22952772 struct ring_buffer_event *
2296
-trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
2773
+trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
22972774 struct trace_event_file *trace_file,
22982775 int type, unsigned long len,
2299
- unsigned long flags, int pc)
2776
+ unsigned int trace_ctx)
23002777 {
23012778 struct ring_buffer_event *entry;
23022779 int val;
23032780
2304
- *current_rb = trace_file->tr->trace_buffer.buffer;
2781
+ *current_rb = trace_file->tr->array_buffer.buffer;
23052782
23062783 if (!ring_buffer_time_stamp_abs(*current_rb) && (trace_file->flags &
23072784 (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED)) &&
....@@ -2309,7 +2786,7 @@
23092786 /* Try to use the per cpu buffer first */
23102787 val = this_cpu_inc_return(trace_buffered_event_cnt);
23112788 if ((len < (PAGE_SIZE - sizeof(*entry) - sizeof(entry->array[0]))) && val == 1) {
2312
- trace_event_setup(entry, type, flags, pc);
2789
+ trace_event_setup(entry, type, trace_ctx);
23132790 entry->array[0] = len;
23142791 return entry;
23152792 }
....@@ -2317,28 +2794,29 @@
23172794 }
23182795
23192796 entry = __trace_buffer_lock_reserve(*current_rb,
2320
- type, len, flags, pc);
2797
+ type, len, trace_ctx);
23212798 /*
23222799 * If tracing is off, but we have triggers enabled
23232800 * we still need to look at the event data. Use the temp_buffer
2324
- * to store the trace event for the tigger to use. It's recusive
2801
+ * to store the trace event for the trigger to use. It's recursive
23252802 * safe and will not be recorded anywhere.
23262803 */
23272804 if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) {
23282805 *current_rb = temp_buffer;
2329
- entry = __trace_buffer_lock_reserve(*current_rb,
2330
- type, len, flags, pc);
2806
+ entry = __trace_buffer_lock_reserve(*current_rb, type, len,
2807
+ trace_ctx);
23312808 }
23322809 return entry;
23332810 }
23342811 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
23352812
2336
-static DEFINE_SPINLOCK(tracepoint_iter_lock);
2813
+static DEFINE_RAW_SPINLOCK(tracepoint_iter_lock);
23372814 static DEFINE_MUTEX(tracepoint_printk_mutex);
23382815
23392816 static void output_printk(struct trace_event_buffer *fbuffer)
23402817 {
23412818 struct trace_event_call *event_call;
2819
+ struct trace_event_file *file;
23422820 struct trace_event *event;
23432821 unsigned long flags;
23442822 struct trace_iterator *iter = tracepoint_print_iter;
....@@ -2352,20 +2830,26 @@
23522830 !event_call->event.funcs->trace)
23532831 return;
23542832
2833
+ file = fbuffer->trace_file;
2834
+ if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
2835
+ (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
2836
+ !filter_match_preds(file->filter, fbuffer->entry)))
2837
+ return;
2838
+
23552839 event = &fbuffer->trace_file->event_call->event;
23562840
2357
- spin_lock_irqsave(&tracepoint_iter_lock, flags);
2841
+ raw_spin_lock_irqsave(&tracepoint_iter_lock, flags);
23582842 trace_seq_init(&iter->seq);
23592843 iter->ent = fbuffer->entry;
23602844 event_call->event.funcs->trace(iter, 0, event);
23612845 trace_seq_putc(&iter->seq, 0);
23622846 printk("%s", iter->seq.buffer);
23632847
2364
- spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
2848
+ raw_spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
23652849 }
23662850
23672851 int tracepoint_printk_sysctl(struct ctl_table *table, int write,
2368
- void __user *buffer, size_t *lenp,
2852
+ void *buffer, size_t *lenp,
23692853 loff_t *ppos)
23702854 {
23712855 int save_tracepoint_printk;
....@@ -2402,9 +2886,11 @@
24022886 if (static_key_false(&tracepoint_printk_key.key))
24032887 output_printk(fbuffer);
24042888
2405
- event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
2889
+ if (static_branch_unlikely(&trace_event_exports_enabled))
2890
+ ftrace_exports(fbuffer->event, TRACE_EXPORT_EVENT);
2891
+ event_trigger_unlock_commit_regs(fbuffer->trace_file, fbuffer->buffer,
24062892 fbuffer->event, fbuffer->entry,
2407
- fbuffer->flags, fbuffer->pc);
2893
+ fbuffer->trace_ctx, fbuffer->regs);
24082894 }
24092895 EXPORT_SYMBOL_GPL(trace_event_buffer_commit);
24102896
....@@ -2418,9 +2904,9 @@
24182904 # define STACK_SKIP 3
24192905
24202906 void trace_buffer_unlock_commit_regs(struct trace_array *tr,
2421
- struct ring_buffer *buffer,
2907
+ struct trace_buffer *buffer,
24222908 struct ring_buffer_event *event,
2423
- unsigned long flags, int pc,
2909
+ unsigned int trace_ctx,
24242910 struct pt_regs *regs)
24252911 {
24262912 __buffer_unlock_commit(buffer, event);
....@@ -2431,155 +2917,31 @@
24312917 * and mmiotrace, but that's ok if they lose a function or
24322918 * two. They are not that meaningful.
24332919 */
2434
- ftrace_trace_stack(tr, buffer, flags, regs ? 0 : STACK_SKIP, pc, regs);
2435
- ftrace_trace_userstack(tr, buffer, flags, pc);
2920
+ ftrace_trace_stack(tr, buffer, trace_ctx, regs ? 0 : STACK_SKIP, regs);
2921
+ ftrace_trace_userstack(tr, buffer, trace_ctx);
24362922 }
24372923
24382924 /*
24392925 * Similar to trace_buffer_unlock_commit_regs() but do not dump stack.
24402926 */
24412927 void
2442
-trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer,
2928
+trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
24432929 struct ring_buffer_event *event)
24442930 {
24452931 __buffer_unlock_commit(buffer, event);
24462932 }
24472933
2448
-static void
2449
-trace_process_export(struct trace_export *export,
2450
- struct ring_buffer_event *event)
2451
-{
2452
- struct trace_entry *entry;
2453
- unsigned int size = 0;
2454
-
2455
- entry = ring_buffer_event_data(event);
2456
- size = ring_buffer_event_length(event);
2457
- export->write(export, entry, size);
2458
-}
2459
-
2460
-static DEFINE_MUTEX(ftrace_export_lock);
2461
-
2462
-static struct trace_export __rcu *ftrace_exports_list __read_mostly;
2463
-
2464
-static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);
2465
-
2466
-static inline void ftrace_exports_enable(void)
2467
-{
2468
- static_branch_enable(&ftrace_exports_enabled);
2469
-}
2470
-
2471
-static inline void ftrace_exports_disable(void)
2472
-{
2473
- static_branch_disable(&ftrace_exports_enabled);
2474
-}
2475
-
2476
-void ftrace_exports(struct ring_buffer_event *event)
2477
-{
2478
- struct trace_export *export;
2479
-
2480
- preempt_disable_notrace();
2481
-
2482
- export = rcu_dereference_raw_notrace(ftrace_exports_list);
2483
- while (export) {
2484
- trace_process_export(export, event);
2485
- export = rcu_dereference_raw_notrace(export->next);
2486
- }
2487
-
2488
- preempt_enable_notrace();
2489
-}
2490
-
2491
-static inline void
2492
-add_trace_export(struct trace_export **list, struct trace_export *export)
2493
-{
2494
- rcu_assign_pointer(export->next, *list);
2495
- /*
2496
- * We are entering export into the list but another
2497
- * CPU might be walking that list. We need to make sure
2498
- * the export->next pointer is valid before another CPU sees
2499
- * the export pointer included into the list.
2500
- */
2501
- rcu_assign_pointer(*list, export);
2502
-}
2503
-
2504
-static inline int
2505
-rm_trace_export(struct trace_export **list, struct trace_export *export)
2506
-{
2507
- struct trace_export **p;
2508
-
2509
- for (p = list; *p != NULL; p = &(*p)->next)
2510
- if (*p == export)
2511
- break;
2512
-
2513
- if (*p != export)
2514
- return -1;
2515
-
2516
- rcu_assign_pointer(*p, (*p)->next);
2517
-
2518
- return 0;
2519
-}
2520
-
2521
-static inline void
2522
-add_ftrace_export(struct trace_export **list, struct trace_export *export)
2523
-{
2524
- if (*list == NULL)
2525
- ftrace_exports_enable();
2526
-
2527
- add_trace_export(list, export);
2528
-}
2529
-
2530
-static inline int
2531
-rm_ftrace_export(struct trace_export **list, struct trace_export *export)
2532
-{
2533
- int ret;
2534
-
2535
- ret = rm_trace_export(list, export);
2536
- if (*list == NULL)
2537
- ftrace_exports_disable();
2538
-
2539
- return ret;
2540
-}
2541
-
2542
-int register_ftrace_export(struct trace_export *export)
2543
-{
2544
- if (WARN_ON_ONCE(!export->write))
2545
- return -1;
2546
-
2547
- mutex_lock(&ftrace_export_lock);
2548
-
2549
- add_ftrace_export(&ftrace_exports_list, export);
2550
-
2551
- mutex_unlock(&ftrace_export_lock);
2552
-
2553
- return 0;
2554
-}
2555
-EXPORT_SYMBOL_GPL(register_ftrace_export);
2556
-
2557
-int unregister_ftrace_export(struct trace_export *export)
2558
-{
2559
- int ret;
2560
-
2561
- mutex_lock(&ftrace_export_lock);
2562
-
2563
- ret = rm_ftrace_export(&ftrace_exports_list, export);
2564
-
2565
- mutex_unlock(&ftrace_export_lock);
2566
-
2567
- return ret;
2568
-}
2569
-EXPORT_SYMBOL_GPL(unregister_ftrace_export);
2570
-
25712934 void
2572
-trace_function(struct trace_array *tr,
2573
- unsigned long ip, unsigned long parent_ip, unsigned long flags,
2574
- int pc)
2935
+trace_function(struct trace_array *tr, unsigned long ip, unsigned long
2936
+ parent_ip, unsigned int trace_ctx)
25752937 {
25762938 struct trace_event_call *call = &event_function;
2577
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
2939
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
25782940 struct ring_buffer_event *event;
25792941 struct ftrace_entry *entry;
25802942
25812943 event = __trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry),
2582
- flags, pc);
2944
+ trace_ctx);
25832945 if (!event)
25842946 return;
25852947 entry = ring_buffer_event_data(event);
....@@ -2587,35 +2949,41 @@
25872949 entry->parent_ip = parent_ip;
25882950
25892951 if (!call_filter_check_discard(call, entry, buffer, event)) {
2590
- if (static_branch_unlikely(&ftrace_exports_enabled))
2591
- ftrace_exports(event);
2952
+ if (static_branch_unlikely(&trace_function_exports_enabled))
2953
+ ftrace_exports(event, TRACE_EXPORT_FUNCTION);
25922954 __buffer_unlock_commit(buffer, event);
25932955 }
25942956 }
25952957
25962958 #ifdef CONFIG_STACKTRACE
25972959
2598
-#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
2960
+/* Allow 4 levels of nesting: normal, softirq, irq, NMI */
2961
+#define FTRACE_KSTACK_NESTING 4
2962
+
2963
+#define FTRACE_KSTACK_ENTRIES (PAGE_SIZE / FTRACE_KSTACK_NESTING)
2964
+
25992965 struct ftrace_stack {
2600
- unsigned long calls[FTRACE_STACK_MAX_ENTRIES];
2966
+ unsigned long calls[FTRACE_KSTACK_ENTRIES];
26012967 };
26022968
2603
-static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);
2969
+
2970
+struct ftrace_stacks {
2971
+ struct ftrace_stack stacks[FTRACE_KSTACK_NESTING];
2972
+};
2973
+
2974
+static DEFINE_PER_CPU(struct ftrace_stacks, ftrace_stacks);
26042975 static DEFINE_PER_CPU(int, ftrace_stack_reserve);
26052976
2606
-static void __ftrace_trace_stack(struct ring_buffer *buffer,
2607
- unsigned long flags,
2608
- int skip, int pc, struct pt_regs *regs)
2977
+static void __ftrace_trace_stack(struct trace_buffer *buffer,
2978
+ unsigned int trace_ctx,
2979
+ int skip, struct pt_regs *regs)
26092980 {
26102981 struct trace_event_call *call = &event_kernel_stack;
26112982 struct ring_buffer_event *event;
2983
+ unsigned int size, nr_entries;
2984
+ struct ftrace_stack *fstack;
26122985 struct stack_entry *entry;
2613
- struct stack_trace trace;
2614
- int use_stack;
2615
- int size = FTRACE_STACK_ENTRIES;
2616
-
2617
- trace.nr_entries = 0;
2618
- trace.skip = skip;
2986
+ int stackidx;
26192987
26202988 /*
26212989 * Add one, for this function and the call to save_stack_trace()
....@@ -2623,65 +2991,46 @@
26232991 */
26242992 #ifndef CONFIG_UNWINDER_ORC
26252993 if (!regs)
2626
- trace.skip++;
2994
+ skip++;
26272995 #endif
26282996
2629
- /*
2630
- * Since events can happen in NMIs there's no safe way to
2631
- * use the per cpu ftrace_stacks. We reserve it and if an interrupt
2632
- * or NMI comes in, it will just have to use the default
2633
- * FTRACE_STACK_SIZE.
2634
- */
26352997 preempt_disable_notrace();
26362998
2637
- use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
2999
+ stackidx = __this_cpu_inc_return(ftrace_stack_reserve) - 1;
3000
+
3001
+ /* This should never happen. If it does, yell once and skip */
3002
+ if (WARN_ON_ONCE(stackidx >= FTRACE_KSTACK_NESTING))
3003
+ goto out;
3004
+
26383005 /*
2639
- * We don't need any atomic variables, just a barrier.
2640
- * If an interrupt comes in, we don't care, because it would
2641
- * have exited and put the counter back to what we want.
2642
- * We just need a barrier to keep gcc from moving things
2643
- * around.
3006
+ * The above __this_cpu_inc_return() is 'atomic' cpu local. An
3007
+ * interrupt will either see the value pre increment or post
3008
+ * increment. If the interrupt happens pre increment it will have
3009
+ * restored the counter when it returns. We just need a barrier to
3010
+ * keep gcc from moving things around.
26443011 */
26453012 barrier();
2646
- if (use_stack == 1) {
2647
- trace.entries = this_cpu_ptr(ftrace_stack.calls);
2648
- trace.max_entries = FTRACE_STACK_MAX_ENTRIES;
26493013
2650
- if (regs)
2651
- save_stack_trace_regs(regs, &trace);
2652
- else
2653
- save_stack_trace(&trace);
3014
+ fstack = this_cpu_ptr(ftrace_stacks.stacks) + stackidx;
3015
+ size = ARRAY_SIZE(fstack->calls);
26543016
2655
- if (trace.nr_entries > size)
2656
- size = trace.nr_entries;
2657
- } else
2658
- /* From now on, use_stack is a boolean */
2659
- use_stack = 0;
3017
+ if (regs) {
3018
+ nr_entries = stack_trace_save_regs(regs, fstack->calls,
3019
+ size, skip);
3020
+ } else {
3021
+ nr_entries = stack_trace_save(fstack->calls, size, skip);
3022
+ }
26603023
2661
- size *= sizeof(unsigned long);
2662
-
3024
+ size = nr_entries * sizeof(unsigned long);
26633025 event = __trace_buffer_lock_reserve(buffer, TRACE_STACK,
26643026 (sizeof(*entry) - sizeof(entry->caller)) + size,
2665
- flags, pc);
3027
+ trace_ctx);
26663028 if (!event)
26673029 goto out;
26683030 entry = ring_buffer_event_data(event);
26693031
2670
- memset(&entry->caller, 0, size);
2671
-
2672
- if (use_stack)
2673
- memcpy(&entry->caller, trace.entries,
2674
- trace.nr_entries * sizeof(unsigned long));
2675
- else {
2676
- trace.max_entries = FTRACE_STACK_ENTRIES;
2677
- trace.entries = entry->caller;
2678
- if (regs)
2679
- save_stack_trace_regs(regs, &trace);
2680
- else
2681
- save_stack_trace(&trace);
2682
- }
2683
-
2684
- entry->size = trace.nr_entries;
3032
+ memcpy(&entry->caller, fstack->calls, size);
3033
+ entry->size = nr_entries;
26853034
26863035 if (!call_filter_check_discard(call, entry, buffer, event))
26873036 __buffer_unlock_commit(buffer, event);
....@@ -2695,23 +3044,23 @@
26953044 }
26963045
26973046 static inline void ftrace_trace_stack(struct trace_array *tr,
2698
- struct ring_buffer *buffer,
2699
- unsigned long flags,
2700
- int skip, int pc, struct pt_regs *regs)
3047
+ struct trace_buffer *buffer,
3048
+ unsigned int trace_ctx,
3049
+ int skip, struct pt_regs *regs)
27013050 {
27023051 if (!(tr->trace_flags & TRACE_ITER_STACKTRACE))
27033052 return;
27043053
2705
- __ftrace_trace_stack(buffer, flags, skip, pc, regs);
3054
+ __ftrace_trace_stack(buffer, trace_ctx, skip, regs);
27063055 }
27073056
2708
-void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
2709
- int pc)
3057
+void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
3058
+ int skip)
27103059 {
2711
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
3060
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
27123061
27133062 if (rcu_is_watching()) {
2714
- __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
3063
+ __ftrace_trace_stack(buffer, trace_ctx, skip, NULL);
27153064 return;
27163065 }
27173066
....@@ -2725,7 +3074,7 @@
27253074 return;
27263075
27273076 rcu_irq_enter_irqson();
2728
- __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
3077
+ __ftrace_trace_stack(buffer, trace_ctx, skip, NULL);
27293078 rcu_irq_exit_irqson();
27303079 }
27313080
....@@ -2735,31 +3084,28 @@
27353084 */
27363085 void trace_dump_stack(int skip)
27373086 {
2738
- unsigned long flags;
2739
-
27403087 if (tracing_disabled || tracing_selftest_running)
27413088 return;
2742
-
2743
- local_save_flags(flags);
27443089
27453090 #ifndef CONFIG_UNWINDER_ORC
27463091 /* Skip 1 to skip this function. */
27473092 skip++;
27483093 #endif
2749
- __ftrace_trace_stack(global_trace.trace_buffer.buffer,
2750
- flags, skip, preempt_count(), NULL);
3094
+ __ftrace_trace_stack(global_trace.array_buffer.buffer,
3095
+ tracing_gen_ctx(), skip, NULL);
27513096 }
3097
+EXPORT_SYMBOL_GPL(trace_dump_stack);
27523098
3099
+#ifdef CONFIG_USER_STACKTRACE_SUPPORT
27533100 static DEFINE_PER_CPU(int, user_stack_count);
27543101
2755
-void
3102
+static void
27563103 ftrace_trace_userstack(struct trace_array *tr,
2757
- struct ring_buffer *buffer, unsigned long flags, int pc)
3104
+ struct trace_buffer *buffer, unsigned int trace_ctx)
27583105 {
27593106 struct trace_event_call *call = &event_user_stack;
27603107 struct ring_buffer_event *event;
27613108 struct userstack_entry *entry;
2762
- struct stack_trace trace;
27633109
27643110 if (!(tr->trace_flags & TRACE_ITER_USERSTACKTRACE))
27653111 return;
....@@ -2782,7 +3128,7 @@
27823128 __this_cpu_inc(user_stack_count);
27833129
27843130 event = __trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
2785
- sizeof(*entry), flags, pc);
3131
+ sizeof(*entry), trace_ctx);
27863132 if (!event)
27873133 goto out_drop_count;
27883134 entry = ring_buffer_event_data(event);
....@@ -2790,12 +3136,7 @@
27903136 entry->tgid = current->tgid;
27913137 memset(&entry->caller, 0, sizeof(entry->caller));
27923138
2793
- trace.nr_entries = 0;
2794
- trace.max_entries = FTRACE_STACK_ENTRIES;
2795
- trace.skip = 0;
2796
- trace.entries = entry->caller;
2797
-
2798
- save_stack_trace_user(&trace);
3139
+ stack_trace_save_user(entry->caller, FTRACE_STACK_ENTRIES);
27993140 if (!call_filter_check_discard(call, entry, buffer, event))
28003141 __buffer_unlock_commit(buffer, event);
28013142
....@@ -2804,13 +3145,13 @@
28043145 out:
28053146 preempt_enable();
28063147 }
2807
-
2808
-#ifdef UNUSED
2809
-static void __trace_userstack(struct trace_array *tr, unsigned long flags)
3148
+#else /* CONFIG_USER_STACKTRACE_SUPPORT */
3149
+static void ftrace_trace_userstack(struct trace_array *tr,
3150
+ struct trace_buffer *buffer,
3151
+ unsigned int trace_ctx)
28103152 {
2811
- ftrace_trace_userstack(tr, flags, preempt_count());
28123153 }
2813
-#endif /* UNUSED */
3154
+#endif /* !CONFIG_USER_STACKTRACE_SUPPORT */
28143155
28153156 #endif /* CONFIG_STACKTRACE */
28163157
....@@ -2851,8 +3192,11 @@
28513192 {
28523193 struct trace_buffer_struct __percpu *buffers;
28533194
3195
+ if (trace_percpu_buffer)
3196
+ return 0;
3197
+
28543198 buffers = alloc_percpu(struct trace_buffer_struct);
2855
- if (WARN(!buffers, "Could not allocate percpu trace_printk buffer"))
3199
+ if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer"))
28563200 return -ENOMEM;
28573201
28583202 trace_percpu_buffer = buffers;
....@@ -2897,9 +3241,10 @@
28973241 * directly here. If the global_trace.buffer is already
28983242 * allocated here, then this was called by module code.
28993243 */
2900
- if (global_trace.trace_buffer.buffer)
3244
+ if (global_trace.array_buffer.buffer)
29013245 tracing_start_cmdline_record();
29023246 }
3247
+EXPORT_SYMBOL_GPL(trace_printk_init_buffers);
29033248
29043249 void trace_printk_start_comm(void)
29053250 {
....@@ -2922,18 +3267,20 @@
29223267
29233268 /**
29243269 * trace_vbprintk - write binary msg to tracing buffer
2925
- *
3270
+ * @ip: The address of the caller
3271
+ * @fmt: The string format to write to the buffer
3272
+ * @args: Arguments for @fmt
29263273 */
29273274 int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
29283275 {
29293276 struct trace_event_call *call = &event_bprint;
29303277 struct ring_buffer_event *event;
2931
- struct ring_buffer *buffer;
3278
+ struct trace_buffer *buffer;
29323279 struct trace_array *tr = &global_trace;
29333280 struct bprint_entry *entry;
2934
- unsigned long flags;
3281
+ unsigned int trace_ctx;
29353282 char *tbuffer;
2936
- int len = 0, size, pc;
3283
+ int len = 0, size;
29373284
29383285 if (unlikely(tracing_selftest_running || tracing_disabled))
29393286 return 0;
....@@ -2941,7 +3288,7 @@
29413288 /* Don't pollute graph traces with trace_vprintk internals */
29423289 pause_graph_tracing();
29433290
2944
- pc = preempt_count();
3291
+ trace_ctx = tracing_gen_ctx();
29453292 preempt_disable_notrace();
29463293
29473294 tbuffer = get_trace_buf();
....@@ -2953,13 +3300,13 @@
29533300 len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args);
29543301
29553302 if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0)
2956
- goto out;
3303
+ goto out_put;
29573304
2958
- local_save_flags(flags);
29593305 size = sizeof(*entry) + sizeof(u32) * len;
2960
- buffer = tr->trace_buffer.buffer;
3306
+ buffer = tr->array_buffer.buffer;
3307
+ ring_buffer_nest_start(buffer);
29613308 event = __trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size,
2962
- flags, pc);
3309
+ trace_ctx);
29633310 if (!event)
29643311 goto out;
29653312 entry = ring_buffer_event_data(event);
....@@ -2969,10 +3316,12 @@
29693316 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
29703317 if (!call_filter_check_discard(call, entry, buffer, event)) {
29713318 __buffer_unlock_commit(buffer, event);
2972
- ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL);
3319
+ ftrace_trace_stack(tr, buffer, trace_ctx, 6, NULL);
29733320 }
29743321
29753322 out:
3323
+ ring_buffer_nest_end(buffer);
3324
+out_put:
29763325 put_trace_buf();
29773326
29783327 out_nobuffer:
....@@ -2985,14 +3334,14 @@
29853334
29863335 __printf(3, 0)
29873336 static int
2988
-__trace_array_vprintk(struct ring_buffer *buffer,
3337
+__trace_array_vprintk(struct trace_buffer *buffer,
29893338 unsigned long ip, const char *fmt, va_list args)
29903339 {
29913340 struct trace_event_call *call = &event_print;
29923341 struct ring_buffer_event *event;
2993
- int len = 0, size, pc;
3342
+ int len = 0, size;
29943343 struct print_entry *entry;
2995
- unsigned long flags;
3344
+ unsigned int trace_ctx;
29963345 char *tbuffer;
29973346
29983347 if (tracing_disabled || tracing_selftest_running)
....@@ -3001,7 +3350,7 @@
30013350 /* Don't pollute graph traces with trace_vprintk internals */
30023351 pause_graph_tracing();
30033352
3004
- pc = preempt_count();
3353
+ trace_ctx = tracing_gen_ctx();
30053354 preempt_disable_notrace();
30063355
30073356
....@@ -3013,10 +3362,10 @@
30133362
30143363 len = vscnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args);
30153364
3016
- local_save_flags(flags);
30173365 size = sizeof(*entry) + len + 1;
3366
+ ring_buffer_nest_start(buffer);
30183367 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
3019
- flags, pc);
3368
+ trace_ctx);
30203369 if (!event)
30213370 goto out;
30223371 entry = ring_buffer_event_data(event);
....@@ -3025,10 +3374,11 @@
30253374 memcpy(&entry->buf, tbuffer, len + 1);
30263375 if (!call_filter_check_discard(call, entry, buffer, event)) {
30273376 __buffer_unlock_commit(buffer, event);
3028
- ftrace_trace_stack(&global_trace, buffer, flags, 6, pc, NULL);
3377
+ ftrace_trace_stack(&global_trace, buffer, trace_ctx, 6, NULL);
30293378 }
30303379
30313380 out:
3381
+ ring_buffer_nest_end(buffer);
30323382 put_trace_buf();
30333383
30343384 out_nobuffer:
....@@ -3042,9 +3392,29 @@
30423392 int trace_array_vprintk(struct trace_array *tr,
30433393 unsigned long ip, const char *fmt, va_list args)
30443394 {
3045
- return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args);
3395
+ return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args);
30463396 }
30473397
3398
+/**
3399
+ * trace_array_printk - Print a message to a specific instance
3400
+ * @tr: The instance trace_array descriptor
3401
+ * @ip: The instruction pointer that this is called from.
3402
+ * @fmt: The format to print (printf format)
3403
+ *
3404
+ * If a subsystem sets up its own instance, they have the right to
3405
+ * printk strings into their tracing instance buffer using this
3406
+ * function. Note, this function will not write into the top level
3407
+ * buffer (use trace_printk() for that), as writing into the top level
3408
+ * buffer should only have events that can be individually disabled.
3409
+ * trace_printk() is only used for debugging a kernel, and should not
3410
+ * be ever encorporated in normal use.
3411
+ *
3412
+ * trace_array_printk() can be used, as it will not add noise to the
3413
+ * top level tracing buffer.
3414
+ *
3415
+ * Note, trace_array_init_printk() must be called on @tr before this
3416
+ * can be used.
3417
+ */
30483418 __printf(3, 0)
30493419 int trace_array_printk(struct trace_array *tr,
30503420 unsigned long ip, const char *fmt, ...)
....@@ -3052,20 +3422,46 @@
30523422 int ret;
30533423 va_list ap;
30543424
3055
- if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
3056
- return 0;
3057
-
30583425 if (!tr)
30593426 return -ENOENT;
3427
+
3428
+ /* This is only allowed for created instances */
3429
+ if (tr == &global_trace)
3430
+ return 0;
3431
+
3432
+ if (!(tr->trace_flags & TRACE_ITER_PRINTK))
3433
+ return 0;
30603434
30613435 va_start(ap, fmt);
30623436 ret = trace_array_vprintk(tr, ip, fmt, ap);
30633437 va_end(ap);
30643438 return ret;
30653439 }
3440
+EXPORT_SYMBOL_GPL(trace_array_printk);
3441
+
3442
+/**
3443
+ * trace_array_init_printk - Initialize buffers for trace_array_printk()
3444
+ * @tr: The trace array to initialize the buffers for
3445
+ *
3446
+ * As trace_array_printk() only writes into instances, they are OK to
3447
+ * have in the kernel (unlike trace_printk()). This needs to be called
3448
+ * before trace_array_printk() can be used on a trace_array.
3449
+ */
3450
+int trace_array_init_printk(struct trace_array *tr)
3451
+{
3452
+ if (!tr)
3453
+ return -ENOENT;
3454
+
3455
+ /* This is only allowed for created instances */
3456
+ if (tr == &global_trace)
3457
+ return -EINVAL;
3458
+
3459
+ return alloc_percpu_trace_buffer();
3460
+}
3461
+EXPORT_SYMBOL_GPL(trace_array_init_printk);
30663462
30673463 __printf(3, 4)
3068
-int trace_array_printk_buf(struct ring_buffer *buffer,
3464
+int trace_array_printk_buf(struct trace_buffer *buffer,
30693465 unsigned long ip, const char *fmt, ...)
30703466 {
30713467 int ret;
....@@ -3093,7 +3489,7 @@
30933489
30943490 iter->idx++;
30953491 if (buf_iter)
3096
- ring_buffer_read(buf_iter, NULL);
3492
+ ring_buffer_iter_advance(buf_iter);
30973493 }
30983494
30993495 static struct trace_entry *
....@@ -3103,11 +3499,15 @@
31033499 struct ring_buffer_event *event;
31043500 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu);
31053501
3106
- if (buf_iter)
3502
+ if (buf_iter) {
31073503 event = ring_buffer_iter_peek(buf_iter, ts);
3108
- else
3109
- event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts,
3504
+ if (lost_events)
3505
+ *lost_events = ring_buffer_iter_dropped(buf_iter) ?
3506
+ (unsigned long)-1 : 0;
3507
+ } else {
3508
+ event = ring_buffer_peek(iter->array_buffer->buffer, cpu, ts,
31103509 lost_events);
3510
+ }
31113511
31123512 if (event) {
31133513 iter->ent_size = ring_buffer_event_length(event);
....@@ -3121,7 +3521,7 @@
31213521 __find_next_entry(struct trace_iterator *iter, int *ent_cpu,
31223522 unsigned long *missing_events, u64 *ent_ts)
31233523 {
3124
- struct ring_buffer *buffer = iter->trace_buffer->buffer;
3524
+ struct trace_buffer *buffer = iter->array_buffer->buffer;
31253525 struct trace_entry *ent, *next = NULL;
31263526 unsigned long lost_events = 0, next_lost = 0;
31273527 int cpu_file = iter->cpu_file;
....@@ -3177,11 +3577,53 @@
31773577 return next;
31783578 }
31793579
3580
+#define STATIC_TEMP_BUF_SIZE 128
3581
+static char static_temp_buf[STATIC_TEMP_BUF_SIZE] __aligned(4);
3582
+
31803583 /* Find the next real entry, without updating the iterator itself */
31813584 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
31823585 int *ent_cpu, u64 *ent_ts)
31833586 {
3184
- return __find_next_entry(iter, ent_cpu, NULL, ent_ts);
3587
+ /* __find_next_entry will reset ent_size */
3588
+ int ent_size = iter->ent_size;
3589
+ struct trace_entry *entry;
3590
+
3591
+ /*
3592
+ * If called from ftrace_dump(), then the iter->temp buffer
3593
+ * will be the static_temp_buf and not created from kmalloc.
3594
+ * If the entry size is greater than the buffer, we can
3595
+ * not save it. Just return NULL in that case. This is only
3596
+ * used to add markers when two consecutive events' time
3597
+ * stamps have a large delta. See trace_print_lat_context()
3598
+ */
3599
+ if (iter->temp == static_temp_buf &&
3600
+ STATIC_TEMP_BUF_SIZE < ent_size)
3601
+ return NULL;
3602
+
3603
+ /*
3604
+ * The __find_next_entry() may call peek_next_entry(), which may
3605
+ * call ring_buffer_peek() that may make the contents of iter->ent
3606
+ * undefined. Need to copy iter->ent now.
3607
+ */
3608
+ if (iter->ent && iter->ent != iter->temp) {
3609
+ if ((!iter->temp || iter->temp_size < iter->ent_size) &&
3610
+ !WARN_ON_ONCE(iter->temp == static_temp_buf)) {
3611
+ void *temp;
3612
+ temp = kmalloc(iter->ent_size, GFP_KERNEL);
3613
+ if (!temp)
3614
+ return NULL;
3615
+ kfree(iter->temp);
3616
+ iter->temp = temp;
3617
+ iter->temp_size = iter->ent_size;
3618
+ }
3619
+ memcpy(iter->temp, iter->ent, iter->ent_size);
3620
+ iter->ent = iter->temp;
3621
+ }
3622
+ entry = __find_next_entry(iter, ent_cpu, NULL, ent_ts);
3623
+ /* Put back the original ent_size */
3624
+ iter->ent_size = ent_size;
3625
+
3626
+ return entry;
31853627 }
31863628
31873629 /* Find the next real entry, and increment the iterator to the next entry */
....@@ -3198,7 +3640,7 @@
31983640
31993641 static void trace_consume(struct trace_iterator *iter)
32003642 {
3201
- ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts,
3643
+ ring_buffer_consume(iter->array_buffer->buffer, iter->cpu, &iter->ts,
32023644 &iter->lost_events);
32033645 }
32043646
....@@ -3231,12 +3673,11 @@
32313673
32323674 void tracing_iter_reset(struct trace_iterator *iter, int cpu)
32333675 {
3234
- struct ring_buffer_event *event;
32353676 struct ring_buffer_iter *buf_iter;
32363677 unsigned long entries = 0;
32373678 u64 ts;
32383679
3239
- per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0;
3680
+ per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = 0;
32403681
32413682 buf_iter = trace_buffer_iter(iter, cpu);
32423683 if (!buf_iter)
....@@ -3249,14 +3690,14 @@
32493690 * that a reset never took place on a cpu. This is evident
32503691 * by the timestamp being before the start of the buffer.
32513692 */
3252
- while ((event = ring_buffer_iter_peek(buf_iter, &ts))) {
3253
- if (ts >= iter->trace_buffer->time_start)
3693
+ while (ring_buffer_iter_peek(buf_iter, &ts)) {
3694
+ if (ts >= iter->array_buffer->time_start)
32543695 break;
32553696 entries++;
3256
- ring_buffer_read(buf_iter, NULL);
3697
+ ring_buffer_iter_advance(buf_iter);
32573698 }
32583699
3259
- per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries;
3700
+ per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = entries;
32603701 }
32613702
32623703 /*
....@@ -3335,49 +3776,84 @@
33353776 }
33363777
33373778 static void
3338
-get_total_entries(struct trace_buffer *buf,
3339
- unsigned long *total, unsigned long *entries)
3779
+get_total_entries_cpu(struct array_buffer *buf, unsigned long *total,
3780
+ unsigned long *entries, int cpu)
33403781 {
33413782 unsigned long count;
3783
+
3784
+ count = ring_buffer_entries_cpu(buf->buffer, cpu);
3785
+ /*
3786
+ * If this buffer has skipped entries, then we hold all
3787
+ * entries for the trace and we need to ignore the
3788
+ * ones before the time stamp.
3789
+ */
3790
+ if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
3791
+ count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
3792
+ /* total is the same as the entries */
3793
+ *total = count;
3794
+ } else
3795
+ *total = count +
3796
+ ring_buffer_overrun_cpu(buf->buffer, cpu);
3797
+ *entries = count;
3798
+}
3799
+
3800
+static void
3801
+get_total_entries(struct array_buffer *buf,
3802
+ unsigned long *total, unsigned long *entries)
3803
+{
3804
+ unsigned long t, e;
33423805 int cpu;
33433806
33443807 *total = 0;
33453808 *entries = 0;
33463809
33473810 for_each_tracing_cpu(cpu) {
3348
- count = ring_buffer_entries_cpu(buf->buffer, cpu);
3349
- /*
3350
- * If this buffer has skipped entries, then we hold all
3351
- * entries for the trace and we need to ignore the
3352
- * ones before the time stamp.
3353
- */
3354
- if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
3355
- count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
3356
- /* total is the same as the entries */
3357
- *total += count;
3358
- } else
3359
- *total += count +
3360
- ring_buffer_overrun_cpu(buf->buffer, cpu);
3361
- *entries += count;
3811
+ get_total_entries_cpu(buf, &t, &e, cpu);
3812
+ *total += t;
3813
+ *entries += e;
33623814 }
3815
+}
3816
+
3817
+unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu)
3818
+{
3819
+ unsigned long total, entries;
3820
+
3821
+ if (!tr)
3822
+ tr = &global_trace;
3823
+
3824
+ get_total_entries_cpu(&tr->array_buffer, &total, &entries, cpu);
3825
+
3826
+ return entries;
3827
+}
3828
+
3829
+unsigned long trace_total_entries(struct trace_array *tr)
3830
+{
3831
+ unsigned long total, entries;
3832
+
3833
+ if (!tr)
3834
+ tr = &global_trace;
3835
+
3836
+ get_total_entries(&tr->array_buffer, &total, &entries);
3837
+
3838
+ return entries;
33633839 }
33643840
33653841 static void print_lat_help_header(struct seq_file *m)
33663842 {
3367
- seq_puts(m, "# _--------=> CPU# \n"
3368
- "# / _-------=> irqs-off \n"
3369
- "# | / _------=> need-resched \n"
3370
- "# || / _-----=> need-resched_lazy \n"
3371
- "# ||| / _----=> hardirq/softirq \n"
3372
- "# |||| / _---=> preempt-depth \n"
3373
- "# ||||| / _--=> preempt-lazy-depth\n"
3374
- "# |||||| / _-=> migrate-disable \n"
3375
- "# ||||||| / delay \n"
3376
- "# cmd pid |||||||| time | caller \n"
3377
- "# \\ / |||||||| \\ | / \n");
3843
+ seq_puts(m, "# _--------=> CPU# \n"
3844
+ "# / _-------=> irqs-off \n"
3845
+ "# | / _------=> need-resched \n"
3846
+ "# || / _-----=> need-resched-lazy\n"
3847
+ "# ||| / _----=> hardirq/softirq \n"
3848
+ "# |||| / _---=> preempt-depth \n"
3849
+ "# ||||| / _--=> preempt-lazy-depth\n"
3850
+ "# |||||| / _-=> migrate-disable \n"
3851
+ "# ||||||| / delay \n"
3852
+ "# cmd pid |||||||| time | caller \n"
3853
+ "# \\ / |||||||| \\ | / \n");
33783854 }
33793855
3380
-static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
3856
+static void print_event_info(struct array_buffer *buf, struct seq_file *m)
33813857 {
33823858 unsigned long total;
33833859 unsigned long entries;
....@@ -3388,49 +3864,43 @@
33883864 seq_puts(m, "#\n");
33893865 }
33903866
3391
-static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m,
3867
+static void print_func_help_header(struct array_buffer *buf, struct seq_file *m,
33923868 unsigned int flags)
33933869 {
33943870 bool tgid = flags & TRACE_ITER_RECORD_TGID;
33953871
33963872 print_event_info(buf, m);
33973873
3398
- seq_printf(m, "# TASK-PID %s CPU# TIMESTAMP FUNCTION\n", tgid ? "TGID " : "");
3399
- seq_printf(m, "# | | %s | | |\n", tgid ? " | " : "");
3874
+ seq_printf(m, "# TASK-PID %s CPU# TIMESTAMP FUNCTION\n", tgid ? " TGID " : "");
3875
+ seq_printf(m, "# | | %s | | |\n", tgid ? " | " : "");
34003876 }
34013877
3402
-static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m,
3878
+static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file *m,
34033879 unsigned int flags)
34043880 {
34053881 bool tgid = flags & TRACE_ITER_RECORD_TGID;
3406
- const char tgid_space[] = " ";
3407
- const char space[] = " ";
3882
+ const char *space = " ";
3883
+ int prec = tgid ? 12 : 2;
34083884
34093885 print_event_info(buf, m);
34103886
3411
- seq_printf(m, "# %s _-----=> irqs-off\n",
3412
- tgid ? tgid_space : space);
3413
- seq_printf(m, "# %s / _----=> need-resched\n",
3414
- tgid ? tgid_space : space);
3415
- seq_printf(m, "# %s| / _---=> need-resched_lazy\n",
3416
- tgid ? tgid_space : space);
3417
- seq_printf(m, "# %s|| / _--=> hardirq/softirq\n",
3418
- tgid ? tgid_space : space);
3419
- seq_printf(m, "# %s||| / preempt-depth\n",
3420
- tgid ? tgid_space : space);
3421
- seq_printf(m, "# %s|||| / delay\n",
3422
- tgid ? tgid_space : space);
3423
- seq_printf(m, "# TASK-PID %sCPU# ||||| TIMESTAMP FUNCTION\n",
3424
- tgid ? " TGID " : space);
3425
- seq_printf(m, "# | | %s | ||||| | |\n",
3426
- tgid ? " | " : space);
3887
+ seq_printf(m, "# %.*s _-------=> irqs-off\n", prec, space);
3888
+ seq_printf(m, "# %.*s / _------=> need-resched\n", prec, space);
3889
+ seq_printf(m, "# %.*s| / _-----=> need-resched-lazy\n", prec, space);
3890
+ seq_printf(m, "# %.*s|| / _----=> hardirq/softirq\n", prec, space);
3891
+ seq_printf(m, "# %.*s||| / _---=> preempt-depth\n", prec, space);
3892
+ seq_printf(m, "# %.*s|||| / _--=> preempt-lazy-depth\n", prec, space);
3893
+ seq_printf(m, "# %.*s||||| / _-=> migrate-disable\n", prec, space);
3894
+ seq_printf(m, "# %.*s|||||| / delay\n", prec, space);
3895
+ seq_printf(m, "# TASK-PID %.*s CPU# ||||||| TIMESTAMP FUNCTION\n", prec, " TGID ");
3896
+ seq_printf(m, "# | | %.*s | ||||||| | |\n", prec, " | ");
34273897 }
34283898
34293899 void
34303900 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
34313901 {
34323902 unsigned long sym_flags = (global_trace.trace_flags & TRACE_ITER_SYM_MASK);
3433
- struct trace_buffer *buf = iter->trace_buffer;
3903
+ struct array_buffer *buf = iter->array_buffer;
34343904 struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu);
34353905 struct tracer *type = iter->trace;
34363906 unsigned long entries;
....@@ -3457,6 +3927,8 @@
34573927 "desktop",
34583928 #elif defined(CONFIG_PREEMPT)
34593929 "preempt",
3930
+#elif defined(CONFIG_PREEMPT_RT)
3931
+ "preempt_rt",
34603932 #else
34613933 "unknown",
34623934 #endif
....@@ -3503,7 +3975,7 @@
35033975 cpumask_test_cpu(iter->cpu, iter->started))
35043976 return;
35053977
3506
- if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries)
3978
+ if (per_cpu_ptr(iter->array_buffer->data, iter->cpu)->skipped_entries)
35073979 return;
35083980
35093981 if (cpumask_available(iter->started))
....@@ -3637,7 +4109,7 @@
36374109 if (!ring_buffer_iter_empty(buf_iter))
36384110 return 0;
36394111 } else {
3640
- if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu))
4112
+ if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu))
36414113 return 0;
36424114 }
36434115 return 1;
....@@ -3649,7 +4121,7 @@
36494121 if (!ring_buffer_iter_empty(buf_iter))
36504122 return 0;
36514123 } else {
3652
- if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu))
4124
+ if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu))
36534125 return 0;
36544126 }
36554127 }
....@@ -3665,8 +4137,12 @@
36654137 enum print_line_t ret;
36664138
36674139 if (iter->lost_events) {
3668
- trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
3669
- iter->cpu, iter->lost_events);
4140
+ if (iter->lost_events == (unsigned long)-1)
4141
+ trace_seq_printf(&iter->seq, "CPU:%d [LOST EVENTS]\n",
4142
+ iter->cpu);
4143
+ else
4144
+ trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
4145
+ iter->cpu, iter->lost_events);
36704146 if (trace_seq_has_overflowed(&iter->seq))
36714147 return TRACE_TYPE_PARTIAL_LINE;
36724148 }
....@@ -3739,10 +4215,10 @@
37394215 } else {
37404216 if (!(trace_flags & TRACE_ITER_VERBOSE)) {
37414217 if (trace_flags & TRACE_ITER_IRQ_INFO)
3742
- print_func_help_header_irq(iter->trace_buffer,
4218
+ print_func_help_header_irq(iter->array_buffer,
37434219 m, trace_flags);
37444220 else
3745
- print_func_help_header(iter->trace_buffer, m,
4221
+ print_func_help_header(iter->array_buffer, m,
37464222 trace_flags);
37474223 }
37484224 }
....@@ -3882,6 +4358,18 @@
38824358 goto release;
38834359
38844360 /*
4361
+ * trace_find_next_entry() may need to save off iter->ent.
4362
+ * It will place it into the iter->temp buffer. As most
4363
+ * events are less than 128, allocate a buffer of that size.
4364
+ * If one is greater, then trace_find_next_entry() will
4365
+ * allocate a new buffer to adjust for the bigger iter->ent.
4366
+ * It's not critical if it fails to get allocated here.
4367
+ */
4368
+ iter->temp = kmalloc(128, GFP_KERNEL);
4369
+ if (iter->temp)
4370
+ iter->temp_size = 128;
4371
+
4372
+ /*
38854373 * We make a copy of the current tracer to avoid concurrent
38864374 * changes on it while we are reading.
38874375 */
....@@ -3900,35 +4388,38 @@
39004388 #ifdef CONFIG_TRACER_MAX_TRACE
39014389 /* Currently only the top directory has a snapshot */
39024390 if (tr->current_trace->print_max || snapshot)
3903
- iter->trace_buffer = &tr->max_buffer;
4391
+ iter->array_buffer = &tr->max_buffer;
39044392 else
39054393 #endif
3906
- iter->trace_buffer = &tr->trace_buffer;
4394
+ iter->array_buffer = &tr->array_buffer;
39074395 iter->snapshot = snapshot;
39084396 iter->pos = -1;
39094397 iter->cpu_file = tracing_get_cpu(inode);
39104398 mutex_init(&iter->mutex);
39114399
39124400 /* Notify the tracer early; before we stop tracing. */
3913
- if (iter->trace && iter->trace->open)
4401
+ if (iter->trace->open)
39144402 iter->trace->open(iter);
39154403
39164404 /* Annotate start of buffers if we had overruns */
3917
- if (ring_buffer_overruns(iter->trace_buffer->buffer))
4405
+ if (ring_buffer_overruns(iter->array_buffer->buffer))
39184406 iter->iter_flags |= TRACE_FILE_ANNOTATE;
39194407
39204408 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
39214409 if (trace_clocks[tr->clock_id].in_ns)
39224410 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
39234411
3924
- /* stop the trace while dumping if we are not opening "snapshot" */
3925
- if (!iter->snapshot)
4412
+ /*
4413
+ * If pause-on-trace is enabled, then stop the trace while
4414
+ * dumping, unless this is the "snapshot" file
4415
+ */
4416
+ if (!iter->snapshot && (tr->trace_flags & TRACE_ITER_PAUSE_ON_TRACE))
39264417 tracing_stop_tr(tr);
39274418
39284419 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
39294420 for_each_tracing_cpu(cpu) {
39304421 iter->buffer_iter[cpu] =
3931
- ring_buffer_read_prepare(iter->trace_buffer->buffer,
4422
+ ring_buffer_read_prepare(iter->array_buffer->buffer,
39324423 cpu, GFP_KERNEL);
39334424 }
39344425 ring_buffer_read_prepare_sync();
....@@ -3939,7 +4430,7 @@
39394430 } else {
39404431 cpu = iter->cpu_file;
39414432 iter->buffer_iter[cpu] =
3942
- ring_buffer_read_prepare(iter->trace_buffer->buffer,
4433
+ ring_buffer_read_prepare(iter->array_buffer->buffer,
39434434 cpu, GFP_KERNEL);
39444435 ring_buffer_read_prepare_sync();
39454436 ring_buffer_read_start(iter->buffer_iter[cpu]);
....@@ -3953,6 +4444,7 @@
39534444 fail:
39544445 mutex_unlock(&trace_types_lock);
39554446 kfree(iter->trace);
4447
+ kfree(iter->temp);
39564448 kfree(iter->buffer_iter);
39574449 release:
39584450 seq_release_private(inode, file);
....@@ -3961,8 +4453,11 @@
39614453
39624454 int tracing_open_generic(struct inode *inode, struct file *filp)
39634455 {
3964
- if (tracing_disabled)
3965
- return -ENODEV;
4456
+ int ret;
4457
+
4458
+ ret = tracing_check_open_get_tr(NULL);
4459
+ if (ret)
4460
+ return ret;
39664461
39674462 filp->private_data = inode->i_private;
39684463 return 0;
....@@ -3977,15 +4472,14 @@
39774472 * Open and update trace_array ref count.
39784473 * Must have the current trace_array passed to it.
39794474 */
3980
-static int tracing_open_generic_tr(struct inode *inode, struct file *filp)
4475
+int tracing_open_generic_tr(struct inode *inode, struct file *filp)
39814476 {
39824477 struct trace_array *tr = inode->i_private;
4478
+ int ret;
39834479
3984
- if (tracing_disabled)
3985
- return -ENODEV;
3986
-
3987
- if (trace_array_get(tr) < 0)
3988
- return -ENODEV;
4480
+ ret = tracing_check_open_get_tr(tr);
4481
+ if (ret)
4482
+ return ret;
39894483
39904484 filp->private_data = inode->i_private;
39914485
....@@ -4016,7 +4510,7 @@
40164510 if (iter->trace && iter->trace->close)
40174511 iter->trace->close(iter);
40184512
4019
- if (!iter->snapshot)
4513
+ if (!iter->snapshot && tr->stop_count)
40204514 /* reenable tracing if it was previously enabled */
40214515 tracing_start_tr(tr);
40224516
....@@ -4026,6 +4520,7 @@
40264520
40274521 mutex_destroy(&iter->mutex);
40284522 free_cpumask_var(iter->started);
4523
+ kfree(iter->temp);
40294524 kfree(iter->trace);
40304525 kfree(iter->buffer_iter);
40314526 seq_release_private(inode, file);
....@@ -4054,15 +4549,16 @@
40544549 {
40554550 struct trace_array *tr = inode->i_private;
40564551 struct trace_iterator *iter;
4057
- int ret = 0;
4552
+ int ret;
40584553
4059
- if (trace_array_get(tr) < 0)
4060
- return -ENODEV;
4554
+ ret = tracing_check_open_get_tr(tr);
4555
+ if (ret)
4556
+ return ret;
40614557
40624558 /* If this file was open for write, then erase contents */
40634559 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
40644560 int cpu = tracing_get_cpu(inode);
4065
- struct trace_buffer *trace_buf = &tr->trace_buffer;
4561
+ struct array_buffer *trace_buf = &tr->array_buffer;
40664562
40674563 #ifdef CONFIG_TRACER_MAX_TRACE
40684564 if (tr->current_trace->print_max)
....@@ -4072,7 +4568,7 @@
40724568 if (cpu == RING_BUFFER_ALL_CPUS)
40734569 tracing_reset_online_cpus(trace_buf);
40744570 else
4075
- tracing_reset(trace_buf, cpu);
4571
+ tracing_reset_cpu(trace_buf, cpu);
40764572 }
40774573
40784574 if (file->f_mode & FMODE_READ) {
....@@ -4173,11 +4669,9 @@
41734669 struct seq_file *m;
41744670 int ret;
41754671
4176
- if (tracing_disabled)
4177
- return -ENODEV;
4178
-
4179
- if (trace_array_get(tr) < 0)
4180
- return -ENODEV;
4672
+ ret = tracing_check_open_get_tr(tr);
4673
+ if (ret)
4674
+ return ret;
41814675
41824676 ret = seq_open(file, &show_traces_seq_ops);
41834677 if (ret) {
....@@ -4261,20 +4755,13 @@
42614755 return count;
42624756 }
42634757
4264
-static ssize_t
4265
-tracing_cpumask_write(struct file *filp, const char __user *ubuf,
4266
- size_t count, loff_t *ppos)
4758
+int tracing_set_cpumask(struct trace_array *tr,
4759
+ cpumask_var_t tracing_cpumask_new)
42674760 {
4268
- struct trace_array *tr = file_inode(filp)->i_private;
4269
- cpumask_var_t tracing_cpumask_new;
4270
- int err, cpu;
4761
+ int cpu;
42714762
4272
- if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
4273
- return -ENOMEM;
4274
-
4275
- err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
4276
- if (err)
4277
- goto err_unlock;
4763
+ if (!tr)
4764
+ return -EINVAL;
42784765
42794766 local_irq_disable();
42804767 arch_spin_lock(&tr->max_lock);
....@@ -4285,24 +4772,47 @@
42854772 */
42864773 if (cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
42874774 !cpumask_test_cpu(cpu, tracing_cpumask_new)) {
4288
- atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
4289
- ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu);
4775
+ atomic_inc(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled);
4776
+ ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu);
42904777 }
42914778 if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
42924779 cpumask_test_cpu(cpu, tracing_cpumask_new)) {
4293
- atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
4294
- ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu);
4780
+ atomic_dec(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled);
4781
+ ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu);
42954782 }
42964783 }
42974784 arch_spin_unlock(&tr->max_lock);
42984785 local_irq_enable();
42994786
43004787 cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new);
4788
+
4789
+ return 0;
4790
+}
4791
+
4792
+static ssize_t
4793
+tracing_cpumask_write(struct file *filp, const char __user *ubuf,
4794
+ size_t count, loff_t *ppos)
4795
+{
4796
+ struct trace_array *tr = file_inode(filp)->i_private;
4797
+ cpumask_var_t tracing_cpumask_new;
4798
+ int err;
4799
+
4800
+ if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
4801
+ return -ENOMEM;
4802
+
4803
+ err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
4804
+ if (err)
4805
+ goto err_free;
4806
+
4807
+ err = tracing_set_cpumask(tr, tracing_cpumask_new);
4808
+ if (err)
4809
+ goto err_free;
4810
+
43014811 free_cpumask_var(tracing_cpumask_new);
43024812
43034813 return count;
43044814
4305
-err_unlock:
4815
+err_free:
43064816 free_cpumask_var(tracing_cpumask_new);
43074817
43084818 return err;
....@@ -4444,7 +4954,7 @@
44444954 ftrace_pid_follow_fork(tr, enabled);
44454955
44464956 if (mask == TRACE_ITER_OVERWRITE) {
4447
- ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled);
4957
+ ring_buffer_change_overwrite(tr->array_buffer.buffer, enabled);
44484958 #ifdef CONFIG_TRACER_MAX_TRACE
44494959 ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled);
44504960 #endif
....@@ -4458,19 +4968,21 @@
44584968 return 0;
44594969 }
44604970
4461
-static int trace_set_options(struct trace_array *tr, char *option)
4971
+int trace_set_options(struct trace_array *tr, char *option)
44624972 {
44634973 char *cmp;
44644974 int neg = 0;
44654975 int ret;
44664976 size_t orig_len = strlen(option);
4977
+ int len;
44674978
44684979 cmp = strstrip(option);
44694980
4470
- if (strncmp(cmp, "no", 2) == 0) {
4981
+ len = str_has_prefix(cmp, "no");
4982
+ if (len)
44714983 neg = 1;
4472
- cmp += 2;
4473
- }
4984
+
4985
+ cmp += len;
44744986
44754987 mutex_lock(&event_mutex);
44764988 mutex_lock(&trace_types_lock);
....@@ -4546,11 +5058,9 @@
45465058 struct trace_array *tr = inode->i_private;
45475059 int ret;
45485060
4549
- if (tracing_disabled)
4550
- return -ENODEV;
4551
-
4552
- if (trace_array_get(tr) < 0)
4553
- return -ENODEV;
5061
+ ret = tracing_check_open_get_tr(tr);
5062
+ if (ret)
5063
+ return ret;
45545064
45555065 ret = single_open(file, tracing_trace_options_show, inode->i_private);
45565066 if (ret < 0)
....@@ -4577,6 +5087,7 @@
45775087 " trace_pipe\t\t- A consuming read to see the contents of the buffer\n"
45785088 " current_tracer\t- function and latency tracers\n"
45795089 " available_tracers\t- list of configured tracers for current_tracer\n"
5090
+ " error_log\t- error log for failed commands (that support it)\n"
45805091 " buffer_size_kb\t- view and modify size of per cpu buffer\n"
45815092 " buffer_total_size_kb - view total size of all cpu buffers\n\n"
45825093 " trace_clock\t\t-change the clock used to order events\n"
....@@ -4597,7 +5108,7 @@
45975108 " instances\t\t- Make sub-buffers with: mkdir instances/foo\n"
45985109 "\t\t\t Remove sub-buffer with rmdir\n"
45995110 " trace_options\t\t- Set format or modify how tracing happens\n"
4600
- "\t\t\t Disable an option by adding a suffix 'no' to the\n"
5111
+ "\t\t\t Disable an option by prefixing 'no' to the\n"
46015112 "\t\t\t option name\n"
46025113 " saved_cmdlines_size\t- echo command number in here to store comm-pid list\n"
46035114 #ifdef CONFIG_DYNAMIC_FTRACE
....@@ -4641,6 +5152,8 @@
46415152 #ifdef CONFIG_FUNCTION_TRACER
46425153 " set_ftrace_pid\t- Write pid(s) to only function trace those pids\n"
46435154 "\t\t (function)\n"
5155
+ " set_ftrace_notrace_pid\t- Write pid(s) to not function trace those pids\n"
5156
+ "\t\t (function)\n"
46445157 #endif
46455158 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
46465159 " set_graph_function\t- Trace the nested calls of a function (function_graph)\n"
....@@ -4662,31 +5175,49 @@
46625175 "\t\t\t traces\n"
46635176 #endif
46645177 #endif /* CONFIG_STACK_TRACER */
5178
+#ifdef CONFIG_DYNAMIC_EVENTS
5179
+ " dynamic_events\t\t- Create/append/remove/show the generic dynamic events\n"
5180
+ "\t\t\t Write into this file to define/undefine new trace events.\n"
5181
+#endif
46655182 #ifdef CONFIG_KPROBE_EVENTS
4666
- " kprobe_events\t\t- Add/remove/show the kernel dynamic events\n"
5183
+ " kprobe_events\t\t- Create/append/remove/show the kernel dynamic events\n"
46675184 "\t\t\t Write into this file to define/undefine new trace events.\n"
46685185 #endif
46695186 #ifdef CONFIG_UPROBE_EVENTS
4670
- " uprobe_events\t\t- Add/remove/show the userspace dynamic events\n"
5187
+ " uprobe_events\t\t- Create/append/remove/show the userspace dynamic events\n"
46715188 "\t\t\t Write into this file to define/undefine new trace events.\n"
46725189 #endif
46735190 #if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
46745191 "\t accepts: event-definitions (one definition per line)\n"
46755192 "\t Format: p[:[<group>/]<event>] <place> [<args>]\n"
46765193 "\t r[maxactive][:[<group>/]<event>] <place> [<args>]\n"
5194
+#ifdef CONFIG_HIST_TRIGGERS
5195
+ "\t s:[synthetic/]<event> <field> [<field>]\n"
5196
+#endif
46775197 "\t -:[<group>/]<event>\n"
46785198 #ifdef CONFIG_KPROBE_EVENTS
46795199 "\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
4680
- "place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n"
5200
+ "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
46815201 #endif
46825202 #ifdef CONFIG_UPROBE_EVENTS
4683
- "\t place: <path>:<offset>\n"
5203
+ " place (uprobe): <path>:<offset>[%return][(ref_ctr_offset)]\n"
46845204 #endif
46855205 "\t args: <name>=fetcharg[:type]\n"
46865206 "\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
4687
- "\t $stack<index>, $stack, $retval, $comm\n"
4688
- "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,\n"
4689
- "\t b<bit-width>@<bit-offset>/<container-size>\n"
5207
+#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
5208
+ "\t $stack<index>, $stack, $retval, $comm, $arg<N>,\n"
5209
+#else
5210
+ "\t $stack<index>, $stack, $retval, $comm,\n"
5211
+#endif
5212
+ "\t +|-[u]<offset>(<fetcharg>), \\imm-value, \\\"imm-string\"\n"
5213
+ "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n"
5214
+ "\t b<bit-width>@<bit-offset>/<container-size>, ustring,\n"
5215
+ "\t <type>\\[<array-size>\\]\n"
5216
+#ifdef CONFIG_HIST_TRIGGERS
5217
+ "\t field: <stype> <name>;\n"
5218
+ "\t stype: u8/u16/u32/u64, s8/s16/s32/s64, pid_t,\n"
5219
+ "\t [unsigned] char/int/long\n"
5220
+#endif
46905221 #endif
46915222 " events/\t\t- Directory containing all trace event subsystems:\n"
46925223 " enable\t\t- Write 0/1 to enable/disable tracing of all events\n"
....@@ -4739,6 +5270,7 @@
47395270 "\t [:size=#entries]\n"
47405271 "\t [:pause][:continue][:clear]\n"
47415272 "\t [:name=histname1]\n"
5273
+ "\t [:<handler>.<action>]\n"
47425274 "\t [if <filter>]\n\n"
47435275 "\t Note, special fields can be used as well:\n"
47445276 "\t common_timestamp - to record current timestamp\n"
....@@ -4783,8 +5315,26 @@
47835315 "\t unchanged.\n\n"
47845316 "\t The enable_hist and disable_hist triggers can be used to\n"
47855317 "\t have one event conditionally start and stop another event's\n"
4786
- "\t already-attached hist trigger. The syntax is analagous to\n"
4787
- "\t the enable_event and disable_event triggers.\n"
5318
+ "\t already-attached hist trigger. The syntax is analogous to\n"
5319
+ "\t the enable_event and disable_event triggers.\n\n"
5320
+ "\t Hist trigger handlers and actions are executed whenever a\n"
5321
+ "\t a histogram entry is added or updated. They take the form:\n\n"
5322
+ "\t <handler>.<action>\n\n"
5323
+ "\t The available handlers are:\n\n"
5324
+ "\t onmatch(matching.event) - invoke on addition or update\n"
5325
+ "\t onmax(var) - invoke if var exceeds current max\n"
5326
+ "\t onchange(var) - invoke action if var changes\n\n"
5327
+ "\t The available actions are:\n\n"
5328
+ "\t trace(<synthetic_event>,param list) - generate synthetic event\n"
5329
+ "\t save(field,...) - save current event fields\n"
5330
+#ifdef CONFIG_TRACER_SNAPSHOT
5331
+ "\t snapshot() - snapshot the trace buffer\n\n"
5332
+#endif
5333
+#ifdef CONFIG_SYNTH_EVENTS
5334
+ " events/synthetic_events\t- Create/append/remove/show synthetic events\n"
5335
+ "\t Write into this file to define/undefine new synthetic events.\n"
5336
+ "\t example: echo 'myevent u64 lat; char name[]' >> synthetic_events\n"
5337
+#endif
47885338 #endif
47895339 ;
47905340
....@@ -4842,8 +5392,11 @@
48425392
48435393 static int tracing_saved_tgids_open(struct inode *inode, struct file *filp)
48445394 {
4845
- if (tracing_disabled)
4846
- return -ENODEV;
5395
+ int ret;
5396
+
5397
+ ret = tracing_check_open_get_tr(NULL);
5398
+ if (ret)
5399
+ return ret;
48475400
48485401 return seq_open(filp, &tracing_saved_tgids_seq_ops);
48495402 }
....@@ -4919,8 +5472,11 @@
49195472
49205473 static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp)
49215474 {
4922
- if (tracing_disabled)
4923
- return -ENODEV;
5475
+ int ret;
5476
+
5477
+ ret = tracing_check_open_get_tr(NULL);
5478
+ if (ret)
5479
+ return ret;
49245480
49255481 return seq_open(filp, &tracing_saved_cmdlines_seq_ops);
49265482 }
....@@ -4939,9 +5495,11 @@
49395495 char buf[64];
49405496 int r;
49415497
5498
+ preempt_disable();
49425499 arch_spin_lock(&trace_cmdline_lock);
49435500 r = scnprintf(buf, sizeof(buf), "%u\n", savedcmd->cmdline_num);
49445501 arch_spin_unlock(&trace_cmdline_lock);
5502
+ preempt_enable();
49455503
49465504 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
49475505 }
....@@ -4966,10 +5524,12 @@
49665524 return -ENOMEM;
49675525 }
49685526
5527
+ preempt_disable();
49695528 arch_spin_lock(&trace_cmdline_lock);
49705529 savedcmd_temp = savedcmd;
49715530 savedcmd = s;
49725531 arch_spin_unlock(&trace_cmdline_lock);
5532
+ preempt_enable();
49735533 free_saved_cmdlines_buffer(savedcmd_temp);
49745534
49755535 return 0;
....@@ -5028,14 +5588,12 @@
50285588 * Paranoid! If ptr points to end, we don't want to increment past it.
50295589 * This really should never happen.
50305590 */
5591
+ (*pos)++;
50315592 ptr = update_eval_map(ptr);
50325593 if (WARN_ON_ONCE(!ptr))
50335594 return NULL;
50345595
50355596 ptr++;
5036
-
5037
- (*pos)++;
5038
-
50395597 ptr = update_eval_map(ptr);
50405598
50415599 return ptr;
....@@ -5084,8 +5642,11 @@
50845642
50855643 static int tracing_eval_map_open(struct inode *inode, struct file *filp)
50865644 {
5087
- if (tracing_disabled)
5088
- return -ENODEV;
5645
+ int ret;
5646
+
5647
+ ret = tracing_check_open_get_tr(NULL);
5648
+ if (ret)
5649
+ return ret;
50895650
50905651 return seq_open(filp, &tracing_eval_map_seq_ops);
50915652 }
....@@ -5198,11 +5759,11 @@
51985759
51995760 int tracer_init(struct tracer *t, struct trace_array *tr)
52005761 {
5201
- tracing_reset_online_cpus(&tr->trace_buffer);
5762
+ tracing_reset_online_cpus(&tr->array_buffer);
52025763 return t->init(tr);
52035764 }
52045765
5205
-static void set_buffer_entries(struct trace_buffer *buf, unsigned long val)
5766
+static void set_buffer_entries(struct array_buffer *buf, unsigned long val)
52065767 {
52075768 int cpu;
52085769
....@@ -5212,8 +5773,8 @@
52125773
52135774 #ifdef CONFIG_TRACER_MAX_TRACE
52145775 /* resize @tr's buffer to the size of @size_tr's entries */
5215
-static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
5216
- struct trace_buffer *size_buf, int cpu_id)
5776
+static int resize_buffer_duplicate_size(struct array_buffer *trace_buf,
5777
+ struct array_buffer *size_buf, int cpu_id)
52175778 {
52185779 int cpu, ret = 0;
52195780
....@@ -5251,10 +5812,10 @@
52515812 ring_buffer_expanded = true;
52525813
52535814 /* May be called before buffers are initialized */
5254
- if (!tr->trace_buffer.buffer)
5815
+ if (!tr->array_buffer.buffer)
52555816 return 0;
52565817
5257
- ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu);
5818
+ ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu);
52585819 if (ret < 0)
52595820 return ret;
52605821
....@@ -5265,8 +5826,8 @@
52655826
52665827 ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu);
52675828 if (ret < 0) {
5268
- int r = resize_buffer_duplicate_size(&tr->trace_buffer,
5269
- &tr->trace_buffer, cpu);
5829
+ int r = resize_buffer_duplicate_size(&tr->array_buffer,
5830
+ &tr->array_buffer, cpu);
52705831 if (r < 0) {
52715832 /*
52725833 * AARGH! We are left with different
....@@ -5297,15 +5858,15 @@
52975858 #endif /* CONFIG_TRACER_MAX_TRACE */
52985859
52995860 if (cpu == RING_BUFFER_ALL_CPUS)
5300
- set_buffer_entries(&tr->trace_buffer, size);
5861
+ set_buffer_entries(&tr->array_buffer, size);
53015862 else
5302
- per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size;
5863
+ per_cpu_ptr(tr->array_buffer.data, cpu)->entries = size;
53035864
53045865 return ret;
53055866 }
53065867
5307
-static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
5308
- unsigned long size, int cpu_id)
5868
+ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
5869
+ unsigned long size, int cpu_id)
53095870 {
53105871 int ret = size;
53115872
....@@ -5375,16 +5936,22 @@
53755936 tr->current_trace = &nop_trace;
53765937 }
53775938
5939
+static bool tracer_options_updated;
5940
+
53785941 static void add_tracer_options(struct trace_array *tr, struct tracer *t)
53795942 {
53805943 /* Only enable if the directory has been created already. */
53815944 if (!tr->dir)
53825945 return;
53835946
5947
+ /* Only create trace option files after update_tracer_options finish */
5948
+ if (!tracer_options_updated)
5949
+ return;
5950
+
53845951 create_trace_option_files(tr, t);
53855952 }
53865953
5387
-static int tracing_set_tracer(struct trace_array *tr, const char *buf)
5954
+int tracing_set_tracer(struct trace_array *tr, const char *buf)
53885955 {
53895956 struct tracer *t;
53905957 #ifdef CONFIG_TRACER_MAX_TRACE
....@@ -5413,6 +5980,18 @@
54135980 if (t == tr->current_trace)
54145981 goto out;
54155982
5983
+#ifdef CONFIG_TRACER_SNAPSHOT
5984
+ if (t->use_max_tr) {
5985
+ local_irq_disable();
5986
+ arch_spin_lock(&tr->max_lock);
5987
+ if (tr->cond_snapshot)
5988
+ ret = -EBUSY;
5989
+ arch_spin_unlock(&tr->max_lock);
5990
+ local_irq_enable();
5991
+ if (ret)
5992
+ goto out;
5993
+ }
5994
+#endif
54165995 /* Some tracers won't work on kernel command line */
54175996 if (system_state < SYSTEM_RUNNING && t->noboot) {
54185997 pr_warn("Tracer '%s' is not allowed on command line, ignored\n",
....@@ -5427,7 +6006,7 @@
54276006 }
54286007
54296008 /* If trace pipe files are being read, we can't change the tracer */
5430
- if (tr->current_trace->ref) {
6009
+ if (tr->trace_ref) {
54316010 ret = -EBUSY;
54326011 goto out;
54336012 }
....@@ -5439,11 +6018,11 @@
54396018 if (tr->current_trace->reset)
54406019 tr->current_trace->reset(tr);
54416020
5442
- /* Current trace needs to be nop_trace before synchronize_sched */
5443
- tr->current_trace = &nop_trace;
5444
-
54456021 #ifdef CONFIG_TRACER_MAX_TRACE
5446
- had_max_tr = tr->allocated_snapshot;
6022
+ had_max_tr = tr->current_trace->use_max_tr;
6023
+
6024
+ /* Current trace needs to be nop_trace before synchronize_rcu */
6025
+ tr->current_trace = &nop_trace;
54476026
54486027 if (had_max_tr && !t->use_max_tr) {
54496028 /*
....@@ -5453,17 +6032,17 @@
54536032 * The update_max_tr is called from interrupts disabled
54546033 * so a synchronized_sched() is sufficient.
54556034 */
5456
- synchronize_sched();
6035
+ synchronize_rcu();
54576036 free_snapshot(tr);
54586037 }
5459
-#endif
54606038
5461
-#ifdef CONFIG_TRACER_MAX_TRACE
5462
- if (t->use_max_tr && !had_max_tr) {
6039
+ if (t->use_max_tr && !tr->allocated_snapshot) {
54636040 ret = tracing_alloc_snapshot_instance(tr);
54646041 if (ret < 0)
54656042 goto out;
54666043 }
6044
+#else
6045
+ tr->current_trace = &nop_trace;
54676046 #endif
54686047
54696048 if (t->init) {
....@@ -5598,13 +6177,11 @@
55986177 {
55996178 struct trace_array *tr = inode->i_private;
56006179 struct trace_iterator *iter;
5601
- int ret = 0;
6180
+ int ret;
56026181
5603
- if (tracing_disabled)
5604
- return -ENODEV;
5605
-
5606
- if (trace_array_get(tr) < 0)
5607
- return -ENODEV;
6182
+ ret = tracing_check_open_get_tr(tr);
6183
+ if (ret)
6184
+ return ret;
56086185
56096186 mutex_lock(&trace_types_lock);
56106187
....@@ -5635,7 +6212,7 @@
56356212 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
56366213
56376214 iter->tr = tr;
5638
- iter->trace_buffer = &tr->trace_buffer;
6215
+ iter->array_buffer = &tr->array_buffer;
56396216 iter->cpu_file = tracing_get_cpu(inode);
56406217 mutex_init(&iter->mutex);
56416218 filp->private_data = iter;
....@@ -5645,7 +6222,7 @@
56456222
56466223 nonseekable_open(inode, filp);
56476224
5648
- tr->current_trace->ref++;
6225
+ tr->trace_ref++;
56496226 out:
56506227 mutex_unlock(&trace_types_lock);
56516228 return ret;
....@@ -5664,7 +6241,7 @@
56646241
56656242 mutex_lock(&trace_types_lock);
56666243
5667
- tr->current_trace->ref--;
6244
+ tr->trace_ref--;
56686245
56696246 if (iter->trace->pipe_close)
56706247 iter->trace->pipe_close(iter);
....@@ -5695,8 +6272,8 @@
56956272 */
56966273 return EPOLLIN | EPOLLRDNORM;
56976274 else
5698
- return ring_buffer_poll_wait(iter->trace_buffer->buffer, iter->cpu_file,
5699
- filp, poll_table);
6275
+ return ring_buffer_poll_wait(iter->array_buffer->buffer, iter->cpu_file,
6276
+ filp, poll_table, iter->tr->buffer_percent);
57006277 }
57016278
57026279 static __poll_t
....@@ -5733,7 +6310,7 @@
57336310
57346311 mutex_unlock(&iter->mutex);
57356312
5736
- ret = wait_on_pipe(iter, false);
6313
+ ret = wait_on_pipe(iter, 0);
57376314
57386315 mutex_lock(&iter->mutex);
57396316
....@@ -5849,14 +6426,6 @@
58496426 __free_page(spd->pages[idx]);
58506427 }
58516428
5852
-static const struct pipe_buf_operations tracing_pipe_buf_ops = {
5853
- .can_merge = 0,
5854
- .confirm = generic_pipe_buf_confirm,
5855
- .release = generic_pipe_buf_release,
5856
- .steal = generic_pipe_buf_steal,
5857
- .get = generic_pipe_buf_get,
5858
-};
5859
-
58606429 static size_t
58616430 tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
58626431 {
....@@ -5918,7 +6487,7 @@
59186487 .partial = partial_def,
59196488 .nr_pages = 0, /* This gets updated below. */
59206489 .nr_pages_max = PIPE_DEF_BUFFERS,
5921
- .ops = &tracing_pipe_buf_ops,
6490
+ .ops = &default_pipe_buf_ops,
59226491 .spd_release = tracing_spd_release_pipe,
59236492 };
59246493 ssize_t ret;
....@@ -6013,8 +6582,8 @@
60136582 for_each_tracing_cpu(cpu) {
60146583 /* fill in the size from first enabled cpu */
60156584 if (size == 0)
6016
- size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries;
6017
- if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) {
6585
+ size = per_cpu_ptr(tr->array_buffer.data, cpu)->entries;
6586
+ if (size != per_cpu_ptr(tr->array_buffer.data, cpu)->entries) {
60186587 buf_size_same = 0;
60196588 break;
60206589 }
....@@ -6030,7 +6599,7 @@
60306599 } else
60316600 r = sprintf(buf, "X\n");
60326601 } else
6033
- r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10);
6602
+ r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->array_buffer.data, cpu)->entries >> 10);
60346603
60356604 mutex_unlock(&trace_types_lock);
60366605
....@@ -6077,7 +6646,7 @@
60776646
60786647 mutex_lock(&trace_types_lock);
60796648 for_each_tracing_cpu(cpu) {
6080
- size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10;
6649
+ size += per_cpu_ptr(tr->array_buffer.data, cpu)->entries >> 10;
60816650 if (!ring_buffer_expanded)
60826651 expanded_size += trace_buf_size >> 10;
60836652 }
....@@ -6127,16 +6696,15 @@
61276696 struct trace_array *tr = filp->private_data;
61286697 struct ring_buffer_event *event;
61296698 enum event_trigger_type tt = ETT_NONE;
6130
- struct ring_buffer *buffer;
6699
+ struct trace_buffer *buffer;
61316700 struct print_entry *entry;
6132
- unsigned long irq_flags;
6133
- const char faulted[] = "<faulted>";
61346701 ssize_t written;
61356702 int size;
61366703 int len;
61376704
61386705 /* Used in tracing_mark_raw_write() as well */
6139
-#define FAULTED_SIZE (sizeof(faulted) - 1) /* '\0' is already accounted for */
6706
+#define FAULTED_STR "<faulted>"
6707
+#define FAULTED_SIZE (sizeof(FAULTED_STR) - 1) /* '\0' is already accounted for */
61406708
61416709 if (tracing_disabled)
61426710 return -EINVAL;
....@@ -6149,16 +6717,15 @@
61496717
61506718 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
61516719
6152
- local_save_flags(irq_flags);
61536720 size = sizeof(*entry) + cnt + 2; /* add '\0' and possible '\n' */
61546721
61556722 /* If less than "<faulted>", then make sure we can still add that */
61566723 if (cnt < FAULTED_SIZE)
61576724 size += FAULTED_SIZE - cnt;
61586725
6159
- buffer = tr->trace_buffer.buffer;
6726
+ buffer = tr->array_buffer.buffer;
61606727 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
6161
- irq_flags, preempt_count());
6728
+ tracing_gen_ctx());
61626729 if (unlikely(!event))
61636730 /* Ring buffer disabled, return as if not open for write */
61646731 return -EBADF;
....@@ -6168,12 +6735,11 @@
61686735
61696736 len = __copy_from_user_inatomic(&entry->buf, ubuf, cnt);
61706737 if (len) {
6171
- memcpy(&entry->buf, faulted, FAULTED_SIZE);
6738
+ memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE);
61726739 cnt = FAULTED_SIZE;
61736740 written = -EFAULT;
61746741 } else
61756742 written = cnt;
6176
- len = cnt;
61776743
61786744 if (tr->trace_marker_file && !list_empty(&tr->trace_marker_file->triggers)) {
61796745 /* do not add \n before testing triggers, but add \0 */
....@@ -6187,6 +6753,8 @@
61876753 } else
61886754 entry->buf[cnt] = '\0';
61896755
6756
+ if (static_branch_unlikely(&trace_marker_exports_enabled))
6757
+ ftrace_exports(event, TRACE_EXPORT_MARKER);
61906758 __buffer_unlock_commit(buffer, event);
61916759
61926760 if (tt)
....@@ -6207,10 +6775,8 @@
62076775 {
62086776 struct trace_array *tr = filp->private_data;
62096777 struct ring_buffer_event *event;
6210
- struct ring_buffer *buffer;
6778
+ struct trace_buffer *buffer;
62116779 struct raw_data_entry *entry;
6212
- const char faulted[] = "<faulted>";
6213
- unsigned long irq_flags;
62146780 ssize_t written;
62156781 int size;
62166782 int len;
....@@ -6232,14 +6798,13 @@
62326798
62336799 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
62346800
6235
- local_save_flags(irq_flags);
62366801 size = sizeof(*entry) + cnt;
62376802 if (cnt < FAULT_SIZE_ID)
62386803 size += FAULT_SIZE_ID - cnt;
62396804
6240
- buffer = tr->trace_buffer.buffer;
6805
+ buffer = tr->array_buffer.buffer;
62416806 event = __trace_buffer_lock_reserve(buffer, TRACE_RAW_DATA, size,
6242
- irq_flags, preempt_count());
6807
+ tracing_gen_ctx());
62436808 if (!event)
62446809 /* Ring buffer disabled, return as if not open for write */
62456810 return -EBADF;
....@@ -6249,7 +6814,7 @@
62496814 len = __copy_from_user_inatomic(&entry->id, ubuf, cnt);
62506815 if (len) {
62516816 entry->id = -1;
6252
- memcpy(&entry->buf, faulted, FAULTED_SIZE);
6817
+ memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE);
62536818 written = -EFAULT;
62546819 } else
62556820 written = cnt;
....@@ -6292,13 +6857,13 @@
62926857
62936858 tr->clock_id = i;
62946859
6295
- ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func);
6860
+ ring_buffer_set_clock(tr->array_buffer.buffer, trace_clocks[i].func);
62966861
62976862 /*
62986863 * New clock may not be consistent with the previous clock.
62996864 * Reset the buffer so that it doesn't have incomparable timestamps.
63006865 */
6301
- tracing_reset_online_cpus(&tr->trace_buffer);
6866
+ tracing_reset_online_cpus(&tr->array_buffer);
63026867
63036868 #ifdef CONFIG_TRACER_MAX_TRACE
63046869 if (tr->max_buffer.buffer)
....@@ -6344,11 +6909,9 @@
63446909 struct trace_array *tr = inode->i_private;
63456910 int ret;
63466911
6347
- if (tracing_disabled)
6348
- return -ENODEV;
6349
-
6350
- if (trace_array_get(tr))
6351
- return -ENODEV;
6912
+ ret = tracing_check_open_get_tr(tr);
6913
+ if (ret)
6914
+ return ret;
63526915
63536916 ret = single_open(file, tracing_clock_show, inode->i_private);
63546917 if (ret < 0)
....@@ -6363,7 +6926,7 @@
63636926
63646927 mutex_lock(&trace_types_lock);
63656928
6366
- if (ring_buffer_time_stamp_abs(tr->trace_buffer.buffer))
6929
+ if (ring_buffer_time_stamp_abs(tr->array_buffer.buffer))
63676930 seq_puts(m, "delta [absolute]\n");
63686931 else
63696932 seq_puts(m, "[delta] absolute\n");
....@@ -6378,11 +6941,9 @@
63786941 struct trace_array *tr = inode->i_private;
63796942 int ret;
63806943
6381
- if (tracing_disabled)
6382
- return -ENODEV;
6383
-
6384
- if (trace_array_get(tr))
6385
- return -ENODEV;
6944
+ ret = tracing_check_open_get_tr(tr);
6945
+ if (ret)
6946
+ return ret;
63866947
63876948 ret = single_open(file, tracing_time_stamp_mode_show, inode->i_private);
63886949 if (ret < 0)
....@@ -6410,7 +6971,7 @@
64106971 goto out;
64116972 }
64126973
6413
- ring_buffer_set_time_stamp_abs(tr->trace_buffer.buffer, abs);
6974
+ ring_buffer_set_time_stamp_abs(tr->array_buffer.buffer, abs);
64146975
64156976 #ifdef CONFIG_TRACER_MAX_TRACE
64166977 if (tr->max_buffer.buffer)
....@@ -6435,10 +6996,11 @@
64356996 struct trace_array *tr = inode->i_private;
64366997 struct trace_iterator *iter;
64376998 struct seq_file *m;
6438
- int ret = 0;
6999
+ int ret;
64397000
6440
- if (trace_array_get(tr) < 0)
6441
- return -ENODEV;
7001
+ ret = tracing_check_open_get_tr(tr);
7002
+ if (ret)
7003
+ return ret;
64427004
64437005 if (file->f_mode & FMODE_READ) {
64447006 iter = __tracing_open(inode, file, true);
....@@ -6458,7 +7020,7 @@
64587020 ret = 0;
64597021
64607022 iter->tr = tr;
6461
- iter->trace_buffer = &tr->max_buffer;
7023
+ iter->array_buffer = &tr->max_buffer;
64627024 iter->cpu_file = tracing_get_cpu(inode);
64637025 m->private = iter;
64647026 file->private_data = m;
....@@ -6495,6 +7057,15 @@
64957057 goto out;
64967058 }
64977059
7060
+ local_irq_disable();
7061
+ arch_spin_lock(&tr->max_lock);
7062
+ if (tr->cond_snapshot)
7063
+ ret = -EBUSY;
7064
+ arch_spin_unlock(&tr->max_lock);
7065
+ local_irq_enable();
7066
+ if (ret)
7067
+ goto out;
7068
+
64987069 switch (val) {
64997070 case 0:
65007071 if (iter->cpu_file != RING_BUFFER_ALL_CPUS) {
....@@ -6514,7 +7085,7 @@
65147085 #endif
65157086 if (tr->allocated_snapshot)
65167087 ret = resize_buffer_duplicate_size(&tr->max_buffer,
6517
- &tr->trace_buffer, iter->cpu_file);
7088
+ &tr->array_buffer, iter->cpu_file);
65187089 else
65197090 ret = tracing_alloc_snapshot_instance(tr);
65207091 if (ret < 0)
....@@ -6522,7 +7093,7 @@
65227093 local_irq_disable();
65237094 /* Now, we're going to swap */
65247095 if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
6525
- update_max_tr(tr, current, smp_processor_id());
7096
+ update_max_tr(tr, current, smp_processor_id(), NULL);
65267097 else
65277098 update_max_tr_single(tr, current, iter->cpu_file);
65287099 local_irq_enable();
....@@ -6532,7 +7103,7 @@
65327103 if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
65337104 tracing_reset_online_cpus(&tr->max_buffer);
65347105 else
6535
- tracing_reset(&tr->max_buffer, iter->cpu_file);
7106
+ tracing_reset_cpu(&tr->max_buffer, iter->cpu_file);
65367107 }
65377108 break;
65387109 }
....@@ -6576,6 +7147,7 @@
65767147 struct ftrace_buffer_info *info;
65777148 int ret;
65787149
7150
+ /* The following checks for tracefs lockdown */
65797151 ret = tracing_buffers_open(inode, filp);
65807152 if (ret < 0)
65817153 return ret;
....@@ -6588,7 +7160,7 @@
65887160 }
65897161
65907162 info->iter.snapshot = true;
6591
- info->iter.trace_buffer = &info->iter.tr->max_buffer;
7163
+ info->iter.array_buffer = &info->iter.tr->max_buffer;
65927164
65937165 return ret;
65947166 }
....@@ -6697,19 +7269,263 @@
66977269
66987270 #endif /* CONFIG_TRACER_SNAPSHOT */
66997271
7272
+#define TRACING_LOG_ERRS_MAX 8
7273
+#define TRACING_LOG_LOC_MAX 128
7274
+
7275
+#define CMD_PREFIX " Command: "
7276
+
7277
+struct err_info {
7278
+ const char **errs; /* ptr to loc-specific array of err strings */
7279
+ u8 type; /* index into errs -> specific err string */
7280
+ u8 pos; /* MAX_FILTER_STR_VAL = 256 */
7281
+ u64 ts;
7282
+};
7283
+
7284
+struct tracing_log_err {
7285
+ struct list_head list;
7286
+ struct err_info info;
7287
+ char loc[TRACING_LOG_LOC_MAX]; /* err location */
7288
+ char cmd[MAX_FILTER_STR_VAL]; /* what caused err */
7289
+};
7290
+
7291
+static DEFINE_MUTEX(tracing_err_log_lock);
7292
+
7293
+static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr)
7294
+{
7295
+ struct tracing_log_err *err;
7296
+
7297
+ if (tr->n_err_log_entries < TRACING_LOG_ERRS_MAX) {
7298
+ err = kzalloc(sizeof(*err), GFP_KERNEL);
7299
+ if (!err)
7300
+ err = ERR_PTR(-ENOMEM);
7301
+ else
7302
+ tr->n_err_log_entries++;
7303
+
7304
+ return err;
7305
+ }
7306
+
7307
+ err = list_first_entry(&tr->err_log, struct tracing_log_err, list);
7308
+ list_del(&err->list);
7309
+
7310
+ return err;
7311
+}
7312
+
7313
+/**
7314
+ * err_pos - find the position of a string within a command for error careting
7315
+ * @cmd: The tracing command that caused the error
7316
+ * @str: The string to position the caret at within @cmd
7317
+ *
7318
+ * Finds the position of the first occurence of @str within @cmd. The
7319
+ * return value can be passed to tracing_log_err() for caret placement
7320
+ * within @cmd.
7321
+ *
7322
+ * Returns the index within @cmd of the first occurence of @str or 0
7323
+ * if @str was not found.
7324
+ */
7325
+unsigned int err_pos(char *cmd, const char *str)
7326
+{
7327
+ char *found;
7328
+
7329
+ if (WARN_ON(!strlen(cmd)))
7330
+ return 0;
7331
+
7332
+ found = strstr(cmd, str);
7333
+ if (found)
7334
+ return found - cmd;
7335
+
7336
+ return 0;
7337
+}
7338
+
7339
+/**
7340
+ * tracing_log_err - write an error to the tracing error log
7341
+ * @tr: The associated trace array for the error (NULL for top level array)
7342
+ * @loc: A string describing where the error occurred
7343
+ * @cmd: The tracing command that caused the error
7344
+ * @errs: The array of loc-specific static error strings
7345
+ * @type: The index into errs[], which produces the specific static err string
7346
+ * @pos: The position the caret should be placed in the cmd
7347
+ *
7348
+ * Writes an error into tracing/error_log of the form:
7349
+ *
7350
+ * <loc>: error: <text>
7351
+ * Command: <cmd>
7352
+ * ^
7353
+ *
7354
+ * tracing/error_log is a small log file containing the last
7355
+ * TRACING_LOG_ERRS_MAX errors (8). Memory for errors isn't allocated
7356
+ * unless there has been a tracing error, and the error log can be
7357
+ * cleared and have its memory freed by writing the empty string in
7358
+ * truncation mode to it i.e. echo > tracing/error_log.
7359
+ *
7360
+ * NOTE: the @errs array along with the @type param are used to
7361
+ * produce a static error string - this string is not copied and saved
7362
+ * when the error is logged - only a pointer to it is saved. See
7363
+ * existing callers for examples of how static strings are typically
7364
+ * defined for use with tracing_log_err().
7365
+ */
7366
+void tracing_log_err(struct trace_array *tr,
7367
+ const char *loc, const char *cmd,
7368
+ const char **errs, u8 type, u8 pos)
7369
+{
7370
+ struct tracing_log_err *err;
7371
+
7372
+ if (!tr)
7373
+ tr = &global_trace;
7374
+
7375
+ mutex_lock(&tracing_err_log_lock);
7376
+ err = get_tracing_log_err(tr);
7377
+ if (PTR_ERR(err) == -ENOMEM) {
7378
+ mutex_unlock(&tracing_err_log_lock);
7379
+ return;
7380
+ }
7381
+
7382
+ snprintf(err->loc, TRACING_LOG_LOC_MAX, "%s: error: ", loc);
7383
+ snprintf(err->cmd, MAX_FILTER_STR_VAL,"\n" CMD_PREFIX "%s\n", cmd);
7384
+
7385
+ err->info.errs = errs;
7386
+ err->info.type = type;
7387
+ err->info.pos = pos;
7388
+ err->info.ts = local_clock();
7389
+
7390
+ list_add_tail(&err->list, &tr->err_log);
7391
+ mutex_unlock(&tracing_err_log_lock);
7392
+}
7393
+
7394
+static void clear_tracing_err_log(struct trace_array *tr)
7395
+{
7396
+ struct tracing_log_err *err, *next;
7397
+
7398
+ mutex_lock(&tracing_err_log_lock);
7399
+ list_for_each_entry_safe(err, next, &tr->err_log, list) {
7400
+ list_del(&err->list);
7401
+ kfree(err);
7402
+ }
7403
+
7404
+ tr->n_err_log_entries = 0;
7405
+ mutex_unlock(&tracing_err_log_lock);
7406
+}
7407
+
7408
+static void *tracing_err_log_seq_start(struct seq_file *m, loff_t *pos)
7409
+{
7410
+ struct trace_array *tr = m->private;
7411
+
7412
+ mutex_lock(&tracing_err_log_lock);
7413
+
7414
+ return seq_list_start(&tr->err_log, *pos);
7415
+}
7416
+
7417
+static void *tracing_err_log_seq_next(struct seq_file *m, void *v, loff_t *pos)
7418
+{
7419
+ struct trace_array *tr = m->private;
7420
+
7421
+ return seq_list_next(v, &tr->err_log, pos);
7422
+}
7423
+
7424
+static void tracing_err_log_seq_stop(struct seq_file *m, void *v)
7425
+{
7426
+ mutex_unlock(&tracing_err_log_lock);
7427
+}
7428
+
7429
+static void tracing_err_log_show_pos(struct seq_file *m, u8 pos)
7430
+{
7431
+ u8 i;
7432
+
7433
+ for (i = 0; i < sizeof(CMD_PREFIX) - 1; i++)
7434
+ seq_putc(m, ' ');
7435
+ for (i = 0; i < pos; i++)
7436
+ seq_putc(m, ' ');
7437
+ seq_puts(m, "^\n");
7438
+}
7439
+
7440
+static int tracing_err_log_seq_show(struct seq_file *m, void *v)
7441
+{
7442
+ struct tracing_log_err *err = v;
7443
+
7444
+ if (err) {
7445
+ const char *err_text = err->info.errs[err->info.type];
7446
+ u64 sec = err->info.ts;
7447
+ u32 nsec;
7448
+
7449
+ nsec = do_div(sec, NSEC_PER_SEC);
7450
+ seq_printf(m, "[%5llu.%06u] %s%s", sec, nsec / 1000,
7451
+ err->loc, err_text);
7452
+ seq_printf(m, "%s", err->cmd);
7453
+ tracing_err_log_show_pos(m, err->info.pos);
7454
+ }
7455
+
7456
+ return 0;
7457
+}
7458
+
7459
+static const struct seq_operations tracing_err_log_seq_ops = {
7460
+ .start = tracing_err_log_seq_start,
7461
+ .next = tracing_err_log_seq_next,
7462
+ .stop = tracing_err_log_seq_stop,
7463
+ .show = tracing_err_log_seq_show
7464
+};
7465
+
7466
+static int tracing_err_log_open(struct inode *inode, struct file *file)
7467
+{
7468
+ struct trace_array *tr = inode->i_private;
7469
+ int ret = 0;
7470
+
7471
+ ret = tracing_check_open_get_tr(tr);
7472
+ if (ret)
7473
+ return ret;
7474
+
7475
+ /* If this file was opened for write, then erase contents */
7476
+ if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC))
7477
+ clear_tracing_err_log(tr);
7478
+
7479
+ if (file->f_mode & FMODE_READ) {
7480
+ ret = seq_open(file, &tracing_err_log_seq_ops);
7481
+ if (!ret) {
7482
+ struct seq_file *m = file->private_data;
7483
+ m->private = tr;
7484
+ } else {
7485
+ trace_array_put(tr);
7486
+ }
7487
+ }
7488
+ return ret;
7489
+}
7490
+
7491
+static ssize_t tracing_err_log_write(struct file *file,
7492
+ const char __user *buffer,
7493
+ size_t count, loff_t *ppos)
7494
+{
7495
+ return count;
7496
+}
7497
+
7498
+static int tracing_err_log_release(struct inode *inode, struct file *file)
7499
+{
7500
+ struct trace_array *tr = inode->i_private;
7501
+
7502
+ trace_array_put(tr);
7503
+
7504
+ if (file->f_mode & FMODE_READ)
7505
+ seq_release(inode, file);
7506
+
7507
+ return 0;
7508
+}
7509
+
7510
+static const struct file_operations tracing_err_log_fops = {
7511
+ .open = tracing_err_log_open,
7512
+ .write = tracing_err_log_write,
7513
+ .read = seq_read,
7514
+ .llseek = seq_lseek,
7515
+ .release = tracing_err_log_release,
7516
+};
7517
+
67007518 static int tracing_buffers_open(struct inode *inode, struct file *filp)
67017519 {
67027520 struct trace_array *tr = inode->i_private;
67037521 struct ftrace_buffer_info *info;
67047522 int ret;
67057523
6706
- if (tracing_disabled)
6707
- return -ENODEV;
7524
+ ret = tracing_check_open_get_tr(tr);
7525
+ if (ret)
7526
+ return ret;
67087527
6709
- if (trace_array_get(tr) < 0)
6710
- return -ENODEV;
6711
-
6712
- info = kzalloc(sizeof(*info), GFP_KERNEL);
7528
+ info = kvzalloc(sizeof(*info), GFP_KERNEL);
67137529 if (!info) {
67147530 trace_array_put(tr);
67157531 return -ENOMEM;
....@@ -6720,14 +7536,14 @@
67207536 info->iter.tr = tr;
67217537 info->iter.cpu_file = tracing_get_cpu(inode);
67227538 info->iter.trace = tr->current_trace;
6723
- info->iter.trace_buffer = &tr->trace_buffer;
7539
+ info->iter.array_buffer = &tr->array_buffer;
67247540 info->spare = NULL;
67257541 /* Force reading ring buffer for first read */
67267542 info->read = (unsigned int)-1;
67277543
67287544 filp->private_data = info;
67297545
6730
- tr->current_trace->ref++;
7546
+ tr->trace_ref++;
67317547
67327548 mutex_unlock(&trace_types_lock);
67337549
....@@ -6765,7 +7581,7 @@
67657581 #endif
67667582
67677583 if (!info->spare) {
6768
- info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer,
7584
+ info->spare = ring_buffer_alloc_read_page(iter->array_buffer->buffer,
67697585 iter->cpu_file);
67707586 if (IS_ERR(info->spare)) {
67717587 ret = PTR_ERR(info->spare);
....@@ -6783,7 +7599,7 @@
67837599
67847600 again:
67857601 trace_access_lock(iter->cpu_file);
6786
- ret = ring_buffer_read_page(iter->trace_buffer->buffer,
7602
+ ret = ring_buffer_read_page(iter->array_buffer->buffer,
67877603 &info->spare,
67887604 count,
67897605 iter->cpu_file, 0);
....@@ -6794,7 +7610,7 @@
67947610 if ((filp->f_flags & O_NONBLOCK))
67957611 return -EAGAIN;
67967612
6797
- ret = wait_on_pipe(iter, false);
7613
+ ret = wait_on_pipe(iter, 0);
67987614 if (ret)
67997615 return ret;
68007616
....@@ -6828,14 +7644,14 @@
68287644
68297645 mutex_lock(&trace_types_lock);
68307646
6831
- iter->tr->current_trace->ref--;
7647
+ iter->tr->trace_ref--;
68327648
68337649 __trace_array_put(iter->tr);
68347650
68357651 if (info->spare)
6836
- ring_buffer_free_read_page(iter->trace_buffer->buffer,
7652
+ ring_buffer_free_read_page(iter->array_buffer->buffer,
68377653 info->spare_cpu, info->spare);
6838
- kfree(info);
7654
+ kvfree(info);
68397655
68407656 mutex_unlock(&trace_types_lock);
68417657
....@@ -6843,7 +7659,7 @@
68437659 }
68447660
68457661 struct buffer_ref {
6846
- struct ring_buffer *buffer;
7662
+ struct trace_buffer *buffer;
68477663 void *page;
68487664 int cpu;
68497665 refcount_t refcount;
....@@ -6880,10 +7696,7 @@
68807696
68817697 /* Pipe buffer operations for a buffer. */
68827698 static const struct pipe_buf_operations buffer_pipe_buf_ops = {
6883
- .can_merge = 0,
6884
- .confirm = generic_pipe_buf_confirm,
68857699 .release = buffer_pipe_buf_release,
6886
- .steal = generic_pipe_buf_nosteal,
68877700 .get = buffer_pipe_buf_get,
68887701 };
68897702
....@@ -6939,7 +7752,7 @@
69397752
69407753 again:
69417754 trace_access_lock(iter->cpu_file);
6942
- entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file);
7755
+ entries = ring_buffer_entries_cpu(iter->array_buffer->buffer, iter->cpu_file);
69437756
69447757 for (i = 0; i < spd.nr_pages_max && len && entries; i++, len -= PAGE_SIZE) {
69457758 struct page *page;
....@@ -6952,7 +7765,7 @@
69527765 }
69537766
69547767 refcount_set(&ref->refcount, 1);
6955
- ref->buffer = iter->trace_buffer->buffer;
7768
+ ref->buffer = iter->array_buffer->buffer;
69567769 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file);
69577770 if (IS_ERR(ref->page)) {
69587771 ret = PTR_ERR(ref->page);
....@@ -6980,7 +7793,7 @@
69807793 spd.nr_pages++;
69817794 *ppos += PAGE_SIZE;
69827795
6983
- entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file);
7796
+ entries = ring_buffer_entries_cpu(iter->array_buffer->buffer, iter->cpu_file);
69847797 }
69857798
69867799 trace_access_unlock(iter->cpu_file);
....@@ -6995,7 +7808,7 @@
69957808 if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
69967809 goto out;
69977810
6998
- ret = wait_on_pipe(iter, true);
7811
+ ret = wait_on_pipe(iter, iter->tr->buffer_percent);
69997812 if (ret)
70007813 goto out;
70017814
....@@ -7024,7 +7837,7 @@
70247837 {
70257838 struct inode *inode = file_inode(filp);
70267839 struct trace_array *tr = inode->i_private;
7027
- struct trace_buffer *trace_buf = &tr->trace_buffer;
7840
+ struct array_buffer *trace_buf = &tr->array_buffer;
70287841 int cpu = tracing_get_cpu(inode);
70297842 struct trace_seq *s;
70307843 unsigned long cnt;
....@@ -7095,14 +7908,23 @@
70957908 tracing_read_dyn_info(struct file *filp, char __user *ubuf,
70967909 size_t cnt, loff_t *ppos)
70977910 {
7098
- unsigned long *p = filp->private_data;
7099
- char buf[64]; /* Not too big for a shallow stack */
7911
+ ssize_t ret;
7912
+ char *buf;
71007913 int r;
71017914
7102
- r = scnprintf(buf, 63, "%ld", *p);
7103
- buf[r++] = '\n';
7915
+ /* 256 should be plenty to hold the amount needed */
7916
+ buf = kmalloc(256, GFP_KERNEL);
7917
+ if (!buf)
7918
+ return -ENOMEM;
71047919
7105
- return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
7920
+ r = scnprintf(buf, 256, "%ld pages:%ld groups: %ld\n",
7921
+ ftrace_update_tot_cnt,
7922
+ ftrace_number_of_pages,
7923
+ ftrace_number_of_groups);
7924
+
7925
+ ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
7926
+ kfree(buf);
7927
+ return ret;
71067928 }
71077929
71087930 static const struct file_operations tracing_dyn_info_fops = {
....@@ -7296,7 +8118,7 @@
72968118
72978119 tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer);
72988120
7299
- WARN_ONCE(!tr->percpu_dir,
8121
+ MEM_FAIL(!tr->percpu_dir,
73008122 "Could not create tracefs directory 'per_cpu/%d'\n", cpu);
73018123
73028124 return tr->percpu_dir;
....@@ -7617,7 +8439,7 @@
76178439 for (cnt = 0; opts[cnt].name; cnt++) {
76188440 create_trace_option_file(tr, &topts[cnt], flags,
76198441 &opts[cnt]);
7620
- WARN_ONCE(topts[cnt].entry == NULL,
8442
+ MEM_FAIL(topts[cnt].entry == NULL,
76218443 "Failed to create trace option: %s",
76228444 opts[cnt].name);
76238445 }
....@@ -7674,7 +8496,7 @@
76748496 size_t cnt, loff_t *ppos)
76758497 {
76768498 struct trace_array *tr = filp->private_data;
7677
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
8499
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
76788500 unsigned long val;
76798501 int ret;
76808502
....@@ -7711,13 +8533,60 @@
77118533 .llseek = default_llseek,
77128534 };
77138535
7714
-struct dentry *trace_instance_dir;
8536
+static ssize_t
8537
+buffer_percent_read(struct file *filp, char __user *ubuf,
8538
+ size_t cnt, loff_t *ppos)
8539
+{
8540
+ struct trace_array *tr = filp->private_data;
8541
+ char buf[64];
8542
+ int r;
8543
+
8544
+ r = tr->buffer_percent;
8545
+ r = sprintf(buf, "%d\n", r);
8546
+
8547
+ return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
8548
+}
8549
+
8550
+static ssize_t
8551
+buffer_percent_write(struct file *filp, const char __user *ubuf,
8552
+ size_t cnt, loff_t *ppos)
8553
+{
8554
+ struct trace_array *tr = filp->private_data;
8555
+ unsigned long val;
8556
+ int ret;
8557
+
8558
+ ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
8559
+ if (ret)
8560
+ return ret;
8561
+
8562
+ if (val > 100)
8563
+ return -EINVAL;
8564
+
8565
+ if (!val)
8566
+ val = 1;
8567
+
8568
+ tr->buffer_percent = val;
8569
+
8570
+ (*ppos)++;
8571
+
8572
+ return cnt;
8573
+}
8574
+
8575
+static const struct file_operations buffer_percent_fops = {
8576
+ .open = tracing_open_generic_tr,
8577
+ .read = buffer_percent_read,
8578
+ .write = buffer_percent_write,
8579
+ .release = tracing_release_generic_tr,
8580
+ .llseek = default_llseek,
8581
+};
8582
+
8583
+static struct dentry *trace_instance_dir;
77158584
77168585 static void
77178586 init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);
77188587
77198588 static int
7720
-allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size)
8589
+allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size)
77218590 {
77228591 enum ring_buffer_flags rb_flags;
77238592
....@@ -7737,8 +8606,8 @@
77378606 }
77388607
77398608 /* Allocate the first page for all buffers */
7740
- set_buffer_entries(&tr->trace_buffer,
7741
- ring_buffer_size(tr->trace_buffer.buffer, 0));
8609
+ set_buffer_entries(&tr->array_buffer,
8610
+ ring_buffer_size(tr->array_buffer.buffer, 0));
77428611
77438612 return 0;
77448613 }
....@@ -7747,18 +8616,18 @@
77478616 {
77488617 int ret;
77498618
7750
- ret = allocate_trace_buffer(tr, &tr->trace_buffer, size);
8619
+ ret = allocate_trace_buffer(tr, &tr->array_buffer, size);
77518620 if (ret)
77528621 return ret;
77538622
77548623 #ifdef CONFIG_TRACER_MAX_TRACE
77558624 ret = allocate_trace_buffer(tr, &tr->max_buffer,
77568625 allocate_snapshot ? size : 1);
7757
- if (WARN_ON(ret)) {
7758
- ring_buffer_free(tr->trace_buffer.buffer);
7759
- tr->trace_buffer.buffer = NULL;
7760
- free_percpu(tr->trace_buffer.data);
7761
- tr->trace_buffer.data = NULL;
8626
+ if (MEM_FAIL(ret, "Failed to allocate trace buffer\n")) {
8627
+ ring_buffer_free(tr->array_buffer.buffer);
8628
+ tr->array_buffer.buffer = NULL;
8629
+ free_percpu(tr->array_buffer.data);
8630
+ tr->array_buffer.data = NULL;
77628631 return -ENOMEM;
77638632 }
77648633 tr->allocated_snapshot = allocate_snapshot;
....@@ -7770,22 +8639,10 @@
77708639 allocate_snapshot = false;
77718640 #endif
77728641
7773
- /*
7774
- * Because of some magic with the way alloc_percpu() works on
7775
- * x86_64, we need to synchronize the pgd of all the tables,
7776
- * otherwise the trace events that happen in x86_64 page fault
7777
- * handlers can't cope with accessing the chance that a
7778
- * alloc_percpu()'d memory might be touched in the page fault trace
7779
- * event. Oh, and we need to audit all other alloc_percpu() and vmalloc()
7780
- * calls in tracing, because something might get triggered within a
7781
- * page fault trace event!
7782
- */
7783
- vmalloc_sync_mappings();
7784
-
77858642 return 0;
77868643 }
77878644
7788
-static void free_trace_buffer(struct trace_buffer *buf)
8645
+static void free_trace_buffer(struct array_buffer *buf)
77898646 {
77908647 if (buf->buffer) {
77918648 ring_buffer_free(buf->buffer);
....@@ -7800,7 +8657,7 @@
78008657 if (!tr)
78018658 return;
78028659
7803
- free_trace_buffer(&tr->trace_buffer);
8660
+ free_trace_buffer(&tr->array_buffer);
78048661
78058662 #ifdef CONFIG_TRACER_MAX_TRACE
78068663 free_trace_buffer(&tr->max_buffer);
....@@ -7827,28 +8684,68 @@
78278684 static void update_tracer_options(struct trace_array *tr)
78288685 {
78298686 mutex_lock(&trace_types_lock);
8687
+ tracer_options_updated = true;
78308688 __update_tracer_options(tr);
78318689 mutex_unlock(&trace_types_lock);
78328690 }
78338691
7834
-static int instance_mkdir(const char *name)
8692
+/* Must have trace_types_lock held */
8693
+struct trace_array *trace_array_find(const char *instance)
8694
+{
8695
+ struct trace_array *tr, *found = NULL;
8696
+
8697
+ list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8698
+ if (tr->name && strcmp(tr->name, instance) == 0) {
8699
+ found = tr;
8700
+ break;
8701
+ }
8702
+ }
8703
+
8704
+ return found;
8705
+}
8706
+
8707
+struct trace_array *trace_array_find_get(const char *instance)
8708
+{
8709
+ struct trace_array *tr;
8710
+
8711
+ mutex_lock(&trace_types_lock);
8712
+ tr = trace_array_find(instance);
8713
+ if (tr)
8714
+ tr->ref++;
8715
+ mutex_unlock(&trace_types_lock);
8716
+
8717
+ return tr;
8718
+}
8719
+
8720
+static int trace_array_create_dir(struct trace_array *tr)
8721
+{
8722
+ int ret;
8723
+
8724
+ tr->dir = tracefs_create_dir(tr->name, trace_instance_dir);
8725
+ if (!tr->dir)
8726
+ return -EINVAL;
8727
+
8728
+ ret = event_trace_add_tracer(tr->dir, tr);
8729
+ if (ret) {
8730
+ tracefs_remove(tr->dir);
8731
+ return ret;
8732
+ }
8733
+
8734
+ init_tracer_tracefs(tr, tr->dir);
8735
+ __update_tracer_options(tr);
8736
+
8737
+ return ret;
8738
+}
8739
+
8740
+static struct trace_array *trace_array_create(const char *name)
78358741 {
78368742 struct trace_array *tr;
78378743 int ret;
78388744
7839
- mutex_lock(&event_mutex);
7840
- mutex_lock(&trace_types_lock);
7841
-
7842
- ret = -EEXIST;
7843
- list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7844
- if (tr->name && strcmp(tr->name, name) == 0)
7845
- goto out_unlock;
7846
- }
7847
-
78488745 ret = -ENOMEM;
78498746 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
78508747 if (!tr)
7851
- goto out_unlock;
8748
+ return ERR_PTR(ret);
78528749
78538750 tr->name = kstrdup(name, GFP_KERNEL);
78548751 if (!tr->name)
....@@ -7870,70 +8767,112 @@
78708767 INIT_LIST_HEAD(&tr->systems);
78718768 INIT_LIST_HEAD(&tr->events);
78728769 INIT_LIST_HEAD(&tr->hist_vars);
8770
+ INIT_LIST_HEAD(&tr->err_log);
78738771
78748772 if (allocate_trace_buffers(tr, trace_buf_size) < 0)
78758773 goto out_free_tr;
78768774
7877
- tr->dir = tracefs_create_dir(name, trace_instance_dir);
7878
- if (!tr->dir)
8775
+ if (ftrace_allocate_ftrace_ops(tr) < 0)
78798776 goto out_free_tr;
7880
-
7881
- ret = event_trace_add_tracer(tr->dir, tr);
7882
- if (ret) {
7883
- tracefs_remove_recursive(tr->dir);
7884
- goto out_free_tr;
7885
- }
78868777
78878778 ftrace_init_trace_array(tr);
78888779
7889
- init_tracer_tracefs(tr, tr->dir);
78908780 init_trace_flags_index(tr);
7891
- __update_tracer_options(tr);
8781
+
8782
+ if (trace_instance_dir) {
8783
+ ret = trace_array_create_dir(tr);
8784
+ if (ret)
8785
+ goto out_free_tr;
8786
+ } else
8787
+ __trace_early_add_events(tr);
78928788
78938789 list_add(&tr->list, &ftrace_trace_arrays);
78948790
7895
- mutex_unlock(&trace_types_lock);
7896
- mutex_unlock(&event_mutex);
8791
+ tr->ref++;
78978792
7898
- return 0;
8793
+ return tr;
78998794
79008795 out_free_tr:
8796
+ ftrace_free_ftrace_ops(tr);
79018797 free_trace_buffers(tr);
79028798 free_cpumask_var(tr->tracing_cpumask);
79038799 kfree(tr->name);
79048800 kfree(tr);
79058801
7906
- out_unlock:
7907
- mutex_unlock(&trace_types_lock);
7908
- mutex_unlock(&event_mutex);
7909
-
7910
- return ret;
7911
-
8802
+ return ERR_PTR(ret);
79128803 }
79138804
7914
-static int instance_rmdir(const char *name)
8805
+static int instance_mkdir(const char *name)
79158806 {
79168807 struct trace_array *tr;
7917
- int found = 0;
79188808 int ret;
7919
- int i;
79208809
79218810 mutex_lock(&event_mutex);
79228811 mutex_lock(&trace_types_lock);
79238812
7924
- ret = -ENODEV;
7925
- list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7926
- if (tr->name && strcmp(tr->name, name) == 0) {
7927
- found = 1;
7928
- break;
7929
- }
7930
- }
7931
- if (!found)
8813
+ ret = -EEXIST;
8814
+ if (trace_array_find(name))
79328815 goto out_unlock;
79338816
7934
- ret = -EBUSY;
7935
- if (tr->ref || (tr->current_trace && tr->current_trace->ref))
7936
- goto out_unlock;
8817
+ tr = trace_array_create(name);
8818
+
8819
+ ret = PTR_ERR_OR_ZERO(tr);
8820
+
8821
+out_unlock:
8822
+ mutex_unlock(&trace_types_lock);
8823
+ mutex_unlock(&event_mutex);
8824
+ return ret;
8825
+}
8826
+
8827
+/**
8828
+ * trace_array_get_by_name - Create/Lookup a trace array, given its name.
8829
+ * @name: The name of the trace array to be looked up/created.
8830
+ *
8831
+ * Returns pointer to trace array with given name.
8832
+ * NULL, if it cannot be created.
8833
+ *
8834
+ * NOTE: This function increments the reference counter associated with the
8835
+ * trace array returned. This makes sure it cannot be freed while in use.
8836
+ * Use trace_array_put() once the trace array is no longer needed.
8837
+ * If the trace_array is to be freed, trace_array_destroy() needs to
8838
+ * be called after the trace_array_put(), or simply let user space delete
8839
+ * it from the tracefs instances directory. But until the
8840
+ * trace_array_put() is called, user space can not delete it.
8841
+ *
8842
+ */
8843
+struct trace_array *trace_array_get_by_name(const char *name)
8844
+{
8845
+ struct trace_array *tr;
8846
+
8847
+ mutex_lock(&event_mutex);
8848
+ mutex_lock(&trace_types_lock);
8849
+
8850
+ list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8851
+ if (tr->name && strcmp(tr->name, name) == 0)
8852
+ goto out_unlock;
8853
+ }
8854
+
8855
+ tr = trace_array_create(name);
8856
+
8857
+ if (IS_ERR(tr))
8858
+ tr = NULL;
8859
+out_unlock:
8860
+ if (tr)
8861
+ tr->ref++;
8862
+
8863
+ mutex_unlock(&trace_types_lock);
8864
+ mutex_unlock(&event_mutex);
8865
+ return tr;
8866
+}
8867
+EXPORT_SYMBOL_GPL(trace_array_get_by_name);
8868
+
8869
+static int __remove_instance(struct trace_array *tr)
8870
+{
8871
+ int i;
8872
+
8873
+ /* Reference counter for a newly created trace array = 1. */
8874
+ if (tr->ref > 1 || (tr->current_trace && tr->trace_ref))
8875
+ return -EBUSY;
79378876
79388877 list_del(&tr->list);
79398878
....@@ -7948,7 +8887,7 @@
79488887 event_trace_del_tracer(tr);
79498888 ftrace_clear_pids(tr);
79508889 ftrace_destroy_function_files(tr);
7951
- tracefs_remove_recursive(tr->dir);
8890
+ tracefs_remove(tr->dir);
79528891 free_trace_buffers(tr);
79538892
79548893 for (i = 0; i < tr->nr_topts; i++) {
....@@ -7960,9 +8899,50 @@
79608899 kfree(tr->name);
79618900 kfree(tr);
79628901
7963
- ret = 0;
8902
+ return 0;
8903
+}
79648904
7965
- out_unlock:
8905
+int trace_array_destroy(struct trace_array *this_tr)
8906
+{
8907
+ struct trace_array *tr;
8908
+ int ret;
8909
+
8910
+ if (!this_tr)
8911
+ return -EINVAL;
8912
+
8913
+ mutex_lock(&event_mutex);
8914
+ mutex_lock(&trace_types_lock);
8915
+
8916
+ ret = -ENODEV;
8917
+
8918
+ /* Making sure trace array exists before destroying it. */
8919
+ list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8920
+ if (tr == this_tr) {
8921
+ ret = __remove_instance(tr);
8922
+ break;
8923
+ }
8924
+ }
8925
+
8926
+ mutex_unlock(&trace_types_lock);
8927
+ mutex_unlock(&event_mutex);
8928
+
8929
+ return ret;
8930
+}
8931
+EXPORT_SYMBOL_GPL(trace_array_destroy);
8932
+
8933
+static int instance_rmdir(const char *name)
8934
+{
8935
+ struct trace_array *tr;
8936
+ int ret;
8937
+
8938
+ mutex_lock(&event_mutex);
8939
+ mutex_lock(&trace_types_lock);
8940
+
8941
+ ret = -ENODEV;
8942
+ tr = trace_array_find(name);
8943
+ if (tr)
8944
+ ret = __remove_instance(tr);
8945
+
79668946 mutex_unlock(&trace_types_lock);
79678947 mutex_unlock(&event_mutex);
79688948
....@@ -7971,11 +8951,27 @@
79718951
79728952 static __init void create_trace_instances(struct dentry *d_tracer)
79738953 {
8954
+ struct trace_array *tr;
8955
+
79748956 trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer,
79758957 instance_mkdir,
79768958 instance_rmdir);
7977
- if (WARN_ON(!trace_instance_dir))
8959
+ if (MEM_FAIL(!trace_instance_dir, "Failed to create instances directory\n"))
79788960 return;
8961
+
8962
+ mutex_lock(&event_mutex);
8963
+ mutex_lock(&trace_types_lock);
8964
+
8965
+ list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8966
+ if (!tr->name)
8967
+ continue;
8968
+ if (MEM_FAIL(trace_array_create_dir(tr) < 0,
8969
+ "Failed to create instance directory\n"))
8970
+ break;
8971
+ }
8972
+
8973
+ mutex_unlock(&trace_types_lock);
8974
+ mutex_unlock(&event_mutex);
79798975 }
79808976
79818977 static void
....@@ -8032,20 +9028,27 @@
80329028 trace_create_file("timestamp_mode", 0444, d_tracer, tr,
80339029 &trace_time_stamp_mode_fops);
80349030
9031
+ tr->buffer_percent = 50;
9032
+
9033
+ trace_create_file("buffer_percent", 0444, d_tracer,
9034
+ tr, &buffer_percent_fops);
9035
+
80359036 create_trace_options_dir(tr);
80369037
80379038 #if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
8038
- trace_create_file("tracing_max_latency", 0644, d_tracer,
8039
- &tr->max_latency, &tracing_max_lat_fops);
9039
+ trace_create_maxlat_file(tr, d_tracer);
80409040 #endif
80419041
80429042 if (ftrace_create_function_files(tr, d_tracer))
8043
- WARN(1, "Could not allocate function filter files");
9043
+ MEM_FAIL(1, "Could not allocate function filter files");
80449044
80459045 #ifdef CONFIG_TRACER_SNAPSHOT
80469046 trace_create_file("snapshot", 0644, d_tracer,
80479047 tr, &snapshot_fops);
80489048 #endif
9049
+
9050
+ trace_create_file("error_log", 0644, d_tracer,
9051
+ tr, &tracing_err_log_fops);
80499052
80509053 for_each_tracing_cpu(cpu)
80519054 tracing_init_tracefs_percpu(tr, cpu);
....@@ -8053,6 +9056,7 @@
80539056 ftrace_init_tracefs(tr, d_tracer);
80549057 }
80559058
9059
+#ifndef CONFIG_TRACEFS_DISABLE_AUTOMOUNT
80569060 static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)
80579061 {
80589062 struct vfsmount *mnt;
....@@ -8074,6 +9078,7 @@
80749078
80759079 return mnt;
80769080 }
9081
+#endif
80779082
80789083 /**
80799084 * tracing_init_dentry - initialize top level trace array
....@@ -8082,19 +9087,23 @@
80829087 * directory. It is called via fs_initcall() by any of the boot up code
80839088 * and expects to return the dentry of the top level tracing directory.
80849089 */
8085
-struct dentry *tracing_init_dentry(void)
9090
+int tracing_init_dentry(void)
80869091 {
80879092 struct trace_array *tr = &global_trace;
80889093
9094
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
9095
+ pr_warn("Tracing disabled due to lockdown\n");
9096
+ return -EPERM;
9097
+ }
9098
+
80899099 /* The top level trace array uses NULL as parent */
80909100 if (tr->dir)
8091
- return NULL;
9101
+ return 0;
80929102
8093
- if (WARN_ON(!tracefs_initialized()) ||
8094
- (IS_ENABLED(CONFIG_DEBUG_FS) &&
8095
- WARN_ON(!debugfs_initialized())))
8096
- return ERR_PTR(-ENODEV);
9103
+ if (WARN_ON(!tracefs_initialized()))
9104
+ return -ENODEV;
80979105
9106
+#ifndef CONFIG_TRACEFS_DISABLE_AUTOMOUNT
80989107 /*
80999108 * As there may still be users that expect the tracing
81009109 * files to exist in debugfs/tracing, we must automount
....@@ -8103,12 +9112,11 @@
81039112 */
81049113 tr->dir = debugfs_create_automount("tracing", NULL,
81059114 trace_automount, NULL);
8106
- if (!tr->dir) {
8107
- pr_warn_once("Could not create debugfs directory 'tracing'\n");
8108
- return ERR_PTR(-ENOMEM);
8109
- }
9115
+#else
9116
+ tr->dir = ERR_PTR(-ENODEV);
9117
+#endif
81109118
8111
- return NULL;
9119
+ return 0;
81129120 }
81139121
81149122 extern struct trace_eval_map *__start_ftrace_eval_maps[];
....@@ -8184,7 +9192,7 @@
81849192 break;
81859193 }
81869194
8187
- return 0;
9195
+ return NOTIFY_OK;
81889196 }
81899197
81909198 static struct notifier_block trace_module_nb = {
....@@ -8195,48 +9203,48 @@
81959203
81969204 static __init int tracer_init_tracefs(void)
81979205 {
8198
- struct dentry *d_tracer;
9206
+ int ret;
81999207
82009208 trace_access_lock_init();
82019209
8202
- d_tracer = tracing_init_dentry();
8203
- if (IS_ERR(d_tracer))
9210
+ ret = tracing_init_dentry();
9211
+ if (ret)
82049212 return 0;
82059213
82069214 event_trace_init();
82079215
8208
- init_tracer_tracefs(&global_trace, d_tracer);
8209
- ftrace_init_tracefs_toplevel(&global_trace, d_tracer);
9216
+ init_tracer_tracefs(&global_trace, NULL);
9217
+ ftrace_init_tracefs_toplevel(&global_trace, NULL);
82109218
8211
- trace_create_file("tracing_thresh", 0644, d_tracer,
9219
+ trace_create_file("tracing_thresh", 0644, NULL,
82129220 &global_trace, &tracing_thresh_fops);
82139221
8214
- trace_create_file("README", 0444, d_tracer,
9222
+ trace_create_file("README", 0444, NULL,
82159223 NULL, &tracing_readme_fops);
82169224
8217
- trace_create_file("saved_cmdlines", 0444, d_tracer,
9225
+ trace_create_file("saved_cmdlines", 0444, NULL,
82189226 NULL, &tracing_saved_cmdlines_fops);
82199227
8220
- trace_create_file("saved_cmdlines_size", 0644, d_tracer,
9228
+ trace_create_file("saved_cmdlines_size", 0644, NULL,
82219229 NULL, &tracing_saved_cmdlines_size_fops);
82229230
8223
- trace_create_file("saved_tgids", 0444, d_tracer,
9231
+ trace_create_file("saved_tgids", 0444, NULL,
82249232 NULL, &tracing_saved_tgids_fops);
82259233
82269234 trace_eval_init();
82279235
8228
- trace_create_eval_file(d_tracer);
9236
+ trace_create_eval_file(NULL);
82299237
82309238 #ifdef CONFIG_MODULES
82319239 register_module_notifier(&trace_module_nb);
82329240 #endif
82339241
82349242 #ifdef CONFIG_DYNAMIC_FTRACE
8235
- trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
8236
- &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
9243
+ trace_create_file("dyn_ftrace_total_info", 0444, NULL,
9244
+ NULL, &tracing_dyn_info_fops);
82379245 #endif
82389246
8239
- create_trace_instances(d_tracer);
9247
+ create_trace_instances(NULL);
82409248
82419249 update_tracer_options(&global_trace);
82429250
....@@ -8246,8 +9254,17 @@
82469254 static int trace_panic_handler(struct notifier_block *this,
82479255 unsigned long event, void *unused)
82489256 {
9257
+ bool ftrace_check = false;
9258
+
9259
+ trace_android_vh_ftrace_oops_enter(&ftrace_check);
9260
+
9261
+ if (ftrace_check)
9262
+ return NOTIFY_OK;
9263
+
82499264 if (ftrace_dump_on_oops)
82509265 ftrace_dump(ftrace_dump_on_oops);
9266
+
9267
+ trace_android_vh_ftrace_oops_exit(&ftrace_check);
82519268 return NOTIFY_OK;
82529269 }
82539270
....@@ -8261,6 +9278,13 @@
82619278 unsigned long val,
82629279 void *data)
82639280 {
9281
+ bool ftrace_check = false;
9282
+
9283
+ trace_android_vh_ftrace_oops_enter(&ftrace_check);
9284
+
9285
+ if (ftrace_check)
9286
+ return NOTIFY_OK;
9287
+
82649288 switch (val) {
82659289 case DIE_OOPS:
82669290 if (ftrace_dump_on_oops)
....@@ -8269,6 +9293,8 @@
82699293 default:
82709294 break;
82719295 }
9296
+
9297
+ trace_android_vh_ftrace_oops_exit(&ftrace_check);
82729298 return NOTIFY_OK;
82739299 }
82749300
....@@ -8293,6 +9319,8 @@
82939319 void
82949320 trace_printk_seq(struct trace_seq *s)
82959321 {
9322
+ bool dump_printk = true;
9323
+
82969324 /* Probably should print a warning here. */
82979325 if (s->seq.len >= TRACE_MAX_PRINT)
82989326 s->seq.len = TRACE_MAX_PRINT;
....@@ -8308,7 +9336,9 @@
83089336 /* should be zero ended, but we are paranoid. */
83099337 s->buffer[s->seq.len] = 0;
83109338
8311
- printk(KERN_TRACE "%s", s->buffer);
9339
+ trace_android_vh_ftrace_dump_buffer(s, &dump_printk);
9340
+ if (dump_printk)
9341
+ printk(KERN_TRACE "%s", s->buffer);
83129342
83139343 trace_seq_init(s);
83149344 }
....@@ -8318,13 +9348,13 @@
83189348 iter->tr = &global_trace;
83199349 iter->trace = iter->tr->current_trace;
83209350 iter->cpu_file = RING_BUFFER_ALL_CPUS;
8321
- iter->trace_buffer = &global_trace.trace_buffer;
9351
+ iter->array_buffer = &global_trace.array_buffer;
83229352
83239353 if (iter->trace && iter->trace->open)
83249354 iter->trace->open(iter);
83259355
83269356 /* Annotate start of buffers if we had overruns */
8327
- if (ring_buffer_overruns(iter->trace_buffer->buffer))
9357
+ if (ring_buffer_overruns(iter->array_buffer->buffer))
83289358 iter->iter_flags |= TRACE_FILE_ANNOTATE;
83299359
83309360 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
....@@ -8341,6 +9371,8 @@
83419371 unsigned int old_userobj;
83429372 unsigned long flags;
83439373 int cnt = 0, cpu;
9374
+ bool ftrace_check = false;
9375
+ unsigned long size;
83449376
83459377 /* Only allow one dump user at a time. */
83469378 if (atomic_inc_return(&dump_running) != 1) {
....@@ -8359,19 +9391,26 @@
83599391 tracing_off();
83609392
83619393 local_irq_save(flags);
8362
- printk_nmi_direct_enter();
83639394
83649395 /* Simulate the iterator */
83659396 trace_init_global_iter(&iter);
9397
+ /* Can not use kmalloc for iter.temp */
9398
+ iter.temp = static_temp_buf;
9399
+ iter.temp_size = STATIC_TEMP_BUF_SIZE;
83669400
83679401 for_each_tracing_cpu(cpu) {
8368
- atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
9402
+ atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled);
9403
+ size = ring_buffer_size(iter.array_buffer->buffer, cpu);
9404
+ trace_android_vh_ftrace_size_check(size, &ftrace_check);
83699405 }
83709406
83719407 old_userobj = tr->trace_flags & TRACE_ITER_SYM_USEROBJ;
83729408
83739409 /* don't look at user memory in panic mode */
83749410 tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
9411
+
9412
+ if (ftrace_check)
9413
+ goto out_enable;
83759414
83769415 switch (oops_dump_mode) {
83779416 case DUMP_ALL:
....@@ -8396,13 +9435,14 @@
83969435 }
83979436
83989437 /*
8399
- * We need to stop all tracing on all CPUS to read the
9438
+ * We need to stop all tracing on all CPUS to read
84009439 * the next buffer. This is a bit expensive, but is
84019440 * not done often. We fill all what we can read,
84029441 * and then release the locks again.
84039442 */
84049443
84059444 while (!trace_empty(&iter)) {
9445
+ ftrace_check = true;
84069446
84079447 if (!cnt)
84089448 printk(KERN_TRACE "---------------------------------\n");
....@@ -8410,7 +9450,9 @@
84109450 cnt++;
84119451
84129452 trace_iterator_reset(&iter);
8413
- iter.iter_flags |= TRACE_FILE_LAT_FMT;
9453
+ trace_android_vh_ftrace_format_check(&ftrace_check);
9454
+ if (ftrace_check)
9455
+ iter.iter_flags |= TRACE_FILE_LAT_FMT;
84149456
84159457 if (trace_find_next_entry_inc(&iter) != NULL) {
84169458 int ret;
....@@ -8433,10 +9475,9 @@
84339475 tr->trace_flags |= old_userobj;
84349476
84359477 for_each_tracing_cpu(cpu) {
8436
- atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
9478
+ atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled);
84379479 }
84389480 atomic_dec(&dump_running);
8439
- printk_nmi_direct_exit();
84409481 local_irq_restore(flags);
84419482 }
84429483 EXPORT_SYMBOL_GPL(ftrace_dump);
....@@ -8532,8 +9573,14 @@
85329573 int ring_buf_size;
85339574 int ret = -ENOMEM;
85349575
9576
+
9577
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
9578
+ pr_warn("Tracing disabled due to lockdown\n");
9579
+ return -EPERM;
9580
+ }
9581
+
85359582 /*
8536
- * Make sure we don't accidently add more trace options
9583
+ * Make sure we don't accidentally add more trace options
85379584 * than we have bits for.
85389585 */
85399586 BUILD_BUG_ON(TRACE_ITER_LAST_BIT > TRACE_FLAGS_MAX_SIZE);
....@@ -8562,7 +9609,7 @@
85629609
85639610 /*
85649611 * The prepare callbacks allocates some memory for the ring buffer. We
8565
- * don't free the buffer if the if the CPU goes down. If we were to free
9612
+ * don't free the buffer if the CPU goes down. If we were to free
85669613 * the buffer, then the user would lose any trace that was in the
85679614 * buffer. The memory will be removed once the "instance" is removed.
85689615 */
....@@ -8582,8 +9629,7 @@
85829629
85839630 /* TODO: make the number of buffers hot pluggable with CPUS */
85849631 if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) {
8585
- printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
8586
- WARN_ON(1);
9632
+ MEM_FAIL(1, "tracer: failed to allocate ring buffer!\n");
85879633 goto out_free_savedcmd;
85889634 }
85899635
....@@ -8628,6 +9674,7 @@
86289674 INIT_LIST_HEAD(&global_trace.systems);
86299675 INIT_LIST_HEAD(&global_trace.events);
86309676 INIT_LIST_HEAD(&global_trace.hist_vars);
9677
+ INIT_LIST_HEAD(&global_trace.err_log);
86319678 list_add(&global_trace.list, &ftrace_trace_arrays);
86329679
86339680 apply_trace_boot_options();
....@@ -8655,7 +9702,8 @@
86559702 if (tracepoint_printk) {
86569703 tracepoint_print_iter =
86579704 kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
8658
- if (WARN_ON(!tracepoint_print_iter))
9705
+ if (MEM_FAIL(!tracepoint_print_iter,
9706
+ "Failed to allocate trace iterator\n"))
86599707 tracepoint_printk = 0;
86609708 else
86619709 static_key_enable(&tracepoint_printk_key.key);
....@@ -8695,6 +9743,11 @@
86959743 {
86969744 /* sched_clock_stable() is determined in late_initcall */
86979745 if (!trace_boot_clock && !sched_clock_stable()) {
9746
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
9747
+ pr_warn("Can not set tracing clock due to lockdown\n");
9748
+ return -EPERM;
9749
+ }
9750
+
86989751 printk(KERN_WARNING
86999752 "Unstable clock detected, switching default tracing clock to \"global\"\n"
87009753 "If you want to keep using the local clock, then add:\n"