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,35 +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->pid = (tsk) ? tsk->pid : 0;
2155
- entry->flags =
2156
-#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
2157
- (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
2613
+#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT)
2614
+ return current->migration_disabled;
21582615 #else
2159
- TRACE_FLAG_IRQS_NOSUPPORT |
2616
+ return 0;
21602617 #endif
2161
- ((pc & NMI_MASK ) ? TRACE_FLAG_NMI : 0) |
2162
- ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
2163
- ((pc & SOFTIRQ_OFFSET) ? TRACE_FLAG_SOFTIRQ : 0) |
2164
- (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
2165
- (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
21662618 }
2167
-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
+}
21682649
21692650 struct ring_buffer_event *
2170
-trace_buffer_lock_reserve(struct ring_buffer *buffer,
2651
+trace_buffer_lock_reserve(struct trace_buffer *buffer,
21712652 int type,
21722653 unsigned long len,
2173
- unsigned long flags, int pc)
2654
+ unsigned int trace_ctx)
21742655 {
2175
- return __trace_buffer_lock_reserve(buffer, type, len, flags, pc);
2656
+ return __trace_buffer_lock_reserve(buffer, type, len, trace_ctx);
21762657 }
21772658
21782659 DEFINE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
....@@ -2217,7 +2698,7 @@
22172698
22182699 preempt_disable();
22192700 if (cpu == smp_processor_id() &&
2220
- this_cpu_read(trace_buffered_event) !=
2701
+ __this_cpu_read(trace_buffered_event) !=
22212702 per_cpu(trace_buffered_event, cpu))
22222703 WARN_ON_ONCE(1);
22232704 preempt_enable();
....@@ -2267,7 +2748,7 @@
22672748 preempt_enable();
22682749
22692750 /* Wait for all current users to finish */
2270
- synchronize_sched();
2751
+ synchronize_rcu();
22712752
22722753 for_each_tracing_cpu(cpu) {
22732754 free_page((unsigned long)per_cpu(trace_buffered_event, cpu));
....@@ -2286,18 +2767,18 @@
22862767 preempt_enable();
22872768 }
22882769
2289
-static struct ring_buffer *temp_buffer;
2770
+static struct trace_buffer *temp_buffer;
22902771
22912772 struct ring_buffer_event *
2292
-trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
2773
+trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
22932774 struct trace_event_file *trace_file,
22942775 int type, unsigned long len,
2295
- unsigned long flags, int pc)
2776
+ unsigned int trace_ctx)
22962777 {
22972778 struct ring_buffer_event *entry;
22982779 int val;
22992780
2300
- *current_rb = trace_file->tr->trace_buffer.buffer;
2781
+ *current_rb = trace_file->tr->array_buffer.buffer;
23012782
23022783 if (!ring_buffer_time_stamp_abs(*current_rb) && (trace_file->flags &
23032784 (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED)) &&
....@@ -2305,7 +2786,7 @@
23052786 /* Try to use the per cpu buffer first */
23062787 val = this_cpu_inc_return(trace_buffered_event_cnt);
23072788 if ((len < (PAGE_SIZE - sizeof(*entry) - sizeof(entry->array[0]))) && val == 1) {
2308
- trace_event_setup(entry, type, flags, pc);
2789
+ trace_event_setup(entry, type, trace_ctx);
23092790 entry->array[0] = len;
23102791 return entry;
23112792 }
....@@ -2313,28 +2794,29 @@
23132794 }
23142795
23152796 entry = __trace_buffer_lock_reserve(*current_rb,
2316
- type, len, flags, pc);
2797
+ type, len, trace_ctx);
23172798 /*
23182799 * If tracing is off, but we have triggers enabled
23192800 * we still need to look at the event data. Use the temp_buffer
2320
- * 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
23212802 * safe and will not be recorded anywhere.
23222803 */
23232804 if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) {
23242805 *current_rb = temp_buffer;
2325
- entry = __trace_buffer_lock_reserve(*current_rb,
2326
- type, len, flags, pc);
2806
+ entry = __trace_buffer_lock_reserve(*current_rb, type, len,
2807
+ trace_ctx);
23272808 }
23282809 return entry;
23292810 }
23302811 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
23312812
2332
-static DEFINE_SPINLOCK(tracepoint_iter_lock);
2813
+static DEFINE_RAW_SPINLOCK(tracepoint_iter_lock);
23332814 static DEFINE_MUTEX(tracepoint_printk_mutex);
23342815
23352816 static void output_printk(struct trace_event_buffer *fbuffer)
23362817 {
23372818 struct trace_event_call *event_call;
2819
+ struct trace_event_file *file;
23382820 struct trace_event *event;
23392821 unsigned long flags;
23402822 struct trace_iterator *iter = tracepoint_print_iter;
....@@ -2348,20 +2830,26 @@
23482830 !event_call->event.funcs->trace)
23492831 return;
23502832
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
+
23512839 event = &fbuffer->trace_file->event_call->event;
23522840
2353
- spin_lock_irqsave(&tracepoint_iter_lock, flags);
2841
+ raw_spin_lock_irqsave(&tracepoint_iter_lock, flags);
23542842 trace_seq_init(&iter->seq);
23552843 iter->ent = fbuffer->entry;
23562844 event_call->event.funcs->trace(iter, 0, event);
23572845 trace_seq_putc(&iter->seq, 0);
23582846 printk("%s", iter->seq.buffer);
23592847
2360
- spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
2848
+ raw_spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
23612849 }
23622850
23632851 int tracepoint_printk_sysctl(struct ctl_table *table, int write,
2364
- void __user *buffer, size_t *lenp,
2852
+ void *buffer, size_t *lenp,
23652853 loff_t *ppos)
23662854 {
23672855 int save_tracepoint_printk;
....@@ -2398,9 +2886,11 @@
23982886 if (static_key_false(&tracepoint_printk_key.key))
23992887 output_printk(fbuffer);
24002888
2401
- 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,
24022892 fbuffer->event, fbuffer->entry,
2403
- fbuffer->flags, fbuffer->pc);
2893
+ fbuffer->trace_ctx, fbuffer->regs);
24042894 }
24052895 EXPORT_SYMBOL_GPL(trace_event_buffer_commit);
24062896
....@@ -2414,9 +2904,9 @@
24142904 # define STACK_SKIP 3
24152905
24162906 void trace_buffer_unlock_commit_regs(struct trace_array *tr,
2417
- struct ring_buffer *buffer,
2907
+ struct trace_buffer *buffer,
24182908 struct ring_buffer_event *event,
2419
- unsigned long flags, int pc,
2909
+ unsigned int trace_ctx,
24202910 struct pt_regs *regs)
24212911 {
24222912 __buffer_unlock_commit(buffer, event);
....@@ -2427,155 +2917,31 @@
24272917 * and mmiotrace, but that's ok if they lose a function or
24282918 * two. They are not that meaningful.
24292919 */
2430
- ftrace_trace_stack(tr, buffer, flags, regs ? 0 : STACK_SKIP, pc, regs);
2431
- 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);
24322922 }
24332923
24342924 /*
24352925 * Similar to trace_buffer_unlock_commit_regs() but do not dump stack.
24362926 */
24372927 void
2438
-trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer,
2928
+trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
24392929 struct ring_buffer_event *event)
24402930 {
24412931 __buffer_unlock_commit(buffer, event);
24422932 }
24432933
2444
-static void
2445
-trace_process_export(struct trace_export *export,
2446
- struct ring_buffer_event *event)
2447
-{
2448
- struct trace_entry *entry;
2449
- unsigned int size = 0;
2450
-
2451
- entry = ring_buffer_event_data(event);
2452
- size = ring_buffer_event_length(event);
2453
- export->write(export, entry, size);
2454
-}
2455
-
2456
-static DEFINE_MUTEX(ftrace_export_lock);
2457
-
2458
-static struct trace_export __rcu *ftrace_exports_list __read_mostly;
2459
-
2460
-static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);
2461
-
2462
-static inline void ftrace_exports_enable(void)
2463
-{
2464
- static_branch_enable(&ftrace_exports_enabled);
2465
-}
2466
-
2467
-static inline void ftrace_exports_disable(void)
2468
-{
2469
- static_branch_disable(&ftrace_exports_enabled);
2470
-}
2471
-
2472
-void ftrace_exports(struct ring_buffer_event *event)
2473
-{
2474
- struct trace_export *export;
2475
-
2476
- preempt_disable_notrace();
2477
-
2478
- export = rcu_dereference_raw_notrace(ftrace_exports_list);
2479
- while (export) {
2480
- trace_process_export(export, event);
2481
- export = rcu_dereference_raw_notrace(export->next);
2482
- }
2483
-
2484
- preempt_enable_notrace();
2485
-}
2486
-
2487
-static inline void
2488
-add_trace_export(struct trace_export **list, struct trace_export *export)
2489
-{
2490
- rcu_assign_pointer(export->next, *list);
2491
- /*
2492
- * We are entering export into the list but another
2493
- * CPU might be walking that list. We need to make sure
2494
- * the export->next pointer is valid before another CPU sees
2495
- * the export pointer included into the list.
2496
- */
2497
- rcu_assign_pointer(*list, export);
2498
-}
2499
-
2500
-static inline int
2501
-rm_trace_export(struct trace_export **list, struct trace_export *export)
2502
-{
2503
- struct trace_export **p;
2504
-
2505
- for (p = list; *p != NULL; p = &(*p)->next)
2506
- if (*p == export)
2507
- break;
2508
-
2509
- if (*p != export)
2510
- return -1;
2511
-
2512
- rcu_assign_pointer(*p, (*p)->next);
2513
-
2514
- return 0;
2515
-}
2516
-
2517
-static inline void
2518
-add_ftrace_export(struct trace_export **list, struct trace_export *export)
2519
-{
2520
- if (*list == NULL)
2521
- ftrace_exports_enable();
2522
-
2523
- add_trace_export(list, export);
2524
-}
2525
-
2526
-static inline int
2527
-rm_ftrace_export(struct trace_export **list, struct trace_export *export)
2528
-{
2529
- int ret;
2530
-
2531
- ret = rm_trace_export(list, export);
2532
- if (*list == NULL)
2533
- ftrace_exports_disable();
2534
-
2535
- return ret;
2536
-}
2537
-
2538
-int register_ftrace_export(struct trace_export *export)
2539
-{
2540
- if (WARN_ON_ONCE(!export->write))
2541
- return -1;
2542
-
2543
- mutex_lock(&ftrace_export_lock);
2544
-
2545
- add_ftrace_export(&ftrace_exports_list, export);
2546
-
2547
- mutex_unlock(&ftrace_export_lock);
2548
-
2549
- return 0;
2550
-}
2551
-EXPORT_SYMBOL_GPL(register_ftrace_export);
2552
-
2553
-int unregister_ftrace_export(struct trace_export *export)
2554
-{
2555
- int ret;
2556
-
2557
- mutex_lock(&ftrace_export_lock);
2558
-
2559
- ret = rm_ftrace_export(&ftrace_exports_list, export);
2560
-
2561
- mutex_unlock(&ftrace_export_lock);
2562
-
2563
- return ret;
2564
-}
2565
-EXPORT_SYMBOL_GPL(unregister_ftrace_export);
2566
-
25672934 void
2568
-trace_function(struct trace_array *tr,
2569
- unsigned long ip, unsigned long parent_ip, unsigned long flags,
2570
- int pc)
2935
+trace_function(struct trace_array *tr, unsigned long ip, unsigned long
2936
+ parent_ip, unsigned int trace_ctx)
25712937 {
25722938 struct trace_event_call *call = &event_function;
2573
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
2939
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
25742940 struct ring_buffer_event *event;
25752941 struct ftrace_entry *entry;
25762942
25772943 event = __trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry),
2578
- flags, pc);
2944
+ trace_ctx);
25792945 if (!event)
25802946 return;
25812947 entry = ring_buffer_event_data(event);
....@@ -2583,35 +2949,41 @@
25832949 entry->parent_ip = parent_ip;
25842950
25852951 if (!call_filter_check_discard(call, entry, buffer, event)) {
2586
- if (static_branch_unlikely(&ftrace_exports_enabled))
2587
- ftrace_exports(event);
2952
+ if (static_branch_unlikely(&trace_function_exports_enabled))
2953
+ ftrace_exports(event, TRACE_EXPORT_FUNCTION);
25882954 __buffer_unlock_commit(buffer, event);
25892955 }
25902956 }
25912957
25922958 #ifdef CONFIG_STACKTRACE
25932959
2594
-#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
+
25952965 struct ftrace_stack {
2596
- unsigned long calls[FTRACE_STACK_MAX_ENTRIES];
2966
+ unsigned long calls[FTRACE_KSTACK_ENTRIES];
25972967 };
25982968
2599
-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);
26002975 static DEFINE_PER_CPU(int, ftrace_stack_reserve);
26012976
2602
-static void __ftrace_trace_stack(struct ring_buffer *buffer,
2603
- unsigned long flags,
2604
- 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)
26052980 {
26062981 struct trace_event_call *call = &event_kernel_stack;
26072982 struct ring_buffer_event *event;
2983
+ unsigned int size, nr_entries;
2984
+ struct ftrace_stack *fstack;
26082985 struct stack_entry *entry;
2609
- struct stack_trace trace;
2610
- int use_stack;
2611
- int size = FTRACE_STACK_ENTRIES;
2612
-
2613
- trace.nr_entries = 0;
2614
- trace.skip = skip;
2986
+ int stackidx;
26152987
26162988 /*
26172989 * Add one, for this function and the call to save_stack_trace()
....@@ -2619,65 +2991,46 @@
26192991 */
26202992 #ifndef CONFIG_UNWINDER_ORC
26212993 if (!regs)
2622
- trace.skip++;
2994
+ skip++;
26232995 #endif
26242996
2625
- /*
2626
- * Since events can happen in NMIs there's no safe way to
2627
- * use the per cpu ftrace_stacks. We reserve it and if an interrupt
2628
- * or NMI comes in, it will just have to use the default
2629
- * FTRACE_STACK_SIZE.
2630
- */
26312997 preempt_disable_notrace();
26322998
2633
- 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
+
26343005 /*
2635
- * We don't need any atomic variables, just a barrier.
2636
- * If an interrupt comes in, we don't care, because it would
2637
- * have exited and put the counter back to what we want.
2638
- * We just need a barrier to keep gcc from moving things
2639
- * 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.
26403011 */
26413012 barrier();
2642
- if (use_stack == 1) {
2643
- trace.entries = this_cpu_ptr(ftrace_stack.calls);
2644
- trace.max_entries = FTRACE_STACK_MAX_ENTRIES;
26453013
2646
- if (regs)
2647
- save_stack_trace_regs(regs, &trace);
2648
- else
2649
- save_stack_trace(&trace);
3014
+ fstack = this_cpu_ptr(ftrace_stacks.stacks) + stackidx;
3015
+ size = ARRAY_SIZE(fstack->calls);
26503016
2651
- if (trace.nr_entries > size)
2652
- size = trace.nr_entries;
2653
- } else
2654
- /* From now on, use_stack is a boolean */
2655
- 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
+ }
26563023
2657
- size *= sizeof(unsigned long);
2658
-
3024
+ size = nr_entries * sizeof(unsigned long);
26593025 event = __trace_buffer_lock_reserve(buffer, TRACE_STACK,
26603026 (sizeof(*entry) - sizeof(entry->caller)) + size,
2661
- flags, pc);
3027
+ trace_ctx);
26623028 if (!event)
26633029 goto out;
26643030 entry = ring_buffer_event_data(event);
26653031
2666
- memset(&entry->caller, 0, size);
2667
-
2668
- if (use_stack)
2669
- memcpy(&entry->caller, trace.entries,
2670
- trace.nr_entries * sizeof(unsigned long));
2671
- else {
2672
- trace.max_entries = FTRACE_STACK_ENTRIES;
2673
- trace.entries = entry->caller;
2674
- if (regs)
2675
- save_stack_trace_regs(regs, &trace);
2676
- else
2677
- save_stack_trace(&trace);
2678
- }
2679
-
2680
- entry->size = trace.nr_entries;
3032
+ memcpy(&entry->caller, fstack->calls, size);
3033
+ entry->size = nr_entries;
26813034
26823035 if (!call_filter_check_discard(call, entry, buffer, event))
26833036 __buffer_unlock_commit(buffer, event);
....@@ -2691,23 +3044,23 @@
26913044 }
26923045
26933046 static inline void ftrace_trace_stack(struct trace_array *tr,
2694
- struct ring_buffer *buffer,
2695
- unsigned long flags,
2696
- 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)
26973050 {
26983051 if (!(tr->trace_flags & TRACE_ITER_STACKTRACE))
26993052 return;
27003053
2701
- __ftrace_trace_stack(buffer, flags, skip, pc, regs);
3054
+ __ftrace_trace_stack(buffer, trace_ctx, skip, regs);
27023055 }
27033056
2704
-void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
2705
- int pc)
3057
+void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
3058
+ int skip)
27063059 {
2707
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
3060
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
27083061
27093062 if (rcu_is_watching()) {
2710
- __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
3063
+ __ftrace_trace_stack(buffer, trace_ctx, skip, NULL);
27113064 return;
27123065 }
27133066
....@@ -2721,7 +3074,7 @@
27213074 return;
27223075
27233076 rcu_irq_enter_irqson();
2724
- __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
3077
+ __ftrace_trace_stack(buffer, trace_ctx, skip, NULL);
27253078 rcu_irq_exit_irqson();
27263079 }
27273080
....@@ -2731,31 +3084,28 @@
27313084 */
27323085 void trace_dump_stack(int skip)
27333086 {
2734
- unsigned long flags;
2735
-
27363087 if (tracing_disabled || tracing_selftest_running)
27373088 return;
2738
-
2739
- local_save_flags(flags);
27403089
27413090 #ifndef CONFIG_UNWINDER_ORC
27423091 /* Skip 1 to skip this function. */
27433092 skip++;
27443093 #endif
2745
- __ftrace_trace_stack(global_trace.trace_buffer.buffer,
2746
- flags, skip, preempt_count(), NULL);
3094
+ __ftrace_trace_stack(global_trace.array_buffer.buffer,
3095
+ tracing_gen_ctx(), skip, NULL);
27473096 }
3097
+EXPORT_SYMBOL_GPL(trace_dump_stack);
27483098
3099
+#ifdef CONFIG_USER_STACKTRACE_SUPPORT
27493100 static DEFINE_PER_CPU(int, user_stack_count);
27503101
2751
-void
3102
+static void
27523103 ftrace_trace_userstack(struct trace_array *tr,
2753
- struct ring_buffer *buffer, unsigned long flags, int pc)
3104
+ struct trace_buffer *buffer, unsigned int trace_ctx)
27543105 {
27553106 struct trace_event_call *call = &event_user_stack;
27563107 struct ring_buffer_event *event;
27573108 struct userstack_entry *entry;
2758
- struct stack_trace trace;
27593109
27603110 if (!(tr->trace_flags & TRACE_ITER_USERSTACKTRACE))
27613111 return;
....@@ -2778,7 +3128,7 @@
27783128 __this_cpu_inc(user_stack_count);
27793129
27803130 event = __trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
2781
- sizeof(*entry), flags, pc);
3131
+ sizeof(*entry), trace_ctx);
27823132 if (!event)
27833133 goto out_drop_count;
27843134 entry = ring_buffer_event_data(event);
....@@ -2786,12 +3136,7 @@
27863136 entry->tgid = current->tgid;
27873137 memset(&entry->caller, 0, sizeof(entry->caller));
27883138
2789
- trace.nr_entries = 0;
2790
- trace.max_entries = FTRACE_STACK_ENTRIES;
2791
- trace.skip = 0;
2792
- trace.entries = entry->caller;
2793
-
2794
- save_stack_trace_user(&trace);
3139
+ stack_trace_save_user(entry->caller, FTRACE_STACK_ENTRIES);
27953140 if (!call_filter_check_discard(call, entry, buffer, event))
27963141 __buffer_unlock_commit(buffer, event);
27973142
....@@ -2800,13 +3145,13 @@
28003145 out:
28013146 preempt_enable();
28023147 }
2803
-
2804
-#ifdef UNUSED
2805
-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)
28063152 {
2807
- ftrace_trace_userstack(tr, flags, preempt_count());
28083153 }
2809
-#endif /* UNUSED */
3154
+#endif /* !CONFIG_USER_STACKTRACE_SUPPORT */
28103155
28113156 #endif /* CONFIG_STACKTRACE */
28123157
....@@ -2847,8 +3192,11 @@
28473192 {
28483193 struct trace_buffer_struct __percpu *buffers;
28493194
3195
+ if (trace_percpu_buffer)
3196
+ return 0;
3197
+
28503198 buffers = alloc_percpu(struct trace_buffer_struct);
2851
- if (WARN(!buffers, "Could not allocate percpu trace_printk buffer"))
3199
+ if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer"))
28523200 return -ENOMEM;
28533201
28543202 trace_percpu_buffer = buffers;
....@@ -2893,9 +3241,10 @@
28933241 * directly here. If the global_trace.buffer is already
28943242 * allocated here, then this was called by module code.
28953243 */
2896
- if (global_trace.trace_buffer.buffer)
3244
+ if (global_trace.array_buffer.buffer)
28973245 tracing_start_cmdline_record();
28983246 }
3247
+EXPORT_SYMBOL_GPL(trace_printk_init_buffers);
28993248
29003249 void trace_printk_start_comm(void)
29013250 {
....@@ -2918,18 +3267,20 @@
29183267
29193268 /**
29203269 * trace_vbprintk - write binary msg to tracing buffer
2921
- *
3270
+ * @ip: The address of the caller
3271
+ * @fmt: The string format to write to the buffer
3272
+ * @args: Arguments for @fmt
29223273 */
29233274 int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
29243275 {
29253276 struct trace_event_call *call = &event_bprint;
29263277 struct ring_buffer_event *event;
2927
- struct ring_buffer *buffer;
3278
+ struct trace_buffer *buffer;
29283279 struct trace_array *tr = &global_trace;
29293280 struct bprint_entry *entry;
2930
- unsigned long flags;
3281
+ unsigned int trace_ctx;
29313282 char *tbuffer;
2932
- int len = 0, size, pc;
3283
+ int len = 0, size;
29333284
29343285 if (unlikely(tracing_selftest_running || tracing_disabled))
29353286 return 0;
....@@ -2937,7 +3288,7 @@
29373288 /* Don't pollute graph traces with trace_vprintk internals */
29383289 pause_graph_tracing();
29393290
2940
- pc = preempt_count();
3291
+ trace_ctx = tracing_gen_ctx();
29413292 preempt_disable_notrace();
29423293
29433294 tbuffer = get_trace_buf();
....@@ -2949,13 +3300,13 @@
29493300 len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args);
29503301
29513302 if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0)
2952
- goto out;
3303
+ goto out_put;
29533304
2954
- local_save_flags(flags);
29553305 size = sizeof(*entry) + sizeof(u32) * len;
2956
- buffer = tr->trace_buffer.buffer;
3306
+ buffer = tr->array_buffer.buffer;
3307
+ ring_buffer_nest_start(buffer);
29573308 event = __trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size,
2958
- flags, pc);
3309
+ trace_ctx);
29593310 if (!event)
29603311 goto out;
29613312 entry = ring_buffer_event_data(event);
....@@ -2965,10 +3316,12 @@
29653316 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
29663317 if (!call_filter_check_discard(call, entry, buffer, event)) {
29673318 __buffer_unlock_commit(buffer, event);
2968
- ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL);
3319
+ ftrace_trace_stack(tr, buffer, trace_ctx, 6, NULL);
29693320 }
29703321
29713322 out:
3323
+ ring_buffer_nest_end(buffer);
3324
+out_put:
29723325 put_trace_buf();
29733326
29743327 out_nobuffer:
....@@ -2981,14 +3334,14 @@
29813334
29823335 __printf(3, 0)
29833336 static int
2984
-__trace_array_vprintk(struct ring_buffer *buffer,
3337
+__trace_array_vprintk(struct trace_buffer *buffer,
29853338 unsigned long ip, const char *fmt, va_list args)
29863339 {
29873340 struct trace_event_call *call = &event_print;
29883341 struct ring_buffer_event *event;
2989
- int len = 0, size, pc;
3342
+ int len = 0, size;
29903343 struct print_entry *entry;
2991
- unsigned long flags;
3344
+ unsigned int trace_ctx;
29923345 char *tbuffer;
29933346
29943347 if (tracing_disabled || tracing_selftest_running)
....@@ -2997,7 +3350,7 @@
29973350 /* Don't pollute graph traces with trace_vprintk internals */
29983351 pause_graph_tracing();
29993352
3000
- pc = preempt_count();
3353
+ trace_ctx = tracing_gen_ctx();
30013354 preempt_disable_notrace();
30023355
30033356
....@@ -3009,10 +3362,10 @@
30093362
30103363 len = vscnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args);
30113364
3012
- local_save_flags(flags);
30133365 size = sizeof(*entry) + len + 1;
3366
+ ring_buffer_nest_start(buffer);
30143367 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
3015
- flags, pc);
3368
+ trace_ctx);
30163369 if (!event)
30173370 goto out;
30183371 entry = ring_buffer_event_data(event);
....@@ -3021,10 +3374,11 @@
30213374 memcpy(&entry->buf, tbuffer, len + 1);
30223375 if (!call_filter_check_discard(call, entry, buffer, event)) {
30233376 __buffer_unlock_commit(buffer, event);
3024
- ftrace_trace_stack(&global_trace, buffer, flags, 6, pc, NULL);
3377
+ ftrace_trace_stack(&global_trace, buffer, trace_ctx, 6, NULL);
30253378 }
30263379
30273380 out:
3381
+ ring_buffer_nest_end(buffer);
30283382 put_trace_buf();
30293383
30303384 out_nobuffer:
....@@ -3038,9 +3392,29 @@
30383392 int trace_array_vprintk(struct trace_array *tr,
30393393 unsigned long ip, const char *fmt, va_list args)
30403394 {
3041
- return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args);
3395
+ return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args);
30423396 }
30433397
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
+ */
30443418 __printf(3, 0)
30453419 int trace_array_printk(struct trace_array *tr,
30463420 unsigned long ip, const char *fmt, ...)
....@@ -3048,20 +3422,46 @@
30483422 int ret;
30493423 va_list ap;
30503424
3051
- if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
3052
- return 0;
3053
-
30543425 if (!tr)
30553426 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;
30563434
30573435 va_start(ap, fmt);
30583436 ret = trace_array_vprintk(tr, ip, fmt, ap);
30593437 va_end(ap);
30603438 return ret;
30613439 }
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);
30623462
30633463 __printf(3, 4)
3064
-int trace_array_printk_buf(struct ring_buffer *buffer,
3464
+int trace_array_printk_buf(struct trace_buffer *buffer,
30653465 unsigned long ip, const char *fmt, ...)
30663466 {
30673467 int ret;
....@@ -3089,7 +3489,7 @@
30893489
30903490 iter->idx++;
30913491 if (buf_iter)
3092
- ring_buffer_read(buf_iter, NULL);
3492
+ ring_buffer_iter_advance(buf_iter);
30933493 }
30943494
30953495 static struct trace_entry *
....@@ -3099,11 +3499,15 @@
30993499 struct ring_buffer_event *event;
31003500 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu);
31013501
3102
- if (buf_iter)
3502
+ if (buf_iter) {
31033503 event = ring_buffer_iter_peek(buf_iter, ts);
3104
- else
3105
- 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,
31063509 lost_events);
3510
+ }
31073511
31083512 if (event) {
31093513 iter->ent_size = ring_buffer_event_length(event);
....@@ -3117,7 +3521,7 @@
31173521 __find_next_entry(struct trace_iterator *iter, int *ent_cpu,
31183522 unsigned long *missing_events, u64 *ent_ts)
31193523 {
3120
- struct ring_buffer *buffer = iter->trace_buffer->buffer;
3524
+ struct trace_buffer *buffer = iter->array_buffer->buffer;
31213525 struct trace_entry *ent, *next = NULL;
31223526 unsigned long lost_events = 0, next_lost = 0;
31233527 int cpu_file = iter->cpu_file;
....@@ -3173,11 +3577,53 @@
31733577 return next;
31743578 }
31753579
3580
+#define STATIC_TEMP_BUF_SIZE 128
3581
+static char static_temp_buf[STATIC_TEMP_BUF_SIZE] __aligned(4);
3582
+
31763583 /* Find the next real entry, without updating the iterator itself */
31773584 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
31783585 int *ent_cpu, u64 *ent_ts)
31793586 {
3180
- 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;
31813627 }
31823628
31833629 /* Find the next real entry, and increment the iterator to the next entry */
....@@ -3194,7 +3640,7 @@
31943640
31953641 static void trace_consume(struct trace_iterator *iter)
31963642 {
3197
- ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts,
3643
+ ring_buffer_consume(iter->array_buffer->buffer, iter->cpu, &iter->ts,
31983644 &iter->lost_events);
31993645 }
32003646
....@@ -3227,12 +3673,11 @@
32273673
32283674 void tracing_iter_reset(struct trace_iterator *iter, int cpu)
32293675 {
3230
- struct ring_buffer_event *event;
32313676 struct ring_buffer_iter *buf_iter;
32323677 unsigned long entries = 0;
32333678 u64 ts;
32343679
3235
- per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0;
3680
+ per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = 0;
32363681
32373682 buf_iter = trace_buffer_iter(iter, cpu);
32383683 if (!buf_iter)
....@@ -3245,14 +3690,14 @@
32453690 * that a reset never took place on a cpu. This is evident
32463691 * by the timestamp being before the start of the buffer.
32473692 */
3248
- while ((event = ring_buffer_iter_peek(buf_iter, &ts))) {
3249
- if (ts >= iter->trace_buffer->time_start)
3693
+ while (ring_buffer_iter_peek(buf_iter, &ts)) {
3694
+ if (ts >= iter->array_buffer->time_start)
32503695 break;
32513696 entries++;
3252
- ring_buffer_read(buf_iter, NULL);
3697
+ ring_buffer_iter_advance(buf_iter);
32533698 }
32543699
3255
- per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries;
3700
+ per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = entries;
32563701 }
32573702
32583703 /*
....@@ -3331,46 +3776,84 @@
33313776 }
33323777
33333778 static void
3334
-get_total_entries(struct trace_buffer *buf,
3335
- unsigned long *total, unsigned long *entries)
3779
+get_total_entries_cpu(struct array_buffer *buf, unsigned long *total,
3780
+ unsigned long *entries, int cpu)
33363781 {
33373782 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;
33383805 int cpu;
33393806
33403807 *total = 0;
33413808 *entries = 0;
33423809
33433810 for_each_tracing_cpu(cpu) {
3344
- count = ring_buffer_entries_cpu(buf->buffer, cpu);
3345
- /*
3346
- * If this buffer has skipped entries, then we hold all
3347
- * entries for the trace and we need to ignore the
3348
- * ones before the time stamp.
3349
- */
3350
- if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
3351
- count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
3352
- /* total is the same as the entries */
3353
- *total += count;
3354
- } else
3355
- *total += count +
3356
- ring_buffer_overrun_cpu(buf->buffer, cpu);
3357
- *entries += count;
3811
+ get_total_entries_cpu(buf, &t, &e, cpu);
3812
+ *total += t;
3813
+ *entries += e;
33583814 }
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;
33593839 }
33603840
33613841 static void print_lat_help_header(struct seq_file *m)
33623842 {
3363
- seq_puts(m, "# _------=> CPU# \n"
3364
- "# / _-----=> irqs-off \n"
3365
- "# | / _----=> need-resched \n"
3366
- "# || / _---=> hardirq/softirq \n"
3367
- "# ||| / _--=> preempt-depth \n"
3368
- "# |||| / delay \n"
3369
- "# cmd pid ||||| time | caller \n"
3370
- "# \\ / ||||| \\ | / \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");
33713854 }
33723855
3373
-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)
33743857 {
33753858 unsigned long total;
33763859 unsigned long entries;
....@@ -3381,47 +3864,43 @@
33813864 seq_puts(m, "#\n");
33823865 }
33833866
3384
-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,
33853868 unsigned int flags)
33863869 {
33873870 bool tgid = flags & TRACE_ITER_RECORD_TGID;
33883871
33893872 print_event_info(buf, m);
33903873
3391
- seq_printf(m, "# TASK-PID %s CPU# TIMESTAMP FUNCTION\n", tgid ? "TGID " : "");
3392
- 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 ? " | " : "");
33933876 }
33943877
3395
-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,
33963879 unsigned int flags)
33973880 {
33983881 bool tgid = flags & TRACE_ITER_RECORD_TGID;
3399
- const char tgid_space[] = " ";
3400
- const char space[] = " ";
3882
+ const char *space = " ";
3883
+ int prec = tgid ? 12 : 2;
34013884
34023885 print_event_info(buf, m);
34033886
3404
- seq_printf(m, "# %s _-----=> irqs-off\n",
3405
- tgid ? tgid_space : space);
3406
- seq_printf(m, "# %s / _----=> need-resched\n",
3407
- tgid ? tgid_space : space);
3408
- seq_printf(m, "# %s| / _---=> hardirq/softirq\n",
3409
- tgid ? tgid_space : space);
3410
- seq_printf(m, "# %s|| / _--=> preempt-depth\n",
3411
- tgid ? tgid_space : space);
3412
- seq_printf(m, "# %s||| / delay\n",
3413
- tgid ? tgid_space : space);
3414
- seq_printf(m, "# TASK-PID %sCPU# |||| TIMESTAMP FUNCTION\n",
3415
- tgid ? " TGID " : space);
3416
- seq_printf(m, "# | | %s | |||| | |\n",
3417
- 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, " | ");
34183897 }
34193898
34203899 void
34213900 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
34223901 {
34233902 unsigned long sym_flags = (global_trace.trace_flags & TRACE_ITER_SYM_MASK);
3424
- struct trace_buffer *buf = iter->trace_buffer;
3903
+ struct array_buffer *buf = iter->array_buffer;
34253904 struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu);
34263905 struct tracer *type = iter->trace;
34273906 unsigned long entries;
....@@ -3448,6 +3927,8 @@
34483927 "desktop",
34493928 #elif defined(CONFIG_PREEMPT)
34503929 "preempt",
3930
+#elif defined(CONFIG_PREEMPT_RT)
3931
+ "preempt_rt",
34513932 #else
34523933 "unknown",
34533934 #endif
....@@ -3494,7 +3975,7 @@
34943975 cpumask_test_cpu(iter->cpu, iter->started))
34953976 return;
34963977
3497
- 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)
34983979 return;
34993980
35003981 if (cpumask_available(iter->started))
....@@ -3628,7 +4109,7 @@
36284109 if (!ring_buffer_iter_empty(buf_iter))
36294110 return 0;
36304111 } else {
3631
- if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu))
4112
+ if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu))
36324113 return 0;
36334114 }
36344115 return 1;
....@@ -3640,7 +4121,7 @@
36404121 if (!ring_buffer_iter_empty(buf_iter))
36414122 return 0;
36424123 } else {
3643
- if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu))
4124
+ if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu))
36444125 return 0;
36454126 }
36464127 }
....@@ -3656,8 +4137,12 @@
36564137 enum print_line_t ret;
36574138
36584139 if (iter->lost_events) {
3659
- trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
3660
- 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);
36614146 if (trace_seq_has_overflowed(&iter->seq))
36624147 return TRACE_TYPE_PARTIAL_LINE;
36634148 }
....@@ -3730,10 +4215,10 @@
37304215 } else {
37314216 if (!(trace_flags & TRACE_ITER_VERBOSE)) {
37324217 if (trace_flags & TRACE_ITER_IRQ_INFO)
3733
- print_func_help_header_irq(iter->trace_buffer,
4218
+ print_func_help_header_irq(iter->array_buffer,
37344219 m, trace_flags);
37354220 else
3736
- print_func_help_header(iter->trace_buffer, m,
4221
+ print_func_help_header(iter->array_buffer, m,
37374222 trace_flags);
37384223 }
37394224 }
....@@ -3873,6 +4358,18 @@
38734358 goto release;
38744359
38754360 /*
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
+ /*
38764373 * We make a copy of the current tracer to avoid concurrent
38774374 * changes on it while we are reading.
38784375 */
....@@ -3891,35 +4388,38 @@
38914388 #ifdef CONFIG_TRACER_MAX_TRACE
38924389 /* Currently only the top directory has a snapshot */
38934390 if (tr->current_trace->print_max || snapshot)
3894
- iter->trace_buffer = &tr->max_buffer;
4391
+ iter->array_buffer = &tr->max_buffer;
38954392 else
38964393 #endif
3897
- iter->trace_buffer = &tr->trace_buffer;
4394
+ iter->array_buffer = &tr->array_buffer;
38984395 iter->snapshot = snapshot;
38994396 iter->pos = -1;
39004397 iter->cpu_file = tracing_get_cpu(inode);
39014398 mutex_init(&iter->mutex);
39024399
39034400 /* Notify the tracer early; before we stop tracing. */
3904
- if (iter->trace && iter->trace->open)
4401
+ if (iter->trace->open)
39054402 iter->trace->open(iter);
39064403
39074404 /* Annotate start of buffers if we had overruns */
3908
- if (ring_buffer_overruns(iter->trace_buffer->buffer))
4405
+ if (ring_buffer_overruns(iter->array_buffer->buffer))
39094406 iter->iter_flags |= TRACE_FILE_ANNOTATE;
39104407
39114408 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
39124409 if (trace_clocks[tr->clock_id].in_ns)
39134410 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
39144411
3915
- /* stop the trace while dumping if we are not opening "snapshot" */
3916
- 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))
39174417 tracing_stop_tr(tr);
39184418
39194419 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
39204420 for_each_tracing_cpu(cpu) {
39214421 iter->buffer_iter[cpu] =
3922
- ring_buffer_read_prepare(iter->trace_buffer->buffer,
4422
+ ring_buffer_read_prepare(iter->array_buffer->buffer,
39234423 cpu, GFP_KERNEL);
39244424 }
39254425 ring_buffer_read_prepare_sync();
....@@ -3930,7 +4430,7 @@
39304430 } else {
39314431 cpu = iter->cpu_file;
39324432 iter->buffer_iter[cpu] =
3933
- ring_buffer_read_prepare(iter->trace_buffer->buffer,
4433
+ ring_buffer_read_prepare(iter->array_buffer->buffer,
39344434 cpu, GFP_KERNEL);
39354435 ring_buffer_read_prepare_sync();
39364436 ring_buffer_read_start(iter->buffer_iter[cpu]);
....@@ -3944,6 +4444,7 @@
39444444 fail:
39454445 mutex_unlock(&trace_types_lock);
39464446 kfree(iter->trace);
4447
+ kfree(iter->temp);
39474448 kfree(iter->buffer_iter);
39484449 release:
39494450 seq_release_private(inode, file);
....@@ -3952,8 +4453,11 @@
39524453
39534454 int tracing_open_generic(struct inode *inode, struct file *filp)
39544455 {
3955
- if (tracing_disabled)
3956
- return -ENODEV;
4456
+ int ret;
4457
+
4458
+ ret = tracing_check_open_get_tr(NULL);
4459
+ if (ret)
4460
+ return ret;
39574461
39584462 filp->private_data = inode->i_private;
39594463 return 0;
....@@ -3968,15 +4472,14 @@
39684472 * Open and update trace_array ref count.
39694473 * Must have the current trace_array passed to it.
39704474 */
3971
-static int tracing_open_generic_tr(struct inode *inode, struct file *filp)
4475
+int tracing_open_generic_tr(struct inode *inode, struct file *filp)
39724476 {
39734477 struct trace_array *tr = inode->i_private;
4478
+ int ret;
39744479
3975
- if (tracing_disabled)
3976
- return -ENODEV;
3977
-
3978
- if (trace_array_get(tr) < 0)
3979
- return -ENODEV;
4480
+ ret = tracing_check_open_get_tr(tr);
4481
+ if (ret)
4482
+ return ret;
39804483
39814484 filp->private_data = inode->i_private;
39824485
....@@ -4007,7 +4510,7 @@
40074510 if (iter->trace && iter->trace->close)
40084511 iter->trace->close(iter);
40094512
4010
- if (!iter->snapshot)
4513
+ if (!iter->snapshot && tr->stop_count)
40114514 /* reenable tracing if it was previously enabled */
40124515 tracing_start_tr(tr);
40134516
....@@ -4017,6 +4520,7 @@
40174520
40184521 mutex_destroy(&iter->mutex);
40194522 free_cpumask_var(iter->started);
4523
+ kfree(iter->temp);
40204524 kfree(iter->trace);
40214525 kfree(iter->buffer_iter);
40224526 seq_release_private(inode, file);
....@@ -4045,15 +4549,16 @@
40454549 {
40464550 struct trace_array *tr = inode->i_private;
40474551 struct trace_iterator *iter;
4048
- int ret = 0;
4552
+ int ret;
40494553
4050
- if (trace_array_get(tr) < 0)
4051
- return -ENODEV;
4554
+ ret = tracing_check_open_get_tr(tr);
4555
+ if (ret)
4556
+ return ret;
40524557
40534558 /* If this file was open for write, then erase contents */
40544559 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
40554560 int cpu = tracing_get_cpu(inode);
4056
- struct trace_buffer *trace_buf = &tr->trace_buffer;
4561
+ struct array_buffer *trace_buf = &tr->array_buffer;
40574562
40584563 #ifdef CONFIG_TRACER_MAX_TRACE
40594564 if (tr->current_trace->print_max)
....@@ -4063,7 +4568,7 @@
40634568 if (cpu == RING_BUFFER_ALL_CPUS)
40644569 tracing_reset_online_cpus(trace_buf);
40654570 else
4066
- tracing_reset(trace_buf, cpu);
4571
+ tracing_reset_cpu(trace_buf, cpu);
40674572 }
40684573
40694574 if (file->f_mode & FMODE_READ) {
....@@ -4164,11 +4669,9 @@
41644669 struct seq_file *m;
41654670 int ret;
41664671
4167
- if (tracing_disabled)
4168
- return -ENODEV;
4169
-
4170
- if (trace_array_get(tr) < 0)
4171
- return -ENODEV;
4672
+ ret = tracing_check_open_get_tr(tr);
4673
+ if (ret)
4674
+ return ret;
41724675
41734676 ret = seq_open(file, &show_traces_seq_ops);
41744677 if (ret) {
....@@ -4252,20 +4755,13 @@
42524755 return count;
42534756 }
42544757
4255
-static ssize_t
4256
-tracing_cpumask_write(struct file *filp, const char __user *ubuf,
4257
- size_t count, loff_t *ppos)
4758
+int tracing_set_cpumask(struct trace_array *tr,
4759
+ cpumask_var_t tracing_cpumask_new)
42584760 {
4259
- struct trace_array *tr = file_inode(filp)->i_private;
4260
- cpumask_var_t tracing_cpumask_new;
4261
- int err, cpu;
4761
+ int cpu;
42624762
4263
- if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
4264
- return -ENOMEM;
4265
-
4266
- err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
4267
- if (err)
4268
- goto err_unlock;
4763
+ if (!tr)
4764
+ return -EINVAL;
42694765
42704766 local_irq_disable();
42714767 arch_spin_lock(&tr->max_lock);
....@@ -4276,24 +4772,47 @@
42764772 */
42774773 if (cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
42784774 !cpumask_test_cpu(cpu, tracing_cpumask_new)) {
4279
- atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
4280
- 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);
42814777 }
42824778 if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
42834779 cpumask_test_cpu(cpu, tracing_cpumask_new)) {
4284
- atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
4285
- 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);
42864782 }
42874783 }
42884784 arch_spin_unlock(&tr->max_lock);
42894785 local_irq_enable();
42904786
42914787 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
+
42924811 free_cpumask_var(tracing_cpumask_new);
42934812
42944813 return count;
42954814
4296
-err_unlock:
4815
+err_free:
42974816 free_cpumask_var(tracing_cpumask_new);
42984817
42994818 return err;
....@@ -4435,7 +4954,7 @@
44354954 ftrace_pid_follow_fork(tr, enabled);
44364955
44374956 if (mask == TRACE_ITER_OVERWRITE) {
4438
- ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled);
4957
+ ring_buffer_change_overwrite(tr->array_buffer.buffer, enabled);
44394958 #ifdef CONFIG_TRACER_MAX_TRACE
44404959 ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled);
44414960 #endif
....@@ -4449,19 +4968,21 @@
44494968 return 0;
44504969 }
44514970
4452
-static int trace_set_options(struct trace_array *tr, char *option)
4971
+int trace_set_options(struct trace_array *tr, char *option)
44534972 {
44544973 char *cmp;
44554974 int neg = 0;
44564975 int ret;
44574976 size_t orig_len = strlen(option);
4977
+ int len;
44584978
44594979 cmp = strstrip(option);
44604980
4461
- if (strncmp(cmp, "no", 2) == 0) {
4981
+ len = str_has_prefix(cmp, "no");
4982
+ if (len)
44624983 neg = 1;
4463
- cmp += 2;
4464
- }
4984
+
4985
+ cmp += len;
44654986
44664987 mutex_lock(&event_mutex);
44674988 mutex_lock(&trace_types_lock);
....@@ -4537,11 +5058,9 @@
45375058 struct trace_array *tr = inode->i_private;
45385059 int ret;
45395060
4540
- if (tracing_disabled)
4541
- return -ENODEV;
4542
-
4543
- if (trace_array_get(tr) < 0)
4544
- return -ENODEV;
5061
+ ret = tracing_check_open_get_tr(tr);
5062
+ if (ret)
5063
+ return ret;
45455064
45465065 ret = single_open(file, tracing_trace_options_show, inode->i_private);
45475066 if (ret < 0)
....@@ -4568,6 +5087,7 @@
45685087 " trace_pipe\t\t- A consuming read to see the contents of the buffer\n"
45695088 " current_tracer\t- function and latency tracers\n"
45705089 " available_tracers\t- list of configured tracers for current_tracer\n"
5090
+ " error_log\t- error log for failed commands (that support it)\n"
45715091 " buffer_size_kb\t- view and modify size of per cpu buffer\n"
45725092 " buffer_total_size_kb - view total size of all cpu buffers\n\n"
45735093 " trace_clock\t\t-change the clock used to order events\n"
....@@ -4588,7 +5108,7 @@
45885108 " instances\t\t- Make sub-buffers with: mkdir instances/foo\n"
45895109 "\t\t\t Remove sub-buffer with rmdir\n"
45905110 " trace_options\t\t- Set format or modify how tracing happens\n"
4591
- "\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"
45925112 "\t\t\t option name\n"
45935113 " saved_cmdlines_size\t- echo command number in here to store comm-pid list\n"
45945114 #ifdef CONFIG_DYNAMIC_FTRACE
....@@ -4632,6 +5152,8 @@
46325152 #ifdef CONFIG_FUNCTION_TRACER
46335153 " set_ftrace_pid\t- Write pid(s) to only function trace those pids\n"
46345154 "\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"
46355157 #endif
46365158 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
46375159 " set_graph_function\t- Trace the nested calls of a function (function_graph)\n"
....@@ -4653,31 +5175,49 @@
46535175 "\t\t\t traces\n"
46545176 #endif
46555177 #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
46565182 #ifdef CONFIG_KPROBE_EVENTS
4657
- " 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"
46585184 "\t\t\t Write into this file to define/undefine new trace events.\n"
46595185 #endif
46605186 #ifdef CONFIG_UPROBE_EVENTS
4661
- " 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"
46625188 "\t\t\t Write into this file to define/undefine new trace events.\n"
46635189 #endif
46645190 #if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
46655191 "\t accepts: event-definitions (one definition per line)\n"
46665192 "\t Format: p[:[<group>/]<event>] <place> [<args>]\n"
46675193 "\t r[maxactive][:[<group>/]<event>] <place> [<args>]\n"
5194
+#ifdef CONFIG_HIST_TRIGGERS
5195
+ "\t s:[synthetic/]<event> <field> [<field>]\n"
5196
+#endif
46685197 "\t -:[<group>/]<event>\n"
46695198 #ifdef CONFIG_KPROBE_EVENTS
46705199 "\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
4671
- "place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n"
5200
+ "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
46725201 #endif
46735202 #ifdef CONFIG_UPROBE_EVENTS
4674
- "\t place: <path>:<offset>\n"
5203
+ " place (uprobe): <path>:<offset>[%return][(ref_ctr_offset)]\n"
46755204 #endif
46765205 "\t args: <name>=fetcharg[:type]\n"
46775206 "\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
4678
- "\t $stack<index>, $stack, $retval, $comm\n"
4679
- "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,\n"
4680
- "\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
46815221 #endif
46825222 " events/\t\t- Directory containing all trace event subsystems:\n"
46835223 " enable\t\t- Write 0/1 to enable/disable tracing of all events\n"
....@@ -4730,6 +5270,7 @@
47305270 "\t [:size=#entries]\n"
47315271 "\t [:pause][:continue][:clear]\n"
47325272 "\t [:name=histname1]\n"
5273
+ "\t [:<handler>.<action>]\n"
47335274 "\t [if <filter>]\n\n"
47345275 "\t Note, special fields can be used as well:\n"
47355276 "\t common_timestamp - to record current timestamp\n"
....@@ -4774,8 +5315,26 @@
47745315 "\t unchanged.\n\n"
47755316 "\t The enable_hist and disable_hist triggers can be used to\n"
47765317 "\t have one event conditionally start and stop another event's\n"
4777
- "\t already-attached hist trigger. The syntax is analagous to\n"
4778
- "\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
47795338 #endif
47805339 ;
47815340
....@@ -4833,8 +5392,11 @@
48335392
48345393 static int tracing_saved_tgids_open(struct inode *inode, struct file *filp)
48355394 {
4836
- if (tracing_disabled)
4837
- return -ENODEV;
5395
+ int ret;
5396
+
5397
+ ret = tracing_check_open_get_tr(NULL);
5398
+ if (ret)
5399
+ return ret;
48385400
48395401 return seq_open(filp, &tracing_saved_tgids_seq_ops);
48405402 }
....@@ -4910,8 +5472,11 @@
49105472
49115473 static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp)
49125474 {
4913
- if (tracing_disabled)
4914
- return -ENODEV;
5475
+ int ret;
5476
+
5477
+ ret = tracing_check_open_get_tr(NULL);
5478
+ if (ret)
5479
+ return ret;
49155480
49165481 return seq_open(filp, &tracing_saved_cmdlines_seq_ops);
49175482 }
....@@ -4930,9 +5495,11 @@
49305495 char buf[64];
49315496 int r;
49325497
5498
+ preempt_disable();
49335499 arch_spin_lock(&trace_cmdline_lock);
49345500 r = scnprintf(buf, sizeof(buf), "%u\n", savedcmd->cmdline_num);
49355501 arch_spin_unlock(&trace_cmdline_lock);
5502
+ preempt_enable();
49365503
49375504 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
49385505 }
....@@ -4957,10 +5524,12 @@
49575524 return -ENOMEM;
49585525 }
49595526
5527
+ preempt_disable();
49605528 arch_spin_lock(&trace_cmdline_lock);
49615529 savedcmd_temp = savedcmd;
49625530 savedcmd = s;
49635531 arch_spin_unlock(&trace_cmdline_lock);
5532
+ preempt_enable();
49645533 free_saved_cmdlines_buffer(savedcmd_temp);
49655534
49665535 return 0;
....@@ -5019,14 +5588,12 @@
50195588 * Paranoid! If ptr points to end, we don't want to increment past it.
50205589 * This really should never happen.
50215590 */
5591
+ (*pos)++;
50225592 ptr = update_eval_map(ptr);
50235593 if (WARN_ON_ONCE(!ptr))
50245594 return NULL;
50255595
50265596 ptr++;
5027
-
5028
- (*pos)++;
5029
-
50305597 ptr = update_eval_map(ptr);
50315598
50325599 return ptr;
....@@ -5075,8 +5642,11 @@
50755642
50765643 static int tracing_eval_map_open(struct inode *inode, struct file *filp)
50775644 {
5078
- if (tracing_disabled)
5079
- return -ENODEV;
5645
+ int ret;
5646
+
5647
+ ret = tracing_check_open_get_tr(NULL);
5648
+ if (ret)
5649
+ return ret;
50805650
50815651 return seq_open(filp, &tracing_eval_map_seq_ops);
50825652 }
....@@ -5189,11 +5759,11 @@
51895759
51905760 int tracer_init(struct tracer *t, struct trace_array *tr)
51915761 {
5192
- tracing_reset_online_cpus(&tr->trace_buffer);
5762
+ tracing_reset_online_cpus(&tr->array_buffer);
51935763 return t->init(tr);
51945764 }
51955765
5196
-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)
51975767 {
51985768 int cpu;
51995769
....@@ -5203,8 +5773,8 @@
52035773
52045774 #ifdef CONFIG_TRACER_MAX_TRACE
52055775 /* resize @tr's buffer to the size of @size_tr's entries */
5206
-static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
5207
- 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)
52085778 {
52095779 int cpu, ret = 0;
52105780
....@@ -5242,10 +5812,10 @@
52425812 ring_buffer_expanded = true;
52435813
52445814 /* May be called before buffers are initialized */
5245
- if (!tr->trace_buffer.buffer)
5815
+ if (!tr->array_buffer.buffer)
52465816 return 0;
52475817
5248
- ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu);
5818
+ ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu);
52495819 if (ret < 0)
52505820 return ret;
52515821
....@@ -5256,8 +5826,8 @@
52565826
52575827 ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu);
52585828 if (ret < 0) {
5259
- int r = resize_buffer_duplicate_size(&tr->trace_buffer,
5260
- &tr->trace_buffer, cpu);
5829
+ int r = resize_buffer_duplicate_size(&tr->array_buffer,
5830
+ &tr->array_buffer, cpu);
52615831 if (r < 0) {
52625832 /*
52635833 * AARGH! We are left with different
....@@ -5288,15 +5858,15 @@
52885858 #endif /* CONFIG_TRACER_MAX_TRACE */
52895859
52905860 if (cpu == RING_BUFFER_ALL_CPUS)
5291
- set_buffer_entries(&tr->trace_buffer, size);
5861
+ set_buffer_entries(&tr->array_buffer, size);
52925862 else
5293
- per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size;
5863
+ per_cpu_ptr(tr->array_buffer.data, cpu)->entries = size;
52945864
52955865 return ret;
52965866 }
52975867
5298
-static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
5299
- unsigned long size, int cpu_id)
5868
+ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
5869
+ unsigned long size, int cpu_id)
53005870 {
53015871 int ret = size;
53025872
....@@ -5366,16 +5936,22 @@
53665936 tr->current_trace = &nop_trace;
53675937 }
53685938
5939
+static bool tracer_options_updated;
5940
+
53695941 static void add_tracer_options(struct trace_array *tr, struct tracer *t)
53705942 {
53715943 /* Only enable if the directory has been created already. */
53725944 if (!tr->dir)
53735945 return;
53745946
5947
+ /* Only create trace option files after update_tracer_options finish */
5948
+ if (!tracer_options_updated)
5949
+ return;
5950
+
53755951 create_trace_option_files(tr, t);
53765952 }
53775953
5378
-static int tracing_set_tracer(struct trace_array *tr, const char *buf)
5954
+int tracing_set_tracer(struct trace_array *tr, const char *buf)
53795955 {
53805956 struct tracer *t;
53815957 #ifdef CONFIG_TRACER_MAX_TRACE
....@@ -5404,6 +5980,18 @@
54045980 if (t == tr->current_trace)
54055981 goto out;
54065982
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
54075995 /* Some tracers won't work on kernel command line */
54085996 if (system_state < SYSTEM_RUNNING && t->noboot) {
54095997 pr_warn("Tracer '%s' is not allowed on command line, ignored\n",
....@@ -5418,7 +6006,7 @@
54186006 }
54196007
54206008 /* If trace pipe files are being read, we can't change the tracer */
5421
- if (tr->current_trace->ref) {
6009
+ if (tr->trace_ref) {
54226010 ret = -EBUSY;
54236011 goto out;
54246012 }
....@@ -5430,11 +6018,11 @@
54306018 if (tr->current_trace->reset)
54316019 tr->current_trace->reset(tr);
54326020
5433
- /* Current trace needs to be nop_trace before synchronize_sched */
5434
- tr->current_trace = &nop_trace;
5435
-
54366021 #ifdef CONFIG_TRACER_MAX_TRACE
5437
- 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;
54386026
54396027 if (had_max_tr && !t->use_max_tr) {
54406028 /*
....@@ -5444,17 +6032,17 @@
54446032 * The update_max_tr is called from interrupts disabled
54456033 * so a synchronized_sched() is sufficient.
54466034 */
5447
- synchronize_sched();
6035
+ synchronize_rcu();
54486036 free_snapshot(tr);
54496037 }
5450
-#endif
54516038
5452
-#ifdef CONFIG_TRACER_MAX_TRACE
5453
- if (t->use_max_tr && !had_max_tr) {
6039
+ if (t->use_max_tr && !tr->allocated_snapshot) {
54546040 ret = tracing_alloc_snapshot_instance(tr);
54556041 if (ret < 0)
54566042 goto out;
54576043 }
6044
+#else
6045
+ tr->current_trace = &nop_trace;
54586046 #endif
54596047
54606048 if (t->init) {
....@@ -5589,13 +6177,11 @@
55896177 {
55906178 struct trace_array *tr = inode->i_private;
55916179 struct trace_iterator *iter;
5592
- int ret = 0;
6180
+ int ret;
55936181
5594
- if (tracing_disabled)
5595
- return -ENODEV;
5596
-
5597
- if (trace_array_get(tr) < 0)
5598
- return -ENODEV;
6182
+ ret = tracing_check_open_get_tr(tr);
6183
+ if (ret)
6184
+ return ret;
55996185
56006186 mutex_lock(&trace_types_lock);
56016187
....@@ -5626,7 +6212,7 @@
56266212 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
56276213
56286214 iter->tr = tr;
5629
- iter->trace_buffer = &tr->trace_buffer;
6215
+ iter->array_buffer = &tr->array_buffer;
56306216 iter->cpu_file = tracing_get_cpu(inode);
56316217 mutex_init(&iter->mutex);
56326218 filp->private_data = iter;
....@@ -5636,7 +6222,7 @@
56366222
56376223 nonseekable_open(inode, filp);
56386224
5639
- tr->current_trace->ref++;
6225
+ tr->trace_ref++;
56406226 out:
56416227 mutex_unlock(&trace_types_lock);
56426228 return ret;
....@@ -5655,7 +6241,7 @@
56556241
56566242 mutex_lock(&trace_types_lock);
56576243
5658
- tr->current_trace->ref--;
6244
+ tr->trace_ref--;
56596245
56606246 if (iter->trace->pipe_close)
56616247 iter->trace->pipe_close(iter);
....@@ -5686,8 +6272,8 @@
56866272 */
56876273 return EPOLLIN | EPOLLRDNORM;
56886274 else
5689
- return ring_buffer_poll_wait(iter->trace_buffer->buffer, iter->cpu_file,
5690
- filp, poll_table);
6275
+ return ring_buffer_poll_wait(iter->array_buffer->buffer, iter->cpu_file,
6276
+ filp, poll_table, iter->tr->buffer_percent);
56916277 }
56926278
56936279 static __poll_t
....@@ -5724,7 +6310,7 @@
57246310
57256311 mutex_unlock(&iter->mutex);
57266312
5727
- ret = wait_on_pipe(iter, false);
6313
+ ret = wait_on_pipe(iter, 0);
57286314
57296315 mutex_lock(&iter->mutex);
57306316
....@@ -5840,14 +6426,6 @@
58406426 __free_page(spd->pages[idx]);
58416427 }
58426428
5843
-static const struct pipe_buf_operations tracing_pipe_buf_ops = {
5844
- .can_merge = 0,
5845
- .confirm = generic_pipe_buf_confirm,
5846
- .release = generic_pipe_buf_release,
5847
- .steal = generic_pipe_buf_steal,
5848
- .get = generic_pipe_buf_get,
5849
-};
5850
-
58516429 static size_t
58526430 tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
58536431 {
....@@ -5909,7 +6487,7 @@
59096487 .partial = partial_def,
59106488 .nr_pages = 0, /* This gets updated below. */
59116489 .nr_pages_max = PIPE_DEF_BUFFERS,
5912
- .ops = &tracing_pipe_buf_ops,
6490
+ .ops = &default_pipe_buf_ops,
59136491 .spd_release = tracing_spd_release_pipe,
59146492 };
59156493 ssize_t ret;
....@@ -6004,8 +6582,8 @@
60046582 for_each_tracing_cpu(cpu) {
60056583 /* fill in the size from first enabled cpu */
60066584 if (size == 0)
6007
- size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries;
6008
- 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) {
60096587 buf_size_same = 0;
60106588 break;
60116589 }
....@@ -6021,7 +6599,7 @@
60216599 } else
60226600 r = sprintf(buf, "X\n");
60236601 } else
6024
- 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);
60256603
60266604 mutex_unlock(&trace_types_lock);
60276605
....@@ -6068,7 +6646,7 @@
60686646
60696647 mutex_lock(&trace_types_lock);
60706648 for_each_tracing_cpu(cpu) {
6071
- size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10;
6649
+ size += per_cpu_ptr(tr->array_buffer.data, cpu)->entries >> 10;
60726650 if (!ring_buffer_expanded)
60736651 expanded_size += trace_buf_size >> 10;
60746652 }
....@@ -6118,16 +6696,15 @@
61186696 struct trace_array *tr = filp->private_data;
61196697 struct ring_buffer_event *event;
61206698 enum event_trigger_type tt = ETT_NONE;
6121
- struct ring_buffer *buffer;
6699
+ struct trace_buffer *buffer;
61226700 struct print_entry *entry;
6123
- unsigned long irq_flags;
6124
- const char faulted[] = "<faulted>";
61256701 ssize_t written;
61266702 int size;
61276703 int len;
61286704
61296705 /* Used in tracing_mark_raw_write() as well */
6130
-#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 */
61316708
61326709 if (tracing_disabled)
61336710 return -EINVAL;
....@@ -6140,16 +6717,15 @@
61406717
61416718 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
61426719
6143
- local_save_flags(irq_flags);
61446720 size = sizeof(*entry) + cnt + 2; /* add '\0' and possible '\n' */
61456721
61466722 /* If less than "<faulted>", then make sure we can still add that */
61476723 if (cnt < FAULTED_SIZE)
61486724 size += FAULTED_SIZE - cnt;
61496725
6150
- buffer = tr->trace_buffer.buffer;
6726
+ buffer = tr->array_buffer.buffer;
61516727 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
6152
- irq_flags, preempt_count());
6728
+ tracing_gen_ctx());
61536729 if (unlikely(!event))
61546730 /* Ring buffer disabled, return as if not open for write */
61556731 return -EBADF;
....@@ -6159,12 +6735,11 @@
61596735
61606736 len = __copy_from_user_inatomic(&entry->buf, ubuf, cnt);
61616737 if (len) {
6162
- memcpy(&entry->buf, faulted, FAULTED_SIZE);
6738
+ memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE);
61636739 cnt = FAULTED_SIZE;
61646740 written = -EFAULT;
61656741 } else
61666742 written = cnt;
6167
- len = cnt;
61686743
61696744 if (tr->trace_marker_file && !list_empty(&tr->trace_marker_file->triggers)) {
61706745 /* do not add \n before testing triggers, but add \0 */
....@@ -6178,6 +6753,8 @@
61786753 } else
61796754 entry->buf[cnt] = '\0';
61806755
6756
+ if (static_branch_unlikely(&trace_marker_exports_enabled))
6757
+ ftrace_exports(event, TRACE_EXPORT_MARKER);
61816758 __buffer_unlock_commit(buffer, event);
61826759
61836760 if (tt)
....@@ -6198,10 +6775,8 @@
61986775 {
61996776 struct trace_array *tr = filp->private_data;
62006777 struct ring_buffer_event *event;
6201
- struct ring_buffer *buffer;
6778
+ struct trace_buffer *buffer;
62026779 struct raw_data_entry *entry;
6203
- const char faulted[] = "<faulted>";
6204
- unsigned long irq_flags;
62056780 ssize_t written;
62066781 int size;
62076782 int len;
....@@ -6223,14 +6798,13 @@
62236798
62246799 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
62256800
6226
- local_save_flags(irq_flags);
62276801 size = sizeof(*entry) + cnt;
62286802 if (cnt < FAULT_SIZE_ID)
62296803 size += FAULT_SIZE_ID - cnt;
62306804
6231
- buffer = tr->trace_buffer.buffer;
6805
+ buffer = tr->array_buffer.buffer;
62326806 event = __trace_buffer_lock_reserve(buffer, TRACE_RAW_DATA, size,
6233
- irq_flags, preempt_count());
6807
+ tracing_gen_ctx());
62346808 if (!event)
62356809 /* Ring buffer disabled, return as if not open for write */
62366810 return -EBADF;
....@@ -6240,7 +6814,7 @@
62406814 len = __copy_from_user_inatomic(&entry->id, ubuf, cnt);
62416815 if (len) {
62426816 entry->id = -1;
6243
- memcpy(&entry->buf, faulted, FAULTED_SIZE);
6817
+ memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE);
62446818 written = -EFAULT;
62456819 } else
62466820 written = cnt;
....@@ -6283,13 +6857,13 @@
62836857
62846858 tr->clock_id = i;
62856859
6286
- 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);
62876861
62886862 /*
62896863 * New clock may not be consistent with the previous clock.
62906864 * Reset the buffer so that it doesn't have incomparable timestamps.
62916865 */
6292
- tracing_reset_online_cpus(&tr->trace_buffer);
6866
+ tracing_reset_online_cpus(&tr->array_buffer);
62936867
62946868 #ifdef CONFIG_TRACER_MAX_TRACE
62956869 if (tr->max_buffer.buffer)
....@@ -6335,11 +6909,9 @@
63356909 struct trace_array *tr = inode->i_private;
63366910 int ret;
63376911
6338
- if (tracing_disabled)
6339
- return -ENODEV;
6340
-
6341
- if (trace_array_get(tr))
6342
- return -ENODEV;
6912
+ ret = tracing_check_open_get_tr(tr);
6913
+ if (ret)
6914
+ return ret;
63436915
63446916 ret = single_open(file, tracing_clock_show, inode->i_private);
63456917 if (ret < 0)
....@@ -6354,7 +6926,7 @@
63546926
63556927 mutex_lock(&trace_types_lock);
63566928
6357
- if (ring_buffer_time_stamp_abs(tr->trace_buffer.buffer))
6929
+ if (ring_buffer_time_stamp_abs(tr->array_buffer.buffer))
63586930 seq_puts(m, "delta [absolute]\n");
63596931 else
63606932 seq_puts(m, "[delta] absolute\n");
....@@ -6369,11 +6941,9 @@
63696941 struct trace_array *tr = inode->i_private;
63706942 int ret;
63716943
6372
- if (tracing_disabled)
6373
- return -ENODEV;
6374
-
6375
- if (trace_array_get(tr))
6376
- return -ENODEV;
6944
+ ret = tracing_check_open_get_tr(tr);
6945
+ if (ret)
6946
+ return ret;
63776947
63786948 ret = single_open(file, tracing_time_stamp_mode_show, inode->i_private);
63796949 if (ret < 0)
....@@ -6401,7 +6971,7 @@
64016971 goto out;
64026972 }
64036973
6404
- ring_buffer_set_time_stamp_abs(tr->trace_buffer.buffer, abs);
6974
+ ring_buffer_set_time_stamp_abs(tr->array_buffer.buffer, abs);
64056975
64066976 #ifdef CONFIG_TRACER_MAX_TRACE
64076977 if (tr->max_buffer.buffer)
....@@ -6426,10 +6996,11 @@
64266996 struct trace_array *tr = inode->i_private;
64276997 struct trace_iterator *iter;
64286998 struct seq_file *m;
6429
- int ret = 0;
6999
+ int ret;
64307000
6431
- if (trace_array_get(tr) < 0)
6432
- return -ENODEV;
7001
+ ret = tracing_check_open_get_tr(tr);
7002
+ if (ret)
7003
+ return ret;
64337004
64347005 if (file->f_mode & FMODE_READ) {
64357006 iter = __tracing_open(inode, file, true);
....@@ -6449,7 +7020,7 @@
64497020 ret = 0;
64507021
64517022 iter->tr = tr;
6452
- iter->trace_buffer = &tr->max_buffer;
7023
+ iter->array_buffer = &tr->max_buffer;
64537024 iter->cpu_file = tracing_get_cpu(inode);
64547025 m->private = iter;
64557026 file->private_data = m;
....@@ -6486,6 +7057,15 @@
64867057 goto out;
64877058 }
64887059
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
+
64897069 switch (val) {
64907070 case 0:
64917071 if (iter->cpu_file != RING_BUFFER_ALL_CPUS) {
....@@ -6505,7 +7085,7 @@
65057085 #endif
65067086 if (tr->allocated_snapshot)
65077087 ret = resize_buffer_duplicate_size(&tr->max_buffer,
6508
- &tr->trace_buffer, iter->cpu_file);
7088
+ &tr->array_buffer, iter->cpu_file);
65097089 else
65107090 ret = tracing_alloc_snapshot_instance(tr);
65117091 if (ret < 0)
....@@ -6513,7 +7093,7 @@
65137093 local_irq_disable();
65147094 /* Now, we're going to swap */
65157095 if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
6516
- update_max_tr(tr, current, smp_processor_id());
7096
+ update_max_tr(tr, current, smp_processor_id(), NULL);
65177097 else
65187098 update_max_tr_single(tr, current, iter->cpu_file);
65197099 local_irq_enable();
....@@ -6523,7 +7103,7 @@
65237103 if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
65247104 tracing_reset_online_cpus(&tr->max_buffer);
65257105 else
6526
- tracing_reset(&tr->max_buffer, iter->cpu_file);
7106
+ tracing_reset_cpu(&tr->max_buffer, iter->cpu_file);
65277107 }
65287108 break;
65297109 }
....@@ -6567,6 +7147,7 @@
65677147 struct ftrace_buffer_info *info;
65687148 int ret;
65697149
7150
+ /* The following checks for tracefs lockdown */
65707151 ret = tracing_buffers_open(inode, filp);
65717152 if (ret < 0)
65727153 return ret;
....@@ -6579,7 +7160,7 @@
65797160 }
65807161
65817162 info->iter.snapshot = true;
6582
- info->iter.trace_buffer = &info->iter.tr->max_buffer;
7163
+ info->iter.array_buffer = &info->iter.tr->max_buffer;
65837164
65847165 return ret;
65857166 }
....@@ -6688,19 +7269,263 @@
66887269
66897270 #endif /* CONFIG_TRACER_SNAPSHOT */
66907271
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
+
66917518 static int tracing_buffers_open(struct inode *inode, struct file *filp)
66927519 {
66937520 struct trace_array *tr = inode->i_private;
66947521 struct ftrace_buffer_info *info;
66957522 int ret;
66967523
6697
- if (tracing_disabled)
6698
- return -ENODEV;
7524
+ ret = tracing_check_open_get_tr(tr);
7525
+ if (ret)
7526
+ return ret;
66997527
6700
- if (trace_array_get(tr) < 0)
6701
- return -ENODEV;
6702
-
6703
- info = kzalloc(sizeof(*info), GFP_KERNEL);
7528
+ info = kvzalloc(sizeof(*info), GFP_KERNEL);
67047529 if (!info) {
67057530 trace_array_put(tr);
67067531 return -ENOMEM;
....@@ -6711,14 +7536,14 @@
67117536 info->iter.tr = tr;
67127537 info->iter.cpu_file = tracing_get_cpu(inode);
67137538 info->iter.trace = tr->current_trace;
6714
- info->iter.trace_buffer = &tr->trace_buffer;
7539
+ info->iter.array_buffer = &tr->array_buffer;
67157540 info->spare = NULL;
67167541 /* Force reading ring buffer for first read */
67177542 info->read = (unsigned int)-1;
67187543
67197544 filp->private_data = info;
67207545
6721
- tr->current_trace->ref++;
7546
+ tr->trace_ref++;
67227547
67237548 mutex_unlock(&trace_types_lock);
67247549
....@@ -6756,7 +7581,7 @@
67567581 #endif
67577582
67587583 if (!info->spare) {
6759
- info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer,
7584
+ info->spare = ring_buffer_alloc_read_page(iter->array_buffer->buffer,
67607585 iter->cpu_file);
67617586 if (IS_ERR(info->spare)) {
67627587 ret = PTR_ERR(info->spare);
....@@ -6774,7 +7599,7 @@
67747599
67757600 again:
67767601 trace_access_lock(iter->cpu_file);
6777
- ret = ring_buffer_read_page(iter->trace_buffer->buffer,
7602
+ ret = ring_buffer_read_page(iter->array_buffer->buffer,
67787603 &info->spare,
67797604 count,
67807605 iter->cpu_file, 0);
....@@ -6785,7 +7610,7 @@
67857610 if ((filp->f_flags & O_NONBLOCK))
67867611 return -EAGAIN;
67877612
6788
- ret = wait_on_pipe(iter, false);
7613
+ ret = wait_on_pipe(iter, 0);
67897614 if (ret)
67907615 return ret;
67917616
....@@ -6819,14 +7644,14 @@
68197644
68207645 mutex_lock(&trace_types_lock);
68217646
6822
- iter->tr->current_trace->ref--;
7647
+ iter->tr->trace_ref--;
68237648
68247649 __trace_array_put(iter->tr);
68257650
68267651 if (info->spare)
6827
- ring_buffer_free_read_page(iter->trace_buffer->buffer,
7652
+ ring_buffer_free_read_page(iter->array_buffer->buffer,
68287653 info->spare_cpu, info->spare);
6829
- kfree(info);
7654
+ kvfree(info);
68307655
68317656 mutex_unlock(&trace_types_lock);
68327657
....@@ -6834,7 +7659,7 @@
68347659 }
68357660
68367661 struct buffer_ref {
6837
- struct ring_buffer *buffer;
7662
+ struct trace_buffer *buffer;
68387663 void *page;
68397664 int cpu;
68407665 refcount_t refcount;
....@@ -6871,10 +7696,7 @@
68717696
68727697 /* Pipe buffer operations for a buffer. */
68737698 static const struct pipe_buf_operations buffer_pipe_buf_ops = {
6874
- .can_merge = 0,
6875
- .confirm = generic_pipe_buf_confirm,
68767699 .release = buffer_pipe_buf_release,
6877
- .steal = generic_pipe_buf_nosteal,
68787700 .get = buffer_pipe_buf_get,
68797701 };
68807702
....@@ -6930,7 +7752,7 @@
69307752
69317753 again:
69327754 trace_access_lock(iter->cpu_file);
6933
- 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);
69347756
69357757 for (i = 0; i < spd.nr_pages_max && len && entries; i++, len -= PAGE_SIZE) {
69367758 struct page *page;
....@@ -6943,7 +7765,7 @@
69437765 }
69447766
69457767 refcount_set(&ref->refcount, 1);
6946
- ref->buffer = iter->trace_buffer->buffer;
7768
+ ref->buffer = iter->array_buffer->buffer;
69477769 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file);
69487770 if (IS_ERR(ref->page)) {
69497771 ret = PTR_ERR(ref->page);
....@@ -6971,7 +7793,7 @@
69717793 spd.nr_pages++;
69727794 *ppos += PAGE_SIZE;
69737795
6974
- 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);
69757797 }
69767798
69777799 trace_access_unlock(iter->cpu_file);
....@@ -6986,7 +7808,7 @@
69867808 if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
69877809 goto out;
69887810
6989
- ret = wait_on_pipe(iter, true);
7811
+ ret = wait_on_pipe(iter, iter->tr->buffer_percent);
69907812 if (ret)
69917813 goto out;
69927814
....@@ -7015,7 +7837,7 @@
70157837 {
70167838 struct inode *inode = file_inode(filp);
70177839 struct trace_array *tr = inode->i_private;
7018
- struct trace_buffer *trace_buf = &tr->trace_buffer;
7840
+ struct array_buffer *trace_buf = &tr->array_buffer;
70197841 int cpu = tracing_get_cpu(inode);
70207842 struct trace_seq *s;
70217843 unsigned long cnt;
....@@ -7086,14 +7908,23 @@
70867908 tracing_read_dyn_info(struct file *filp, char __user *ubuf,
70877909 size_t cnt, loff_t *ppos)
70887910 {
7089
- unsigned long *p = filp->private_data;
7090
- char buf[64]; /* Not too big for a shallow stack */
7911
+ ssize_t ret;
7912
+ char *buf;
70917913 int r;
70927914
7093
- r = scnprintf(buf, 63, "%ld", *p);
7094
- 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;
70957919
7096
- 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;
70977928 }
70987929
70997930 static const struct file_operations tracing_dyn_info_fops = {
....@@ -7287,7 +8118,7 @@
72878118
72888119 tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer);
72898120
7290
- WARN_ONCE(!tr->percpu_dir,
8121
+ MEM_FAIL(!tr->percpu_dir,
72918122 "Could not create tracefs directory 'per_cpu/%d'\n", cpu);
72928123
72938124 return tr->percpu_dir;
....@@ -7608,7 +8439,7 @@
76088439 for (cnt = 0; opts[cnt].name; cnt++) {
76098440 create_trace_option_file(tr, &topts[cnt], flags,
76108441 &opts[cnt]);
7611
- WARN_ONCE(topts[cnt].entry == NULL,
8442
+ MEM_FAIL(topts[cnt].entry == NULL,
76128443 "Failed to create trace option: %s",
76138444 opts[cnt].name);
76148445 }
....@@ -7665,7 +8496,7 @@
76658496 size_t cnt, loff_t *ppos)
76668497 {
76678498 struct trace_array *tr = filp->private_data;
7668
- struct ring_buffer *buffer = tr->trace_buffer.buffer;
8499
+ struct trace_buffer *buffer = tr->array_buffer.buffer;
76698500 unsigned long val;
76708501 int ret;
76718502
....@@ -7702,13 +8533,60 @@
77028533 .llseek = default_llseek,
77038534 };
77048535
7705
-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;
77068584
77078585 static void
77088586 init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);
77098587
77108588 static int
7711
-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)
77128590 {
77138591 enum ring_buffer_flags rb_flags;
77148592
....@@ -7728,8 +8606,8 @@
77288606 }
77298607
77308608 /* Allocate the first page for all buffers */
7731
- set_buffer_entries(&tr->trace_buffer,
7732
- ring_buffer_size(tr->trace_buffer.buffer, 0));
8609
+ set_buffer_entries(&tr->array_buffer,
8610
+ ring_buffer_size(tr->array_buffer.buffer, 0));
77338611
77348612 return 0;
77358613 }
....@@ -7738,18 +8616,18 @@
77388616 {
77398617 int ret;
77408618
7741
- ret = allocate_trace_buffer(tr, &tr->trace_buffer, size);
8619
+ ret = allocate_trace_buffer(tr, &tr->array_buffer, size);
77428620 if (ret)
77438621 return ret;
77448622
77458623 #ifdef CONFIG_TRACER_MAX_TRACE
77468624 ret = allocate_trace_buffer(tr, &tr->max_buffer,
77478625 allocate_snapshot ? size : 1);
7748
- if (WARN_ON(ret)) {
7749
- ring_buffer_free(tr->trace_buffer.buffer);
7750
- tr->trace_buffer.buffer = NULL;
7751
- free_percpu(tr->trace_buffer.data);
7752
- 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;
77538631 return -ENOMEM;
77548632 }
77558633 tr->allocated_snapshot = allocate_snapshot;
....@@ -7761,22 +8639,10 @@
77618639 allocate_snapshot = false;
77628640 #endif
77638641
7764
- /*
7765
- * Because of some magic with the way alloc_percpu() works on
7766
- * x86_64, we need to synchronize the pgd of all the tables,
7767
- * otherwise the trace events that happen in x86_64 page fault
7768
- * handlers can't cope with accessing the chance that a
7769
- * alloc_percpu()'d memory might be touched in the page fault trace
7770
- * event. Oh, and we need to audit all other alloc_percpu() and vmalloc()
7771
- * calls in tracing, because something might get triggered within a
7772
- * page fault trace event!
7773
- */
7774
- vmalloc_sync_mappings();
7775
-
77768642 return 0;
77778643 }
77788644
7779
-static void free_trace_buffer(struct trace_buffer *buf)
8645
+static void free_trace_buffer(struct array_buffer *buf)
77808646 {
77818647 if (buf->buffer) {
77828648 ring_buffer_free(buf->buffer);
....@@ -7791,7 +8657,7 @@
77918657 if (!tr)
77928658 return;
77938659
7794
- free_trace_buffer(&tr->trace_buffer);
8660
+ free_trace_buffer(&tr->array_buffer);
77958661
77968662 #ifdef CONFIG_TRACER_MAX_TRACE
77978663 free_trace_buffer(&tr->max_buffer);
....@@ -7818,28 +8684,68 @@
78188684 static void update_tracer_options(struct trace_array *tr)
78198685 {
78208686 mutex_lock(&trace_types_lock);
8687
+ tracer_options_updated = true;
78218688 __update_tracer_options(tr);
78228689 mutex_unlock(&trace_types_lock);
78238690 }
78248691
7825
-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)
78268741 {
78278742 struct trace_array *tr;
78288743 int ret;
78298744
7830
- mutex_lock(&event_mutex);
7831
- mutex_lock(&trace_types_lock);
7832
-
7833
- ret = -EEXIST;
7834
- list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7835
- if (tr->name && strcmp(tr->name, name) == 0)
7836
- goto out_unlock;
7837
- }
7838
-
78398745 ret = -ENOMEM;
78408746 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
78418747 if (!tr)
7842
- goto out_unlock;
8748
+ return ERR_PTR(ret);
78438749
78448750 tr->name = kstrdup(name, GFP_KERNEL);
78458751 if (!tr->name)
....@@ -7861,70 +8767,112 @@
78618767 INIT_LIST_HEAD(&tr->systems);
78628768 INIT_LIST_HEAD(&tr->events);
78638769 INIT_LIST_HEAD(&tr->hist_vars);
8770
+ INIT_LIST_HEAD(&tr->err_log);
78648771
78658772 if (allocate_trace_buffers(tr, trace_buf_size) < 0)
78668773 goto out_free_tr;
78678774
7868
- tr->dir = tracefs_create_dir(name, trace_instance_dir);
7869
- if (!tr->dir)
8775
+ if (ftrace_allocate_ftrace_ops(tr) < 0)
78708776 goto out_free_tr;
7871
-
7872
- ret = event_trace_add_tracer(tr->dir, tr);
7873
- if (ret) {
7874
- tracefs_remove_recursive(tr->dir);
7875
- goto out_free_tr;
7876
- }
78778777
78788778 ftrace_init_trace_array(tr);
78798779
7880
- init_tracer_tracefs(tr, tr->dir);
78818780 init_trace_flags_index(tr);
7882
- __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);
78838788
78848789 list_add(&tr->list, &ftrace_trace_arrays);
78858790
7886
- mutex_unlock(&trace_types_lock);
7887
- mutex_unlock(&event_mutex);
8791
+ tr->ref++;
78888792
7889
- return 0;
8793
+ return tr;
78908794
78918795 out_free_tr:
8796
+ ftrace_free_ftrace_ops(tr);
78928797 free_trace_buffers(tr);
78938798 free_cpumask_var(tr->tracing_cpumask);
78948799 kfree(tr->name);
78958800 kfree(tr);
78968801
7897
- out_unlock:
7898
- mutex_unlock(&trace_types_lock);
7899
- mutex_unlock(&event_mutex);
7900
-
7901
- return ret;
7902
-
8802
+ return ERR_PTR(ret);
79038803 }
79048804
7905
-static int instance_rmdir(const char *name)
8805
+static int instance_mkdir(const char *name)
79068806 {
79078807 struct trace_array *tr;
7908
- int found = 0;
79098808 int ret;
7910
- int i;
79118809
79128810 mutex_lock(&event_mutex);
79138811 mutex_lock(&trace_types_lock);
79148812
7915
- ret = -ENODEV;
7916
- list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7917
- if (tr->name && strcmp(tr->name, name) == 0) {
7918
- found = 1;
7919
- break;
7920
- }
7921
- }
7922
- if (!found)
8813
+ ret = -EEXIST;
8814
+ if (trace_array_find(name))
79238815 goto out_unlock;
79248816
7925
- ret = -EBUSY;
7926
- if (tr->ref || (tr->current_trace && tr->current_trace->ref))
7927
- 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;
79288876
79298877 list_del(&tr->list);
79308878
....@@ -7939,7 +8887,7 @@
79398887 event_trace_del_tracer(tr);
79408888 ftrace_clear_pids(tr);
79418889 ftrace_destroy_function_files(tr);
7942
- tracefs_remove_recursive(tr->dir);
8890
+ tracefs_remove(tr->dir);
79438891 free_trace_buffers(tr);
79448892
79458893 for (i = 0; i < tr->nr_topts; i++) {
....@@ -7951,9 +8899,50 @@
79518899 kfree(tr->name);
79528900 kfree(tr);
79538901
7954
- ret = 0;
8902
+ return 0;
8903
+}
79558904
7956
- 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
+
79578946 mutex_unlock(&trace_types_lock);
79588947 mutex_unlock(&event_mutex);
79598948
....@@ -7962,11 +8951,27 @@
79628951
79638952 static __init void create_trace_instances(struct dentry *d_tracer)
79648953 {
8954
+ struct trace_array *tr;
8955
+
79658956 trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer,
79668957 instance_mkdir,
79678958 instance_rmdir);
7968
- if (WARN_ON(!trace_instance_dir))
8959
+ if (MEM_FAIL(!trace_instance_dir, "Failed to create instances directory\n"))
79698960 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);
79708975 }
79718976
79728977 static void
....@@ -8023,20 +9028,27 @@
80239028 trace_create_file("timestamp_mode", 0444, d_tracer, tr,
80249029 &trace_time_stamp_mode_fops);
80259030
9031
+ tr->buffer_percent = 50;
9032
+
9033
+ trace_create_file("buffer_percent", 0444, d_tracer,
9034
+ tr, &buffer_percent_fops);
9035
+
80269036 create_trace_options_dir(tr);
80279037
80289038 #if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
8029
- trace_create_file("tracing_max_latency", 0644, d_tracer,
8030
- &tr->max_latency, &tracing_max_lat_fops);
9039
+ trace_create_maxlat_file(tr, d_tracer);
80319040 #endif
80329041
80339042 if (ftrace_create_function_files(tr, d_tracer))
8034
- WARN(1, "Could not allocate function filter files");
9043
+ MEM_FAIL(1, "Could not allocate function filter files");
80359044
80369045 #ifdef CONFIG_TRACER_SNAPSHOT
80379046 trace_create_file("snapshot", 0644, d_tracer,
80389047 tr, &snapshot_fops);
80399048 #endif
9049
+
9050
+ trace_create_file("error_log", 0644, d_tracer,
9051
+ tr, &tracing_err_log_fops);
80409052
80419053 for_each_tracing_cpu(cpu)
80429054 tracing_init_tracefs_percpu(tr, cpu);
....@@ -8044,6 +9056,7 @@
80449056 ftrace_init_tracefs(tr, d_tracer);
80459057 }
80469058
9059
+#ifndef CONFIG_TRACEFS_DISABLE_AUTOMOUNT
80479060 static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)
80489061 {
80499062 struct vfsmount *mnt;
....@@ -8065,6 +9078,7 @@
80659078
80669079 return mnt;
80679080 }
9081
+#endif
80689082
80699083 /**
80709084 * tracing_init_dentry - initialize top level trace array
....@@ -8073,19 +9087,23 @@
80739087 * directory. It is called via fs_initcall() by any of the boot up code
80749088 * and expects to return the dentry of the top level tracing directory.
80759089 */
8076
-struct dentry *tracing_init_dentry(void)
9090
+int tracing_init_dentry(void)
80779091 {
80789092 struct trace_array *tr = &global_trace;
80799093
9094
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
9095
+ pr_warn("Tracing disabled due to lockdown\n");
9096
+ return -EPERM;
9097
+ }
9098
+
80809099 /* The top level trace array uses NULL as parent */
80819100 if (tr->dir)
8082
- return NULL;
9101
+ return 0;
80839102
8084
- if (WARN_ON(!tracefs_initialized()) ||
8085
- (IS_ENABLED(CONFIG_DEBUG_FS) &&
8086
- WARN_ON(!debugfs_initialized())))
8087
- return ERR_PTR(-ENODEV);
9103
+ if (WARN_ON(!tracefs_initialized()))
9104
+ return -ENODEV;
80889105
9106
+#ifndef CONFIG_TRACEFS_DISABLE_AUTOMOUNT
80899107 /*
80909108 * As there may still be users that expect the tracing
80919109 * files to exist in debugfs/tracing, we must automount
....@@ -8094,12 +9112,11 @@
80949112 */
80959113 tr->dir = debugfs_create_automount("tracing", NULL,
80969114 trace_automount, NULL);
8097
- if (!tr->dir) {
8098
- pr_warn_once("Could not create debugfs directory 'tracing'\n");
8099
- return ERR_PTR(-ENOMEM);
8100
- }
9115
+#else
9116
+ tr->dir = ERR_PTR(-ENODEV);
9117
+#endif
81019118
8102
- return NULL;
9119
+ return 0;
81039120 }
81049121
81059122 extern struct trace_eval_map *__start_ftrace_eval_maps[];
....@@ -8175,7 +9192,7 @@
81759192 break;
81769193 }
81779194
8178
- return 0;
9195
+ return NOTIFY_OK;
81799196 }
81809197
81819198 static struct notifier_block trace_module_nb = {
....@@ -8186,48 +9203,48 @@
81869203
81879204 static __init int tracer_init_tracefs(void)
81889205 {
8189
- struct dentry *d_tracer;
9206
+ int ret;
81909207
81919208 trace_access_lock_init();
81929209
8193
- d_tracer = tracing_init_dentry();
8194
- if (IS_ERR(d_tracer))
9210
+ ret = tracing_init_dentry();
9211
+ if (ret)
81959212 return 0;
81969213
81979214 event_trace_init();
81989215
8199
- init_tracer_tracefs(&global_trace, d_tracer);
8200
- ftrace_init_tracefs_toplevel(&global_trace, d_tracer);
9216
+ init_tracer_tracefs(&global_trace, NULL);
9217
+ ftrace_init_tracefs_toplevel(&global_trace, NULL);
82019218
8202
- trace_create_file("tracing_thresh", 0644, d_tracer,
9219
+ trace_create_file("tracing_thresh", 0644, NULL,
82039220 &global_trace, &tracing_thresh_fops);
82049221
8205
- trace_create_file("README", 0444, d_tracer,
9222
+ trace_create_file("README", 0444, NULL,
82069223 NULL, &tracing_readme_fops);
82079224
8208
- trace_create_file("saved_cmdlines", 0444, d_tracer,
9225
+ trace_create_file("saved_cmdlines", 0444, NULL,
82099226 NULL, &tracing_saved_cmdlines_fops);
82109227
8211
- trace_create_file("saved_cmdlines_size", 0644, d_tracer,
9228
+ trace_create_file("saved_cmdlines_size", 0644, NULL,
82129229 NULL, &tracing_saved_cmdlines_size_fops);
82139230
8214
- trace_create_file("saved_tgids", 0444, d_tracer,
9231
+ trace_create_file("saved_tgids", 0444, NULL,
82159232 NULL, &tracing_saved_tgids_fops);
82169233
82179234 trace_eval_init();
82189235
8219
- trace_create_eval_file(d_tracer);
9236
+ trace_create_eval_file(NULL);
82209237
82219238 #ifdef CONFIG_MODULES
82229239 register_module_notifier(&trace_module_nb);
82239240 #endif
82249241
82259242 #ifdef CONFIG_DYNAMIC_FTRACE
8226
- trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
8227
- &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
9243
+ trace_create_file("dyn_ftrace_total_info", 0444, NULL,
9244
+ NULL, &tracing_dyn_info_fops);
82289245 #endif
82299246
8230
- create_trace_instances(d_tracer);
9247
+ create_trace_instances(NULL);
82319248
82329249 update_tracer_options(&global_trace);
82339250
....@@ -8237,8 +9254,17 @@
82379254 static int trace_panic_handler(struct notifier_block *this,
82389255 unsigned long event, void *unused)
82399256 {
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
+
82409264 if (ftrace_dump_on_oops)
82419265 ftrace_dump(ftrace_dump_on_oops);
9266
+
9267
+ trace_android_vh_ftrace_oops_exit(&ftrace_check);
82429268 return NOTIFY_OK;
82439269 }
82449270
....@@ -8252,6 +9278,13 @@
82529278 unsigned long val,
82539279 void *data)
82549280 {
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
+
82559288 switch (val) {
82569289 case DIE_OOPS:
82579290 if (ftrace_dump_on_oops)
....@@ -8260,6 +9293,8 @@
82609293 default:
82619294 break;
82629295 }
9296
+
9297
+ trace_android_vh_ftrace_oops_exit(&ftrace_check);
82639298 return NOTIFY_OK;
82649299 }
82659300
....@@ -8284,6 +9319,8 @@
82849319 void
82859320 trace_printk_seq(struct trace_seq *s)
82869321 {
9322
+ bool dump_printk = true;
9323
+
82879324 /* Probably should print a warning here. */
82889325 if (s->seq.len >= TRACE_MAX_PRINT)
82899326 s->seq.len = TRACE_MAX_PRINT;
....@@ -8299,7 +9336,9 @@
82999336 /* should be zero ended, but we are paranoid. */
83009337 s->buffer[s->seq.len] = 0;
83019338
8302
- 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);
83039342
83049343 trace_seq_init(s);
83059344 }
....@@ -8309,13 +9348,13 @@
83099348 iter->tr = &global_trace;
83109349 iter->trace = iter->tr->current_trace;
83119350 iter->cpu_file = RING_BUFFER_ALL_CPUS;
8312
- iter->trace_buffer = &global_trace.trace_buffer;
9351
+ iter->array_buffer = &global_trace.array_buffer;
83139352
83149353 if (iter->trace && iter->trace->open)
83159354 iter->trace->open(iter);
83169355
83179356 /* Annotate start of buffers if we had overruns */
8318
- if (ring_buffer_overruns(iter->trace_buffer->buffer))
9357
+ if (ring_buffer_overruns(iter->array_buffer->buffer))
83199358 iter->iter_flags |= TRACE_FILE_ANNOTATE;
83209359
83219360 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
....@@ -8332,6 +9371,8 @@
83329371 unsigned int old_userobj;
83339372 unsigned long flags;
83349373 int cnt = 0, cpu;
9374
+ bool ftrace_check = false;
9375
+ unsigned long size;
83359376
83369377 /* Only allow one dump user at a time. */
83379378 if (atomic_inc_return(&dump_running) != 1) {
....@@ -8350,19 +9391,26 @@
83509391 tracing_off();
83519392
83529393 local_irq_save(flags);
8353
- printk_nmi_direct_enter();
83549394
83559395 /* Simulate the iterator */
83569396 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;
83579400
83589401 for_each_tracing_cpu(cpu) {
8359
- 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);
83609405 }
83619406
83629407 old_userobj = tr->trace_flags & TRACE_ITER_SYM_USEROBJ;
83639408
83649409 /* don't look at user memory in panic mode */
83659410 tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
9411
+
9412
+ if (ftrace_check)
9413
+ goto out_enable;
83669414
83679415 switch (oops_dump_mode) {
83689416 case DUMP_ALL:
....@@ -8387,13 +9435,14 @@
83879435 }
83889436
83899437 /*
8390
- * We need to stop all tracing on all CPUS to read the
9438
+ * We need to stop all tracing on all CPUS to read
83919439 * the next buffer. This is a bit expensive, but is
83929440 * not done often. We fill all what we can read,
83939441 * and then release the locks again.
83949442 */
83959443
83969444 while (!trace_empty(&iter)) {
9445
+ ftrace_check = true;
83979446
83989447 if (!cnt)
83999448 printk(KERN_TRACE "---------------------------------\n");
....@@ -8401,7 +9450,9 @@
84019450 cnt++;
84029451
84039452 trace_iterator_reset(&iter);
8404
- 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;
84059456
84069457 if (trace_find_next_entry_inc(&iter) != NULL) {
84079458 int ret;
....@@ -8424,10 +9475,9 @@
84249475 tr->trace_flags |= old_userobj;
84259476
84269477 for_each_tracing_cpu(cpu) {
8427
- atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled);
9478
+ atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled);
84289479 }
84299480 atomic_dec(&dump_running);
8430
- printk_nmi_direct_exit();
84319481 local_irq_restore(flags);
84329482 }
84339483 EXPORT_SYMBOL_GPL(ftrace_dump);
....@@ -8523,8 +9573,14 @@
85239573 int ring_buf_size;
85249574 int ret = -ENOMEM;
85259575
9576
+
9577
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
9578
+ pr_warn("Tracing disabled due to lockdown\n");
9579
+ return -EPERM;
9580
+ }
9581
+
85269582 /*
8527
- * Make sure we don't accidently add more trace options
9583
+ * Make sure we don't accidentally add more trace options
85289584 * than we have bits for.
85299585 */
85309586 BUILD_BUG_ON(TRACE_ITER_LAST_BIT > TRACE_FLAGS_MAX_SIZE);
....@@ -8553,7 +9609,7 @@
85539609
85549610 /*
85559611 * The prepare callbacks allocates some memory for the ring buffer. We
8556
- * 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
85579613 * the buffer, then the user would lose any trace that was in the
85589614 * buffer. The memory will be removed once the "instance" is removed.
85599615 */
....@@ -8573,8 +9629,7 @@
85739629
85749630 /* TODO: make the number of buffers hot pluggable with CPUS */
85759631 if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) {
8576
- printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
8577
- WARN_ON(1);
9632
+ MEM_FAIL(1, "tracer: failed to allocate ring buffer!\n");
85789633 goto out_free_savedcmd;
85799634 }
85809635
....@@ -8619,6 +9674,7 @@
86199674 INIT_LIST_HEAD(&global_trace.systems);
86209675 INIT_LIST_HEAD(&global_trace.events);
86219676 INIT_LIST_HEAD(&global_trace.hist_vars);
9677
+ INIT_LIST_HEAD(&global_trace.err_log);
86229678 list_add(&global_trace.list, &ftrace_trace_arrays);
86239679
86249680 apply_trace_boot_options();
....@@ -8646,7 +9702,8 @@
86469702 if (tracepoint_printk) {
86479703 tracepoint_print_iter =
86489704 kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
8649
- if (WARN_ON(!tracepoint_print_iter))
9705
+ if (MEM_FAIL(!tracepoint_print_iter,
9706
+ "Failed to allocate trace iterator\n"))
86509707 tracepoint_printk = 0;
86519708 else
86529709 static_key_enable(&tracepoint_printk_key.key);
....@@ -8686,6 +9743,11 @@
86869743 {
86879744 /* sched_clock_stable() is determined in late_initcall */
86889745 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
+
86899751 printk(KERN_WARNING
86909752 "Unstable clock detected, switching default tracing clock to \"global\"\n"
86919753 "If you want to keep using the local clock, then add:\n"