History

Merge tag 'trace-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace

Pull tracing updates from Steven Rostedt: "The majority of the changes are for fixes and clean ups. Notable changes: - Rework trace event triggers code to be easier to interact with. - Support for embedding bootconfig with the kernel (as suppose to having it embedded in initram). This is useful for embedded boards without initram disks. - Speed up boot by parallelizing the creation of tracefs files. - Allow absolute ring buffer timestamps handle timestamps that use more than 59 bits. - Added new tracing clock "TAI" (International Atomic Time) - Have weak functions show up in available_filter_function list as: __ftrace_invalid_address___<invalid-offset> instead of using the name of the function before it" * tag 'trace-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (52 commits) ftrace: Add FTRACE_MCOUNT_MAX_OFFSET to avoid adding weak function tracing: Fix comments for event_trigger_separate_filter() x86/traceponit: Fix comment about irq vector tracepoints x86,tracing: Remove unused headers ftrace: Clean up hash direct_functions on register failures tracing: Fix comments of create_filter() tracing: Disable kcov on trace_preemptirq.c tracing: Initialize integer variable to prevent garbage return value ftrace: Fix typo in comment ftrace: Remove return value of ftrace_arch_modify_*() tracing: Cleanup code by removing init "char *name" tracing: Change "char *" string form to "char []" tracing/timerlat: Do not wakeup the thread if the trace stops at the IRQ tracing/timerlat: Print stacktrace in the IRQ handler if needed tracing/timerlat: Notify IRQ new max latency only if stop tracing is set kprobes: Fix build errors with CONFIG_KRETPROBES=n tracing: Fix return value of trace_pid_write() tracing: Fix potential double free in create_var_ref() tracing: Use strim() to remove whitespace instead of doing it manually ftrace: Deal with error return code of the ftrace_process_locs() function ...

Linus Torvalds committed 4 years ago

Commit 76bfd3d2 parents 09f73a1 b39181f40 files · +822 −646Browse files

Unified · Split

40 files
  1. Documentation/admin-guide/bootconfig.rst +28 −3
  2. Documentation/trace/ftrace.rst +12 −0
  3. Documentation/trace/timerlat-tracer.rst +3 −2
  4. MAINTAINERS +3 −2
  5. arch/arm/kernel/ftrace.c +2 −4
  6. arch/riscv/kernel/ftrace.c +2 −4
  7. arch/s390/kernel/ftrace.c +1 −2
  8. arch/x86/include/asm/ftrace.h +7 −0
  9. arch/x86/kernel/ftrace.c +2 −4
  10. arch/x86/kernel/tracepoint.c +0 −6
  11. include/linux/bootconfig.h +10 −0
  12. include/linux/ftrace.h +2 −2
  13. include/linux/kprobes.h +1 −1
  14. init/Kconfig +20 −1
  15. init/main.c +19 −19
  16. kernel/kprobes.c +71 −73
  17. kernel/trace/Makefile +4 −0
  18. kernel/trace/ftrace.c +174 −36
  19. kernel/trace/pid_list.c +2 −2
  20. kernel/trace/ring_buffer.c +64 −17
  21. kernel/trace/trace.c +45 −27
  22. kernel/trace/trace.h +11 −15
  23. kernel/trace/trace_boot.c +1 −1
  24. kernel/trace/trace_dynevent.c +2 −7
  25. kernel/trace/trace_eprobe.c +12 −12
  26. kernel/trace/trace_events.c +30 −39
  27. kernel/trace/trace_events_filter.c +1 −1
  28. kernel/trace/trace_events_hist.c +99 −92
  29. kernel/trace/trace_events_trigger.c +108 −216
  30. kernel/trace/trace_kprobe.c +4 −11
  31. kernel/trace/trace_osnoise.c +19 −3
  32. kernel/trace/trace_output.c +12 −13
  33. kernel/trace/trace_recursion_record.c +2 −5
  34. kernel/trace/trace_selftest.c +3 −0
  35. kernel/trace/trace_syscalls.c +11 −24
  36. kernel/trace/tracing_map.c +2 −1
  37. lib/.gitignore +1 −0
  38. lib/Makefile +9 −1
  39. lib/bootconfig-data.S +10 −0
  40. lib/bootconfig.c +13 −0
Documentation/admin-guide/bootconfig.rst+28−3
@@ -158,9 +158,15 @@ Each key-value pair is shown in each line with following style:: · 157 unmodified lines
158158 Boot Kernel With a Boot Config
159159 ==============================
160160
161−Since the boot configuration file is loaded with initrd, it will be added
162−to the end of the initrd (initramfs) image file with padding, size,
163−checksum and 12-byte magic word as below.
161+There are two options to boot the kernel with bootconfig: attaching the
162+bootconfig to the initrd image or embedding it in the kernel itself.
163+
164+Attaching a Boot Config to Initrd
165+---------------------------------
166+
167+Since the boot configuration file is loaded with initrd by default,
168+it will be added to the end of the initrd (initramfs) image file with
169+padding, size, checksum and 12-byte magic word as below.
164170
165171 [initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]
166172
@@ -196,6 +202,25 @@ To remove the config from the image, you can use -d option as below:: · 29 unmodified lines
196202 Then add "bootconfig" on the normal kernel command line to tell the
197203 kernel to look for the bootconfig at the end of the initrd file.
198204
205+Embedding a Boot Config into Kernel
206+-----------------------------------
207+
208+If you can not use initrd, you can also embed the bootconfig file in the
209+kernel by Kconfig options. In this case, you need to recompile the kernel
210+with the following configs::
211+
212+ CONFIG_BOOT_CONFIG_EMBED=y
213+ CONFIG_BOOT_CONFIG_EMBED_FILE="/PATH/TO/BOOTCONFIG/FILE"
214+
215+``CONFIG_BOOT_CONFIG_EMBED_FILE`` requires an absolute path or a relative
216+path to the bootconfig file from source tree or object tree.
217+The kernel will embed it as the default bootconfig.
218+
219+Just as when attaching the bootconfig to the initrd, you need ``bootconfig``
220+option on the kernel command line to enable the embedded bootconfig.
221+
222+Note that even if you set this option, you can override the embedded
223+bootconfig by another bootconfig which attached to the initrd.
199224
200225 Kernel parameters via Boot Config
201226 =================================
Documentation/trace/ftrace.rst+12−0
@@ -517,6 +517,18 @@ of ftrace. Here is a list of some of the key files: · 516 unmodified lines
517517 processing should be able to handle them. See comments in the
518518 ktime_get_boot_fast_ns() function for more information.
519519
520+ tai:
521+ This is the tai clock (CLOCK_TAI) and is derived from the wall-
522+ clock time. However, this clock does not experience
523+ discontinuities and backwards jumps caused by NTP inserting leap
524+ seconds. Since the clock access is designed for use in tracing,
525+ side effects are possible. The clock access may yield wrong
526+ readouts in case the internal TAI offset is updated e.g., caused
527+ by setting the system time or using adjtimex() with an offset.
528+ These effects are rare and post processing should be able to
529+ handle them. See comments in the ktime_get_tai_fast_ns()
530+ function for more information.
531+
520532 To set a clock, simply echo the clock name into this file::
521533
522534 # echo global > trace_clock
Documentation/trace/timerlat-tracer.rst+3−2
@@ -74,8 +74,9 @@ directory. The timerlat configs are: · 73 unmodified lines
7474 - stop_tracing_total_us: stop the system tracing if a
7575 timer latency at the *thread* context is higher than the configured
7676 value happens. Writing 0 disables this option.
77− - print_stack: save the stack of the IRQ occurrence, and print
78− it after the *thread context* event".
77+ - print_stack: save the stack of the IRQ occurrence. The stack is printed
78+ after the *thread context* event, or at the IRQ handler if *stop_tracing_us*
79+ is hit.
7980
8081 timerlat and osnoise
8182 ----------------------------
MAINTAINERS+3−2
@@ -7517,6 +7517,7 @@ S: Maintained · 7516 unmodified lines
75177517 F: Documentation/admin-guide/bootconfig.rst
75187518 F: fs/proc/bootconfig.c
75197519 F: include/linux/bootconfig.h
7520+F: lib/bootconfig-data.S
75207521 F: lib/bootconfig.c
75217522 F: tools/bootconfig/*
75227523 F: tools/bootconfig/scripts/*
@@ -20119,8 +20120,8 @@ M: Ingo Molnar <mingo@redhat.com> · 12596 unmodified lines
2011920120 S: Maintained
2012020121 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
2012120122 F: Documentation/trace/ftrace.rst
20122−F: arch/*/*/*/ftrace.h
20123−F: arch/*/kernel/ftrace.c
20123+F: arch/*/*/*/*ftrace*
20124+F: arch/*/*/*ftrace*
2012420125 F: fs/tracefs/
2012520126 F: include/*/ftrace.h
2012620127 F: include/linux/trace*.h
arch/arm/kernel/ftrace.c+2−4
@@ -79,16 +79,14 @@ static unsigned long __ref adjust_address(struct dyn_ftrace *rec, · 78 unmodified lines
7979 return (unsigned long)&ftrace_regs_caller_from_init;
8080 }
8181
82−int ftrace_arch_code_modify_prepare(void)
82+void ftrace_arch_code_modify_prepare(void)
8383 {
84− return 0;
8584 }
8685
87−int ftrace_arch_code_modify_post_process(void)
86+void ftrace_arch_code_modify_post_process(void)
8887 {
8988 /* Make sure any TLB misses during machine stop are cleared. */
9089 flush_tlb_all();
91− return 0;
9290 }
9391
9492 static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr,
arch/riscv/kernel/ftrace.c+2−4
@@ -12,16 +12,14 @@ · 11 unmodified lines
1212 #include <asm/patch.h>
1313
1414 #ifdef CONFIG_DYNAMIC_FTRACE
15−int ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
15+void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
1616 {
1717 mutex_lock(&text_mutex);
18− return 0;
1918 }
2019
21−int ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
20+void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
2221 {
2322 mutex_unlock(&text_mutex);
24− return 0;
2523 }
2624
2725 static int ftrace_check_current_call(unsigned long hook_pos,
arch/s390/kernel/ftrace.c+1−2
@@ -225,14 +225,13 @@ void arch_ftrace_update_code(int command) · 224 unmodified lines
225225 ftrace_modify_all_code(command);
226226 }
227227
228−int ftrace_arch_code_modify_post_process(void)
228+void ftrace_arch_code_modify_post_process(void)
229229 {
230230 /*
231231 * Flush any pre-fetched instructions on all
232232 * CPUs to make the new code visible.
233233 */
234234 text_poke_sync_lock();
235− return 0;
236235 }
237236
238237 #ifdef CONFIG_MODULES
arch/x86/include/asm/ftrace.h+7−0
@@ -9,6 +9,13 @@ · 8 unmodified lines
99 # define MCOUNT_ADDR ((unsigned long)(__fentry__))
1010 #define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */
1111
12+/* Ignore unused weak functions which will have non zero offsets */
13+#ifdef CONFIG_HAVE_FENTRY
14+# include <asm/ibt.h>
15+/* Add offset for endbr64 if IBT enabled */
16+# define FTRACE_MCOUNT_MAX_OFFSET ENDBR_INSN_SIZE
17+#endif
18+
1219 #ifdef CONFIG_DYNAMIC_FTRACE
1320 #define ARCH_SUPPORTS_FTRACE_OPS 1
1421 #endif
arch/x86/kernel/ftrace.c+2−4
@@ -37,7 +37,7 @@ · 36 unmodified lines
3737
3838 static int ftrace_poke_late = 0;
3939
40−int ftrace_arch_code_modify_prepare(void)
40+void ftrace_arch_code_modify_prepare(void)
4141 __acquires(&text_mutex)
4242 {
4343 /*
@@ -47,10 +47,9 @@ int ftrace_arch_code_modify_prepare(void) · 3 unmodified lines
4747 */
4848 mutex_lock(&text_mutex);
4949 ftrace_poke_late = 1;
50− return 0;
5150 }
5251
53−int ftrace_arch_code_modify_post_process(void)
52+void ftrace_arch_code_modify_post_process(void)
5453 __releases(&text_mutex)
5554 {
5655 /*
@@ -61,7 +60,6 @@ int ftrace_arch_code_modify_post_process(void) · 4 unmodified lines
6160 text_poke_finish();
6261 ftrace_poke_late = 0;
6362 mutex_unlock(&text_mutex);
64− return 0;
6563 }
6664
6765 static const char *ftrace_nop_replace(void)
arch/x86/kernel/tracepoint.c+0−6
@@ -1,17 +1,11 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
3− * Code for supporting irq vector tracepoints.
4− *
53 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
6− *
74 */
85 #include <linux/jump_label.h>
96 #include <linux/atomic.h>
107
11−#include <asm/hw_irq.h>
12−#include <asm/desc.h>
138 #include <asm/trace/exceptions.h>
14−#include <asm/trace/irq_vectors.h>
159
1610 DEFINE_STATIC_KEY_FALSE(trace_pagefault_key);
1711
include/linux/bootconfig.h+10−0
@@ -289,4 +289,14 @@ int __init xbc_get_info(int *node_size, size_t *data_size); · 288 unmodified lines
289289 /* XBC cleanup data structures */
290290 void __init xbc_exit(void);
291291
292+/* XBC embedded bootconfig data in kernel */
293+#ifdef CONFIG_BOOT_CONFIG_EMBED
294+const char * __init xbc_get_embedded_bootconfig(size_t *size);
295+#else
296+static inline const char *xbc_get_embedded_bootconfig(size_t *size)
297+{
298+ return NULL;
299+}
300+#endif
301+
292302 #endif
include/linux/ftrace.h+2−2
@@ -452,8 +452,8 @@ static inline void stack_tracer_enable(void) { } · 451 unmodified lines
452452
453453 #ifdef CONFIG_DYNAMIC_FTRACE
454454
455−int ftrace_arch_code_modify_prepare(void);
456−int ftrace_arch_code_modify_post_process(void);
455+void ftrace_arch_code_modify_prepare(void);
456+void ftrace_arch_code_modify_post_process(void);
457457
458458 enum ftrace_bug_type {
459459 FTRACE_BUG_UNKNOWN,
include/linux/kprobes.h+1−1
@@ -424,7 +424,7 @@ void unregister_kretprobe(struct kretprobe *rp); · 423 unmodified lines
424424 int register_kretprobes(struct kretprobe **rps, int num);
425425 void unregister_kretprobes(struct kretprobe **rps, int num);
426426
427−#ifdef CONFIG_KRETPROBE_ON_RETHOOK
427+#if defined(CONFIG_KRETPROBE_ON_RETHOOK) || !defined(CONFIG_KRETPROBES)
428428 #define kprobe_flush_task(tk) do {} while (0)
429429 #else
430430 void kprobe_flush_task(struct task_struct *tk);
init/Kconfig+20−1
@@ -1338,7 +1338,7 @@ endif · 1337 unmodified lines
13381338
13391339 config BOOT_CONFIG
13401340 bool "Boot config support"
1341− select BLK_DEV_INITRD
1341+ select BLK_DEV_INITRD if !BOOT_CONFIG_EMBED
13421342 help
13431343 Extra boot config allows system admin to pass a config file as
13441344 complemental extension of kernel cmdline when booting.
@@ -1348,6 +1348,25 @@ config BOOT_CONFIG · 3 unmodified lines
13481348
13491349 If unsure, say Y.
13501350
1351+config BOOT_CONFIG_EMBED
1352+ bool "Embed bootconfig file in the kernel"
1353+ depends on BOOT_CONFIG
1354+ help
1355+ Embed a bootconfig file given by BOOT_CONFIG_EMBED_FILE in the
1356+ kernel. Usually, the bootconfig file is loaded with the initrd
1357+ image. But if the system doesn't support initrd, this option will
1358+ help you by embedding a bootconfig file while building the kernel.
1359+
1360+ If unsure, say N.
1361+
1362+config BOOT_CONFIG_EMBED_FILE
1363+ string "Embedded bootconfig file path"
1364+ depends on BOOT_CONFIG_EMBED
1365+ help
1366+ Specify a bootconfig file which will be embedded to the kernel.
1367+ This bootconfig will be used if there is no initrd or no other
1368+ bootconfig in the initrd.
1369+
13511370 config INITRAMFS_PRESERVE_MTIME
13521371 bool "Preserve cpio archive mtimes in initramfs"
13531372 default y
init/main.c+19−19
@@ -266,7 +266,7 @@ static int __init loglevel(char *str) · 265 unmodified lines
266266 early_param("loglevel", loglevel);
267267
268268 #ifdef CONFIG_BLK_DEV_INITRD
269−static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
269+static void * __init get_boot_config_from_initrd(size_t *_size)
270270 {
271271 u32 size, csum;
272272 char *data;
@@ -300,17 +300,20 @@ found: · 27 unmodified lines
300300 return NULL;
301301 }
302302
303+ if (xbc_calc_checksum(data, size) != csum) {
304+ pr_err("bootconfig checksum failed\n");
305+ return NULL;
306+ }
307+
303308 /* Remove bootconfig from initramfs/initrd */
304309 initrd_end = (unsigned long)data;
305310 if (_size)
306311 *_size = size;
307− if (_csum)
308− *_csum = csum;
309312
310313 return data;
311314 }
312315 #else
313−static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
316+static void * __init get_boot_config_from_initrd(size_t *_size)
314317 {
315318 return NULL;
316319 }
@@ -407,14 +410,16 @@ static int __init warn_bootconfig(char *str) · 90 unmodified lines
407410 static void __init setup_boot_config(void)
408411 {
409412 static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
410− const char *msg;
411− int pos;
412− u32 size, csum;
413− char *data, *err;
414− int ret;
413+ const char *msg, *data;
414+ int pos, ret;
415+ size_t size;
416+ char *err;
415417
416418 /* Cut out the bootconfig data even if we have no bootconfig option */
417− data = get_boot_config_from_initrd(&size, &csum);
419+ data = get_boot_config_from_initrd(&size);
420+ /* If there is no bootconfig in initrd, try embedded one. */
421+ if (!data)
422+ data = xbc_get_embedded_bootconfig(&size);
418423
419424 strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
420425 err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
@@ -433,13 +438,8 @@ static void __init setup_boot_config(void) · 12 unmodified lines
433438 }
434439
435440 if (size >= XBC_DATA_MAX) {
436− pr_err("bootconfig size %d greater than max size %d\n",
437− size, XBC_DATA_MAX);
438− return;
439− }
440−
441− if (xbc_calc_checksum(data, size) != csum) {
442− pr_err("bootconfig checksum failed\n");
441+ pr_err("bootconfig size %ld greater than max size %d\n",
442+ (long)size, XBC_DATA_MAX);
443443 return;
444444 }
445445
@@ -452,7 +452,7 @@ static void __init setup_boot_config(void) · 6 unmodified lines
452452 msg, pos);
453453 } else {
454454 xbc_get_info(&ret, NULL);
455− pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret);
455+ pr_info("Load bootconfig: %ld bytes %d nodes\n", (long)size, ret);
456456 /* keys starting with "kernel." are passed via cmdline */
457457 extra_command_line = xbc_make_cmdline("kernel");
458458 /* Also, "init." keys are init arguments */
@@ -471,7 +471,7 @@ static void __init exit_boot_config(void) · 12 unmodified lines
471471 static void __init setup_boot_config(void)
472472 {
473473 /* Remove bootconfig data from initrd */
474− get_boot_config_from_initrd(NULL, NULL);
474+ get_boot_config_from_initrd(NULL);
475475 }
476476
477477 static int __init warn_bootconfig(char *str)
kernel/kprobes.c+71−73
@@ -1257,79 +1257,6 @@ void kprobe_busy_end(void) · 1256 unmodified lines
12571257 preempt_enable();
12581258 }
12591259
1260−#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1261−static void free_rp_inst_rcu(struct rcu_head *head)
1262−{
1263− struct kretprobe_instance *ri = container_of(head, struct kretprobe_instance, rcu);
1264−
1265− if (refcount_dec_and_test(&ri->rph->ref))
1266− kfree(ri->rph);
1267− kfree(ri);
1268−}
1269−NOKPROBE_SYMBOL(free_rp_inst_rcu);
1270−
1271−static void recycle_rp_inst(struct kretprobe_instance *ri)
1272−{
1273− struct kretprobe *rp = get_kretprobe(ri);
1274−
1275− if (likely(rp))
1276− freelist_add(&ri->freelist, &rp->freelist);
1277− else
1278− call_rcu(&ri->rcu, free_rp_inst_rcu);
1279−}
1280−NOKPROBE_SYMBOL(recycle_rp_inst);
1281−
1282−/*
1283− * This function is called from delayed_put_task_struct() when a task is
1284− * dead and cleaned up to recycle any kretprobe instances associated with
1285− * this task. These left over instances represent probed functions that
1286− * have been called but will never return.
1287− */
1288−void kprobe_flush_task(struct task_struct *tk)
1289−{
1290− struct kretprobe_instance *ri;
1291− struct llist_node *node;
1292−
1293− /* Early boot, not yet initialized. */
1294− if (unlikely(!kprobes_initialized))
1295− return;
1296−
1297− kprobe_busy_begin();
1298−
1299− node = __llist_del_all(&tk->kretprobe_instances);
1300− while (node) {
1301− ri = container_of(node, struct kretprobe_instance, llist);
1302− node = node->next;
1303−
1304− recycle_rp_inst(ri);
1305− }
1306−
1307− kprobe_busy_end();
1308−}
1309−NOKPROBE_SYMBOL(kprobe_flush_task);
1310−
1311−static inline void free_rp_inst(struct kretprobe *rp)
1312−{
1313− struct kretprobe_instance *ri;
1314− struct freelist_node *node;
1315− int count = 0;
1316−
1317− node = rp->freelist.head;
1318− while (node) {
1319− ri = container_of(node, struct kretprobe_instance, freelist);
1320− node = node->next;
1321−
1322− kfree(ri);
1323− count++;
1324− }
1325−
1326− if (refcount_sub_and_test(count, &rp->rph->ref)) {
1327− kfree(rp->rph);
1328− rp->rph = NULL;
1329− }
1330−}
1331−#endif /* !CONFIG_KRETPROBE_ON_RETHOOK */
1332−
13331260 /* Add the new probe to 'ap->list'. */
13341261 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
13351262 {
@@ -1928,6 +1855,77 @@ static struct notifier_block kprobe_exceptions_nb = { · 592 unmodified lines
19281855 #ifdef CONFIG_KRETPROBES
19291856
19301857 #if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1858+static void free_rp_inst_rcu(struct rcu_head *head)
1859+{
1860+ struct kretprobe_instance *ri = container_of(head, struct kretprobe_instance, rcu);
1861+
1862+ if (refcount_dec_and_test(&ri->rph->ref))
1863+ kfree(ri->rph);
1864+ kfree(ri);
1865+}
1866+NOKPROBE_SYMBOL(free_rp_inst_rcu);
1867+
1868+static void recycle_rp_inst(struct kretprobe_instance *ri)
1869+{
1870+ struct kretprobe *rp = get_kretprobe(ri);
1871+
1872+ if (likely(rp))
1873+ freelist_add(&ri->freelist, &rp->freelist);
1874+ else
1875+ call_rcu(&ri->rcu, free_rp_inst_rcu);
1876+}
1877+NOKPROBE_SYMBOL(recycle_rp_inst);
1878+
1879+/*
1880+ * This function is called from delayed_put_task_struct() when a task is
1881+ * dead and cleaned up to recycle any kretprobe instances associated with
1882+ * this task. These left over instances represent probed functions that
1883+ * have been called but will never return.
1884+ */
1885+void kprobe_flush_task(struct task_struct *tk)
1886+{
1887+ struct kretprobe_instance *ri;
1888+ struct llist_node *node;
1889+
1890+ /* Early boot, not yet initialized. */
1891+ if (unlikely(!kprobes_initialized))
1892+ return;
1893+
1894+ kprobe_busy_begin();
1895+
1896+ node = __llist_del_all(&tk->kretprobe_instances);
1897+ while (node) {
1898+ ri = container_of(node, struct kretprobe_instance, llist);
1899+ node = node->next;
1900+
1901+ recycle_rp_inst(ri);
1902+ }
1903+
1904+ kprobe_busy_end();
1905+}
1906+NOKPROBE_SYMBOL(kprobe_flush_task);
1907+
1908+static inline void free_rp_inst(struct kretprobe *rp)
1909+{
1910+ struct kretprobe_instance *ri;
1911+ struct freelist_node *node;
1912+ int count = 0;
1913+
1914+ node = rp->freelist.head;
1915+ while (node) {
1916+ ri = container_of(node, struct kretprobe_instance, freelist);
1917+ node = node->next;
1918+
1919+ kfree(ri);
1920+ count++;
1921+ }
1922+
1923+ if (refcount_sub_and_test(count, &rp->rph->ref)) {
1924+ kfree(rp->rph);
1925+ rp->rph = NULL;
1926+ }
1927+}
1928+
19311929 /* This assumes the 'tsk' is the current task or the is not running. */
19321930 static kprobe_opcode_t *__kretprobe_find_ret_addr(struct task_struct *tsk,
19331931 struct llist_node **cur)
kernel/trace/Makefile+4−0
@@ -31,6 +31,10 @@ ifdef CONFIG_GCOV_PROFILE_FTRACE · 30 unmodified lines
3131 GCOV_PROFILE := y
3232 endif
3333
34+# Functions in this file could be invoked from early interrupt
35+# code and produce random code coverage.
36+KCOV_INSTRUMENT_trace_preemptirq.o := n
37+
3438 CFLAGS_bpf_trace.o := -I$(src)
3539
3640 CFLAGS_trace_benchmark.o := -I$(src)
kernel/trace/ftrace.c+174−36
@@ -45,6 +45,8 @@ · 44 unmodified lines
4545 #include "trace_output.h"
4646 #include "trace_stat.h"
4747
48+#define FTRACE_INVALID_FUNCTION "__ftrace_invalid_address__"
49+
4850 #define FTRACE_WARN_ON(cond) \
4951 ({ \
5052 int ___r = cond; \
@@ -119,7 +121,7 @@ struct ftrace_ops __rcu *ftrace_ops_list __read_mostly = &ftrace_list_end; · 68 unmodified lines
119121 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
120122 struct ftrace_ops global_ops;
121123
122−/* Defined by vmlinux.lds.h see the commment above arch_ftrace_ops_list_func for details */
124+/* Defined by vmlinux.lds.h see the comment above arch_ftrace_ops_list_func for details */
123125 void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
124126 struct ftrace_ops *op, struct ftrace_regs *fregs);
125127
@@ -952,7 +954,6 @@ static struct tracer_stat function_stats __initdata = { · 826 unmodified lines
952954 static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
953955 {
954956 struct ftrace_profile_stat *stat;
955− struct dentry *entry;
956957 char *name;
957958 int ret;
958959 int cpu;
@@ -983,11 +984,9 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer) · 24 unmodified lines
983984 }
984985 }
985986
986− entry = tracefs_create_file("function_profile_enabled",
987− TRACE_MODE_WRITE, d_tracer, NULL,
988− &ftrace_profile_fops);
989− if (!entry)
990− pr_warn("Could not create tracefs 'function_profile_enabled' entry\n");
987+ trace_create_file("function_profile_enabled",
988+ TRACE_MODE_WRITE, d_tracer, NULL,
989+ &ftrace_profile_fops);
991990 }
992991
993992 #else /* CONFIG_FUNCTION_PROFILER */
@@ -2707,18 +2706,16 @@ ftrace_nop_initialize(struct module *mod, struct dyn_ftrace *rec) · 1713 unmodified lines
27072706 * archs can override this function if they must do something
27082707 * before the modifying code is performed.
27092708 */
2710−int __weak ftrace_arch_code_modify_prepare(void)
2709+void __weak ftrace_arch_code_modify_prepare(void)
27112710 {
2712− return 0;
27132711 }
27142712
27152713 /*
27162714 * archs can override this function if they must do something
27172715 * after the modifying code is performed.
27182716 */
2719−int __weak ftrace_arch_code_modify_post_process(void)
2717+void __weak ftrace_arch_code_modify_post_process(void)
27202718 {
2721− return 0;
27222719 }
27232720
27242721 void ftrace_modify_all_code(int command)
@@ -2804,12 +2801,7 @@ void __weak arch_ftrace_update_code(int command) · 79 unmodified lines
28042801
28052802 static void ftrace_run_update_code(int command)
28062803 {
2807− int ret;
2808−
2809− ret = ftrace_arch_code_modify_prepare();
2810− FTRACE_WARN_ON(ret);
2811− if (ret)
2812− return;
2804+ ftrace_arch_code_modify_prepare();
28132805
28142806 /*
28152807 * By default we use stop_machine() to modify the code.
@@ -2819,8 +2811,7 @@ static void ftrace_run_update_code(int command) · 3 unmodified lines
28192811 */
28202812 arch_ftrace_update_code(command);
28212813
2822− ret = ftrace_arch_code_modify_post_process();
2823− FTRACE_WARN_ON(ret);
2814+ ftrace_arch_code_modify_post_process();
28242815 }
28252816
28262817 static void ftrace_run_modify_code(struct ftrace_ops *ops, int command,
@@ -3631,6 +3622,105 @@ static void add_trampoline_func(struct seq_file *m, struct ftrace_ops *ops, · 804 unmodified lines
36313622 seq_printf(m, " ->%pS", ptr);
36323623 }
36333624
3625+#ifdef FTRACE_MCOUNT_MAX_OFFSET
3626+/*
3627+ * Weak functions can still have an mcount/fentry that is saved in
3628+ * the __mcount_loc section. These can be detected by having a
3629+ * symbol offset of greater than FTRACE_MCOUNT_MAX_OFFSET, as the
3630+ * symbol found by kallsyms is not the function that the mcount/fentry
3631+ * is part of. The offset is much greater in these cases.
3632+ *
3633+ * Test the record to make sure that the ip points to a valid kallsyms
3634+ * and if not, mark it disabled.
3635+ */
3636+static int test_for_valid_rec(struct dyn_ftrace *rec)
3637+{
3638+ char str[KSYM_SYMBOL_LEN];
3639+ unsigned long offset;
3640+ const char *ret;
3641+
3642+ ret = kallsyms_lookup(rec->ip, NULL, &offset, NULL, str);
3643+
3644+ /* Weak functions can cause invalid addresses */
3645+ if (!ret || offset > FTRACE_MCOUNT_MAX_OFFSET) {
3646+ rec->flags |= FTRACE_FL_DISABLED;
3647+ return 0;
3648+ }
3649+ return 1;
3650+}
3651+
3652+static struct workqueue_struct *ftrace_check_wq __initdata;
3653+static struct work_struct ftrace_check_work __initdata;
3654+
3655+/*
3656+ * Scan all the mcount/fentry entries to make sure they are valid.
3657+ */
3658+static __init void ftrace_check_work_func(struct work_struct *work)
3659+{
3660+ struct ftrace_page *pg;
3661+ struct dyn_ftrace *rec;
3662+
3663+ mutex_lock(&ftrace_lock);
3664+ do_for_each_ftrace_rec(pg, rec) {
3665+ test_for_valid_rec(rec);
3666+ } while_for_each_ftrace_rec();
3667+ mutex_unlock(&ftrace_lock);
3668+}
3669+
3670+static int __init ftrace_check_for_weak_functions(void)
3671+{
3672+ INIT_WORK(&ftrace_check_work, ftrace_check_work_func);
3673+
3674+ ftrace_check_wq = alloc_workqueue("ftrace_check_wq", WQ_UNBOUND, 0);
3675+
3676+ queue_work(ftrace_check_wq, &ftrace_check_work);
3677+ return 0;
3678+}
3679+
3680+static int __init ftrace_check_sync(void)
3681+{
3682+ /* Make sure the ftrace_check updates are finished */
3683+ if (ftrace_check_wq)
3684+ destroy_workqueue(ftrace_check_wq);
3685+ return 0;
3686+}
3687+
3688+late_initcall_sync(ftrace_check_sync);
3689+subsys_initcall(ftrace_check_for_weak_functions);
3690+
3691+static int print_rec(struct seq_file *m, unsigned long ip)
3692+{
3693+ unsigned long offset;
3694+ char str[KSYM_SYMBOL_LEN];
3695+ char *modname;
3696+ const char *ret;
3697+
3698+ ret = kallsyms_lookup(ip, NULL, &offset, &modname, str);
3699+ /* Weak functions can cause invalid addresses */
3700+ if (!ret || offset > FTRACE_MCOUNT_MAX_OFFSET) {
3701+ snprintf(str, KSYM_SYMBOL_LEN, "%s_%ld",
3702+ FTRACE_INVALID_FUNCTION, offset);
3703+ ret = NULL;
3704+ }
3705+
3706+ seq_puts(m, str);
3707+ if (modname)
3708+ seq_printf(m, " [%s]", modname);
3709+ return ret == NULL ? -1 : 0;
3710+}
3711+#else
3712+static inline int test_for_valid_rec(struct dyn_ftrace *rec)
3713+{
3714+ return 1;
3715+}
3716+
3717+static inline int print_rec(struct seq_file *m, unsigned long ip)
3718+{
3719+ seq_printf(m, "%ps", (void *)ip);
3720+ return 0;
3721+}
3722+#endif
3723+
36343724 static int t_show(struct seq_file *m, void *v)
36353725 {
36363726 struct ftrace_iterator *iter = m->private;
@@ -3655,7 +3745,13 @@ static int t_show(struct seq_file *m, void *v) · 18 unmodified lines
36553745 if (!rec)
36563746 return 0;
36573747
3658− seq_printf(m, "%ps", (void *)rec->ip);
3748+ if (print_rec(m, rec->ip)) {
3749+ /* This should only happen when a rec is disabled */
3750+ WARN_ON_ONCE(!(rec->flags & FTRACE_FL_DISABLED));
3751+ seq_putc(m, '\n');
3752+ return 0;
3753+ }
3754+
36593755 if (iter->flags & FTRACE_ITER_ENABLED) {
36603756 struct ftrace_ops *ops;
36613757
@@ -3973,6 +4069,24 @@ add_rec_by_index(struct ftrace_hash *hash, struct ftrace_glob *func_g, · 311 unmodified lines
39734069 return 0;
39744070 }
39754071
4072+#ifdef FTRACE_MCOUNT_MAX_OFFSET
4073+static int lookup_ip(unsigned long ip, char **modname, char *str)
4074+{
4075+ unsigned long offset;
4076+
4077+ kallsyms_lookup(ip, NULL, &offset, modname, str);
4078+ if (offset > FTRACE_MCOUNT_MAX_OFFSET)
4079+ return -1;
4080+ return 0;
4081+}
4082+#else
4083+static int lookup_ip(unsigned long ip, char **modname, char *str)
4084+{
4085+ kallsyms_lookup(ip, NULL, NULL, modname, str);
4086+ return 0;
4087+}
4088+#endif
4089+
39764090 static int
39774091 ftrace_match_record(struct dyn_ftrace *rec, struct ftrace_glob *func_g,
39784092 struct ftrace_glob *mod_g, int exclude_mod)
@@ -3980,7 +4094,12 @@ ftrace_match_record(struct dyn_ftrace *rec, struct ftrace_glob *func_g, · 1 unmodified line
39804094 char str[KSYM_SYMBOL_LEN];
39814095 char *modname;
39824096
3983− kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
4097+ if (lookup_ip(rec->ip, &modname, str)) {
4098+ /* This should only happen when a rec is disabled */
4099+ WARN_ON_ONCE(system_state == SYSTEM_RUNNING &&
4100+ !(rec->flags & FTRACE_FL_DISABLED));
4101+ return 0;
4102+ }
39844103
39854104 if (mod_g) {
39864105 int mod_matches = (modname) ? ftrace_match(modname, mod_g) : 0;
@@ -4431,7 +4550,7 @@ int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper, · 444 unmodified lines
44314550 * @ip: The instruction pointer address to remove the data from
44324551 *
44334552 * Returns the data if it is found, otherwise NULL.
4434− * Note, if the data pointer is used as the data itself, (see
4553+ * Note, if the data pointer is used as the data itself, (see
44354554 * ftrace_func_mapper_find_ip(), then the return value may be meaningless,
44364555 * if the data pointer was set to zero.
44374556 */
@@ -4526,8 +4645,8 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr, · 88 unmodified lines
45264645 struct ftrace_probe_ops *probe_ops,
45274646 void *data)
45284647 {
4648+ struct ftrace_func_probe *probe = NULL, *iter;
45294649 struct ftrace_func_entry *entry;
4530− struct ftrace_func_probe *probe;
45314650 struct ftrace_hash **orig_hash;
45324651 struct ftrace_hash *old_hash;
45334652 struct ftrace_hash *hash;
@@ -4546,11 +4665,13 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr, · 12 unmodified lines
45464665
45474666 mutex_lock(&ftrace_lock);
45484667 /* Check if the probe_ops is already registered */
4549− list_for_each_entry(probe, &tr->func_probes, list) {
4550− if (probe->probe_ops == probe_ops)
4668+ list_for_each_entry(iter, &tr->func_probes, list) {
4669+ if (iter->probe_ops == probe_ops) {
4670+ probe = iter;
45514671 break;
4672+ }
45524673 }
4553− if (&probe->list == &tr->func_probes) {
4674+ if (!probe) {
45544675 probe = kzalloc(sizeof(*probe), GFP_KERNEL);
45554676 if (!probe) {
45564677 mutex_unlock(&ftrace_lock);
@@ -4668,9 +4789,9 @@ int · 111 unmodified lines
46684789 unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
46694790 struct ftrace_probe_ops *probe_ops)
46704791 {
4792+ struct ftrace_func_probe *probe = NULL, *iter;
46714793 struct ftrace_ops_hash old_hash_ops;
46724794 struct ftrace_func_entry *entry;
4673− struct ftrace_func_probe *probe;
46744795 struct ftrace_glob func_g;
46754796 struct ftrace_hash **orig_hash;
46764797 struct ftrace_hash *old_hash;
@@ -4698,11 +4819,13 @@ unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr, · 21 unmodified lines
46984819
46994820 mutex_lock(&ftrace_lock);
47004821 /* Check if the probe_ops is already registered */
4701− list_for_each_entry(probe, &tr->func_probes, list) {
4702− if (probe->probe_ops == probe_ops)
4822+ list_for_each_entry(iter, &tr->func_probes, list) {
4823+ if (iter->probe_ops == probe_ops) {
4824+ probe = iter;
47034825 break;
4826+ }
47044827 }
4705− if (&probe->list == &tr->func_probes)
4828+ if (!probe)
47064829 goto err_unlock_ftrace;
47074830
47084831 ret = -EINVAL;
@@ -5161,8 +5284,6 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) · 452 unmodified lines
51615284 goto out_unlock;
51625285
51635286 ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0);
5164− if (ret)
5165− remove_hash_entry(direct_functions, entry);
51665287
51675288 if (!ret && !(direct_ops.flags & FTRACE_OPS_FL_ENABLED)) {
51685289 ret = register_ftrace_function(&direct_ops);
@@ -5171,6 +5292,7 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) · 2 unmodified lines
51715292 }
51725293
51735294 if (ret) {
5295+ remove_hash_entry(direct_functions, entry);
51745296 kfree(entry);
51755297 if (!direct->count) {
51765298 list_del_rcu(&direct->next);
@@ -6793,6 +6915,13 @@ void ftrace_module_enable(struct module *mod) · 1616 unmodified lines
67936915 !within_module_init(rec->ip, mod))
67946916 break;
67956917
6918+ /* Weak functions should still be ignored */
6919+ if (!test_for_valid_rec(rec)) {
6920+ /* Clear all other flags. Should not be enabled anyway */
6921+ rec->flags = FTRACE_FL_DISABLED;
6922+ continue;
6923+ }
6924+
67966925 cnt = 0;
67976926
67986927 /*
@@ -6829,11 +6958,16 @@ void ftrace_module_enable(struct module *mod) · 30 unmodified lines
68296958
68306959 void ftrace_module_init(struct module *mod)
68316960 {
6961+ int ret;
6962+
68326963 if (ftrace_disabled || !mod->num_ftrace_callsites)
68336964 return;
68346965
6835− ftrace_process_locs(mod, mod->ftrace_callsites,
6836− mod->ftrace_callsites + mod->num_ftrace_callsites);
6966+ ret = ftrace_process_locs(mod, mod->ftrace_callsites,
6967+ mod->ftrace_callsites + mod->num_ftrace_callsites);
6968+ if (ret)
6969+ pr_warn("ftrace: failed to allocate entries for module '%s' functions\n",
6970+ mod->name);
68376971 }
68386972
68396973 static void save_ftrace_mod_rec(struct ftrace_mod_map *mod_map,
@@ -7166,15 +7300,19 @@ void __init ftrace_init(void) · 326 unmodified lines
71667300 pr_info("ftrace: allocating %ld entries in %ld pages\n",
71677301 count, count / ENTRIES_PER_PAGE + 1);
71687302
7169− last_ftrace_enabled = ftrace_enabled = 1;
7170−
71717303 ret = ftrace_process_locs(NULL,
71727304 __start_mcount_loc,
71737305 __stop_mcount_loc);
7306+ if (ret) {
7307+ pr_warn("ftrace: failed to allocate entries for functions\n");
7308+ goto failed;
7309+ }
71747310
71757311 pr_info("ftrace: allocated %ld pages with %ld groups\n",
71767312 ftrace_number_of_pages, ftrace_number_of_groups);
71777313
7314+ last_ftrace_enabled = ftrace_enabled = 1;
7315+
71787316 set_ftrace_early_filters();
71797317
71807318 return;
kernel/trace/pid_list.c+2−2
@@ -118,9 +118,9 @@ static inline unsigned int pid_join(unsigned int upper1, · 117 unmodified lines
118118 /**
119119 * trace_pid_list_is_set - test if the pid is set in the list
120120 * @pid_list: The pid list to test
121− * @pid: The pid to to see if set in the list.
121+ * @pid: The pid to see if set in the list.
122122 *
123− * Tests if @pid is is set in the @pid_list. This is usually called
123+ * Tests if @pid is set in the @pid_list. This is usually called
124124 * from the scheduler when a task is scheduled. Its pid is checked
125125 * if it should be traced or not.
126126 *
kernel/trace/ring_buffer.c+64−17
@@ -29,6 +29,14 @@ · 28 unmodified lines
2929
3030 #include <asm/local.h>
3131
32+/*
33+ * The "absolute" timestamp in the buffer is only 59 bits.
34+ * If a clock has the 5 MSBs set, it needs to be saved and
35+ * reinserted.
36+ */
37+#define TS_MSB (0xf8ULL << 56)
38+#define ABS_TS_MASK (~TS_MSB)
39+
3240 static void update_pages_handler(struct work_struct *work);
3341
3442 /*
@@ -468,6 +476,7 @@ struct rb_time_struct { · 433 unmodified lines
468476 local_t cnt;
469477 local_t top;
470478 local_t bottom;
479+ local_t msb;
471480 };
472481 #else
473482 #include <asm/local64.h>
@@ -569,7 +578,6 @@ struct ring_buffer_iter { · 95 unmodified lines
569578 * For the ring buffer, 64 bit required operations for the time is
570579 * the following:
571580 *
572− * - Only need 59 bits (uses 60 to make it even).
573581 * - Reads may fail if it interrupted a modification of the time stamp.
574582 * It will succeed if it did not interrupt another write even if
575583 * the read itself is interrupted by a write.
@@ -594,6 +602,7 @@ struct ring_buffer_iter { · 18 unmodified lines
594602 */
595603 #define RB_TIME_SHIFT 30
596604 #define RB_TIME_VAL_MASK ((1 << RB_TIME_SHIFT) - 1)
605+#define RB_TIME_MSB_SHIFT 60
597606
598607 static inline int rb_time_cnt(unsigned long val)
599608 {
@@ -613,7 +622,7 @@ static inline u64 rb_time_val(unsigned long top, unsigned long bottom) · 13 unmodified lines
613622
614623 static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt)
615624 {
616− unsigned long top, bottom;
625+ unsigned long top, bottom, msb;
617626 unsigned long c;
618627
619628 /*
@@ -625,6 +634,7 @@ static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt) · 5 unmodified lines
625634 c = local_read(&t->cnt);
626635 top = local_read(&t->top);
627636 bottom = local_read(&t->bottom);
637+ msb = local_read(&t->msb);
628638 } while (c != local_read(&t->cnt));
629639
630640 *cnt = rb_time_cnt(top);
@@ -633,7 +643,8 @@ static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt) · 2 unmodified lines
633643 if (*cnt != rb_time_cnt(bottom))
634644 return false;
635645
636− *ret = rb_time_val(top, bottom);
646+ /* The shift to msb will lose its cnt bits */
647+ *ret = rb_time_val(top, bottom) | ((u64)msb << RB_TIME_MSB_SHIFT);
637648 return true;
638649 }
639650
@@ -649,10 +660,12 @@ static inline unsigned long rb_time_val_cnt(unsigned long val, unsigned long cnt · 9 unmodified lines
649660 return (val & RB_TIME_VAL_MASK) | ((cnt & 3) << RB_TIME_SHIFT);
650661 }
651662
652−static inline void rb_time_split(u64 val, unsigned long *top, unsigned long *bottom)
663+static inline void rb_time_split(u64 val, unsigned long *top, unsigned long *bottom,
664+ unsigned long *msb)
653665 {
654666 *top = (unsigned long)((val >> RB_TIME_SHIFT) & RB_TIME_VAL_MASK);
655667 *bottom = (unsigned long)(val & RB_TIME_VAL_MASK);
668+ *msb = (unsigned long)(val >> RB_TIME_MSB_SHIFT);
656669 }
657670
658671 static inline void rb_time_val_set(local_t *t, unsigned long val, unsigned long cnt)
@@ -663,15 +676,16 @@ static inline void rb_time_val_set(local_t *t, unsigned long val, unsigned long · 4 unmodified lines
663676
664677 static void rb_time_set(rb_time_t *t, u64 val)
665678 {
666− unsigned long cnt, top, bottom;
679+ unsigned long cnt, top, bottom, msb;
667680
668− rb_time_split(val, &top, &bottom);
681+ rb_time_split(val, &top, &bottom, &msb);
669682
670683 /* Writes always succeed with a valid number even if it gets interrupted. */
671684 do {
672685 cnt = local_inc_return(&t->cnt);
673686 rb_time_val_set(&t->top, top, cnt);
674687 rb_time_val_set(&t->bottom, bottom, cnt);
688+ rb_time_val_set(&t->msb, val >> RB_TIME_MSB_SHIFT, cnt);
675689 } while (cnt != local_read(&t->cnt));
676690 }
677691
@@ -686,8 +700,8 @@ rb_time_read_cmpxchg(local_t *l, unsigned long expect, unsigned long set) · 8 unmodified lines
686700
687701 static int rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)
688702 {
689− unsigned long cnt, top, bottom;
690− unsigned long cnt2, top2, bottom2;
703+ unsigned long cnt, top, bottom, msb;
704+ unsigned long cnt2, top2, bottom2, msb2;
691705 u64 val;
692706
693707 /* The cmpxchg always fails if it interrupted an update */
@@ -703,16 +717,18 @@ static int rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set) · 9 unmodified lines
703717
704718 cnt2 = cnt + 1;
705719
706− rb_time_split(val, &top, &bottom);
720+ rb_time_split(val, &top, &bottom, &msb);
707721 top = rb_time_val_cnt(top, cnt);
708722 bottom = rb_time_val_cnt(bottom, cnt);
709723
710− rb_time_split(set, &top2, &bottom2);
724+ rb_time_split(set, &top2, &bottom2, &msb2);
711725 top2 = rb_time_val_cnt(top2, cnt2);
712726 bottom2 = rb_time_val_cnt(bottom2, cnt2);
713727
714728 if (!rb_time_read_cmpxchg(&t->cnt, cnt, cnt2))
715729 return false;
730+ if (!rb_time_read_cmpxchg(&t->msb, msb, msb2))
731+ return false;
716732 if (!rb_time_read_cmpxchg(&t->top, top, top2))
717733 return false;
718734 if (!rb_time_read_cmpxchg(&t->bottom, bottom, bottom2))
@@ -783,6 +799,24 @@ static inline void verify_event(struct ring_buffer_per_cpu *cpu_buffer, · 64 unmodified lines
783799 }
784800 #endif
785801
802+/*
803+ * The absolute time stamp drops the 5 MSBs and some clocks may
804+ * require them. The rb_fix_abs_ts() will take a previous full
805+ * time stamp, and add the 5 MSB of that time stamp on to the
806+ * saved absolute time stamp. Then they are compared in case of
807+ * the unlikely event that the latest time stamp incremented
808+ * the 5 MSB.
809+ */
810+static inline u64 rb_fix_abs_ts(u64 abs, u64 save_ts)
811+{
812+ if (save_ts & TS_MSB) {
813+ abs |= save_ts & TS_MSB;
814+ /* Check for overflow */
815+ if (unlikely(abs < save_ts))
816+ abs += 1ULL << 59;
817+ }
818+ return abs;
819+}
786820
787821 static inline u64 rb_time_stamp(struct trace_buffer *buffer);
788822
@@ -811,8 +845,10 @@ u64 ring_buffer_event_time_stamp(struct trace_buffer *buffer, · 22 unmodified lines
811845 u64 ts;
812846
813847 /* If the event includes an absolute time, then just use that */
814− if (event->type_len == RINGBUF_TYPE_TIME_STAMP)
815− return rb_event_time_stamp(event);
848+ if (event->type_len == RINGBUF_TYPE_TIME_STAMP) {
849+ ts = rb_event_time_stamp(event);
850+ return rb_fix_abs_ts(ts, cpu_buffer->tail_page->page->time_stamp);
851+ }
816852
817853 nest = local_read(&cpu_buffer->committing);
818854 verify_event(cpu_buffer, event);
@@ -2754,8 +2790,15 @@ static void rb_add_timestamp(struct ring_buffer_per_cpu *cpu_buffer, · 1935 unmodified lines
27542790 (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE);
27552791
27562792 if (unlikely(info->delta > (1ULL << 59))) {
2793+ /*
2794+ * Some timers can use more than 59 bits, and when a timestamp
2795+ * is added to the buffer, it will lose those bits.
2796+ */
2797+ if (abs && (info->ts & TS_MSB)) {
2798+ info->delta &= ABS_TS_MASK;
2799+
27572800 /* did the clock go backwards */
2758− if (info->before == info->after && info->before > info->ts) {
2801+ } else if (info->before == info->after && info->before > info->ts) {
27592802 /* not interrupted */
27602803 static int once;
27612804
@@ -3304,7 +3347,7 @@ static void dump_buffer_page(struct buffer_data_page *bpage, · 542 unmodified lines
33043347
33053348 case RINGBUF_TYPE_TIME_STAMP:
33063349 delta = rb_event_time_stamp(event);
3307− ts = delta;
3350+ ts = rb_fix_abs_ts(delta, ts);
33083351 pr_warn(" [%lld] absolute:%lld TIME STAMP\n", ts, delta);
33093352 break;
33103353
@@ -3380,7 +3423,7 @@ static void check_buffer(struct ring_buffer_per_cpu *cpu_buffer, · 69 unmodified lines
33803423
33813424 case RINGBUF_TYPE_TIME_STAMP:
33823425 delta = rb_event_time_stamp(event);
3383− ts = delta;
3426+ ts = rb_fix_abs_ts(delta, ts);
33843427 break;
33853428
33863429 case RINGBUF_TYPE_PADDING:
@@ -4367,6 +4410,7 @@ rb_update_read_stamp(struct ring_buffer_per_cpu *cpu_buffer, · 980 unmodified lines
43674410
43684411 case RINGBUF_TYPE_TIME_STAMP:
43694412 delta = rb_event_time_stamp(event);
4413+ delta = rb_fix_abs_ts(delta, cpu_buffer->read_stamp);
43704414 cpu_buffer->read_stamp = delta;
43714415 return;
43724416
@@ -4397,6 +4441,7 @@ rb_update_iter_read_stamp(struct ring_buffer_iter *iter, · 24 unmodified lines
43974441
43984442 case RINGBUF_TYPE_TIME_STAMP:
43994443 delta = rb_event_time_stamp(event);
4444+ delta = rb_fix_abs_ts(delta, iter->read_stamp);
44004445 iter->read_stamp = delta;
44014446 return;
44024447
@@ -4650,6 +4695,7 @@ rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts, · 247 unmodified lines
46504695 case RINGBUF_TYPE_TIME_STAMP:
46514696 if (ts) {
46524697 *ts = rb_event_time_stamp(event);
4698+ *ts = rb_fix_abs_ts(*ts, reader->page->time_stamp);
46534699 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,
46544700 cpu_buffer->cpu, ts);
46554701 }
@@ -4741,6 +4787,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) · 85 unmodified lines
47414787 case RINGBUF_TYPE_TIME_STAMP:
47424788 if (ts) {
47434789 *ts = rb_event_time_stamp(event);
4790+ *ts = rb_fix_abs_ts(*ts, iter->head_page->page->time_stamp);
47444791 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,
47454792 cpu_buffer->cpu, ts);
47464793 }
@@ -6011,10 +6058,10 @@ static __init int test_ringbuffer(void) · 1264 unmodified lines
60116058 pr_info(" total events: %ld\n", total_lost + total_read);
60126059 pr_info(" recorded len bytes: %ld\n", total_len);
60136060 pr_info(" recorded size bytes: %ld\n", total_size);
6014− if (total_lost)
6061+ if (total_lost) {
60156062 pr_info(" With dropped events, record len and size may not match\n"
60166063 " alloced and written from above\n");
6017− if (!total_lost) {
6064+ } else {
60186065 if (RB_WARN_ON(buffer, total_len != total_alloc ||
60196066 total_size != total_written))
60206067 break;
kernel/trace/trace.c+45−27
@@ -721,13 +721,16 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, · 720 unmodified lines
721721 pos = 0;
722722
723723 ret = trace_get_user(&parser, ubuf, cnt, &pos);
724− if (ret < 0 || !trace_parser_loaded(&parser))
724+ if (ret < 0)
725725 break;
726726
727727 read += ret;
728728 ubuf += ret;
729729 cnt -= ret;
730730
731+ if (!trace_parser_loaded(&parser))
732+ break;
733+
731734 ret = -EINVAL;
732735 if (kstrtoul(parser.buffer, 0, &val))
733736 break;
@@ -753,7 +756,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, · 19 unmodified lines
753756 if (!nr_pids) {
754757 /* Cleared the list of pids */
755758 trace_pid_list_free(pid_list);
756− read = ret;
757759 pid_list = NULL;
758760 }
759761
@@ -1174,7 +1176,7 @@ void tracing_snapshot_cond(struct trace_array *tr, void *cond_data) · 414 unmodified lines
11741176 EXPORT_SYMBOL_GPL(tracing_snapshot_cond);
11751177
11761178 /**
1177− * tracing_snapshot_cond_data - get the user data associated with a snapshot
1179+ * tracing_cond_snapshot_data - get the user data associated with a snapshot
11781180 * @tr: The tracing instance
11791181 *
11801182 * When the user enables a conditional snapshot using
@@ -1542,6 +1544,7 @@ static struct { · 361 unmodified lines
15421544 { ktime_get_mono_fast_ns, "mono", 1 },
15431545 { ktime_get_raw_fast_ns, "mono_raw", 1 },
15441546 { ktime_get_boot_fast_ns, "boot", 1 },
1547+ { ktime_get_tai_fast_ns, "tai", 1 },
15451548 ARCH_TRACE_CLOCKS
15461549 };
15471550
@@ -2835,7 +2838,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb, · 1287 unmodified lines
28352838 }
28362839 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
28372840
2838−static DEFINE_SPINLOCK(tracepoint_iter_lock);
2841+static DEFINE_RAW_SPINLOCK(tracepoint_iter_lock);
28392842 static DEFINE_MUTEX(tracepoint_printk_mutex);
28402843
28412844 static void output_printk(struct trace_event_buffer *fbuffer)
@@ -2863,14 +2866,14 @@ static void output_printk(struct trace_event_buffer *fbuffer) · 21 unmodified lines
28632866
28642867 event = &fbuffer->trace_file->event_call->event;
28652868
2866− spin_lock_irqsave(&tracepoint_iter_lock, flags);
2869+ raw_spin_lock_irqsave(&tracepoint_iter_lock, flags);
28672870 trace_seq_init(&iter->seq);
28682871 iter->ent = fbuffer->entry;
28692872 event_call->event.funcs->trace(iter, 0, event);
28702873 trace_seq_putc(&iter->seq, 0);
28712874 printk("%s", iter->seq.buffer);
28722875
2873− spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
2876+ raw_spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
28742877 }
28752878
28762879 int tracepoint_printk_sysctl(struct ctl_table *table, int write,
@@ -4249,7 +4252,7 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file · 1372 unmodified lines
42494252 unsigned int flags)
42504253 {
42514254 bool tgid = flags & TRACE_ITER_RECORD_TGID;
4252− const char *space = " ";
4255+ static const char space[] = " ";
42534256 int prec = tgid ? 12 : 2;
42544257
42554258 print_event_info(buf, m);
@@ -4273,9 +4276,7 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) · 17 unmodified lines
42734276 struct tracer *type = iter->trace;
42744277 unsigned long entries;
42754278 unsigned long total;
4276− const char *name = "preemption";
4277−
4278− name = type->name;
4279+ const char *name = type->name;
42794280
42804281 get_total_entries(buf, &total, &entries);
42814282
@@ -5469,7 +5470,7 @@ static const char readme_msg[] = · 1187 unmodified lines
54695470 " error_log\t- error log for failed commands (that support it)\n"
54705471 " buffer_size_kb\t- view and modify size of per cpu buffer\n"
54715472 " buffer_total_size_kb - view total size of all cpu buffers\n\n"
5472− " trace_clock\t\t-change the clock used to order events\n"
5473+ " trace_clock\t\t- change the clock used to order events\n"
54735474 " local: Per cpu clock but may not be synced across CPUs\n"
54745475 " global: Synced across CPUs but slows tracing down.\n"
54755476 " counter: Not a clock, but just an increment\n"
@@ -5478,7 +5479,7 @@ static const char readme_msg[] = · 2 unmodified lines
54785479 #ifdef CONFIG_X86_64
54795480 " x86-tsc: TSC cycle counter\n"
54805481 #endif
5481− "\n timestamp_mode\t-view the mode used to timestamp events\n"
5482+ "\n timestamp_mode\t- view the mode used to timestamp events\n"
54825483 " delta: Delta difference against a buffer-wide timestamp\n"
54835484 " absolute: Absolute (standalone) timestamp\n"
54845485 "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n"
@@ -6326,12 +6327,18 @@ static void tracing_set_nop(struct trace_array *tr) · 841 unmodified lines
63266327 tr->current_trace = &nop_trace;
63276328 }
63286329
6330+static bool tracer_options_updated;
6331+
63296332 static void add_tracer_options(struct trace_array *tr, struct tracer *t)
63306333 {
63316334 /* Only enable if the directory has been created already. */
63326335 if (!tr->dir)
63336336 return;
63346337
6338+ /* Only create trace option files after update_tracer_options finish */
6339+ if (!tracer_options_updated)
6340+ return;
6341+
63356342 create_trace_option_files(tr, t);
63366343 }
63376344
@@ -6448,7 +6455,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, · 110 unmodified lines
64486455 {
64496456 struct trace_array *tr = filp->private_data;
64506457 char buf[MAX_TRACER_SIZE+1];
6451− int i;
6458+ char *name;
64526459 size_t ret;
64536460 int err;
64546461
@@ -6462,11 +6469,9 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, · 7 unmodified lines
64626469
64636470 buf[cnt] = 0;
64646471
6465− /* strip ending whitespace. */
6466− for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
6467− buf[i] = 0;
6472+ name = strim(buf);
64686473
6469− err = tracing_set_tracer(tr, buf);
6474+ err = tracing_set_tracer(tr, name);
64706475 if (err)
64716476 return err;
64726477
@@ -9170,6 +9175,7 @@ static void __update_tracer_options(struct trace_array *tr) · 2697 unmodified lines
91709175 static void update_tracer_options(struct trace_array *tr)
91719176 {
91729177 mutex_lock(&trace_types_lock);
9178+ tracer_options_updated = true;
91739179 __update_tracer_options(tr);
91749180 mutex_unlock(&trace_types_lock);
91759181 }
@@ -9602,6 +9608,7 @@ extern struct trace_eval_map *__stop_ftrace_eval_maps[]; · 426 unmodified lines
96029608
96039609 static struct workqueue_struct *eval_map_wq __initdata;
96049610 static struct work_struct eval_map_work __initdata;
9611+static struct work_struct tracerfs_init_work __initdata;
96059612
96069613 static void __init eval_map_work_func(struct work_struct *work)
96079614 {
@@ -9627,6 +9634,8 @@ static int __init trace_eval_init(void) · 19 unmodified lines
96279634 return 0;
96289635 }
96299636
9637+subsys_initcall(trace_eval_init);
9638+
96309639 static int __init trace_eval_sync(void)
96319640 {
96329641 /* Make sure the eval map updates are finished */
@@ -9709,15 +9718,8 @@ static struct notifier_block trace_module_nb = { · 76 unmodified lines
97099718 };
97109719 #endif /* CONFIG_MODULES */
97119720
9712−static __init int tracer_init_tracefs(void)
9721+static __init void tracer_init_tracefs_work_func(struct work_struct *work)
97139722 {
9714− int ret;
9715−
9716− trace_access_lock_init();
9717−
9718− ret = tracing_init_dentry();
9719− if (ret)
9720− return 0;
97219723
97229724 event_trace_init();
97239725
@@ -9739,8 +9741,6 @@ static __init int tracer_init_tracefs(void) · 15 unmodified lines
97399741 trace_create_file("saved_tgids", TRACE_MODE_READ, NULL,
97409742 NULL, &tracing_saved_tgids_fops);
97419743
9742− trace_eval_init();
9743−
97449744 trace_create_eval_file(NULL);
97459745
97469746 #ifdef CONFIG_MODULES
@@ -9755,6 +9755,24 @@ static __init int tracer_init_tracefs(void) · 8 unmodified lines
97559755 create_trace_instances(NULL);
97569756
97579757 update_tracer_options(&global_trace);
9758+}
9759+
9760+static __init int tracer_init_tracefs(void)
9761+{
9762+ int ret;
9763+
9764+ trace_access_lock_init();
9765+
9766+ ret = tracing_init_dentry();
9767+ if (ret)
9768+ return 0;
9769+
9770+ if (eval_map_wq) {
9771+ INIT_WORK(&tracerfs_init_work, tracer_init_tracefs_work_func);
9772+ queue_work(eval_map_wq, &tracerfs_init_work);
9773+ } else {
9774+ tracer_init_tracefs_work_func(NULL);
9775+ }
97589776
97599777 return 0;
97609778 }
kernel/trace/trace.h+11−15
@@ -1573,13 +1573,12 @@ struct enable_trigger_data { · 1572 unmodified lines
15731573 };
15741574
15751575 extern int event_enable_trigger_print(struct seq_file *m,
1576− struct event_trigger_ops *ops,
1577− struct event_trigger_data *data);
1578−extern void event_enable_trigger_free(struct event_trigger_ops *ops,
15791576 struct event_trigger_data *data);
1577+extern void event_enable_trigger_free(struct event_trigger_data *data);
15801578 extern int event_enable_trigger_parse(struct event_command *cmd_ops,
15811579 struct trace_event_file *file,
1582− char *glob, char *cmd, char *param);
1580+ char *glob, char *cmd,
1581+ char *param_and_filter);
15831582 extern int event_enable_register_trigger(char *glob,
15841583 struct event_trigger_data *data,
15851584 struct trace_event_file *file);
@@ -1587,8 +1586,7 @@ extern void event_enable_unregister_trigger(char *glob, · 1 unmodified line
15871586 struct event_trigger_data *test,
15881587 struct trace_event_file *file);
15891588 extern void trigger_data_free(struct event_trigger_data *data);
1590−extern int event_trigger_init(struct event_trigger_ops *ops,
1591− struct event_trigger_data *data);
1589+extern int event_trigger_init(struct event_trigger_data *data);
15921590 extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
15931591 int trigger_enable);
15941592 extern void update_cond_flag(struct trace_event_file *file);
@@ -1629,10 +1627,11 @@ extern void event_trigger_reset_filter(struct event_command *cmd_ops, · 34 unmodified lines
16291627 extern int event_trigger_register(struct event_command *cmd_ops,
16301628 struct trace_event_file *file,
16311629 char *glob,
1632− char *cmd,
1633− char *trigger,
1634− struct event_trigger_data *trigger_data,
1635− int *n_registered);
1630+ struct event_trigger_data *trigger_data);
1631+extern void event_trigger_unregister(struct event_command *cmd_ops,
1632+ struct trace_event_file *file,
1633+ char *glob,
1634+ struct event_trigger_data *trigger_data);
16361635
16371636 /**
16381637 * struct event_trigger_ops - callbacks for trace event triggers
@@ -1686,12 +1685,9 @@ struct event_trigger_ops { · 47 unmodified lines
16861685 struct trace_buffer *buffer,
16871686 void *rec,
16881687 struct ring_buffer_event *rbe);
1689− int (*init)(struct event_trigger_ops *ops,
1690− struct event_trigger_data *data);
1691− void (*free)(struct event_trigger_ops *ops,
1692− struct event_trigger_data *data);
1688+ int (*init)(struct event_trigger_data *data);
1689+ void (*free)(struct event_trigger_data *data);
16931690 int (*print)(struct seq_file *m,
1694− struct event_trigger_ops *ops,
16951691 struct event_trigger_data *data);
16961692 };
16971693
kernel/trace/trace_boot.c+1−1
@@ -300,7 +300,7 @@ trace_boot_hist_add_handlers(struct xbc_node *hnode, char **bufp, · 299 unmodified lines
300300 {
301301 struct xbc_node *node;
302302 const char *p, *handler;
303− int ret;
303+ int ret = 0;
304304
305305 handler = xbc_node_get_data(hnode);
306306
kernel/trace/trace_dynevent.c+2−7
@@ -255,19 +255,14 @@ static const struct file_operations dynamic_events_ops = { · 254 unmodified lines
255255 /* Make a tracefs interface for controlling dynamic events */
256256 static __init int init_dynamic_event(void)
257257 {
258− struct dentry *entry;
259258 int ret;
260259
261260 ret = tracing_init_dentry();
262261 if (ret)
263262 return 0;
264263
265− entry = tracefs_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,
266− NULL, &dynamic_events_ops);
267−
268− /* Event list interface */
269− if (!entry)
270− pr_warn("Could not create tracefs 'dynamic_events' entry\n");
264+ trace_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,
265+ NULL, &dynamic_events_ops);
271266
272267 return 0;
273268 }
kernel/trace/trace_eprobe.c+12−12
@@ -511,20 +511,17 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec) · 510 unmodified lines
511511 * functions are just stubs to fulfill what is needed to use the trigger
512512 * infrastructure.
513513 */
514−static int eprobe_trigger_init(struct event_trigger_ops *ops,
515− struct event_trigger_data *data)
514+static int eprobe_trigger_init(struct event_trigger_data *data)
516515 {
517516 return 0;
518517 }
519518
520−static void eprobe_trigger_free(struct event_trigger_ops *ops,
521− struct event_trigger_data *data)
519+static void eprobe_trigger_free(struct event_trigger_data *data)
522520 {
523521
524522 }
525523
526524 static int eprobe_trigger_print(struct seq_file *m,
527− struct event_trigger_ops *ops,
528525 struct event_trigger_data *data)
529526 {
530527 /* Do not print eprobe event triggers */
@@ -549,7 +546,8 @@ static struct event_trigger_ops eprobe_trigger_ops = { · 18 unmodified lines
549546
550547 static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops,
551548 struct trace_event_file *file,
552− char *glob, char *cmd, char *param)
549+ char *glob, char *cmd,
550+ char *param_and_filter)
553551 {
554552 return -1;
555553 }
@@ -650,7 +648,7 @@ static struct trace_event_functions eprobe_funcs = { · 94 unmodified lines
650648 static int disable_eprobe(struct trace_eprobe *ep,
651649 struct trace_array *tr)
652650 {
653− struct event_trigger_data *trigger;
651+ struct event_trigger_data *trigger = NULL, *iter;
654652 struct trace_event_file *file;
655653 struct eprobe_data *edata;
656654
@@ -658,14 +656,16 @@ static int disable_eprobe(struct trace_eprobe *ep, · 1 unmodified line
658656 if (!file)
659657 return -ENOENT;
660658
661− list_for_each_entry(trigger, &file->triggers, list) {
662− if (!(trigger->flags & EVENT_TRIGGER_FL_PROBE))
659+ list_for_each_entry(iter, &file->triggers, list) {
660+ if (!(iter->flags & EVENT_TRIGGER_FL_PROBE))
663661 continue;
664− edata = trigger->private_data;
665− if (edata->ep == ep)
662+ edata = iter->private_data;
663+ if (edata->ep == ep) {
664+ trigger = iter;
666665 break;
666+ }
667667 }
668− if (list_entry_is_head(trigger, &file->triggers, list))
668+ if (!trigger)
669669 return -ENODEV;
670670
671671 list_del_rcu(&trigger->list);
kernel/trace/trace_events.c+30−39
@@ -392,12 +392,6 @@ static void test_event_printk(struct trace_event_call *call) · 391 unmodified lines
392392 if (!(dereference_flags & (1ULL << arg)))
393393 goto next_arg;
394394
395− /* Check for __get_sockaddr */;
396− if (str_has_prefix(fmt + i, "__get_sockaddr(")) {
397− dereference_flags &= ~(1ULL << arg);
398− goto next_arg;
399− }
400−
401395 /* Find the REC-> in the argument */
402396 c = strchr(fmt + i, ',');
403397 r = strstr(fmt + i, "REC->");
@@ -413,7 +407,14 @@ static void test_event_printk(struct trace_event_call *call) · 9 unmodified lines
413407 a = strchr(fmt + i, '&');
414408 if ((a && (a < r)) || test_field(r, call))
415409 dereference_flags &= ~(1ULL << arg);
410+ } else if ((r = strstr(fmt + i, "__get_dynamic_array(")) &&
411+ (!c || r < c)) {
412+ dereference_flags &= ~(1ULL << arg);
413+ } else if ((r = strstr(fmt + i, "__get_sockaddr(")) &&
414+ (!c || r < c)) {
415+ dereference_flags &= ~(1ULL << arg);
416416 }
417+
417418 next_arg:
418419 i--;
419420 arg++;
@@ -1723,9 +1724,9 @@ static LIST_HEAD(event_subsystems); · 1303 unmodified lines
17231724
17241725 static int subsystem_open(struct inode *inode, struct file *filp)
17251726 {
1727+ struct trace_subsystem_dir *dir = NULL, *iter_dir;
1728+ struct trace_array *tr = NULL, *iter_tr;
17261729 struct event_subsystem *system = NULL;
1727− struct trace_subsystem_dir *dir = NULL; /* Initialize for gcc */
1728− struct trace_array *tr;
17291730 int ret;
17301731
17311732 if (tracing_is_disabled())
@@ -1734,10 +1735,12 @@ static int subsystem_open(struct inode *inode, struct file *filp) · 2 unmodified lines
17341735 /* Make sure the system still exists */
17351736 mutex_lock(&event_mutex);
17361737 mutex_lock(&trace_types_lock);
1737− list_for_each_entry(tr, &ftrace_trace_arrays, list) {
1738− list_for_each_entry(dir, &tr->systems, list) {
1739− if (dir == inode->i_private) {
1738+ list_for_each_entry(iter_tr, &ftrace_trace_arrays, list) {
1739+ list_for_each_entry(iter_dir, &iter_tr->systems, list) {
1740+ if (iter_dir == inode->i_private) {
17401741 /* Don't open systems with no events */
1742+ tr = iter_tr;
1743+ dir = iter_dir;
17411744 if (dir->nr_events) {
17421745 __get_system_dir(dir);
17431746 system = dir->subsystem;
@@ -1753,9 +1756,6 @@ static int subsystem_open(struct inode *inode, struct file *filp) · 9 unmodified lines
17531756 if (!system)
17541757 return -ENODEV;
17551758
1756− /* Some versions of gcc think dir can be uninitialized here */
1757− WARN_ON(!dir);
1758−
17591759 /* Still need to increment the ref count of the system */
17601760 if (trace_array_get(tr) < 0) {
17611761 put_system(dir);
@@ -2280,8 +2280,8 @@ static struct dentry * · 518 unmodified lines
22802280 event_subsystem_dir(struct trace_array *tr, const char *name,
22812281 struct trace_event_file *file, struct dentry *parent)
22822282 {
2283+ struct event_subsystem *system, *iter;
22832284 struct trace_subsystem_dir *dir;
2284− struct event_subsystem *system;
22852285 struct dentry *entry;
22862286
22872287 /* First see if we did not already create this dir */
@@ -2295,13 +2295,13 @@ event_subsystem_dir(struct trace_array *tr, const char *name, · 7 unmodified lines
22952295 }
22962296
22972297 /* Now see if the system itself exists. */
2298− list_for_each_entry(system, &event_subsystems, list) {
2299− if (strcmp(system->name, name) == 0)
2298+ system = NULL;
2299+ list_for_each_entry(iter, &event_subsystems, list) {
2300+ if (strcmp(iter->name, name) == 0) {
2301+ system = iter;
23002302 break;
2303+ }
23012304 }
2302− /* Reset system variable when not found */
2303− if (&system->list == &event_subsystems)
2304− system = NULL;
23052305
23062306 dir = kmalloc(sizeof(*dir), GFP_KERNEL);
23072307 if (!dir)
@@ -3546,12 +3546,10 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) · 1238 unmodified lines
35463546 struct dentry *d_events;
35473547 struct dentry *entry;
35483548
3549− entry = tracefs_create_file("set_event", TRACE_MODE_WRITE, parent,
3550− tr, &ftrace_set_event_fops);
3551− if (!entry) {
3552− pr_warn("Could not create tracefs 'set_event' entry\n");
3549+ entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent,
3550+ tr, &ftrace_set_event_fops);
3551+ if (!entry)
35533552 return -ENOMEM;
3554− }
35553553
35563554 d_events = tracefs_create_dir("events", parent);
35573555 if (!d_events) {
@@ -3566,16 +3564,12 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) · 8 unmodified lines
35663564
35673565 /* There are not as crucial, just warn if they are not created */
35683566
3569− entry = tracefs_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
3570− tr, &ftrace_set_event_pid_fops);
3571− if (!entry)
3572− pr_warn("Could not create tracefs 'set_event_pid' entry\n");
3567+ trace_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
3568+ tr, &ftrace_set_event_pid_fops);
35733569
3574− entry = tracefs_create_file("set_event_notrace_pid",
3575− TRACE_MODE_WRITE, parent, tr,
3576− &ftrace_set_event_notrace_pid_fops);
3577− if (!entry)
3578− pr_warn("Could not create tracefs 'set_event_notrace_pid' entry\n");
3570+ trace_create_file("set_event_notrace_pid",
3571+ TRACE_MODE_WRITE, parent, tr,
3572+ &ftrace_set_event_notrace_pid_fops);
35793573
35803574 /* ring buffer internal formats */
35813575 trace_create_file("header_page", TRACE_MODE_READ, d_events,
@@ -3790,17 +3784,14 @@ static __init int event_trace_init_fields(void) · 208 unmodified lines
37903784 __init int event_trace_init(void)
37913785 {
37923786 struct trace_array *tr;
3793− struct dentry *entry;
37943787 int ret;
37953788
37963789 tr = top_trace_array();
37973790 if (!tr)
37983791 return -ENODEV;
37993792
3800− entry = tracefs_create_file("available_events", TRACE_MODE_READ,
3801− NULL, tr, &ftrace_avail_fops);
3802− if (!entry)
3803− pr_warn("Could not create tracefs 'available_events' entry\n");
3793+ trace_create_file("available_events", TRACE_MODE_READ,
3794+ NULL, tr, &ftrace_avail_fops);
38043795
38053796 ret = early_event_add_tracer(NULL, tr);
38063797 if (ret)
kernel/trace/trace_events_filter.c+1−1
@@ -1816,7 +1816,7 @@ static void create_filter_finish(struct filter_parse_error *pe) · 1815 unmodified lines
18161816 * create_filter - create a filter for a trace_event_call
18171817 * @tr: the trace array associated with these events
18181818 * @call: trace_event_call to create a filter for
1819− * @filter_str: filter string
1819+ * @filter_string: filter string
18201820 * @set_str: remember @filter_str and enable detailed error in filter
18211821 * @filterp: out param for created filter (always updated on return)
18221822 * Must be a pointer that references a NULL pointer.
kernel/trace/trace_events_hist.c+99−92
@@ -2093,8 +2093,11 @@ static int init_var_ref(struct hist_field *ref_field, · 2092 unmodified lines
20932093 return err;
20942094 free:
20952095 kfree(ref_field->system);
2096+ ref_field->system = NULL;
20962097 kfree(ref_field->event_name);
2098+ ref_field->event_name = NULL;
20972099 kfree(ref_field->name);
2100+ ref_field->name = NULL;
20982101
20992102 goto out;
21002103 }
@@ -2785,7 +2788,8 @@ static char *find_trigger_filter(struct hist_trigger_data *hist_data, · 684 unmodified lines
27852788 static struct event_command trigger_hist_cmd;
27862789 static int event_hist_trigger_parse(struct event_command *cmd_ops,
27872790 struct trace_event_file *file,
2788− char *glob, char *cmd, char *param);
2791+ char *glob, char *cmd,
2792+ char *param_and_filter);
27892793
27902794 static bool compatible_keys(struct hist_trigger_data *target_hist_data,
27912795 struct hist_trigger_data *hist_data,
@@ -4161,7 +4165,7 @@ static int create_val_field(struct hist_trigger_data *hist_data, · 1369 unmodified lines
41614165 return __create_val_field(hist_data, val_idx, file, NULL, field_str, 0);
41624166 }
41634167
4164−static const char *no_comm = "(no comm)";
4168+static const char no_comm[] = "(no comm)";
41654169
41664170 static u64 hist_field_execname(struct hist_field *hist_field,
41674171 struct tracing_map_elt *elt,
@@ -5252,7 +5256,7 @@ static void hist_trigger_show(struct seq_file *m, · 1084 unmodified lines
52525256 seq_puts(m, "\n\n");
52535257
52545258 seq_puts(m, "# event histogram\n#\n# trigger info: ");
5255− data->ops->print(m, data->ops, data);
5259+ data->ops->print(m, data);
52565260 seq_puts(m, "#\n\n");
52575261
52585262 hist_data = data->private_data;
@@ -5484,7 +5488,7 @@ static void hist_trigger_debug_show(struct seq_file *m, · 225 unmodified lines
54845488 seq_puts(m, "\n\n");
54855489
54865490 seq_puts(m, "# event histogram\n#\n# trigger info: ");
5487− data->ops->print(m, data->ops, data);
5491+ data->ops->print(m, data);
54885492 seq_puts(m, "#\n\n");
54895493
54905494 hist_data = data->private_data;
@@ -5621,7 +5625,6 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) · 130 unmodified lines
56215625 }
56225626
56235627 static int event_hist_trigger_print(struct seq_file *m,
5624− struct event_trigger_ops *ops,
56255628 struct event_trigger_data *data)
56265629 {
56275630 struct hist_trigger_data *hist_data = data->private_data;
@@ -5729,8 +5732,7 @@ static int event_hist_trigger_print(struct seq_file *m, · 101 unmodified lines
57295732 return 0;
57305733 }
57315734
5732−static int event_hist_trigger_init(struct event_trigger_ops *ops,
5733− struct event_trigger_data *data)
5735+static int event_hist_trigger_init(struct event_trigger_data *data)
57345736 {
57355737 struct hist_trigger_data *hist_data = data->private_data;
57365738
@@ -5758,8 +5760,7 @@ static void unregister_field_var_hists(struct hist_trigger_data *hist_data) · 21 unmodified lines
57585760 }
57595761 }
57605762
5761−static void event_hist_trigger_free(struct event_trigger_ops *ops,
5762− struct event_trigger_data *data)
5763+static void event_hist_trigger_free(struct event_trigger_data *data)
57635764 {
57645765 struct hist_trigger_data *hist_data = data->private_data;
57655766
@@ -5788,25 +5789,23 @@ static struct event_trigger_ops event_hist_trigger_ops = { · 22 unmodified lines
57885789 .free = event_hist_trigger_free,
57895790 };
57905791
5791−static int event_hist_trigger_named_init(struct event_trigger_ops *ops,
5792− struct event_trigger_data *data)
5792+static int event_hist_trigger_named_init(struct event_trigger_data *data)
57935793 {
57945794 data->ref++;
57955795
57965796 save_named_trigger(data->named_data->name, data);
57975797
5798− event_hist_trigger_init(ops, data->named_data);
5798+ event_hist_trigger_init(data->named_data);
57995799
58005800 return 0;
58015801 }
58025802
5803−static void event_hist_trigger_named_free(struct event_trigger_ops *ops,
5804− struct event_trigger_data *data)
5803+static void event_hist_trigger_named_free(struct event_trigger_data *data)
58055804 {
58065805 if (WARN_ON_ONCE(data->ref <= 0))
58075806 return;
58085807
5809− event_hist_trigger_free(ops, data->named_data);
5808+ event_hist_trigger_free(data->named_data);
58105809
58115810 data->ref--;
58125811 if (!data->ref) {
@@ -5933,6 +5932,48 @@ static bool hist_trigger_match(struct event_trigger_data *data, · 120 unmodified lines
59335932 return true;
59345933 }
59355934
5935+static bool existing_hist_update_only(char *glob,
5936+ struct event_trigger_data *data,
5937+ struct trace_event_file *file)
5938+{
5939+ struct hist_trigger_data *hist_data = data->private_data;
5940+ struct event_trigger_data *test, *named_data = NULL;
5941+ bool updated = false;
5942+
5943+ if (!hist_data->attrs->pause && !hist_data->attrs->cont &&
5944+ !hist_data->attrs->clear)
5945+ goto out;
5946+
5947+ if (hist_data->attrs->name) {
5948+ named_data = find_named_trigger(hist_data->attrs->name);
5949+ if (named_data) {
5950+ if (!hist_trigger_match(data, named_data, named_data,
5951+ true))
5952+ goto out;
5953+ }
5954+ }
5955+
5956+ if (hist_data->attrs->name && !named_data)
5957+ goto out;
5958+
5959+ list_for_each_entry(test, &file->triggers, list) {
5960+ if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
5961+ if (!hist_trigger_match(data, test, named_data, false))
5962+ continue;
5963+ if (hist_data->attrs->pause)
5964+ test->paused = true;
5965+ else if (hist_data->attrs->cont)
5966+ test->paused = false;
5967+ else if (hist_data->attrs->clear)
5968+ hist_clear(test);
5969+ updated = true;
5970+ goto out;
5971+ }
5972+ }
5973+ out:
5974+ return updated;
5975+}
5976+
59365977 static int hist_register_trigger(char *glob,
59375978 struct event_trigger_data *data,
59385979 struct trace_event_file *file)
@@ -5961,19 +6002,11 @@ static int hist_register_trigger(char *glob, · 22 unmodified lines
59616002
59626003 list_for_each_entry(test, &file->triggers, list) {
59636004 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
5964− if (!hist_trigger_match(data, test, named_data, false))
5965− continue;
5966− if (hist_data->attrs->pause)
5967− test->paused = true;
5968− else if (hist_data->attrs->cont)
5969− test->paused = false;
5970− else if (hist_data->attrs->clear)
5971− hist_clear(test);
5972− else {
6005+ if (hist_trigger_match(data, test, named_data, false)) {
59736006 hist_err(tr, HIST_ERR_TRIGGER_EEXIST, 0);
59746007 ret = -EEXIST;
6008+ goto out;
59756009 }
5976− goto out;
59776010 }
59786011 }
59796012 new:
@@ -5993,7 +6026,7 @@ static int hist_register_trigger(char *glob, · 13 unmodified lines
59936026 }
59946027
59956028 if (data->ops->init) {
5996− ret = data->ops->init(data->ops, data);
6029+ ret = data->ops->init(data);
59976030 if (ret < 0)
59986031 goto out;
59996032 }
@@ -6012,8 +6045,6 @@ static int hist_register_trigger(char *glob, · 12 unmodified lines
60126045
60136046 if (named_data)
60146047 destroy_hist_data(hist_data);
6015−
6016− ret++;
60176048 out:
60186049 return ret;
60196050 }
@@ -6089,20 +6120,19 @@ static void hist_unregister_trigger(char *glob, · 69 unmodified lines
60896120 struct event_trigger_data *data,
60906121 struct trace_event_file *file)
60916122 {
6123+ struct event_trigger_data *test = NULL, *iter, *named_data = NULL;
60926124 struct hist_trigger_data *hist_data = data->private_data;
6093− struct event_trigger_data *test, *named_data = NULL;
6094− bool unregistered = false;
60956125
60966126 lockdep_assert_held(&event_mutex);
60976127
60986128 if (hist_data->attrs->name)
60996129 named_data = find_named_trigger(hist_data->attrs->name);
61006130
6101− list_for_each_entry(test, &file->triggers, list) {
6102− if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
6103− if (!hist_trigger_match(data, test, named_data, false))
6131+ list_for_each_entry(iter, &file->triggers, list) {
6132+ if (iter->cmd_ops->trigger_type == ETT_EVENT_HIST) {
6133+ if (!hist_trigger_match(data, iter, named_data, false))
61046134 continue;
6105− unregistered = true;
6135+ test = iter;
61066136 list_del_rcu(&test->list);
61076137 trace_event_trigger_enable_disable(file, 0);
61086138 update_cond_flag(file);
@@ -6110,11 +6140,11 @@ static void hist_unregister_trigger(char *glob, · 1 unmodified line
61106140 }
61116141 }
61126142
6113− if (unregistered && test->ops->free)
6114− test->ops->free(test->ops, test);
6143+ if (test && test->ops->free)
6144+ test->ops->free(test);
61156145
61166146 if (hist_data->enable_timestamps) {
6117− if (!hist_data->remove || unregistered)
6147+ if (!hist_data->remove || test)
61186148 tracing_set_filter_buffering(file->tr, false);
61196149 }
61206150 }
@@ -6164,57 +6194,57 @@ static void hist_unreg_all(struct trace_event_file *file) · 43 unmodified lines
61646194 if (hist_data->enable_timestamps)
61656195 tracing_set_filter_buffering(file->tr, false);
61666196 if (test->ops->free)
6167− test->ops->free(test->ops, test);
6197+ test->ops->free(test);
61686198 }
61696199 }
61706200 }
61716201
61726202 static int event_hist_trigger_parse(struct event_command *cmd_ops,
61736203 struct trace_event_file *file,
6174− char *glob, char *cmd, char *param)
6204+ char *glob, char *cmd,
6205+ char *param_and_filter)
61756206 {
61766207 unsigned int hist_trigger_bits = TRACING_MAP_BITS_DEFAULT;
61776208 struct event_trigger_data *trigger_data;
61786209 struct hist_trigger_attrs *attrs;
6179− struct event_trigger_ops *trigger_ops;
61806210 struct hist_trigger_data *hist_data;
6211+ char *param, *filter, *p, *start;
61816212 struct synth_event *se;
61826213 const char *se_name;
6183− bool remove = false;
6184− char *trigger, *p, *start;
6214+ bool remove;
61856215 int ret = 0;
61866216
61876217 lockdep_assert_held(&event_mutex);
61886218
6189− WARN_ON(!glob);
6219+ if (WARN_ON(!glob))
6220+ return -EINVAL;
61906221
6191− if (strlen(glob)) {
6222+ if (glob[0]) {
61926223 hist_err_clear();
6193− last_cmd_set(file, param);
6224+ last_cmd_set(file, param_and_filter);
61946225 }
61956226
6196− if (!param)
6197− return -EINVAL;
6227+ remove = event_trigger_check_remove(glob);
61986228
6199− if (glob[0] == '!')
6200− remove = true;
6229+ if (event_trigger_empty_param(param_and_filter))
6230+ return -EINVAL;
62016231
62026232 /*
62036233 * separate the trigger from the filter (k:v [if filter])
62046234 * allowing for whitespace in the trigger
62056235 */
6206− p = trigger = param;
6236+ p = param = param_and_filter;
62076237 do {
62086238 p = strstr(p, "if");
62096239 if (!p)
62106240 break;
6211− if (p == param)
6241+ if (p == param_and_filter)
62126242 return -EINVAL;
62136243 if (*(p - 1) != ' ' && *(p - 1) != '\t') {
62146244 p++;
62156245 continue;
62166246 }
6217− if (p >= param + strlen(param) - (sizeof("if") - 1) - 1)
6247+ if (p >= param_and_filter + strlen(param_and_filter) - (sizeof("if") - 1) - 1)
62186248 return -EINVAL;
62196249 if (*(p + sizeof("if") - 1) != ' ' && *(p + sizeof("if") - 1) != '\t') {
62206250 p++;
@@ -6224,24 +6254,24 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 3 unmodified lines
62246254 } while (1);
62256255
62266256 if (!p)
6227− param = NULL;
6257+ filter = NULL;
62286258 else {
62296259 *(p - 1) = '\0';
6230− param = strstrip(p);
6231− trigger = strstrip(trigger);
6260+ filter = strstrip(p);
6261+ param = strstrip(param);
62326262 }
62336263
62346264 /*
62356265 * To simplify arithmetic expression parsing, replace occurrences of
62366266 * '.sym-offset' modifier with '.symXoffset'
62376267 */
6238− start = strstr(trigger, ".sym-offset");
6268+ start = strstr(param, ".sym-offset");
62396269 while (start) {
62406270 *(start + 4) = 'X';
62416271 start = strstr(start + 11, ".sym-offset");
62426272 }
62436273
6244− attrs = parse_hist_trigger_attrs(file->tr, trigger);
6274+ attrs = parse_hist_trigger_attrs(file->tr, param);
62456275 if (IS_ERR(attrs))
62466276 return PTR_ERR(attrs);
62476277
@@ -6254,29 +6284,15 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 6 unmodified lines
62546284 return PTR_ERR(hist_data);
62556285 }
62566286
6257− trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
6258−
6259− trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
6287+ trigger_data = event_trigger_alloc(cmd_ops, cmd, param, hist_data);
62606288 if (!trigger_data) {
62616289 ret = -ENOMEM;
62626290 goto out_free;
62636291 }
62646292
6265− trigger_data->count = -1;
6266− trigger_data->ops = trigger_ops;
6267− trigger_data->cmd_ops = cmd_ops;
6268−
6269− INIT_LIST_HEAD(&trigger_data->list);
6270− RCU_INIT_POINTER(trigger_data->filter, NULL);
6271−
6272− trigger_data->private_data = hist_data;
6273−
6274− /* if param is non-empty, it's supposed to be a filter */
6275− if (param && cmd_ops->set_filter) {
6276− ret = cmd_ops->set_filter(param, trigger_data, file);
6277− if (ret < 0)
6278− goto out_free;
6279− }
6293+ ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
6294+ if (ret < 0)
6295+ goto out_free;
62806296
62816297 if (remove) {
62826298 if (!have_hist_trigger_match(trigger_data, file))
@@ -6287,7 +6303,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 4 unmodified lines
62876303 goto out_free;
62886304 }
62896305
6290− cmd_ops->unreg(glob+1, trigger_data, file);
6306+ event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
62916307 se_name = trace_event_name(file->event_call);
62926308 se = find_synth_event(se_name);
62936309 if (se)
@@ -6296,17 +6312,11 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 2 unmodified lines
62966312 goto out_free;
62976313 }
62986314
6299− ret = cmd_ops->reg(glob, trigger_data, file);
6300− /*
6301− * The above returns on success the # of triggers registered,
6302− * but if it didn't register any it returns zero. Consider no
6303− * triggers registered a failure too.
6304− */
6305− if (!ret) {
6306− if (!(attrs->pause || attrs->cont || attrs->clear))
6307− ret = -ENOENT;
6315+ if (existing_hist_update_only(glob, trigger_data, file))
63086316 goto out_free;
6309− } else if (ret < 0)
6317+
6318+ ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
6319+ if (ret < 0)
63106320 goto out_free;
63116321
63126322 if (get_named_trigger_data(trigger_data))
@@ -6331,18 +6341,15 @@ enable: · 18 unmodified lines
63316341 se = find_synth_event(se_name);
63326342 if (se)
63336343 se->ref++;
6334− /* Just return zero, not the number of registered triggers */
6335− ret = 0;
63366344 out:
63376345 if (ret == 0)
63386346 hist_err_clear();
63396347
63406348 return ret;
63416349 out_unreg:
6342− cmd_ops->unreg(glob+1, trigger_data, file);
6350+ event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
63436351 out_free:
6344− if (cmd_ops->set_filter)
6345− cmd_ops->set_filter(NULL, trigger_data, NULL);
6352+ event_trigger_reset_filter(cmd_ops, trigger_data);
63466353
63476354 remove_hist_vars(hist_data);
63486355
@@ -6463,7 +6470,7 @@ static void hist_enable_unreg_all(struct trace_event_file *file) · 114 unmodified lines
64636470 update_cond_flag(file);
64646471 trace_event_trigger_enable_disable(file, 0);
64656472 if (test->ops->free)
6466− test->ops->free(test->ops, test);
6473+ test->ops->free(test);
64676474 }
64686475 }
64696476 }
kernel/trace/trace_events_trigger.c+108−216
@@ -188,7 +188,7 @@ static int trigger_show(struct seq_file *m, void *v) · 187 unmodified lines
188188 }
189189
190190 data = list_entry(v, struct event_trigger_data, list);
191− data->ops->print(m, data->ops, data);
191+ data->ops->print(m, data);
192192
193193 return 0;
194194 }
@@ -432,7 +432,6 @@ event_trigger_print(const char *name, struct seq_file *m, · 237 unmodified lines
432432
433433 /**
434434 * event_trigger_init - Generic event_trigger_ops @init implementation
435− * @ops: The trigger ops associated with the trigger
436435 * @data: Trigger-specific data
437436 *
438437 * Common implementation of event trigger initialization.
@@ -442,8 +441,7 @@ event_trigger_print(const char *name, struct seq_file *m, · 3 unmodified lines
442441 *
443442 * Return: 0 on success, errno otherwise
444443 */
445−int event_trigger_init(struct event_trigger_ops *ops,
446− struct event_trigger_data *data)
444+int event_trigger_init(struct event_trigger_data *data)
447445 {
448446 data->ref++;
449447 return 0;
@@ -451,7 +449,6 @@ int event_trigger_init(struct event_trigger_ops *ops, · 1 unmodified line
451449
452450 /**
453451 * event_trigger_free - Generic event_trigger_ops @free implementation
454− * @ops: The trigger ops associated with the trigger
455452 * @data: Trigger-specific data
456453 *
457454 * Common implementation of event trigger de-initialization.
@@ -460,8 +457,7 @@ int event_trigger_init(struct event_trigger_ops *ops, · 2 unmodified lines
460457 * implementations.
461458 */
462459 static void
463−event_trigger_free(struct event_trigger_ops *ops,
464− struct event_trigger_data *data)
460+event_trigger_free(struct event_trigger_data *data)
465461 {
466462 if (WARN_ON_ONCE(data->ref <= 0))
467463 return;
@@ -515,7 +511,7 @@ clear_event_triggers(struct trace_array *tr) · 47 unmodified lines
515511 trace_event_trigger_enable_disable(file, 0);
516512 list_del_rcu(&data->list);
517513 if (data->ops->free)
518− data->ops->free(data->ops, data);
514+ data->ops->free(data);
519515 }
520516 }
521517 }
@@ -581,19 +577,18 @@ static int register_trigger(char *glob, · 59 unmodified lines
581577 }
582578
583579 if (data->ops->init) {
584− ret = data->ops->init(data->ops, data);
580+ ret = data->ops->init(data);
585581 if (ret < 0)
586582 goto out;
587583 }
588584
589585 list_add_rcu(&data->list, &file->triggers);
590− ret++;
591586
592587 update_cond_flag(file);
593− if (trace_event_trigger_enable_disable(file, 1) < 0) {
588+ ret = trace_event_trigger_enable_disable(file, 1);
589+ if (ret < 0) {
594590 list_del_rcu(&data->list);
595591 update_cond_flag(file);
596− ret--;
597592 }
598593 out:
599594 return ret;
@@ -614,14 +609,13 @@ static void unregister_trigger(char *glob, · 14 unmodified lines
614609 struct event_trigger_data *test,
615610 struct trace_event_file *file)
616611 {
617− struct event_trigger_data *data;
618− bool unregistered = false;
612+ struct event_trigger_data *data = NULL, *iter;
619613
620614 lockdep_assert_held(&event_mutex);
621615
622− list_for_each_entry(data, &file->triggers, list) {
623− if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
624− unregistered = true;
616+ list_for_each_entry(iter, &file->triggers, list) {
617+ if (iter->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
618+ data = iter;
625619 list_del_rcu(&data->list);
626620 trace_event_trigger_enable_disable(file, 0);
627621 update_cond_flag(file);
@@ -629,8 +623,8 @@ static void unregister_trigger(char *glob, · 1 unmodified line
629623 }
630624 }
631625
632− if (unregistered && data->ops->free)
633− data->ops->free(data->ops, data);
626+ if (data && data->ops->free)
627+ data->ops->free(data);
634628 }
635629
636630 /*
@@ -744,15 +738,15 @@ bool event_trigger_empty_param(const char *param) · 107 unmodified lines
744738
745739 /**
746740 * event_trigger_separate_filter - separate an event trigger from a filter
747− * @param: The param string containing trigger and possibly filter
748− * @trigger: outparam, will be filled with a pointer to the trigger
741+ * @param_and_filter: String containing trigger and possibly filter
742+ * @param: outparam, will be filled with a pointer to the trigger
749743 * @filter: outparam, will be filled with a pointer to the filter
750744 * @param_required: Specifies whether or not the param string is required
751745 *
752746 * Given a param string of the form '[trigger] [if filter]', this
753747 * function separates the filter from the trigger and returns the
754− * trigger in *trigger and the filter in *filter. Either the *trigger
755− * or the *filter may be set to NULL by this function - if not set to
748+ * trigger in @param and the filter in @filter. Either the @param
749+ * or the @filter may be set to NULL by this function - if not set to
756750 * NULL, they will contain strings corresponding to the trigger and
757751 * filter.
758752 *
@@ -927,48 +921,37 @@ void event_trigger_reset_filter(struct event_command *cmd_ops, · 168 unmodified lines
927921 * @cmd_ops: The event_command operations for the trigger
928922 * @file: The event file for the trigger's event
929923 * @glob: The trigger command string, with optional remove(!) operator
930− * @cmd: The cmd string
931− * @param: The param string
932924 * @trigger_data: The trigger_data for the trigger
933− * @n_registered: optional outparam, the number of triggers registered
934925 *
935926 * Register an event trigger. The @cmd_ops are used to call the
936− * cmd_ops->reg() function which actually does the registration. The
937− * cmd_ops->reg() function returns the number of triggers registered,
938− * which is assigned to n_registered, if n_registered is non-NULL.
927+ * cmd_ops->reg() function which actually does the registration.
939928 *
940929 * Return: 0 on success, errno otherwise
941930 */
942931 int event_trigger_register(struct event_command *cmd_ops,
943932 struct trace_event_file *file,
944933 char *glob,
945− char *cmd,
946− char *param,
947− struct event_trigger_data *trigger_data,
948− int *n_registered)
934+ struct event_trigger_data *trigger_data)
949935 {
950− int ret;
951−
952− if (n_registered)
953− *n_registered = 0;
954−
955− ret = cmd_ops->reg(glob, trigger_data, file);
956− /*
957− * The above returns on success the # of functions enabled,
958− * but if it didn't find any functions it returns zero.
959− * Consider no functions a failure too.
960− */
961− if (!ret) {
962− cmd_ops->unreg(glob, trigger_data, file);
963− ret = -ENOENT;
964− } else if (ret > 0) {
965− if (n_registered)
966− *n_registered = ret;
967− /* Just return zero, not the number of enabled functions */
968− ret = 0;
969− }
936+ return cmd_ops->reg(glob, trigger_data, file);
937+}
970938
971− return ret;
939+/**
940+ * event_trigger_unregister - unregister an event trigger
941+ * @cmd_ops: The event_command operations for the trigger
942+ * @file: The event file for the trigger's event
943+ * @glob: The trigger command string, with optional remove(!) operator
944+ * @trigger_data: The trigger_data for the trigger
945+ *
946+ * Unregister an event trigger. The @cmd_ops are used to call the
947+ * cmd_ops->unreg() function which actually does the unregistration.
948+ */
949+void event_trigger_unregister(struct event_command *cmd_ops,
950+ struct trace_event_file *file,
951+ char *glob,
952+ struct event_trigger_data *trigger_data)
953+{
954+ cmd_ops->unreg(glob, trigger_data, file);
972955 }
973956
974957 /*
@@ -981,7 +964,7 @@ int event_trigger_register(struct event_command *cmd_ops, · 6 unmodified lines
981964 * @file: The trace_event_file associated with the event
982965 * @glob: The raw string used to register the trigger
983966 * @cmd: The cmd portion of the string used to register the trigger
984− * @param: The params portion of the string used to register the trigger
967+ * @param_and_filter: The param and filter portion of the string used to register the trigger
985968 *
986969 * Common implementation for event command parsing and trigger
987970 * instantiation.
@@ -994,94 +977,53 @@ int event_trigger_register(struct event_command *cmd_ops, · 6 unmodified lines
994977 static int
995978 event_trigger_parse(struct event_command *cmd_ops,
996979 struct trace_event_file *file,
997− char *glob, char *cmd, char *param)
980+ char *glob, char *cmd, char *param_and_filter)
998981 {
999982 struct event_trigger_data *trigger_data;
1000− struct event_trigger_ops *trigger_ops;
1001− char *trigger = NULL;
1002− char *number;
983+ char *param, *filter;
984+ bool remove;
1003985 int ret;
1004986
1005− /* separate the trigger from the filter (t:n [if filter]) */
1006− if (param && isdigit(param[0])) {
1007− trigger = strsep(&param, " \t");
1008− if (param) {
1009− param = skip_spaces(param);
1010− if (!*param)
1011− param = NULL;
1012− }
1013− }
987+ remove = event_trigger_check_remove(glob);
1014988
1015− trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
989+ ret = event_trigger_separate_filter(param_and_filter, &param, &filter, false);
990+ if (ret)
991+ return ret;
1016992
1017993 ret = -ENOMEM;
1018− trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
994+ trigger_data = event_trigger_alloc(cmd_ops, cmd, param, file);
1019995 if (!trigger_data)
1020996 goto out;
1021997
1022− trigger_data->count = -1;
1023− trigger_data->ops = trigger_ops;
1024− trigger_data->cmd_ops = cmd_ops;
1025− trigger_data->private_data = file;
1026− INIT_LIST_HEAD(&trigger_data->list);
1027− INIT_LIST_HEAD(&trigger_data->named_list);
1028−
1029− if (glob[0] == '!') {
1030− cmd_ops->unreg(glob+1, trigger_data, file);
998+ if (remove) {
999+ event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
10311000 kfree(trigger_data);
10321001 ret = 0;
10331002 goto out;
10341003 }
10351004
1036− if (trigger) {
1037− number = strsep(&trigger, ":");
1038−
1039− ret = -EINVAL;
1040− if (!strlen(number))
1041− goto out_free;
1042−
1043− /*
1044− * We use the callback data field (which is a pointer)
1045− * as our counter.
1046− */
1047− ret = kstrtoul(number, 0, &trigger_data->count);
1048− if (ret)
1049− goto out_free;
1050− }
1051−
1052− if (!param) /* if param is non-empty, it's supposed to be a filter */
1053− goto out_reg;
1054−
1055− if (!cmd_ops->set_filter)
1056− goto out_reg;
1005+ ret = event_trigger_parse_num(param, trigger_data);
1006+ if (ret)
1007+ goto out_free;
10571008
1058− ret = cmd_ops->set_filter(param, trigger_data, file);
1009+ ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
10591010 if (ret < 0)
10601011 goto out_free;
10611012
1062− out_reg:
10631013 /* Up the trigger_data count to make sure reg doesn't free it on failure */
1064− event_trigger_init(trigger_ops, trigger_data);
1065− ret = cmd_ops->reg(glob, trigger_data, file);
1066− /*
1067− * The above returns on success the # of functions enabled,
1068− * but if it didn't find any functions it returns zero.
1069− * Consider no functions a failure too.
1070− */
1071− if (!ret) {
1072− cmd_ops->unreg(glob, trigger_data, file);
1073− ret = -ENOENT;
1074− } else if (ret > 0)
1075− ret = 0;
1014+ event_trigger_init(trigger_data);
1015+
1016+ ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1017+ if (ret)
1018+ goto out_free;
10761019
10771020 /* Down the counter of trigger_data or free it if not used anymore */
1078− event_trigger_free(trigger_ops, trigger_data);
1021+ event_trigger_free(trigger_data);
10791022 out:
10801023 return ret;
10811024
10821025 out_free:
1083− if (cmd_ops->set_filter)
1084− cmd_ops->set_filter(NULL, trigger_data, NULL);
1026+ event_trigger_reset_filter(cmd_ops, trigger_data);
10851027 kfree(trigger_data);
10861028 goto out;
10871029 }
@@ -1401,16 +1343,14 @@ traceoff_count_trigger(struct event_trigger_data *data, · 313 unmodified lines
14011343 }
14021344
14031345 static int
1404−traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1405− struct event_trigger_data *data)
1346+traceon_trigger_print(struct seq_file *m, struct event_trigger_data *data)
14061347 {
14071348 return event_trigger_print("traceon", m, (void *)data->count,
14081349 data->filter_str);
14091350 }
14101351
14111352 static int
1412−traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1413− struct event_trigger_data *data)
1353+traceoff_trigger_print(struct seq_file *m, struct event_trigger_data *data)
14141354 {
14151355 return event_trigger_print("traceoff", m, (void *)data->count,
14161356 data->filter_str);
@@ -1521,8 +1461,7 @@ register_snapshot_trigger(char *glob, · 104 unmodified lines
15211461 }
15221462
15231463 static int
1524−snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1525− struct event_trigger_data *data)
1464+snapshot_trigger_print(struct seq_file *m, struct event_trigger_data *data)
15261465 {
15271466 return event_trigger_print("snapshot", m, (void *)data->count,
15281467 data->filter_str);
@@ -1617,8 +1556,7 @@ stacktrace_count_trigger(struct event_trigger_data *data, · 88 unmodified lines
16171556 }
16181557
16191558 static int
1620−stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
1621− struct event_trigger_data *data)
1559+stacktrace_trigger_print(struct seq_file *m, struct event_trigger_data *data)
16221560 {
16231561 return event_trigger_print("stacktrace", m, (void *)data->count,
16241562 data->filter_str);
@@ -1708,7 +1646,6 @@ event_enable_count_trigger(struct event_trigger_data *data, · 83 unmodified lines
17081646 }
17091647
17101648 int event_enable_trigger_print(struct seq_file *m,
1711− struct event_trigger_ops *ops,
17121649 struct event_trigger_data *data)
17131650 {
17141651 struct enable_trigger_data *enable_data = data->private_data;
@@ -1733,8 +1670,7 @@ int event_enable_trigger_print(struct seq_file *m, · 18 unmodified lines
17331670 return 0;
17341671 }
17351672
1736−void event_enable_trigger_free(struct event_trigger_ops *ops,
1737− struct event_trigger_data *data)
1673+void event_enable_trigger_free(struct event_trigger_data *data)
17381674 {
17391675 struct enable_trigger_data *enable_data = data->private_data;
17401676
@@ -1781,39 +1717,33 @@ static struct event_trigger_ops event_disable_count_trigger_ops = { · 40 unmodified lines
17811717
17821718 int event_enable_trigger_parse(struct event_command *cmd_ops,
17831719 struct trace_event_file *file,
1784− char *glob, char *cmd, char *param)
1720+ char *glob, char *cmd, char *param_and_filter)
17851721 {
17861722 struct trace_event_file *event_enable_file;
17871723 struct enable_trigger_data *enable_data;
17881724 struct event_trigger_data *trigger_data;
1789− struct event_trigger_ops *trigger_ops;
17901725 struct trace_array *tr = file->tr;
1726+ char *param, *filter;
1727+ bool enable, remove;
17911728 const char *system;
17921729 const char *event;
17931730 bool hist = false;
1794− char *trigger;
1795− char *number;
1796− bool enable;
17971731 int ret;
17981732
1799− if (!param)
1800− return -EINVAL;
1733+ remove = event_trigger_check_remove(glob);
18011734
1802− /* separate the trigger from the filter (s:e:n [if filter]) */
1803− trigger = strsep(&param, " \t");
1804− if (!trigger)
1735+ if (event_trigger_empty_param(param_and_filter))
18051736 return -EINVAL;
1806− if (param) {
1807− param = skip_spaces(param);
1808− if (!*param)
1809− param = NULL;
1810− }
18111737
1812− system = strsep(&trigger, ":");
1813− if (!trigger)
1738+ ret = event_trigger_separate_filter(param_and_filter, &param, &filter, true);
1739+ if (ret)
1740+ return ret;
1741+
1742+ system = strsep(&param, ":");
1743+ if (!param)
18141744 return -EINVAL;
18151745
1816− event = strsep(&trigger, ":");
1746+ event = strsep(&param, ":");
18171747
18181748 ret = -EINVAL;
18191749 event_enable_file = find_event_file(tr, system, event);
@@ -1829,32 +1759,24 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, · 9 unmodified lines
18291759 #else
18301760 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
18311761 #endif
1832− trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
1833−
18341762 ret = -ENOMEM;
1835− trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
1836− if (!trigger_data)
1837− goto out;
18381763
18391764 enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);
1840− if (!enable_data) {
1841− kfree(trigger_data);
1765+ if (!enable_data)
18421766 goto out;
1843− }
1844−
1845− trigger_data->count = -1;
1846− trigger_data->ops = trigger_ops;
1847− trigger_data->cmd_ops = cmd_ops;
1848− INIT_LIST_HEAD(&trigger_data->list);
1849− RCU_INIT_POINTER(trigger_data->filter, NULL);
18501767
18511768 enable_data->hist = hist;
18521769 enable_data->enable = enable;
18531770 enable_data->file = event_enable_file;
1854− trigger_data->private_data = enable_data;
18551771
1856− if (glob[0] == '!') {
1857− cmd_ops->unreg(glob+1, trigger_data, file);
1772+ trigger_data = event_trigger_alloc(cmd_ops, cmd, param, enable_data);
1773+ if (!trigger_data) {
1774+ kfree(enable_data);
1775+ goto out;
1776+ }
1777+
1778+ if (remove) {
1779+ event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
18581780 kfree(trigger_data);
18591781 kfree(enable_data);
18601782 ret = 0;
@@ -1862,35 +1784,16 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, · 1 unmodified line
18621784 }
18631785
18641786 /* Up the trigger_data count to make sure nothing frees it on failure */
1865− event_trigger_init(trigger_ops, trigger_data);
1866−
1867− if (trigger) {
1868− number = strsep(&trigger, ":");
1869−
1870− ret = -EINVAL;
1871− if (!strlen(number))
1872− goto out_free;
1873−
1874− /*
1875− * We use the callback data field (which is a pointer)
1876− * as our counter.
1877− */
1878− ret = kstrtoul(number, 0, &trigger_data->count);
1879− if (ret)
1880− goto out_free;
1881− }
1787+ event_trigger_init(trigger_data);
18821788
1883− if (!param) /* if param is non-empty, it's supposed to be a filter */
1884− goto out_reg;
1885−
1886− if (!cmd_ops->set_filter)
1887− goto out_reg;
1789+ ret = event_trigger_parse_num(param, trigger_data);
1790+ if (ret)
1791+ goto out_free;
18881792
1889− ret = cmd_ops->set_filter(param, trigger_data, file);
1793+ ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
18901794 if (ret < 0)
18911795 goto out_free;
18921796
1893− out_reg:
18941797 /* Don't let event modules unload while probe registered */
18951798 ret = trace_event_try_get_ref(event_enable_file->event_call);
18961799 if (!ret) {
@@ -1901,32 +1804,23 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, · 4 unmodified lines
19011804 ret = trace_event_enable_disable(event_enable_file, 1, 1);
19021805 if (ret < 0)
19031806 goto out_put;
1904− ret = cmd_ops->reg(glob, trigger_data, file);
1905− /*
1906− * The above returns on success the # of functions enabled,
1907− * but if it didn't find any functions it returns zero.
1908− * Consider no functions a failure too.
1909− */
1910− if (!ret) {
1911− ret = -ENOENT;
1912− goto out_disable;
1913− } else if (ret < 0)
1807+
1808+ ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1809+ if (ret)
19141810 goto out_disable;
1915− /* Just return zero, not the number of enabled functions */
1916− ret = 0;
1917− event_trigger_free(trigger_ops, trigger_data);
1811+
1812+ event_trigger_free(trigger_data);
19181813 out:
19191814 return ret;
1920−
19211815 out_disable:
19221816 trace_event_enable_disable(event_enable_file, 0, 1);
19231817 out_put:
19241818 trace_event_put_ref(event_enable_file->event_call);
19251819 out_free:
1926− if (cmd_ops->set_filter)
1927− cmd_ops->set_filter(NULL, trigger_data, NULL);
1928− event_trigger_free(trigger_ops, trigger_data);
1820+ event_trigger_reset_filter(cmd_ops, trigger_data);
1821+ event_trigger_free(trigger_data);
19291822 kfree(enable_data);
1823+
19301824 goto out;
19311825 }
19321826
@@ -1953,19 +1847,18 @@ int event_enable_register_trigger(char *glob, · 20 unmodified lines
19531847 }
19541848
19551849 if (data->ops->init) {
1956− ret = data->ops->init(data->ops, data);
1850+ ret = data->ops->init(data);
19571851 if (ret < 0)
19581852 goto out;
19591853 }
19601854
19611855 list_add_rcu(&data->list, &file->triggers);
1962− ret++;
19631856
19641857 update_cond_flag(file);
1965− if (trace_event_trigger_enable_disable(file, 1) < 0) {
1858+ ret = trace_event_trigger_enable_disable(file, 1);
1859+ if (ret < 0) {
19661860 list_del_rcu(&data->list);
19671861 update_cond_flag(file);
1968− ret--;
19691862 }
19701863 out:
19711864 return ret;
@@ -1976,19 +1869,18 @@ void event_enable_unregister_trigger(char *glob, · 4 unmodified lines
19761869 struct trace_event_file *file)
19771870 {
19781871 struct enable_trigger_data *test_enable_data = test->private_data;
1872+ struct event_trigger_data *data = NULL, *iter;
19791873 struct enable_trigger_data *enable_data;
1980− struct event_trigger_data *data;
1981− bool unregistered = false;
19821874
19831875 lockdep_assert_held(&event_mutex);
19841876
1985− list_for_each_entry(data, &file->triggers, list) {
1986− enable_data = data->private_data;
1877+ list_for_each_entry(iter, &file->triggers, list) {
1878+ enable_data = iter->private_data;
19871879 if (enable_data &&
1988− (data->cmd_ops->trigger_type ==
1880+ (iter->cmd_ops->trigger_type ==
19891881 test->cmd_ops->trigger_type) &&
19901882 (enable_data->file == test_enable_data->file)) {
1991− unregistered = true;
1883+ data = iter;
19921884 list_del_rcu(&data->list);
19931885 trace_event_trigger_enable_disable(file, 0);
19941886 update_cond_flag(file);
@@ -1996,8 +1888,8 @@ void event_enable_unregister_trigger(char *glob, · 1 unmodified line
19961888 }
19971889 }
19981890
1999− if (unregistered && data->ops->free)
2000− data->ops->free(data->ops, data);
1891+ if (data && data->ops->free)
1892+ data->ops->free(data);
20011893 }
20021894
20031895 static struct event_trigger_ops *
kernel/trace/trace_kprobe.c+4−11
@@ -1907,25 +1907,18 @@ core_initcall(init_kprobe_trace_early); · 1906 unmodified lines
19071907 static __init int init_kprobe_trace(void)
19081908 {
19091909 int ret;
1910− struct dentry *entry;
19111910
19121911 ret = tracing_init_dentry();
19131912 if (ret)
19141913 return 0;
19151914
1916− entry = tracefs_create_file("kprobe_events", TRACE_MODE_WRITE,
1917− NULL, NULL, &kprobe_events_ops);
1918−
19191915 /* Event list interface */
1920− if (!entry)
1921− pr_warn("Could not create tracefs 'kprobe_events' entry\n");
1916+ trace_create_file("kprobe_events", TRACE_MODE_WRITE,
1917+ NULL, NULL, &kprobe_events_ops);
19221918
19231919 /* Profile interface */
1924− entry = tracefs_create_file("kprobe_profile", TRACE_MODE_READ,
1925− NULL, NULL, &kprobe_profile_ops);
1926−
1927− if (!entry)
1928− pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
1920+ trace_create_file("kprobe_profile", TRACE_MODE_READ,
1921+ NULL, NULL, &kprobe_profile_ops);
19291922
19301923 setup_boot_kprobe_events();
19311924
kernel/trace/trace_osnoise.c+19−3
@@ -1578,11 +1578,27 @@ static enum hrtimer_restart timerlat_irq(struct hrtimer *timer) · 1577 unmodified lines
15781578
15791579 trace_timerlat_sample(&s);
15801580
1581− notify_new_max_latency(diff);
1581+ if (osnoise_data.stop_tracing) {
1582+ if (time_to_us(diff) >= osnoise_data.stop_tracing) {
1583+
1584+ /*
1585+ * At this point, if stop_tracing is set and <= print_stack,
1586+ * print_stack is set and would be printed in the thread handler.
1587+ *
1588+ * Thus, print the stack trace as it is helpful to define the
1589+ * root cause of an IRQ latency.
1590+ */
1591+ if (osnoise_data.stop_tracing <= osnoise_data.print_stack) {
1592+ timerlat_save_stack(0);
1593+ timerlat_dump_stack(time_to_us(diff));
1594+ }
15821595
1583− if (osnoise_data.stop_tracing)
1584− if (time_to_us(diff) >= osnoise_data.stop_tracing)
15851596 osnoise_stop_tracing();
1597+ notify_new_max_latency(diff);
1598+
1599+ return HRTIMER_NORESTART;
1600+ }
1601+ }
15861602
15871603 wake_up_process(tlat->kthread);
15881604
kernel/trace/trace_output.c+12−13
@@ -692,7 +692,7 @@ static LIST_HEAD(ftrace_event_list); · 691 unmodified lines
692692
693693 static int trace_search_list(struct list_head **list)
694694 {
695− struct trace_event *e;
695+ struct trace_event *e = NULL, *iter;
696696 int next = __TRACE_LAST_TYPE;
697697
698698 if (list_empty(&ftrace_event_list)) {
@@ -704,9 +704,11 @@ static int trace_search_list(struct list_head **list) · 5 unmodified lines
704704 * We used up all possible max events,
705705 * lets see if somebody freed one.
706706 */
707− list_for_each_entry(e, &ftrace_event_list, list) {
708− if (e->type != next)
707+ list_for_each_entry(iter, &ftrace_event_list, list) {
708+ if (iter->type != next) {
709+ e = iter;
709710 break;
711+ }
710712 next++;
711713 }
712714
@@ -714,7 +716,10 @@ static int trace_search_list(struct list_head **list) · 1 unmodified line
714716 if (next > TRACE_EVENT_TYPE_MAX)
715717 return 0;
716718
717− *list = &e->list;
719+ if (e)
720+ *list = &e->list;
721+ else
722+ *list = &ftrace_event_list;
718723 return next;
719724 }
720725
@@ -778,9 +783,8 @@ int register_trace_event(struct trace_event *event) · 57 unmodified lines
778783
779784 list_add_tail(&event->list, list);
780785
781− } else if (event->type > __TRACE_LAST_TYPE) {
782− printk(KERN_WARNING "Need to add type to trace.h\n");
783− WARN_ON(1);
786+ } else if (WARN(event->type > __TRACE_LAST_TYPE,
787+ "Need to add type to trace.h")) {
784788 goto out;
785789 } else {
786790 /* Is this event already used */
@@ -1571,13 +1575,8 @@ __init static int init_events(void) · 784 unmodified lines
15711575
15721576 for (i = 0; events[i]; i++) {
15731577 event = events[i];
1574−
15751578 ret = register_trace_event(event);
1576− if (!ret) {
1577− printk(KERN_WARNING "event %d failed to register\n",
1578− event->type);
1579− WARN_ON_ONCE(1);
1580− }
1579+ WARN_ONCE(!ret, "event %d failed to register", event->type);
15811580 }
15821581
15831582 return 0;
kernel/trace/trace_recursion_record.c+2−5
@@ -224,12 +224,9 @@ static const struct file_operations recursed_functions_fops = { · 223 unmodified lines
224224
225225 __init static int create_recursed_functions(void)
226226 {
227− struct dentry *dentry;
228227
229− dentry = trace_create_file("recursed_functions", TRACE_MODE_WRITE,
230− NULL, NULL, &recursed_functions_fops);
231− if (!dentry)
232− pr_warn("WARNING: Failed to create recursed_functions\n");
228+ trace_create_file("recursed_functions", TRACE_MODE_WRITE,
229+ NULL, NULL, &recursed_functions_fops);
233230 return 0;
234231 }
235232
kernel/trace/trace_selftest.c+3−0
@@ -895,6 +895,9 @@ trace_selftest_startup_function_graph(struct tracer *trace, · 894 unmodified lines
895895 ret = -1;
896896 goto out;
897897 }
898+
899+ /* Enable tracing on all functions again */
900+ ftrace_set_global_filter(NULL, 0, 1);
898901 #endif
899902
900903 /* Don't test dynamic tracing, the function tracer already did */
kernel/trace/trace_syscalls.c+11−24
@@ -154,7 +154,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags, · 153 unmodified lines
154154 goto end;
155155
156156 /* parameter types */
157− if (tr->trace_flags & TRACE_ITER_VERBOSE)
157+ if (tr && tr->trace_flags & TRACE_ITER_VERBOSE)
158158 trace_seq_printf(s, "%s ", entry->types[i]);
159159
160160 /* parameter values */
@@ -296,9 +296,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 135 unmodified lines
296296 struct trace_event_file *trace_file;
297297 struct syscall_trace_enter *entry;
298298 struct syscall_metadata *sys_data;
299− struct ring_buffer_event *event;
300− struct trace_buffer *buffer;
301− unsigned int trace_ctx;
299+ struct trace_event_buffer fbuffer;
302300 unsigned long args[6];
303301 int syscall_nr;
304302 int size;
@@ -321,20 +319,16 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 16 unmodified lines
321319
322320 size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;
323321
324− trace_ctx = tracing_gen_ctx();
325−
326− event = trace_event_buffer_lock_reserve(&buffer, trace_file,
327− sys_data->enter_event->event.type, size, trace_ctx);
328− if (!event)
322+ entry = trace_event_buffer_reserve(&fbuffer, trace_file, size);
323+ if (!entry)
329324 return;
330325
331− entry = ring_buffer_event_data(event);
326+ entry = ring_buffer_event_data(fbuffer.event);
332327 entry->nr = syscall_nr;
333328 syscall_get_arguments(current, regs, args);
334329 memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args);
335330
336− event_trigger_unlock_commit(trace_file, buffer, event, entry,
337− trace_ctx);
331+ trace_event_buffer_commit(&fbuffer);
338332 }
339333
340334 static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
@@ -343,9 +337,7 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) · 2 unmodified lines
343337 struct trace_event_file *trace_file;
344338 struct syscall_trace_exit *entry;
345339 struct syscall_metadata *sys_data;
346− struct ring_buffer_event *event;
347− struct trace_buffer *buffer;
348− unsigned int trace_ctx;
340+ struct trace_event_buffer fbuffer;
349341 int syscall_nr;
350342
351343 syscall_nr = trace_get_syscall_nr(current, regs);
@@ -364,20 +356,15 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) · 12 unmodified lines
364356 if (!sys_data)
365357 return;
366358
367− trace_ctx = tracing_gen_ctx();
368−
369− event = trace_event_buffer_lock_reserve(&buffer, trace_file,
370− sys_data->exit_event->event.type, sizeof(*entry),
371− trace_ctx);
372− if (!event)
359+ entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry));
360+ if (!entry)
373361 return;
374362
375− entry = ring_buffer_event_data(event);
363+ entry = ring_buffer_event_data(fbuffer.event);
376364 entry->nr = syscall_nr;
377365 entry->ret = syscall_get_return_value(current, regs);
378366
379− event_trigger_unlock_commit(trace_file, buffer, event, entry,
380− trace_ctx);
367+ trace_event_buffer_commit(&fbuffer);
381368 }
382369
383370 static int reg_event_syscall_enter(struct trace_event_file *file,
kernel/trace/tracing_map.c+2−1
@@ -1045,7 +1045,8 @@ static void sort_secondary(struct tracing_map *map, · 1044 unmodified lines
10451045 /**
10461046 * tracing_map_sort_entries - Sort the current set of tracing_map_elts in a map
10471047 * @map: The tracing_map
1048− * @sort_key: The sort key to use for sorting
1048+ * @sort_keys: The sort key to use for sorting
1049+ * @n_sort_keys: hitcount, always have at least one
10491050 * @sort_entries: outval: pointer to allocated and sorted array of entries
10501051 *
10511052 * tracing_map_sort_entries() sorts the current set of entries in the
lib/.gitignore+1−0
@@ -1,6 +1,7 @@
11 # SPDX-License-Identifier: GPL-2.0-only
22 /crc32table.h
33 /crc64table.h
4+/default.bconf
45 /gen_crc32table
56 /gen_crc64table
67 /oid_registry_data.c
lib/Makefile+9−1
@@ -281,7 +281,15 @@ $(foreach file, $(libfdt_files), \ · 280 unmodified lines
281281 $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
282282 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
283283
284−lib-$(CONFIG_BOOT_CONFIG) += bootconfig.o
284+obj-$(CONFIG_BOOT_CONFIG) += bootconfig.o
285+obj-$(CONFIG_BOOT_CONFIG_EMBED) += bootconfig-data.o
286+
287+$(obj)/bootconfig-data.o: $(obj)/default.bconf
288+
289+targets += default.bconf
290+filechk_defbconf = cat $(or $(real-prereqs), /dev/null)
291+$(obj)/default.bconf: $(CONFIG_BOOT_CONFIG_EMBED_FILE) FORCE
292+ $(call filechk,defbconf)
285293
286294 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
287295 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
lib/bootconfig-data.S+10−0
@@ -0,0 +1,10 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+/*
3+ * Embed default bootconfig in the kernel.
4+ */
5+ .section .init.rodata, "aw"
6+ .global embedded_bootconfig_data
7+embedded_bootconfig_data:
8+ .incbin "lib/default.bconf"
9+ .global embedded_bootconfig_data_end
10+embedded_bootconfig_data_end:
lib/bootconfig.c+13−0
@@ -12,6 +12,19 @@ · 11 unmodified lines
1212 #include <linux/kernel.h>
1313 #include <linux/memblock.h>
1414 #include <linux/string.h>
15+
16+#ifdef CONFIG_BOOT_CONFIG_EMBED
17+/* embedded_bootconfig_data is defined in bootconfig-data.S */
18+extern __visible const char embedded_bootconfig_data[];
19+extern __visible const char embedded_bootconfig_data_end[];
20+
21+const char * __init xbc_get_embedded_bootconfig(size_t *size)
22+{
23+ *size = embedded_bootconfig_data_end - embedded_bootconfig_data;
24+ return (*size) ? embedded_bootconfig_data : NULL;
25+}
26+#endif
27+
1528 #else /* !__KERNEL__ */
1629 /*
1730 * NOTE: This is only for tools/bootconfig, because tools/bootconfig will