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
158Boot Kernel With a Boot Config158Boot Kernel With a Boot Config
159==============================159==============================
160 160
161Since the boot configuration file is loaded with initrd, it will be added161There are two options to boot the kernel with bootconfig: attaching the
162to the end of the initrd (initramfs) image file with padding, size,162bootconfig to the initrd image or embedding it in the kernel itself.
163checksum and 12-byte magic word as below.163
164Attaching a Boot Config to Initrd
165---------------------------------
166
167Since the boot configuration file is loaded with initrd by default,
168it will be added to the end of the initrd (initramfs) image file with
169padding, size, checksum and 12-byte magic word as below.
164 170
165[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]171[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]
166 172
@@ -196,6 +202,25 @@ To remove the config from the image, you can use -d option as below:: · 29 unmodified lines
196Then add "bootconfig" on the normal kernel command line to tell the202Then add "bootconfig" on the normal kernel command line to tell the
197kernel to look for the bootconfig at the end of the initrd file.203kernel to look for the bootconfig at the end of the initrd file.
198 204
205Embedding a Boot Config into Kernel
206-----------------------------------
207
208If you can not use initrd, you can also embed the bootconfig file in the
209kernel by Kconfig options. In this case, you need to recompile the kernel
210with 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
216path to the bootconfig file from source tree or object tree.
217The kernel will embed it as the default bootconfig.
218
219Just as when attaching the bootconfig to the initrd, you need ``bootconfig``
220option on the kernel command line to enable the embedded bootconfig.
221
222Note that even if you set this option, you can override the embedded
223bootconfig by another bootconfig which attached to the initrd.
199 224
200Kernel parameters via Boot Config225Kernel parameters via Boot Config
201=================================226=================================
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
517 processing should be able to handle them. See comments in the517 processing should be able to handle them. See comments in the
518 ktime_get_boot_fast_ns() function for more information.518 ktime_get_boot_fast_ns() function for more information.
519 519
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
520 To set a clock, simply echo the clock name into this file::532 To set a clock, simply echo the clock name into this file::
521 533
522 # echo global > trace_clock534 # echo global > trace_clock
Documentation/trace/timerlat-tracer.rst+3−2
@@ -74,8 +74,9 @@ directory. The timerlat configs are: · 73 unmodified lines
74 - stop_tracing_total_us: stop the system tracing if a74 - stop_tracing_total_us: stop the system tracing if a
75 timer latency at the *thread* context is higher than the configured75 timer latency at the *thread* context is higher than the configured
76 value happens. Writing 0 disables this option.76 value happens. Writing 0 disables this option.
77 - print_stack: save the stack of the IRQ occurrence, and print77 - print_stack: save the stack of the IRQ occurrence. The stack is printed
78 it after the *thread context* event".78 after the *thread context* event, or at the IRQ handler if *stop_tracing_us*
79 is hit.
79 80
80timerlat and osnoise81timerlat and osnoise
81----------------------------82----------------------------
MAINTAINERS+3−2
@@ -7517,6 +7517,7 @@ S: Maintained · 7516 unmodified lines
7517F: Documentation/admin-guide/bootconfig.rst7517F: Documentation/admin-guide/bootconfig.rst
7518F: fs/proc/bootconfig.c7518F: fs/proc/bootconfig.c
7519F: include/linux/bootconfig.h7519F: include/linux/bootconfig.h
7520F: lib/bootconfig-data.S
7520F: lib/bootconfig.c7521F: lib/bootconfig.c
7521F: tools/bootconfig/*7522F: tools/bootconfig/*
7522F: tools/bootconfig/scripts/*7523F: tools/bootconfig/scripts/*
@@ -20119,8 +20120,8 @@ M: Ingo Molnar <mingo@redhat.com> · 12596 unmodified lines
20119S: Maintained20120S: Maintained
20120T: git git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git20121T: git git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
20121F: Documentation/trace/ftrace.rst20122F: Documentation/trace/ftrace.rst
20122F: arch/*/*/*/ftrace.h20123F: arch/*/*/*/*ftrace*
20123F: arch/*/kernel/ftrace.c20124F: arch/*/*/*ftrace*
20124F: fs/tracefs/20125F: fs/tracefs/
20125F: include/*/ftrace.h20126F: include/*/ftrace.h
20126F: include/linux/trace*.h20127F: 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
79 return (unsigned long)&ftrace_regs_caller_from_init;79 return (unsigned long)&ftrace_regs_caller_from_init;
80}80}
81 81
82int ftrace_arch_code_modify_prepare(void)82void ftrace_arch_code_modify_prepare(void)
83{83{
84 return 0;
85}84}
86 85
87int ftrace_arch_code_modify_post_process(void)86void ftrace_arch_code_modify_post_process(void)
88{87{
89 /* Make sure any TLB misses during machine stop are cleared. */88 /* Make sure any TLB misses during machine stop are cleared. */
90 flush_tlb_all();89 flush_tlb_all();
91 return 0;
92}90}
93 91
94static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr,92static 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
12#include <asm/patch.h>12#include <asm/patch.h>
13 13
14#ifdef CONFIG_DYNAMIC_FTRACE14#ifdef CONFIG_DYNAMIC_FTRACE
15int ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)15void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
16{16{
17 mutex_lock(&text_mutex);17 mutex_lock(&text_mutex);
18 return 0;
19}18}
20 19
21int ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)20void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
22{21{
23 mutex_unlock(&text_mutex);22 mutex_unlock(&text_mutex);
24 return 0;
25}23}
26 24
27static int ftrace_check_current_call(unsigned long hook_pos,25static 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
225 ftrace_modify_all_code(command);225 ftrace_modify_all_code(command);
226}226}
227 227
228int ftrace_arch_code_modify_post_process(void)228void ftrace_arch_code_modify_post_process(void)
229{229{
230 /*230 /*
231 * Flush any pre-fetched instructions on all231 * Flush any pre-fetched instructions on all
232 * CPUs to make the new code visible.232 * CPUs to make the new code visible.
233 */233 */
234 text_poke_sync_lock();234 text_poke_sync_lock();
235 return 0;
236}235}
237 236
238#ifdef CONFIG_MODULES237#ifdef CONFIG_MODULES
arch/x86/include/asm/ftrace.h+7−0
@@ -9,6 +9,13 @@ · 8 unmodified lines
9# define MCOUNT_ADDR ((unsigned long)(__fentry__))9# define MCOUNT_ADDR ((unsigned long)(__fentry__))
10#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */10#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */
11 11
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
12#ifdef CONFIG_DYNAMIC_FTRACE19#ifdef CONFIG_DYNAMIC_FTRACE
13#define ARCH_SUPPORTS_FTRACE_OPS 120#define ARCH_SUPPORTS_FTRACE_OPS 1
14#endif21#endif
arch/x86/kernel/ftrace.c+2−4
@@ -37,7 +37,7 @@ · 36 unmodified lines
37 37
38static int ftrace_poke_late = 0;38static int ftrace_poke_late = 0;
39 39
40int ftrace_arch_code_modify_prepare(void)40void ftrace_arch_code_modify_prepare(void)
41 __acquires(&text_mutex)41 __acquires(&text_mutex)
42{42{
43 /*43 /*
@@ -47,10 +47,9 @@ int ftrace_arch_code_modify_prepare(void) · 3 unmodified lines
47 */47 */
48 mutex_lock(&text_mutex);48 mutex_lock(&text_mutex);
49 ftrace_poke_late = 1;49 ftrace_poke_late = 1;
50 return 0;
51}50}
52 51
53int ftrace_arch_code_modify_post_process(void)52void ftrace_arch_code_modify_post_process(void)
54 __releases(&text_mutex)53 __releases(&text_mutex)
55{54{
56 /*55 /*
@@ -61,7 +60,6 @@ int ftrace_arch_code_modify_post_process(void) · 4 unmodified lines
61 text_poke_finish();60 text_poke_finish();
62 ftrace_poke_late = 0;61 ftrace_poke_late = 0;
63 mutex_unlock(&text_mutex);62 mutex_unlock(&text_mutex);
64 return 0;
65}63}
66 64
67static const char *ftrace_nop_replace(void)65static const char *ftrace_nop_replace(void)
arch/x86/kernel/tracepoint.c+0−6
@@ -1,17 +1,11 @@
1// SPDX-License-Identifier: GPL-2.01// SPDX-License-Identifier: GPL-2.0
2/*2/*
3 * Code for supporting irq vector tracepoints.
4 *
5 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>3 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
6 *
7 */4 */
8#include <linux/jump_label.h>5#include <linux/jump_label.h>
9#include <linux/atomic.h>6#include <linux/atomic.h>
10 7
11#include <asm/hw_irq.h>
12#include <asm/desc.h>
13#include <asm/trace/exceptions.h>8#include <asm/trace/exceptions.h>
14#include <asm/trace/irq_vectors.h>
15 9
16DEFINE_STATIC_KEY_FALSE(trace_pagefault_key);10DEFINE_STATIC_KEY_FALSE(trace_pagefault_key);
17 11
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
289/* XBC cleanup data structures */289/* XBC cleanup data structures */
290void __init xbc_exit(void);290void __init xbc_exit(void);
291 291
292/* XBC embedded bootconfig data in kernel */
293#ifdef CONFIG_BOOT_CONFIG_EMBED
294const char * __init xbc_get_embedded_bootconfig(size_t *size);
295#else
296static inline const char *xbc_get_embedded_bootconfig(size_t *size)
297{
298 return NULL;
299}
300#endif
301
292#endif302#endif
include/linux/ftrace.h+2−2
@@ -452,8 +452,8 @@ static inline void stack_tracer_enable(void) { } · 451 unmodified lines
452 452
453#ifdef CONFIG_DYNAMIC_FTRACE453#ifdef CONFIG_DYNAMIC_FTRACE
454 454
455int ftrace_arch_code_modify_prepare(void);455void ftrace_arch_code_modify_prepare(void);
456int ftrace_arch_code_modify_post_process(void);456void ftrace_arch_code_modify_post_process(void);
457 457
458enum ftrace_bug_type {458enum ftrace_bug_type {
459 FTRACE_BUG_UNKNOWN,459 FTRACE_BUG_UNKNOWN,
include/linux/kprobes.h+1−1
@@ -424,7 +424,7 @@ void unregister_kretprobe(struct kretprobe *rp); · 423 unmodified lines
424int register_kretprobes(struct kretprobe **rps, int num);424int register_kretprobes(struct kretprobe **rps, int num);
425void unregister_kretprobes(struct kretprobe **rps, int num);425void unregister_kretprobes(struct kretprobe **rps, int num);
426 426
427#ifdef CONFIG_KRETPROBE_ON_RETHOOK427#if defined(CONFIG_KRETPROBE_ON_RETHOOK) || !defined(CONFIG_KRETPROBES)
428#define kprobe_flush_task(tk) do {} while (0)428#define kprobe_flush_task(tk) do {} while (0)
429#else429#else
430void kprobe_flush_task(struct task_struct *tk);430void kprobe_flush_task(struct task_struct *tk);
init/Kconfig+20−1
@@ -1338,7 +1338,7 @@ endif · 1337 unmodified lines
1338 1338
1339config BOOT_CONFIG1339config BOOT_CONFIG
1340 bool "Boot config support"1340 bool "Boot config support"
1341 select BLK_DEV_INITRD1341 select BLK_DEV_INITRD if !BOOT_CONFIG_EMBED
1342 help1342 help
1343 Extra boot config allows system admin to pass a config file as1343 Extra boot config allows system admin to pass a config file as
1344 complemental extension of kernel cmdline when booting.1344 complemental extension of kernel cmdline when booting.
@@ -1348,6 +1348,25 @@ config BOOT_CONFIG · 3 unmodified lines
1348 1348
1349 If unsure, say Y.1349 If unsure, say Y.
1350 1350
1351config 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
1362config 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
1351config INITRAMFS_PRESERVE_MTIME1370config INITRAMFS_PRESERVE_MTIME
1352 bool "Preserve cpio archive mtimes in initramfs"1371 bool "Preserve cpio archive mtimes in initramfs"
1353 default y1372 default y
init/main.c+19−19
@@ -266,7 +266,7 @@ static int __init loglevel(char *str) · 265 unmodified lines
266early_param("loglevel", loglevel);266early_param("loglevel", loglevel);
267 267
268#ifdef CONFIG_BLK_DEV_INITRD268#ifdef CONFIG_BLK_DEV_INITRD
269static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)269static void * __init get_boot_config_from_initrd(size_t *_size)
270{270{
271 u32 size, csum;271 u32 size, csum;
272 char *data;272 char *data;
@@ -300,17 +300,20 @@ found: · 27 unmodified lines
300 return NULL;300 return NULL;
301 }301 }
302 302
303 if (xbc_calc_checksum(data, size) != csum) {
304 pr_err("bootconfig checksum failed\n");
305 return NULL;
306 }
307
303 /* Remove bootconfig from initramfs/initrd */308 /* Remove bootconfig from initramfs/initrd */
304 initrd_end = (unsigned long)data;309 initrd_end = (unsigned long)data;
305 if (_size)310 if (_size)
306 *_size = size;311 *_size = size;
307 if (_csum)
308 *_csum = csum;
309 312
310 return data;313 return data;
311}314}
312#else315#else
313static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)316static void * __init get_boot_config_from_initrd(size_t *_size)
314{317{
315 return NULL;318 return NULL;
316}319}
@@ -407,14 +410,16 @@ static int __init warn_bootconfig(char *str) · 90 unmodified lines
407static void __init setup_boot_config(void)410static void __init setup_boot_config(void)
408{411{
409 static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;412 static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
410 const char *msg;413 const char *msg, *data;
411 int pos;414 int pos, ret;
412 u32 size, csum;415 size_t size;
413 char *data, *err;416 char *err;
414 int ret;
415 417
416 /* Cut out the bootconfig data even if we have no bootconfig option */418 /* 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);
418 423
419 strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);424 strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
420 err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,425 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
433 }438 }
434 439
435 if (size >= XBC_DATA_MAX) {440 if (size >= XBC_DATA_MAX) {
436 pr_err("bootconfig size %d greater than max size %d\n",441 pr_err("bootconfig size %ld greater than max size %d\n",
437 size, XBC_DATA_MAX);442 (long)size, XBC_DATA_MAX);
438 return;
439 }
440
441 if (xbc_calc_checksum(data, size) != csum) {
442 pr_err("bootconfig checksum failed\n");
443 return;443 return;
444 }444 }
445 445
@@ -452,7 +452,7 @@ static void __init setup_boot_config(void) · 6 unmodified lines
452 msg, pos);452 msg, pos);
453 } else {453 } else {
454 xbc_get_info(&ret, NULL);454 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);
456 /* keys starting with "kernel." are passed via cmdline */456 /* keys starting with "kernel." are passed via cmdline */
457 extra_command_line = xbc_make_cmdline("kernel");457 extra_command_line = xbc_make_cmdline("kernel");
458 /* Also, "init." keys are init arguments */458 /* Also, "init." keys are init arguments */
@@ -471,7 +471,7 @@ static void __init exit_boot_config(void) · 12 unmodified lines
471static void __init setup_boot_config(void)471static void __init setup_boot_config(void)
472{472{
473 /* Remove bootconfig data from initrd */473 /* Remove bootconfig data from initrd */
474 get_boot_config_from_initrd(NULL, NULL);474 get_boot_config_from_initrd(NULL);
475}475}
476 476
477static int __init warn_bootconfig(char *str)477static int __init warn_bootconfig(char *str)
kernel/kprobes.c+71−73
@@ -1257,79 +1257,6 @@ void kprobe_busy_end(void) · 1256 unmodified lines
1257 preempt_enable();1257 preempt_enable();
1258}1258}
1259 1259
1260#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1261static 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}
1269NOKPROBE_SYMBOL(free_rp_inst_rcu);
1270
1271static 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}
1280NOKPROBE_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 */
1288void 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}
1309NOKPROBE_SYMBOL(kprobe_flush_task);
1310
1311static 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
1333/* Add the new probe to 'ap->list'. */1260/* Add the new probe to 'ap->list'. */
1334static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)1261static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
1335{1262{
@@ -1928,6 +1855,77 @@ static struct notifier_block kprobe_exceptions_nb = { · 592 unmodified lines
1928#ifdef CONFIG_KRETPROBES1855#ifdef CONFIG_KRETPROBES
1929 1856
1930#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)1857#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1858static 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}
1866NOKPROBE_SYMBOL(free_rp_inst_rcu);
1867
1868static 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}
1877NOKPROBE_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 */
1885void 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}
1906NOKPROBE_SYMBOL(kprobe_flush_task);
1907
1908static 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
1931/* This assumes the 'tsk' is the current task or the is not running. */1929/* This assumes the 'tsk' is the current task or the is not running. */
1932static kprobe_opcode_t *__kretprobe_find_ret_addr(struct task_struct *tsk,1930static kprobe_opcode_t *__kretprobe_find_ret_addr(struct task_struct *tsk,
1933 struct llist_node **cur)1931 struct llist_node **cur)
kernel/trace/Makefile+4−0
@@ -31,6 +31,10 @@ ifdef CONFIG_GCOV_PROFILE_FTRACE · 30 unmodified lines
31GCOV_PROFILE := y31GCOV_PROFILE := y
32endif32endif
33 33
34# Functions in this file could be invoked from early interrupt
35# code and produce random code coverage.
36KCOV_INSTRUMENT_trace_preemptirq.o := n
37
34CFLAGS_bpf_trace.o := -I$(src)38CFLAGS_bpf_trace.o := -I$(src)
35 39
36CFLAGS_trace_benchmark.o := -I$(src)40CFLAGS_trace_benchmark.o := -I$(src)
kernel/trace/ftrace.c+174−36
@@ -45,6 +45,8 @@ · 44 unmodified lines
45#include "trace_output.h"45#include "trace_output.h"
46#include "trace_stat.h"46#include "trace_stat.h"
47 47
48#define FTRACE_INVALID_FUNCTION "__ftrace_invalid_address__"
49
48#define FTRACE_WARN_ON(cond) \50#define FTRACE_WARN_ON(cond) \
49 ({ \51 ({ \
50 int ___r = cond; \52 int ___r = cond; \
@@ -119,7 +121,7 @@ struct ftrace_ops __rcu *ftrace_ops_list __read_mostly = &ftrace_list_end; · 68 unmodified lines
119ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;121ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
120struct ftrace_ops global_ops;122struct ftrace_ops global_ops;
121 123
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 */
123void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,125void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
124 struct ftrace_ops *op, struct ftrace_regs *fregs);126 struct ftrace_ops *op, struct ftrace_regs *fregs);
125 127
@@ -952,7 +954,6 @@ static struct tracer_stat function_stats __initdata = { · 826 unmodified lines
952static __init void ftrace_profile_tracefs(struct dentry *d_tracer)954static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
953{955{
954 struct ftrace_profile_stat *stat;956 struct ftrace_profile_stat *stat;
955 struct dentry *entry;
956 char *name;957 char *name;
957 int ret;958 int ret;
958 int cpu;959 int cpu;
@@ -983,11 +984,9 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer) · 24 unmodified lines
983 }984 }
984 }985 }
985 986
986 entry = tracefs_create_file("function_profile_enabled",987 trace_create_file("function_profile_enabled",
987 TRACE_MODE_WRITE, d_tracer, NULL,988 TRACE_MODE_WRITE, d_tracer, NULL,
988 &ftrace_profile_fops);989 &ftrace_profile_fops);
989 if (!entry)
990 pr_warn("Could not create tracefs 'function_profile_enabled' entry\n");
991}990}
992 991
993#else /* CONFIG_FUNCTION_PROFILER */992#else /* CONFIG_FUNCTION_PROFILER */
@@ -2707,18 +2706,16 @@ ftrace_nop_initialize(struct module *mod, struct dyn_ftrace *rec) · 1713 unmodified lines
2707 * archs can override this function if they must do something2706 * archs can override this function if they must do something
2708 * before the modifying code is performed.2707 * before the modifying code is performed.
2709 */2708 */
2710int __weak ftrace_arch_code_modify_prepare(void)2709void __weak ftrace_arch_code_modify_prepare(void)
2711{2710{
2712 return 0;
2713}2711}
2714 2712
2715/*2713/*
2716 * archs can override this function if they must do something2714 * archs can override this function if they must do something
2717 * after the modifying code is performed.2715 * after the modifying code is performed.
2718 */2716 */
2719int __weak ftrace_arch_code_modify_post_process(void)2717void __weak ftrace_arch_code_modify_post_process(void)
2720{2718{
2721 return 0;
2722}2719}
2723 2720
2724void ftrace_modify_all_code(int command)2721void ftrace_modify_all_code(int command)
@@ -2804,12 +2801,7 @@ void __weak arch_ftrace_update_code(int command) · 79 unmodified lines
2804 2801
2805static void ftrace_run_update_code(int command)2802static void ftrace_run_update_code(int command)
2806{2803{
2807 int ret;2804 ftrace_arch_code_modify_prepare();
2808
2809 ret = ftrace_arch_code_modify_prepare();
2810 FTRACE_WARN_ON(ret);
2811 if (ret)
2812 return;
2813 2805
2814 /*2806 /*
2815 * By default we use stop_machine() to modify the code.2807 * 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
2819 */2811 */
2820 arch_ftrace_update_code(command);2812 arch_ftrace_update_code(command);
2821 2813
2822 ret = ftrace_arch_code_modify_post_process();2814 ftrace_arch_code_modify_post_process();
2823 FTRACE_WARN_ON(ret);
2824}2815}
2825 2816
2826static void ftrace_run_modify_code(struct ftrace_ops *ops, int command,2817static 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
3631 seq_printf(m, " ->%pS", ptr);3622 seq_printf(m, " ->%pS", ptr);
3632}3623}
3633 3624
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 */
3636static 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
3652static struct workqueue_struct *ftrace_check_wq __initdata;
3653static struct work_struct ftrace_check_work __initdata;
3654
3655/*
3656 * Scan all the mcount/fentry entries to make sure they are valid.
3657 */
3658static __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
3670static 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
3680static 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
3688late_initcall_sync(ftrace_check_sync);
3689subsys_initcall(ftrace_check_for_weak_functions);
3690
3691static 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
3712static inline int test_for_valid_rec(struct dyn_ftrace *rec)
3713{
3714 return 1;
3715}
3716
3717static 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
3634static int t_show(struct seq_file *m, void *v)3724static int t_show(struct seq_file *m, void *v)
3635{3725{
3636 struct ftrace_iterator *iter = m->private;3726 struct ftrace_iterator *iter = m->private;
@@ -3655,7 +3745,13 @@ static int t_show(struct seq_file *m, void *v) · 18 unmodified lines
3655 if (!rec)3745 if (!rec)
3656 return 0;3746 return 0;
3657 3747
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
3659 if (iter->flags & FTRACE_ITER_ENABLED) {3755 if (iter->flags & FTRACE_ITER_ENABLED) {
3660 struct ftrace_ops *ops;3756 struct ftrace_ops *ops;
3661 3757
@@ -3973,6 +4069,24 @@ add_rec_by_index(struct ftrace_hash *hash, struct ftrace_glob *func_g, · 311 unmodified lines
3973 return 0;4069 return 0;
3974}4070}
3975 4071
4072#ifdef FTRACE_MCOUNT_MAX_OFFSET
4073static 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
4083static 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
3976static int4090static int
3977ftrace_match_record(struct dyn_ftrace *rec, struct ftrace_glob *func_g,4091ftrace_match_record(struct dyn_ftrace *rec, struct ftrace_glob *func_g,
3978 struct ftrace_glob *mod_g, int exclude_mod)4092 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
3980 char str[KSYM_SYMBOL_LEN];4094 char str[KSYM_SYMBOL_LEN];
3981 char *modname;4095 char *modname;
3982 4096
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 }
3984 4103
3985 if (mod_g) {4104 if (mod_g) {
3986 int mod_matches = (modname) ? ftrace_match(modname, mod_g) : 0;4105 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
4431 * @ip: The instruction pointer address to remove the data from4550 * @ip: The instruction pointer address to remove the data from
4432 *4551 *
4433 * Returns the data if it is found, otherwise NULL.4552 * 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
4435 * ftrace_func_mapper_find_ip(), then the return value may be meaningless,4554 * ftrace_func_mapper_find_ip(), then the return value may be meaningless,
4436 * if the data pointer was set to zero.4555 * if the data pointer was set to zero.
4437 */4556 */
@@ -4526,8 +4645,8 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr, · 88 unmodified lines
4526 struct ftrace_probe_ops *probe_ops,4645 struct ftrace_probe_ops *probe_ops,
4527 void *data)4646 void *data)
4528{4647{
4648 struct ftrace_func_probe *probe = NULL, *iter;
4529 struct ftrace_func_entry *entry;4649 struct ftrace_func_entry *entry;
4530 struct ftrace_func_probe *probe;
4531 struct ftrace_hash **orig_hash;4650 struct ftrace_hash **orig_hash;
4532 struct ftrace_hash *old_hash;4651 struct ftrace_hash *old_hash;
4533 struct ftrace_hash *hash;4652 struct ftrace_hash *hash;
@@ -4546,11 +4665,13 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr, · 12 unmodified lines
4546 4665
4547 mutex_lock(&ftrace_lock);4666 mutex_lock(&ftrace_lock);
4548 /* Check if the probe_ops is already registered */4667 /* Check if the probe_ops is already registered */
4549 list_for_each_entry(probe, &tr->func_probes, list) {4668 list_for_each_entry(iter, &tr->func_probes, list) {
4550 if (probe->probe_ops == probe_ops)4669 if (iter->probe_ops == probe_ops) {
4670 probe = iter;
4551 break;4671 break;
4672 }
4552 }4673 }
4553 if (&probe->list == &tr->func_probes) {4674 if (!probe) {
4554 probe = kzalloc(sizeof(*probe), GFP_KERNEL);4675 probe = kzalloc(sizeof(*probe), GFP_KERNEL);
4555 if (!probe) {4676 if (!probe) {
4556 mutex_unlock(&ftrace_lock);4677 mutex_unlock(&ftrace_lock);
@@ -4668,9 +4789,9 @@ int · 111 unmodified lines
4668unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,4789unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
4669 struct ftrace_probe_ops *probe_ops)4790 struct ftrace_probe_ops *probe_ops)
4670{4791{
4792 struct ftrace_func_probe *probe = NULL, *iter;
4671 struct ftrace_ops_hash old_hash_ops;4793 struct ftrace_ops_hash old_hash_ops;
4672 struct ftrace_func_entry *entry;4794 struct ftrace_func_entry *entry;
4673 struct ftrace_func_probe *probe;
4674 struct ftrace_glob func_g;4795 struct ftrace_glob func_g;
4675 struct ftrace_hash **orig_hash;4796 struct ftrace_hash **orig_hash;
4676 struct ftrace_hash *old_hash;4797 struct ftrace_hash *old_hash;
@@ -4698,11 +4819,13 @@ unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr, · 21 unmodified lines
4698 4819
4699 mutex_lock(&ftrace_lock);4820 mutex_lock(&ftrace_lock);
4700 /* Check if the probe_ops is already registered */4821 /* Check if the probe_ops is already registered */
4701 list_for_each_entry(probe, &tr->func_probes, list) {4822 list_for_each_entry(iter, &tr->func_probes, list) {
4702 if (probe->probe_ops == probe_ops)4823 if (iter->probe_ops == probe_ops) {
4824 probe = iter;
4703 break;4825 break;
4826 }
4704 }4827 }
4705 if (&probe->list == &tr->func_probes)4828 if (!probe)
4706 goto err_unlock_ftrace;4829 goto err_unlock_ftrace;
4707 4830
4708 ret = -EINVAL;4831 ret = -EINVAL;
@@ -5161,8 +5284,6 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) · 452 unmodified lines
5161 goto out_unlock;5284 goto out_unlock;
5162 5285
5163 ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0);5286 ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0);
5164 if (ret)
5165 remove_hash_entry(direct_functions, entry);
5166 5287
5167 if (!ret && !(direct_ops.flags & FTRACE_OPS_FL_ENABLED)) {5288 if (!ret && !(direct_ops.flags & FTRACE_OPS_FL_ENABLED)) {
5168 ret = register_ftrace_function(&direct_ops);5289 ret = register_ftrace_function(&direct_ops);
@@ -5171,6 +5292,7 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) · 2 unmodified lines
5171 }5292 }
5172 5293
5173 if (ret) {5294 if (ret) {
5295 remove_hash_entry(direct_functions, entry);
5174 kfree(entry);5296 kfree(entry);
5175 if (!direct->count) {5297 if (!direct->count) {
5176 list_del_rcu(&direct->next);5298 list_del_rcu(&direct->next);
@@ -6793,6 +6915,13 @@ void ftrace_module_enable(struct module *mod) · 1616 unmodified lines
6793 !within_module_init(rec->ip, mod))6915 !within_module_init(rec->ip, mod))
6794 break;6916 break;
6795 6917
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
6796 cnt = 0;6925 cnt = 0;
6797 6926
6798 /*6927 /*
@@ -6829,11 +6958,16 @@ void ftrace_module_enable(struct module *mod) · 30 unmodified lines
6829 6958
6830void ftrace_module_init(struct module *mod)6959void ftrace_module_init(struct module *mod)
6831{6960{
6961 int ret;
6962
6832 if (ftrace_disabled || !mod->num_ftrace_callsites)6963 if (ftrace_disabled || !mod->num_ftrace_callsites)
6833 return;6964 return;
6834 6965
6835 ftrace_process_locs(mod, mod->ftrace_callsites,6966 ret = ftrace_process_locs(mod, mod->ftrace_callsites,
6836 mod->ftrace_callsites + mod->num_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);
6837}6971}
6838 6972
6839static void save_ftrace_mod_rec(struct ftrace_mod_map *mod_map,6973static void save_ftrace_mod_rec(struct ftrace_mod_map *mod_map,
@@ -7166,15 +7300,19 @@ void __init ftrace_init(void) · 326 unmodified lines
7166 pr_info("ftrace: allocating %ld entries in %ld pages\n",7300 pr_info("ftrace: allocating %ld entries in %ld pages\n",
7167 count, count / ENTRIES_PER_PAGE + 1);7301 count, count / ENTRIES_PER_PAGE + 1);
7168 7302
7169 last_ftrace_enabled = ftrace_enabled = 1;
7170
7171 ret = ftrace_process_locs(NULL,7303 ret = ftrace_process_locs(NULL,
7172 __start_mcount_loc,7304 __start_mcount_loc,
7173 __stop_mcount_loc);7305 __stop_mcount_loc);
7306 if (ret) {
7307 pr_warn("ftrace: failed to allocate entries for functions\n");
7308 goto failed;
7309 }
7174 7310
7175 pr_info("ftrace: allocated %ld pages with %ld groups\n",7311 pr_info("ftrace: allocated %ld pages with %ld groups\n",
7176 ftrace_number_of_pages, ftrace_number_of_groups);7312 ftrace_number_of_pages, ftrace_number_of_groups);
7177 7313
7314 last_ftrace_enabled = ftrace_enabled = 1;
7315
7178 set_ftrace_early_filters();7316 set_ftrace_early_filters();
7179 7317
7180 return;7318 return;
kernel/trace/pid_list.c+2−2
@@ -118,9 +118,9 @@ static inline unsigned int pid_join(unsigned int upper1, · 117 unmodified lines
118/**118/**
119 * trace_pid_list_is_set - test if the pid is set in the list119 * trace_pid_list_is_set - test if the pid is set in the list
120 * @pid_list: The pid list to test120 * @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.
122 *122 *
123 * Tests if @pid is is set in the @pid_list. This is usually called123 * Tests if @pid is set in the @pid_list. This is usually called
124 * from the scheduler when a task is scheduled. Its pid is checked124 * from the scheduler when a task is scheduled. Its pid is checked
125 * if it should be traced or not.125 * if it should be traced or not.
126 *126 *
kernel/trace/ring_buffer.c+64−17
@@ -29,6 +29,14 @@ · 28 unmodified lines
29 29
30#include <asm/local.h>30#include <asm/local.h>
31 31
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
32static void update_pages_handler(struct work_struct *work);40static void update_pages_handler(struct work_struct *work);
33 41
34/*42/*
@@ -468,6 +476,7 @@ struct rb_time_struct { · 433 unmodified lines
468 local_t cnt;476 local_t cnt;
469 local_t top;477 local_t top;
470 local_t bottom;478 local_t bottom;
479 local_t msb;
471};480};
472#else481#else
473#include <asm/local64.h>482#include <asm/local64.h>
@@ -569,7 +578,6 @@ struct ring_buffer_iter { · 95 unmodified lines
569 * For the ring buffer, 64 bit required operations for the time is578 * For the ring buffer, 64 bit required operations for the time is
570 * the following:579 * the following:
571 *580 *
572 * - Only need 59 bits (uses 60 to make it even).
573 * - Reads may fail if it interrupted a modification of the time stamp.581 * - Reads may fail if it interrupted a modification of the time stamp.
574 * It will succeed if it did not interrupt another write even if582 * It will succeed if it did not interrupt another write even if
575 * the read itself is interrupted by a write.583 * the read itself is interrupted by a write.
@@ -594,6 +602,7 @@ struct ring_buffer_iter { · 18 unmodified lines
594 */602 */
595#define RB_TIME_SHIFT 30603#define RB_TIME_SHIFT 30
596#define RB_TIME_VAL_MASK ((1 << RB_TIME_SHIFT) - 1)604#define RB_TIME_VAL_MASK ((1 << RB_TIME_SHIFT) - 1)
605#define RB_TIME_MSB_SHIFT 60
597 606
598static inline int rb_time_cnt(unsigned long val)607static inline int rb_time_cnt(unsigned long val)
599{608{
@@ -613,7 +622,7 @@ static inline u64 rb_time_val(unsigned long top, unsigned long bottom) · 13 unmodified lines
613 622
614static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt)623static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt)
615{624{
616 unsigned long top, bottom;625 unsigned long top, bottom, msb;
617 unsigned long c;626 unsigned long c;
618 627
619 /*628 /*
@@ -625,6 +634,7 @@ static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt) · 5 unmodified lines
625 c = local_read(&t->cnt);634 c = local_read(&t->cnt);
626 top = local_read(&t->top);635 top = local_read(&t->top);
627 bottom = local_read(&t->bottom);636 bottom = local_read(&t->bottom);
637 msb = local_read(&t->msb);
628 } while (c != local_read(&t->cnt));638 } while (c != local_read(&t->cnt));
629 639
630 *cnt = rb_time_cnt(top);640 *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
633 if (*cnt != rb_time_cnt(bottom))643 if (*cnt != rb_time_cnt(bottom))
634 return false;644 return false;
635 645
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);
637 return true;648 return true;
638}649}
639 650
@@ -649,10 +660,12 @@ static inline unsigned long rb_time_val_cnt(unsigned long val, unsigned long cnt · 9 unmodified lines
649 return (val & RB_TIME_VAL_MASK) | ((cnt & 3) << RB_TIME_SHIFT);660 return (val & RB_TIME_VAL_MASK) | ((cnt & 3) << RB_TIME_SHIFT);
650}661}
651 662
652static inline void rb_time_split(u64 val, unsigned long *top, unsigned long *bottom)663static inline void rb_time_split(u64 val, unsigned long *top, unsigned long *bottom,
664 unsigned long *msb)
653{665{
654 *top = (unsigned long)((val >> RB_TIME_SHIFT) & RB_TIME_VAL_MASK);666 *top = (unsigned long)((val >> RB_TIME_SHIFT) & RB_TIME_VAL_MASK);
655 *bottom = (unsigned long)(val & RB_TIME_VAL_MASK);667 *bottom = (unsigned long)(val & RB_TIME_VAL_MASK);
668 *msb = (unsigned long)(val >> RB_TIME_MSB_SHIFT);
656}669}
657 670
658static inline void rb_time_val_set(local_t *t, unsigned long val, unsigned long cnt)671static 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
663 676
664static void rb_time_set(rb_time_t *t, u64 val)677static void rb_time_set(rb_time_t *t, u64 val)
665{678{
666 unsigned long cnt, top, bottom;679 unsigned long cnt, top, bottom, msb;
667 680
668 rb_time_split(val, &top, &bottom);681 rb_time_split(val, &top, &bottom, &msb);
669 682
670 /* Writes always succeed with a valid number even if it gets interrupted. */683 /* Writes always succeed with a valid number even if it gets interrupted. */
671 do {684 do {
672 cnt = local_inc_return(&t->cnt);685 cnt = local_inc_return(&t->cnt);
673 rb_time_val_set(&t->top, top, cnt);686 rb_time_val_set(&t->top, top, cnt);
674 rb_time_val_set(&t->bottom, bottom, cnt);687 rb_time_val_set(&t->bottom, bottom, cnt);
688 rb_time_val_set(&t->msb, val >> RB_TIME_MSB_SHIFT, cnt);
675 } while (cnt != local_read(&t->cnt));689 } while (cnt != local_read(&t->cnt));
676}690}
677 691
@@ -686,8 +700,8 @@ rb_time_read_cmpxchg(local_t *l, unsigned long expect, unsigned long set) · 8 unmodified lines
686 700
687static int rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)701static int rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)
688{702{
689 unsigned long cnt, top, bottom;703 unsigned long cnt, top, bottom, msb;
690 unsigned long cnt2, top2, bottom2;704 unsigned long cnt2, top2, bottom2, msb2;
691 u64 val;705 u64 val;
692 706
693 /* The cmpxchg always fails if it interrupted an update */707 /* 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
703 717
704 cnt2 = cnt + 1;718 cnt2 = cnt + 1;
705 719
706 rb_time_split(val, &top, &bottom);720 rb_time_split(val, &top, &bottom, &msb);
707 top = rb_time_val_cnt(top, cnt);721 top = rb_time_val_cnt(top, cnt);
708 bottom = rb_time_val_cnt(bottom, cnt);722 bottom = rb_time_val_cnt(bottom, cnt);
709 723
710 rb_time_split(set, &top2, &bottom2);724 rb_time_split(set, &top2, &bottom2, &msb2);
711 top2 = rb_time_val_cnt(top2, cnt2);725 top2 = rb_time_val_cnt(top2, cnt2);
712 bottom2 = rb_time_val_cnt(bottom2, cnt2);726 bottom2 = rb_time_val_cnt(bottom2, cnt2);
713 727
714 if (!rb_time_read_cmpxchg(&t->cnt, cnt, cnt2))728 if (!rb_time_read_cmpxchg(&t->cnt, cnt, cnt2))
715 return false;729 return false;
730 if (!rb_time_read_cmpxchg(&t->msb, msb, msb2))
731 return false;
716 if (!rb_time_read_cmpxchg(&t->top, top, top2))732 if (!rb_time_read_cmpxchg(&t->top, top, top2))
717 return false;733 return false;
718 if (!rb_time_read_cmpxchg(&t->bottom, bottom, bottom2))734 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
783}799}
784#endif800#endif
785 801
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 */
810static 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}
786 820
787static inline u64 rb_time_stamp(struct trace_buffer *buffer);821static inline u64 rb_time_stamp(struct trace_buffer *buffer);
788 822
@@ -811,8 +845,10 @@ u64 ring_buffer_event_time_stamp(struct trace_buffer *buffer, · 22 unmodified lines
811 u64 ts;845 u64 ts;
812 846
813 /* If the event includes an absolute time, then just use that */847 /* If the event includes an absolute time, then just use that */
814 if (event->type_len == RINGBUF_TYPE_TIME_STAMP)848 if (event->type_len == RINGBUF_TYPE_TIME_STAMP) {
815 return rb_event_time_stamp(event);849 ts = rb_event_time_stamp(event);
850 return rb_fix_abs_ts(ts, cpu_buffer->tail_page->page->time_stamp);
851 }
816 852
817 nest = local_read(&cpu_buffer->committing);853 nest = local_read(&cpu_buffer->committing);
818 verify_event(cpu_buffer, event);854 verify_event(cpu_buffer, event);
@@ -2754,8 +2790,15 @@ static void rb_add_timestamp(struct ring_buffer_per_cpu *cpu_buffer, · 1935 unmodified lines
2754 (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE);2790 (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE);
2755 2791
2756 if (unlikely(info->delta > (1ULL << 59))) {2792 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
2757 /* did the clock go backwards */2800 /* 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) {
2759 /* not interrupted */2802 /* not interrupted */
2760 static int once;2803 static int once;
2761 2804
@@ -3304,7 +3347,7 @@ static void dump_buffer_page(struct buffer_data_page *bpage, · 542 unmodified lines
3304 3347
3305 case RINGBUF_TYPE_TIME_STAMP:3348 case RINGBUF_TYPE_TIME_STAMP:
3306 delta = rb_event_time_stamp(event);3349 delta = rb_event_time_stamp(event);
3307 ts = delta;3350 ts = rb_fix_abs_ts(delta, ts);
3308 pr_warn(" [%lld] absolute:%lld TIME STAMP\n", ts, delta);3351 pr_warn(" [%lld] absolute:%lld TIME STAMP\n", ts, delta);
3309 break;3352 break;
3310 3353
@@ -3380,7 +3423,7 @@ static void check_buffer(struct ring_buffer_per_cpu *cpu_buffer, · 69 unmodified lines
3380 3423
3381 case RINGBUF_TYPE_TIME_STAMP:3424 case RINGBUF_TYPE_TIME_STAMP:
3382 delta = rb_event_time_stamp(event);3425 delta = rb_event_time_stamp(event);
3383 ts = delta;3426 ts = rb_fix_abs_ts(delta, ts);
3384 break;3427 break;
3385 3428
3386 case RINGBUF_TYPE_PADDING:3429 case RINGBUF_TYPE_PADDING:
@@ -4367,6 +4410,7 @@ rb_update_read_stamp(struct ring_buffer_per_cpu *cpu_buffer, · 980 unmodified lines
4367 4410
4368 case RINGBUF_TYPE_TIME_STAMP:4411 case RINGBUF_TYPE_TIME_STAMP:
4369 delta = rb_event_time_stamp(event);4412 delta = rb_event_time_stamp(event);
4413 delta = rb_fix_abs_ts(delta, cpu_buffer->read_stamp);
4370 cpu_buffer->read_stamp = delta;4414 cpu_buffer->read_stamp = delta;
4371 return;4415 return;
4372 4416
@@ -4397,6 +4441,7 @@ rb_update_iter_read_stamp(struct ring_buffer_iter *iter, · 24 unmodified lines
4397 4441
4398 case RINGBUF_TYPE_TIME_STAMP:4442 case RINGBUF_TYPE_TIME_STAMP:
4399 delta = rb_event_time_stamp(event);4443 delta = rb_event_time_stamp(event);
4444 delta = rb_fix_abs_ts(delta, iter->read_stamp);
4400 iter->read_stamp = delta;4445 iter->read_stamp = delta;
4401 return;4446 return;
4402 4447
@@ -4650,6 +4695,7 @@ rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts, · 247 unmodified lines
4650 case RINGBUF_TYPE_TIME_STAMP:4695 case RINGBUF_TYPE_TIME_STAMP:
4651 if (ts) {4696 if (ts) {
4652 *ts = rb_event_time_stamp(event);4697 *ts = rb_event_time_stamp(event);
4698 *ts = rb_fix_abs_ts(*ts, reader->page->time_stamp);
4653 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,4699 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,
4654 cpu_buffer->cpu, ts);4700 cpu_buffer->cpu, ts);
4655 }4701 }
@@ -4741,6 +4787,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) · 85 unmodified lines
4741 case RINGBUF_TYPE_TIME_STAMP:4787 case RINGBUF_TYPE_TIME_STAMP:
4742 if (ts) {4788 if (ts) {
4743 *ts = rb_event_time_stamp(event);4789 *ts = rb_event_time_stamp(event);
4790 *ts = rb_fix_abs_ts(*ts, iter->head_page->page->time_stamp);
4744 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,4791 ring_buffer_normalize_time_stamp(cpu_buffer->buffer,
4745 cpu_buffer->cpu, ts);4792 cpu_buffer->cpu, ts);
4746 }4793 }
@@ -6011,10 +6058,10 @@ static __init int test_ringbuffer(void) · 1264 unmodified lines
6011 pr_info(" total events: %ld\n", total_lost + total_read);6058 pr_info(" total events: %ld\n", total_lost + total_read);
6012 pr_info(" recorded len bytes: %ld\n", total_len);6059 pr_info(" recorded len bytes: %ld\n", total_len);
6013 pr_info(" recorded size bytes: %ld\n", total_size);6060 pr_info(" recorded size bytes: %ld\n", total_size);
6014 if (total_lost)6061 if (total_lost) {
6015 pr_info(" With dropped events, record len and size may not match\n"6062 pr_info(" With dropped events, record len and size may not match\n"
6016 " alloced and written from above\n");6063 " alloced and written from above\n");
6017 if (!total_lost) {6064 } else {
6018 if (RB_WARN_ON(buffer, total_len != total_alloc ||6065 if (RB_WARN_ON(buffer, total_len != total_alloc ||
6019 total_size != total_written))6066 total_size != total_written))
6020 break;6067 break;
kernel/trace/trace.c+45−27
@@ -721,13 +721,16 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, · 720 unmodified lines
721 pos = 0;721 pos = 0;
722 722
723 ret = trace_get_user(&parser, ubuf, cnt, &pos);723 ret = trace_get_user(&parser, ubuf, cnt, &pos);
724 if (ret < 0 || !trace_parser_loaded(&parser))724 if (ret < 0)
725 break;725 break;
726 726
727 read += ret;727 read += ret;
728 ubuf += ret;728 ubuf += ret;
729 cnt -= ret;729 cnt -= ret;
730 730
731 if (!trace_parser_loaded(&parser))
732 break;
733
731 ret = -EINVAL;734 ret = -EINVAL;
732 if (kstrtoul(parser.buffer, 0, &val))735 if (kstrtoul(parser.buffer, 0, &val))
733 break;736 break;
@@ -753,7 +756,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, · 19 unmodified lines
753 if (!nr_pids) {756 if (!nr_pids) {
754 /* Cleared the list of pids */757 /* Cleared the list of pids */
755 trace_pid_list_free(pid_list);758 trace_pid_list_free(pid_list);
756 read = ret;
757 pid_list = NULL;759 pid_list = NULL;
758 }760 }
759 761
@@ -1174,7 +1176,7 @@ void tracing_snapshot_cond(struct trace_array *tr, void *cond_data) · 414 unmodified lines
1174EXPORT_SYMBOL_GPL(tracing_snapshot_cond);1176EXPORT_SYMBOL_GPL(tracing_snapshot_cond);
1175 1177
1176/**1178/**
1177 * tracing_snapshot_cond_data - get the user data associated with a snapshot1179 * tracing_cond_snapshot_data - get the user data associated with a snapshot
1178 * @tr: The tracing instance1180 * @tr: The tracing instance
1179 *1181 *
1180 * When the user enables a conditional snapshot using1182 * When the user enables a conditional snapshot using
@@ -1542,6 +1544,7 @@ static struct { · 361 unmodified lines
1542 { ktime_get_mono_fast_ns, "mono", 1 },1544 { ktime_get_mono_fast_ns, "mono", 1 },
1543 { ktime_get_raw_fast_ns, "mono_raw", 1 },1545 { ktime_get_raw_fast_ns, "mono_raw", 1 },
1544 { ktime_get_boot_fast_ns, "boot", 1 },1546 { ktime_get_boot_fast_ns, "boot", 1 },
1547 { ktime_get_tai_fast_ns, "tai", 1 },
1545 ARCH_TRACE_CLOCKS1548 ARCH_TRACE_CLOCKS
1546};1549};
1547 1550
@@ -2835,7 +2838,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb, · 1287 unmodified lines
2835}2838}
2836EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);2839EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
2837 2840
2838static DEFINE_SPINLOCK(tracepoint_iter_lock);2841static DEFINE_RAW_SPINLOCK(tracepoint_iter_lock);
2839static DEFINE_MUTEX(tracepoint_printk_mutex);2842static DEFINE_MUTEX(tracepoint_printk_mutex);
2840 2843
2841static void output_printk(struct trace_event_buffer *fbuffer)2844static void output_printk(struct trace_event_buffer *fbuffer)
@@ -2863,14 +2866,14 @@ static void output_printk(struct trace_event_buffer *fbuffer) · 21 unmodified lines
2863 2866
2864 event = &fbuffer->trace_file->event_call->event;2867 event = &fbuffer->trace_file->event_call->event;
2865 2868
2866 spin_lock_irqsave(&tracepoint_iter_lock, flags);2869 raw_spin_lock_irqsave(&tracepoint_iter_lock, flags);
2867 trace_seq_init(&iter->seq);2870 trace_seq_init(&iter->seq);
2868 iter->ent = fbuffer->entry;2871 iter->ent = fbuffer->entry;
2869 event_call->event.funcs->trace(iter, 0, event);2872 event_call->event.funcs->trace(iter, 0, event);
2870 trace_seq_putc(&iter->seq, 0);2873 trace_seq_putc(&iter->seq, 0);
2871 printk("%s", iter->seq.buffer);2874 printk("%s", iter->seq.buffer);
2872 2875
2873 spin_unlock_irqrestore(&tracepoint_iter_lock, flags);2876 raw_spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
2874}2877}
2875 2878
2876int tracepoint_printk_sysctl(struct ctl_table *table, int write,2879int 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
4249 unsigned int flags)4252 unsigned int flags)
4250{4253{
4251 bool tgid = flags & TRACE_ITER_RECORD_TGID;4254 bool tgid = flags & TRACE_ITER_RECORD_TGID;
4252 const char *space = " ";4255 static const char space[] = " ";
4253 int prec = tgid ? 12 : 2;4256 int prec = tgid ? 12 : 2;
4254 4257
4255 print_event_info(buf, m);4258 print_event_info(buf, m);
@@ -4273,9 +4276,7 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) · 17 unmodified lines
4273 struct tracer *type = iter->trace;4276 struct tracer *type = iter->trace;
4274 unsigned long entries;4277 unsigned long entries;
4275 unsigned long total;4278 unsigned long total;
4276 const char *name = "preemption";4279 const char *name = type->name;
4277
4278 name = type->name;
4279 4280
4280 get_total_entries(buf, &total, &entries);4281 get_total_entries(buf, &total, &entries);
4281 4282
@@ -5469,7 +5470,7 @@ static const char readme_msg[] = · 1187 unmodified lines
5469 " error_log\t- error log for failed commands (that support it)\n"5470 " error_log\t- error log for failed commands (that support it)\n"
5470 " buffer_size_kb\t- view and modify size of per cpu buffer\n"5471 " buffer_size_kb\t- view and modify size of per cpu buffer\n"
5471 " buffer_total_size_kb - view total size of all cpu buffers\n\n"5472 " 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"
5473 " local: Per cpu clock but may not be synced across CPUs\n"5474 " local: Per cpu clock but may not be synced across CPUs\n"
5474 " global: Synced across CPUs but slows tracing down.\n"5475 " global: Synced across CPUs but slows tracing down.\n"
5475 " counter: Not a clock, but just an increment\n"5476 " counter: Not a clock, but just an increment\n"
@@ -5478,7 +5479,7 @@ static const char readme_msg[] = · 2 unmodified lines
5478#ifdef CONFIG_X86_645479#ifdef CONFIG_X86_64
5479 " x86-tsc: TSC cycle counter\n"5480 " x86-tsc: TSC cycle counter\n"
5480#endif5481#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"
5482 " delta: Delta difference against a buffer-wide timestamp\n"5483 " delta: Delta difference against a buffer-wide timestamp\n"
5483 " absolute: Absolute (standalone) timestamp\n"5484 " absolute: Absolute (standalone) timestamp\n"
5484 "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n"5485 "\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
6326 tr->current_trace = &nop_trace;6327 tr->current_trace = &nop_trace;
6327}6328}
6328 6329
6330static bool tracer_options_updated;
6331
6329static void add_tracer_options(struct trace_array *tr, struct tracer *t)6332static void add_tracer_options(struct trace_array *tr, struct tracer *t)
6330{6333{
6331 /* Only enable if the directory has been created already. */6334 /* Only enable if the directory has been created already. */
6332 if (!tr->dir)6335 if (!tr->dir)
6333 return;6336 return;
6334 6337
6338 /* Only create trace option files after update_tracer_options finish */
6339 if (!tracer_options_updated)
6340 return;
6341
6335 create_trace_option_files(tr, t);6342 create_trace_option_files(tr, t);
6336}6343}
6337 6344
@@ -6448,7 +6455,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, · 110 unmodified lines
6448{6455{
6449 struct trace_array *tr = filp->private_data;6456 struct trace_array *tr = filp->private_data;
6450 char buf[MAX_TRACER_SIZE+1];6457 char buf[MAX_TRACER_SIZE+1];
6451 int i;6458 char *name;
6452 size_t ret;6459 size_t ret;
6453 int err;6460 int err;
6454 6461
@@ -6462,11 +6469,9 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, · 7 unmodified lines
6462 6469
6463 buf[cnt] = 0;6470 buf[cnt] = 0;
6464 6471
6465 /* strip ending whitespace. */6472 name = strim(buf);
6466 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
6467 buf[i] = 0;
6468 6473
6469 err = tracing_set_tracer(tr, buf);6474 err = tracing_set_tracer(tr, name);
6470 if (err)6475 if (err)
6471 return err;6476 return err;
6472 6477
@@ -9170,6 +9175,7 @@ static void __update_tracer_options(struct trace_array *tr) · 2697 unmodified lines
9170static void update_tracer_options(struct trace_array *tr)9175static void update_tracer_options(struct trace_array *tr)
9171{9176{
9172 mutex_lock(&trace_types_lock);9177 mutex_lock(&trace_types_lock);
9178 tracer_options_updated = true;
9173 __update_tracer_options(tr);9179 __update_tracer_options(tr);
9174 mutex_unlock(&trace_types_lock);9180 mutex_unlock(&trace_types_lock);
9175}9181}
@@ -9602,6 +9608,7 @@ extern struct trace_eval_map *__stop_ftrace_eval_maps[]; · 426 unmodified lines
9602 9608
9603static struct workqueue_struct *eval_map_wq __initdata;9609static struct workqueue_struct *eval_map_wq __initdata;
9604static struct work_struct eval_map_work __initdata;9610static struct work_struct eval_map_work __initdata;
9611static struct work_struct tracerfs_init_work __initdata;
9605 9612
9606static void __init eval_map_work_func(struct work_struct *work)9613static void __init eval_map_work_func(struct work_struct *work)
9607{9614{
@@ -9627,6 +9634,8 @@ static int __init trace_eval_init(void) · 19 unmodified lines
9627 return 0;9634 return 0;
9628}9635}
9629 9636
9637subsys_initcall(trace_eval_init);
9638
9630static int __init trace_eval_sync(void)9639static int __init trace_eval_sync(void)
9631{9640{
9632 /* Make sure the eval map updates are finished */9641 /* Make sure the eval map updates are finished */
@@ -9709,15 +9718,8 @@ static struct notifier_block trace_module_nb = { · 76 unmodified lines
9709};9718};
9710#endif /* CONFIG_MODULES */9719#endif /* CONFIG_MODULES */
9711 9720
9712static __init int tracer_init_tracefs(void)9721static __init void tracer_init_tracefs_work_func(struct work_struct *work)
9713{9722{
9714 int ret;
9715
9716 trace_access_lock_init();
9717
9718 ret = tracing_init_dentry();
9719 if (ret)
9720 return 0;
9721 9723
9722 event_trace_init();9724 event_trace_init();
9723 9725
@@ -9739,8 +9741,6 @@ static __init int tracer_init_tracefs(void) · 15 unmodified lines
9739 trace_create_file("saved_tgids", TRACE_MODE_READ, NULL,9741 trace_create_file("saved_tgids", TRACE_MODE_READ, NULL,
9740 NULL, &tracing_saved_tgids_fops);9742 NULL, &tracing_saved_tgids_fops);
9741 9743
9742 trace_eval_init();
9743
9744 trace_create_eval_file(NULL);9744 trace_create_eval_file(NULL);
9745 9745
9746#ifdef CONFIG_MODULES9746#ifdef CONFIG_MODULES
@@ -9755,6 +9755,24 @@ static __init int tracer_init_tracefs(void) · 8 unmodified lines
9755 create_trace_instances(NULL);9755 create_trace_instances(NULL);
9756 9756
9757 update_tracer_options(&global_trace);9757 update_tracer_options(&global_trace);
9758}
9759
9760static __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 }
9758 9776
9759 return 0;9777 return 0;
9760}9778}
kernel/trace/trace.h+11−15
@@ -1573,13 +1573,12 @@ struct enable_trigger_data { · 1572 unmodified lines
1573};1573};
1574 1574
1575extern int event_enable_trigger_print(struct seq_file *m,1575extern int event_enable_trigger_print(struct seq_file *m,
1576 struct event_trigger_ops *ops,
1577 struct event_trigger_data *data);
1578extern void event_enable_trigger_free(struct event_trigger_ops *ops,
1579 struct event_trigger_data *data);1576 struct event_trigger_data *data);
1577extern void event_enable_trigger_free(struct event_trigger_data *data);
1580extern int event_enable_trigger_parse(struct event_command *cmd_ops,1578extern int event_enable_trigger_parse(struct event_command *cmd_ops,
1581 struct trace_event_file *file,1579 struct trace_event_file *file,
1582 char *glob, char *cmd, char *param);1580 char *glob, char *cmd,
1581 char *param_and_filter);
1583extern int event_enable_register_trigger(char *glob,1582extern int event_enable_register_trigger(char *glob,
1584 struct event_trigger_data *data,1583 struct event_trigger_data *data,
1585 struct trace_event_file *file);1584 struct trace_event_file *file);
@@ -1587,8 +1586,7 @@ extern void event_enable_unregister_trigger(char *glob, · 1 unmodified line
1587 struct event_trigger_data *test,1586 struct event_trigger_data *test,
1588 struct trace_event_file *file);1587 struct trace_event_file *file);
1589extern void trigger_data_free(struct event_trigger_data *data);1588extern void trigger_data_free(struct event_trigger_data *data);
1590extern int event_trigger_init(struct event_trigger_ops *ops,1589extern int event_trigger_init(struct event_trigger_data *data);
1591 struct event_trigger_data *data);
1592extern int trace_event_trigger_enable_disable(struct trace_event_file *file,1590extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
1593 int trigger_enable);1591 int trigger_enable);
1594extern void update_cond_flag(struct trace_event_file *file);1592extern 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
1629extern int event_trigger_register(struct event_command *cmd_ops,1627extern int event_trigger_register(struct event_command *cmd_ops,
1630 struct trace_event_file *file,1628 struct trace_event_file *file,
1631 char *glob,1629 char *glob,
1632 char *cmd,1630 struct event_trigger_data *trigger_data);
1633 char *trigger,1631extern void event_trigger_unregister(struct event_command *cmd_ops,
1634 struct event_trigger_data *trigger_data,1632 struct trace_event_file *file,
1635 int *n_registered);1633 char *glob,
1634 struct event_trigger_data *trigger_data);
1636 1635
1637/**1636/**
1638 * struct event_trigger_ops - callbacks for trace event triggers1637 * struct event_trigger_ops - callbacks for trace event triggers
@@ -1686,12 +1685,9 @@ struct event_trigger_ops { · 47 unmodified lines
1686 struct trace_buffer *buffer,1685 struct trace_buffer *buffer,
1687 void *rec,1686 void *rec,
1688 struct ring_buffer_event *rbe);1687 struct ring_buffer_event *rbe);
1689 int (*init)(struct event_trigger_ops *ops,1688 int (*init)(struct event_trigger_data *data);
1690 struct event_trigger_data *data);1689 void (*free)(struct event_trigger_data *data);
1691 void (*free)(struct event_trigger_ops *ops,
1692 struct event_trigger_data *data);
1693 int (*print)(struct seq_file *m,1690 int (*print)(struct seq_file *m,
1694 struct event_trigger_ops *ops,
1695 struct event_trigger_data *data);1691 struct event_trigger_data *data);
1696};1692};
1697 1693
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
300{300{
301 struct xbc_node *node;301 struct xbc_node *node;
302 const char *p, *handler;302 const char *p, *handler;
303 int ret;303 int ret = 0;
304 304
305 handler = xbc_node_get_data(hnode);305 handler = xbc_node_get_data(hnode);
306 306
kernel/trace/trace_dynevent.c+2−7
@@ -255,19 +255,14 @@ static const struct file_operations dynamic_events_ops = { · 254 unmodified lines
255/* Make a tracefs interface for controlling dynamic events */255/* Make a tracefs interface for controlling dynamic events */
256static __init int init_dynamic_event(void)256static __init int init_dynamic_event(void)
257{257{
258 struct dentry *entry;
259 int ret;258 int ret;
260 259
261 ret = tracing_init_dentry();260 ret = tracing_init_dentry();
262 if (ret)261 if (ret)
263 return 0;262 return 0;
264 263
265 entry = tracefs_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,264 trace_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,
266 NULL, &dynamic_events_ops);265 NULL, &dynamic_events_ops);
267
268 /* Event list interface */
269 if (!entry)
270 pr_warn("Could not create tracefs 'dynamic_events' entry\n");
271 266
272 return 0;267 return 0;
273}268}
kernel/trace/trace_eprobe.c+12−12
@@ -511,20 +511,17 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec) · 510 unmodified lines
511 * functions are just stubs to fulfill what is needed to use the trigger511 * functions are just stubs to fulfill what is needed to use the trigger
512 * infrastructure.512 * infrastructure.
513 */513 */
514static int eprobe_trigger_init(struct event_trigger_ops *ops,514static int eprobe_trigger_init(struct event_trigger_data *data)
515 struct event_trigger_data *data)
516{515{
517 return 0;516 return 0;
518}517}
519 518
520static void eprobe_trigger_free(struct event_trigger_ops *ops,519static void eprobe_trigger_free(struct event_trigger_data *data)
521 struct event_trigger_data *data)
522{520{
523 521
524}522}
525 523
526static int eprobe_trigger_print(struct seq_file *m,524static int eprobe_trigger_print(struct seq_file *m,
527 struct event_trigger_ops *ops,
528 struct event_trigger_data *data)525 struct event_trigger_data *data)
529{526{
530 /* Do not print eprobe event triggers */527 /* Do not print eprobe event triggers */
@@ -549,7 +546,8 @@ static struct event_trigger_ops eprobe_trigger_ops = { · 18 unmodified lines
549 546
550static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops,547static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops,
551 struct trace_event_file *file,548 struct trace_event_file *file,
552 char *glob, char *cmd, char *param)549 char *glob, char *cmd,
550 char *param_and_filter)
553{551{
554 return -1;552 return -1;
555}553}
@@ -650,7 +648,7 @@ static struct trace_event_functions eprobe_funcs = { · 94 unmodified lines
650static int disable_eprobe(struct trace_eprobe *ep,648static int disable_eprobe(struct trace_eprobe *ep,
651 struct trace_array *tr)649 struct trace_array *tr)
652{650{
653 struct event_trigger_data *trigger;651 struct event_trigger_data *trigger = NULL, *iter;
654 struct trace_event_file *file;652 struct trace_event_file *file;
655 struct eprobe_data *edata;653 struct eprobe_data *edata;
656 654
@@ -658,14 +656,16 @@ static int disable_eprobe(struct trace_eprobe *ep, · 1 unmodified line
658 if (!file)656 if (!file)
659 return -ENOENT;657 return -ENOENT;
660 658
661 list_for_each_entry(trigger, &file->triggers, list) {659 list_for_each_entry(iter, &file->triggers, list) {
662 if (!(trigger->flags & EVENT_TRIGGER_FL_PROBE))660 if (!(iter->flags & EVENT_TRIGGER_FL_PROBE))
663 continue;661 continue;
664 edata = trigger->private_data;662 edata = iter->private_data;
665 if (edata->ep == ep)663 if (edata->ep == ep) {
664 trigger = iter;
666 break;665 break;
666 }
667 }667 }
668 if (list_entry_is_head(trigger, &file->triggers, list))668 if (!trigger)
669 return -ENODEV;669 return -ENODEV;
670 670
671 list_del_rcu(&trigger->list);671 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
392 if (!(dereference_flags & (1ULL << arg)))392 if (!(dereference_flags & (1ULL << arg)))
393 goto next_arg;393 goto next_arg;
394 394
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
401 /* Find the REC-> in the argument */395 /* Find the REC-> in the argument */
402 c = strchr(fmt + i, ',');396 c = strchr(fmt + i, ',');
403 r = strstr(fmt + i, "REC->");397 r = strstr(fmt + i, "REC->");
@@ -413,7 +407,14 @@ static void test_event_printk(struct trace_event_call *call) · 9 unmodified lines
413 a = strchr(fmt + i, '&');407 a = strchr(fmt + i, '&');
414 if ((a && (a < r)) || test_field(r, call))408 if ((a && (a < r)) || test_field(r, call))
415 dereference_flags &= ~(1ULL << arg);409 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);
416 }416 }
417
417 next_arg:418 next_arg:
418 i--;419 i--;
419 arg++;420 arg++;
@@ -1723,9 +1724,9 @@ static LIST_HEAD(event_subsystems); · 1303 unmodified lines
1723 1724
1724static int subsystem_open(struct inode *inode, struct file *filp)1725static int subsystem_open(struct inode *inode, struct file *filp)
1725{1726{
1727 struct trace_subsystem_dir *dir = NULL, *iter_dir;
1728 struct trace_array *tr = NULL, *iter_tr;
1726 struct event_subsystem *system = NULL;1729 struct event_subsystem *system = NULL;
1727 struct trace_subsystem_dir *dir = NULL; /* Initialize for gcc */
1728 struct trace_array *tr;
1729 int ret;1730 int ret;
1730 1731
1731 if (tracing_is_disabled())1732 if (tracing_is_disabled())
@@ -1734,10 +1735,12 @@ static int subsystem_open(struct inode *inode, struct file *filp) · 2 unmodified lines
1734 /* Make sure the system still exists */1735 /* Make sure the system still exists */
1735 mutex_lock(&event_mutex);1736 mutex_lock(&event_mutex);
1736 mutex_lock(&trace_types_lock);1737 mutex_lock(&trace_types_lock);
1737 list_for_each_entry(tr, &ftrace_trace_arrays, list) {1738 list_for_each_entry(iter_tr, &ftrace_trace_arrays, list) {
1738 list_for_each_entry(dir, &tr->systems, list) {1739 list_for_each_entry(iter_dir, &iter_tr->systems, list) {
1739 if (dir == inode->i_private) {1740 if (iter_dir == inode->i_private) {
1740 /* Don't open systems with no events */1741 /* Don't open systems with no events */
1742 tr = iter_tr;
1743 dir = iter_dir;
1741 if (dir->nr_events) {1744 if (dir->nr_events) {
1742 __get_system_dir(dir);1745 __get_system_dir(dir);
1743 system = dir->subsystem;1746 system = dir->subsystem;
@@ -1753,9 +1756,6 @@ static int subsystem_open(struct inode *inode, struct file *filp) · 9 unmodified lines
1753 if (!system)1756 if (!system)
1754 return -ENODEV;1757 return -ENODEV;
1755 1758
1756 /* Some versions of gcc think dir can be uninitialized here */
1757 WARN_ON(!dir);
1758
1759 /* Still need to increment the ref count of the system */1759 /* Still need to increment the ref count of the system */
1760 if (trace_array_get(tr) < 0) {1760 if (trace_array_get(tr) < 0) {
1761 put_system(dir);1761 put_system(dir);
@@ -2280,8 +2280,8 @@ static struct dentry * · 518 unmodified lines
2280event_subsystem_dir(struct trace_array *tr, const char *name,2280event_subsystem_dir(struct trace_array *tr, const char *name,
2281 struct trace_event_file *file, struct dentry *parent)2281 struct trace_event_file *file, struct dentry *parent)
2282{2282{
2283 struct event_subsystem *system, *iter;
2283 struct trace_subsystem_dir *dir;2284 struct trace_subsystem_dir *dir;
2284 struct event_subsystem *system;
2285 struct dentry *entry;2285 struct dentry *entry;
2286 2286
2287 /* First see if we did not already create this dir */2287 /* 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
2295 }2295 }
2296 2296
2297 /* Now see if the system itself exists. */2297 /* Now see if the system itself exists. */
2298 list_for_each_entry(system, &event_subsystems, list) {2298 system = NULL;
2299 if (strcmp(system->name, name) == 0)2299 list_for_each_entry(iter, &event_subsystems, list) {
2300 if (strcmp(iter->name, name) == 0) {
2301 system = iter;
2300 break;2302 break;
2303 }
2301 }2304 }
2302 /* Reset system variable when not found */
2303 if (&system->list == &event_subsystems)
2304 system = NULL;
2305 2305
2306 dir = kmalloc(sizeof(*dir), GFP_KERNEL);2306 dir = kmalloc(sizeof(*dir), GFP_KERNEL);
2307 if (!dir)2307 if (!dir)
@@ -3546,12 +3546,10 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) · 1238 unmodified lines
3546 struct dentry *d_events;3546 struct dentry *d_events;
3547 struct dentry *entry;3547 struct dentry *entry;
3548 3548
3549 entry = tracefs_create_file("set_event", TRACE_MODE_WRITE, parent,3549 entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent,
3550 tr, &ftrace_set_event_fops);3550 tr, &ftrace_set_event_fops);
3551 if (!entry) {3551 if (!entry)
3552 pr_warn("Could not create tracefs 'set_event' entry\n");
3553 return -ENOMEM;3552 return -ENOMEM;
3554 }
3555 3553
3556 d_events = tracefs_create_dir("events", parent);3554 d_events = tracefs_create_dir("events", parent);
3557 if (!d_events) {3555 if (!d_events) {
@@ -3566,16 +3564,12 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) · 8 unmodified lines
3566 3564
3567 /* There are not as crucial, just warn if they are not created */3565 /* There are not as crucial, just warn if they are not created */
3568 3566
3569 entry = tracefs_create_file("set_event_pid", TRACE_MODE_WRITE, parent,3567 trace_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
3570 tr, &ftrace_set_event_pid_fops);3568 tr, &ftrace_set_event_pid_fops);
3571 if (!entry)
3572 pr_warn("Could not create tracefs 'set_event_pid' entry\n");
3573 3569
3574 entry = tracefs_create_file("set_event_notrace_pid",3570 trace_create_file("set_event_notrace_pid",
3575 TRACE_MODE_WRITE, parent, tr,3571 TRACE_MODE_WRITE, parent, tr,
3576 &ftrace_set_event_notrace_pid_fops);3572 &ftrace_set_event_notrace_pid_fops);
3577 if (!entry)
3578 pr_warn("Could not create tracefs 'set_event_notrace_pid' entry\n");
3579 3573
3580 /* ring buffer internal formats */3574 /* ring buffer internal formats */
3581 trace_create_file("header_page", TRACE_MODE_READ, d_events,3575 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
3790__init int event_trace_init(void)3784__init int event_trace_init(void)
3791{3785{
3792 struct trace_array *tr;3786 struct trace_array *tr;
3793 struct dentry *entry;
3794 int ret;3787 int ret;
3795 3788
3796 tr = top_trace_array();3789 tr = top_trace_array();
3797 if (!tr)3790 if (!tr)
3798 return -ENODEV;3791 return -ENODEV;
3799 3792
3800 entry = tracefs_create_file("available_events", TRACE_MODE_READ,3793 trace_create_file("available_events", TRACE_MODE_READ,
3801 NULL, tr, &ftrace_avail_fops);3794 NULL, tr, &ftrace_avail_fops);
3802 if (!entry)
3803 pr_warn("Could not create tracefs 'available_events' entry\n");
3804 3795
3805 ret = early_event_add_tracer(NULL, tr);3796 ret = early_event_add_tracer(NULL, tr);
3806 if (ret)3797 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
1816 * create_filter - create a filter for a trace_event_call1816 * create_filter - create a filter for a trace_event_call
1817 * @tr: the trace array associated with these events1817 * @tr: the trace array associated with these events
1818 * @call: trace_event_call to create a filter for1818 * @call: trace_event_call to create a filter for
1819 * @filter_str: filter string1819 * @filter_string: filter string
1820 * @set_str: remember @filter_str and enable detailed error in filter1820 * @set_str: remember @filter_str and enable detailed error in filter
1821 * @filterp: out param for created filter (always updated on return)1821 * @filterp: out param for created filter (always updated on return)
1822 * Must be a pointer that references a NULL pointer.1822 * 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
2093 return err;2093 return err;
2094 free:2094 free:
2095 kfree(ref_field->system);2095 kfree(ref_field->system);
2096 ref_field->system = NULL;
2096 kfree(ref_field->event_name);2097 kfree(ref_field->event_name);
2098 ref_field->event_name = NULL;
2097 kfree(ref_field->name);2099 kfree(ref_field->name);
2100 ref_field->name = NULL;
2098 2101
2099 goto out;2102 goto out;
2100}2103}
@@ -2785,7 +2788,8 @@ static char *find_trigger_filter(struct hist_trigger_data *hist_data, · 684 unmodified lines
2785static struct event_command trigger_hist_cmd;2788static struct event_command trigger_hist_cmd;
2786static int event_hist_trigger_parse(struct event_command *cmd_ops,2789static int event_hist_trigger_parse(struct event_command *cmd_ops,
2787 struct trace_event_file *file,2790 struct trace_event_file *file,
2788 char *glob, char *cmd, char *param);2791 char *glob, char *cmd,
2792 char *param_and_filter);
2789 2793
2790static bool compatible_keys(struct hist_trigger_data *target_hist_data,2794static bool compatible_keys(struct hist_trigger_data *target_hist_data,
2791 struct hist_trigger_data *hist_data,2795 struct hist_trigger_data *hist_data,
@@ -4161,7 +4165,7 @@ static int create_val_field(struct hist_trigger_data *hist_data, · 1369 unmodified lines
4161 return __create_val_field(hist_data, val_idx, file, NULL, field_str, 0);4165 return __create_val_field(hist_data, val_idx, file, NULL, field_str, 0);
4162}4166}
4163 4167
4164static const char *no_comm = "(no comm)";4168static const char no_comm[] = "(no comm)";
4165 4169
4166static u64 hist_field_execname(struct hist_field *hist_field,4170static u64 hist_field_execname(struct hist_field *hist_field,
4167 struct tracing_map_elt *elt,4171 struct tracing_map_elt *elt,
@@ -5252,7 +5256,7 @@ static void hist_trigger_show(struct seq_file *m, · 1084 unmodified lines
5252 seq_puts(m, "\n\n");5256 seq_puts(m, "\n\n");
5253 5257
5254 seq_puts(m, "# event histogram\n#\n# trigger info: ");5258 seq_puts(m, "# event histogram\n#\n# trigger info: ");
5255 data->ops->print(m, data->ops, data);5259 data->ops->print(m, data);
5256 seq_puts(m, "#\n\n");5260 seq_puts(m, "#\n\n");
5257 5261
5258 hist_data = data->private_data;5262 hist_data = data->private_data;
@@ -5484,7 +5488,7 @@ static void hist_trigger_debug_show(struct seq_file *m, · 225 unmodified lines
5484 seq_puts(m, "\n\n");5488 seq_puts(m, "\n\n");
5485 5489
5486 seq_puts(m, "# event histogram\n#\n# trigger info: ");5490 seq_puts(m, "# event histogram\n#\n# trigger info: ");
5487 data->ops->print(m, data->ops, data);5491 data->ops->print(m, data);
5488 seq_puts(m, "#\n\n");5492 seq_puts(m, "#\n\n");
5489 5493
5490 hist_data = data->private_data;5494 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
5621}5625}
5622 5626
5623static int event_hist_trigger_print(struct seq_file *m,5627static int event_hist_trigger_print(struct seq_file *m,
5624 struct event_trigger_ops *ops,
5625 struct event_trigger_data *data)5628 struct event_trigger_data *data)
5626{5629{
5627 struct hist_trigger_data *hist_data = data->private_data;5630 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
5729 return 0;5732 return 0;
5730}5733}
5731 5734
5732static int event_hist_trigger_init(struct event_trigger_ops *ops,5735static int event_hist_trigger_init(struct event_trigger_data *data)
5733 struct event_trigger_data *data)
5734{5736{
5735 struct hist_trigger_data *hist_data = data->private_data;5737 struct hist_trigger_data *hist_data = data->private_data;
5736 5738
@@ -5758,8 +5760,7 @@ static void unregister_field_var_hists(struct hist_trigger_data *hist_data) · 21 unmodified lines
5758 }5760 }
5759}5761}
5760 5762
5761static void event_hist_trigger_free(struct event_trigger_ops *ops,5763static void event_hist_trigger_free(struct event_trigger_data *data)
5762 struct event_trigger_data *data)
5763{5764{
5764 struct hist_trigger_data *hist_data = data->private_data;5765 struct hist_trigger_data *hist_data = data->private_data;
5765 5766
@@ -5788,25 +5789,23 @@ static struct event_trigger_ops event_hist_trigger_ops = { · 22 unmodified lines
5788 .free = event_hist_trigger_free,5789 .free = event_hist_trigger_free,
5789};5790};
5790 5791
5791static int event_hist_trigger_named_init(struct event_trigger_ops *ops,5792static int event_hist_trigger_named_init(struct event_trigger_data *data)
5792 struct event_trigger_data *data)
5793{5793{
5794 data->ref++;5794 data->ref++;
5795 5795
5796 save_named_trigger(data->named_data->name, data);5796 save_named_trigger(data->named_data->name, data);
5797 5797
5798 event_hist_trigger_init(ops, data->named_data);5798 event_hist_trigger_init(data->named_data);
5799 5799
5800 return 0;5800 return 0;
5801}5801}
5802 5802
5803static void event_hist_trigger_named_free(struct event_trigger_ops *ops,5803static void event_hist_trigger_named_free(struct event_trigger_data *data)
5804 struct event_trigger_data *data)
5805{5804{
5806 if (WARN_ON_ONCE(data->ref <= 0))5805 if (WARN_ON_ONCE(data->ref <= 0))
5807 return;5806 return;
5808 5807
5809 event_hist_trigger_free(ops, data->named_data);5808 event_hist_trigger_free(data->named_data);
5810 5809
5811 data->ref--;5810 data->ref--;
5812 if (!data->ref) {5811 if (!data->ref) {
@@ -5933,6 +5932,48 @@ static bool hist_trigger_match(struct event_trigger_data *data, · 120 unmodified lines
5933 return true;5932 return true;
5934}5933}
5935 5934
5935static 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
5936static int hist_register_trigger(char *glob,5977static int hist_register_trigger(char *glob,
5937 struct event_trigger_data *data,5978 struct event_trigger_data *data,
5938 struct trace_event_file *file)5979 struct trace_event_file *file)
@@ -5961,19 +6002,11 @@ static int hist_register_trigger(char *glob, · 22 unmodified lines
5961 6002
5962 list_for_each_entry(test, &file->triggers, list) {6003 list_for_each_entry(test, &file->triggers, list) {
5963 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {6004 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
5964 if (!hist_trigger_match(data, test, named_data, false))6005 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 {
5973 hist_err(tr, HIST_ERR_TRIGGER_EEXIST, 0);6006 hist_err(tr, HIST_ERR_TRIGGER_EEXIST, 0);
5974 ret = -EEXIST;6007 ret = -EEXIST;
6008 goto out;
5975 }6009 }
5976 goto out;
5977 }6010 }
5978 }6011 }
5979 new:6012 new:
@@ -5993,7 +6026,7 @@ static int hist_register_trigger(char *glob, · 13 unmodified lines
5993 }6026 }
5994 6027
5995 if (data->ops->init) {6028 if (data->ops->init) {
5996 ret = data->ops->init(data->ops, data);6029 ret = data->ops->init(data);
5997 if (ret < 0)6030 if (ret < 0)
5998 goto out;6031 goto out;
5999 }6032 }
@@ -6012,8 +6045,6 @@ static int hist_register_trigger(char *glob, · 12 unmodified lines
6012 6045
6013 if (named_data)6046 if (named_data)
6014 destroy_hist_data(hist_data);6047 destroy_hist_data(hist_data);
6015
6016 ret++;
6017 out:6048 out:
6018 return ret;6049 return ret;
6019}6050}
@@ -6089,20 +6120,19 @@ static void hist_unregister_trigger(char *glob, · 69 unmodified lines
6089 struct event_trigger_data *data,6120 struct event_trigger_data *data,
6090 struct trace_event_file *file)6121 struct trace_event_file *file)
6091{6122{
6123 struct event_trigger_data *test = NULL, *iter, *named_data = NULL;
6092 struct hist_trigger_data *hist_data = data->private_data;6124 struct hist_trigger_data *hist_data = data->private_data;
6093 struct event_trigger_data *test, *named_data = NULL;
6094 bool unregistered = false;
6095 6125
6096 lockdep_assert_held(&event_mutex);6126 lockdep_assert_held(&event_mutex);
6097 6127
6098 if (hist_data->attrs->name)6128 if (hist_data->attrs->name)
6099 named_data = find_named_trigger(hist_data->attrs->name);6129 named_data = find_named_trigger(hist_data->attrs->name);
6100 6130
6101 list_for_each_entry(test, &file->triggers, list) {6131 list_for_each_entry(iter, &file->triggers, list) {
6102 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {6132 if (iter->cmd_ops->trigger_type == ETT_EVENT_HIST) {
6103 if (!hist_trigger_match(data, test, named_data, false))6133 if (!hist_trigger_match(data, iter, named_data, false))
6104 continue;6134 continue;
6105 unregistered = true;6135 test = iter;
6106 list_del_rcu(&test->list);6136 list_del_rcu(&test->list);
6107 trace_event_trigger_enable_disable(file, 0);6137 trace_event_trigger_enable_disable(file, 0);
6108 update_cond_flag(file);6138 update_cond_flag(file);
@@ -6110,11 +6140,11 @@ static void hist_unregister_trigger(char *glob, · 1 unmodified line
6110 }6140 }
6111 }6141 }
6112 6142
6113 if (unregistered && test->ops->free)6143 if (test && test->ops->free)
6114 test->ops->free(test->ops, test);6144 test->ops->free(test);
6115 6145
6116 if (hist_data->enable_timestamps) {6146 if (hist_data->enable_timestamps) {
6117 if (!hist_data->remove || unregistered)6147 if (!hist_data->remove || test)
6118 tracing_set_filter_buffering(file->tr, false);6148 tracing_set_filter_buffering(file->tr, false);
6119 }6149 }
6120}6150}
@@ -6164,57 +6194,57 @@ static void hist_unreg_all(struct trace_event_file *file) · 43 unmodified lines
6164 if (hist_data->enable_timestamps)6194 if (hist_data->enable_timestamps)
6165 tracing_set_filter_buffering(file->tr, false);6195 tracing_set_filter_buffering(file->tr, false);
6166 if (test->ops->free)6196 if (test->ops->free)
6167 test->ops->free(test->ops, test);6197 test->ops->free(test);
6168 }6198 }
6169 }6199 }
6170}6200}
6171 6201
6172static int event_hist_trigger_parse(struct event_command *cmd_ops,6202static int event_hist_trigger_parse(struct event_command *cmd_ops,
6173 struct trace_event_file *file,6203 struct trace_event_file *file,
6174 char *glob, char *cmd, char *param)6204 char *glob, char *cmd,
6205 char *param_and_filter)
6175{6206{
6176 unsigned int hist_trigger_bits = TRACING_MAP_BITS_DEFAULT;6207 unsigned int hist_trigger_bits = TRACING_MAP_BITS_DEFAULT;
6177 struct event_trigger_data *trigger_data;6208 struct event_trigger_data *trigger_data;
6178 struct hist_trigger_attrs *attrs;6209 struct hist_trigger_attrs *attrs;
6179 struct event_trigger_ops *trigger_ops;
6180 struct hist_trigger_data *hist_data;6210 struct hist_trigger_data *hist_data;
6211 char *param, *filter, *p, *start;
6181 struct synth_event *se;6212 struct synth_event *se;
6182 const char *se_name;6213 const char *se_name;
6183 bool remove = false;6214 bool remove;
6184 char *trigger, *p, *start;
6185 int ret = 0;6215 int ret = 0;
6186 6216
6187 lockdep_assert_held(&event_mutex);6217 lockdep_assert_held(&event_mutex);
6188 6218
6189 WARN_ON(!glob);6219 if (WARN_ON(!glob))
6220 return -EINVAL;
6190 6221
6191 if (strlen(glob)) {6222 if (glob[0]) {
6192 hist_err_clear();6223 hist_err_clear();
6193 last_cmd_set(file, param);6224 last_cmd_set(file, param_and_filter);
6194 }6225 }
6195 6226
6196 if (!param)6227 remove = event_trigger_check_remove(glob);
6197 return -EINVAL;
6198 6228
6199 if (glob[0] == '!')6229 if (event_trigger_empty_param(param_and_filter))
6200 remove = true;6230 return -EINVAL;
6201 6231
6202 /*6232 /*
6203 * separate the trigger from the filter (k:v [if filter])6233 * separate the trigger from the filter (k:v [if filter])
6204 * allowing for whitespace in the trigger6234 * allowing for whitespace in the trigger
6205 */6235 */
6206 p = trigger = param;6236 p = param = param_and_filter;
6207 do {6237 do {
6208 p = strstr(p, "if");6238 p = strstr(p, "if");
6209 if (!p)6239 if (!p)
6210 break;6240 break;
6211 if (p == param)6241 if (p == param_and_filter)
6212 return -EINVAL;6242 return -EINVAL;
6213 if (*(p - 1) != ' ' && *(p - 1) != '\t') {6243 if (*(p - 1) != ' ' && *(p - 1) != '\t') {
6214 p++;6244 p++;
6215 continue;6245 continue;
6216 }6246 }
6217 if (p >= param + strlen(param) - (sizeof("if") - 1) - 1)6247 if (p >= param_and_filter + strlen(param_and_filter) - (sizeof("if") - 1) - 1)
6218 return -EINVAL;6248 return -EINVAL;
6219 if (*(p + sizeof("if") - 1) != ' ' && *(p + sizeof("if") - 1) != '\t') {6249 if (*(p + sizeof("if") - 1) != ' ' && *(p + sizeof("if") - 1) != '\t') {
6220 p++;6250 p++;
@@ -6224,24 +6254,24 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 3 unmodified lines
6224 } while (1);6254 } while (1);
6225 6255
6226 if (!p)6256 if (!p)
6227 param = NULL;6257 filter = NULL;
6228 else {6258 else {
6229 *(p - 1) = '\0';6259 *(p - 1) = '\0';
6230 param = strstrip(p);6260 filter = strstrip(p);
6231 trigger = strstrip(trigger);6261 param = strstrip(param);
6232 }6262 }
6233 6263
6234 /*6264 /*
6235 * To simplify arithmetic expression parsing, replace occurrences of6265 * To simplify arithmetic expression parsing, replace occurrences of
6236 * '.sym-offset' modifier with '.symXoffset'6266 * '.sym-offset' modifier with '.symXoffset'
6237 */6267 */
6238 start = strstr(trigger, ".sym-offset");6268 start = strstr(param, ".sym-offset");
6239 while (start) {6269 while (start) {
6240 *(start + 4) = 'X';6270 *(start + 4) = 'X';
6241 start = strstr(start + 11, ".sym-offset");6271 start = strstr(start + 11, ".sym-offset");
6242 }6272 }
6243 6273
6244 attrs = parse_hist_trigger_attrs(file->tr, trigger);6274 attrs = parse_hist_trigger_attrs(file->tr, param);
6245 if (IS_ERR(attrs))6275 if (IS_ERR(attrs))
6246 return PTR_ERR(attrs);6276 return PTR_ERR(attrs);
6247 6277
@@ -6254,29 +6284,15 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 6 unmodified lines
6254 return PTR_ERR(hist_data);6284 return PTR_ERR(hist_data);
6255 }6285 }
6256 6286
6257 trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);6287 trigger_data = event_trigger_alloc(cmd_ops, cmd, param, hist_data);
6258
6259 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
6260 if (!trigger_data) {6288 if (!trigger_data) {
6261 ret = -ENOMEM;6289 ret = -ENOMEM;
6262 goto out_free;6290 goto out_free;
6263 }6291 }
6264 6292
6265 trigger_data->count = -1;6293 ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
6266 trigger_data->ops = trigger_ops;6294 if (ret < 0)
6267 trigger_data->cmd_ops = cmd_ops;6295 goto out_free;
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 }
6280 6296
6281 if (remove) {6297 if (remove) {
6282 if (!have_hist_trigger_match(trigger_data, file))6298 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
6287 goto out_free;6303 goto out_free;
6288 }6304 }
6289 6305
6290 cmd_ops->unreg(glob+1, trigger_data, file);6306 event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
6291 se_name = trace_event_name(file->event_call);6307 se_name = trace_event_name(file->event_call);
6292 se = find_synth_event(se_name);6308 se = find_synth_event(se_name);
6293 if (se)6309 if (se)
@@ -6296,17 +6312,11 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, · 2 unmodified lines
6296 goto out_free;6312 goto out_free;
6297 }6313 }
6298 6314
6299 ret = cmd_ops->reg(glob, trigger_data, file);6315 if (existing_hist_update_only(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;
6308 goto out_free;6316 goto out_free;
6309 } else if (ret < 0)6317
6318 ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
6319 if (ret < 0)
6310 goto out_free;6320 goto out_free;
6311 6321
6312 if (get_named_trigger_data(trigger_data))6322 if (get_named_trigger_data(trigger_data))
@@ -6331,18 +6341,15 @@ enable: · 18 unmodified lines
6331 se = find_synth_event(se_name);6341 se = find_synth_event(se_name);
6332 if (se)6342 if (se)
6333 se->ref++;6343 se->ref++;
6334 /* Just return zero, not the number of registered triggers */
6335 ret = 0;
6336 out:6344 out:
6337 if (ret == 0)6345 if (ret == 0)
6338 hist_err_clear();6346 hist_err_clear();
6339 6347
6340 return ret;6348 return ret;
6341 out_unreg:6349 out_unreg:
6342 cmd_ops->unreg(glob+1, trigger_data, file);6350 event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
6343 out_free:6351 out_free:
6344 if (cmd_ops->set_filter)6352 event_trigger_reset_filter(cmd_ops, trigger_data);
6345 cmd_ops->set_filter(NULL, trigger_data, NULL);
6346 6353
6347 remove_hist_vars(hist_data);6354 remove_hist_vars(hist_data);
6348 6355
@@ -6463,7 +6470,7 @@ static void hist_enable_unreg_all(struct trace_event_file *file) · 114 unmodified lines
6463 update_cond_flag(file);6470 update_cond_flag(file);
6464 trace_event_trigger_enable_disable(file, 0);6471 trace_event_trigger_enable_disable(file, 0);
6465 if (test->ops->free)6472 if (test->ops->free)
6466 test->ops->free(test->ops, test);6473 test->ops->free(test);
6467 }6474 }
6468 }6475 }
6469}6476}
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
188 }188 }
189 189
190 data = list_entry(v, struct event_trigger_data, list);190 data = list_entry(v, struct event_trigger_data, list);
191 data->ops->print(m, data->ops, data);191 data->ops->print(m, data);
192 192
193 return 0;193 return 0;
194}194}
@@ -432,7 +432,6 @@ event_trigger_print(const char *name, struct seq_file *m, · 237 unmodified lines
432 432
433/**433/**
434 * event_trigger_init - Generic event_trigger_ops @init implementation434 * event_trigger_init - Generic event_trigger_ops @init implementation
435 * @ops: The trigger ops associated with the trigger
436 * @data: Trigger-specific data435 * @data: Trigger-specific data
437 *436 *
438 * Common implementation of event trigger initialization.437 * Common implementation of event trigger initialization.
@@ -442,8 +441,7 @@ event_trigger_print(const char *name, struct seq_file *m, · 3 unmodified lines
442 *441 *
443 * Return: 0 on success, errno otherwise442 * Return: 0 on success, errno otherwise
444 */443 */
445int event_trigger_init(struct event_trigger_ops *ops,444int event_trigger_init(struct event_trigger_data *data)
446 struct event_trigger_data *data)
447{445{
448 data->ref++;446 data->ref++;
449 return 0;447 return 0;
@@ -451,7 +449,6 @@ int event_trigger_init(struct event_trigger_ops *ops, · 1 unmodified line
451 449
452/**450/**
453 * event_trigger_free - Generic event_trigger_ops @free implementation451 * event_trigger_free - Generic event_trigger_ops @free implementation
454 * @ops: The trigger ops associated with the trigger
455 * @data: Trigger-specific data452 * @data: Trigger-specific data
456 *453 *
457 * Common implementation of event trigger de-initialization.454 * Common implementation of event trigger de-initialization.
@@ -460,8 +457,7 @@ int event_trigger_init(struct event_trigger_ops *ops, · 2 unmodified lines
460 * implementations.457 * implementations.
461 */458 */
462static void459static void
463event_trigger_free(struct event_trigger_ops *ops,460event_trigger_free(struct event_trigger_data *data)
464 struct event_trigger_data *data)
465{461{
466 if (WARN_ON_ONCE(data->ref <= 0))462 if (WARN_ON_ONCE(data->ref <= 0))
467 return;463 return;
@@ -515,7 +511,7 @@ clear_event_triggers(struct trace_array *tr) · 47 unmodified lines
515 trace_event_trigger_enable_disable(file, 0);511 trace_event_trigger_enable_disable(file, 0);
516 list_del_rcu(&data->list);512 list_del_rcu(&data->list);
517 if (data->ops->free)513 if (data->ops->free)
518 data->ops->free(data->ops, data);514 data->ops->free(data);
519 }515 }
520 }516 }
521}517}
@@ -581,19 +577,18 @@ static int register_trigger(char *glob, · 59 unmodified lines
581 }577 }
582 578
583 if (data->ops->init) {579 if (data->ops->init) {
584 ret = data->ops->init(data->ops, data);580 ret = data->ops->init(data);
585 if (ret < 0)581 if (ret < 0)
586 goto out;582 goto out;
587 }583 }
588 584
589 list_add_rcu(&data->list, &file->triggers);585 list_add_rcu(&data->list, &file->triggers);
590 ret++;
591 586
592 update_cond_flag(file);587 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) {
594 list_del_rcu(&data->list);590 list_del_rcu(&data->list);
595 update_cond_flag(file);591 update_cond_flag(file);
596 ret--;
597 }592 }
598out:593out:
599 return ret;594 return ret;
@@ -614,14 +609,13 @@ static void unregister_trigger(char *glob, · 14 unmodified lines
614 struct event_trigger_data *test,609 struct event_trigger_data *test,
615 struct trace_event_file *file)610 struct trace_event_file *file)
616{611{
617 struct event_trigger_data *data;612 struct event_trigger_data *data = NULL, *iter;
618 bool unregistered = false;
619 613
620 lockdep_assert_held(&event_mutex);614 lockdep_assert_held(&event_mutex);
621 615
622 list_for_each_entry(data, &file->triggers, list) {616 list_for_each_entry(iter, &file->triggers, list) {
623 if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {617 if (iter->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
624 unregistered = true;618 data = iter;
625 list_del_rcu(&data->list);619 list_del_rcu(&data->list);
626 trace_event_trigger_enable_disable(file, 0);620 trace_event_trigger_enable_disable(file, 0);
627 update_cond_flag(file);621 update_cond_flag(file);
@@ -629,8 +623,8 @@ static void unregister_trigger(char *glob, · 1 unmodified line
629 }623 }
630 }624 }
631 625
632 if (unregistered && data->ops->free)626 if (data && data->ops->free)
633 data->ops->free(data->ops, data);627 data->ops->free(data);
634}628}
635 629
636/*630/*
@@ -744,15 +738,15 @@ bool event_trigger_empty_param(const char *param) · 107 unmodified lines
744 738
745/**739/**
746 * event_trigger_separate_filter - separate an event trigger from a filter740 * event_trigger_separate_filter - separate an event trigger from a filter
747 * @param: The param string containing trigger and possibly filter741 * @param_and_filter: String containing trigger and possibly filter
748 * @trigger: outparam, will be filled with a pointer to the trigger742 * @param: outparam, will be filled with a pointer to the trigger
749 * @filter: outparam, will be filled with a pointer to the filter743 * @filter: outparam, will be filled with a pointer to the filter
750 * @param_required: Specifies whether or not the param string is required744 * @param_required: Specifies whether or not the param string is required
751 *745 *
752 * Given a param string of the form '[trigger] [if filter]', this746 * Given a param string of the form '[trigger] [if filter]', this
753 * function separates the filter from the trigger and returns the747 * function separates the filter from the trigger and returns the
754 * trigger in *trigger and the filter in *filter. Either the *trigger748 * trigger in @param and the filter in @filter. Either the @param
755 * or the *filter may be set to NULL by this function - if not set to749 * or the @filter may be set to NULL by this function - if not set to
756 * NULL, they will contain strings corresponding to the trigger and750 * NULL, they will contain strings corresponding to the trigger and
757 * filter.751 * filter.
758 *752 *
@@ -927,48 +921,37 @@ void event_trigger_reset_filter(struct event_command *cmd_ops, · 168 unmodified lines
927 * @cmd_ops: The event_command operations for the trigger921 * @cmd_ops: The event_command operations for the trigger
928 * @file: The event file for the trigger's event922 * @file: The event file for the trigger's event
929 * @glob: The trigger command string, with optional remove(!) operator923 * @glob: The trigger command string, with optional remove(!) operator
930 * @cmd: The cmd string
931 * @param: The param string
932 * @trigger_data: The trigger_data for the trigger924 * @trigger_data: The trigger_data for the trigger
933 * @n_registered: optional outparam, the number of triggers registered
934 *925 *
935 * Register an event trigger. The @cmd_ops are used to call the926 * Register an event trigger. The @cmd_ops are used to call the
936 * cmd_ops->reg() function which actually does the registration. The927 * cmd_ops->reg() function which actually does the registration.
937 * cmd_ops->reg() function returns the number of triggers registered,
938 * which is assigned to n_registered, if n_registered is non-NULL.
939 *928 *
940 * Return: 0 on success, errno otherwise929 * Return: 0 on success, errno otherwise
941 */930 */
942int event_trigger_register(struct event_command *cmd_ops,931int event_trigger_register(struct event_command *cmd_ops,
943 struct trace_event_file *file,932 struct trace_event_file *file,
944 char *glob,933 char *glob,
945 char *cmd,934 struct event_trigger_data *trigger_data)
946 char *param,
947 struct event_trigger_data *trigger_data,
948 int *n_registered)
949{935{
950 int ret;936 return cmd_ops->reg(glob, trigger_data, file);
951 937}
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 }
970 938
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 */
949void 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);
972}955}
973 956
974/*957/*
@@ -981,7 +964,7 @@ int event_trigger_register(struct event_command *cmd_ops, · 6 unmodified lines
981 * @file: The trace_event_file associated with the event964 * @file: The trace_event_file associated with the event
982 * @glob: The raw string used to register the trigger965 * @glob: The raw string used to register the trigger
983 * @cmd: The cmd portion of the string used to register the trigger966 * @cmd: The cmd portion of the string used to register the trigger
984 * @param: The params portion of the string used to register the trigger967 * @param_and_filter: The param and filter portion of the string used to register the trigger
985 *968 *
986 * Common implementation for event command parsing and trigger969 * Common implementation for event command parsing and trigger
987 * instantiation.970 * instantiation.
@@ -994,94 +977,53 @@ int event_trigger_register(struct event_command *cmd_ops, · 6 unmodified lines
994static int977static int
995event_trigger_parse(struct event_command *cmd_ops,978event_trigger_parse(struct event_command *cmd_ops,
996 struct trace_event_file *file,979 struct trace_event_file *file,
997 char *glob, char *cmd, char *param)980 char *glob, char *cmd, char *param_and_filter)
998{981{
999 struct event_trigger_data *trigger_data;982 struct event_trigger_data *trigger_data;
1000 struct event_trigger_ops *trigger_ops;983 char *param, *filter;
1001 char *trigger = NULL;984 bool remove;
1002 char *number;
1003 int ret;985 int ret;
1004 986
1005 /* separate the trigger from the filter (t:n [if filter]) */987 remove = event_trigger_check_remove(glob);
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 }
1014 988
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;
1016 992
1017 ret = -ENOMEM;993 ret = -ENOMEM;
1018 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);994 trigger_data = event_trigger_alloc(cmd_ops, cmd, param, file);
1019 if (!trigger_data)995 if (!trigger_data)
1020 goto out;996 goto out;
1021 997
1022 trigger_data->count = -1;998 if (remove) {
1023 trigger_data->ops = trigger_ops;999 event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
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);
1031 kfree(trigger_data);1000 kfree(trigger_data);
1032 ret = 0;1001 ret = 0;
1033 goto out;1002 goto out;
1034 }1003 }
1035 1004
1036 if (trigger) {1005 ret = event_trigger_parse_num(param, trigger_data);
1037 number = strsep(&trigger, ":");1006 if (ret)
1038 1007 goto out_free;
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;
1057 1008
1058 ret = cmd_ops->set_filter(param, trigger_data, file);1009 ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
1059 if (ret < 0)1010 if (ret < 0)
1060 goto out_free;1011 goto out_free;
1061 1012
1062 out_reg:
1063 /* Up the trigger_data count to make sure reg doesn't free it on failure */1013 /* Up the trigger_data count to make sure reg doesn't free it on failure */
1064 event_trigger_init(trigger_ops, trigger_data);1014 event_trigger_init(trigger_data);
1065 ret = cmd_ops->reg(glob, trigger_data, file);1015
1066 /*1016 ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1067 * The above returns on success the # of functions enabled,1017 if (ret)
1068 * but if it didn't find any functions it returns zero.1018 goto out_free;
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;
1076 1019
1077 /* Down the counter of trigger_data or free it if not used anymore */1020 /* 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);
1079 out:1022 out:
1080 return ret;1023 return ret;
1081 1024
1082 out_free:1025 out_free:
1083 if (cmd_ops->set_filter)1026 event_trigger_reset_filter(cmd_ops, trigger_data);
1084 cmd_ops->set_filter(NULL, trigger_data, NULL);
1085 kfree(trigger_data);1027 kfree(trigger_data);
1086 goto out;1028 goto out;
1087}1029}
@@ -1401,16 +1343,14 @@ traceoff_count_trigger(struct event_trigger_data *data, · 313 unmodified lines
1401}1343}
1402 1344
1403static int1345static int
1404traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,1346traceon_trigger_print(struct seq_file *m, struct event_trigger_data *data)
1405 struct event_trigger_data *data)
1406{1347{
1407 return event_trigger_print("traceon", m, (void *)data->count,1348 return event_trigger_print("traceon", m, (void *)data->count,
1408 data->filter_str);1349 data->filter_str);
1409}1350}
1410 1351
1411static int1352static int
1412traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,1353traceoff_trigger_print(struct seq_file *m, struct event_trigger_data *data)
1413 struct event_trigger_data *data)
1414{1354{
1415 return event_trigger_print("traceoff", m, (void *)data->count,1355 return event_trigger_print("traceoff", m, (void *)data->count,
1416 data->filter_str);1356 data->filter_str);
@@ -1521,8 +1461,7 @@ register_snapshot_trigger(char *glob, · 104 unmodified lines
1521}1461}
1522 1462
1523static int1463static int
1524snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,1464snapshot_trigger_print(struct seq_file *m, struct event_trigger_data *data)
1525 struct event_trigger_data *data)
1526{1465{
1527 return event_trigger_print("snapshot", m, (void *)data->count,1466 return event_trigger_print("snapshot", m, (void *)data->count,
1528 data->filter_str);1467 data->filter_str);
@@ -1617,8 +1556,7 @@ stacktrace_count_trigger(struct event_trigger_data *data, · 88 unmodified lines
1617}1556}
1618 1557
1619static int1558static int
1620stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,1559stacktrace_trigger_print(struct seq_file *m, struct event_trigger_data *data)
1621 struct event_trigger_data *data)
1622{1560{
1623 return event_trigger_print("stacktrace", m, (void *)data->count,1561 return event_trigger_print("stacktrace", m, (void *)data->count,
1624 data->filter_str);1562 data->filter_str);
@@ -1708,7 +1646,6 @@ event_enable_count_trigger(struct event_trigger_data *data, · 83 unmodified lines
1708}1646}
1709 1647
1710int event_enable_trigger_print(struct seq_file *m,1648int event_enable_trigger_print(struct seq_file *m,
1711 struct event_trigger_ops *ops,
1712 struct event_trigger_data *data)1649 struct event_trigger_data *data)
1713{1650{
1714 struct enable_trigger_data *enable_data = data->private_data;1651 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
1733 return 0;1670 return 0;
1734}1671}
1735 1672
1736void event_enable_trigger_free(struct event_trigger_ops *ops,1673void event_enable_trigger_free(struct event_trigger_data *data)
1737 struct event_trigger_data *data)
1738{1674{
1739 struct enable_trigger_data *enable_data = data->private_data;1675 struct enable_trigger_data *enable_data = data->private_data;
1740 1676
@@ -1781,39 +1717,33 @@ static struct event_trigger_ops event_disable_count_trigger_ops = { · 40 unmodified lines
1781 1717
1782int event_enable_trigger_parse(struct event_command *cmd_ops,1718int event_enable_trigger_parse(struct event_command *cmd_ops,
1783 struct trace_event_file *file,1719 struct trace_event_file *file,
1784 char *glob, char *cmd, char *param)1720 char *glob, char *cmd, char *param_and_filter)
1785{1721{
1786 struct trace_event_file *event_enable_file;1722 struct trace_event_file *event_enable_file;
1787 struct enable_trigger_data *enable_data;1723 struct enable_trigger_data *enable_data;
1788 struct event_trigger_data *trigger_data;1724 struct event_trigger_data *trigger_data;
1789 struct event_trigger_ops *trigger_ops;
1790 struct trace_array *tr = file->tr;1725 struct trace_array *tr = file->tr;
1726 char *param, *filter;
1727 bool enable, remove;
1791 const char *system;1728 const char *system;
1792 const char *event;1729 const char *event;
1793 bool hist = false;1730 bool hist = false;
1794 char *trigger;
1795 char *number;
1796 bool enable;
1797 int ret;1731 int ret;
1798 1732
1799 if (!param)1733 remove = event_trigger_check_remove(glob);
1800 return -EINVAL;
1801 1734
1802 /* separate the trigger from the filter (s:e:n [if filter]) */1735 if (event_trigger_empty_param(param_and_filter))
1803 trigger = strsep(&param, " \t");
1804 if (!trigger)
1805 return -EINVAL;1736 return -EINVAL;
1806 if (param) {
1807 param = skip_spaces(param);
1808 if (!*param)
1809 param = NULL;
1810 }
1811 1737
1812 system = strsep(&trigger, ":");1738 ret = event_trigger_separate_filter(param_and_filter, &param, &filter, true);
1813 if (!trigger)1739 if (ret)
1740 return ret;
1741
1742 system = strsep(&param, ":");
1743 if (!param)
1814 return -EINVAL;1744 return -EINVAL;
1815 1745
1816 event = strsep(&trigger, ":");1746 event = strsep(&param, ":");
1817 1747
1818 ret = -EINVAL;1748 ret = -EINVAL;
1819 event_enable_file = find_event_file(tr, system, event);1749 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
1829#else1759#else
1830 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;1760 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
1831#endif1761#endif
1832 trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
1833
1834 ret = -ENOMEM;1762 ret = -ENOMEM;
1835 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
1836 if (!trigger_data)
1837 goto out;
1838 1763
1839 enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);1764 enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);
1840 if (!enable_data) {1765 if (!enable_data)
1841 kfree(trigger_data);
1842 goto out;1766 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);
1850 1767
1851 enable_data->hist = hist;1768 enable_data->hist = hist;
1852 enable_data->enable = enable;1769 enable_data->enable = enable;
1853 enable_data->file = event_enable_file;1770 enable_data->file = event_enable_file;
1854 trigger_data->private_data = enable_data;
1855 1771
1856 if (glob[0] == '!') {1772 trigger_data = event_trigger_alloc(cmd_ops, cmd, param, enable_data);
1857 cmd_ops->unreg(glob+1, trigger_data, file);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);
1858 kfree(trigger_data);1780 kfree(trigger_data);
1859 kfree(enable_data);1781 kfree(enable_data);
1860 ret = 0;1782 ret = 0;
@@ -1862,35 +1784,16 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, · 1 unmodified line
1862 }1784 }
1863 1785
1864 /* Up the trigger_data count to make sure nothing frees it on failure */1786 /* Up the trigger_data count to make sure nothing frees it on failure */
1865 event_trigger_init(trigger_ops, trigger_data);1787 event_trigger_init(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 }
1882 1788
1883 if (!param) /* if param is non-empty, it's supposed to be a filter */1789 ret = event_trigger_parse_num(param, trigger_data);
1884 goto out_reg;1790 if (ret)
1885 1791 goto out_free;
1886 if (!cmd_ops->set_filter)
1887 goto out_reg;
1888 1792
1889 ret = cmd_ops->set_filter(param, trigger_data, file);1793 ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
1890 if (ret < 0)1794 if (ret < 0)
1891 goto out_free;1795 goto out_free;
1892 1796
1893 out_reg:
1894 /* Don't let event modules unload while probe registered */1797 /* Don't let event modules unload while probe registered */
1895 ret = trace_event_try_get_ref(event_enable_file->event_call);1798 ret = trace_event_try_get_ref(event_enable_file->event_call);
1896 if (!ret) {1799 if (!ret) {
@@ -1901,32 +1804,23 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, · 4 unmodified lines
1901 ret = trace_event_enable_disable(event_enable_file, 1, 1);1804 ret = trace_event_enable_disable(event_enable_file, 1, 1);
1902 if (ret < 0)1805 if (ret < 0)
1903 goto out_put;1806 goto out_put;
1904 ret = cmd_ops->reg(glob, trigger_data, file);1807
1905 /*1808 ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1906 * The above returns on success the # of functions enabled,1809 if (ret)
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)
1914 goto out_disable;1810 goto out_disable;
1915 /* Just return zero, not the number of enabled functions */1811
1916 ret = 0;1812 event_trigger_free(trigger_data);
1917 event_trigger_free(trigger_ops, trigger_data);
1918 out:1813 out:
1919 return ret;1814 return ret;
1920
1921 out_disable:1815 out_disable:
1922 trace_event_enable_disable(event_enable_file, 0, 1);1816 trace_event_enable_disable(event_enable_file, 0, 1);
1923 out_put:1817 out_put:
1924 trace_event_put_ref(event_enable_file->event_call);1818 trace_event_put_ref(event_enable_file->event_call);
1925 out_free:1819 out_free:
1926 if (cmd_ops->set_filter)1820 event_trigger_reset_filter(cmd_ops, trigger_data);
1927 cmd_ops->set_filter(NULL, trigger_data, NULL);1821 event_trigger_free(trigger_data);
1928 event_trigger_free(trigger_ops, trigger_data);
1929 kfree(enable_data);1822 kfree(enable_data);
1823
1930 goto out;1824 goto out;
1931}1825}
1932 1826
@@ -1953,19 +1847,18 @@ int event_enable_register_trigger(char *glob, · 20 unmodified lines
1953 }1847 }
1954 1848
1955 if (data->ops->init) {1849 if (data->ops->init) {
1956 ret = data->ops->init(data->ops, data);1850 ret = data->ops->init(data);
1957 if (ret < 0)1851 if (ret < 0)
1958 goto out;1852 goto out;
1959 }1853 }
1960 1854
1961 list_add_rcu(&data->list, &file->triggers);1855 list_add_rcu(&data->list, &file->triggers);
1962 ret++;
1963 1856
1964 update_cond_flag(file);1857 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) {
1966 list_del_rcu(&data->list);1860 list_del_rcu(&data->list);
1967 update_cond_flag(file);1861 update_cond_flag(file);
1968 ret--;
1969 }1862 }
1970out:1863out:
1971 return ret;1864 return ret;
@@ -1976,19 +1869,18 @@ void event_enable_unregister_trigger(char *glob, · 4 unmodified lines
1976 struct trace_event_file *file)1869 struct trace_event_file *file)
1977{1870{
1978 struct enable_trigger_data *test_enable_data = test->private_data;1871 struct enable_trigger_data *test_enable_data = test->private_data;
1872 struct event_trigger_data *data = NULL, *iter;
1979 struct enable_trigger_data *enable_data;1873 struct enable_trigger_data *enable_data;
1980 struct event_trigger_data *data;
1981 bool unregistered = false;
1982 1874
1983 lockdep_assert_held(&event_mutex);1875 lockdep_assert_held(&event_mutex);
1984 1876
1985 list_for_each_entry(data, &file->triggers, list) {1877 list_for_each_entry(iter, &file->triggers, list) {
1986 enable_data = data->private_data;1878 enable_data = iter->private_data;
1987 if (enable_data &&1879 if (enable_data &&
1988 (data->cmd_ops->trigger_type ==1880 (iter->cmd_ops->trigger_type ==
1989 test->cmd_ops->trigger_type) &&1881 test->cmd_ops->trigger_type) &&
1990 (enable_data->file == test_enable_data->file)) {1882 (enable_data->file == test_enable_data->file)) {
1991 unregistered = true;1883 data = iter;
1992 list_del_rcu(&data->list);1884 list_del_rcu(&data->list);
1993 trace_event_trigger_enable_disable(file, 0);1885 trace_event_trigger_enable_disable(file, 0);
1994 update_cond_flag(file);1886 update_cond_flag(file);
@@ -1996,8 +1888,8 @@ void event_enable_unregister_trigger(char *glob, · 1 unmodified line
1996 }1888 }
1997 }1889 }
1998 1890
1999 if (unregistered && data->ops->free)1891 if (data && data->ops->free)
2000 data->ops->free(data->ops, data);1892 data->ops->free(data);
2001}1893}
2002 1894
2003static struct event_trigger_ops *1895static struct event_trigger_ops *
kernel/trace/trace_kprobe.c+4−11
@@ -1907,25 +1907,18 @@ core_initcall(init_kprobe_trace_early); · 1906 unmodified lines
1907static __init int init_kprobe_trace(void)1907static __init int init_kprobe_trace(void)
1908{1908{
1909 int ret;1909 int ret;
1910 struct dentry *entry;
1911 1910
1912 ret = tracing_init_dentry();1911 ret = tracing_init_dentry();
1913 if (ret)1912 if (ret)
1914 return 0;1913 return 0;
1915 1914
1916 entry = tracefs_create_file("kprobe_events", TRACE_MODE_WRITE,
1917 NULL, NULL, &kprobe_events_ops);
1918
1919 /* Event list interface */1915 /* Event list interface */
1920 if (!entry)1916 trace_create_file("kprobe_events", TRACE_MODE_WRITE,
1921 pr_warn("Could not create tracefs 'kprobe_events' entry\n");1917 NULL, NULL, &kprobe_events_ops);
1922 1918
1923 /* Profile interface */1919 /* Profile interface */
1924 entry = tracefs_create_file("kprobe_profile", TRACE_MODE_READ,1920 trace_create_file("kprobe_profile", TRACE_MODE_READ,
1925 NULL, NULL, &kprobe_profile_ops);1921 NULL, NULL, &kprobe_profile_ops);
1926
1927 if (!entry)
1928 pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
1929 1922
1930 setup_boot_kprobe_events();1923 setup_boot_kprobe_events();
1931 1924
kernel/trace/trace_osnoise.c+19−3
@@ -1578,11 +1578,27 @@ static enum hrtimer_restart timerlat_irq(struct hrtimer *timer) · 1577 unmodified lines
1578 1578
1579 trace_timerlat_sample(&s);1579 trace_timerlat_sample(&s);
1580 1580
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 }
1582 1595
1583 if (osnoise_data.stop_tracing)
1584 if (time_to_us(diff) >= osnoise_data.stop_tracing)
1585 osnoise_stop_tracing();1596 osnoise_stop_tracing();
1597 notify_new_max_latency(diff);
1598
1599 return HRTIMER_NORESTART;
1600 }
1601 }
1586 1602
1587 wake_up_process(tlat->kthread);1603 wake_up_process(tlat->kthread);
1588 1604
kernel/trace/trace_output.c+12−13
@@ -692,7 +692,7 @@ static LIST_HEAD(ftrace_event_list); · 691 unmodified lines
692 692
693static int trace_search_list(struct list_head **list)693static int trace_search_list(struct list_head **list)
694{694{
695 struct trace_event *e;695 struct trace_event *e = NULL, *iter;
696 int next = __TRACE_LAST_TYPE;696 int next = __TRACE_LAST_TYPE;
697 697
698 if (list_empty(&ftrace_event_list)) {698 if (list_empty(&ftrace_event_list)) {
@@ -704,9 +704,11 @@ static int trace_search_list(struct list_head **list) · 5 unmodified lines
704 * We used up all possible max events,704 * We used up all possible max events,
705 * lets see if somebody freed one.705 * lets see if somebody freed one.
706 */706 */
707 list_for_each_entry(e, &ftrace_event_list, list) {707 list_for_each_entry(iter, &ftrace_event_list, list) {
708 if (e->type != next)708 if (iter->type != next) {
709 e = iter;
709 break;710 break;
711 }
710 next++;712 next++;
711 }713 }
712 714
@@ -714,7 +716,10 @@ static int trace_search_list(struct list_head **list) · 1 unmodified line
714 if (next > TRACE_EVENT_TYPE_MAX)716 if (next > TRACE_EVENT_TYPE_MAX)
715 return 0;717 return 0;
716 718
717 *list = &e->list;719 if (e)
720 *list = &e->list;
721 else
722 *list = &ftrace_event_list;
718 return next;723 return next;
719}724}
720 725
@@ -778,9 +783,8 @@ int register_trace_event(struct trace_event *event) · 57 unmodified lines
778 783
779 list_add_tail(&event->list, list);784 list_add_tail(&event->list, list);
780 785
781 } else if (event->type > __TRACE_LAST_TYPE) {786 } else if (WARN(event->type > __TRACE_LAST_TYPE,
782 printk(KERN_WARNING "Need to add type to trace.h\n");787 "Need to add type to trace.h")) {
783 WARN_ON(1);
784 goto out;788 goto out;
785 } else {789 } else {
786 /* Is this event already used */790 /* Is this event already used */
@@ -1571,13 +1575,8 @@ __init static int init_events(void) · 784 unmodified lines
1571 1575
1572 for (i = 0; events[i]; i++) {1576 for (i = 0; events[i]; i++) {
1573 event = events[i];1577 event = events[i];
1574
1575 ret = register_trace_event(event);1578 ret = register_trace_event(event);
1576 if (!ret) {1579 WARN_ONCE(!ret, "event %d failed to register", event->type);
1577 printk(KERN_WARNING "event %d failed to register\n",
1578 event->type);
1579 WARN_ON_ONCE(1);
1580 }
1581 }1580 }
1582 1581
1583 return 0;1582 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
224 224
225__init static int create_recursed_functions(void)225__init static int create_recursed_functions(void)
226{226{
227 struct dentry *dentry;
228 227
229 dentry = trace_create_file("recursed_functions", TRACE_MODE_WRITE,228 trace_create_file("recursed_functions", TRACE_MODE_WRITE,
230 NULL, NULL, &recursed_functions_fops);229 NULL, NULL, &recursed_functions_fops);
231 if (!dentry)
232 pr_warn("WARNING: Failed to create recursed_functions\n");
233 return 0;230 return 0;
234}231}
235 232
kernel/trace/trace_selftest.c+3−0
@@ -895,6 +895,9 @@ trace_selftest_startup_function_graph(struct tracer *trace, · 894 unmodified lines
895 ret = -1;895 ret = -1;
896 goto out;896 goto out;
897 }897 }
898
899 /* Enable tracing on all functions again */
900 ftrace_set_global_filter(NULL, 0, 1);
898#endif901#endif
899 902
900 /* Don't test dynamic tracing, the function tracer already did */903 /* 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
154 goto end;154 goto end;
155 155
156 /* parameter types */156 /* parameter types */
157 if (tr->trace_flags & TRACE_ITER_VERBOSE)157 if (tr && tr->trace_flags & TRACE_ITER_VERBOSE)
158 trace_seq_printf(s, "%s ", entry->types[i]);158 trace_seq_printf(s, "%s ", entry->types[i]);
159 159
160 /* parameter values */160 /* parameter values */
@@ -296,9 +296,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 135 unmodified lines
296 struct trace_event_file *trace_file;296 struct trace_event_file *trace_file;
297 struct syscall_trace_enter *entry;297 struct syscall_trace_enter *entry;
298 struct syscall_metadata *sys_data;298 struct syscall_metadata *sys_data;
299 struct ring_buffer_event *event;299 struct trace_event_buffer fbuffer;
300 struct trace_buffer *buffer;
301 unsigned int trace_ctx;
302 unsigned long args[6];300 unsigned long args[6];
303 int syscall_nr;301 int syscall_nr;
304 int size;302 int size;
@@ -321,20 +319,16 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 16 unmodified lines
321 319
322 size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;320 size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;
323 321
324 trace_ctx = tracing_gen_ctx();322 entry = trace_event_buffer_reserve(&fbuffer, trace_file, size);
325 323 if (!entry)
326 event = trace_event_buffer_lock_reserve(&buffer, trace_file,
327 sys_data->enter_event->event.type, size, trace_ctx);
328 if (!event)
329 return;324 return;
330 325
331 entry = ring_buffer_event_data(event);326 entry = ring_buffer_event_data(fbuffer.event);
332 entry->nr = syscall_nr;327 entry->nr = syscall_nr;
333 syscall_get_arguments(current, regs, args);328 syscall_get_arguments(current, regs, args);
334 memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args);329 memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args);
335 330
336 event_trigger_unlock_commit(trace_file, buffer, event, entry,331 trace_event_buffer_commit(&fbuffer);
337 trace_ctx);
338}332}
339 333
340static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)334static 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
343 struct trace_event_file *trace_file;337 struct trace_event_file *trace_file;
344 struct syscall_trace_exit *entry;338 struct syscall_trace_exit *entry;
345 struct syscall_metadata *sys_data;339 struct syscall_metadata *sys_data;
346 struct ring_buffer_event *event;340 struct trace_event_buffer fbuffer;
347 struct trace_buffer *buffer;
348 unsigned int trace_ctx;
349 int syscall_nr;341 int syscall_nr;
350 342
351 syscall_nr = trace_get_syscall_nr(current, regs);343 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
364 if (!sys_data)356 if (!sys_data)
365 return;357 return;
366 358
367 trace_ctx = tracing_gen_ctx();359 entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry));
368 360 if (!entry)
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)
373 return;361 return;
374 362
375 entry = ring_buffer_event_data(event);363 entry = ring_buffer_event_data(fbuffer.event);
376 entry->nr = syscall_nr;364 entry->nr = syscall_nr;
377 entry->ret = syscall_get_return_value(current, regs);365 entry->ret = syscall_get_return_value(current, regs);
378 366
379 event_trigger_unlock_commit(trace_file, buffer, event, entry,367 trace_event_buffer_commit(&fbuffer);
380 trace_ctx);
381}368}
382 369
383static int reg_event_syscall_enter(struct trace_event_file *file,370static 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
1045/**1045/**
1046 * tracing_map_sort_entries - Sort the current set of tracing_map_elts in a map1046 * tracing_map_sort_entries - Sort the current set of tracing_map_elts in a map
1047 * @map: The tracing_map1047 * @map: The tracing_map
1048 * @sort_key: The sort key to use for sorting1048 * @sort_keys: The sort key to use for sorting
1049 * @n_sort_keys: hitcount, always have at least one
1049 * @sort_entries: outval: pointer to allocated and sorted array of entries1050 * @sort_entries: outval: pointer to allocated and sorted array of entries
1050 *1051 *
1051 * tracing_map_sort_entries() sorts the current set of entries in the1052 * tracing_map_sort_entries() sorts the current set of entries in the
lib/.gitignore+1−0
@@ -1,6 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0-only1# SPDX-License-Identifier: GPL-2.0-only
2/crc32table.h2/crc32table.h
3/crc64table.h3/crc64table.h
4/default.bconf
4/gen_crc32table5/gen_crc32table
5/gen_crc64table6/gen_crc64table
6/oid_registry_data.c7/oid_registry_data.c
lib/Makefile+9−1
@@ -281,7 +281,15 @@ $(foreach file, $(libfdt_files), \ · 280 unmodified lines
281 $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))281 $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
282lib-$(CONFIG_LIBFDT) += $(libfdt_files)282lib-$(CONFIG_LIBFDT) += $(libfdt_files)
283 283
284lib-$(CONFIG_BOOT_CONFIG) += bootconfig.o284obj-$(CONFIG_BOOT_CONFIG) += bootconfig.o
285obj-$(CONFIG_BOOT_CONFIG_EMBED) += bootconfig-data.o
286
287$(obj)/bootconfig-data.o: $(obj)/default.bconf
288
289targets += default.bconf
290filechk_defbconf = cat $(or $(real-prereqs), /dev/null)
291$(obj)/default.bconf: $(CONFIG_BOOT_CONFIG_EMBED_FILE) FORCE
292 $(call filechk,defbconf)
285 293
286obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o294obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
287obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o295obj-$(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
7embedded_bootconfig_data:
8 .incbin "lib/default.bconf"
9 .global embedded_bootconfig_data_end
10embedded_bootconfig_data_end:
lib/bootconfig.c+13−0
@@ -12,6 +12,19 @@ · 11 unmodified lines
12#include <linux/kernel.h>12#include <linux/kernel.h>
13#include <linux/memblock.h>13#include <linux/memblock.h>
14#include <linux/string.h>14#include <linux/string.h>
15
16#ifdef CONFIG_BOOT_CONFIG_EMBED
17/* embedded_bootconfig_data is defined in bootconfig-data.S */
18extern __visible const char embedded_bootconfig_data[];
19extern __visible const char embedded_bootconfig_data_end[];
20
21const 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
15#else /* !__KERNEL__ */28#else /* !__KERNEL__ */
16/*29/*
17 * NOTE: This is only for tools/bootconfig, because tools/bootconfig will30 * NOTE: This is only for tools/bootconfig, because tools/bootconfig will