Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Pull tracing updates from Steven Rostedt:

- Added new "bootconfig".

This looks for a file appended to initrd to add boot config options,
and has been discussed thoroughly at Linux Plumbers.

Very useful for adding kprobes at bootup.

Only enabled if "bootconfig" is on the real kernel command line.

- Created dynamic event creation.

Merges common code between creating synthetic events and kprobe
events.

- Rename perf "ring_buffer" structure to "perf_buffer"

- Rename ftrace "ring_buffer" structure to "trace_buffer"

Had to rename existing "trace_buffer" to "array_buffer"

- Allow trace_printk() to work withing (some) tracing code.

- Sort of tracing configs to be a little better organized

- Fixed bug where ftrace_graph hash was not being protected properly

- Various other small fixes and clean ups

* tag 'trace-v5.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (88 commits)
bootconfig: Show the number of nodes on boot message
tools/bootconfig: Show the number of bootconfig nodes
bootconfig: Add more parse error messages
bootconfig: Use bootconfig instead of boot config
ftrace: Protect ftrace_graph_hash with ftrace_sync
ftrace: Add comment to why rcu_dereference_sched() is open coded
tracing: Annotate ftrace_graph_notrace_hash pointer with __rcu
tracing: Annotate ftrace_graph_hash pointer with __rcu
bootconfig: Only load bootconfig if "bootconfig" is on the kernel cmdline
tracing: Use seq_buf for building dynevent_cmd string
tracing: Remove useless code in dynevent_arg_pair_add()
tracing: Remove check_arg() callbacks from dynevent args
tracing: Consolidate some synth_event_trace code
tracing: Fix now invalid var_ref_vals assumption in trace action
tracing: Change trace_boot to use synth_event interface
tracing: Move tracing selftests to bottom of menu
tracing: Move mmio tracer config up with the other tracers
tracing: Move tracing test module configs together
tracing: Move all function tracing configs together
tracing: Documentation for in-kernel synthetic event API
...

+6491 -837
+190
Documentation/admin-guide/bootconfig.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + .. _bootconfig: 4 + 5 + ================== 6 + Boot Configuration 7 + ================== 8 + 9 + :Author: Masami Hiramatsu <mhiramat@kernel.org> 10 + 11 + Overview 12 + ======== 13 + 14 + The boot configuration expands the current kernel command line to support 15 + additional key-value data when booting the kernel in an efficient way. 16 + This allows administrators to pass a structured-Key config file. 17 + 18 + Config File Syntax 19 + ================== 20 + 21 + The boot config syntax is a simple structured key-value. Each key consists 22 + of dot-connected-words, and key and value are connected by ``=``. The value 23 + has to be terminated by semi-colon (``;``) or newline (``\n``). 24 + For array value, array entries are separated by comma (``,``). :: 25 + 26 + KEY[.WORD[...]] = VALUE[, VALUE2[...]][;] 27 + 28 + Unlike the kernel command line syntax, spaces are OK around the comma and ``=``. 29 + 30 + Each key word must contain only alphabets, numbers, dash (``-``) or underscore 31 + (``_``). And each value only contains printable characters or spaces except 32 + for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``), 33 + hash (``#``) and closing brace (``}``). 34 + 35 + If you want to use those delimiters in a value, you can use either double- 36 + quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that 37 + you can not escape these quotes. 38 + 39 + There can be a key which doesn't have value or has an empty value. Those keys 40 + are used for checking if the key exists or not (like a boolean). 41 + 42 + Key-Value Syntax 43 + ---------------- 44 + 45 + The boot config file syntax allows user to merge partially same word keys 46 + by brace. For example:: 47 + 48 + foo.bar.baz = value1 49 + foo.bar.qux.quux = value2 50 + 51 + These can be written also in:: 52 + 53 + foo.bar { 54 + baz = value1 55 + qux.quux = value2 56 + } 57 + 58 + Or more shorter, written as following:: 59 + 60 + foo.bar { baz = value1; qux.quux = value2 } 61 + 62 + In both styles, same key words are automatically merged when parsing it 63 + at boot time. So you can append similar trees or key-values. 64 + 65 + Comments 66 + -------- 67 + 68 + The config syntax accepts shell-script style comments. The comments starting 69 + with hash ("#") until newline ("\n") will be ignored. 70 + 71 + :: 72 + 73 + # comment line 74 + foo = value # value is set to foo. 75 + bar = 1, # 1st element 76 + 2, # 2nd element 77 + 3 # 3rd element 78 + 79 + This is parsed as below:: 80 + 81 + foo = value 82 + bar = 1, 2, 3 83 + 84 + Note that you can not put a comment between value and delimiter(``,`` or 85 + ``;``). This means following config has a syntax error :: 86 + 87 + key = 1 # comment 88 + ,2 89 + 90 + 91 + /proc/bootconfig 92 + ================ 93 + 94 + /proc/bootconfig is a user-space interface of the boot config. 95 + Unlike /proc/cmdline, this file shows the key-value style list. 96 + Each key-value pair is shown in each line with following style:: 97 + 98 + KEY[.WORDS...] = "[VALUE]"[,"VALUE2"...] 99 + 100 + 101 + Boot Kernel With a Boot Config 102 + ============================== 103 + 104 + Since the boot configuration file is loaded with initrd, it will be added 105 + to the end of the initrd (initramfs) image file. The Linux kernel decodes 106 + the last part of the initrd image in memory to get the boot configuration 107 + data. 108 + Because of this "piggyback" method, there is no need to change or 109 + update the boot loader and the kernel image itself. 110 + 111 + To do this operation, Linux kernel provides "bootconfig" command under 112 + tools/bootconfig, which allows admin to apply or delete the config file 113 + to/from initrd image. You can build it by the following command:: 114 + 115 + # make -C tools/bootconfig 116 + 117 + To add your boot config file to initrd image, run bootconfig as below 118 + (Old data is removed automatically if exists):: 119 + 120 + # tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z 121 + 122 + To remove the config from the image, you can use -d option as below:: 123 + 124 + # tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z 125 + 126 + Then add "bootconfig" on the normal kernel command line to tell the 127 + kernel to look for the bootconfig at the end of the initrd file. 128 + 129 + Config File Limitation 130 + ====================== 131 + 132 + Currently the maximum config size size is 32KB and the total key-words (not 133 + key-value entries) must be under 1024 nodes. 134 + Note: this is not the number of entries but nodes, an entry must consume 135 + more than 2 nodes (a key-word and a value). So theoretically, it will be 136 + up to 512 key-value pairs. If keys contains 3 words in average, it can 137 + contain 256 key-value pairs. In most cases, the number of config items 138 + will be under 100 entries and smaller than 8KB, so it would be enough. 139 + If the node number exceeds 1024, parser returns an error even if the file 140 + size is smaller than 32KB. 141 + Anyway, since bootconfig command verifies it when appending a boot config 142 + to initrd image, user can notice it before boot. 143 + 144 + 145 + Bootconfig APIs 146 + =============== 147 + 148 + User can query or loop on key-value pairs, also it is possible to find 149 + a root (prefix) key node and find key-values under that node. 150 + 151 + If you have a key string, you can query the value directly with the key 152 + using xbc_find_value(). If you want to know what keys exist in the boot 153 + config, you can use xbc_for_each_key_value() to iterate key-value pairs. 154 + Note that you need to use xbc_array_for_each_value() for accessing 155 + each array's value, e.g.:: 156 + 157 + vnode = NULL; 158 + xbc_find_value("key.word", &vnode); 159 + if (vnode && xbc_node_is_array(vnode)) 160 + xbc_array_for_each_value(vnode, value) { 161 + printk("%s ", value); 162 + } 163 + 164 + If you want to focus on keys which have a prefix string, you can use 165 + xbc_find_node() to find a node by the prefix string, and iterate 166 + keys under the prefix node with xbc_node_for_each_key_value(). 167 + 168 + But the most typical usage is to get the named value under prefix 169 + or get the named array under prefix as below:: 170 + 171 + root = xbc_find_node("key.prefix"); 172 + value = xbc_node_find_value(root, "option", &vnode); 173 + ... 174 + xbc_node_for_each_array_value(root, "array-option", value, anode) { 175 + ... 176 + } 177 + 178 + This accesses a value of "key.prefix.option" and an array of 179 + "key.prefix.array-option". 180 + 181 + Locking is not needed, since after initialization, the config becomes 182 + read-only. All data and keys must be copied if you need to modify it. 183 + 184 + 185 + Functions and structures 186 + ======================== 187 + 188 + .. kernel-doc:: include/linux/bootconfig.h 189 + .. kernel-doc:: lib/bootconfig.c 190 +
+1
Documentation/admin-guide/index.rst
··· 64 64 binderfs 65 65 binfmt-misc 66 66 blockdev/index 67 + bootconfig 67 68 braille-console 68 69 btmrvl 69 70 cgroup-v1/index
+6
Documentation/admin-guide/kernel-parameters.txt
··· 437 437 no delay (0). 438 438 Format: integer 439 439 440 + bootconfig [KNL] 441 + Extended command line options can be added to an initrd 442 + and this will cause the kernel to look for it. 443 + 444 + See Documentation/admin-guide/bootconfig.rst 445 + 440 446 bert_disable [ACPI] 441 447 Disable BERT OS support on buggy BIOSes. 442 448
+184
Documentation/trace/boottime-trace.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ================= 4 + Boot-time tracing 5 + ================= 6 + 7 + :Author: Masami Hiramatsu <mhiramat@kernel.org> 8 + 9 + Overview 10 + ======== 11 + 12 + Boot-time tracing allows users to trace boot-time process including 13 + device initialization with full features of ftrace including per-event 14 + filter and actions, histograms, kprobe-events and synthetic-events, 15 + and trace instances. 16 + Since kernel command line is not enough to control these complex features, 17 + this uses bootconfig file to describe tracing feature programming. 18 + 19 + Options in the Boot Config 20 + ========================== 21 + 22 + Here is the list of available options list for boot time tracing in 23 + boot config file [1]_. All options are under "ftrace." or "kernel." 24 + prefix. See kernel parameters for the options which starts 25 + with "kernel." prefix [2]_. 26 + 27 + .. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>` 28 + .. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>` 29 + 30 + Ftrace Global Options 31 + --------------------- 32 + 33 + Ftrace global options have "kernel." prefix in boot config, which means 34 + these options are passed as a part of kernel legacy command line. 35 + 36 + kernel.tp_printk 37 + Output trace-event data on printk buffer too. 38 + 39 + kernel.dump_on_oops [= MODE] 40 + Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer 41 + on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops. 42 + 43 + kernel.traceoff_on_warning 44 + Stop tracing if WARN_ON() occurs. 45 + 46 + kernel.fgraph_max_depth = MAX_DEPTH 47 + Set MAX_DEPTH to maximum depth of fgraph tracer. 48 + 49 + kernel.fgraph_filters = FILTER[, FILTER2...] 50 + Add fgraph tracing function filters. 51 + 52 + kernel.fgraph_notraces = FILTER[, FILTER2...] 53 + Add fgraph non-tracing function filters. 54 + 55 + 56 + Ftrace Per-instance Options 57 + --------------------------- 58 + 59 + These options can be used for each instance including global ftrace node. 60 + 61 + ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]] 62 + Enable given ftrace options. 63 + 64 + ftrace.[instance.INSTANCE.]trace_clock = CLOCK 65 + Set given CLOCK to ftrace's trace_clock. 66 + 67 + ftrace.[instance.INSTANCE.]buffer_size = SIZE 68 + Configure ftrace buffer size to SIZE. You can use "KB" or "MB" 69 + for that SIZE. 70 + 71 + ftrace.[instance.INSTANCE.]alloc_snapshot 72 + Allocate snapshot buffer. 73 + 74 + ftrace.[instance.INSTANCE.]cpumask = CPUMASK 75 + Set CPUMASK as trace cpu-mask. 76 + 77 + ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]] 78 + Enable given events on boot. You can use a wild card in EVENT. 79 + 80 + ftrace.[instance.INSTANCE.]tracer = TRACER 81 + Set TRACER to current tracer on boot. (e.g. function) 82 + 83 + ftrace.[instance.INSTANCE.]ftrace.filters 84 + This will take an array of tracing function filter rules. 85 + 86 + ftrace.[instance.INSTANCE.]ftrace.notraces 87 + This will take an array of NON-tracing function filter rules. 88 + 89 + 90 + Ftrace Per-Event Options 91 + ------------------------ 92 + 93 + These options are setting per-event options. 94 + 95 + ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable 96 + Enable GROUP:EVENT tracing. 97 + 98 + ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER 99 + Set FILTER rule to the GROUP:EVENT. 100 + 101 + ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]] 102 + Set ACTIONs to the GROUP:EVENT. 103 + 104 + ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]] 105 + Defines new kprobe event based on PROBEs. It is able to define 106 + multiple probes on one event, but those must have same type of 107 + arguments. This option is available only for the event which 108 + group name is "kprobes". 109 + 110 + ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]] 111 + Defines new synthetic event with FIELDs. Each field should be 112 + "type varname". 113 + 114 + Note that kprobe and synthetic event definitions can be written under 115 + instance node, but those are also visible from other instances. So please 116 + take care for event name conflict. 117 + 118 + 119 + Examples 120 + ======== 121 + 122 + For example, to add filter and actions for each event, define kprobe 123 + events, and synthetic events with histogram, write a boot config like 124 + below:: 125 + 126 + ftrace.event { 127 + task.task_newtask { 128 + filter = "pid < 128" 129 + enable 130 + } 131 + kprobes.vfs_read { 132 + probes = "vfs_read $arg1 $arg2" 133 + filter = "common_pid < 200" 134 + enable 135 + } 136 + synthetic.initcall_latency { 137 + fields = "unsigned long func", "u64 lat" 138 + actions = "hist:keys=func.sym,lat:vals=lat:sort=lat" 139 + } 140 + initcall.initcall_start { 141 + actions = "hist:keys=func:ts0=common_timestamp.usecs" 142 + } 143 + initcall.initcall_finish { 144 + actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)" 145 + } 146 + } 147 + 148 + Also, boot-time tracing supports "instance" node, which allows us to run 149 + several tracers for different purpose at once. For example, one tracer 150 + is for tracing functions starting with "user\_", and others tracing 151 + "kernel\_" functions, you can write boot config as below:: 152 + 153 + ftrace.instance { 154 + foo { 155 + tracer = "function" 156 + ftrace.filters = "user_*" 157 + } 158 + bar { 159 + tracer = "function" 160 + ftrace.filters = "kernel_*" 161 + } 162 + } 163 + 164 + The instance node also accepts event nodes so that each instance 165 + can customize its event tracing. 166 + 167 + This boot-time tracing also supports ftrace kernel parameters via boot 168 + config. 169 + For example, following kernel parameters:: 170 + 171 + trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*" 172 + 173 + This can be written in boot config like below:: 174 + 175 + kernel { 176 + trace_options = sym-addr 177 + trace_event = "initcall:*" 178 + tp_printk 179 + trace_buf_size = 1M 180 + ftrace = function 181 + ftrace_filter = "vfs*" 182 + } 183 + 184 + Note that parameters start with "kernel" prefix instead of "ftrace".
+515
Documentation/trace/events.rst
··· 525 525 event counts (hitcount). 526 526 527 527 See Documentation/trace/histogram.rst for details and examples. 528 + 529 + 6.3 In-kernel trace event API 530 + ----------------------------- 531 + 532 + In most cases, the command-line interface to trace events is more than 533 + sufficient. Sometimes, however, applications might find the need for 534 + more complex relationships than can be expressed through a simple 535 + series of linked command-line expressions, or putting together sets of 536 + commands may be simply too cumbersome. An example might be an 537 + application that needs to 'listen' to the trace stream in order to 538 + maintain an in-kernel state machine detecting, for instance, when an 539 + illegal kernel state occurs in the scheduler. 540 + 541 + The trace event subsystem provides an in-kernel API allowing modules 542 + or other kernel code to generate user-defined 'synthetic' events at 543 + will, which can be used to either augment the existing trace stream 544 + and/or signal that a particular important state has occurred. 545 + 546 + A similar in-kernel API is also available for creating kprobe and 547 + kretprobe events. 548 + 549 + Both the synthetic event and k/ret/probe event APIs are built on top 550 + of a lower-level "dynevent_cmd" event command API, which is also 551 + available for more specialized applications, or as the basis of other 552 + higher-level trace event APIs. 553 + 554 + The API provided for these purposes is describe below and allows the 555 + following: 556 + 557 + - dynamically creating synthetic event definitions 558 + - dynamically creating kprobe and kretprobe event definitions 559 + - tracing synthetic events from in-kernel code 560 + - the low-level "dynevent_cmd" API 561 + 562 + 6.3.1 Dyamically creating synthetic event definitions 563 + ----------------------------------------------------- 564 + 565 + There are a couple ways to create a new synthetic event from a kernel 566 + module or other kernel code. 567 + 568 + The first creates the event in one step, using synth_event_create(). 569 + In this method, the name of the event to create and an array defining 570 + the fields is supplied to synth_event_create(). If successful, a 571 + synthetic event with that name and fields will exist following that 572 + call. For example, to create a new "schedtest" synthetic event: 573 + 574 + ret = synth_event_create("schedtest", sched_fields, 575 + ARRAY_SIZE(sched_fields), THIS_MODULE); 576 + 577 + The sched_fields param in this example points to an array of struct 578 + synth_field_desc, each of which describes an event field by type and 579 + name: 580 + 581 + static struct synth_field_desc sched_fields[] = { 582 + { .type = "pid_t", .name = "next_pid_field" }, 583 + { .type = "char[16]", .name = "next_comm_field" }, 584 + { .type = "u64", .name = "ts_ns" }, 585 + { .type = "u64", .name = "ts_ms" }, 586 + { .type = "unsigned int", .name = "cpu" }, 587 + { .type = "char[64]", .name = "my_string_field" }, 588 + { .type = "int", .name = "my_int_field" }, 589 + }; 590 + 591 + See synth_field_size() for available types. If field_name contains [n] 592 + the field is considered to be an array. 593 + 594 + If the event is created from within a module, a pointer to the module 595 + must be passed to synth_event_create(). This will ensure that the 596 + trace buffer won't contain unreadable events when the module is 597 + removed. 598 + 599 + At this point, the event object is ready to be used for generating new 600 + events. 601 + 602 + In the second method, the event is created in several steps. This 603 + allows events to be created dynamically and without the need to create 604 + and populate an array of fields beforehand. 605 + 606 + To use this method, an empty or partially empty synthetic event should 607 + first be created using synth_event_gen_cmd_start() or 608 + synth_event_gen_cmd_array_start(). For synth_event_gen_cmd_start(), 609 + the name of the event along with one or more pairs of args each pair 610 + representing a 'type field_name;' field specification should be 611 + supplied. For synth_event_gen_cmd_array_start(), the name of the 612 + event along with an array of struct synth_field_desc should be 613 + supplied. Before calling synth_event_gen_cmd_start() or 614 + synth_event_gen_cmd_array_start(), the user should create and 615 + initialize a dynevent_cmd object using synth_event_cmd_init(). 616 + 617 + For example, to create a new "schedtest" synthetic event with two 618 + fields: 619 + 620 + struct dynevent_cmd cmd; 621 + char *buf; 622 + 623 + /* Create a buffer to hold the generated command */ 624 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 625 + 626 + /* Before generating the command, initialize the cmd object */ 627 + synth_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 628 + 629 + ret = synth_event_gen_cmd_start(&cmd, "schedtest", THIS_MODULE, 630 + "pid_t", "next_pid_field", 631 + "u64", "ts_ns"); 632 + 633 + Alternatively, using an array of struct synth_field_desc fields 634 + containing the same information: 635 + 636 + ret = synth_event_gen_cmd_array_start(&cmd, "schedtest", THIS_MODULE, 637 + fields, n_fields); 638 + 639 + Once the synthetic event object has been created, it can then be 640 + populated with more fields. Fields are added one by one using 641 + synth_event_add_field(), supplying the dynevent_cmd object, a field 642 + type, and a field name. For example, to add a new int field named 643 + "intfield", the following call should be made: 644 + 645 + ret = synth_event_add_field(&cmd, "int", "intfield"); 646 + 647 + See synth_field_size() for available types. If field_name contains [n] 648 + the field is considered to be an array. 649 + 650 + A group of fields can also be added all at once using an array of 651 + synth_field_desc with add_synth_fields(). For example, this would add 652 + just the first four sched_fields: 653 + 654 + ret = synth_event_add_fields(&cmd, sched_fields, 4); 655 + 656 + If you already have a string of the form 'type field_name', 657 + synth_event_add_field_str() can be used to add it as-is; it will 658 + also automatically append a ';' to the string. 659 + 660 + Once all the fields have been added, the event should be finalized and 661 + registered by calling the synth_event_gen_cmd_end() function: 662 + 663 + ret = synth_event_gen_cmd_end(&cmd); 664 + 665 + At this point, the event object is ready to be used for tracing new 666 + events. 667 + 668 + 6.3.3 Tracing synthetic events from in-kernel code 669 + -------------------------------------------------- 670 + 671 + To trace a synthetic event, there are several options. The first 672 + option is to trace the event in one call, using synth_event_trace() 673 + with a variable number of values, or synth_event_trace_array() with an 674 + array of values to be set. A second option can be used to avoid the 675 + need for a pre-formed array of values or list of arguments, via 676 + synth_event_trace_start() and synth_event_trace_end() along with 677 + synth_event_add_next_val() or synth_event_add_val() to add the values 678 + piecewise. 679 + 680 + 6.3.3.1 Tracing a synthetic event all at once 681 + --------------------------------------------- 682 + 683 + To trace a synthetic event all at once, the synth_event_trace() or 684 + synth_event_trace_array() functions can be used. 685 + 686 + The synth_event_trace() function is passed the trace_event_file 687 + representing the synthetic event (which can be retrieved using 688 + trace_get_event_file() using the synthetic event name, "synthetic" as 689 + the system name, and the trace instance name (NULL if using the global 690 + trace array)), along with an variable number of u64 args, one for each 691 + synthetic event field, and the number of values being passed. 692 + 693 + So, to trace an event corresponding to the synthetic event definition 694 + above, code like the following could be used: 695 + 696 + ret = synth_event_trace(create_synth_test, 7, /* number of values */ 697 + 444, /* next_pid_field */ 698 + (u64)"clackers", /* next_comm_field */ 699 + 1000000, /* ts_ns */ 700 + 1000, /* ts_ms */ 701 + smp_processor_id(),/* cpu */ 702 + (u64)"Thneed", /* my_string_field */ 703 + 999); /* my_int_field */ 704 + 705 + All vals should be cast to u64, and string vals are just pointers to 706 + strings, cast to u64. Strings will be copied into space reserved in 707 + the event for the string, using these pointers. 708 + 709 + Alternatively, the synth_event_trace_array() function can be used to 710 + accomplish the same thing. It is passed the trace_event_file 711 + representing the synthetic event (which can be retrieved using 712 + trace_get_event_file() using the synthetic event name, "synthetic" as 713 + the system name, and the trace instance name (NULL if using the global 714 + trace array)), along with an array of u64, one for each synthetic 715 + event field. 716 + 717 + To trace an event corresponding to the synthetic event definition 718 + above, code like the following could be used: 719 + 720 + u64 vals[7]; 721 + 722 + vals[0] = 777; /* next_pid_field */ 723 + vals[1] = (u64)"tiddlywinks"; /* next_comm_field */ 724 + vals[2] = 1000000; /* ts_ns */ 725 + vals[3] = 1000; /* ts_ms */ 726 + vals[4] = smp_processor_id(); /* cpu */ 727 + vals[5] = (u64)"thneed"; /* my_string_field */ 728 + vals[6] = 398; /* my_int_field */ 729 + 730 + The 'vals' array is just an array of u64, the number of which must 731 + match the number of field in the synthetic event, and which must be in 732 + the same order as the synthetic event fields. 733 + 734 + All vals should be cast to u64, and string vals are just pointers to 735 + strings, cast to u64. Strings will be copied into space reserved in 736 + the event for the string, using these pointers. 737 + 738 + In order to trace a synthetic event, a pointer to the trace event file 739 + is needed. The trace_get_event_file() function can be used to get 740 + it - it will find the file in the given trace instance (in this case 741 + NULL since the top trace array is being used) while at the same time 742 + preventing the instance containing it from going away: 743 + 744 + schedtest_event_file = trace_get_event_file(NULL, "synthetic", 745 + "schedtest"); 746 + 747 + Before tracing the event, it should be enabled in some way, otherwise 748 + the synthetic event won't actually show up in the trace buffer. 749 + 750 + To enable a synthetic event from the kernel, trace_array_set_clr_event() 751 + can be used (which is not specific to synthetic events, so does need 752 + the "synthetic" system name to be specified explicitly). 753 + 754 + To enable the event, pass 'true' to it: 755 + 756 + trace_array_set_clr_event(schedtest_event_file->tr, 757 + "synthetic", "schedtest", true); 758 + 759 + To disable it pass false: 760 + 761 + trace_array_set_clr_event(schedtest_event_file->tr, 762 + "synthetic", "schedtest", false); 763 + 764 + Finally, synth_event_trace_array() can be used to actually trace the 765 + event, which should be visible in the trace buffer afterwards: 766 + 767 + ret = synth_event_trace_array(schedtest_event_file, vals, 768 + ARRAY_SIZE(vals)); 769 + 770 + To remove the synthetic event, the event should be disabled, and the 771 + trace instance should be 'put' back using trace_put_event_file(): 772 + 773 + trace_array_set_clr_event(schedtest_event_file->tr, 774 + "synthetic", "schedtest", false); 775 + trace_put_event_file(schedtest_event_file); 776 + 777 + If those have been successful, synth_event_delete() can be called to 778 + remove the event: 779 + 780 + ret = synth_event_delete("schedtest"); 781 + 782 + 6.3.3.1 Tracing a synthetic event piecewise 783 + ------------------------------------------- 784 + 785 + To trace a synthetic using the piecewise method described above, the 786 + synth_event_trace_start() function is used to 'open' the synthetic 787 + event trace: 788 + 789 + struct synth_trace_state trace_state; 790 + 791 + ret = synth_event_trace_start(schedtest_event_file, &trace_state); 792 + 793 + It's passed the trace_event_file representing the synthetic event 794 + using the same methods as described above, along with a pointer to a 795 + struct synth_trace_state object, which will be zeroed before use and 796 + used to maintain state between this and following calls. 797 + 798 + Once the event has been opened, which means space for it has been 799 + reserved in the trace buffer, the individual fields can be set. There 800 + are two ways to do that, either one after another for each field in 801 + the event, which requires no lookups, or by name, which does. The 802 + tradeoff is flexibility in doing the assignments vs the cost of a 803 + lookup per field. 804 + 805 + To assign the values one after the other without lookups, 806 + synth_event_add_next_val() should be used. Each call is passed the 807 + same synth_trace_state object used in the synth_event_trace_start(), 808 + along with the value to set the next field in the event. After each 809 + field is set, the 'cursor' points to the next field, which will be set 810 + by the subsequent call, continuing until all the fields have been set 811 + in order. The same sequence of calls as in the above examples using 812 + this method would be (without error-handling code): 813 + 814 + /* next_pid_field */ 815 + ret = synth_event_add_next_val(777, &trace_state); 816 + 817 + /* next_comm_field */ 818 + ret = synth_event_add_next_val((u64)"slinky", &trace_state); 819 + 820 + /* ts_ns */ 821 + ret = synth_event_add_next_val(1000000, &trace_state); 822 + 823 + /* ts_ms */ 824 + ret = synth_event_add_next_val(1000, &trace_state); 825 + 826 + /* cpu */ 827 + ret = synth_event_add_next_val(smp_processor_id(), &trace_state); 828 + 829 + /* my_string_field */ 830 + ret = synth_event_add_next_val((u64)"thneed_2.01", &trace_state); 831 + 832 + /* my_int_field */ 833 + ret = synth_event_add_next_val(395, &trace_state); 834 + 835 + To assign the values in any order, synth_event_add_val() should be 836 + used. Each call is passed the same synth_trace_state object used in 837 + the synth_event_trace_start(), along with the field name of the field 838 + to set and the value to set it to. The same sequence of calls as in 839 + the above examples using this method would be (without error-handling 840 + code): 841 + 842 + ret = synth_event_add_val("next_pid_field", 777, &trace_state); 843 + ret = synth_event_add_val("next_comm_field", (u64)"silly putty", 844 + &trace_state); 845 + ret = synth_event_add_val("ts_ns", 1000000, &trace_state); 846 + ret = synth_event_add_val("ts_ms", 1000, &trace_state); 847 + ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state); 848 + ret = synth_event_add_val("my_string_field", (u64)"thneed_9", 849 + &trace_state); 850 + ret = synth_event_add_val("my_int_field", 3999, &trace_state); 851 + 852 + Note that synth_event_add_next_val() and synth_event_add_val() are 853 + incompatible if used within the same trace of an event - either one 854 + can be used but not both at the same time. 855 + 856 + Finally, the event won't be actually traced until it's 'closed', 857 + which is done using synth_event_trace_end(), which takes only the 858 + struct synth_trace_state object used in the previous calls: 859 + 860 + ret = synth_event_trace_end(&trace_state); 861 + 862 + Note that synth_event_trace_end() must be called at the end regardless 863 + of whether any of the add calls failed (say due to a bad field name 864 + being passed in). 865 + 866 + 6.3.4 Dyamically creating kprobe and kretprobe event definitions 867 + ---------------------------------------------------------------- 868 + 869 + To create a kprobe or kretprobe trace event from kernel code, the 870 + kprobe_event_gen_cmd_start() or kretprobe_event_gen_cmd_start() 871 + functions can be used. 872 + 873 + To create a kprobe event, an empty or partially empty kprobe event 874 + should first be created using kprobe_event_gen_cmd_start(). The name 875 + of the event and the probe location should be specfied along with one 876 + or args each representing a probe field should be supplied to this 877 + function. Before calling kprobe_event_gen_cmd_start(), the user 878 + should create and initialize a dynevent_cmd object using 879 + kprobe_event_cmd_init(). 880 + 881 + For example, to create a new "schedtest" kprobe event with two fields: 882 + 883 + struct dynevent_cmd cmd; 884 + char *buf; 885 + 886 + /* Create a buffer to hold the generated command */ 887 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 888 + 889 + /* Before generating the command, initialize the cmd object */ 890 + kprobe_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 891 + 892 + /* 893 + * Define the gen_kprobe_test event with the first 2 kprobe 894 + * fields. 895 + */ 896 + ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test", "do_sys_open", 897 + "dfd=%ax", "filename=%dx"); 898 + 899 + Once the kprobe event object has been created, it can then be 900 + populated with more fields. Fields can be added using 901 + kprobe_event_add_fields(), supplying the dynevent_cmd object along 902 + with a variable arg list of probe fields. For example, to add a 903 + couple additional fields, the following call could be made: 904 + 905 + ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)"); 906 + 907 + Once all the fields have been added, the event should be finalized and 908 + registered by calling the kprobe_event_gen_cmd_end() or 909 + kretprobe_event_gen_cmd_end() functions, depending on whether a kprobe 910 + or kretprobe command was started: 911 + 912 + ret = kprobe_event_gen_cmd_end(&cmd); 913 + 914 + or 915 + 916 + ret = kretprobe_event_gen_cmd_end(&cmd); 917 + 918 + At this point, the event object is ready to be used for tracing new 919 + events. 920 + 921 + Similarly, a kretprobe event can be created using 922 + kretprobe_event_gen_cmd_start() with a probe name and location and 923 + additional params such as $retval: 924 + 925 + ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test", 926 + "do_sys_open", "$retval"); 927 + 928 + Similar to the synthetic event case, code like the following can be 929 + used to enable the newly created kprobe event: 930 + 931 + gen_kprobe_test = trace_get_event_file(NULL, "kprobes", "gen_kprobe_test"); 932 + 933 + ret = trace_array_set_clr_event(gen_kprobe_test->tr, 934 + "kprobes", "gen_kprobe_test", true); 935 + 936 + Finally, also similar to synthetic events, the following code can be 937 + used to give the kprobe event file back and delete the event: 938 + 939 + trace_put_event_file(gen_kprobe_test); 940 + 941 + ret = kprobe_event_delete("gen_kprobe_test"); 942 + 943 + 6.3.4 The "dynevent_cmd" low-level API 944 + -------------------------------------- 945 + 946 + Both the in-kernel synthetic event and kprobe interfaces are built on 947 + top of a lower-level "dynevent_cmd" interface. This interface is 948 + meant to provide the basis for higher-level interfaces such as the 949 + synthetic and kprobe interfaces, which can be used as examples. 950 + 951 + The basic idea is simple and amounts to providing a general-purpose 952 + layer that can be used to generate trace event commands. The 953 + generated command strings can then be passed to the command-parsing 954 + and event creation code that already exists in the trace event 955 + subystem for creating the corresponding trace events. 956 + 957 + In a nutshell, the way it works is that the higher-level interface 958 + code creates a struct dynevent_cmd object, then uses a couple 959 + functions, dynevent_arg_add() and dynevent_arg_pair_add() to build up 960 + a command string, which finally causes the command to be executed 961 + using the dynevent_create() function. The details of the interface 962 + are described below. 963 + 964 + The first step in building a new command string is to create and 965 + initialize an instance of a dynevent_cmd. Here, for instance, we 966 + create a dynevent_cmd on the stack and initialize it: 967 + 968 + struct dynevent_cmd cmd; 969 + char *buf; 970 + int ret; 971 + 972 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 973 + 974 + dynevent_cmd_init(cmd, buf, maxlen, DYNEVENT_TYPE_FOO, 975 + foo_event_run_command); 976 + 977 + The dynevent_cmd initialization needs to be given a user-specified 978 + buffer and the length of the buffer (MAX_DYNEVENT_CMD_LEN can be used 979 + for this purpose - at 2k it's generally too big to be comfortably put 980 + on the stack, so is dynamically allocated), a dynevent type id, which 981 + is meant to be used to check that further API calls are for the 982 + correct command type, and a pointer to an event-specific run_command() 983 + callback that will be called to actually execute the event-specific 984 + command function. 985 + 986 + Once that's done, the command string can by built up by successive 987 + calls to argument-adding functions. 988 + 989 + To add a single argument, define and initialize a struct dynevent_arg 990 + or struct dynevent_arg_pair object. Here's an example of the simplest 991 + possible arg addition, which is simply to append the given string as 992 + a whitespace-separated argument to the command: 993 + 994 + struct dynevent_arg arg; 995 + 996 + dynevent_arg_init(&arg, NULL, 0); 997 + 998 + arg.str = name; 999 + 1000 + ret = dynevent_arg_add(cmd, &arg); 1001 + 1002 + The arg object is first initialized using dynevent_arg_init() and in 1003 + this case the parameters are NULL or 0, which means there's no 1004 + optional sanity-checking function or separator appended to the end of 1005 + the arg. 1006 + 1007 + Here's another more complicated example using an 'arg pair', which is 1008 + used to create an argument that consists of a couple components added 1009 + together as a unit, for example, a 'type field_name;' arg or a simple 1010 + expression arg e.g. 'flags=%cx': 1011 + 1012 + struct dynevent_arg_pair arg_pair; 1013 + 1014 + dynevent_arg_pair_init(&arg_pair, dynevent_foo_check_arg_fn, 0, ';'); 1015 + 1016 + arg_pair.lhs = type; 1017 + arg_pair.rhs = name; 1018 + 1019 + ret = dynevent_arg_pair_add(cmd, &arg_pair); 1020 + 1021 + Again, the arg_pair is first initialized, in this case with a callback 1022 + function used to check the sanity of the args (for example, that 1023 + neither part of the pair is NULL), along with a character to be used 1024 + to add an operator between the pair (here none) and a separator to be 1025 + appended onto the end of the arg pair (here ';'). 1026 + 1027 + There's also a dynevent_str_add() function that can be used to simply 1028 + add a string as-is, with no spaces, delimeters, or arg check. 1029 + 1030 + Any number of dynevent_*_add() calls can be made to build up the string 1031 + (until its length surpasses cmd->maxlen). When all the arguments have 1032 + been added and the command string is complete, the only thing left to 1033 + do is run the command, which happens by simply calling 1034 + dynevent_create(): 1035 + 1036 + ret = dynevent_create(&cmd); 1037 + 1038 + At that point, if the return value is 0, the dynamic event has been 1039 + created and is ready to use. 1040 + 1041 + See the dynevent_cmd function definitions themselves for the details 1042 + of the API.
+1
Documentation/trace/index.rst
··· 19 19 events-msr 20 20 mmiotrace 21 21 histogram 22 + boottime-trace 22 23 hwlat_detector 23 24 intel_th 24 25 stm
+1
Documentation/trace/kprobetrace.rst
··· 97 97 For $comm, the default type is "string"; any other type is invalid. 98 98 99 99 .. _user_mem_access: 100 + 100 101 User Memory Access 101 102 ------------------ 102 103 Kprobe events supports user-space memory access. For that purpose, you can use
+9
MAINTAINERS
··· 15934 15934 F: Documentation/networking/device_drivers/stmicro/ 15935 15935 F: drivers/net/ethernet/stmicro/stmmac/ 15936 15936 15937 + EXTRA BOOT CONFIG 15938 + M: Masami Hiramatsu <mhiramat@kernel.org> 15939 + S: Maintained 15940 + F: lib/bootconfig.c 15941 + F: fs/proc/bootconfig.c 15942 + F: include/linux/bootconfig.h 15943 + F: tools/bootconfig/* 15944 + F: Documentation/admin-guide/bootconfig.rst 15945 + 15937 15946 SUN3/3X 15938 15947 M: Sam Creasey <sammy@sammy.net> 15939 15948 W: http://sammy.net/sun3/
+1 -1
drivers/oprofile/cpu_buffer.c
··· 32 32 33 33 #define OP_BUFFER_FLAGS 0 34 34 35 - static struct ring_buffer *op_ring_buffer; 35 + static struct trace_buffer *op_ring_buffer; 36 36 DEFINE_PER_CPU(struct oprofile_cpu_buffer, op_cpu_buffer); 37 37 38 38 static void wq_sync_buffer(struct work_struct *work);
+1
fs/proc/Makefile
··· 33 33 proc-$(CONFIG_PROC_VMCORE) += vmcore.o 34 34 proc-$(CONFIG_PRINTK) += kmsg.o 35 35 proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o 36 + proc-$(CONFIG_BOOT_CONFIG) += bootconfig.o
+89
fs/proc/bootconfig.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * /proc/bootconfig - Extra boot configuration 4 + */ 5 + #include <linux/fs.h> 6 + #include <linux/init.h> 7 + #include <linux/printk.h> 8 + #include <linux/proc_fs.h> 9 + #include <linux/seq_file.h> 10 + #include <linux/bootconfig.h> 11 + #include <linux/slab.h> 12 + 13 + static char *saved_boot_config; 14 + 15 + static int boot_config_proc_show(struct seq_file *m, void *v) 16 + { 17 + if (saved_boot_config) 18 + seq_puts(m, saved_boot_config); 19 + return 0; 20 + } 21 + 22 + /* Rest size of buffer */ 23 + #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) 24 + 25 + /* Return the needed total length if @size is 0 */ 26 + static int __init copy_xbc_key_value_list(char *dst, size_t size) 27 + { 28 + struct xbc_node *leaf, *vnode; 29 + const char *val; 30 + char *key, *end = dst + size; 31 + int ret = 0; 32 + 33 + key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); 34 + 35 + xbc_for_each_key_value(leaf, val) { 36 + ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX); 37 + if (ret < 0) 38 + break; 39 + ret = snprintf(dst, rest(dst, end), "%s = ", key); 40 + if (ret < 0) 41 + break; 42 + dst += ret; 43 + vnode = xbc_node_get_child(leaf); 44 + if (vnode && xbc_node_is_array(vnode)) { 45 + xbc_array_for_each_value(vnode, val) { 46 + ret = snprintf(dst, rest(dst, end), "\"%s\"%s", 47 + val, vnode->next ? ", " : "\n"); 48 + if (ret < 0) 49 + goto out; 50 + dst += ret; 51 + } 52 + } else { 53 + ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val); 54 + if (ret < 0) 55 + break; 56 + dst += ret; 57 + } 58 + } 59 + out: 60 + kfree(key); 61 + 62 + return ret < 0 ? ret : dst - (end - size); 63 + } 64 + 65 + static int __init proc_boot_config_init(void) 66 + { 67 + int len; 68 + 69 + len = copy_xbc_key_value_list(NULL, 0); 70 + if (len < 0) 71 + return len; 72 + 73 + if (len > 0) { 74 + saved_boot_config = kzalloc(len + 1, GFP_KERNEL); 75 + if (!saved_boot_config) 76 + return -ENOMEM; 77 + 78 + len = copy_xbc_key_value_list(saved_boot_config, len + 1); 79 + if (len < 0) { 80 + kfree(saved_boot_config); 81 + return len; 82 + } 83 + } 84 + 85 + proc_create_single("bootconfig", 0, NULL, boot_config_proc_show); 86 + 87 + return 0; 88 + } 89 + fs_initcall(proc_boot_config_init);
+224
include/linux/bootconfig.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_XBC_H 3 + #define _LINUX_XBC_H 4 + /* 5 + * Extra Boot Config 6 + * Copyright (C) 2019 Linaro Ltd. 7 + * Author: Masami Hiramatsu <mhiramat@kernel.org> 8 + */ 9 + 10 + #include <linux/kernel.h> 11 + #include <linux/types.h> 12 + 13 + /* XBC tree node */ 14 + struct xbc_node { 15 + u16 next; 16 + u16 child; 17 + u16 parent; 18 + u16 data; 19 + } __attribute__ ((__packed__)); 20 + 21 + #define XBC_KEY 0 22 + #define XBC_VALUE (1 << 15) 23 + /* Maximum size of boot config is 32KB - 1 */ 24 + #define XBC_DATA_MAX (XBC_VALUE - 1) 25 + 26 + #define XBC_NODE_MAX 1024 27 + #define XBC_KEYLEN_MAX 256 28 + #define XBC_DEPTH_MAX 16 29 + 30 + /* Node tree access raw APIs */ 31 + struct xbc_node * __init xbc_root_node(void); 32 + int __init xbc_node_index(struct xbc_node *node); 33 + struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node); 34 + struct xbc_node * __init xbc_node_get_child(struct xbc_node *node); 35 + struct xbc_node * __init xbc_node_get_next(struct xbc_node *node); 36 + const char * __init xbc_node_get_data(struct xbc_node *node); 37 + 38 + /** 39 + * xbc_node_is_value() - Test the node is a value node 40 + * @node: An XBC node. 41 + * 42 + * Test the @node is a value node and return true if a value node, false if not. 43 + */ 44 + static inline __init bool xbc_node_is_value(struct xbc_node *node) 45 + { 46 + return node->data & XBC_VALUE; 47 + } 48 + 49 + /** 50 + * xbc_node_is_key() - Test the node is a key node 51 + * @node: An XBC node. 52 + * 53 + * Test the @node is a key node and return true if a key node, false if not. 54 + */ 55 + static inline __init bool xbc_node_is_key(struct xbc_node *node) 56 + { 57 + return !xbc_node_is_value(node); 58 + } 59 + 60 + /** 61 + * xbc_node_is_array() - Test the node is an arraied value node 62 + * @node: An XBC node. 63 + * 64 + * Test the @node is an arraied value node. 65 + */ 66 + static inline __init bool xbc_node_is_array(struct xbc_node *node) 67 + { 68 + return xbc_node_is_value(node) && node->next != 0; 69 + } 70 + 71 + /** 72 + * xbc_node_is_leaf() - Test the node is a leaf key node 73 + * @node: An XBC node. 74 + * 75 + * Test the @node is a leaf key node which is a key node and has a value node 76 + * or no child. Returns true if it is a leaf node, or false if not. 77 + */ 78 + static inline __init bool xbc_node_is_leaf(struct xbc_node *node) 79 + { 80 + return xbc_node_is_key(node) && 81 + (!node->child || xbc_node_is_value(xbc_node_get_child(node))); 82 + } 83 + 84 + /* Tree-based key-value access APIs */ 85 + struct xbc_node * __init xbc_node_find_child(struct xbc_node *parent, 86 + const char *key); 87 + 88 + const char * __init xbc_node_find_value(struct xbc_node *parent, 89 + const char *key, 90 + struct xbc_node **vnode); 91 + 92 + struct xbc_node * __init xbc_node_find_next_leaf(struct xbc_node *root, 93 + struct xbc_node *leaf); 94 + 95 + const char * __init xbc_node_find_next_key_value(struct xbc_node *root, 96 + struct xbc_node **leaf); 97 + 98 + /** 99 + * xbc_find_value() - Find a value which matches the key 100 + * @key: Search key 101 + * @vnode: A container pointer of XBC value node. 102 + * 103 + * Search a value whose key matches @key from whole of XBC tree and return 104 + * the value if found. Found value node is stored in *@vnode. 105 + * Note that this can return 0-length string and store NULL in *@vnode for 106 + * key-only (non-value) entry. 107 + */ 108 + static inline const char * __init 109 + xbc_find_value(const char *key, struct xbc_node **vnode) 110 + { 111 + return xbc_node_find_value(NULL, key, vnode); 112 + } 113 + 114 + /** 115 + * xbc_find_node() - Find a node which matches the key 116 + * @key: Search key 117 + * 118 + * Search a (key) node whose key matches @key from whole of XBC tree and 119 + * return the node if found. If not found, returns NULL. 120 + */ 121 + static inline struct xbc_node * __init xbc_find_node(const char *key) 122 + { 123 + return xbc_node_find_child(NULL, key); 124 + } 125 + 126 + /** 127 + * xbc_array_for_each_value() - Iterate value nodes on an array 128 + * @anode: An XBC arraied value node 129 + * @value: A value 130 + * 131 + * Iterate array value nodes and values starts from @anode. This is expected to 132 + * be used with xbc_find_value() and xbc_node_find_value(), so that user can 133 + * process each array entry node. 134 + */ 135 + #define xbc_array_for_each_value(anode, value) \ 136 + for (value = xbc_node_get_data(anode); anode != NULL ; \ 137 + anode = xbc_node_get_next(anode), \ 138 + value = anode ? xbc_node_get_data(anode) : NULL) 139 + 140 + /** 141 + * xbc_node_for_each_child() - Iterate child nodes 142 + * @parent: An XBC node. 143 + * @child: Iterated XBC node. 144 + * 145 + * Iterate child nodes of @parent. Each child nodes are stored to @child. 146 + */ 147 + #define xbc_node_for_each_child(parent, child) \ 148 + for (child = xbc_node_get_child(parent); child != NULL ; \ 149 + child = xbc_node_get_next(child)) 150 + 151 + /** 152 + * xbc_node_for_each_array_value() - Iterate array entries of geven key 153 + * @node: An XBC node. 154 + * @key: A key string searched under @node 155 + * @anode: Iterated XBC node of array entry. 156 + * @value: Iterated value of array entry. 157 + * 158 + * Iterate array entries of given @key under @node. Each array entry node 159 + * is stroed to @anode and @value. If the @node doesn't have @key node, 160 + * it does nothing. 161 + * Note that even if the found key node has only one value (not array) 162 + * this executes block once. Hoever, if the found key node has no value 163 + * (key-only node), this does nothing. So don't use this for testing the 164 + * key-value pair existence. 165 + */ 166 + #define xbc_node_for_each_array_value(node, key, anode, value) \ 167 + for (value = xbc_node_find_value(node, key, &anode); value != NULL; \ 168 + anode = xbc_node_get_next(anode), \ 169 + value = anode ? xbc_node_get_data(anode) : NULL) 170 + 171 + /** 172 + * xbc_node_for_each_key_value() - Iterate key-value pairs under a node 173 + * @node: An XBC node. 174 + * @knode: Iterated key node 175 + * @value: Iterated value string 176 + * 177 + * Iterate key-value pairs under @node. Each key node and value string are 178 + * stored in @knode and @value respectively. 179 + */ 180 + #define xbc_node_for_each_key_value(node, knode, value) \ 181 + for (knode = NULL, value = xbc_node_find_next_key_value(node, &knode);\ 182 + knode != NULL; value = xbc_node_find_next_key_value(node, &knode)) 183 + 184 + /** 185 + * xbc_for_each_key_value() - Iterate key-value pairs 186 + * @knode: Iterated key node 187 + * @value: Iterated value string 188 + * 189 + * Iterate key-value pairs in whole XBC tree. Each key node and value string 190 + * are stored in @knode and @value respectively. 191 + */ 192 + #define xbc_for_each_key_value(knode, value) \ 193 + xbc_node_for_each_key_value(NULL, knode, value) 194 + 195 + /* Compose partial key */ 196 + int __init xbc_node_compose_key_after(struct xbc_node *root, 197 + struct xbc_node *node, char *buf, size_t size); 198 + 199 + /** 200 + * xbc_node_compose_key() - Compose full key string of the XBC node 201 + * @node: An XBC node. 202 + * @buf: A buffer to store the key. 203 + * @size: The size of the @buf. 204 + * 205 + * Compose the full-length key of the @node into @buf. Returns the total 206 + * length of the key stored in @buf. Or returns -EINVAL if @node is NULL, 207 + * and -ERANGE if the key depth is deeper than max depth. 208 + */ 209 + static inline int __init xbc_node_compose_key(struct xbc_node *node, 210 + char *buf, size_t size) 211 + { 212 + return xbc_node_compose_key_after(NULL, node, buf, size); 213 + } 214 + 215 + /* XBC node initializer */ 216 + int __init xbc_init(char *buf); 217 + 218 + /* XBC cleanup data structures */ 219 + void __init xbc_destroy_all(void); 220 + 221 + /* Debug dump functions */ 222 + void __init xbc_debug_dump(void); 223 + 224 + #endif
+3 -3
include/linux/perf_event.h
··· 582 582 #define PERF_ATTACH_ITRACE 0x10 583 583 584 584 struct perf_cgroup; 585 - struct ring_buffer; 585 + struct perf_buffer; 586 586 587 587 struct pmu_event_list { 588 588 raw_spinlock_t lock; ··· 694 694 struct mutex mmap_mutex; 695 695 atomic_t mmap_count; 696 696 697 - struct ring_buffer *rb; 697 + struct perf_buffer *rb; 698 698 struct list_head rb_entry; 699 699 unsigned long rcu_batches; 700 700 int rcu_pending; ··· 854 854 855 855 struct perf_output_handle { 856 856 struct perf_event *event; 857 - struct ring_buffer *rb; 857 + struct perf_buffer *rb; 858 858 unsigned long wakeup; 859 859 unsigned long size; 860 860 u64 aux_flags;
+52 -52
include/linux/ring_buffer.h
··· 6 6 #include <linux/seq_file.h> 7 7 #include <linux/poll.h> 8 8 9 - struct ring_buffer; 9 + struct trace_buffer; 10 10 struct ring_buffer_iter; 11 11 12 12 /* ··· 77 77 * else 78 78 * ring_buffer_unlock_commit(buffer, event); 79 79 */ 80 - void ring_buffer_discard_commit(struct ring_buffer *buffer, 80 + void ring_buffer_discard_commit(struct trace_buffer *buffer, 81 81 struct ring_buffer_event *event); 82 82 83 83 /* 84 84 * size is in bytes for each per CPU buffer. 85 85 */ 86 - struct ring_buffer * 86 + struct trace_buffer * 87 87 __ring_buffer_alloc(unsigned long size, unsigned flags, struct lock_class_key *key); 88 88 89 89 /* ··· 97 97 __ring_buffer_alloc((size), (flags), &__key); \ 98 98 }) 99 99 100 - int ring_buffer_wait(struct ring_buffer *buffer, int cpu, int full); 101 - __poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu, 100 + int ring_buffer_wait(struct trace_buffer *buffer, int cpu, int full); 101 + __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu, 102 102 struct file *filp, poll_table *poll_table); 103 103 104 104 105 105 #define RING_BUFFER_ALL_CPUS -1 106 106 107 - void ring_buffer_free(struct ring_buffer *buffer); 107 + void ring_buffer_free(struct trace_buffer *buffer); 108 108 109 - int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size, int cpu); 109 + int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, int cpu); 110 110 111 - void ring_buffer_change_overwrite(struct ring_buffer *buffer, int val); 111 + void ring_buffer_change_overwrite(struct trace_buffer *buffer, int val); 112 112 113 - struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer, 113 + struct ring_buffer_event *ring_buffer_lock_reserve(struct trace_buffer *buffer, 114 114 unsigned long length); 115 - int ring_buffer_unlock_commit(struct ring_buffer *buffer, 115 + int ring_buffer_unlock_commit(struct trace_buffer *buffer, 116 116 struct ring_buffer_event *event); 117 - int ring_buffer_write(struct ring_buffer *buffer, 117 + int ring_buffer_write(struct trace_buffer *buffer, 118 118 unsigned long length, void *data); 119 119 120 - void ring_buffer_nest_start(struct ring_buffer *buffer); 121 - void ring_buffer_nest_end(struct ring_buffer *buffer); 120 + void ring_buffer_nest_start(struct trace_buffer *buffer); 121 + void ring_buffer_nest_end(struct trace_buffer *buffer); 122 122 123 123 struct ring_buffer_event * 124 - ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts, 124 + ring_buffer_peek(struct trace_buffer *buffer, int cpu, u64 *ts, 125 125 unsigned long *lost_events); 126 126 struct ring_buffer_event * 127 - ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts, 127 + ring_buffer_consume(struct trace_buffer *buffer, int cpu, u64 *ts, 128 128 unsigned long *lost_events); 129 129 130 130 struct ring_buffer_iter * 131 - ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags); 131 + ring_buffer_read_prepare(struct trace_buffer *buffer, int cpu, gfp_t flags); 132 132 void ring_buffer_read_prepare_sync(void); 133 133 void ring_buffer_read_start(struct ring_buffer_iter *iter); 134 134 void ring_buffer_read_finish(struct ring_buffer_iter *iter); ··· 140 140 void ring_buffer_iter_reset(struct ring_buffer_iter *iter); 141 141 int ring_buffer_iter_empty(struct ring_buffer_iter *iter); 142 142 143 - unsigned long ring_buffer_size(struct ring_buffer *buffer, int cpu); 143 + unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu); 144 144 145 - void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu); 146 - void ring_buffer_reset(struct ring_buffer *buffer); 145 + void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu); 146 + void ring_buffer_reset(struct trace_buffer *buffer); 147 147 148 148 #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP 149 - int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, 150 - struct ring_buffer *buffer_b, int cpu); 149 + int ring_buffer_swap_cpu(struct trace_buffer *buffer_a, 150 + struct trace_buffer *buffer_b, int cpu); 151 151 #else 152 152 static inline int 153 - ring_buffer_swap_cpu(struct ring_buffer *buffer_a, 154 - struct ring_buffer *buffer_b, int cpu) 153 + ring_buffer_swap_cpu(struct trace_buffer *buffer_a, 154 + struct trace_buffer *buffer_b, int cpu) 155 155 { 156 156 return -ENODEV; 157 157 } 158 158 #endif 159 159 160 - bool ring_buffer_empty(struct ring_buffer *buffer); 161 - bool ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu); 160 + bool ring_buffer_empty(struct trace_buffer *buffer); 161 + bool ring_buffer_empty_cpu(struct trace_buffer *buffer, int cpu); 162 162 163 - void ring_buffer_record_disable(struct ring_buffer *buffer); 164 - void ring_buffer_record_enable(struct ring_buffer *buffer); 165 - void ring_buffer_record_off(struct ring_buffer *buffer); 166 - void ring_buffer_record_on(struct ring_buffer *buffer); 167 - bool ring_buffer_record_is_on(struct ring_buffer *buffer); 168 - bool ring_buffer_record_is_set_on(struct ring_buffer *buffer); 169 - void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu); 170 - void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); 163 + void ring_buffer_record_disable(struct trace_buffer *buffer); 164 + void ring_buffer_record_enable(struct trace_buffer *buffer); 165 + void ring_buffer_record_off(struct trace_buffer *buffer); 166 + void ring_buffer_record_on(struct trace_buffer *buffer); 167 + bool ring_buffer_record_is_on(struct trace_buffer *buffer); 168 + bool ring_buffer_record_is_set_on(struct trace_buffer *buffer); 169 + void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu); 170 + void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu); 171 171 172 - u64 ring_buffer_oldest_event_ts(struct ring_buffer *buffer, int cpu); 173 - unsigned long ring_buffer_bytes_cpu(struct ring_buffer *buffer, int cpu); 174 - unsigned long ring_buffer_entries(struct ring_buffer *buffer); 175 - unsigned long ring_buffer_overruns(struct ring_buffer *buffer); 176 - unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); 177 - unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); 178 - unsigned long ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu); 179 - unsigned long ring_buffer_dropped_events_cpu(struct ring_buffer *buffer, int cpu); 180 - unsigned long ring_buffer_read_events_cpu(struct ring_buffer *buffer, int cpu); 172 + u64 ring_buffer_oldest_event_ts(struct trace_buffer *buffer, int cpu); 173 + unsigned long ring_buffer_bytes_cpu(struct trace_buffer *buffer, int cpu); 174 + unsigned long ring_buffer_entries(struct trace_buffer *buffer); 175 + unsigned long ring_buffer_overruns(struct trace_buffer *buffer); 176 + unsigned long ring_buffer_entries_cpu(struct trace_buffer *buffer, int cpu); 177 + unsigned long ring_buffer_overrun_cpu(struct trace_buffer *buffer, int cpu); 178 + unsigned long ring_buffer_commit_overrun_cpu(struct trace_buffer *buffer, int cpu); 179 + unsigned long ring_buffer_dropped_events_cpu(struct trace_buffer *buffer, int cpu); 180 + unsigned long ring_buffer_read_events_cpu(struct trace_buffer *buffer, int cpu); 181 181 182 - u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu); 183 - void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer, 182 + u64 ring_buffer_time_stamp(struct trace_buffer *buffer, int cpu); 183 + void ring_buffer_normalize_time_stamp(struct trace_buffer *buffer, 184 184 int cpu, u64 *ts); 185 - void ring_buffer_set_clock(struct ring_buffer *buffer, 185 + void ring_buffer_set_clock(struct trace_buffer *buffer, 186 186 u64 (*clock)(void)); 187 - void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs); 188 - bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer); 187 + void ring_buffer_set_time_stamp_abs(struct trace_buffer *buffer, bool abs); 188 + bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer); 189 189 190 - size_t ring_buffer_nr_pages(struct ring_buffer *buffer, int cpu); 191 - size_t ring_buffer_nr_dirty_pages(struct ring_buffer *buffer, int cpu); 190 + size_t ring_buffer_nr_pages(struct trace_buffer *buffer, int cpu); 191 + size_t ring_buffer_nr_dirty_pages(struct trace_buffer *buffer, int cpu); 192 192 193 - void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu); 194 - void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data); 195 - int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page, 193 + void *ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu); 194 + void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu, void *data); 195 + int ring_buffer_read_page(struct trace_buffer *buffer, void **data_page, 196 196 size_t len, int cpu, int full); 197 197 198 198 struct trace_seq;
+127 -4
include/linux/trace_events.h
··· 11 11 #include <linux/tracepoint.h> 12 12 13 13 struct trace_array; 14 - struct trace_buffer; 14 + struct array_buffer; 15 15 struct tracer; 16 16 struct dentry; 17 17 struct bpf_prog; ··· 79 79 struct trace_iterator { 80 80 struct trace_array *tr; 81 81 struct tracer *trace; 82 - struct trace_buffer *trace_buffer; 82 + struct array_buffer *array_buffer; 83 83 void *private; 84 84 int cpu_file; 85 85 struct mutex mutex; ··· 153 153 struct trace_event_file; 154 154 155 155 struct ring_buffer_event * 156 - trace_event_buffer_lock_reserve(struct ring_buffer **current_buffer, 156 + trace_event_buffer_lock_reserve(struct trace_buffer **current_buffer, 157 157 struct trace_event_file *trace_file, 158 158 int type, unsigned long len, 159 159 unsigned long flags, int pc); ··· 226 226 enum trace_reg type, void *data); 227 227 228 228 struct trace_event_buffer { 229 - struct ring_buffer *buffer; 229 + struct trace_buffer *buffer; 230 230 struct ring_buffer_event *event; 231 231 struct trace_event_file *trace_file; 232 232 void *entry; 233 233 unsigned long flags; 234 234 int pc; 235 + struct pt_regs *regs; 235 236 }; 236 237 237 238 void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer, ··· 364 363 EVENT_FILE_FL_PID_FILTER_BIT, 365 364 EVENT_FILE_FL_WAS_ENABLED_BIT, 366 365 }; 366 + 367 + extern struct trace_event_file *trace_get_event_file(const char *instance, 368 + const char *system, 369 + const char *event); 370 + extern void trace_put_event_file(struct trace_event_file *file); 371 + 372 + #define MAX_DYNEVENT_CMD_LEN (2048) 373 + 374 + enum dynevent_type { 375 + DYNEVENT_TYPE_SYNTH = 1, 376 + DYNEVENT_TYPE_KPROBE, 377 + DYNEVENT_TYPE_NONE, 378 + }; 379 + 380 + struct dynevent_cmd; 381 + 382 + typedef int (*dynevent_create_fn_t)(struct dynevent_cmd *cmd); 383 + 384 + struct dynevent_cmd { 385 + struct seq_buf seq; 386 + const char *event_name; 387 + unsigned int n_fields; 388 + enum dynevent_type type; 389 + dynevent_create_fn_t run_command; 390 + void *private_data; 391 + }; 392 + 393 + extern int dynevent_create(struct dynevent_cmd *cmd); 394 + 395 + extern int synth_event_delete(const char *name); 396 + 397 + extern void synth_event_cmd_init(struct dynevent_cmd *cmd, 398 + char *buf, int maxlen); 399 + 400 + extern int __synth_event_gen_cmd_start(struct dynevent_cmd *cmd, 401 + const char *name, 402 + struct module *mod, ...); 403 + 404 + #define synth_event_gen_cmd_start(cmd, name, mod, ...) \ 405 + __synth_event_gen_cmd_start(cmd, name, mod, ## __VA_ARGS__, NULL) 406 + 407 + struct synth_field_desc { 408 + const char *type; 409 + const char *name; 410 + }; 411 + 412 + extern int synth_event_gen_cmd_array_start(struct dynevent_cmd *cmd, 413 + const char *name, 414 + struct module *mod, 415 + struct synth_field_desc *fields, 416 + unsigned int n_fields); 417 + extern int synth_event_create(const char *name, 418 + struct synth_field_desc *fields, 419 + unsigned int n_fields, struct module *mod); 420 + 421 + extern int synth_event_add_field(struct dynevent_cmd *cmd, 422 + const char *type, 423 + const char *name); 424 + extern int synth_event_add_field_str(struct dynevent_cmd *cmd, 425 + const char *type_name); 426 + extern int synth_event_add_fields(struct dynevent_cmd *cmd, 427 + struct synth_field_desc *fields, 428 + unsigned int n_fields); 429 + 430 + #define synth_event_gen_cmd_end(cmd) \ 431 + dynevent_create(cmd) 432 + 433 + struct synth_event; 434 + 435 + struct synth_event_trace_state { 436 + struct trace_event_buffer fbuffer; 437 + struct synth_trace_event *entry; 438 + struct trace_buffer *buffer; 439 + struct synth_event *event; 440 + unsigned int cur_field; 441 + unsigned int n_u64; 442 + bool enabled; 443 + bool add_next; 444 + bool add_name; 445 + }; 446 + 447 + extern int synth_event_trace(struct trace_event_file *file, 448 + unsigned int n_vals, ...); 449 + extern int synth_event_trace_array(struct trace_event_file *file, u64 *vals, 450 + unsigned int n_vals); 451 + extern int synth_event_trace_start(struct trace_event_file *file, 452 + struct synth_event_trace_state *trace_state); 453 + extern int synth_event_add_next_val(u64 val, 454 + struct synth_event_trace_state *trace_state); 455 + extern int synth_event_add_val(const char *field_name, u64 val, 456 + struct synth_event_trace_state *trace_state); 457 + extern int synth_event_trace_end(struct synth_event_trace_state *trace_state); 458 + 459 + extern int kprobe_event_delete(const char *name); 460 + 461 + extern void kprobe_event_cmd_init(struct dynevent_cmd *cmd, 462 + char *buf, int maxlen); 463 + 464 + #define kprobe_event_gen_cmd_start(cmd, name, loc, ...) \ 465 + __kprobe_event_gen_cmd_start(cmd, false, name, loc, ## __VA_ARGS__, NULL) 466 + 467 + #define kretprobe_event_gen_cmd_start(cmd, name, loc, ...) \ 468 + __kprobe_event_gen_cmd_start(cmd, true, name, loc, ## __VA_ARGS__, NULL) 469 + 470 + extern int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, 471 + bool kretprobe, 472 + const char *name, 473 + const char *loc, ...); 474 + 475 + #define kprobe_event_add_fields(cmd, ...) \ 476 + __kprobe_event_add_fields(cmd, ## __VA_ARGS__, NULL) 477 + 478 + #define kprobe_event_add_field(cmd, field) \ 479 + __kprobe_event_add_fields(cmd, field, NULL) 480 + 481 + extern int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...); 482 + 483 + #define kprobe_event_gen_cmd_end(cmd) \ 484 + dynevent_create(cmd) 485 + 486 + #define kretprobe_event_gen_cmd_end(cmd) \ 487 + dynevent_create(cmd) 367 488 368 489 /* 369 490 * Event file flags:
+7 -4
include/trace/trace_events.h
··· 2 2 /* 3 3 * Stage 1 of the trace events. 4 4 * 5 - * Override the macros in <trace/trace_events.h> to include the following: 5 + * Override the macros in the event tracepoint header <trace/events/XXX.h> 6 + * to include the following: 6 7 * 7 8 * struct trace_event_raw_<call> { 8 9 * struct trace_entry ent; ··· 224 223 /* 225 224 * Stage 3 of the trace events. 226 225 * 227 - * Override the macros in <trace/trace_events.h> to include the following: 226 + * Override the macros in the event tracepoint header <trace/events/XXX.h> 227 + * to include the following: 228 228 * 229 229 * enum print_line_t 230 230 * trace_raw_output_<call>(struct trace_iterator *iter, int flags) ··· 535 533 /* 536 534 * Stage 4 of the trace events. 537 535 * 538 - * Override the macros in <trace/trace_events.h> to include the following: 536 + * Override the macros in the event tracepoint header <trace/events/XXX.h> 537 + * to include the following: 539 538 * 540 539 * For those macros defined with TRACE_EVENT: 541 540 * ··· 551 548 * enum event_trigger_type __tt = ETT_NONE; 552 549 * struct ring_buffer_event *event; 553 550 * struct trace_event_raw_<call> *entry; <-- defined in stage 1 554 - * struct ring_buffer *buffer; 551 + * struct trace_buffer *buffer; 555 552 * unsigned long irq_flags; 556 553 * int __data_size; 557 554 * int pc;
+14
init/Kconfig
··· 1224 1224 1225 1225 endif 1226 1226 1227 + config BOOT_CONFIG 1228 + bool "Boot config support" 1229 + depends on BLK_DEV_INITRD 1230 + select LIBXBC 1231 + default y 1232 + help 1233 + Extra boot config allows system admin to pass a config file as 1234 + complemental extension of kernel cmdline when booting. 1235 + The boot config file must be attached at the end of initramfs 1236 + with checksum and size. 1237 + See <file:Documentation/admin-guide/bootconfig.rst> for details. 1238 + 1239 + If unsure, say Y. 1240 + 1227 1241 choice 1228 1242 prompt "Compiler optimization level" 1229 1243 default CC_OPTIMIZE_FOR_PERFORMANCE
+212 -17
init/main.c
··· 28 28 #include <linux/initrd.h> 29 29 #include <linux/memblock.h> 30 30 #include <linux/acpi.h> 31 + #include <linux/bootconfig.h> 31 32 #include <linux/console.h> 32 33 #include <linux/nmi.h> 33 34 #include <linux/percpu.h> ··· 137 136 char *saved_command_line; 138 137 /* Command line for parameter parsing */ 139 138 static char *static_command_line; 140 - /* Command line for per-initcall parameter parsing */ 141 - static char *initcall_command_line; 139 + /* Untouched extra command line */ 140 + static char *extra_command_line; 141 + /* Extra init arguments */ 142 + static char *extra_init_args; 142 143 143 144 static char *execute_command; 144 145 static char *ramdisk_execute_command; ··· 247 244 } 248 245 249 246 early_param("loglevel", loglevel); 247 + 248 + #ifdef CONFIG_BOOT_CONFIG 249 + 250 + char xbc_namebuf[XBC_KEYLEN_MAX] __initdata; 251 + 252 + #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) 253 + 254 + static int __init xbc_snprint_cmdline(char *buf, size_t size, 255 + struct xbc_node *root) 256 + { 257 + struct xbc_node *knode, *vnode; 258 + char *end = buf + size; 259 + char c = '\"'; 260 + const char *val; 261 + int ret; 262 + 263 + xbc_node_for_each_key_value(root, knode, val) { 264 + ret = xbc_node_compose_key_after(root, knode, 265 + xbc_namebuf, XBC_KEYLEN_MAX); 266 + if (ret < 0) 267 + return ret; 268 + 269 + vnode = xbc_node_get_child(knode); 270 + ret = snprintf(buf, rest(buf, end), "%s%c", xbc_namebuf, 271 + vnode ? '=' : ' '); 272 + if (ret < 0) 273 + return ret; 274 + buf += ret; 275 + if (!vnode) 276 + continue; 277 + 278 + c = '\"'; 279 + xbc_array_for_each_value(vnode, val) { 280 + ret = snprintf(buf, rest(buf, end), "%c%s", c, val); 281 + if (ret < 0) 282 + return ret; 283 + buf += ret; 284 + c = ','; 285 + } 286 + if (rest(buf, end) > 2) 287 + strcpy(buf, "\" "); 288 + buf += 2; 289 + } 290 + 291 + return buf - (end - size); 292 + } 293 + #undef rest 294 + 295 + /* Make an extra command line under given key word */ 296 + static char * __init xbc_make_cmdline(const char *key) 297 + { 298 + struct xbc_node *root; 299 + char *new_cmdline; 300 + int ret, len = 0; 301 + 302 + root = xbc_find_node(key); 303 + if (!root) 304 + return NULL; 305 + 306 + /* Count required buffer size */ 307 + len = xbc_snprint_cmdline(NULL, 0, root); 308 + if (len <= 0) 309 + return NULL; 310 + 311 + new_cmdline = memblock_alloc(len + 1, SMP_CACHE_BYTES); 312 + if (!new_cmdline) { 313 + pr_err("Failed to allocate memory for extra kernel cmdline.\n"); 314 + return NULL; 315 + } 316 + 317 + ret = xbc_snprint_cmdline(new_cmdline, len + 1, root); 318 + if (ret < 0 || ret > len) { 319 + pr_err("Failed to print extra kernel cmdline.\n"); 320 + return NULL; 321 + } 322 + 323 + return new_cmdline; 324 + } 325 + 326 + u32 boot_config_checksum(unsigned char *p, u32 size) 327 + { 328 + u32 ret = 0; 329 + 330 + while (size--) 331 + ret += *p++; 332 + 333 + return ret; 334 + } 335 + 336 + static void __init setup_boot_config(const char *cmdline) 337 + { 338 + u32 size, csum; 339 + char *data, *copy; 340 + const char *p; 341 + u32 *hdr; 342 + int ret; 343 + 344 + p = strstr(cmdline, "bootconfig"); 345 + if (!p || (p != cmdline && !isspace(*(p-1))) || 346 + (p[10] && !isspace(p[10]))) 347 + return; 348 + 349 + if (!initrd_end) 350 + goto not_found; 351 + 352 + hdr = (u32 *)(initrd_end - 8); 353 + size = hdr[0]; 354 + csum = hdr[1]; 355 + 356 + if (size >= XBC_DATA_MAX) { 357 + pr_err("bootconfig size %d greater than max size %d\n", 358 + size, XBC_DATA_MAX); 359 + return; 360 + } 361 + 362 + data = ((void *)hdr) - size; 363 + if ((unsigned long)data < initrd_start) 364 + goto not_found; 365 + 366 + if (boot_config_checksum((unsigned char *)data, size) != csum) { 367 + pr_err("bootconfig checksum failed\n"); 368 + return; 369 + } 370 + 371 + copy = memblock_alloc(size + 1, SMP_CACHE_BYTES); 372 + if (!copy) { 373 + pr_err("Failed to allocate memory for bootconfig\n"); 374 + return; 375 + } 376 + 377 + memcpy(copy, data, size); 378 + copy[size] = '\0'; 379 + 380 + ret = xbc_init(copy); 381 + if (ret < 0) 382 + pr_err("Failed to parse bootconfig\n"); 383 + else { 384 + pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); 385 + /* keys starting with "kernel." are passed via cmdline */ 386 + extra_command_line = xbc_make_cmdline("kernel"); 387 + /* Also, "init." keys are init arguments */ 388 + extra_init_args = xbc_make_cmdline("init"); 389 + } 390 + return; 391 + not_found: 392 + pr_err("'bootconfig' found on command line, but no bootconfig found\n"); 393 + } 394 + #else 395 + #define setup_boot_config(cmdline) do { } while (0) 396 + #endif 250 397 251 398 /* Change NUL term back to "=", to make "param" the whole string. */ 252 399 static void __init repair_env_string(char *param, char *val) ··· 526 373 */ 527 374 static void __init setup_command_line(char *command_line) 528 375 { 529 - size_t len = strlen(boot_command_line) + 1; 376 + size_t len, xlen = 0, ilen = 0; 530 377 531 - saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 378 + if (extra_command_line) 379 + xlen = strlen(extra_command_line); 380 + if (extra_init_args) 381 + ilen = strlen(extra_init_args) + 4; /* for " -- " */ 382 + 383 + len = xlen + strlen(boot_command_line) + 1; 384 + 385 + saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES); 532 386 if (!saved_command_line) 533 - panic("%s: Failed to allocate %zu bytes\n", __func__, len); 534 - 535 - initcall_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 536 - if (!initcall_command_line) 537 - panic("%s: Failed to allocate %zu bytes\n", __func__, len); 387 + panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen); 538 388 539 389 static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 540 390 if (!static_command_line) 541 391 panic("%s: Failed to allocate %zu bytes\n", __func__, len); 542 392 543 - strcpy(saved_command_line, boot_command_line); 544 - strcpy(static_command_line, command_line); 393 + if (xlen) { 394 + /* 395 + * We have to put extra_command_line before boot command 396 + * lines because there could be dashes (separator of init 397 + * command line) in the command lines. 398 + */ 399 + strcpy(saved_command_line, extra_command_line); 400 + strcpy(static_command_line, extra_command_line); 401 + } 402 + strcpy(saved_command_line + xlen, boot_command_line); 403 + strcpy(static_command_line + xlen, command_line); 404 + 405 + if (ilen) { 406 + /* 407 + * Append supplemental init boot args to saved_command_line 408 + * so that user can check what command line options passed 409 + * to init. 410 + */ 411 + len = strlen(saved_command_line); 412 + if (!strstr(boot_command_line, " -- ")) { 413 + strcpy(saved_command_line + len, " -- "); 414 + len += 4; 415 + } else 416 + saved_command_line[len++] = ' '; 417 + 418 + strcpy(saved_command_line + len, extra_init_args); 419 + } 545 420 } 546 421 547 422 /* ··· 776 595 pr_notice("%s", linux_banner); 777 596 early_security_init(); 778 597 setup_arch(&command_line); 598 + setup_boot_config(command_line); 779 599 setup_command_line(command_line); 780 600 setup_nr_cpu_ids(); 781 601 setup_per_cpu_areas(); ··· 786 604 build_all_zonelists(NULL); 787 605 page_alloc_init(); 788 606 789 - pr_notice("Kernel command line: %s\n", boot_command_line); 607 + pr_notice("Kernel command line: %s\n", saved_command_line); 790 608 /* parameters may set static keys */ 791 609 jump_label_init(); 792 610 parse_early_param(); ··· 797 615 if (!IS_ERR_OR_NULL(after_dashes)) 798 616 parse_args("Setting init args", after_dashes, NULL, 0, -1, -1, 799 617 NULL, set_init_arg); 618 + if (extra_init_args) 619 + parse_args("Setting extra init args", extra_init_args, 620 + NULL, 0, -1, -1, NULL, set_init_arg); 800 621 801 622 /* 802 623 * These use large bootmem allocations and must precede ··· 1181 996 return 0; 1182 997 } 1183 998 1184 - static void __init do_initcall_level(int level) 999 + static void __init do_initcall_level(int level, char *command_line) 1185 1000 { 1186 1001 initcall_entry_t *fn; 1187 1002 1188 - strcpy(initcall_command_line, saved_command_line); 1189 1003 parse_args(initcall_level_names[level], 1190 - initcall_command_line, __start___param, 1004 + command_line, __start___param, 1191 1005 __stop___param - __start___param, 1192 1006 level, level, 1193 1007 NULL, ignore_unknown_bootoption); ··· 1199 1015 static void __init do_initcalls(void) 1200 1016 { 1201 1017 int level; 1018 + size_t len = strlen(saved_command_line) + 1; 1019 + char *command_line; 1202 1020 1203 - for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) 1204 - do_initcall_level(level); 1021 + command_line = kzalloc(len, GFP_KERNEL); 1022 + if (!command_line) 1023 + panic("%s: Failed to allocate %zu bytes\n", __func__, len); 1024 + 1025 + for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) { 1026 + /* Parser modifies command_line, restore it each time */ 1027 + strcpy(command_line, saved_command_line); 1028 + do_initcall_level(level, command_line); 1029 + } 1030 + 1031 + kfree(command_line); 1205 1032 } 1206 1033 1207 1034 /*
+21 -21
kernel/events/core.c
··· 4373 4373 } 4374 4374 4375 4375 static void ring_buffer_attach(struct perf_event *event, 4376 - struct ring_buffer *rb); 4376 + struct perf_buffer *rb); 4377 4377 4378 4378 static void detach_sb_event(struct perf_event *event) 4379 4379 { ··· 5054 5054 static __poll_t perf_poll(struct file *file, poll_table *wait) 5055 5055 { 5056 5056 struct perf_event *event = file->private_data; 5057 - struct ring_buffer *rb; 5057 + struct perf_buffer *rb; 5058 5058 __poll_t events = EPOLLHUP; 5059 5059 5060 5060 poll_wait(file, &event->waitq, wait); ··· 5296 5296 return perf_event_set_bpf_prog(event, arg); 5297 5297 5298 5298 case PERF_EVENT_IOC_PAUSE_OUTPUT: { 5299 - struct ring_buffer *rb; 5299 + struct perf_buffer *rb; 5300 5300 5301 5301 rcu_read_lock(); 5302 5302 rb = rcu_dereference(event->rb); ··· 5432 5432 static void perf_event_init_userpage(struct perf_event *event) 5433 5433 { 5434 5434 struct perf_event_mmap_page *userpg; 5435 - struct ring_buffer *rb; 5435 + struct perf_buffer *rb; 5436 5436 5437 5437 rcu_read_lock(); 5438 5438 rb = rcu_dereference(event->rb); ··· 5464 5464 void perf_event_update_userpage(struct perf_event *event) 5465 5465 { 5466 5466 struct perf_event_mmap_page *userpg; 5467 - struct ring_buffer *rb; 5467 + struct perf_buffer *rb; 5468 5468 u64 enabled, running, now; 5469 5469 5470 5470 rcu_read_lock(); ··· 5515 5515 static vm_fault_t perf_mmap_fault(struct vm_fault *vmf) 5516 5516 { 5517 5517 struct perf_event *event = vmf->vma->vm_file->private_data; 5518 - struct ring_buffer *rb; 5518 + struct perf_buffer *rb; 5519 5519 vm_fault_t ret = VM_FAULT_SIGBUS; 5520 5520 5521 5521 if (vmf->flags & FAULT_FLAG_MKWRITE) { ··· 5548 5548 } 5549 5549 5550 5550 static void ring_buffer_attach(struct perf_event *event, 5551 - struct ring_buffer *rb) 5551 + struct perf_buffer *rb) 5552 5552 { 5553 - struct ring_buffer *old_rb = NULL; 5553 + struct perf_buffer *old_rb = NULL; 5554 5554 unsigned long flags; 5555 5555 5556 5556 if (event->rb) { ··· 5608 5608 5609 5609 static void ring_buffer_wakeup(struct perf_event *event) 5610 5610 { 5611 - struct ring_buffer *rb; 5611 + struct perf_buffer *rb; 5612 5612 5613 5613 rcu_read_lock(); 5614 5614 rb = rcu_dereference(event->rb); ··· 5619 5619 rcu_read_unlock(); 5620 5620 } 5621 5621 5622 - struct ring_buffer *ring_buffer_get(struct perf_event *event) 5622 + struct perf_buffer *ring_buffer_get(struct perf_event *event) 5623 5623 { 5624 - struct ring_buffer *rb; 5624 + struct perf_buffer *rb; 5625 5625 5626 5626 rcu_read_lock(); 5627 5627 rb = rcu_dereference(event->rb); ··· 5634 5634 return rb; 5635 5635 } 5636 5636 5637 - void ring_buffer_put(struct ring_buffer *rb) 5637 + void ring_buffer_put(struct perf_buffer *rb) 5638 5638 { 5639 5639 if (!refcount_dec_and_test(&rb->refcount)) 5640 5640 return; ··· 5672 5672 { 5673 5673 struct perf_event *event = vma->vm_file->private_data; 5674 5674 5675 - struct ring_buffer *rb = ring_buffer_get(event); 5675 + struct perf_buffer *rb = ring_buffer_get(event); 5676 5676 struct user_struct *mmap_user = rb->mmap_user; 5677 5677 int mmap_locked = rb->mmap_locked; 5678 5678 unsigned long size = perf_data_size(rb); ··· 5790 5790 struct perf_event *event = file->private_data; 5791 5791 unsigned long user_locked, user_lock_limit; 5792 5792 struct user_struct *user = current_user(); 5793 + struct perf_buffer *rb = NULL; 5793 5794 unsigned long locked, lock_limit; 5794 - struct ring_buffer *rb = NULL; 5795 5795 unsigned long vma_size; 5796 5796 unsigned long nr_pages; 5797 5797 long user_extra = 0, extra = 0; ··· 6266 6266 size_t size) 6267 6267 { 6268 6268 struct perf_event *sampler = event->aux_event; 6269 - struct ring_buffer *rb; 6269 + struct perf_buffer *rb; 6270 6270 6271 6271 data->aux_size = 0; 6272 6272 ··· 6299 6299 return data->aux_size; 6300 6300 } 6301 6301 6302 - long perf_pmu_snapshot_aux(struct ring_buffer *rb, 6302 + long perf_pmu_snapshot_aux(struct perf_buffer *rb, 6303 6303 struct perf_event *event, 6304 6304 struct perf_output_handle *handle, 6305 6305 unsigned long size) ··· 6338 6338 struct perf_sample_data *data) 6339 6339 { 6340 6340 struct perf_event *sampler = event->aux_event; 6341 + struct perf_buffer *rb; 6341 6342 unsigned long pad; 6342 - struct ring_buffer *rb; 6343 6343 long size; 6344 6344 6345 6345 if (WARN_ON_ONCE(!sampler || !data->aux_size)) ··· 6707 6707 int wakeup_events = event->attr.wakeup_events; 6708 6708 6709 6709 if (wakeup_events) { 6710 - struct ring_buffer *rb = handle->rb; 6710 + struct perf_buffer *rb = handle->rb; 6711 6711 int events = local_inc_return(&rb->events); 6712 6712 6713 6713 if (events >= wakeup_events) { ··· 7150 7150 } 7151 7151 7152 7152 struct remote_output { 7153 - struct ring_buffer *rb; 7153 + struct perf_buffer *rb; 7154 7154 int err; 7155 7155 }; 7156 7156 ··· 7158 7158 { 7159 7159 struct perf_event *parent = event->parent; 7160 7160 struct remote_output *ro = data; 7161 - struct ring_buffer *rb = ro->rb; 7161 + struct perf_buffer *rb = ro->rb; 7162 7162 struct stop_event_data sd = { 7163 7163 .event = event, 7164 7164 }; ··· 10998 10998 static int 10999 10999 perf_event_set_output(struct perf_event *event, struct perf_event *output_event) 11000 11000 { 11001 - struct ring_buffer *rb = NULL; 11001 + struct perf_buffer *rb = NULL; 11002 11002 int ret = -EINVAL; 11003 11003 11004 11004 if (!output_event)
+17 -17
kernel/events/internal.h
··· 10 10 11 11 #define RING_BUFFER_WRITABLE 0x01 12 12 13 - struct ring_buffer { 13 + struct perf_buffer { 14 14 refcount_t refcount; 15 15 struct rcu_head rcu_head; 16 16 #ifdef CONFIG_PERF_USE_VMALLOC ··· 58 58 void *data_pages[0]; 59 59 }; 60 60 61 - extern void rb_free(struct ring_buffer *rb); 61 + extern void rb_free(struct perf_buffer *rb); 62 62 63 63 static inline void rb_free_rcu(struct rcu_head *rcu_head) 64 64 { 65 - struct ring_buffer *rb; 65 + struct perf_buffer *rb; 66 66 67 - rb = container_of(rcu_head, struct ring_buffer, rcu_head); 67 + rb = container_of(rcu_head, struct perf_buffer, rcu_head); 68 68 rb_free(rb); 69 69 } 70 70 71 - static inline void rb_toggle_paused(struct ring_buffer *rb, bool pause) 71 + static inline void rb_toggle_paused(struct perf_buffer *rb, bool pause) 72 72 { 73 73 if (!pause && rb->nr_pages) 74 74 rb->paused = 0; ··· 76 76 rb->paused = 1; 77 77 } 78 78 79 - extern struct ring_buffer * 79 + extern struct perf_buffer * 80 80 rb_alloc(int nr_pages, long watermark, int cpu, int flags); 81 81 extern void perf_event_wakeup(struct perf_event *event); 82 - extern int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event, 82 + extern int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, 83 83 pgoff_t pgoff, int nr_pages, long watermark, int flags); 84 - extern void rb_free_aux(struct ring_buffer *rb); 85 - extern struct ring_buffer *ring_buffer_get(struct perf_event *event); 86 - extern void ring_buffer_put(struct ring_buffer *rb); 84 + extern void rb_free_aux(struct perf_buffer *rb); 85 + extern struct perf_buffer *ring_buffer_get(struct perf_event *event); 86 + extern void ring_buffer_put(struct perf_buffer *rb); 87 87 88 - static inline bool rb_has_aux(struct ring_buffer *rb) 88 + static inline bool rb_has_aux(struct perf_buffer *rb) 89 89 { 90 90 return !!rb->aux_nr_pages; 91 91 } ··· 94 94 unsigned long size, u64 flags); 95 95 96 96 extern struct page * 97 - perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff); 97 + perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff); 98 98 99 99 #ifdef CONFIG_PERF_USE_VMALLOC 100 100 /* ··· 103 103 * Required for architectures that have d-cache aliasing issues. 104 104 */ 105 105 106 - static inline int page_order(struct ring_buffer *rb) 106 + static inline int page_order(struct perf_buffer *rb) 107 107 { 108 108 return rb->page_order; 109 109 } 110 110 111 111 #else 112 112 113 - static inline int page_order(struct ring_buffer *rb) 113 + static inline int page_order(struct perf_buffer *rb) 114 114 { 115 115 return 0; 116 116 } 117 117 #endif 118 118 119 - static inline unsigned long perf_data_size(struct ring_buffer *rb) 119 + static inline unsigned long perf_data_size(struct perf_buffer *rb) 120 120 { 121 121 return rb->nr_pages << (PAGE_SHIFT + page_order(rb)); 122 122 } 123 123 124 - static inline unsigned long perf_aux_size(struct ring_buffer *rb) 124 + static inline unsigned long perf_aux_size(struct perf_buffer *rb) 125 125 { 126 126 return rb->aux_nr_pages << PAGE_SHIFT; 127 127 } ··· 141 141 buf += written; \ 142 142 handle->size -= written; \ 143 143 if (!handle->size) { \ 144 - struct ring_buffer *rb = handle->rb; \ 144 + struct perf_buffer *rb = handle->rb; \ 145 145 \ 146 146 handle->page++; \ 147 147 handle->page &= rb->nr_pages - 1; \
+27 -27
kernel/events/ring_buffer.c
··· 35 35 */ 36 36 static void perf_output_get_handle(struct perf_output_handle *handle) 37 37 { 38 - struct ring_buffer *rb = handle->rb; 38 + struct perf_buffer *rb = handle->rb; 39 39 40 40 preempt_disable(); 41 41 ··· 49 49 50 50 static void perf_output_put_handle(struct perf_output_handle *handle) 51 51 { 52 - struct ring_buffer *rb = handle->rb; 52 + struct perf_buffer *rb = handle->rb; 53 53 unsigned long head; 54 54 unsigned int nest; 55 55 ··· 150 150 struct perf_event *event, unsigned int size, 151 151 bool backward) 152 152 { 153 - struct ring_buffer *rb; 153 + struct perf_buffer *rb; 154 154 unsigned long tail, offset, head; 155 155 int have_lost, page_shift; 156 156 struct { ··· 301 301 } 302 302 303 303 static void 304 - ring_buffer_init(struct ring_buffer *rb, long watermark, int flags) 304 + ring_buffer_init(struct perf_buffer *rb, long watermark, int flags) 305 305 { 306 306 long max_size = perf_data_size(rb); 307 307 ··· 361 361 { 362 362 struct perf_event *output_event = event; 363 363 unsigned long aux_head, aux_tail; 364 - struct ring_buffer *rb; 364 + struct perf_buffer *rb; 365 365 unsigned int nest; 366 366 367 367 if (output_event->parent) ··· 449 449 } 450 450 EXPORT_SYMBOL_GPL(perf_aux_output_begin); 451 451 452 - static __always_inline bool rb_need_aux_wakeup(struct ring_buffer *rb) 452 + static __always_inline bool rb_need_aux_wakeup(struct perf_buffer *rb) 453 453 { 454 454 if (rb->aux_overwrite) 455 455 return false; ··· 475 475 void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size) 476 476 { 477 477 bool wakeup = !!(handle->aux_flags & PERF_AUX_FLAG_TRUNCATED); 478 - struct ring_buffer *rb = handle->rb; 478 + struct perf_buffer *rb = handle->rb; 479 479 unsigned long aux_head; 480 480 481 481 /* in overwrite mode, driver provides aux_head via handle */ ··· 532 532 */ 533 533 int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size) 534 534 { 535 - struct ring_buffer *rb = handle->rb; 535 + struct perf_buffer *rb = handle->rb; 536 536 537 537 if (size > handle->size) 538 538 return -ENOSPC; ··· 569 569 struct perf_output_handle *handle, 570 570 unsigned long from, unsigned long to) 571 571 { 572 + struct perf_buffer *rb = aux_handle->rb; 572 573 unsigned long tocopy, remainder, len = 0; 573 - struct ring_buffer *rb = aux_handle->rb; 574 574 void *addr; 575 575 576 576 from &= (rb->aux_nr_pages << PAGE_SHIFT) - 1; ··· 626 626 return page; 627 627 } 628 628 629 - static void rb_free_aux_page(struct ring_buffer *rb, int idx) 629 + static void rb_free_aux_page(struct perf_buffer *rb, int idx) 630 630 { 631 631 struct page *page = virt_to_page(rb->aux_pages[idx]); 632 632 ··· 635 635 __free_page(page); 636 636 } 637 637 638 - static void __rb_free_aux(struct ring_buffer *rb) 638 + static void __rb_free_aux(struct perf_buffer *rb) 639 639 { 640 640 int pg; 641 641 ··· 662 662 } 663 663 } 664 664 665 - int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event, 665 + int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, 666 666 pgoff_t pgoff, int nr_pages, long watermark, int flags) 667 667 { 668 668 bool overwrite = !(flags & RING_BUFFER_WRITABLE); ··· 753 753 return ret; 754 754 } 755 755 756 - void rb_free_aux(struct ring_buffer *rb) 756 + void rb_free_aux(struct perf_buffer *rb) 757 757 { 758 758 if (refcount_dec_and_test(&rb->aux_refcount)) 759 759 __rb_free_aux(rb); ··· 766 766 */ 767 767 768 768 static struct page * 769 - __perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff) 769 + __perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff) 770 770 { 771 771 if (pgoff > rb->nr_pages) 772 772 return NULL; ··· 798 798 __free_page(page); 799 799 } 800 800 801 - struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) 801 + struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) 802 802 { 803 - struct ring_buffer *rb; 803 + struct perf_buffer *rb; 804 804 unsigned long size; 805 805 int i; 806 806 807 - size = sizeof(struct ring_buffer); 807 + size = sizeof(struct perf_buffer); 808 808 size += nr_pages * sizeof(void *); 809 809 810 810 if (order_base_2(size) >= PAGE_SHIFT+MAX_ORDER) ··· 843 843 return NULL; 844 844 } 845 845 846 - void rb_free(struct ring_buffer *rb) 846 + void rb_free(struct perf_buffer *rb) 847 847 { 848 848 int i; 849 849 ··· 854 854 } 855 855 856 856 #else 857 - static int data_page_nr(struct ring_buffer *rb) 857 + static int data_page_nr(struct perf_buffer *rb) 858 858 { 859 859 return rb->nr_pages << page_order(rb); 860 860 } 861 861 862 862 static struct page * 863 - __perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff) 863 + __perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff) 864 864 { 865 865 /* The '>' counts in the user page. */ 866 866 if (pgoff > data_page_nr(rb)) ··· 878 878 879 879 static void rb_free_work(struct work_struct *work) 880 880 { 881 - struct ring_buffer *rb; 881 + struct perf_buffer *rb; 882 882 void *base; 883 883 int i, nr; 884 884 885 - rb = container_of(work, struct ring_buffer, work); 885 + rb = container_of(work, struct perf_buffer, work); 886 886 nr = data_page_nr(rb); 887 887 888 888 base = rb->user_page; ··· 894 894 kfree(rb); 895 895 } 896 896 897 - void rb_free(struct ring_buffer *rb) 897 + void rb_free(struct perf_buffer *rb) 898 898 { 899 899 schedule_work(&rb->work); 900 900 } 901 901 902 - struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) 902 + struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) 903 903 { 904 - struct ring_buffer *rb; 904 + struct perf_buffer *rb; 905 905 unsigned long size; 906 906 void *all_buf; 907 907 908 - size = sizeof(struct ring_buffer); 908 + size = sizeof(struct perf_buffer); 909 909 size += sizeof(void *); 910 910 911 911 rb = kzalloc(size, GFP_KERNEL); ··· 939 939 #endif 940 940 941 941 struct page * 942 - perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff) 942 + perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff) 943 943 { 944 944 if (rb->aux_nr_pages) { 945 945 /* above AUX space */
+201 -167
kernel/trace/Kconfig
··· 141 141 142 142 if FTRACE 143 143 144 + config BOOTTIME_TRACING 145 + bool "Boot-time Tracing support" 146 + depends on BOOT_CONFIG && TRACING 147 + default y 148 + help 149 + Enable developer to setup ftrace subsystem via supplemental 150 + kernel cmdline at boot time for debugging (tracing) driver 151 + initialization and boot process. 152 + 144 153 config FUNCTION_TRACER 145 154 bool "Kernel Function Tracer" 146 155 depends on HAVE_FUNCTION_TRACER ··· 180 171 draw a call graph for each thread with some information like 181 172 the return value. This is done by setting the current return 182 173 address on the current task structure into a stack of calls. 174 + 175 + config DYNAMIC_FTRACE 176 + bool "enable/disable function tracing dynamically" 177 + depends on FUNCTION_TRACER 178 + depends on HAVE_DYNAMIC_FTRACE 179 + default y 180 + help 181 + This option will modify all the calls to function tracing 182 + dynamically (will patch them out of the binary image and 183 + replace them with a No-Op instruction) on boot up. During 184 + compile time, a table is made of all the locations that ftrace 185 + can function trace, and this table is linked into the kernel 186 + image. When this is enabled, functions can be individually 187 + enabled, and the functions not enabled will not affect 188 + performance of the system. 189 + 190 + See the files in /sys/kernel/debug/tracing: 191 + available_filter_functions 192 + set_ftrace_filter 193 + set_ftrace_notrace 194 + 195 + This way a CONFIG_FUNCTION_TRACER kernel is slightly larger, but 196 + otherwise has native performance as long as no tracing is active. 197 + 198 + config DYNAMIC_FTRACE_WITH_REGS 199 + def_bool y 200 + depends on DYNAMIC_FTRACE 201 + depends on HAVE_DYNAMIC_FTRACE_WITH_REGS 202 + 203 + config DYNAMIC_FTRACE_WITH_DIRECT_CALLS 204 + def_bool y 205 + depends on DYNAMIC_FTRACE 206 + depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS 207 + 208 + config FUNCTION_PROFILER 209 + bool "Kernel function profiler" 210 + depends on FUNCTION_TRACER 211 + default n 212 + help 213 + This option enables the kernel function profiler. A file is created 214 + in debugfs called function_profile_enabled which defaults to zero. 215 + When a 1 is echoed into this file profiling begins, and when a 216 + zero is entered, profiling stops. A "functions" file is created in 217 + the trace_stat directory; this file shows the list of functions that 218 + have been hit and their counters. 219 + 220 + If in doubt, say N. 221 + 222 + config STACK_TRACER 223 + bool "Trace max stack" 224 + depends on HAVE_FUNCTION_TRACER 225 + select FUNCTION_TRACER 226 + select STACKTRACE 227 + select KALLSYMS 228 + help 229 + This special tracer records the maximum stack footprint of the 230 + kernel and displays it in /sys/kernel/debug/tracing/stack_trace. 231 + 232 + This tracer works by hooking into every function call that the 233 + kernel executes, and keeping a maximum stack depth value and 234 + stack-trace saved. If this is configured with DYNAMIC_FTRACE 235 + then it will not have any overhead while the stack tracer 236 + is disabled. 237 + 238 + To enable the stack tracer on bootup, pass in 'stacktrace' 239 + on the kernel command line. 240 + 241 + The stack tracer can also be enabled or disabled via the 242 + sysctl kernel.stack_tracer_enabled 243 + 244 + Say N if unsure. 183 245 184 246 config TRACE_PREEMPT_TOGGLE 185 247 bool ··· 361 281 To enable this tracer, echo in "hwlat" into the current_tracer 362 282 file. Every time a latency is greater than tracing_thresh, it will 363 283 be recorded into the ring buffer. 284 + 285 + config MMIOTRACE 286 + bool "Memory mapped IO tracing" 287 + depends on HAVE_MMIOTRACE_SUPPORT && PCI 288 + select GENERIC_TRACER 289 + help 290 + Mmiotrace traces Memory Mapped I/O access and is meant for 291 + debugging and reverse engineering. It is called from the ioremap 292 + implementation and works via page faults. Tracing is disabled by 293 + default and can be enabled at run-time. 294 + 295 + See Documentation/trace/mmiotrace.rst. 296 + If you are not helping to develop drivers, say N. 364 297 365 298 config ENABLE_DEFAULT_TRACERS 366 299 bool "Trace process context switches and events" ··· 503 410 504 411 Say N if unsure. 505 412 506 - config STACK_TRACER 507 - bool "Trace max stack" 508 - depends on HAVE_FUNCTION_TRACER 509 - select FUNCTION_TRACER 510 - select STACKTRACE 511 - select KALLSYMS 512 - help 513 - This special tracer records the maximum stack footprint of the 514 - kernel and displays it in /sys/kernel/debug/tracing/stack_trace. 515 - 516 - This tracer works by hooking into every function call that the 517 - kernel executes, and keeping a maximum stack depth value and 518 - stack-trace saved. If this is configured with DYNAMIC_FTRACE 519 - then it will not have any overhead while the stack tracer 520 - is disabled. 521 - 522 - To enable the stack tracer on bootup, pass in 'stacktrace' 523 - on the kernel command line. 524 - 525 - The stack tracer can also be enabled or disabled via the 526 - sysctl kernel.stack_tracer_enabled 527 - 528 - Say N if unsure. 529 - 530 413 config BLK_DEV_IO_TRACE 531 414 bool "Support for tracing block IO actions" 532 415 depends on SYSFS ··· 600 531 config PROBE_EVENTS 601 532 def_bool n 602 533 603 - config DYNAMIC_FTRACE 604 - bool "enable/disable function tracing dynamically" 605 - depends on FUNCTION_TRACER 606 - depends on HAVE_DYNAMIC_FTRACE 607 - default y 608 - help 609 - This option will modify all the calls to function tracing 610 - dynamically (will patch them out of the binary image and 611 - replace them with a No-Op instruction) on boot up. During 612 - compile time, a table is made of all the locations that ftrace 613 - can function trace, and this table is linked into the kernel 614 - image. When this is enabled, functions can be individually 615 - enabled, and the functions not enabled will not affect 616 - performance of the system. 617 - 618 - See the files in /sys/kernel/debug/tracing: 619 - available_filter_functions 620 - set_ftrace_filter 621 - set_ftrace_notrace 622 - 623 - This way a CONFIG_FUNCTION_TRACER kernel is slightly larger, but 624 - otherwise has native performance as long as no tracing is active. 625 - 626 - config DYNAMIC_FTRACE_WITH_REGS 627 - def_bool y 628 - depends on DYNAMIC_FTRACE 629 - depends on HAVE_DYNAMIC_FTRACE_WITH_REGS 630 - 631 - config DYNAMIC_FTRACE_WITH_DIRECT_CALLS 632 - def_bool y 633 - depends on DYNAMIC_FTRACE 634 - depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS 635 - 636 - config FUNCTION_PROFILER 637 - bool "Kernel function profiler" 638 - depends on FUNCTION_TRACER 639 - default n 640 - help 641 - This option enables the kernel function profiler. A file is created 642 - in debugfs called function_profile_enabled which defaults to zero. 643 - When a 1 is echoed into this file profiling begins, and when a 644 - zero is entered, profiling stops. A "functions" file is created in 645 - the trace_stat directory; this file shows the list of functions that 646 - have been hit and their counters. 647 - 648 - If in doubt, say N. 649 - 650 534 config BPF_KPROBE_OVERRIDE 651 535 bool "Enable BPF programs to override a kprobed function" 652 536 depends on BPF_EVENTS ··· 613 591 def_bool y 614 592 depends on DYNAMIC_FTRACE 615 593 depends on HAVE_FTRACE_MCOUNT_RECORD 616 - 617 - config FTRACE_SELFTEST 618 - bool 619 - 620 - config FTRACE_STARTUP_TEST 621 - bool "Perform a startup test on ftrace" 622 - depends on GENERIC_TRACER 623 - select FTRACE_SELFTEST 624 - help 625 - This option performs a series of startup tests on ftrace. On bootup 626 - a series of tests are made to verify that the tracer is 627 - functioning properly. It will do tests on all the configured 628 - tracers of ftrace. 629 - 630 - config EVENT_TRACE_STARTUP_TEST 631 - bool "Run selftest on trace events" 632 - depends on FTRACE_STARTUP_TEST 633 - default y 634 - help 635 - This option performs a test on all trace events in the system. 636 - It basically just enables each event and runs some code that 637 - will trigger events (not necessarily the event it enables) 638 - This may take some time run as there are a lot of events. 639 - 640 - config EVENT_TRACE_TEST_SYSCALLS 641 - bool "Run selftest on syscall events" 642 - depends on EVENT_TRACE_STARTUP_TEST 643 - help 644 - This option will also enable testing every syscall event. 645 - It only enables the event and disables it and runs various loads 646 - with the event enabled. This adds a bit more time for kernel boot 647 - up since it runs this on every system call defined. 648 - 649 - TBD - enable a way to actually call the syscalls as we test their 650 - events 651 - 652 - config MMIOTRACE 653 - bool "Memory mapped IO tracing" 654 - depends on HAVE_MMIOTRACE_SUPPORT && PCI 655 - select GENERIC_TRACER 656 - help 657 - Mmiotrace traces Memory Mapped I/O access and is meant for 658 - debugging and reverse engineering. It is called from the ioremap 659 - implementation and works via page faults. Tracing is disabled by 660 - default and can be enabled at run-time. 661 - 662 - See Documentation/trace/mmiotrace.rst. 663 - If you are not helping to develop drivers, say N. 664 594 665 595 config TRACING_MAP 666 596 bool ··· 653 679 buffer. This is mainly used for testing purpose. 654 680 655 681 If unsure, say N. 656 - 657 - config MMIOTRACE_TEST 658 - tristate "Test module for mmiotrace" 659 - depends on MMIOTRACE && m 660 - help 661 - This is a dumb module for testing mmiotrace. It is very dangerous 662 - as it will write garbage to IO memory starting at a given address. 663 - However, it should be safe to use on e.g. unused portion of VRAM. 664 - 665 - Say N, unless you absolutely know what you are doing. 666 682 667 683 config TRACEPOINT_BENCHMARK 668 684 bool "Add tracepoint that benchmarks tracepoints" ··· 700 736 701 737 If unsure, say N. 702 738 703 - config RING_BUFFER_STARTUP_TEST 704 - bool "Ring buffer startup self test" 705 - depends on RING_BUFFER 706 - help 707 - Run a simple self test on the ring buffer on boot up. Late in the 708 - kernel boot sequence, the test will start that kicks off 709 - a thread per cpu. Each thread will write various size events 710 - into the ring buffer. Another thread is created to send IPIs 711 - to each of the threads, where the IPI handler will also write 712 - to the ring buffer, to test/stress the nesting ability. 713 - If any anomalies are discovered, a warning will be displayed 714 - and all ring buffers will be disabled. 715 - 716 - The test runs for 10 seconds. This will slow your boot time 717 - by at least 10 more seconds. 718 - 719 - At the end of the test, statics and more checks are done. 720 - It will output the stats of each per cpu buffer. What 721 - was written, the sizes, what was read, what was lost, and 722 - other similar details. 723 - 724 - If unsure, say N 725 - 726 - config PREEMPTIRQ_DELAY_TEST 727 - tristate "Preempt / IRQ disable delay thread to test latency tracers" 728 - depends on m 729 - help 730 - Select this option to build a test module that can help test latency 731 - tracers by executing a preempt or irq disable section with a user 732 - configurable delay. The module busy waits for the duration of the 733 - critical section. 734 - 735 - For example, the following invocation generates a burst of three 736 - irq-disabled critical sections for 500us: 737 - modprobe preemptirq_delay_test test_mode=irq delay=500 burst_size=3 738 - 739 - If unsure, say N 740 - 741 739 config TRACE_EVAL_MAP_FILE 742 740 bool "Show eval mappings for trace events" 743 741 depends on TRACING ··· 739 813 740 814 Note that on a kernel compiled with this config, ftrace will 741 815 run significantly slower. 816 + 817 + config FTRACE_SELFTEST 818 + bool 819 + 820 + config FTRACE_STARTUP_TEST 821 + bool "Perform a startup test on ftrace" 822 + depends on GENERIC_TRACER 823 + select FTRACE_SELFTEST 824 + help 825 + This option performs a series of startup tests on ftrace. On bootup 826 + a series of tests are made to verify that the tracer is 827 + functioning properly. It will do tests on all the configured 828 + tracers of ftrace. 829 + 830 + config EVENT_TRACE_STARTUP_TEST 831 + bool "Run selftest on trace events" 832 + depends on FTRACE_STARTUP_TEST 833 + default y 834 + help 835 + This option performs a test on all trace events in the system. 836 + It basically just enables each event and runs some code that 837 + will trigger events (not necessarily the event it enables) 838 + This may take some time run as there are a lot of events. 839 + 840 + config EVENT_TRACE_TEST_SYSCALLS 841 + bool "Run selftest on syscall events" 842 + depends on EVENT_TRACE_STARTUP_TEST 843 + help 844 + This option will also enable testing every syscall event. 845 + It only enables the event and disables it and runs various loads 846 + with the event enabled. This adds a bit more time for kernel boot 847 + up since it runs this on every system call defined. 848 + 849 + TBD - enable a way to actually call the syscalls as we test their 850 + events 851 + 852 + config RING_BUFFER_STARTUP_TEST 853 + bool "Ring buffer startup self test" 854 + depends on RING_BUFFER 855 + help 856 + Run a simple self test on the ring buffer on boot up. Late in the 857 + kernel boot sequence, the test will start that kicks off 858 + a thread per cpu. Each thread will write various size events 859 + into the ring buffer. Another thread is created to send IPIs 860 + to each of the threads, where the IPI handler will also write 861 + to the ring buffer, to test/stress the nesting ability. 862 + If any anomalies are discovered, a warning will be displayed 863 + and all ring buffers will be disabled. 864 + 865 + The test runs for 10 seconds. This will slow your boot time 866 + by at least 10 more seconds. 867 + 868 + At the end of the test, statics and more checks are done. 869 + It will output the stats of each per cpu buffer. What 870 + was written, the sizes, what was read, what was lost, and 871 + other similar details. 872 + 873 + If unsure, say N 874 + 875 + config MMIOTRACE_TEST 876 + tristate "Test module for mmiotrace" 877 + depends on MMIOTRACE && m 878 + help 879 + This is a dumb module for testing mmiotrace. It is very dangerous 880 + as it will write garbage to IO memory starting at a given address. 881 + However, it should be safe to use on e.g. unused portion of VRAM. 882 + 883 + Say N, unless you absolutely know what you are doing. 884 + 885 + config PREEMPTIRQ_DELAY_TEST 886 + tristate "Test module to create a preempt / IRQ disable delay thread to test latency tracers" 887 + depends on m 888 + help 889 + Select this option to build a test module that can help test latency 890 + tracers by executing a preempt or irq disable section with a user 891 + configurable delay. The module busy waits for the duration of the 892 + critical section. 893 + 894 + For example, the following invocation generates a burst of three 895 + irq-disabled critical sections for 500us: 896 + modprobe preemptirq_delay_test test_mode=irq delay=500 burst_size=3 897 + 898 + If unsure, say N 899 + 900 + config SYNTH_EVENT_GEN_TEST 901 + tristate "Test module for in-kernel synthetic event generation" 902 + depends on HIST_TRIGGERS 903 + help 904 + This option creates a test module to check the base 905 + functionality of in-kernel synthetic event definition and 906 + generation. 907 + 908 + To test, insert the module, and then check the trace buffer 909 + for the generated sample events. 910 + 911 + If unsure, say N. 912 + 913 + config KPROBE_EVENT_GEN_TEST 914 + tristate "Test module for in-kernel kprobe event generation" 915 + depends on KPROBE_EVENTS 916 + help 917 + This option creates a test module to check the base 918 + functionality of in-kernel kprobe event definition. 919 + 920 + To test, insert the module, and then check the trace buffer 921 + for the generated kprobe events. 922 + 923 + If unsure, say N. 742 924 743 925 endif # FTRACE 744 926
+3
kernel/trace/Makefile
··· 44 44 obj-$(CONFIG_TRACING) += trace_printk.o 45 45 obj-$(CONFIG_TRACING_MAP) += tracing_map.o 46 46 obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o 47 + obj-$(CONFIG_SYNTH_EVENT_GEN_TEST) += synth_event_gen_test.o 48 + obj-$(CONFIG_KPROBE_EVENT_GEN_TEST) += kprobe_event_gen_test.o 47 49 obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o 48 50 obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o 49 51 obj-$(CONFIG_PREEMPTIRQ_TRACEPOINTS) += trace_preemptirq.o ··· 85 83 obj-$(CONFIG_DYNAMIC_EVENTS) += trace_dynevent.o 86 84 obj-$(CONFIG_PROBE_EVENTS) += trace_probe.o 87 85 obj-$(CONFIG_UPROBE_EVENTS) += trace_uprobe.o 86 + obj-$(CONFIG_BOOTTIME_TRACING) += trace_boot.o 88 87 89 88 obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o 90 89
+4 -4
kernel/trace/blktrace.c
··· 68 68 { 69 69 struct blk_io_trace *t; 70 70 struct ring_buffer_event *event = NULL; 71 - struct ring_buffer *buffer = NULL; 71 + struct trace_buffer *buffer = NULL; 72 72 int pc = 0; 73 73 int cpu = smp_processor_id(); 74 74 bool blk_tracer = blk_tracer_enabled; 75 75 ssize_t cgid_len = cgid ? sizeof(cgid) : 0; 76 76 77 77 if (blk_tracer) { 78 - buffer = blk_tr->trace_buffer.buffer; 78 + buffer = blk_tr->array_buffer.buffer; 79 79 pc = preempt_count(); 80 80 event = trace_buffer_lock_reserve(buffer, TRACE_BLK, 81 81 sizeof(*t) + len + cgid_len, ··· 215 215 { 216 216 struct task_struct *tsk = current; 217 217 struct ring_buffer_event *event = NULL; 218 - struct ring_buffer *buffer = NULL; 218 + struct trace_buffer *buffer = NULL; 219 219 struct blk_io_trace *t; 220 220 unsigned long flags = 0; 221 221 unsigned long *sequence; ··· 248 248 if (blk_tracer) { 249 249 tracing_record_cmdline(current); 250 250 251 - buffer = blk_tr->trace_buffer.buffer; 251 + buffer = blk_tr->array_buffer.buffer; 252 252 pc = preempt_count(); 253 253 event = trace_buffer_lock_reserve(buffer, TRACE_BLK, 254 254 sizeof(*t) + pdu_len + cgid_len,
+20 -17
kernel/trace/ftrace.c
··· 62 62 }) 63 63 64 64 /* hash bits for specific function selection */ 65 - #define FTRACE_HASH_BITS 7 66 - #define FTRACE_FUNC_HASHSIZE (1 << FTRACE_HASH_BITS) 67 65 #define FTRACE_HASH_DEFAULT_BITS 10 68 66 #define FTRACE_HASH_MAX_BITS 12 69 67 ··· 144 146 { 145 147 struct trace_array *tr = op->private; 146 148 147 - if (tr && this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid)) 149 + if (tr && this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid)) 148 150 return; 149 151 150 152 op->saved_func(ip, parent_ip, op, regs); ··· 1100 1102 1101 1103 #define ENTRY_SIZE sizeof(struct dyn_ftrace) 1102 1104 #define ENTRIES_PER_PAGE (PAGE_SIZE / ENTRY_SIZE) 1103 - 1104 - /* estimate from running different kernels */ 1105 - #define NR_TO_INIT 10000 1106 1105 1107 1106 static struct ftrace_page *ftrace_pages_start; 1108 1107 static struct ftrace_page *ftrace_pages; ··· 5459 5464 struct ftrace_hash *hash; 5460 5465 5461 5466 hash = alloc_ftrace_hash(FTRACE_HASH_DEFAULT_BITS); 5462 - if (WARN_ON(!hash)) 5467 + if (MEM_FAIL(!hash, "Failed to allocate hash\n")) 5463 5468 return; 5464 5469 5465 5470 while (buf) { ··· 5591 5596 5592 5597 static DEFINE_MUTEX(graph_lock); 5593 5598 5594 - struct ftrace_hash *ftrace_graph_hash = EMPTY_HASH; 5595 - struct ftrace_hash *ftrace_graph_notrace_hash = EMPTY_HASH; 5599 + struct ftrace_hash __rcu *ftrace_graph_hash = EMPTY_HASH; 5600 + struct ftrace_hash __rcu *ftrace_graph_notrace_hash = EMPTY_HASH; 5596 5601 5597 5602 enum graph_filter_type { 5598 5603 GRAPH_FILTER_NOTRACE = 0, ··· 5867 5872 5868 5873 mutex_unlock(&graph_lock); 5869 5874 5870 - /* Wait till all users are no longer using the old hash */ 5871 - synchronize_rcu(); 5875 + /* 5876 + * We need to do a hard force of sched synchronization. 5877 + * This is because we use preempt_disable() to do RCU, but 5878 + * the function tracers can be called where RCU is not watching 5879 + * (like before user_exit()). We can not rely on the RCU 5880 + * infrastructure to do the synchronization, thus we must do it 5881 + * ourselves. 5882 + */ 5883 + schedule_on_each_cpu(ftrace_sync); 5872 5884 5873 5885 free_ftrace_hash(old_hash); 5874 5886 } ··· 6598 6596 6599 6597 func = kmalloc(sizeof(*func), GFP_KERNEL); 6600 6598 if (!func) { 6601 - WARN_ONCE(1, "alloc failure, ftrace filter could be stale\n"); 6599 + MEM_FAIL(1, "alloc failure, ftrace filter could be stale\n"); 6602 6600 return; 6603 6601 } 6604 6602 ··· 6924 6922 6925 6923 pid_list = rcu_dereference_sched(tr->function_pids); 6926 6924 6927 - this_cpu_write(tr->trace_buffer.data->ftrace_ignore_pid, 6925 + this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, 6928 6926 trace_ignore_this_task(pid_list, next)); 6929 6927 } 6930 6928 ··· 6978 6976 unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr); 6979 6977 6980 6978 for_each_possible_cpu(cpu) 6981 - per_cpu_ptr(tr->trace_buffer.data, cpu)->ftrace_ignore_pid = false; 6979 + per_cpu_ptr(tr->array_buffer.data, cpu)->ftrace_ignore_pid = false; 6982 6980 6983 6981 rcu_assign_pointer(tr->function_pids, NULL); 6984 6982 ··· 7033 7031 struct trace_array *tr = m->private; 7034 7032 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_pids); 7035 7033 7036 - if (v == FTRACE_NO_PIDS) 7034 + if (v == FTRACE_NO_PIDS) { 7035 + (*pos)++; 7037 7036 return NULL; 7038 - 7037 + } 7039 7038 return trace_pid_next(pid_list, v, pos); 7040 7039 } 7041 7040 ··· 7103 7100 pid_list = rcu_dereference_protected(tr->function_pids, 7104 7101 mutex_is_locked(&ftrace_lock)); 7105 7102 7106 - this_cpu_write(tr->trace_buffer.data->ftrace_ignore_pid, 7103 + this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, 7107 7104 trace_ignore_this_task(pid_list, current)); 7108 7105 } 7109 7106
+225
kernel/trace/kprobe_event_gen_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Test module for in-kernel kprobe event creation and generation. 4 + * 5 + * Copyright (C) 2019 Tom Zanussi <zanussi@kernel.org> 6 + */ 7 + 8 + #include <linux/module.h> 9 + #include <linux/trace_events.h> 10 + 11 + /* 12 + * This module is a simple test of basic functionality for in-kernel 13 + * kprobe/kretprobe event creation. The first test uses 14 + * kprobe_event_gen_cmd_start(), kprobe_event_add_fields() and 15 + * kprobe_event_gen_cmd_end() to create a kprobe event, which is then 16 + * enabled in order to generate trace output. The second creates a 17 + * kretprobe event using kretprobe_event_gen_cmd_start() and 18 + * kretprobe_event_gen_cmd_end(), and is also then enabled. 19 + * 20 + * To test, select CONFIG_KPROBE_EVENT_GEN_TEST and build the module. 21 + * Then: 22 + * 23 + * # insmod kernel/trace/kprobe_event_gen_test.ko 24 + * # cat /sys/kernel/debug/tracing/trace 25 + * 26 + * You should see many instances of the "gen_kprobe_test" and 27 + * "gen_kretprobe_test" events in the trace buffer. 28 + * 29 + * To remove the events, remove the module: 30 + * 31 + * # rmmod kprobe_event_gen_test 32 + * 33 + */ 34 + 35 + static struct trace_event_file *gen_kprobe_test; 36 + static struct trace_event_file *gen_kretprobe_test; 37 + 38 + /* 39 + * Test to make sure we can create a kprobe event, then add more 40 + * fields. 41 + */ 42 + static int __init test_gen_kprobe_cmd(void) 43 + { 44 + struct dynevent_cmd cmd; 45 + char *buf; 46 + int ret; 47 + 48 + /* Create a buffer to hold the generated command */ 49 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 50 + if (!buf) 51 + return -ENOMEM; 52 + 53 + /* Before generating the command, initialize the cmd object */ 54 + kprobe_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 55 + 56 + /* 57 + * Define the gen_kprobe_test event with the first 2 kprobe 58 + * fields. 59 + */ 60 + ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test", 61 + "do_sys_open", 62 + "dfd=%ax", "filename=%dx"); 63 + if (ret) 64 + goto free; 65 + 66 + /* Use kprobe_event_add_fields to add the rest of the fields */ 67 + 68 + ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)"); 69 + if (ret) 70 + goto free; 71 + 72 + /* 73 + * This actually creates the event. 74 + */ 75 + ret = kprobe_event_gen_cmd_end(&cmd); 76 + if (ret) 77 + goto free; 78 + 79 + /* 80 + * Now get the gen_kprobe_test event file. We need to prevent 81 + * the instance and event from disappearing from underneath 82 + * us, which trace_get_event_file() does (though in this case 83 + * we're using the top-level instance which never goes away). 84 + */ 85 + gen_kprobe_test = trace_get_event_file(NULL, "kprobes", 86 + "gen_kprobe_test"); 87 + if (IS_ERR(gen_kprobe_test)) { 88 + ret = PTR_ERR(gen_kprobe_test); 89 + goto delete; 90 + } 91 + 92 + /* Enable the event or you won't see anything */ 93 + ret = trace_array_set_clr_event(gen_kprobe_test->tr, 94 + "kprobes", "gen_kprobe_test", true); 95 + if (ret) { 96 + trace_put_event_file(gen_kprobe_test); 97 + goto delete; 98 + } 99 + out: 100 + return ret; 101 + delete: 102 + /* We got an error after creating the event, delete it */ 103 + ret = kprobe_event_delete("gen_kprobe_test"); 104 + free: 105 + kfree(buf); 106 + 107 + goto out; 108 + } 109 + 110 + /* 111 + * Test to make sure we can create a kretprobe event. 112 + */ 113 + static int __init test_gen_kretprobe_cmd(void) 114 + { 115 + struct dynevent_cmd cmd; 116 + char *buf; 117 + int ret; 118 + 119 + /* Create a buffer to hold the generated command */ 120 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 121 + if (!buf) 122 + return -ENOMEM; 123 + 124 + /* Before generating the command, initialize the cmd object */ 125 + kprobe_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 126 + 127 + /* 128 + * Define the kretprobe event. 129 + */ 130 + ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test", 131 + "do_sys_open", 132 + "$retval"); 133 + if (ret) 134 + goto free; 135 + 136 + /* 137 + * This actually creates the event. 138 + */ 139 + ret = kretprobe_event_gen_cmd_end(&cmd); 140 + if (ret) 141 + goto free; 142 + 143 + /* 144 + * Now get the gen_kretprobe_test event file. We need to 145 + * prevent the instance and event from disappearing from 146 + * underneath us, which trace_get_event_file() does (though in 147 + * this case we're using the top-level instance which never 148 + * goes away). 149 + */ 150 + gen_kretprobe_test = trace_get_event_file(NULL, "kprobes", 151 + "gen_kretprobe_test"); 152 + if (IS_ERR(gen_kretprobe_test)) { 153 + ret = PTR_ERR(gen_kretprobe_test); 154 + goto delete; 155 + } 156 + 157 + /* Enable the event or you won't see anything */ 158 + ret = trace_array_set_clr_event(gen_kretprobe_test->tr, 159 + "kprobes", "gen_kretprobe_test", true); 160 + if (ret) { 161 + trace_put_event_file(gen_kretprobe_test); 162 + goto delete; 163 + } 164 + out: 165 + return ret; 166 + delete: 167 + /* We got an error after creating the event, delete it */ 168 + ret = kprobe_event_delete("gen_kretprobe_test"); 169 + free: 170 + kfree(buf); 171 + 172 + goto out; 173 + } 174 + 175 + static int __init kprobe_event_gen_test_init(void) 176 + { 177 + int ret; 178 + 179 + ret = test_gen_kprobe_cmd(); 180 + if (ret) 181 + return ret; 182 + 183 + ret = test_gen_kretprobe_cmd(); 184 + if (ret) { 185 + WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr, 186 + "kprobes", 187 + "gen_kretprobe_test", false)); 188 + trace_put_event_file(gen_kretprobe_test); 189 + WARN_ON(kprobe_event_delete("gen_kretprobe_test")); 190 + } 191 + 192 + return ret; 193 + } 194 + 195 + static void __exit kprobe_event_gen_test_exit(void) 196 + { 197 + /* Disable the event or you can't remove it */ 198 + WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr, 199 + "kprobes", 200 + "gen_kprobe_test", false)); 201 + 202 + /* Now give the file and instance back */ 203 + trace_put_event_file(gen_kprobe_test); 204 + 205 + /* Now unregister and free the event */ 206 + WARN_ON(kprobe_event_delete("gen_kprobe_test")); 207 + 208 + /* Disable the event or you can't remove it */ 209 + WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr, 210 + "kprobes", 211 + "gen_kretprobe_test", false)); 212 + 213 + /* Now give the file and instance back */ 214 + trace_put_event_file(gen_kretprobe_test); 215 + 216 + /* Now unregister and free the event */ 217 + WARN_ON(kprobe_event_delete("gen_kretprobe_test")); 218 + } 219 + 220 + module_init(kprobe_event_gen_test_init) 221 + module_exit(kprobe_event_gen_test_exit) 222 + 223 + MODULE_AUTHOR("Tom Zanussi"); 224 + MODULE_DESCRIPTION("kprobe event generation test"); 225 + MODULE_LICENSE("GPL v2");
+68 -67
kernel/trace/ring_buffer.c
··· 300 300 /* Missed count stored at end */ 301 301 #define RB_MISSED_STORED (1 << 30) 302 302 303 - #define RB_MISSED_FLAGS (RB_MISSED_EVENTS|RB_MISSED_STORED) 304 - 305 303 struct buffer_data_page { 306 304 u64 time_stamp; /* page time stamp */ 307 305 local_t commit; /* write committed index */ ··· 441 443 struct ring_buffer_per_cpu { 442 444 int cpu; 443 445 atomic_t record_disabled; 444 - struct ring_buffer *buffer; 446 + struct trace_buffer *buffer; 445 447 raw_spinlock_t reader_lock; /* serialize readers */ 446 448 arch_spinlock_t lock; 447 449 struct lock_class_key lock_key; ··· 480 482 struct rb_irq_work irq_work; 481 483 }; 482 484 483 - struct ring_buffer { 485 + struct trace_buffer { 484 486 unsigned flags; 485 487 int cpus; 486 488 atomic_t record_disabled; ··· 516 518 * 517 519 * Returns the number of pages used by a per_cpu buffer of the ring buffer. 518 520 */ 519 - size_t ring_buffer_nr_pages(struct ring_buffer *buffer, int cpu) 521 + size_t ring_buffer_nr_pages(struct trace_buffer *buffer, int cpu) 520 522 { 521 523 return buffer->buffers[cpu]->nr_pages; 522 524 } ··· 528 530 * 529 531 * Returns the number of pages that have content in the ring buffer. 530 532 */ 531 - size_t ring_buffer_nr_dirty_pages(struct ring_buffer *buffer, int cpu) 533 + size_t ring_buffer_nr_dirty_pages(struct trace_buffer *buffer, int cpu) 532 534 { 533 535 size_t read; 534 536 size_t cnt; ··· 571 573 * as data is added to any of the @buffer's cpu buffers. Otherwise 572 574 * it will wait for data to be added to a specific cpu buffer. 573 575 */ 574 - int ring_buffer_wait(struct ring_buffer *buffer, int cpu, int full) 576 + int ring_buffer_wait(struct trace_buffer *buffer, int cpu, int full) 575 577 { 576 578 struct ring_buffer_per_cpu *uninitialized_var(cpu_buffer); 577 579 DEFINE_WAIT(wait); ··· 682 684 * Returns EPOLLIN | EPOLLRDNORM if data exists in the buffers, 683 685 * zero otherwise. 684 686 */ 685 - __poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu, 687 + __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu, 686 688 struct file *filp, poll_table *poll_table) 687 689 { 688 690 struct ring_buffer_per_cpu *cpu_buffer; ··· 740 742 /* Up this if you want to test the TIME_EXTENTS and normalization */ 741 743 #define DEBUG_SHIFT 0 742 744 743 - static inline u64 rb_time_stamp(struct ring_buffer *buffer) 745 + static inline u64 rb_time_stamp(struct trace_buffer *buffer) 744 746 { 745 747 /* shift to debug/test normalization and TIME_EXTENTS */ 746 748 return buffer->clock() << DEBUG_SHIFT; 747 749 } 748 750 749 - u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu) 751 + u64 ring_buffer_time_stamp(struct trace_buffer *buffer, int cpu) 750 752 { 751 753 u64 time; 752 754 ··· 758 760 } 759 761 EXPORT_SYMBOL_GPL(ring_buffer_time_stamp); 760 762 761 - void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer, 763 + void ring_buffer_normalize_time_stamp(struct trace_buffer *buffer, 762 764 int cpu, u64 *ts) 763 765 { 764 766 /* Just stupid testing the normalize function and deltas */ ··· 1281 1283 } 1282 1284 1283 1285 static struct ring_buffer_per_cpu * 1284 - rb_allocate_cpu_buffer(struct ring_buffer *buffer, long nr_pages, int cpu) 1286 + rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu) 1285 1287 { 1286 1288 struct ring_buffer_per_cpu *cpu_buffer; 1287 1289 struct buffer_page *bpage; ··· 1366 1368 * __ring_buffer_alloc - allocate a new ring_buffer 1367 1369 * @size: the size in bytes per cpu that is needed. 1368 1370 * @flags: attributes to set for the ring buffer. 1371 + * @key: ring buffer reader_lock_key. 1369 1372 * 1370 1373 * Currently the only flag that is available is the RB_FL_OVERWRITE 1371 1374 * flag. This flag means that the buffer will overwrite old data 1372 1375 * when the buffer wraps. If this flag is not set, the buffer will 1373 1376 * drop data when the tail hits the head. 1374 1377 */ 1375 - struct ring_buffer *__ring_buffer_alloc(unsigned long size, unsigned flags, 1378 + struct trace_buffer *__ring_buffer_alloc(unsigned long size, unsigned flags, 1376 1379 struct lock_class_key *key) 1377 1380 { 1378 - struct ring_buffer *buffer; 1381 + struct trace_buffer *buffer; 1379 1382 long nr_pages; 1380 1383 int bsize; 1381 1384 int cpu; ··· 1446 1447 * @buffer: the buffer to free. 1447 1448 */ 1448 1449 void 1449 - ring_buffer_free(struct ring_buffer *buffer) 1450 + ring_buffer_free(struct trace_buffer *buffer) 1450 1451 { 1451 1452 int cpu; 1452 1453 ··· 1462 1463 } 1463 1464 EXPORT_SYMBOL_GPL(ring_buffer_free); 1464 1465 1465 - void ring_buffer_set_clock(struct ring_buffer *buffer, 1466 + void ring_buffer_set_clock(struct trace_buffer *buffer, 1466 1467 u64 (*clock)(void)) 1467 1468 { 1468 1469 buffer->clock = clock; 1469 1470 } 1470 1471 1471 - void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs) 1472 + void ring_buffer_set_time_stamp_abs(struct trace_buffer *buffer, bool abs) 1472 1473 { 1473 1474 buffer->time_stamp_abs = abs; 1474 1475 } 1475 1476 1476 - bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer) 1477 + bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer) 1477 1478 { 1478 1479 return buffer->time_stamp_abs; 1479 1480 } ··· 1711 1712 * 1712 1713 * Returns 0 on success and < 0 on failure. 1713 1714 */ 1714 - int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size, 1715 + int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, 1715 1716 int cpu_id) 1716 1717 { 1717 1718 struct ring_buffer_per_cpu *cpu_buffer; ··· 1890 1891 } 1891 1892 EXPORT_SYMBOL_GPL(ring_buffer_resize); 1892 1893 1893 - void ring_buffer_change_overwrite(struct ring_buffer *buffer, int val) 1894 + void ring_buffer_change_overwrite(struct trace_buffer *buffer, int val) 1894 1895 { 1895 1896 mutex_lock(&buffer->mutex); 1896 1897 if (val) ··· 2205 2206 { 2206 2207 struct buffer_page *tail_page = info->tail_page; 2207 2208 struct buffer_page *commit_page = cpu_buffer->commit_page; 2208 - struct ring_buffer *buffer = cpu_buffer->buffer; 2209 + struct trace_buffer *buffer = cpu_buffer->buffer; 2209 2210 struct buffer_page *next_page; 2210 2211 int ret; 2211 2212 ··· 2329 2330 2330 2331 /** 2331 2332 * rb_update_event - update event type and data 2333 + * @cpu_buffer: The per cpu buffer of the @event 2332 2334 * @event: the event to update 2333 - * @type: the type of event 2334 - * @length: the size of the event field in the ring buffer 2335 + * @info: The info to update the @event with (contains length and delta) 2335 2336 * 2336 - * Update the type and data fields of the event. The length 2337 + * Update the type and data fields of the @event. The length 2337 2338 * is the actual size that is written to the ring buffer, 2338 2339 * and with this, we can determine what to place into the 2339 2340 * data field. ··· 2608 2609 } 2609 2610 2610 2611 static __always_inline void 2611 - rb_wakeups(struct ring_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer) 2612 + rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer) 2612 2613 { 2613 2614 size_t nr_pages; 2614 2615 size_t dirty; ··· 2732 2733 * Call this function before calling another ring_buffer_lock_reserve() and 2733 2734 * call ring_buffer_nest_end() after the nested ring_buffer_unlock_commit(). 2734 2735 */ 2735 - void ring_buffer_nest_start(struct ring_buffer *buffer) 2736 + void ring_buffer_nest_start(struct trace_buffer *buffer) 2736 2737 { 2737 2738 struct ring_buffer_per_cpu *cpu_buffer; 2738 2739 int cpu; ··· 2752 2753 * Must be called after ring_buffer_nest_start() and after the 2753 2754 * ring_buffer_unlock_commit(). 2754 2755 */ 2755 - void ring_buffer_nest_end(struct ring_buffer *buffer) 2756 + void ring_buffer_nest_end(struct trace_buffer *buffer) 2756 2757 { 2757 2758 struct ring_buffer_per_cpu *cpu_buffer; 2758 2759 int cpu; ··· 2774 2775 * 2775 2776 * Must be paired with ring_buffer_lock_reserve. 2776 2777 */ 2777 - int ring_buffer_unlock_commit(struct ring_buffer *buffer, 2778 + int ring_buffer_unlock_commit(struct trace_buffer *buffer, 2778 2779 struct ring_buffer_event *event) 2779 2780 { 2780 2781 struct ring_buffer_per_cpu *cpu_buffer; ··· 2867 2868 } 2868 2869 2869 2870 static __always_inline struct ring_buffer_event * 2870 - rb_reserve_next_event(struct ring_buffer *buffer, 2871 + rb_reserve_next_event(struct trace_buffer *buffer, 2871 2872 struct ring_buffer_per_cpu *cpu_buffer, 2872 2873 unsigned long length) 2873 2874 { ··· 2960 2961 * If NULL is returned, then nothing has been allocated or locked. 2961 2962 */ 2962 2963 struct ring_buffer_event * 2963 - ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length) 2964 + ring_buffer_lock_reserve(struct trace_buffer *buffer, unsigned long length) 2964 2965 { 2965 2966 struct ring_buffer_per_cpu *cpu_buffer; 2966 2967 struct ring_buffer_event *event; ··· 3061 3062 * If this function is called, do not call ring_buffer_unlock_commit on 3062 3063 * the event. 3063 3064 */ 3064 - void ring_buffer_discard_commit(struct ring_buffer *buffer, 3065 + void ring_buffer_discard_commit(struct trace_buffer *buffer, 3065 3066 struct ring_buffer_event *event) 3066 3067 { 3067 3068 struct ring_buffer_per_cpu *cpu_buffer; ··· 3112 3113 * Note, like ring_buffer_lock_reserve, the length is the length of the data 3113 3114 * and not the length of the event which would hold the header. 3114 3115 */ 3115 - int ring_buffer_write(struct ring_buffer *buffer, 3116 + int ring_buffer_write(struct trace_buffer *buffer, 3116 3117 unsigned long length, 3117 3118 void *data) 3118 3119 { ··· 3192 3193 * 3193 3194 * The caller should call synchronize_rcu() after this. 3194 3195 */ 3195 - void ring_buffer_record_disable(struct ring_buffer *buffer) 3196 + void ring_buffer_record_disable(struct trace_buffer *buffer) 3196 3197 { 3197 3198 atomic_inc(&buffer->record_disabled); 3198 3199 } ··· 3205 3206 * Note, multiple disables will need the same number of enables 3206 3207 * to truly enable the writing (much like preempt_disable). 3207 3208 */ 3208 - void ring_buffer_record_enable(struct ring_buffer *buffer) 3209 + void ring_buffer_record_enable(struct trace_buffer *buffer) 3209 3210 { 3210 3211 atomic_dec(&buffer->record_disabled); 3211 3212 } ··· 3222 3223 * it works like an on/off switch, where as the disable() version 3223 3224 * must be paired with a enable(). 3224 3225 */ 3225 - void ring_buffer_record_off(struct ring_buffer *buffer) 3226 + void ring_buffer_record_off(struct trace_buffer *buffer) 3226 3227 { 3227 3228 unsigned int rd; 3228 3229 unsigned int new_rd; ··· 3245 3246 * it works like an on/off switch, where as the enable() version 3246 3247 * must be paired with a disable(). 3247 3248 */ 3248 - void ring_buffer_record_on(struct ring_buffer *buffer) 3249 + void ring_buffer_record_on(struct trace_buffer *buffer) 3249 3250 { 3250 3251 unsigned int rd; 3251 3252 unsigned int new_rd; ··· 3263 3264 * 3264 3265 * Returns true if the ring buffer is in a state that it accepts writes. 3265 3266 */ 3266 - bool ring_buffer_record_is_on(struct ring_buffer *buffer) 3267 + bool ring_buffer_record_is_on(struct trace_buffer *buffer) 3267 3268 { 3268 3269 return !atomic_read(&buffer->record_disabled); 3269 3270 } ··· 3279 3280 * ring_buffer_record_disable(), as that is a temporary disabling of 3280 3281 * the ring buffer. 3281 3282 */ 3282 - bool ring_buffer_record_is_set_on(struct ring_buffer *buffer) 3283 + bool ring_buffer_record_is_set_on(struct trace_buffer *buffer) 3283 3284 { 3284 3285 return !(atomic_read(&buffer->record_disabled) & RB_BUFFER_OFF); 3285 3286 } ··· 3294 3295 * 3295 3296 * The caller should call synchronize_rcu() after this. 3296 3297 */ 3297 - void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu) 3298 + void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu) 3298 3299 { 3299 3300 struct ring_buffer_per_cpu *cpu_buffer; 3300 3301 ··· 3314 3315 * Note, multiple disables will need the same number of enables 3315 3316 * to truly enable the writing (much like preempt_disable). 3316 3317 */ 3317 - void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu) 3318 + void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu) 3318 3319 { 3319 3320 struct ring_buffer_per_cpu *cpu_buffer; 3320 3321 ··· 3344 3345 * @buffer: The ring buffer 3345 3346 * @cpu: The per CPU buffer to read from. 3346 3347 */ 3347 - u64 ring_buffer_oldest_event_ts(struct ring_buffer *buffer, int cpu) 3348 + u64 ring_buffer_oldest_event_ts(struct trace_buffer *buffer, int cpu) 3348 3349 { 3349 3350 unsigned long flags; 3350 3351 struct ring_buffer_per_cpu *cpu_buffer; ··· 3377 3378 * @buffer: The ring buffer 3378 3379 * @cpu: The per CPU buffer to read from. 3379 3380 */ 3380 - unsigned long ring_buffer_bytes_cpu(struct ring_buffer *buffer, int cpu) 3381 + unsigned long ring_buffer_bytes_cpu(struct trace_buffer *buffer, int cpu) 3381 3382 { 3382 3383 struct ring_buffer_per_cpu *cpu_buffer; 3383 3384 unsigned long ret; ··· 3397 3398 * @buffer: The ring buffer 3398 3399 * @cpu: The per CPU buffer to get the entries from. 3399 3400 */ 3400 - unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu) 3401 + unsigned long ring_buffer_entries_cpu(struct trace_buffer *buffer, int cpu) 3401 3402 { 3402 3403 struct ring_buffer_per_cpu *cpu_buffer; 3403 3404 ··· 3416 3417 * @buffer: The ring buffer 3417 3418 * @cpu: The per CPU buffer to get the number of overruns from 3418 3419 */ 3419 - unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu) 3420 + unsigned long ring_buffer_overrun_cpu(struct trace_buffer *buffer, int cpu) 3420 3421 { 3421 3422 struct ring_buffer_per_cpu *cpu_buffer; 3422 3423 unsigned long ret; ··· 3439 3440 * @cpu: The per CPU buffer to get the number of overruns from 3440 3441 */ 3441 3442 unsigned long 3442 - ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu) 3443 + ring_buffer_commit_overrun_cpu(struct trace_buffer *buffer, int cpu) 3443 3444 { 3444 3445 struct ring_buffer_per_cpu *cpu_buffer; 3445 3446 unsigned long ret; ··· 3461 3462 * @cpu: The per CPU buffer to get the number of overruns from 3462 3463 */ 3463 3464 unsigned long 3464 - ring_buffer_dropped_events_cpu(struct ring_buffer *buffer, int cpu) 3465 + ring_buffer_dropped_events_cpu(struct trace_buffer *buffer, int cpu) 3465 3466 { 3466 3467 struct ring_buffer_per_cpu *cpu_buffer; 3467 3468 unsigned long ret; ··· 3482 3483 * @cpu: The per CPU buffer to get the number of events read 3483 3484 */ 3484 3485 unsigned long 3485 - ring_buffer_read_events_cpu(struct ring_buffer *buffer, int cpu) 3486 + ring_buffer_read_events_cpu(struct trace_buffer *buffer, int cpu) 3486 3487 { 3487 3488 struct ring_buffer_per_cpu *cpu_buffer; 3488 3489 ··· 3501 3502 * Returns the total number of entries in the ring buffer 3502 3503 * (all CPU entries) 3503 3504 */ 3504 - unsigned long ring_buffer_entries(struct ring_buffer *buffer) 3505 + unsigned long ring_buffer_entries(struct trace_buffer *buffer) 3505 3506 { 3506 3507 struct ring_buffer_per_cpu *cpu_buffer; 3507 3508 unsigned long entries = 0; ··· 3524 3525 * Returns the total number of overruns in the ring buffer 3525 3526 * (all CPU entries) 3526 3527 */ 3527 - unsigned long ring_buffer_overruns(struct ring_buffer *buffer) 3528 + unsigned long ring_buffer_overruns(struct trace_buffer *buffer) 3528 3529 { 3529 3530 struct ring_buffer_per_cpu *cpu_buffer; 3530 3531 unsigned long overruns = 0; ··· 3948 3949 static struct ring_buffer_event * 3949 3950 rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts) 3950 3951 { 3951 - struct ring_buffer *buffer; 3952 + struct trace_buffer *buffer; 3952 3953 struct ring_buffer_per_cpu *cpu_buffer; 3953 3954 struct ring_buffer_event *event; 3954 3955 int nr_loops = 0; ··· 4076 4077 * not consume the data. 4077 4078 */ 4078 4079 struct ring_buffer_event * 4079 - ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts, 4080 + ring_buffer_peek(struct trace_buffer *buffer, int cpu, u64 *ts, 4080 4081 unsigned long *lost_events) 4081 4082 { 4082 4083 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; ··· 4140 4141 * and eventually empty the ring buffer if the producer is slower. 4141 4142 */ 4142 4143 struct ring_buffer_event * 4143 - ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts, 4144 + ring_buffer_consume(struct trace_buffer *buffer, int cpu, u64 *ts, 4144 4145 unsigned long *lost_events) 4145 4146 { 4146 4147 struct ring_buffer_per_cpu *cpu_buffer; ··· 4200 4201 * This overall must be paired with ring_buffer_read_finish. 4201 4202 */ 4202 4203 struct ring_buffer_iter * 4203 - ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags) 4204 + ring_buffer_read_prepare(struct trace_buffer *buffer, int cpu, gfp_t flags) 4204 4205 { 4205 4206 struct ring_buffer_per_cpu *cpu_buffer; 4206 4207 struct ring_buffer_iter *iter; ··· 4330 4331 /** 4331 4332 * ring_buffer_size - return the size of the ring buffer (in bytes) 4332 4333 * @buffer: The ring buffer. 4334 + * @cpu: The CPU to get ring buffer size from. 4333 4335 */ 4334 - unsigned long ring_buffer_size(struct ring_buffer *buffer, int cpu) 4336 + unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu) 4335 4337 { 4336 4338 /* 4337 4339 * Earlier, this method returned ··· 4398 4398 * @buffer: The ring buffer to reset a per cpu buffer of 4399 4399 * @cpu: The CPU buffer to be reset 4400 4400 */ 4401 - void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu) 4401 + void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu) 4402 4402 { 4403 4403 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; 4404 4404 unsigned long flags; ··· 4435 4435 * ring_buffer_reset - reset a ring buffer 4436 4436 * @buffer: The ring buffer to reset all cpu buffers 4437 4437 */ 4438 - void ring_buffer_reset(struct ring_buffer *buffer) 4438 + void ring_buffer_reset(struct trace_buffer *buffer) 4439 4439 { 4440 4440 int cpu; 4441 4441 ··· 4448 4448 * rind_buffer_empty - is the ring buffer empty? 4449 4449 * @buffer: The ring buffer to test 4450 4450 */ 4451 - bool ring_buffer_empty(struct ring_buffer *buffer) 4451 + bool ring_buffer_empty(struct trace_buffer *buffer) 4452 4452 { 4453 4453 struct ring_buffer_per_cpu *cpu_buffer; 4454 4454 unsigned long flags; ··· 4478 4478 * @buffer: The ring buffer 4479 4479 * @cpu: The CPU buffer to test 4480 4480 */ 4481 - bool ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) 4481 + bool ring_buffer_empty_cpu(struct trace_buffer *buffer, int cpu) 4482 4482 { 4483 4483 struct ring_buffer_per_cpu *cpu_buffer; 4484 4484 unsigned long flags; ··· 4504 4504 * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers 4505 4505 * @buffer_a: One buffer to swap with 4506 4506 * @buffer_b: The other buffer to swap with 4507 + * @cpu: the CPU of the buffers to swap 4507 4508 * 4508 4509 * This function is useful for tracers that want to take a "snapshot" 4509 4510 * of a CPU buffer and has another back up buffer lying around. 4510 4511 * it is expected that the tracer handles the cpu buffer not being 4511 4512 * used at the moment. 4512 4513 */ 4513 - int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, 4514 - struct ring_buffer *buffer_b, int cpu) 4514 + int ring_buffer_swap_cpu(struct trace_buffer *buffer_a, 4515 + struct trace_buffer *buffer_b, int cpu) 4515 4516 { 4516 4517 struct ring_buffer_per_cpu *cpu_buffer_a; 4517 4518 struct ring_buffer_per_cpu *cpu_buffer_b; ··· 4591 4590 * Returns: 4592 4591 * The page allocated, or ERR_PTR 4593 4592 */ 4594 - void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu) 4593 + void *ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu) 4595 4594 { 4596 4595 struct ring_buffer_per_cpu *cpu_buffer; 4597 4596 struct buffer_data_page *bpage = NULL; ··· 4638 4637 * 4639 4638 * Free a page allocated from ring_buffer_alloc_read_page. 4640 4639 */ 4641 - void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data) 4640 + void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu, void *data) 4642 4641 { 4643 4642 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; 4644 4643 struct buffer_data_page *bpage = data; ··· 4698 4697 * >=0 if data has been transferred, returns the offset of consumed data. 4699 4698 * <0 if no data has been transferred. 4700 4699 */ 4701 - int ring_buffer_read_page(struct ring_buffer *buffer, 4700 + int ring_buffer_read_page(struct trace_buffer *buffer, 4702 4701 void **data_page, size_t len, int cpu, int full) 4703 4702 { 4704 4703 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; ··· 4869 4868 */ 4870 4869 int trace_rb_cpu_prepare(unsigned int cpu, struct hlist_node *node) 4871 4870 { 4872 - struct ring_buffer *buffer; 4871 + struct trace_buffer *buffer; 4873 4872 long nr_pages_same; 4874 4873 int cpu_i; 4875 4874 unsigned long nr_pages; 4876 4875 4877 - buffer = container_of(node, struct ring_buffer, node); 4876 + buffer = container_of(node, struct trace_buffer, node); 4878 4877 if (cpumask_test_cpu(cpu, buffer->cpumask)) 4879 4878 return 0; 4880 4879 ··· 4924 4923 static struct task_struct *rb_threads[NR_CPUS] __initdata; 4925 4924 4926 4925 struct rb_test_data { 4927 - struct ring_buffer *buffer; 4926 + struct trace_buffer *buffer; 4928 4927 unsigned long events; 4929 4928 unsigned long bytes_written; 4930 4929 unsigned long bytes_alloc; ··· 5066 5065 static __init int test_ringbuffer(void) 5067 5066 { 5068 5067 struct task_struct *rb_hammer; 5069 - struct ring_buffer *buffer; 5068 + struct trace_buffer *buffer; 5070 5069 int cpu; 5071 5070 int ret = 0; 5072 5071
+1 -1
kernel/trace/ring_buffer_benchmark.c
··· 29 29 static DECLARE_COMPLETION(read_start); 30 30 static DECLARE_COMPLETION(read_done); 31 31 32 - static struct ring_buffer *buffer; 32 + static struct trace_buffer *buffer; 33 33 static struct task_struct *producer; 34 34 static struct task_struct *consumer; 35 35 static unsigned long read;
+523
kernel/trace/synth_event_gen_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Test module for in-kernel sythetic event creation and generation. 4 + * 5 + * Copyright (C) 2019 Tom Zanussi <zanussi@kernel.org> 6 + */ 7 + 8 + #include <linux/module.h> 9 + #include <linux/trace_events.h> 10 + 11 + /* 12 + * This module is a simple test of basic functionality for in-kernel 13 + * synthetic event creation and generation, the first and second tests 14 + * using synth_event_gen_cmd_start() and synth_event_add_field(), the 15 + * third uses synth_event_create() to do it all at once with a static 16 + * field array. 17 + * 18 + * Following that are a few examples using the created events to test 19 + * various ways of tracing a synthetic event. 20 + * 21 + * To test, select CONFIG_SYNTH_EVENT_GEN_TEST and build the module. 22 + * Then: 23 + * 24 + * # insmod kernel/trace/synth_event_gen_test.ko 25 + * # cat /sys/kernel/debug/tracing/trace 26 + * 27 + * You should see several events in the trace buffer - 28 + * "create_synth_test", "empty_synth_test", and several instances of 29 + * "gen_synth_test". 30 + * 31 + * To remove the events, remove the module: 32 + * 33 + * # rmmod synth_event_gen_test 34 + * 35 + */ 36 + 37 + static struct trace_event_file *create_synth_test; 38 + static struct trace_event_file *empty_synth_test; 39 + static struct trace_event_file *gen_synth_test; 40 + 41 + /* 42 + * Test to make sure we can create a synthetic event, then add more 43 + * fields. 44 + */ 45 + static int __init test_gen_synth_cmd(void) 46 + { 47 + struct dynevent_cmd cmd; 48 + u64 vals[7]; 49 + char *buf; 50 + int ret; 51 + 52 + /* Create a buffer to hold the generated command */ 53 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 54 + if (!buf) 55 + return -ENOMEM; 56 + 57 + /* Before generating the command, initialize the cmd object */ 58 + synth_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 59 + 60 + /* 61 + * Create the empty gen_synth_test synthetic event with the 62 + * first 4 fields. 63 + */ 64 + ret = synth_event_gen_cmd_start(&cmd, "gen_synth_test", THIS_MODULE, 65 + "pid_t", "next_pid_field", 66 + "char[16]", "next_comm_field", 67 + "u64", "ts_ns", 68 + "u64", "ts_ms"); 69 + if (ret) 70 + goto free; 71 + 72 + /* Use synth_event_add_field to add the rest of the fields */ 73 + 74 + ret = synth_event_add_field(&cmd, "unsigned int", "cpu"); 75 + if (ret) 76 + goto free; 77 + 78 + ret = synth_event_add_field(&cmd, "char[64]", "my_string_field"); 79 + if (ret) 80 + goto free; 81 + 82 + ret = synth_event_add_field(&cmd, "int", "my_int_field"); 83 + if (ret) 84 + goto free; 85 + 86 + ret = synth_event_gen_cmd_end(&cmd); 87 + if (ret) 88 + goto free; 89 + 90 + /* 91 + * Now get the gen_synth_test event file. We need to prevent 92 + * the instance and event from disappearing from underneath 93 + * us, which trace_get_event_file() does (though in this case 94 + * we're using the top-level instance which never goes away). 95 + */ 96 + gen_synth_test = trace_get_event_file(NULL, "synthetic", 97 + "gen_synth_test"); 98 + if (IS_ERR(gen_synth_test)) { 99 + ret = PTR_ERR(gen_synth_test); 100 + goto delete; 101 + } 102 + 103 + /* Enable the event or you won't see anything */ 104 + ret = trace_array_set_clr_event(gen_synth_test->tr, 105 + "synthetic", "gen_synth_test", true); 106 + if (ret) { 107 + trace_put_event_file(gen_synth_test); 108 + goto delete; 109 + } 110 + 111 + /* Create some bogus values just for testing */ 112 + 113 + vals[0] = 777; /* next_pid_field */ 114 + vals[1] = (u64)"hula hoops"; /* next_comm_field */ 115 + vals[2] = 1000000; /* ts_ns */ 116 + vals[3] = 1000; /* ts_ms */ 117 + vals[4] = smp_processor_id(); /* cpu */ 118 + vals[5] = (u64)"thneed"; /* my_string_field */ 119 + vals[6] = 598; /* my_int_field */ 120 + 121 + /* Now generate a gen_synth_test event */ 122 + ret = synth_event_trace_array(gen_synth_test, vals, ARRAY_SIZE(vals)); 123 + out: 124 + return ret; 125 + delete: 126 + /* We got an error after creating the event, delete it */ 127 + synth_event_delete("gen_synth_test"); 128 + free: 129 + kfree(buf); 130 + 131 + goto out; 132 + } 133 + 134 + /* 135 + * Test to make sure we can create an initially empty synthetic event, 136 + * then add all the fields. 137 + */ 138 + static int __init test_empty_synth_event(void) 139 + { 140 + struct dynevent_cmd cmd; 141 + u64 vals[7]; 142 + char *buf; 143 + int ret; 144 + 145 + /* Create a buffer to hold the generated command */ 146 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 147 + if (!buf) 148 + return -ENOMEM; 149 + 150 + /* Before generating the command, initialize the cmd object */ 151 + synth_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 152 + 153 + /* 154 + * Create the empty_synth_test synthetic event with no fields. 155 + */ 156 + ret = synth_event_gen_cmd_start(&cmd, "empty_synth_test", THIS_MODULE); 157 + if (ret) 158 + goto free; 159 + 160 + /* Use synth_event_add_field to add all of the fields */ 161 + 162 + ret = synth_event_add_field(&cmd, "pid_t", "next_pid_field"); 163 + if (ret) 164 + goto free; 165 + 166 + ret = synth_event_add_field(&cmd, "char[16]", "next_comm_field"); 167 + if (ret) 168 + goto free; 169 + 170 + ret = synth_event_add_field(&cmd, "u64", "ts_ns"); 171 + if (ret) 172 + goto free; 173 + 174 + ret = synth_event_add_field(&cmd, "u64", "ts_ms"); 175 + if (ret) 176 + goto free; 177 + 178 + ret = synth_event_add_field(&cmd, "unsigned int", "cpu"); 179 + if (ret) 180 + goto free; 181 + 182 + ret = synth_event_add_field(&cmd, "char[64]", "my_string_field"); 183 + if (ret) 184 + goto free; 185 + 186 + ret = synth_event_add_field(&cmd, "int", "my_int_field"); 187 + if (ret) 188 + goto free; 189 + 190 + /* All fields have been added, close and register the synth event */ 191 + 192 + ret = synth_event_gen_cmd_end(&cmd); 193 + if (ret) 194 + goto free; 195 + 196 + /* 197 + * Now get the empty_synth_test event file. We need to 198 + * prevent the instance and event from disappearing from 199 + * underneath us, which trace_get_event_file() does (though in 200 + * this case we're using the top-level instance which never 201 + * goes away). 202 + */ 203 + empty_synth_test = trace_get_event_file(NULL, "synthetic", 204 + "empty_synth_test"); 205 + if (IS_ERR(empty_synth_test)) { 206 + ret = PTR_ERR(empty_synth_test); 207 + goto delete; 208 + } 209 + 210 + /* Enable the event or you won't see anything */ 211 + ret = trace_array_set_clr_event(empty_synth_test->tr, 212 + "synthetic", "empty_synth_test", true); 213 + if (ret) { 214 + trace_put_event_file(empty_synth_test); 215 + goto delete; 216 + } 217 + 218 + /* Create some bogus values just for testing */ 219 + 220 + vals[0] = 777; /* next_pid_field */ 221 + vals[1] = (u64)"tiddlywinks"; /* next_comm_field */ 222 + vals[2] = 1000000; /* ts_ns */ 223 + vals[3] = 1000; /* ts_ms */ 224 + vals[4] = smp_processor_id(); /* cpu */ 225 + vals[5] = (u64)"thneed_2.0"; /* my_string_field */ 226 + vals[6] = 399; /* my_int_field */ 227 + 228 + /* Now trace an empty_synth_test event */ 229 + ret = synth_event_trace_array(empty_synth_test, vals, ARRAY_SIZE(vals)); 230 + out: 231 + return ret; 232 + delete: 233 + /* We got an error after creating the event, delete it */ 234 + synth_event_delete("empty_synth_test"); 235 + free: 236 + kfree(buf); 237 + 238 + goto out; 239 + } 240 + 241 + static struct synth_field_desc create_synth_test_fields[] = { 242 + { .type = "pid_t", .name = "next_pid_field" }, 243 + { .type = "char[16]", .name = "next_comm_field" }, 244 + { .type = "u64", .name = "ts_ns" }, 245 + { .type = "u64", .name = "ts_ms" }, 246 + { .type = "unsigned int", .name = "cpu" }, 247 + { .type = "char[64]", .name = "my_string_field" }, 248 + { .type = "int", .name = "my_int_field" }, 249 + }; 250 + 251 + /* 252 + * Test synthetic event creation all at once from array of field 253 + * descriptors. 254 + */ 255 + static int __init test_create_synth_event(void) 256 + { 257 + u64 vals[7]; 258 + int ret; 259 + 260 + /* Create the create_synth_test event with the fields above */ 261 + ret = synth_event_create("create_synth_test", 262 + create_synth_test_fields, 263 + ARRAY_SIZE(create_synth_test_fields), 264 + THIS_MODULE); 265 + if (ret) 266 + goto out; 267 + 268 + /* 269 + * Now get the create_synth_test event file. We need to 270 + * prevent the instance and event from disappearing from 271 + * underneath us, which trace_get_event_file() does (though in 272 + * this case we're using the top-level instance which never 273 + * goes away). 274 + */ 275 + create_synth_test = trace_get_event_file(NULL, "synthetic", 276 + "create_synth_test"); 277 + if (IS_ERR(create_synth_test)) { 278 + ret = PTR_ERR(create_synth_test); 279 + goto delete; 280 + } 281 + 282 + /* Enable the event or you won't see anything */ 283 + ret = trace_array_set_clr_event(create_synth_test->tr, 284 + "synthetic", "create_synth_test", true); 285 + if (ret) { 286 + trace_put_event_file(create_synth_test); 287 + goto delete; 288 + } 289 + 290 + /* Create some bogus values just for testing */ 291 + 292 + vals[0] = 777; /* next_pid_field */ 293 + vals[1] = (u64)"tiddlywinks"; /* next_comm_field */ 294 + vals[2] = 1000000; /* ts_ns */ 295 + vals[3] = 1000; /* ts_ms */ 296 + vals[4] = smp_processor_id(); /* cpu */ 297 + vals[5] = (u64)"thneed"; /* my_string_field */ 298 + vals[6] = 398; /* my_int_field */ 299 + 300 + /* Now generate a create_synth_test event */ 301 + ret = synth_event_trace_array(create_synth_test, vals, ARRAY_SIZE(vals)); 302 + out: 303 + return ret; 304 + delete: 305 + /* We got an error after creating the event, delete it */ 306 + ret = synth_event_delete("create_synth_test"); 307 + 308 + goto out; 309 + } 310 + 311 + /* 312 + * Test tracing a synthetic event by reserving trace buffer space, 313 + * then filling in fields one after another. 314 + */ 315 + static int __init test_add_next_synth_val(void) 316 + { 317 + struct synth_event_trace_state trace_state; 318 + int ret; 319 + 320 + /* Start by reserving space in the trace buffer */ 321 + ret = synth_event_trace_start(gen_synth_test, &trace_state); 322 + if (ret) 323 + return ret; 324 + 325 + /* Write some bogus values into the trace buffer, one after another */ 326 + 327 + /* next_pid_field */ 328 + ret = synth_event_add_next_val(777, &trace_state); 329 + if (ret) 330 + goto out; 331 + 332 + /* next_comm_field */ 333 + ret = synth_event_add_next_val((u64)"slinky", &trace_state); 334 + if (ret) 335 + goto out; 336 + 337 + /* ts_ns */ 338 + ret = synth_event_add_next_val(1000000, &trace_state); 339 + if (ret) 340 + goto out; 341 + 342 + /* ts_ms */ 343 + ret = synth_event_add_next_val(1000, &trace_state); 344 + if (ret) 345 + goto out; 346 + 347 + /* cpu */ 348 + ret = synth_event_add_next_val(smp_processor_id(), &trace_state); 349 + if (ret) 350 + goto out; 351 + 352 + /* my_string_field */ 353 + ret = synth_event_add_next_val((u64)"thneed_2.01", &trace_state); 354 + if (ret) 355 + goto out; 356 + 357 + /* my_int_field */ 358 + ret = synth_event_add_next_val(395, &trace_state); 359 + out: 360 + /* Finally, commit the event */ 361 + ret = synth_event_trace_end(&trace_state); 362 + 363 + return ret; 364 + } 365 + 366 + /* 367 + * Test tracing a synthetic event by reserving trace buffer space, 368 + * then filling in fields using field names, which can be done in any 369 + * order. 370 + */ 371 + static int __init test_add_synth_val(void) 372 + { 373 + struct synth_event_trace_state trace_state; 374 + int ret; 375 + 376 + /* Start by reserving space in the trace buffer */ 377 + ret = synth_event_trace_start(gen_synth_test, &trace_state); 378 + if (ret) 379 + return ret; 380 + 381 + /* Write some bogus values into the trace buffer, using field names */ 382 + 383 + ret = synth_event_add_val("ts_ns", 1000000, &trace_state); 384 + if (ret) 385 + goto out; 386 + 387 + ret = synth_event_add_val("ts_ms", 1000, &trace_state); 388 + if (ret) 389 + goto out; 390 + 391 + ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state); 392 + if (ret) 393 + goto out; 394 + 395 + ret = synth_event_add_val("next_pid_field", 777, &trace_state); 396 + if (ret) 397 + goto out; 398 + 399 + ret = synth_event_add_val("next_comm_field", (u64)"silly putty", 400 + &trace_state); 401 + if (ret) 402 + goto out; 403 + 404 + ret = synth_event_add_val("my_string_field", (u64)"thneed_9", 405 + &trace_state); 406 + if (ret) 407 + goto out; 408 + 409 + ret = synth_event_add_val("my_int_field", 3999, &trace_state); 410 + out: 411 + /* Finally, commit the event */ 412 + ret = synth_event_trace_end(&trace_state); 413 + 414 + return ret; 415 + } 416 + 417 + /* 418 + * Test tracing a synthetic event all at once from array of values. 419 + */ 420 + static int __init test_trace_synth_event(void) 421 + { 422 + int ret; 423 + 424 + /* Trace some bogus values just for testing */ 425 + ret = synth_event_trace(create_synth_test, 7, /* number of values */ 426 + 444, /* next_pid_field */ 427 + (u64)"clackers", /* next_comm_field */ 428 + 1000000, /* ts_ns */ 429 + 1000, /* ts_ms */ 430 + smp_processor_id(), /* cpu */ 431 + (u64)"Thneed", /* my_string_field */ 432 + 999); /* my_int_field */ 433 + return ret; 434 + } 435 + 436 + static int __init synth_event_gen_test_init(void) 437 + { 438 + int ret; 439 + 440 + ret = test_gen_synth_cmd(); 441 + if (ret) 442 + return ret; 443 + 444 + ret = test_empty_synth_event(); 445 + if (ret) { 446 + WARN_ON(trace_array_set_clr_event(gen_synth_test->tr, 447 + "synthetic", 448 + "gen_synth_test", false)); 449 + trace_put_event_file(gen_synth_test); 450 + WARN_ON(synth_event_delete("gen_synth_test")); 451 + goto out; 452 + } 453 + 454 + ret = test_create_synth_event(); 455 + if (ret) { 456 + WARN_ON(trace_array_set_clr_event(gen_synth_test->tr, 457 + "synthetic", 458 + "gen_synth_test", false)); 459 + trace_put_event_file(gen_synth_test); 460 + WARN_ON(synth_event_delete("gen_synth_test")); 461 + 462 + WARN_ON(trace_array_set_clr_event(empty_synth_test->tr, 463 + "synthetic", 464 + "empty_synth_test", false)); 465 + trace_put_event_file(empty_synth_test); 466 + WARN_ON(synth_event_delete("empty_synth_test")); 467 + goto out; 468 + } 469 + 470 + ret = test_add_next_synth_val(); 471 + WARN_ON(ret); 472 + 473 + ret = test_add_synth_val(); 474 + WARN_ON(ret); 475 + 476 + ret = test_trace_synth_event(); 477 + WARN_ON(ret); 478 + out: 479 + return ret; 480 + } 481 + 482 + static void __exit synth_event_gen_test_exit(void) 483 + { 484 + /* Disable the event or you can't remove it */ 485 + WARN_ON(trace_array_set_clr_event(gen_synth_test->tr, 486 + "synthetic", 487 + "gen_synth_test", false)); 488 + 489 + /* Now give the file and instance back */ 490 + trace_put_event_file(gen_synth_test); 491 + 492 + /* Now unregister and free the synthetic event */ 493 + WARN_ON(synth_event_delete("gen_synth_test")); 494 + 495 + /* Disable the event or you can't remove it */ 496 + WARN_ON(trace_array_set_clr_event(empty_synth_test->tr, 497 + "synthetic", 498 + "empty_synth_test", false)); 499 + 500 + /* Now give the file and instance back */ 501 + trace_put_event_file(empty_synth_test); 502 + 503 + /* Now unregister and free the synthetic event */ 504 + WARN_ON(synth_event_delete("empty_synth_test")); 505 + 506 + /* Disable the event or you can't remove it */ 507 + WARN_ON(trace_array_set_clr_event(create_synth_test->tr, 508 + "synthetic", 509 + "create_synth_test", false)); 510 + 511 + /* Now give the file and instance back */ 512 + trace_put_event_file(create_synth_test); 513 + 514 + /* Now unregister and free the synthetic event */ 515 + WARN_ON(synth_event_delete("create_synth_test")); 516 + } 517 + 518 + module_init(synth_event_gen_test_init) 519 + module_exit(synth_event_gen_test_exit) 520 + 521 + MODULE_AUTHOR("Tom Zanussi"); 522 + MODULE_DESCRIPTION("synthetic event generation test"); 523 + MODULE_LICENSE("GPL v2");
+258 -195
kernel/trace/trace.c
··· 162 162 static union trace_eval_map_item *trace_eval_maps; 163 163 #endif /* CONFIG_TRACE_EVAL_MAP_FILE */ 164 164 165 - static int tracing_set_tracer(struct trace_array *tr, const char *buf); 166 - static void ftrace_trace_userstack(struct ring_buffer *buffer, 165 + int tracing_set_tracer(struct trace_array *tr, const char *buf); 166 + static void ftrace_trace_userstack(struct trace_buffer *buffer, 167 167 unsigned long flags, int pc); 168 168 169 169 #define MAX_TRACER_SIZE 100 ··· 338 338 } 339 339 340 340 int call_filter_check_discard(struct trace_event_call *call, void *rec, 341 - struct ring_buffer *buffer, 341 + struct trace_buffer *buffer, 342 342 struct ring_buffer_event *event) 343 343 { 344 344 if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && ··· 603 603 return read; 604 604 } 605 605 606 - static u64 buffer_ftrace_now(struct trace_buffer *buf, int cpu) 606 + static u64 buffer_ftrace_now(struct array_buffer *buf, int cpu) 607 607 { 608 608 u64 ts; 609 609 ··· 619 619 620 620 u64 ftrace_now(int cpu) 621 621 { 622 - return buffer_ftrace_now(&global_trace.trace_buffer, cpu); 622 + return buffer_ftrace_now(&global_trace.array_buffer, cpu); 623 623 } 624 624 625 625 /** ··· 747 747 #endif 748 748 749 749 #ifdef CONFIG_STACKTRACE 750 - static void __ftrace_trace_stack(struct ring_buffer *buffer, 750 + static void __ftrace_trace_stack(struct trace_buffer *buffer, 751 751 unsigned long flags, 752 752 int skip, int pc, struct pt_regs *regs); 753 753 static inline void ftrace_trace_stack(struct trace_array *tr, 754 - struct ring_buffer *buffer, 754 + struct trace_buffer *buffer, 755 755 unsigned long flags, 756 756 int skip, int pc, struct pt_regs *regs); 757 757 758 758 #else 759 - static inline void __ftrace_trace_stack(struct ring_buffer *buffer, 759 + static inline void __ftrace_trace_stack(struct trace_buffer *buffer, 760 760 unsigned long flags, 761 761 int skip, int pc, struct pt_regs *regs) 762 762 { 763 763 } 764 764 static inline void ftrace_trace_stack(struct trace_array *tr, 765 - struct ring_buffer *buffer, 765 + struct trace_buffer *buffer, 766 766 unsigned long flags, 767 767 int skip, int pc, struct pt_regs *regs) 768 768 { ··· 780 780 } 781 781 782 782 static __always_inline struct ring_buffer_event * 783 - __trace_buffer_lock_reserve(struct ring_buffer *buffer, 783 + __trace_buffer_lock_reserve(struct trace_buffer *buffer, 784 784 int type, 785 785 unsigned long len, 786 786 unsigned long flags, int pc) ··· 796 796 797 797 void tracer_tracing_on(struct trace_array *tr) 798 798 { 799 - if (tr->trace_buffer.buffer) 800 - ring_buffer_record_on(tr->trace_buffer.buffer); 799 + if (tr->array_buffer.buffer) 800 + ring_buffer_record_on(tr->array_buffer.buffer); 801 801 /* 802 802 * This flag is looked at when buffers haven't been allocated 803 803 * yet, or by some tracers (like irqsoff), that just want to ··· 825 825 826 826 827 827 static __always_inline void 828 - __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) 828 + __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *event) 829 829 { 830 830 __this_cpu_write(trace_taskinfo_save, true); 831 831 ··· 848 848 int __trace_puts(unsigned long ip, const char *str, int size) 849 849 { 850 850 struct ring_buffer_event *event; 851 - struct ring_buffer *buffer; 851 + struct trace_buffer *buffer; 852 852 struct print_entry *entry; 853 853 unsigned long irq_flags; 854 854 int alloc; ··· 865 865 alloc = sizeof(*entry) + size + 2; /* possible \n added */ 866 866 867 867 local_save_flags(irq_flags); 868 - buffer = global_trace.trace_buffer.buffer; 868 + buffer = global_trace.array_buffer.buffer; 869 + ring_buffer_nest_start(buffer); 869 870 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, 870 871 irq_flags, pc); 871 - if (!event) 872 - return 0; 872 + if (!event) { 873 + size = 0; 874 + goto out; 875 + } 873 876 874 877 entry = ring_buffer_event_data(event); 875 878 entry->ip = ip; ··· 888 885 889 886 __buffer_unlock_commit(buffer, event); 890 887 ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL); 891 - 888 + out: 889 + ring_buffer_nest_end(buffer); 892 890 return size; 893 891 } 894 892 EXPORT_SYMBOL_GPL(__trace_puts); ··· 902 898 int __trace_bputs(unsigned long ip, const char *str) 903 899 { 904 900 struct ring_buffer_event *event; 905 - struct ring_buffer *buffer; 901 + struct trace_buffer *buffer; 906 902 struct bputs_entry *entry; 907 903 unsigned long irq_flags; 908 904 int size = sizeof(struct bputs_entry); 905 + int ret = 0; 909 906 int pc; 910 907 911 908 if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) ··· 918 913 return 0; 919 914 920 915 local_save_flags(irq_flags); 921 - buffer = global_trace.trace_buffer.buffer; 916 + buffer = global_trace.array_buffer.buffer; 917 + 918 + ring_buffer_nest_start(buffer); 922 919 event = __trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, 923 920 irq_flags, pc); 924 921 if (!event) 925 - return 0; 922 + goto out; 926 923 927 924 entry = ring_buffer_event_data(event); 928 925 entry->ip = ip; ··· 933 926 __buffer_unlock_commit(buffer, event); 934 927 ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL); 935 928 936 - return 1; 929 + ret = 1; 930 + out: 931 + ring_buffer_nest_end(buffer); 932 + return ret; 937 933 } 938 934 EXPORT_SYMBOL_GPL(__trace_bputs); 939 935 ··· 1046 1036 } 1047 1037 EXPORT_SYMBOL_GPL(tracing_cond_snapshot_data); 1048 1038 1049 - static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, 1050 - struct trace_buffer *size_buf, int cpu_id); 1051 - static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); 1039 + static int resize_buffer_duplicate_size(struct array_buffer *trace_buf, 1040 + struct array_buffer *size_buf, int cpu_id); 1041 + static void set_buffer_entries(struct array_buffer *buf, unsigned long val); 1052 1042 1053 1043 int tracing_alloc_snapshot_instance(struct trace_array *tr) 1054 1044 { ··· 1058 1048 1059 1049 /* allocate spare buffer */ 1060 1050 ret = resize_buffer_duplicate_size(&tr->max_buffer, 1061 - &tr->trace_buffer, RING_BUFFER_ALL_CPUS); 1051 + &tr->array_buffer, RING_BUFFER_ALL_CPUS); 1062 1052 if (ret < 0) 1063 1053 return ret; 1064 1054 ··· 1261 1251 1262 1252 void tracer_tracing_off(struct trace_array *tr) 1263 1253 { 1264 - if (tr->trace_buffer.buffer) 1265 - ring_buffer_record_off(tr->trace_buffer.buffer); 1254 + if (tr->array_buffer.buffer) 1255 + ring_buffer_record_off(tr->array_buffer.buffer); 1266 1256 /* 1267 1257 * This flag is looked at when buffers haven't been allocated 1268 1258 * yet, or by some tracers (like irqsoff), that just want to ··· 1304 1294 */ 1305 1295 bool tracer_tracing_is_on(struct trace_array *tr) 1306 1296 { 1307 - if (tr->trace_buffer.buffer) 1308 - return ring_buffer_record_is_on(tr->trace_buffer.buffer); 1297 + if (tr->array_buffer.buffer) 1298 + return ring_buffer_record_is_on(tr->array_buffer.buffer); 1309 1299 return !tr->buffer_disabled; 1310 1300 } 1311 1301 ··· 1600 1590 static void 1601 1591 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) 1602 1592 { 1603 - struct trace_buffer *trace_buf = &tr->trace_buffer; 1604 - struct trace_buffer *max_buf = &tr->max_buffer; 1593 + struct array_buffer *trace_buf = &tr->array_buffer; 1594 + struct array_buffer *max_buf = &tr->max_buffer; 1605 1595 struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); 1606 1596 struct trace_array_cpu *max_data = per_cpu_ptr(max_buf->data, cpu); 1607 1597 ··· 1659 1649 1660 1650 arch_spin_lock(&tr->max_lock); 1661 1651 1662 - /* Inherit the recordable setting from trace_buffer */ 1663 - if (ring_buffer_record_is_set_on(tr->trace_buffer.buffer)) 1652 + /* Inherit the recordable setting from array_buffer */ 1653 + if (ring_buffer_record_is_set_on(tr->array_buffer.buffer)) 1664 1654 ring_buffer_record_on(tr->max_buffer.buffer); 1665 1655 else 1666 1656 ring_buffer_record_off(tr->max_buffer.buffer); ··· 1669 1659 if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data)) 1670 1660 goto out_unlock; 1671 1661 #endif 1672 - swap(tr->trace_buffer.buffer, tr->max_buffer.buffer); 1662 + swap(tr->array_buffer.buffer, tr->max_buffer.buffer); 1673 1663 1674 1664 __update_max_tr(tr, tsk, cpu); 1675 1665 ··· 1702 1692 1703 1693 arch_spin_lock(&tr->max_lock); 1704 1694 1705 - ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->trace_buffer.buffer, cpu); 1695 + ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->array_buffer.buffer, cpu); 1706 1696 1707 1697 if (ret == -EBUSY) { 1708 1698 /* ··· 1728 1718 if (trace_buffer_iter(iter, iter->cpu_file)) 1729 1719 return 0; 1730 1720 1731 - return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file, 1721 + return ring_buffer_wait(iter->array_buffer->buffer, iter->cpu_file, 1732 1722 full); 1733 1723 } 1734 1724 ··· 1779 1769 * internal tracing to verify that everything is in order. 1780 1770 * If we fail, we do not register this tracer. 1781 1771 */ 1782 - tracing_reset_online_cpus(&tr->trace_buffer); 1772 + tracing_reset_online_cpus(&tr->array_buffer); 1783 1773 1784 1774 tr->current_trace = type; 1785 1775 ··· 1805 1795 return -1; 1806 1796 } 1807 1797 /* Only reset on passing, to avoid touching corrupted buffers */ 1808 - tracing_reset_online_cpus(&tr->trace_buffer); 1798 + tracing_reset_online_cpus(&tr->array_buffer); 1809 1799 1810 1800 #ifdef CONFIG_TRACER_MAX_TRACE 1811 1801 if (type->use_max_tr) { ··· 1972 1962 return ret; 1973 1963 } 1974 1964 1975 - static void tracing_reset_cpu(struct trace_buffer *buf, int cpu) 1965 + static void tracing_reset_cpu(struct array_buffer *buf, int cpu) 1976 1966 { 1977 - struct ring_buffer *buffer = buf->buffer; 1967 + struct trace_buffer *buffer = buf->buffer; 1978 1968 1979 1969 if (!buffer) 1980 1970 return; ··· 1988 1978 ring_buffer_record_enable(buffer); 1989 1979 } 1990 1980 1991 - void tracing_reset_online_cpus(struct trace_buffer *buf) 1981 + void tracing_reset_online_cpus(struct array_buffer *buf) 1992 1982 { 1993 - struct ring_buffer *buffer = buf->buffer; 1983 + struct trace_buffer *buffer = buf->buffer; 1994 1984 int cpu; 1995 1985 1996 1986 if (!buffer) ··· 2018 2008 if (!tr->clear_trace) 2019 2009 continue; 2020 2010 tr->clear_trace = false; 2021 - tracing_reset_online_cpus(&tr->trace_buffer); 2011 + tracing_reset_online_cpus(&tr->array_buffer); 2022 2012 #ifdef CONFIG_TRACER_MAX_TRACE 2023 2013 tracing_reset_online_cpus(&tr->max_buffer); 2024 2014 #endif ··· 2108 2098 */ 2109 2099 void tracing_start(void) 2110 2100 { 2111 - struct ring_buffer *buffer; 2101 + struct trace_buffer *buffer; 2112 2102 unsigned long flags; 2113 2103 2114 2104 if (tracing_disabled) ··· 2127 2117 /* Prevent the buffers from switching */ 2128 2118 arch_spin_lock(&global_trace.max_lock); 2129 2119 2130 - buffer = global_trace.trace_buffer.buffer; 2120 + buffer = global_trace.array_buffer.buffer; 2131 2121 if (buffer) 2132 2122 ring_buffer_record_enable(buffer); 2133 2123 ··· 2145 2135 2146 2136 static void tracing_start_tr(struct trace_array *tr) 2147 2137 { 2148 - struct ring_buffer *buffer; 2138 + struct trace_buffer *buffer; 2149 2139 unsigned long flags; 2150 2140 2151 2141 if (tracing_disabled) ··· 2166 2156 goto out; 2167 2157 } 2168 2158 2169 - buffer = tr->trace_buffer.buffer; 2159 + buffer = tr->array_buffer.buffer; 2170 2160 if (buffer) 2171 2161 ring_buffer_record_enable(buffer); 2172 2162 ··· 2182 2172 */ 2183 2173 void tracing_stop(void) 2184 2174 { 2185 - struct ring_buffer *buffer; 2175 + struct trace_buffer *buffer; 2186 2176 unsigned long flags; 2187 2177 2188 2178 raw_spin_lock_irqsave(&global_trace.start_lock, flags); ··· 2192 2182 /* Prevent the buffers from switching */ 2193 2183 arch_spin_lock(&global_trace.max_lock); 2194 2184 2195 - buffer = global_trace.trace_buffer.buffer; 2185 + buffer = global_trace.array_buffer.buffer; 2196 2186 if (buffer) 2197 2187 ring_buffer_record_disable(buffer); 2198 2188 ··· 2210 2200 2211 2201 static void tracing_stop_tr(struct trace_array *tr) 2212 2202 { 2213 - struct ring_buffer *buffer; 2203 + struct trace_buffer *buffer; 2214 2204 unsigned long flags; 2215 2205 2216 2206 /* If global, we need to also stop the max tracer */ ··· 2221 2211 if (tr->stop_count++) 2222 2212 goto out; 2223 2213 2224 - buffer = tr->trace_buffer.buffer; 2214 + buffer = tr->array_buffer.buffer; 2225 2215 if (buffer) 2226 2216 ring_buffer_record_disable(buffer); 2227 2217 ··· 2452 2442 EXPORT_SYMBOL_GPL(tracing_generic_entry_update); 2453 2443 2454 2444 struct ring_buffer_event * 2455 - trace_buffer_lock_reserve(struct ring_buffer *buffer, 2445 + trace_buffer_lock_reserve(struct trace_buffer *buffer, 2456 2446 int type, 2457 2447 unsigned long len, 2458 2448 unsigned long flags, int pc) ··· 2571 2561 preempt_enable(); 2572 2562 } 2573 2563 2574 - static struct ring_buffer *temp_buffer; 2564 + static struct trace_buffer *temp_buffer; 2575 2565 2576 2566 struct ring_buffer_event * 2577 - trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, 2567 + trace_event_buffer_lock_reserve(struct trace_buffer **current_rb, 2578 2568 struct trace_event_file *trace_file, 2579 2569 int type, unsigned long len, 2580 2570 unsigned long flags, int pc) ··· 2582 2572 struct ring_buffer_event *entry; 2583 2573 int val; 2584 2574 2585 - *current_rb = trace_file->tr->trace_buffer.buffer; 2575 + *current_rb = trace_file->tr->array_buffer.buffer; 2586 2576 2587 2577 if (!ring_buffer_time_stamp_abs(*current_rb) && (trace_file->flags & 2588 2578 (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED)) && ··· 2620 2610 static void output_printk(struct trace_event_buffer *fbuffer) 2621 2611 { 2622 2612 struct trace_event_call *event_call; 2613 + struct trace_event_file *file; 2623 2614 struct trace_event *event; 2624 2615 unsigned long flags; 2625 2616 struct trace_iterator *iter = tracepoint_print_iter; ··· 2632 2621 event_call = fbuffer->trace_file->event_call; 2633 2622 if (!event_call || !event_call->event.funcs || 2634 2623 !event_call->event.funcs->trace) 2624 + return; 2625 + 2626 + file = fbuffer->trace_file; 2627 + if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) || 2628 + (unlikely(file->flags & EVENT_FILE_FL_FILTERED) && 2629 + !filter_match_preds(file->filter, fbuffer->entry))) 2635 2630 return; 2636 2631 2637 2632 event = &fbuffer->trace_file->event_call->event; ··· 2690 2673 if (static_key_false(&tracepoint_printk_key.key)) 2691 2674 output_printk(fbuffer); 2692 2675 2693 - event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer, 2676 + event_trigger_unlock_commit_regs(fbuffer->trace_file, fbuffer->buffer, 2694 2677 fbuffer->event, fbuffer->entry, 2695 - fbuffer->flags, fbuffer->pc); 2678 + fbuffer->flags, fbuffer->pc, fbuffer->regs); 2696 2679 } 2697 2680 EXPORT_SYMBOL_GPL(trace_event_buffer_commit); 2698 2681 ··· 2706 2689 # define STACK_SKIP 3 2707 2690 2708 2691 void trace_buffer_unlock_commit_regs(struct trace_array *tr, 2709 - struct ring_buffer *buffer, 2692 + struct trace_buffer *buffer, 2710 2693 struct ring_buffer_event *event, 2711 2694 unsigned long flags, int pc, 2712 2695 struct pt_regs *regs) ··· 2727 2710 * Similar to trace_buffer_unlock_commit_regs() but do not dump stack. 2728 2711 */ 2729 2712 void 2730 - trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer, 2713 + trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer, 2731 2714 struct ring_buffer_event *event) 2732 2715 { 2733 2716 __buffer_unlock_commit(buffer, event); ··· 2862 2845 int pc) 2863 2846 { 2864 2847 struct trace_event_call *call = &event_function; 2865 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 2848 + struct trace_buffer *buffer = tr->array_buffer.buffer; 2866 2849 struct ring_buffer_event *event; 2867 2850 struct ftrace_entry *entry; 2868 2851 ··· 2900 2883 static DEFINE_PER_CPU(struct ftrace_stacks, ftrace_stacks); 2901 2884 static DEFINE_PER_CPU(int, ftrace_stack_reserve); 2902 2885 2903 - static void __ftrace_trace_stack(struct ring_buffer *buffer, 2886 + static void __ftrace_trace_stack(struct trace_buffer *buffer, 2904 2887 unsigned long flags, 2905 2888 int skip, int pc, struct pt_regs *regs) 2906 2889 { ··· 2975 2958 } 2976 2959 2977 2960 static inline void ftrace_trace_stack(struct trace_array *tr, 2978 - struct ring_buffer *buffer, 2961 + struct trace_buffer *buffer, 2979 2962 unsigned long flags, 2980 2963 int skip, int pc, struct pt_regs *regs) 2981 2964 { ··· 2988 2971 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, 2989 2972 int pc) 2990 2973 { 2991 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 2974 + struct trace_buffer *buffer = tr->array_buffer.buffer; 2992 2975 2993 2976 if (rcu_is_watching()) { 2994 2977 __ftrace_trace_stack(buffer, flags, skip, pc, NULL); ··· 3026 3009 /* Skip 1 to skip this function. */ 3027 3010 skip++; 3028 3011 #endif 3029 - __ftrace_trace_stack(global_trace.trace_buffer.buffer, 3012 + __ftrace_trace_stack(global_trace.array_buffer.buffer, 3030 3013 flags, skip, preempt_count(), NULL); 3031 3014 } 3032 3015 EXPORT_SYMBOL_GPL(trace_dump_stack); ··· 3035 3018 static DEFINE_PER_CPU(int, user_stack_count); 3036 3019 3037 3020 static void 3038 - ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) 3021 + ftrace_trace_userstack(struct trace_buffer *buffer, unsigned long flags, int pc) 3039 3022 { 3040 3023 struct trace_event_call *call = &event_user_stack; 3041 3024 struct ring_buffer_event *event; ··· 3080 3063 preempt_enable(); 3081 3064 } 3082 3065 #else /* CONFIG_USER_STACKTRACE_SUPPORT */ 3083 - static void ftrace_trace_userstack(struct ring_buffer *buffer, 3066 + static void ftrace_trace_userstack(struct trace_buffer *buffer, 3084 3067 unsigned long flags, int pc) 3085 3068 { 3086 3069 } ··· 3126 3109 struct trace_buffer_struct *buffers; 3127 3110 3128 3111 buffers = alloc_percpu(struct trace_buffer_struct); 3129 - if (WARN(!buffers, "Could not allocate percpu trace_printk buffer")) 3112 + if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer")) 3130 3113 return -ENOMEM; 3131 3114 3132 3115 trace_percpu_buffer = buffers; ··· 3171 3154 * directly here. If the global_trace.buffer is already 3172 3155 * allocated here, then this was called by module code. 3173 3156 */ 3174 - if (global_trace.trace_buffer.buffer) 3157 + if (global_trace.array_buffer.buffer) 3175 3158 tracing_start_cmdline_record(); 3176 3159 } 3177 3160 EXPORT_SYMBOL_GPL(trace_printk_init_buffers); ··· 3205 3188 { 3206 3189 struct trace_event_call *call = &event_bprint; 3207 3190 struct ring_buffer_event *event; 3208 - struct ring_buffer *buffer; 3191 + struct trace_buffer *buffer; 3209 3192 struct trace_array *tr = &global_trace; 3210 3193 struct bprint_entry *entry; 3211 3194 unsigned long flags; ··· 3230 3213 len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); 3231 3214 3232 3215 if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) 3233 - goto out; 3216 + goto out_put; 3234 3217 3235 3218 local_save_flags(flags); 3236 3219 size = sizeof(*entry) + sizeof(u32) * len; 3237 - buffer = tr->trace_buffer.buffer; 3220 + buffer = tr->array_buffer.buffer; 3221 + ring_buffer_nest_start(buffer); 3238 3222 event = __trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, 3239 3223 flags, pc); 3240 3224 if (!event) ··· 3251 3233 } 3252 3234 3253 3235 out: 3236 + ring_buffer_nest_end(buffer); 3237 + out_put: 3254 3238 put_trace_buf(); 3255 3239 3256 3240 out_nobuffer: ··· 3265 3245 3266 3246 __printf(3, 0) 3267 3247 static int 3268 - __trace_array_vprintk(struct ring_buffer *buffer, 3248 + __trace_array_vprintk(struct trace_buffer *buffer, 3269 3249 unsigned long ip, const char *fmt, va_list args) 3270 3250 { 3271 3251 struct trace_event_call *call = &event_print; ··· 3295 3275 3296 3276 local_save_flags(flags); 3297 3277 size = sizeof(*entry) + len + 1; 3278 + ring_buffer_nest_start(buffer); 3298 3279 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, 3299 3280 flags, pc); 3300 3281 if (!event) ··· 3310 3289 } 3311 3290 3312 3291 out: 3292 + ring_buffer_nest_end(buffer); 3313 3293 put_trace_buf(); 3314 3294 3315 3295 out_nobuffer: ··· 3324 3302 int trace_array_vprintk(struct trace_array *tr, 3325 3303 unsigned long ip, const char *fmt, va_list args) 3326 3304 { 3327 - return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); 3305 + return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args); 3328 3306 } 3329 3307 3330 3308 __printf(3, 0) ··· 3348 3326 EXPORT_SYMBOL_GPL(trace_array_printk); 3349 3327 3350 3328 __printf(3, 4) 3351 - int trace_array_printk_buf(struct ring_buffer *buffer, 3329 + int trace_array_printk_buf(struct trace_buffer *buffer, 3352 3330 unsigned long ip, const char *fmt, ...) 3353 3331 { 3354 3332 int ret; ··· 3389 3367 if (buf_iter) 3390 3368 event = ring_buffer_iter_peek(buf_iter, ts); 3391 3369 else 3392 - event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, 3370 + event = ring_buffer_peek(iter->array_buffer->buffer, cpu, ts, 3393 3371 lost_events); 3394 3372 3395 3373 if (event) { ··· 3404 3382 __find_next_entry(struct trace_iterator *iter, int *ent_cpu, 3405 3383 unsigned long *missing_events, u64 *ent_ts) 3406 3384 { 3407 - struct ring_buffer *buffer = iter->trace_buffer->buffer; 3385 + struct trace_buffer *buffer = iter->array_buffer->buffer; 3408 3386 struct trace_entry *ent, *next = NULL; 3409 3387 unsigned long lost_events = 0, next_lost = 0; 3410 3388 int cpu_file = iter->cpu_file; ··· 3481 3459 3482 3460 static void trace_consume(struct trace_iterator *iter) 3483 3461 { 3484 - ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, 3462 + ring_buffer_consume(iter->array_buffer->buffer, iter->cpu, &iter->ts, 3485 3463 &iter->lost_events); 3486 3464 } 3487 3465 ··· 3519 3497 unsigned long entries = 0; 3520 3498 u64 ts; 3521 3499 3522 - per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; 3500 + per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = 0; 3523 3501 3524 3502 buf_iter = trace_buffer_iter(iter, cpu); 3525 3503 if (!buf_iter) ··· 3533 3511 * by the timestamp being before the start of the buffer. 3534 3512 */ 3535 3513 while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { 3536 - if (ts >= iter->trace_buffer->time_start) 3514 + if (ts >= iter->array_buffer->time_start) 3537 3515 break; 3538 3516 entries++; 3539 3517 ring_buffer_read(buf_iter, NULL); 3540 3518 } 3541 3519 3542 - per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; 3520 + per_cpu_ptr(iter->array_buffer->data, cpu)->skipped_entries = entries; 3543 3521 } 3544 3522 3545 3523 /* ··· 3624 3602 } 3625 3603 3626 3604 static void 3627 - get_total_entries_cpu(struct trace_buffer *buf, unsigned long *total, 3605 + get_total_entries_cpu(struct array_buffer *buf, unsigned long *total, 3628 3606 unsigned long *entries, int cpu) 3629 3607 { 3630 3608 unsigned long count; ··· 3646 3624 } 3647 3625 3648 3626 static void 3649 - get_total_entries(struct trace_buffer *buf, 3627 + get_total_entries(struct array_buffer *buf, 3650 3628 unsigned long *total, unsigned long *entries) 3651 3629 { 3652 3630 unsigned long t, e; ··· 3669 3647 if (!tr) 3670 3648 tr = &global_trace; 3671 3649 3672 - get_total_entries_cpu(&tr->trace_buffer, &total, &entries, cpu); 3650 + get_total_entries_cpu(&tr->array_buffer, &total, &entries, cpu); 3673 3651 3674 3652 return entries; 3675 3653 } ··· 3681 3659 if (!tr) 3682 3660 tr = &global_trace; 3683 3661 3684 - get_total_entries(&tr->trace_buffer, &total, &entries); 3662 + get_total_entries(&tr->array_buffer, &total, &entries); 3685 3663 3686 3664 return entries; 3687 3665 } ··· 3698 3676 "# \\ / ||||| \\ | / \n"); 3699 3677 } 3700 3678 3701 - static void print_event_info(struct trace_buffer *buf, struct seq_file *m) 3679 + static void print_event_info(struct array_buffer *buf, struct seq_file *m) 3702 3680 { 3703 3681 unsigned long total; 3704 3682 unsigned long entries; ··· 3709 3687 seq_puts(m, "#\n"); 3710 3688 } 3711 3689 3712 - static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m, 3690 + static void print_func_help_header(struct array_buffer *buf, struct seq_file *m, 3713 3691 unsigned int flags) 3714 3692 { 3715 3693 bool tgid = flags & TRACE_ITER_RECORD_TGID; ··· 3720 3698 seq_printf(m, "# | | %s | | |\n", tgid ? " | " : ""); 3721 3699 } 3722 3700 3723 - static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m, 3701 + static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file *m, 3724 3702 unsigned int flags) 3725 3703 { 3726 3704 bool tgid = flags & TRACE_ITER_RECORD_TGID; ··· 3742 3720 print_trace_header(struct seq_file *m, struct trace_iterator *iter) 3743 3721 { 3744 3722 unsigned long sym_flags = (global_trace.trace_flags & TRACE_ITER_SYM_MASK); 3745 - struct trace_buffer *buf = iter->trace_buffer; 3723 + struct array_buffer *buf = iter->array_buffer; 3746 3724 struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); 3747 3725 struct tracer *type = iter->trace; 3748 3726 unsigned long entries; ··· 3817 3795 cpumask_test_cpu(iter->cpu, iter->started)) 3818 3796 return; 3819 3797 3820 - if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) 3798 + if (per_cpu_ptr(iter->array_buffer->data, iter->cpu)->skipped_entries) 3821 3799 return; 3822 3800 3823 3801 if (cpumask_available(iter->started)) ··· 3951 3929 if (!ring_buffer_iter_empty(buf_iter)) 3952 3930 return 0; 3953 3931 } else { 3954 - if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) 3932 + if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu)) 3955 3933 return 0; 3956 3934 } 3957 3935 return 1; ··· 3963 3941 if (!ring_buffer_iter_empty(buf_iter)) 3964 3942 return 0; 3965 3943 } else { 3966 - if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) 3944 + if (!ring_buffer_empty_cpu(iter->array_buffer->buffer, cpu)) 3967 3945 return 0; 3968 3946 } 3969 3947 } ··· 4053 4031 } else { 4054 4032 if (!(trace_flags & TRACE_ITER_VERBOSE)) { 4055 4033 if (trace_flags & TRACE_ITER_IRQ_INFO) 4056 - print_func_help_header_irq(iter->trace_buffer, 4034 + print_func_help_header_irq(iter->array_buffer, 4057 4035 m, trace_flags); 4058 4036 else 4059 - print_func_help_header(iter->trace_buffer, m, 4037 + print_func_help_header(iter->array_buffer, m, 4060 4038 trace_flags); 4061 4039 } 4062 4040 } ··· 4214 4192 #ifdef CONFIG_TRACER_MAX_TRACE 4215 4193 /* Currently only the top directory has a snapshot */ 4216 4194 if (tr->current_trace->print_max || snapshot) 4217 - iter->trace_buffer = &tr->max_buffer; 4195 + iter->array_buffer = &tr->max_buffer; 4218 4196 else 4219 4197 #endif 4220 - iter->trace_buffer = &tr->trace_buffer; 4198 + iter->array_buffer = &tr->array_buffer; 4221 4199 iter->snapshot = snapshot; 4222 4200 iter->pos = -1; 4223 4201 iter->cpu_file = tracing_get_cpu(inode); 4224 4202 mutex_init(&iter->mutex); 4225 4203 4226 4204 /* Notify the tracer early; before we stop tracing. */ 4227 - if (iter->trace && iter->trace->open) 4205 + if (iter->trace->open) 4228 4206 iter->trace->open(iter); 4229 4207 4230 4208 /* Annotate start of buffers if we had overruns */ 4231 - if (ring_buffer_overruns(iter->trace_buffer->buffer)) 4209 + if (ring_buffer_overruns(iter->array_buffer->buffer)) 4232 4210 iter->iter_flags |= TRACE_FILE_ANNOTATE; 4233 4211 4234 4212 /* Output in nanoseconds only if we are using a clock in nanoseconds. */ ··· 4242 4220 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { 4243 4221 for_each_tracing_cpu(cpu) { 4244 4222 iter->buffer_iter[cpu] = 4245 - ring_buffer_read_prepare(iter->trace_buffer->buffer, 4223 + ring_buffer_read_prepare(iter->array_buffer->buffer, 4246 4224 cpu, GFP_KERNEL); 4247 4225 } 4248 4226 ring_buffer_read_prepare_sync(); ··· 4253 4231 } else { 4254 4232 cpu = iter->cpu_file; 4255 4233 iter->buffer_iter[cpu] = 4256 - ring_buffer_read_prepare(iter->trace_buffer->buffer, 4234 + ring_buffer_read_prepare(iter->array_buffer->buffer, 4257 4235 cpu, GFP_KERNEL); 4258 4236 ring_buffer_read_prepare_sync(); 4259 4237 ring_buffer_read_start(iter->buffer_iter[cpu]); ··· 4379 4357 /* If this file was open for write, then erase contents */ 4380 4358 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 4381 4359 int cpu = tracing_get_cpu(inode); 4382 - struct trace_buffer *trace_buf = &tr->trace_buffer; 4360 + struct array_buffer *trace_buf = &tr->array_buffer; 4383 4361 4384 4362 #ifdef CONFIG_TRACER_MAX_TRACE 4385 4363 if (tr->current_trace->print_max) ··· 4576 4554 return count; 4577 4555 } 4578 4556 4579 - static ssize_t 4580 - tracing_cpumask_write(struct file *filp, const char __user *ubuf, 4581 - size_t count, loff_t *ppos) 4557 + int tracing_set_cpumask(struct trace_array *tr, 4558 + cpumask_var_t tracing_cpumask_new) 4582 4559 { 4583 - struct trace_array *tr = file_inode(filp)->i_private; 4584 - cpumask_var_t tracing_cpumask_new; 4585 - int err, cpu; 4560 + int cpu; 4586 4561 4587 - if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) 4588 - return -ENOMEM; 4589 - 4590 - err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); 4591 - if (err) 4592 - goto err_unlock; 4562 + if (!tr) 4563 + return -EINVAL; 4593 4564 4594 4565 local_irq_disable(); 4595 4566 arch_spin_lock(&tr->max_lock); ··· 4593 4578 */ 4594 4579 if (cpumask_test_cpu(cpu, tr->tracing_cpumask) && 4595 4580 !cpumask_test_cpu(cpu, tracing_cpumask_new)) { 4596 - atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); 4597 - ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); 4581 + atomic_inc(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); 4582 + ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu); 4598 4583 } 4599 4584 if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && 4600 4585 cpumask_test_cpu(cpu, tracing_cpumask_new)) { 4601 - atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); 4602 - ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); 4586 + atomic_dec(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); 4587 + ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu); 4603 4588 } 4604 4589 } 4605 4590 arch_spin_unlock(&tr->max_lock); 4606 4591 local_irq_enable(); 4607 4592 4608 4593 cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); 4594 + 4595 + return 0; 4596 + } 4597 + 4598 + static ssize_t 4599 + tracing_cpumask_write(struct file *filp, const char __user *ubuf, 4600 + size_t count, loff_t *ppos) 4601 + { 4602 + struct trace_array *tr = file_inode(filp)->i_private; 4603 + cpumask_var_t tracing_cpumask_new; 4604 + int err; 4605 + 4606 + if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) 4607 + return -ENOMEM; 4608 + 4609 + err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); 4610 + if (err) 4611 + goto err_free; 4612 + 4613 + err = tracing_set_cpumask(tr, tracing_cpumask_new); 4614 + if (err) 4615 + goto err_free; 4616 + 4609 4617 free_cpumask_var(tracing_cpumask_new); 4610 4618 4611 4619 return count; 4612 4620 4613 - err_unlock: 4621 + err_free: 4614 4622 free_cpumask_var(tracing_cpumask_new); 4615 4623 4616 4624 return err; ··· 4764 4726 ftrace_pid_follow_fork(tr, enabled); 4765 4727 4766 4728 if (mask == TRACE_ITER_OVERWRITE) { 4767 - ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); 4729 + ring_buffer_change_overwrite(tr->array_buffer.buffer, enabled); 4768 4730 #ifdef CONFIG_TRACER_MAX_TRACE 4769 4731 ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); 4770 4732 #endif ··· 4778 4740 return 0; 4779 4741 } 4780 4742 4781 - static int trace_set_options(struct trace_array *tr, char *option) 4743 + int trace_set_options(struct trace_array *tr, char *option) 4782 4744 { 4783 4745 char *cmp; 4784 4746 int neg = 0; ··· 5399 5361 * Paranoid! If ptr points to end, we don't want to increment past it. 5400 5362 * This really should never happen. 5401 5363 */ 5364 + (*pos)++; 5402 5365 ptr = update_eval_map(ptr); 5403 5366 if (WARN_ON_ONCE(!ptr)) 5404 5367 return NULL; 5405 5368 5406 5369 ptr++; 5407 - 5408 - (*pos)++; 5409 - 5410 5370 ptr = update_eval_map(ptr); 5411 5371 5412 5372 return ptr; ··· 5570 5534 5571 5535 int tracer_init(struct tracer *t, struct trace_array *tr) 5572 5536 { 5573 - tracing_reset_online_cpus(&tr->trace_buffer); 5537 + tracing_reset_online_cpus(&tr->array_buffer); 5574 5538 return t->init(tr); 5575 5539 } 5576 5540 5577 - static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) 5541 + static void set_buffer_entries(struct array_buffer *buf, unsigned long val) 5578 5542 { 5579 5543 int cpu; 5580 5544 ··· 5584 5548 5585 5549 #ifdef CONFIG_TRACER_MAX_TRACE 5586 5550 /* resize @tr's buffer to the size of @size_tr's entries */ 5587 - static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, 5588 - struct trace_buffer *size_buf, int cpu_id) 5551 + static int resize_buffer_duplicate_size(struct array_buffer *trace_buf, 5552 + struct array_buffer *size_buf, int cpu_id) 5589 5553 { 5590 5554 int cpu, ret = 0; 5591 5555 ··· 5623 5587 ring_buffer_expanded = true; 5624 5588 5625 5589 /* May be called before buffers are initialized */ 5626 - if (!tr->trace_buffer.buffer) 5590 + if (!tr->array_buffer.buffer) 5627 5591 return 0; 5628 5592 5629 - ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); 5593 + ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu); 5630 5594 if (ret < 0) 5631 5595 return ret; 5632 5596 ··· 5637 5601 5638 5602 ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); 5639 5603 if (ret < 0) { 5640 - int r = resize_buffer_duplicate_size(&tr->trace_buffer, 5641 - &tr->trace_buffer, cpu); 5604 + int r = resize_buffer_duplicate_size(&tr->array_buffer, 5605 + &tr->array_buffer, cpu); 5642 5606 if (r < 0) { 5643 5607 /* 5644 5608 * AARGH! We are left with different ··· 5669 5633 #endif /* CONFIG_TRACER_MAX_TRACE */ 5670 5634 5671 5635 if (cpu == RING_BUFFER_ALL_CPUS) 5672 - set_buffer_entries(&tr->trace_buffer, size); 5636 + set_buffer_entries(&tr->array_buffer, size); 5673 5637 else 5674 - per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; 5638 + per_cpu_ptr(tr->array_buffer.data, cpu)->entries = size; 5675 5639 5676 5640 return ret; 5677 5641 } 5678 5642 5679 - static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, 5680 - unsigned long size, int cpu_id) 5643 + ssize_t tracing_resize_ring_buffer(struct trace_array *tr, 5644 + unsigned long size, int cpu_id) 5681 5645 { 5682 5646 int ret = size; 5683 5647 ··· 5756 5720 create_trace_option_files(tr, t); 5757 5721 } 5758 5722 5759 - static int tracing_set_tracer(struct trace_array *tr, const char *buf) 5723 + int tracing_set_tracer(struct trace_array *tr, const char *buf) 5760 5724 { 5761 5725 struct tracer *t; 5762 5726 #ifdef CONFIG_TRACER_MAX_TRACE ··· 6015 5979 iter->iter_flags |= TRACE_FILE_TIME_IN_NS; 6016 5980 6017 5981 iter->tr = tr; 6018 - iter->trace_buffer = &tr->trace_buffer; 5982 + iter->array_buffer = &tr->array_buffer; 6019 5983 iter->cpu_file = tracing_get_cpu(inode); 6020 5984 mutex_init(&iter->mutex); 6021 5985 filp->private_data = iter; ··· 6075 6039 */ 6076 6040 return EPOLLIN | EPOLLRDNORM; 6077 6041 else 6078 - return ring_buffer_poll_wait(iter->trace_buffer->buffer, iter->cpu_file, 6042 + return ring_buffer_poll_wait(iter->array_buffer->buffer, iter->cpu_file, 6079 6043 filp, poll_table); 6080 6044 } 6081 6045 ··· 6392 6356 for_each_tracing_cpu(cpu) { 6393 6357 /* fill in the size from first enabled cpu */ 6394 6358 if (size == 0) 6395 - size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; 6396 - if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { 6359 + size = per_cpu_ptr(tr->array_buffer.data, cpu)->entries; 6360 + if (size != per_cpu_ptr(tr->array_buffer.data, cpu)->entries) { 6397 6361 buf_size_same = 0; 6398 6362 break; 6399 6363 } ··· 6409 6373 } else 6410 6374 r = sprintf(buf, "X\n"); 6411 6375 } else 6412 - r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10); 6376 + r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->array_buffer.data, cpu)->entries >> 10); 6413 6377 6414 6378 mutex_unlock(&trace_types_lock); 6415 6379 ··· 6456 6420 6457 6421 mutex_lock(&trace_types_lock); 6458 6422 for_each_tracing_cpu(cpu) { 6459 - size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; 6423 + size += per_cpu_ptr(tr->array_buffer.data, cpu)->entries >> 10; 6460 6424 if (!ring_buffer_expanded) 6461 6425 expanded_size += trace_buf_size >> 10; 6462 6426 } ··· 6506 6470 struct trace_array *tr = filp->private_data; 6507 6471 struct ring_buffer_event *event; 6508 6472 enum event_trigger_type tt = ETT_NONE; 6509 - struct ring_buffer *buffer; 6473 + struct trace_buffer *buffer; 6510 6474 struct print_entry *entry; 6511 6475 unsigned long irq_flags; 6512 6476 ssize_t written; ··· 6535 6499 if (cnt < FAULTED_SIZE) 6536 6500 size += FAULTED_SIZE - cnt; 6537 6501 6538 - buffer = tr->trace_buffer.buffer; 6502 + buffer = tr->array_buffer.buffer; 6539 6503 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, 6540 6504 irq_flags, preempt_count()); 6541 6505 if (unlikely(!event)) ··· 6586 6550 { 6587 6551 struct trace_array *tr = filp->private_data; 6588 6552 struct ring_buffer_event *event; 6589 - struct ring_buffer *buffer; 6553 + struct trace_buffer *buffer; 6590 6554 struct raw_data_entry *entry; 6591 6555 unsigned long irq_flags; 6592 6556 ssize_t written; ··· 6615 6579 if (cnt < FAULT_SIZE_ID) 6616 6580 size += FAULT_SIZE_ID - cnt; 6617 6581 6618 - buffer = tr->trace_buffer.buffer; 6582 + buffer = tr->array_buffer.buffer; 6619 6583 event = __trace_buffer_lock_reserve(buffer, TRACE_RAW_DATA, size, 6620 6584 irq_flags, preempt_count()); 6621 6585 if (!event) ··· 6670 6634 6671 6635 tr->clock_id = i; 6672 6636 6673 - ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); 6637 + ring_buffer_set_clock(tr->array_buffer.buffer, trace_clocks[i].func); 6674 6638 6675 6639 /* 6676 6640 * New clock may not be consistent with the previous clock. 6677 6641 * Reset the buffer so that it doesn't have incomparable timestamps. 6678 6642 */ 6679 - tracing_reset_online_cpus(&tr->trace_buffer); 6643 + tracing_reset_online_cpus(&tr->array_buffer); 6680 6644 6681 6645 #ifdef CONFIG_TRACER_MAX_TRACE 6682 6646 if (tr->max_buffer.buffer) ··· 6739 6703 6740 6704 mutex_lock(&trace_types_lock); 6741 6705 6742 - if (ring_buffer_time_stamp_abs(tr->trace_buffer.buffer)) 6706 + if (ring_buffer_time_stamp_abs(tr->array_buffer.buffer)) 6743 6707 seq_puts(m, "delta [absolute]\n"); 6744 6708 else 6745 6709 seq_puts(m, "[delta] absolute\n"); ··· 6784 6748 goto out; 6785 6749 } 6786 6750 6787 - ring_buffer_set_time_stamp_abs(tr->trace_buffer.buffer, abs); 6751 + ring_buffer_set_time_stamp_abs(tr->array_buffer.buffer, abs); 6788 6752 6789 6753 #ifdef CONFIG_TRACER_MAX_TRACE 6790 6754 if (tr->max_buffer.buffer) ··· 6833 6797 ret = 0; 6834 6798 6835 6799 iter->tr = tr; 6836 - iter->trace_buffer = &tr->max_buffer; 6800 + iter->array_buffer = &tr->max_buffer; 6837 6801 iter->cpu_file = tracing_get_cpu(inode); 6838 6802 m->private = iter; 6839 6803 file->private_data = m; ··· 6896 6860 #endif 6897 6861 if (tr->allocated_snapshot) 6898 6862 ret = resize_buffer_duplicate_size(&tr->max_buffer, 6899 - &tr->trace_buffer, iter->cpu_file); 6863 + &tr->array_buffer, iter->cpu_file); 6900 6864 else 6901 6865 ret = tracing_alloc_snapshot_instance(tr); 6902 6866 if (ret < 0) ··· 6971 6935 } 6972 6936 6973 6937 info->iter.snapshot = true; 6974 - info->iter.trace_buffer = &info->iter.tr->max_buffer; 6938 + info->iter.array_buffer = &info->iter.tr->max_buffer; 6975 6939 6976 6940 return ret; 6977 6941 } ··· 7346 7310 info->iter.tr = tr; 7347 7311 info->iter.cpu_file = tracing_get_cpu(inode); 7348 7312 info->iter.trace = tr->current_trace; 7349 - info->iter.trace_buffer = &tr->trace_buffer; 7313 + info->iter.array_buffer = &tr->array_buffer; 7350 7314 info->spare = NULL; 7351 7315 /* Force reading ring buffer for first read */ 7352 7316 info->read = (unsigned int)-1; ··· 7391 7355 #endif 7392 7356 7393 7357 if (!info->spare) { 7394 - info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, 7358 + info->spare = ring_buffer_alloc_read_page(iter->array_buffer->buffer, 7395 7359 iter->cpu_file); 7396 7360 if (IS_ERR(info->spare)) { 7397 7361 ret = PTR_ERR(info->spare); ··· 7409 7373 7410 7374 again: 7411 7375 trace_access_lock(iter->cpu_file); 7412 - ret = ring_buffer_read_page(iter->trace_buffer->buffer, 7376 + ret = ring_buffer_read_page(iter->array_buffer->buffer, 7413 7377 &info->spare, 7414 7378 count, 7415 7379 iter->cpu_file, 0); ··· 7459 7423 __trace_array_put(iter->tr); 7460 7424 7461 7425 if (info->spare) 7462 - ring_buffer_free_read_page(iter->trace_buffer->buffer, 7426 + ring_buffer_free_read_page(iter->array_buffer->buffer, 7463 7427 info->spare_cpu, info->spare); 7464 7428 kfree(info); 7465 7429 ··· 7469 7433 } 7470 7434 7471 7435 struct buffer_ref { 7472 - struct ring_buffer *buffer; 7436 + struct trace_buffer *buffer; 7473 7437 void *page; 7474 7438 int cpu; 7475 7439 refcount_t refcount; ··· 7564 7528 7565 7529 again: 7566 7530 trace_access_lock(iter->cpu_file); 7567 - entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); 7531 + entries = ring_buffer_entries_cpu(iter->array_buffer->buffer, iter->cpu_file); 7568 7532 7569 7533 for (i = 0; i < spd.nr_pages_max && len && entries; i++, len -= PAGE_SIZE) { 7570 7534 struct page *page; ··· 7577 7541 } 7578 7542 7579 7543 refcount_set(&ref->refcount, 1); 7580 - ref->buffer = iter->trace_buffer->buffer; 7544 + ref->buffer = iter->array_buffer->buffer; 7581 7545 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); 7582 7546 if (IS_ERR(ref->page)) { 7583 7547 ret = PTR_ERR(ref->page); ··· 7605 7569 spd.nr_pages++; 7606 7570 *ppos += PAGE_SIZE; 7607 7571 7608 - entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); 7572 + entries = ring_buffer_entries_cpu(iter->array_buffer->buffer, iter->cpu_file); 7609 7573 } 7610 7574 7611 7575 trace_access_unlock(iter->cpu_file); ··· 7649 7613 { 7650 7614 struct inode *inode = file_inode(filp); 7651 7615 struct trace_array *tr = inode->i_private; 7652 - struct trace_buffer *trace_buf = &tr->trace_buffer; 7616 + struct array_buffer *trace_buf = &tr->array_buffer; 7653 7617 int cpu = tracing_get_cpu(inode); 7654 7618 struct trace_seq *s; 7655 7619 unsigned long cnt; ··· 7930 7894 7931 7895 tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer); 7932 7896 7933 - WARN_ONCE(!tr->percpu_dir, 7897 + MEM_FAIL(!tr->percpu_dir, 7934 7898 "Could not create tracefs directory 'per_cpu/%d'\n", cpu); 7935 7899 7936 7900 return tr->percpu_dir; ··· 8251 8215 for (cnt = 0; opts[cnt].name; cnt++) { 8252 8216 create_trace_option_file(tr, &topts[cnt], flags, 8253 8217 &opts[cnt]); 8254 - WARN_ONCE(topts[cnt].entry == NULL, 8218 + MEM_FAIL(topts[cnt].entry == NULL, 8255 8219 "Failed to create trace option: %s", 8256 8220 opts[cnt].name); 8257 8221 } ··· 8308 8272 size_t cnt, loff_t *ppos) 8309 8273 { 8310 8274 struct trace_array *tr = filp->private_data; 8311 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 8275 + struct trace_buffer *buffer = tr->array_buffer.buffer; 8312 8276 unsigned long val; 8313 8277 int ret; 8314 8278 ··· 8398 8362 init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer); 8399 8363 8400 8364 static int 8401 - allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size) 8365 + allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size) 8402 8366 { 8403 8367 enum ring_buffer_flags rb_flags; 8404 8368 ··· 8418 8382 } 8419 8383 8420 8384 /* Allocate the first page for all buffers */ 8421 - set_buffer_entries(&tr->trace_buffer, 8422 - ring_buffer_size(tr->trace_buffer.buffer, 0)); 8385 + set_buffer_entries(&tr->array_buffer, 8386 + ring_buffer_size(tr->array_buffer.buffer, 0)); 8423 8387 8424 8388 return 0; 8425 8389 } ··· 8428 8392 { 8429 8393 int ret; 8430 8394 8431 - ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); 8395 + ret = allocate_trace_buffer(tr, &tr->array_buffer, size); 8432 8396 if (ret) 8433 8397 return ret; 8434 8398 8435 8399 #ifdef CONFIG_TRACER_MAX_TRACE 8436 8400 ret = allocate_trace_buffer(tr, &tr->max_buffer, 8437 8401 allocate_snapshot ? size : 1); 8438 - if (WARN_ON(ret)) { 8439 - ring_buffer_free(tr->trace_buffer.buffer); 8440 - tr->trace_buffer.buffer = NULL; 8441 - free_percpu(tr->trace_buffer.data); 8442 - tr->trace_buffer.data = NULL; 8402 + if (MEM_FAIL(ret, "Failed to allocate trace buffer\n")) { 8403 + ring_buffer_free(tr->array_buffer.buffer); 8404 + tr->array_buffer.buffer = NULL; 8405 + free_percpu(tr->array_buffer.data); 8406 + tr->array_buffer.data = NULL; 8443 8407 return -ENOMEM; 8444 8408 } 8445 8409 tr->allocated_snapshot = allocate_snapshot; ··· 8453 8417 return 0; 8454 8418 } 8455 8419 8456 - static void free_trace_buffer(struct trace_buffer *buf) 8420 + static void free_trace_buffer(struct array_buffer *buf) 8457 8421 { 8458 8422 if (buf->buffer) { 8459 8423 ring_buffer_free(buf->buffer); ··· 8468 8432 if (!tr) 8469 8433 return; 8470 8434 8471 - free_trace_buffer(&tr->trace_buffer); 8435 + free_trace_buffer(&tr->array_buffer); 8472 8436 8473 8437 #ifdef CONFIG_TRACER_MAX_TRACE 8474 8438 free_trace_buffer(&tr->max_buffer); ··· 8497 8461 mutex_lock(&trace_types_lock); 8498 8462 __update_tracer_options(tr); 8499 8463 mutex_unlock(&trace_types_lock); 8464 + } 8465 + 8466 + /* Must have trace_types_lock held */ 8467 + struct trace_array *trace_array_find(const char *instance) 8468 + { 8469 + struct trace_array *tr, *found = NULL; 8470 + 8471 + list_for_each_entry(tr, &ftrace_trace_arrays, list) { 8472 + if (tr->name && strcmp(tr->name, instance) == 0) { 8473 + found = tr; 8474 + break; 8475 + } 8476 + } 8477 + 8478 + return found; 8479 + } 8480 + 8481 + struct trace_array *trace_array_find_get(const char *instance) 8482 + { 8483 + struct trace_array *tr; 8484 + 8485 + mutex_lock(&trace_types_lock); 8486 + tr = trace_array_find(instance); 8487 + if (tr) 8488 + tr->ref++; 8489 + mutex_unlock(&trace_types_lock); 8490 + 8491 + return tr; 8500 8492 } 8501 8493 8502 8494 static struct trace_array *trace_array_create(const char *name) ··· 8603 8539 mutex_lock(&trace_types_lock); 8604 8540 8605 8541 ret = -EEXIST; 8606 - list_for_each_entry(tr, &ftrace_trace_arrays, list) { 8607 - if (tr->name && strcmp(tr->name, name) == 0) 8608 - goto out_unlock; 8609 - } 8542 + if (trace_array_find(name)) 8543 + goto out_unlock; 8610 8544 8611 8545 tr = trace_array_create(name); 8612 8546 ··· 8626 8564 * NOTE: This function increments the reference counter associated with the 8627 8565 * trace array returned. This makes sure it cannot be freed while in use. 8628 8566 * Use trace_array_put() once the trace array is no longer needed. 8567 + * If the trace_array is to be freed, trace_array_destroy() needs to 8568 + * be called after the trace_array_put(), or simply let user space delete 8569 + * it from the tracefs instances directory. But until the 8570 + * trace_array_put() is called, user space can not delete it. 8629 8571 * 8630 8572 */ 8631 8573 struct trace_array *trace_array_get_by_name(const char *name) ··· 8732 8666 mutex_lock(&trace_types_lock); 8733 8667 8734 8668 ret = -ENODEV; 8735 - list_for_each_entry(tr, &ftrace_trace_arrays, list) { 8736 - if (tr->name && strcmp(tr->name, name) == 0) { 8737 - ret = __remove_instance(tr); 8738 - break; 8739 - } 8740 - } 8669 + tr = trace_array_find(name); 8670 + if (tr) 8671 + ret = __remove_instance(tr); 8741 8672 8742 8673 mutex_unlock(&trace_types_lock); 8743 8674 mutex_unlock(&event_mutex); ··· 8747 8684 trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer, 8748 8685 instance_mkdir, 8749 8686 instance_rmdir); 8750 - if (WARN_ON(!trace_instance_dir)) 8687 + if (MEM_FAIL(!trace_instance_dir, "Failed to create instances directory\n")) 8751 8688 return; 8752 8689 } 8753 8690 ··· 8817 8754 #endif 8818 8755 8819 8756 if (ftrace_create_function_files(tr, d_tracer)) 8820 - WARN(1, "Could not allocate function filter files"); 8757 + MEM_FAIL(1, "Could not allocate function filter files"); 8821 8758 8822 8759 #ifdef CONFIG_TRACER_SNAPSHOT 8823 8760 trace_create_file("snapshot", 0644, d_tracer, ··· 9099 9036 iter->tr = &global_trace; 9100 9037 iter->trace = iter->tr->current_trace; 9101 9038 iter->cpu_file = RING_BUFFER_ALL_CPUS; 9102 - iter->trace_buffer = &global_trace.trace_buffer; 9039 + iter->array_buffer = &global_trace.array_buffer; 9103 9040 9104 9041 if (iter->trace && iter->trace->open) 9105 9042 iter->trace->open(iter); 9106 9043 9107 9044 /* Annotate start of buffers if we had overruns */ 9108 - if (ring_buffer_overruns(iter->trace_buffer->buffer)) 9045 + if (ring_buffer_overruns(iter->array_buffer->buffer)) 9109 9046 iter->iter_flags |= TRACE_FILE_ANNOTATE; 9110 9047 9111 9048 /* Output in nanoseconds only if we are using a clock in nanoseconds. */ ··· 9146 9083 trace_init_global_iter(&iter); 9147 9084 9148 9085 for_each_tracing_cpu(cpu) { 9149 - atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 9086 + atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); 9150 9087 } 9151 9088 9152 9089 old_userobj = tr->trace_flags & TRACE_ITER_SYM_USEROBJ; ··· 9214 9151 tr->trace_flags |= old_userobj; 9215 9152 9216 9153 for_each_tracing_cpu(cpu) { 9217 - atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 9154 + atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); 9218 9155 } 9219 9156 atomic_dec(&dump_running); 9220 9157 printk_nmi_direct_exit(); ··· 9369 9306 9370 9307 /* TODO: make the number of buffers hot pluggable with CPUS */ 9371 9308 if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { 9372 - printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); 9373 - WARN_ON(1); 9309 + MEM_FAIL(1, "tracer: failed to allocate ring buffer!\n"); 9374 9310 goto out_free_savedcmd; 9375 9311 } 9376 9312 ··· 9442 9380 if (tracepoint_printk) { 9443 9381 tracepoint_print_iter = 9444 9382 kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL); 9445 - if (WARN_ON(!tracepoint_print_iter)) 9383 + if (MEM_FAIL(!tracepoint_print_iter, 9384 + "Failed to allocate trace iterator\n")) 9446 9385 tracepoint_printk = 0; 9447 9386 else 9448 9387 static_key_enable(&tracepoint_printk_key.key);
+74 -24
kernel/trace/trace.h
··· 93 93 94 94 #include "trace_entries.h" 95 95 96 + /* Use this for memory failure errors */ 97 + #define MEM_FAIL(condition, fmt, ...) ({ \ 98 + static bool __section(.data.once) __warned; \ 99 + int __ret_warn_once = !!(condition); \ 100 + \ 101 + if (unlikely(__ret_warn_once && !__warned)) { \ 102 + __warned = true; \ 103 + pr_err("ERROR: " fmt, ##__VA_ARGS__); \ 104 + } \ 105 + unlikely(__ret_warn_once); \ 106 + }) 107 + 96 108 /* 97 109 * syscalls are special, and need special handling, this is why 98 110 * they are not included in trace_entries.h ··· 187 175 struct tracer; 188 176 struct trace_option_dentry; 189 177 190 - struct trace_buffer { 178 + struct array_buffer { 191 179 struct trace_array *tr; 192 - struct ring_buffer *buffer; 180 + struct trace_buffer *buffer; 193 181 struct trace_array_cpu __percpu *data; 194 182 u64 time_start; 195 183 int cpu; ··· 260 248 struct trace_array { 261 249 struct list_head list; 262 250 char *name; 263 - struct trace_buffer trace_buffer; 251 + struct array_buffer array_buffer; 264 252 #ifdef CONFIG_TRACER_MAX_TRACE 265 253 /* 266 254 * The max_buffer is used to snapshot the trace when a maximum ··· 268 256 * Some tracers will use this to store a maximum trace while 269 257 * it continues examining live traces. 270 258 * 271 - * The buffers for the max_buffer are set up the same as the trace_buffer 259 + * The buffers for the max_buffer are set up the same as the array_buffer 272 260 * When a snapshot is taken, the buffer of the max_buffer is swapped 273 - * with the buffer of the trace_buffer and the buffers are reset for 274 - * the trace_buffer so the tracing can continue. 261 + * with the buffer of the array_buffer and the buffers are reset for 262 + * the array_buffer so the tracing can continue. 275 263 */ 276 - struct trace_buffer max_buffer; 264 + struct array_buffer max_buffer; 277 265 bool allocated_snapshot; 278 266 #endif 279 267 #if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) ··· 357 345 358 346 extern int trace_array_get(struct trace_array *tr); 359 347 extern int tracing_check_open_get_tr(struct trace_array *tr); 348 + extern struct trace_array *trace_array_find(const char *instance); 349 + extern struct trace_array *trace_array_find_get(const char *instance); 360 350 361 351 extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs); 362 352 extern int tracing_set_clock(struct trace_array *tr, const char *clockstr); ··· 698 684 699 685 int tracer_init(struct tracer *t, struct trace_array *tr); 700 686 int tracing_is_enabled(void); 701 - void tracing_reset_online_cpus(struct trace_buffer *buf); 687 + void tracing_reset_online_cpus(struct array_buffer *buf); 702 688 void tracing_reset_current(int cpu); 703 689 void tracing_reset_all_online_cpus(void); 704 690 int tracing_open_generic(struct inode *inode, struct file *filp); ··· 718 704 struct ring_buffer_event; 719 705 720 706 struct ring_buffer_event * 721 - trace_buffer_lock_reserve(struct ring_buffer *buffer, 707 + trace_buffer_lock_reserve(struct trace_buffer *buffer, 722 708 int type, 723 709 unsigned long len, 724 710 unsigned long flags, ··· 730 716 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, 731 717 int *ent_cpu, u64 *ent_ts); 732 718 733 - void trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer, 719 + void trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer, 734 720 struct ring_buffer_event *event); 735 721 736 722 int trace_empty(struct trace_iterator *iter); ··· 886 872 extern int 887 873 trace_array_vprintk(struct trace_array *tr, 888 874 unsigned long ip, const char *fmt, va_list args); 889 - int trace_array_printk_buf(struct ring_buffer *buffer, 875 + int trace_array_printk_buf(struct trace_buffer *buffer, 890 876 unsigned long ip, const char *fmt, ...); 891 877 void trace_printk_seq(struct trace_seq *s); 892 878 enum print_line_t print_trace_line(struct trace_iterator *iter); ··· 963 949 unsigned long flags, int pc); 964 950 965 951 #ifdef CONFIG_DYNAMIC_FTRACE 966 - extern struct ftrace_hash *ftrace_graph_hash; 967 - extern struct ftrace_hash *ftrace_graph_notrace_hash; 952 + extern struct ftrace_hash __rcu *ftrace_graph_hash; 953 + extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash; 968 954 969 955 static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace) 970 956 { 971 957 unsigned long addr = trace->func; 972 958 int ret = 0; 959 + struct ftrace_hash *hash; 973 960 974 961 preempt_disable_notrace(); 975 962 976 - if (ftrace_hash_empty(ftrace_graph_hash)) { 963 + /* 964 + * Have to open code "rcu_dereference_sched()" because the 965 + * function graph tracer can be called when RCU is not 966 + * "watching". 967 + * Protected with schedule_on_each_cpu(ftrace_sync) 968 + */ 969 + hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible()); 970 + 971 + if (ftrace_hash_empty(hash)) { 977 972 ret = 1; 978 973 goto out; 979 974 } 980 975 981 - if (ftrace_lookup_ip(ftrace_graph_hash, addr)) { 976 + if (ftrace_lookup_ip(hash, addr)) { 982 977 983 978 /* 984 979 * This needs to be cleared on the return functions ··· 1023 1000 static inline int ftrace_graph_notrace_addr(unsigned long addr) 1024 1001 { 1025 1002 int ret = 0; 1003 + struct ftrace_hash *notrace_hash; 1026 1004 1027 1005 preempt_disable_notrace(); 1028 1006 1029 - if (ftrace_lookup_ip(ftrace_graph_notrace_hash, addr)) 1007 + /* 1008 + * Have to open code "rcu_dereference_sched()" because the 1009 + * function graph tracer can be called when RCU is not 1010 + * "watching". 1011 + * Protected with schedule_on_each_cpu(ftrace_sync) 1012 + */ 1013 + notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash, 1014 + !preemptible()); 1015 + 1016 + if (ftrace_lookup_ip(notrace_hash, addr)) 1030 1017 ret = 1; 1031 1018 1032 1019 preempt_enable_notrace(); ··· 1089 1056 extern bool ftrace_filter_param __initdata; 1090 1057 static inline int ftrace_trace_task(struct trace_array *tr) 1091 1058 { 1092 - return !this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid); 1059 + return !this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid); 1093 1060 } 1094 1061 extern int ftrace_is_dead(void); 1095 1062 int ftrace_create_function_files(struct trace_array *tr, ··· 1177 1144 void ftrace_create_filter_files(struct ftrace_ops *ops, 1178 1145 struct dentry *parent); 1179 1146 void ftrace_destroy_filter_files(struct ftrace_ops *ops); 1147 + 1148 + extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf, 1149 + int len, int reset); 1150 + extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, 1151 + int len, int reset); 1180 1152 #else 1181 1153 struct ftrace_func_command; 1182 1154 ··· 1404 1366 }; 1405 1367 1406 1368 extern int call_filter_check_discard(struct trace_event_call *call, void *rec, 1407 - struct ring_buffer *buffer, 1369 + struct trace_buffer *buffer, 1408 1370 struct ring_buffer_event *event); 1409 1371 1410 1372 void trace_buffer_unlock_commit_regs(struct trace_array *tr, 1411 - struct ring_buffer *buffer, 1373 + struct trace_buffer *buffer, 1412 1374 struct ring_buffer_event *event, 1413 1375 unsigned long flags, int pc, 1414 1376 struct pt_regs *regs); 1415 1377 1416 1378 static inline void trace_buffer_unlock_commit(struct trace_array *tr, 1417 - struct ring_buffer *buffer, 1379 + struct trace_buffer *buffer, 1418 1380 struct ring_buffer_event *event, 1419 1381 unsigned long flags, int pc) 1420 1382 { ··· 1427 1389 void trace_buffered_event_enable(void); 1428 1390 1429 1391 static inline void 1430 - __trace_event_discard_commit(struct ring_buffer *buffer, 1392 + __trace_event_discard_commit(struct trace_buffer *buffer, 1431 1393 struct ring_buffer_event *event) 1432 1394 { 1433 1395 if (this_cpu_read(trace_buffered_event) == event) { ··· 1453 1415 */ 1454 1416 static inline bool 1455 1417 __event_trigger_test_discard(struct trace_event_file *file, 1456 - struct ring_buffer *buffer, 1418 + struct trace_buffer *buffer, 1457 1419 struct ring_buffer_event *event, 1458 1420 void *entry, 1459 1421 enum event_trigger_type *tt) ··· 1488 1450 */ 1489 1451 static inline void 1490 1452 event_trigger_unlock_commit(struct trace_event_file *file, 1491 - struct ring_buffer *buffer, 1453 + struct trace_buffer *buffer, 1492 1454 struct ring_buffer_event *event, 1493 1455 void *entry, unsigned long irq_flags, int pc) 1494 1456 { ··· 1519 1481 */ 1520 1482 static inline void 1521 1483 event_trigger_unlock_commit_regs(struct trace_event_file *file, 1522 - struct ring_buffer *buffer, 1484 + struct trace_buffer *buffer, 1523 1485 struct ring_buffer_event *event, 1524 1486 void *entry, unsigned long irq_flags, int pc, 1525 1487 struct pt_regs *regs) ··· 1930 1892 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set); 1931 1893 int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled); 1932 1894 1895 + /* Used from boot time tracer */ 1896 + extern int trace_set_options(struct trace_array *tr, char *option); 1897 + extern int tracing_set_tracer(struct trace_array *tr, const char *buf); 1898 + extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr, 1899 + unsigned long size, int cpu_id); 1900 + extern int tracing_set_cpumask(struct trace_array *tr, 1901 + cpumask_var_t tracing_cpumask_new); 1902 + 1903 + 1933 1904 #define MAX_EVENT_NAME_LEN 64 1934 1905 1935 1906 extern int trace_run_command(const char *buf, int (*createfn)(int, char**)); ··· 1996 1949 #ifdef CONFIG_EVENT_TRACING 1997 1950 void trace_event_init(void); 1998 1951 void trace_event_eval_update(struct trace_eval_map **map, int len); 1952 + /* Used from boot time tracer */ 1953 + extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set); 1954 + extern int trigger_process_regex(struct trace_event_file *file, char *buff); 1999 1955 #else 2000 1956 static inline void __init trace_event_init(void) { } 2001 1957 static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
+334
kernel/trace/trace_boot.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * trace_boot.c 4 + * Tracing kernel boot-time 5 + */ 6 + 7 + #define pr_fmt(fmt) "trace_boot: " fmt 8 + 9 + #include <linux/bootconfig.h> 10 + #include <linux/cpumask.h> 11 + #include <linux/ftrace.h> 12 + #include <linux/init.h> 13 + #include <linux/kernel.h> 14 + #include <linux/mutex.h> 15 + #include <linux/string.h> 16 + #include <linux/slab.h> 17 + #include <linux/trace.h> 18 + #include <linux/trace_events.h> 19 + 20 + #include "trace.h" 21 + 22 + #define MAX_BUF_LEN 256 23 + 24 + static void __init 25 + trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node) 26 + { 27 + struct xbc_node *anode; 28 + const char *p; 29 + char buf[MAX_BUF_LEN]; 30 + unsigned long v = 0; 31 + 32 + /* Common ftrace options */ 33 + xbc_node_for_each_array_value(node, "options", anode, p) { 34 + if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) { 35 + pr_err("String is too long: %s\n", p); 36 + continue; 37 + } 38 + 39 + if (trace_set_options(tr, buf) < 0) 40 + pr_err("Failed to set option: %s\n", buf); 41 + } 42 + 43 + p = xbc_node_find_value(node, "trace_clock", NULL); 44 + if (p && *p != '\0') { 45 + if (tracing_set_clock(tr, p) < 0) 46 + pr_err("Failed to set trace clock: %s\n", p); 47 + } 48 + 49 + p = xbc_node_find_value(node, "buffer_size", NULL); 50 + if (p && *p != '\0') { 51 + v = memparse(p, NULL); 52 + if (v < PAGE_SIZE) 53 + pr_err("Buffer size is too small: %s\n", p); 54 + if (tracing_resize_ring_buffer(tr, v, RING_BUFFER_ALL_CPUS) < 0) 55 + pr_err("Failed to resize trace buffer to %s\n", p); 56 + } 57 + 58 + p = xbc_node_find_value(node, "cpumask", NULL); 59 + if (p && *p != '\0') { 60 + cpumask_var_t new_mask; 61 + 62 + if (alloc_cpumask_var(&new_mask, GFP_KERNEL)) { 63 + if (cpumask_parse(p, new_mask) < 0 || 64 + tracing_set_cpumask(tr, new_mask) < 0) 65 + pr_err("Failed to set new CPU mask %s\n", p); 66 + free_cpumask_var(new_mask); 67 + } 68 + } 69 + } 70 + 71 + #ifdef CONFIG_EVENT_TRACING 72 + static void __init 73 + trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node) 74 + { 75 + struct xbc_node *anode; 76 + char buf[MAX_BUF_LEN]; 77 + const char *p; 78 + 79 + xbc_node_for_each_array_value(node, "events", anode, p) { 80 + if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) { 81 + pr_err("String is too long: %s\n", p); 82 + continue; 83 + } 84 + 85 + if (ftrace_set_clr_event(tr, buf, 1) < 0) 86 + pr_err("Failed to enable event: %s\n", p); 87 + } 88 + } 89 + 90 + #ifdef CONFIG_KPROBE_EVENTS 91 + static int __init 92 + trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) 93 + { 94 + struct dynevent_cmd cmd; 95 + struct xbc_node *anode; 96 + char buf[MAX_BUF_LEN]; 97 + const char *val; 98 + int ret; 99 + 100 + kprobe_event_cmd_init(&cmd, buf, MAX_BUF_LEN); 101 + 102 + ret = kprobe_event_gen_cmd_start(&cmd, event, NULL); 103 + if (ret) 104 + return ret; 105 + 106 + xbc_node_for_each_array_value(node, "probes", anode, val) { 107 + ret = kprobe_event_add_field(&cmd, val); 108 + if (ret) 109 + return ret; 110 + } 111 + 112 + ret = kprobe_event_gen_cmd_end(&cmd); 113 + if (ret) 114 + pr_err("Failed to add probe: %s\n", buf); 115 + 116 + return ret; 117 + } 118 + #else 119 + static inline int __init 120 + trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) 121 + { 122 + pr_err("Kprobe event is not supported.\n"); 123 + return -ENOTSUPP; 124 + } 125 + #endif 126 + 127 + #ifdef CONFIG_HIST_TRIGGERS 128 + static int __init 129 + trace_boot_add_synth_event(struct xbc_node *node, const char *event) 130 + { 131 + struct dynevent_cmd cmd; 132 + struct xbc_node *anode; 133 + char buf[MAX_BUF_LEN]; 134 + const char *p; 135 + int ret; 136 + 137 + synth_event_cmd_init(&cmd, buf, MAX_BUF_LEN); 138 + 139 + ret = synth_event_gen_cmd_start(&cmd, event, NULL); 140 + if (ret) 141 + return ret; 142 + 143 + xbc_node_for_each_array_value(node, "fields", anode, p) { 144 + ret = synth_event_add_field_str(&cmd, p); 145 + if (ret) 146 + return ret; 147 + } 148 + 149 + ret = synth_event_gen_cmd_end(&cmd); 150 + if (ret < 0) 151 + pr_err("Failed to add synthetic event: %s\n", buf); 152 + 153 + return ret; 154 + } 155 + #else 156 + static inline int __init 157 + trace_boot_add_synth_event(struct xbc_node *node, const char *event) 158 + { 159 + pr_err("Synthetic event is not supported.\n"); 160 + return -ENOTSUPP; 161 + } 162 + #endif 163 + 164 + static void __init 165 + trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, 166 + struct xbc_node *enode) 167 + { 168 + struct trace_event_file *file; 169 + struct xbc_node *anode; 170 + char buf[MAX_BUF_LEN]; 171 + const char *p, *group, *event; 172 + 173 + group = xbc_node_get_data(gnode); 174 + event = xbc_node_get_data(enode); 175 + 176 + if (!strcmp(group, "kprobes")) 177 + if (trace_boot_add_kprobe_event(enode, event) < 0) 178 + return; 179 + if (!strcmp(group, "synthetic")) 180 + if (trace_boot_add_synth_event(enode, event) < 0) 181 + return; 182 + 183 + mutex_lock(&event_mutex); 184 + file = find_event_file(tr, group, event); 185 + if (!file) { 186 + pr_err("Failed to find event: %s:%s\n", group, event); 187 + goto out; 188 + } 189 + 190 + p = xbc_node_find_value(enode, "filter", NULL); 191 + if (p && *p != '\0') { 192 + if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) 193 + pr_err("filter string is too long: %s\n", p); 194 + else if (apply_event_filter(file, buf) < 0) 195 + pr_err("Failed to apply filter: %s\n", buf); 196 + } 197 + 198 + xbc_node_for_each_array_value(enode, "actions", anode, p) { 199 + if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) 200 + pr_err("action string is too long: %s\n", p); 201 + else if (trigger_process_regex(file, buf) < 0) 202 + pr_err("Failed to apply an action: %s\n", buf); 203 + } 204 + 205 + if (xbc_node_find_value(enode, "enable", NULL)) { 206 + if (trace_event_enable_disable(file, 1, 0) < 0) 207 + pr_err("Failed to enable event node: %s:%s\n", 208 + group, event); 209 + } 210 + out: 211 + mutex_unlock(&event_mutex); 212 + } 213 + 214 + static void __init 215 + trace_boot_init_events(struct trace_array *tr, struct xbc_node *node) 216 + { 217 + struct xbc_node *gnode, *enode; 218 + 219 + node = xbc_node_find_child(node, "event"); 220 + if (!node) 221 + return; 222 + /* per-event key starts with "event.GROUP.EVENT" */ 223 + xbc_node_for_each_child(node, gnode) 224 + xbc_node_for_each_child(gnode, enode) 225 + trace_boot_init_one_event(tr, gnode, enode); 226 + } 227 + #else 228 + #define trace_boot_enable_events(tr, node) do {} while (0) 229 + #define trace_boot_init_events(tr, node) do {} while (0) 230 + #endif 231 + 232 + #ifdef CONFIG_DYNAMIC_FTRACE 233 + static void __init 234 + trace_boot_set_ftrace_filter(struct trace_array *tr, struct xbc_node *node) 235 + { 236 + struct xbc_node *anode; 237 + const char *p; 238 + char *q; 239 + 240 + xbc_node_for_each_array_value(node, "ftrace.filters", anode, p) { 241 + q = kstrdup(p, GFP_KERNEL); 242 + if (!q) 243 + return; 244 + if (ftrace_set_filter(tr->ops, q, strlen(q), 0) < 0) 245 + pr_err("Failed to add %s to ftrace filter\n", p); 246 + else 247 + ftrace_filter_param = true; 248 + kfree(q); 249 + } 250 + xbc_node_for_each_array_value(node, "ftrace.notraces", anode, p) { 251 + q = kstrdup(p, GFP_KERNEL); 252 + if (!q) 253 + return; 254 + if (ftrace_set_notrace(tr->ops, q, strlen(q), 0) < 0) 255 + pr_err("Failed to add %s to ftrace filter\n", p); 256 + else 257 + ftrace_filter_param = true; 258 + kfree(q); 259 + } 260 + } 261 + #else 262 + #define trace_boot_set_ftrace_filter(tr, node) do {} while (0) 263 + #endif 264 + 265 + static void __init 266 + trace_boot_enable_tracer(struct trace_array *tr, struct xbc_node *node) 267 + { 268 + const char *p; 269 + 270 + trace_boot_set_ftrace_filter(tr, node); 271 + 272 + p = xbc_node_find_value(node, "tracer", NULL); 273 + if (p && *p != '\0') { 274 + if (tracing_set_tracer(tr, p) < 0) 275 + pr_err("Failed to set given tracer: %s\n", p); 276 + } 277 + } 278 + 279 + static void __init 280 + trace_boot_init_one_instance(struct trace_array *tr, struct xbc_node *node) 281 + { 282 + trace_boot_set_instance_options(tr, node); 283 + trace_boot_init_events(tr, node); 284 + trace_boot_enable_events(tr, node); 285 + trace_boot_enable_tracer(tr, node); 286 + } 287 + 288 + static void __init 289 + trace_boot_init_instances(struct xbc_node *node) 290 + { 291 + struct xbc_node *inode; 292 + struct trace_array *tr; 293 + const char *p; 294 + 295 + node = xbc_node_find_child(node, "instance"); 296 + if (!node) 297 + return; 298 + 299 + xbc_node_for_each_child(node, inode) { 300 + p = xbc_node_get_data(inode); 301 + if (!p || *p == '\0') 302 + continue; 303 + 304 + tr = trace_array_get_by_name(p); 305 + if (!tr) { 306 + pr_err("Failed to get trace instance %s\n", p); 307 + continue; 308 + } 309 + trace_boot_init_one_instance(tr, inode); 310 + trace_array_put(tr); 311 + } 312 + } 313 + 314 + static int __init trace_boot_init(void) 315 + { 316 + struct xbc_node *trace_node; 317 + struct trace_array *tr; 318 + 319 + trace_node = xbc_find_node("ftrace"); 320 + if (!trace_node) 321 + return 0; 322 + 323 + tr = top_trace_array(); 324 + if (!tr) 325 + return 0; 326 + 327 + /* Global trace array is also one instance */ 328 + trace_boot_init_one_instance(tr, trace_node); 329 + trace_boot_init_instances(trace_node); 330 + 331 + return 0; 332 + } 333 + 334 + fs_initcall(trace_boot_init);
+3 -3
kernel/trace/trace_branch.c
··· 32 32 { 33 33 struct trace_event_call *call = &event_branch; 34 34 struct trace_array *tr = branch_tracer; 35 + struct trace_buffer *buffer; 35 36 struct trace_array_cpu *data; 36 37 struct ring_buffer_event *event; 37 38 struct trace_branch *entry; 38 - struct ring_buffer *buffer; 39 39 unsigned long flags; 40 40 int pc; 41 41 const char *p; ··· 55 55 56 56 raw_local_irq_save(flags); 57 57 current->trace_recursion |= TRACE_BRANCH_BIT; 58 - data = this_cpu_ptr(tr->trace_buffer.data); 58 + data = this_cpu_ptr(tr->array_buffer.data); 59 59 if (atomic_read(&data->disabled)) 60 60 goto out; 61 61 62 62 pc = preempt_count(); 63 - buffer = tr->trace_buffer.buffer; 63 + buffer = tr->array_buffer.buffer; 64 64 event = trace_buffer_lock_reserve(buffer, TRACE_BRANCH, 65 65 sizeof(*entry), flags, pc); 66 66 if (!event)
+212
kernel/trace/trace_dynevent.c
··· 223 223 return 0; 224 224 } 225 225 fs_initcall(init_dynamic_event); 226 + 227 + /** 228 + * dynevent_arg_add - Add an arg to a dynevent_cmd 229 + * @cmd: A pointer to the dynevent_cmd struct representing the new event cmd 230 + * @arg: The argument to append to the current cmd 231 + * @check_arg: An (optional) pointer to a function checking arg sanity 232 + * 233 + * Append an argument to a dynevent_cmd. The argument string will be 234 + * appended to the current cmd string, followed by a separator, if 235 + * applicable. Before the argument is added, the @check_arg function, 236 + * if present, will be used to check the sanity of the current arg 237 + * string. 238 + * 239 + * The cmd string and separator should be set using the 240 + * dynevent_arg_init() before any arguments are added using this 241 + * function. 242 + * 243 + * Return: 0 if successful, error otherwise. 244 + */ 245 + int dynevent_arg_add(struct dynevent_cmd *cmd, 246 + struct dynevent_arg *arg, 247 + dynevent_check_arg_fn_t check_arg) 248 + { 249 + int ret = 0; 250 + 251 + if (check_arg) { 252 + ret = check_arg(arg); 253 + if (ret) 254 + return ret; 255 + } 256 + 257 + ret = seq_buf_printf(&cmd->seq, " %s%c", arg->str, arg->separator); 258 + if (ret) { 259 + pr_err("String is too long: %s%c\n", arg->str, arg->separator); 260 + return -E2BIG; 261 + } 262 + 263 + return ret; 264 + } 265 + 266 + /** 267 + * dynevent_arg_pair_add - Add an arg pair to a dynevent_cmd 268 + * @cmd: A pointer to the dynevent_cmd struct representing the new event cmd 269 + * @arg_pair: The argument pair to append to the current cmd 270 + * @check_arg: An (optional) pointer to a function checking arg sanity 271 + * 272 + * Append an argument pair to a dynevent_cmd. An argument pair 273 + * consists of a left-hand-side argument and a right-hand-side 274 + * argument separated by an operator, which can be whitespace, all 275 + * followed by a separator, if applicable. This can be used to add 276 + * arguments of the form 'type variable_name;' or 'x+y'. 277 + * 278 + * The lhs argument string will be appended to the current cmd string, 279 + * followed by an operator, if applicable, followd by the rhs string, 280 + * followed finally by a separator, if applicable. Before the 281 + * argument is added, the @check_arg function, if present, will be 282 + * used to check the sanity of the current arg strings. 283 + * 284 + * The cmd strings, operator, and separator should be set using the 285 + * dynevent_arg_pair_init() before any arguments are added using this 286 + * function. 287 + * 288 + * Return: 0 if successful, error otherwise. 289 + */ 290 + int dynevent_arg_pair_add(struct dynevent_cmd *cmd, 291 + struct dynevent_arg_pair *arg_pair, 292 + dynevent_check_arg_fn_t check_arg) 293 + { 294 + int ret = 0; 295 + 296 + if (check_arg) { 297 + ret = check_arg(arg_pair); 298 + if (ret) 299 + return ret; 300 + } 301 + 302 + ret = seq_buf_printf(&cmd->seq, " %s%c%s%c", arg_pair->lhs, 303 + arg_pair->operator, arg_pair->rhs, 304 + arg_pair->separator); 305 + if (ret) { 306 + pr_err("field string is too long: %s%c%s%c\n", arg_pair->lhs, 307 + arg_pair->operator, arg_pair->rhs, 308 + arg_pair->separator); 309 + return -E2BIG; 310 + } 311 + 312 + return ret; 313 + } 314 + 315 + /** 316 + * dynevent_str_add - Add a string to a dynevent_cmd 317 + * @cmd: A pointer to the dynevent_cmd struct representing the new event cmd 318 + * @str: The string to append to the current cmd 319 + * 320 + * Append a string to a dynevent_cmd. The string will be appended to 321 + * the current cmd string as-is, with nothing prepended or appended. 322 + * 323 + * Return: 0 if successful, error otherwise. 324 + */ 325 + int dynevent_str_add(struct dynevent_cmd *cmd, const char *str) 326 + { 327 + int ret = 0; 328 + 329 + ret = seq_buf_puts(&cmd->seq, str); 330 + if (ret) { 331 + pr_err("String is too long: %s\n", str); 332 + return -E2BIG; 333 + } 334 + 335 + return ret; 336 + } 337 + 338 + /** 339 + * dynevent_cmd_init - Initialize a dynevent_cmd object 340 + * @cmd: A pointer to the dynevent_cmd struct representing the cmd 341 + * @buf: A pointer to the buffer to generate the command into 342 + * @maxlen: The length of the buffer the command will be generated into 343 + * @type: The type of the cmd, checked against further operations 344 + * @run_command: The type-specific function that will actually run the command 345 + * 346 + * Initialize a dynevent_cmd. A dynevent_cmd is used to build up and 347 + * run dynamic event creation commands, such as commands for creating 348 + * synthetic and kprobe events. Before calling any of the functions 349 + * used to build the command, a dynevent_cmd object should be 350 + * instantiated and initialized using this function. 351 + * 352 + * The initialization sets things up by saving a pointer to the 353 + * user-supplied buffer and its length via the @buf and @maxlen 354 + * params, and by saving the cmd-specific @type and @run_command 355 + * params which are used to check subsequent dynevent_cmd operations 356 + * and actually run the command when complete. 357 + */ 358 + void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen, 359 + enum dynevent_type type, 360 + dynevent_create_fn_t run_command) 361 + { 362 + memset(cmd, '\0', sizeof(*cmd)); 363 + 364 + seq_buf_init(&cmd->seq, buf, maxlen); 365 + cmd->type = type; 366 + cmd->run_command = run_command; 367 + } 368 + 369 + /** 370 + * dynevent_arg_init - Initialize a dynevent_arg object 371 + * @arg: A pointer to the dynevent_arg struct representing the arg 372 + * @separator: An (optional) separator, appended after adding the arg 373 + * 374 + * Initialize a dynevent_arg object. A dynevent_arg represents an 375 + * object used to append single arguments to the current command 376 + * string. After the arg string is successfully appended to the 377 + * command string, the optional @separator is appended. If no 378 + * separator was specified when initializing the arg, a space will be 379 + * appended. 380 + */ 381 + void dynevent_arg_init(struct dynevent_arg *arg, 382 + char separator) 383 + { 384 + memset(arg, '\0', sizeof(*arg)); 385 + 386 + if (!separator) 387 + separator = ' '; 388 + arg->separator = separator; 389 + } 390 + 391 + /** 392 + * dynevent_arg_pair_init - Initialize a dynevent_arg_pair object 393 + * @arg_pair: A pointer to the dynevent_arg_pair struct representing the arg 394 + * @operator: An (optional) operator, appended after adding the first arg 395 + * @separator: An (optional) separator, appended after adding the second arg 396 + * 397 + * Initialize a dynevent_arg_pair object. A dynevent_arg_pair 398 + * represents an object used to append argument pairs such as 'type 399 + * variable_name;' or 'x+y' to the current command string. An 400 + * argument pair consists of a left-hand-side argument and a 401 + * right-hand-side argument separated by an operator, which can be 402 + * whitespace, all followed by a separator, if applicable. After the 403 + * first arg string is successfully appended to the command string, 404 + * the optional @operator is appended, followed by the second arg and 405 + * and optional @separator. If no separator was specified when 406 + * initializing the arg, a space will be appended. 407 + */ 408 + void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair, 409 + char operator, char separator) 410 + { 411 + memset(arg_pair, '\0', sizeof(*arg_pair)); 412 + 413 + if (!operator) 414 + operator = ' '; 415 + arg_pair->operator = operator; 416 + 417 + if (!separator) 418 + separator = ' '; 419 + arg_pair->separator = separator; 420 + } 421 + 422 + /** 423 + * dynevent_create - Create the dynamic event contained in dynevent_cmd 424 + * @cmd: The dynevent_cmd object containing the dynamic event creation command 425 + * 426 + * Once a dynevent_cmd object has been successfully built up via the 427 + * dynevent_cmd_init(), dynevent_arg_add() and dynevent_arg_pair_add() 428 + * functions, this function runs the final command to actually create 429 + * the event. 430 + * 431 + * Return: 0 if the event was successfully created, error otherwise. 432 + */ 433 + int dynevent_create(struct dynevent_cmd *cmd) 434 + { 435 + return cmd->run_command(cmd); 436 + } 437 + EXPORT_SYMBOL_GPL(dynevent_create);
+32
kernel/trace/trace_dynevent.h
··· 117 117 #define for_each_dyn_event_safe(pos, n) \ 118 118 list_for_each_entry_safe(pos, n, &dyn_event_list, list) 119 119 120 + extern void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen, 121 + enum dynevent_type type, 122 + dynevent_create_fn_t run_command); 123 + 124 + typedef int (*dynevent_check_arg_fn_t)(void *data); 125 + 126 + struct dynevent_arg { 127 + const char *str; 128 + char separator; /* e.g. ';', ',', or nothing */ 129 + }; 130 + 131 + extern void dynevent_arg_init(struct dynevent_arg *arg, 132 + char separator); 133 + extern int dynevent_arg_add(struct dynevent_cmd *cmd, 134 + struct dynevent_arg *arg, 135 + dynevent_check_arg_fn_t check_arg); 136 + 137 + struct dynevent_arg_pair { 138 + const char *lhs; 139 + const char *rhs; 140 + char operator; /* e.g. '=' or nothing */ 141 + char separator; /* e.g. ';', ',', or nothing */ 142 + }; 143 + 144 + extern void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair, 145 + char operator, char separator); 146 + 147 + extern int dynevent_arg_pair_add(struct dynevent_cmd *cmd, 148 + struct dynevent_arg_pair *arg_pair, 149 + dynevent_check_arg_fn_t check_arg); 150 + extern int dynevent_str_add(struct dynevent_cmd *cmd, const char *str); 151 + 120 152 #endif
+1 -1
kernel/trace/trace_entries.h
··· 164 164 165 165 F_STRUCT( 166 166 __field( int, size ) 167 - __dynamic_array(unsigned long, caller ) 167 + __array( unsigned long, caller, FTRACE_STACK_ENTRIES ) 168 168 ), 169 169 170 170 F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
+96 -10
kernel/trace/trace_events.c
··· 238 238 if (!pid_list) 239 239 return false; 240 240 241 - data = this_cpu_ptr(tr->trace_buffer.data); 241 + data = this_cpu_ptr(tr->array_buffer.data); 242 242 243 243 return data->ignore_pid; 244 244 } ··· 273 273 if (!fbuffer->event) 274 274 return NULL; 275 275 276 + fbuffer->regs = NULL; 276 277 fbuffer->entry = ring_buffer_event_data(fbuffer->event); 277 278 return fbuffer->entry; 278 279 } ··· 548 547 549 548 pid_list = rcu_dereference_sched(tr->filtered_pids); 550 549 551 - this_cpu_write(tr->trace_buffer.data->ignore_pid, 550 + this_cpu_write(tr->array_buffer.data->ignore_pid, 552 551 trace_ignore_this_task(pid_list, prev) && 553 552 trace_ignore_this_task(pid_list, next)); 554 553 } ··· 562 561 563 562 pid_list = rcu_dereference_sched(tr->filtered_pids); 564 563 565 - this_cpu_write(tr->trace_buffer.data->ignore_pid, 564 + this_cpu_write(tr->array_buffer.data->ignore_pid, 566 565 trace_ignore_this_task(pid_list, next)); 567 566 } 568 567 ··· 573 572 struct trace_pid_list *pid_list; 574 573 575 574 /* Nothing to do if we are already tracing */ 576 - if (!this_cpu_read(tr->trace_buffer.data->ignore_pid)) 575 + if (!this_cpu_read(tr->array_buffer.data->ignore_pid)) 577 576 return; 578 577 579 578 pid_list = rcu_dereference_sched(tr->filtered_pids); 580 579 581 - this_cpu_write(tr->trace_buffer.data->ignore_pid, 580 + this_cpu_write(tr->array_buffer.data->ignore_pid, 582 581 trace_ignore_this_task(pid_list, task)); 583 582 } 584 583 ··· 589 588 struct trace_pid_list *pid_list; 590 589 591 590 /* Nothing to do if we are not tracing */ 592 - if (this_cpu_read(tr->trace_buffer.data->ignore_pid)) 591 + if (this_cpu_read(tr->array_buffer.data->ignore_pid)) 593 592 return; 594 593 595 594 pid_list = rcu_dereference_sched(tr->filtered_pids); 596 595 597 596 /* Set tracing if current is enabled */ 598 - this_cpu_write(tr->trace_buffer.data->ignore_pid, 597 + this_cpu_write(tr->array_buffer.data->ignore_pid, 599 598 trace_ignore_this_task(pid_list, current)); 600 599 } 601 600 ··· 627 626 } 628 627 629 628 for_each_possible_cpu(cpu) 630 - per_cpu_ptr(tr->trace_buffer.data, cpu)->ignore_pid = false; 629 + per_cpu_ptr(tr->array_buffer.data, cpu)->ignore_pid = false; 631 630 632 631 rcu_assign_pointer(tr->filtered_pids, NULL); 633 632 ··· 1596 1595 pid_list = rcu_dereference_protected(tr->filtered_pids, 1597 1596 mutex_is_locked(&event_mutex)); 1598 1597 1599 - this_cpu_write(tr->trace_buffer.data->ignore_pid, 1598 + this_cpu_write(tr->array_buffer.data->ignore_pid, 1600 1599 trace_ignore_this_task(pid_list, current)); 1601 1600 } 1602 1601 ··· 2554 2553 return file; 2555 2554 } 2556 2555 2556 + /** 2557 + * trace_get_event_file - Find and return a trace event file 2558 + * @instance: The name of the trace instance containing the event 2559 + * @system: The name of the system containing the event 2560 + * @event: The name of the event 2561 + * 2562 + * Return a trace event file given the trace instance name, trace 2563 + * system, and trace event name. If the instance name is NULL, it 2564 + * refers to the top-level trace array. 2565 + * 2566 + * This function will look it up and return it if found, after calling 2567 + * trace_array_get() to prevent the instance from going away, and 2568 + * increment the event's module refcount to prevent it from being 2569 + * removed. 2570 + * 2571 + * To release the file, call trace_put_event_file(), which will call 2572 + * trace_array_put() and decrement the event's module refcount. 2573 + * 2574 + * Return: The trace event on success, ERR_PTR otherwise. 2575 + */ 2576 + struct trace_event_file *trace_get_event_file(const char *instance, 2577 + const char *system, 2578 + const char *event) 2579 + { 2580 + struct trace_array *tr = top_trace_array(); 2581 + struct trace_event_file *file = NULL; 2582 + int ret = -EINVAL; 2583 + 2584 + if (instance) { 2585 + tr = trace_array_find_get(instance); 2586 + if (!tr) 2587 + return ERR_PTR(-ENOENT); 2588 + } else { 2589 + ret = trace_array_get(tr); 2590 + if (ret) 2591 + return ERR_PTR(ret); 2592 + } 2593 + 2594 + mutex_lock(&event_mutex); 2595 + 2596 + file = find_event_file(tr, system, event); 2597 + if (!file) { 2598 + trace_array_put(tr); 2599 + ret = -EINVAL; 2600 + goto out; 2601 + } 2602 + 2603 + /* Don't let event modules unload while in use */ 2604 + ret = try_module_get(file->event_call->mod); 2605 + if (!ret) { 2606 + trace_array_put(tr); 2607 + ret = -EBUSY; 2608 + goto out; 2609 + } 2610 + 2611 + ret = 0; 2612 + out: 2613 + mutex_unlock(&event_mutex); 2614 + 2615 + if (ret) 2616 + file = ERR_PTR(ret); 2617 + 2618 + return file; 2619 + } 2620 + EXPORT_SYMBOL_GPL(trace_get_event_file); 2621 + 2622 + /** 2623 + * trace_put_event_file - Release a file from trace_get_event_file() 2624 + * @file: The trace event file 2625 + * 2626 + * If a file was retrieved using trace_get_event_file(), this should 2627 + * be called when it's no longer needed. It will cancel the previous 2628 + * trace_array_get() called by that function, and decrement the 2629 + * event's module refcount. 2630 + */ 2631 + void trace_put_event_file(struct trace_event_file *file) 2632 + { 2633 + mutex_lock(&event_mutex); 2634 + module_put(file->event_call->mod); 2635 + mutex_unlock(&event_mutex); 2636 + 2637 + trace_array_put(file->tr); 2638 + } 2639 + EXPORT_SYMBOL_GPL(trace_put_event_file); 2640 + 2557 2641 #ifdef CONFIG_DYNAMIC_FTRACE 2558 2642 2559 2643 /* Avoid typos */ ··· 3495 3409 function_test_events_call(unsigned long ip, unsigned long parent_ip, 3496 3410 struct ftrace_ops *op, struct pt_regs *pt_regs) 3497 3411 { 3412 + struct trace_buffer *buffer; 3498 3413 struct ring_buffer_event *event; 3499 - struct ring_buffer *buffer; 3500 3414 struct ftrace_entry *entry; 3501 3415 unsigned long flags; 3502 3416 long disabled;
+943 -87
kernel/trace/trace_events_hist.c
··· 66 66 C(INVALID_SUBSYS_EVENT, "Invalid subsystem or event name"), \ 67 67 C(INVALID_REF_KEY, "Using variable references in keys not supported"), \ 68 68 C(VAR_NOT_FOUND, "Couldn't find variable"), \ 69 - C(FIELD_NOT_FOUND, "Couldn't find field"), 69 + C(FIELD_NOT_FOUND, "Couldn't find field"), \ 70 + C(EMPTY_ASSIGNMENT, "Empty assignment"), \ 71 + C(INVALID_SORT_MODIFIER,"Invalid sort modifier"), \ 72 + C(EMPTY_SORT_FIELD, "Empty sort field"), \ 73 + C(TOO_MANY_SORT_FIELDS, "Too many sort fields (Max = 2)"), \ 74 + C(INVALID_SORT_FIELD, "Sort field must be a key or a val"), 70 75 71 76 #undef C 72 77 #define C(a, b) HIST_ERR_##a ··· 380 375 unsigned int n_save_var_str; 381 376 }; 382 377 383 - static int synth_event_create(int argc, const char **argv); 378 + static int create_synth_event(int argc, const char **argv); 384 379 static int synth_event_show(struct seq_file *m, struct dyn_event *ev); 385 380 static int synth_event_release(struct dyn_event *ev); 386 381 static bool synth_event_is_busy(struct dyn_event *ev); ··· 388 383 int argc, const char **argv, struct dyn_event *ev); 389 384 390 385 static struct dyn_event_operations synth_event_ops = { 391 - .create = synth_event_create, 386 + .create = create_synth_event, 392 387 .show = synth_event_show, 393 388 .is_busy = synth_event_is_busy, 394 389 .free = synth_event_release, ··· 399 394 char *type; 400 395 char *name; 401 396 size_t size; 397 + unsigned int offset; 402 398 bool is_signed; 403 399 bool is_string; 404 400 }; ··· 414 408 struct trace_event_class class; 415 409 struct trace_event_call call; 416 410 struct tracepoint *tp; 411 + struct module *mod; 417 412 }; 418 413 419 414 static bool is_synth_event(struct dyn_event *ev) ··· 477 470 * When a histogram trigger is hit, the values of any 478 471 * references to variables, including variables being passed 479 472 * as parameters to synthetic events, are collected into a 480 - * var_ref_vals array. This var_ref_idx is the index of the 481 - * first param in the array to be passed to the synthetic 482 - * event invocation. 473 + * var_ref_vals array. This var_ref_idx array is an array of 474 + * indices into the var_ref_vals array, one for each synthetic 475 + * event param, and is passed to the synthetic event 476 + * invocation. 483 477 */ 484 - unsigned int var_ref_idx; 478 + unsigned int var_ref_idx[TRACING_MAP_VARS_MAX]; 485 479 struct synth_event *synth_event; 486 480 bool use_trace_keyword; 487 481 char *synth_event_name; ··· 616 608 if (!str) 617 609 return; 618 610 619 - strncpy(last_cmd, str, MAX_FILTER_STR_VAL - 1); 611 + strcpy(last_cmd, "hist:"); 612 + strncat(last_cmd, str, MAX_FILTER_STR_VAL - 1 - sizeof("hist:")); 620 613 621 614 if (file) { 622 615 call = file->event_call; ··· 670 661 is_signed, FILTER_OTHER); 671 662 if (ret) 672 663 break; 664 + 665 + event->fields[i]->offset = n_u64; 673 666 674 667 if (event->fields[i]->is_string) { 675 668 offset += STR_VAR_LEN_MAX; ··· 845 834 fmt = synth_field_fmt(se->fields[i]->type); 846 835 847 836 /* parameter types */ 848 - if (tr->trace_flags & TRACE_ITER_VERBOSE) 837 + if (tr && tr->trace_flags & TRACE_ITER_VERBOSE) 849 838 trace_seq_printf(s, "%s ", fmt); 850 839 851 840 snprintf(print_fmt, sizeof(print_fmt), "%%s=%s%%s", fmt); ··· 886 875 887 876 static notrace void trace_event_raw_event_synth(void *__data, 888 877 u64 *var_ref_vals, 889 - unsigned int var_ref_idx) 878 + unsigned int *var_ref_idx) 890 879 { 891 880 struct trace_event_file *trace_file = __data; 892 881 struct synth_trace_event *entry; 893 882 struct trace_event_buffer fbuffer; 894 - struct ring_buffer *buffer; 883 + struct trace_buffer *buffer; 895 884 struct synth_event *event; 896 - unsigned int i, n_u64; 885 + unsigned int i, n_u64, val_idx; 897 886 int fields_size = 0; 898 887 899 888 event = trace_file->event_call->data; ··· 907 896 * Avoid ring buffer recursion detection, as this event 908 897 * is being performed within another event. 909 898 */ 910 - buffer = trace_file->tr->trace_buffer.buffer; 899 + buffer = trace_file->tr->array_buffer.buffer; 911 900 ring_buffer_nest_start(buffer); 912 901 913 902 entry = trace_event_buffer_reserve(&fbuffer, trace_file, ··· 916 905 goto out; 917 906 918 907 for (i = 0, n_u64 = 0; i < event->n_fields; i++) { 908 + val_idx = var_ref_idx[i]; 919 909 if (event->fields[i]->is_string) { 920 - char *str_val = (char *)(long)var_ref_vals[var_ref_idx + i]; 910 + char *str_val = (char *)(long)var_ref_vals[val_idx]; 921 911 char *str_field = (char *)&entry->fields[n_u64]; 922 912 923 913 strscpy(str_field, str_val, STR_VAR_LEN_MAX); 924 914 n_u64 += STR_VAR_LEN_MAX / sizeof(u64); 925 915 } else { 926 916 struct synth_field *field = event->fields[i]; 927 - u64 val = var_ref_vals[var_ref_idx + i]; 917 + u64 val = var_ref_vals[val_idx]; 928 918 929 919 switch (field->size) { 930 920 case 1: ··· 1125 1113 } 1126 1114 1127 1115 typedef void (*synth_probe_func_t) (void *__data, u64 *var_ref_vals, 1128 - unsigned int var_ref_idx); 1116 + unsigned int *var_ref_idx); 1129 1117 1130 1118 static inline void trace_synth(struct synth_event *event, u64 *var_ref_vals, 1131 - unsigned int var_ref_idx) 1119 + unsigned int *var_ref_idx) 1132 1120 { 1133 1121 struct tracepoint *tp = event->tp; 1134 1122 ··· 1305 1293 struct hist_trigger_data *hist_data; 1306 1294 }; 1307 1295 1296 + static int synth_event_check_arg_fn(void *data) 1297 + { 1298 + struct dynevent_arg_pair *arg_pair = data; 1299 + int size; 1300 + 1301 + size = synth_field_size((char *)arg_pair->lhs); 1302 + 1303 + return size ? 0 : -EINVAL; 1304 + } 1305 + 1306 + /** 1307 + * synth_event_add_field - Add a new field to a synthetic event cmd 1308 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1309 + * @type: The type of the new field to add 1310 + * @name: The name of the new field to add 1311 + * 1312 + * Add a new field to a synthetic event cmd object. Field ordering is in 1313 + * the same order the fields are added. 1314 + * 1315 + * See synth_field_size() for available types. If field_name contains 1316 + * [n] the field is considered to be an array. 1317 + * 1318 + * Return: 0 if successful, error otherwise. 1319 + */ 1320 + int synth_event_add_field(struct dynevent_cmd *cmd, const char *type, 1321 + const char *name) 1322 + { 1323 + struct dynevent_arg_pair arg_pair; 1324 + int ret; 1325 + 1326 + if (cmd->type != DYNEVENT_TYPE_SYNTH) 1327 + return -EINVAL; 1328 + 1329 + if (!type || !name) 1330 + return -EINVAL; 1331 + 1332 + dynevent_arg_pair_init(&arg_pair, 0, ';'); 1333 + 1334 + arg_pair.lhs = type; 1335 + arg_pair.rhs = name; 1336 + 1337 + ret = dynevent_arg_pair_add(cmd, &arg_pair, synth_event_check_arg_fn); 1338 + if (ret) 1339 + return ret; 1340 + 1341 + if (++cmd->n_fields > SYNTH_FIELDS_MAX) 1342 + ret = -EINVAL; 1343 + 1344 + return ret; 1345 + } 1346 + EXPORT_SYMBOL_GPL(synth_event_add_field); 1347 + 1348 + /** 1349 + * synth_event_add_field_str - Add a new field to a synthetic event cmd 1350 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1351 + * @type_name: The type and name of the new field to add, as a single string 1352 + * 1353 + * Add a new field to a synthetic event cmd object, as a single 1354 + * string. The @type_name string is expected to be of the form 'type 1355 + * name', which will be appended by ';'. No sanity checking is done - 1356 + * what's passed in is assumed to already be well-formed. Field 1357 + * ordering is in the same order the fields are added. 1358 + * 1359 + * See synth_field_size() for available types. If field_name contains 1360 + * [n] the field is considered to be an array. 1361 + * 1362 + * Return: 0 if successful, error otherwise. 1363 + */ 1364 + int synth_event_add_field_str(struct dynevent_cmd *cmd, const char *type_name) 1365 + { 1366 + struct dynevent_arg arg; 1367 + int ret; 1368 + 1369 + if (cmd->type != DYNEVENT_TYPE_SYNTH) 1370 + return -EINVAL; 1371 + 1372 + if (!type_name) 1373 + return -EINVAL; 1374 + 1375 + dynevent_arg_init(&arg, ';'); 1376 + 1377 + arg.str = type_name; 1378 + 1379 + ret = dynevent_arg_add(cmd, &arg, NULL); 1380 + if (ret) 1381 + return ret; 1382 + 1383 + if (++cmd->n_fields > SYNTH_FIELDS_MAX) 1384 + ret = -EINVAL; 1385 + 1386 + return ret; 1387 + } 1388 + EXPORT_SYMBOL_GPL(synth_event_add_field_str); 1389 + 1390 + /** 1391 + * synth_event_add_fields - Add multiple fields to a synthetic event cmd 1392 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1393 + * @fields: An array of type/name field descriptions 1394 + * @n_fields: The number of field descriptions contained in the fields array 1395 + * 1396 + * Add a new set of fields to a synthetic event cmd object. The event 1397 + * fields that will be defined for the event should be passed in as an 1398 + * array of struct synth_field_desc, and the number of elements in the 1399 + * array passed in as n_fields. Field ordering will retain the 1400 + * ordering given in the fields array. 1401 + * 1402 + * See synth_field_size() for available types. If field_name contains 1403 + * [n] the field is considered to be an array. 1404 + * 1405 + * Return: 0 if successful, error otherwise. 1406 + */ 1407 + int synth_event_add_fields(struct dynevent_cmd *cmd, 1408 + struct synth_field_desc *fields, 1409 + unsigned int n_fields) 1410 + { 1411 + unsigned int i; 1412 + int ret = 0; 1413 + 1414 + for (i = 0; i < n_fields; i++) { 1415 + if (fields[i].type == NULL || fields[i].name == NULL) { 1416 + ret = -EINVAL; 1417 + break; 1418 + } 1419 + 1420 + ret = synth_event_add_field(cmd, fields[i].type, fields[i].name); 1421 + if (ret) 1422 + break; 1423 + } 1424 + 1425 + return ret; 1426 + } 1427 + EXPORT_SYMBOL_GPL(synth_event_add_fields); 1428 + 1429 + /** 1430 + * __synth_event_gen_cmd_start - Start a synthetic event command from arg list 1431 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1432 + * @name: The name of the synthetic event 1433 + * @mod: The module creating the event, NULL if not created from a module 1434 + * @args: Variable number of arg (pairs), one pair for each field 1435 + * 1436 + * NOTE: Users normally won't want to call this function directly, but 1437 + * rather use the synth_event_gen_cmd_start() wrapper, which 1438 + * automatically adds a NULL to the end of the arg list. If this 1439 + * function is used directly, make sure the last arg in the variable 1440 + * arg list is NULL. 1441 + * 1442 + * Generate a synthetic event command to be executed by 1443 + * synth_event_gen_cmd_end(). This function can be used to generate 1444 + * the complete command or only the first part of it; in the latter 1445 + * case, synth_event_add_field(), synth_event_add_field_str(), or 1446 + * synth_event_add_fields() can be used to add more fields following 1447 + * this. 1448 + * 1449 + * There should be an even number variable args, each pair consisting 1450 + * of a type followed by a field name. 1451 + * 1452 + * See synth_field_size() for available types. If field_name contains 1453 + * [n] the field is considered to be an array. 1454 + * 1455 + * Return: 0 if successful, error otherwise. 1456 + */ 1457 + int __synth_event_gen_cmd_start(struct dynevent_cmd *cmd, const char *name, 1458 + struct module *mod, ...) 1459 + { 1460 + struct dynevent_arg arg; 1461 + va_list args; 1462 + int ret; 1463 + 1464 + cmd->event_name = name; 1465 + cmd->private_data = mod; 1466 + 1467 + if (cmd->type != DYNEVENT_TYPE_SYNTH) 1468 + return -EINVAL; 1469 + 1470 + dynevent_arg_init(&arg, 0); 1471 + arg.str = name; 1472 + ret = dynevent_arg_add(cmd, &arg, NULL); 1473 + if (ret) 1474 + return ret; 1475 + 1476 + va_start(args, mod); 1477 + for (;;) { 1478 + const char *type, *name; 1479 + 1480 + type = va_arg(args, const char *); 1481 + if (!type) 1482 + break; 1483 + name = va_arg(args, const char *); 1484 + if (!name) 1485 + break; 1486 + 1487 + if (++cmd->n_fields > SYNTH_FIELDS_MAX) { 1488 + ret = -EINVAL; 1489 + break; 1490 + } 1491 + 1492 + ret = synth_event_add_field(cmd, type, name); 1493 + if (ret) 1494 + break; 1495 + } 1496 + va_end(args); 1497 + 1498 + return ret; 1499 + } 1500 + EXPORT_SYMBOL_GPL(__synth_event_gen_cmd_start); 1501 + 1502 + /** 1503 + * synth_event_gen_cmd_array_start - Start synthetic event command from an array 1504 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1505 + * @name: The name of the synthetic event 1506 + * @fields: An array of type/name field descriptions 1507 + * @n_fields: The number of field descriptions contained in the fields array 1508 + * 1509 + * Generate a synthetic event command to be executed by 1510 + * synth_event_gen_cmd_end(). This function can be used to generate 1511 + * the complete command or only the first part of it; in the latter 1512 + * case, synth_event_add_field(), synth_event_add_field_str(), or 1513 + * synth_event_add_fields() can be used to add more fields following 1514 + * this. 1515 + * 1516 + * The event fields that will be defined for the event should be 1517 + * passed in as an array of struct synth_field_desc, and the number of 1518 + * elements in the array passed in as n_fields. Field ordering will 1519 + * retain the ordering given in the fields array. 1520 + * 1521 + * See synth_field_size() for available types. If field_name contains 1522 + * [n] the field is considered to be an array. 1523 + * 1524 + * Return: 0 if successful, error otherwise. 1525 + */ 1526 + int synth_event_gen_cmd_array_start(struct dynevent_cmd *cmd, const char *name, 1527 + struct module *mod, 1528 + struct synth_field_desc *fields, 1529 + unsigned int n_fields) 1530 + { 1531 + struct dynevent_arg arg; 1532 + unsigned int i; 1533 + int ret = 0; 1534 + 1535 + cmd->event_name = name; 1536 + cmd->private_data = mod; 1537 + 1538 + if (cmd->type != DYNEVENT_TYPE_SYNTH) 1539 + return -EINVAL; 1540 + 1541 + if (n_fields > SYNTH_FIELDS_MAX) 1542 + return -EINVAL; 1543 + 1544 + dynevent_arg_init(&arg, 0); 1545 + arg.str = name; 1546 + ret = dynevent_arg_add(cmd, &arg, NULL); 1547 + if (ret) 1548 + return ret; 1549 + 1550 + for (i = 0; i < n_fields; i++) { 1551 + if (fields[i].type == NULL || fields[i].name == NULL) 1552 + return -EINVAL; 1553 + 1554 + ret = synth_event_add_field(cmd, fields[i].type, fields[i].name); 1555 + if (ret) 1556 + break; 1557 + } 1558 + 1559 + return ret; 1560 + } 1561 + EXPORT_SYMBOL_GPL(synth_event_gen_cmd_array_start); 1562 + 1308 1563 static int __create_synth_event(int argc, const char *name, const char **argv) 1309 1564 { 1310 1565 struct synth_field *field, *fields[SYNTH_FIELDS_MAX]; ··· 1640 1361 goto out; 1641 1362 } 1642 1363 1364 + /** 1365 + * synth_event_create - Create a new synthetic event 1366 + * @name: The name of the new sythetic event 1367 + * @fields: An array of type/name field descriptions 1368 + * @n_fields: The number of field descriptions contained in the fields array 1369 + * @mod: The module creating the event, NULL if not created from a module 1370 + * 1371 + * Create a new synthetic event with the given name under the 1372 + * trace/events/synthetic/ directory. The event fields that will be 1373 + * defined for the event should be passed in as an array of struct 1374 + * synth_field_desc, and the number elements in the array passed in as 1375 + * n_fields. Field ordering will retain the ordering given in the 1376 + * fields array. 1377 + * 1378 + * If the new synthetic event is being created from a module, the mod 1379 + * param must be non-NULL. This will ensure that the trace buffer 1380 + * won't contain unreadable events. 1381 + * 1382 + * The new synth event should be deleted using synth_event_delete() 1383 + * function. The new synthetic event can be generated from modules or 1384 + * other kernel code using trace_synth_event() and related functions. 1385 + * 1386 + * Return: 0 if successful, error otherwise. 1387 + */ 1388 + int synth_event_create(const char *name, struct synth_field_desc *fields, 1389 + unsigned int n_fields, struct module *mod) 1390 + { 1391 + struct dynevent_cmd cmd; 1392 + char *buf; 1393 + int ret; 1394 + 1395 + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); 1396 + if (!buf) 1397 + return -ENOMEM; 1398 + 1399 + synth_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); 1400 + 1401 + ret = synth_event_gen_cmd_array_start(&cmd, name, mod, 1402 + fields, n_fields); 1403 + if (ret) 1404 + goto out; 1405 + 1406 + ret = synth_event_gen_cmd_end(&cmd); 1407 + out: 1408 + kfree(buf); 1409 + 1410 + return ret; 1411 + } 1412 + EXPORT_SYMBOL_GPL(synth_event_create); 1413 + 1414 + static int destroy_synth_event(struct synth_event *se) 1415 + { 1416 + int ret; 1417 + 1418 + if (se->ref) 1419 + ret = -EBUSY; 1420 + else { 1421 + ret = unregister_synth_event(se); 1422 + if (!ret) { 1423 + dyn_event_remove(&se->devent); 1424 + free_synth_event(se); 1425 + } 1426 + } 1427 + 1428 + return ret; 1429 + } 1430 + 1431 + /** 1432 + * synth_event_delete - Delete a synthetic event 1433 + * @event_name: The name of the new sythetic event 1434 + * 1435 + * Delete a synthetic event that was created with synth_event_create(). 1436 + * 1437 + * Return: 0 if successful, error otherwise. 1438 + */ 1439 + int synth_event_delete(const char *event_name) 1440 + { 1441 + struct synth_event *se = NULL; 1442 + struct module *mod = NULL; 1443 + int ret = -ENOENT; 1444 + 1445 + mutex_lock(&event_mutex); 1446 + se = find_synth_event(event_name); 1447 + if (se) { 1448 + mod = se->mod; 1449 + ret = destroy_synth_event(se); 1450 + } 1451 + mutex_unlock(&event_mutex); 1452 + 1453 + if (mod) { 1454 + mutex_lock(&trace_types_lock); 1455 + /* 1456 + * It is safest to reset the ring buffer if the module 1457 + * being unloaded registered any events that were 1458 + * used. The only worry is if a new module gets 1459 + * loaded, and takes on the same id as the events of 1460 + * this module. When printing out the buffer, traced 1461 + * events left over from this module may be passed to 1462 + * the new module events and unexpected results may 1463 + * occur. 1464 + */ 1465 + tracing_reset_all_online_cpus(); 1466 + mutex_unlock(&trace_types_lock); 1467 + } 1468 + 1469 + return ret; 1470 + } 1471 + EXPORT_SYMBOL_GPL(synth_event_delete); 1472 + 1643 1473 static int create_or_delete_synth_event(int argc, char **argv) 1644 1474 { 1645 1475 const char *name = argv[0]; 1646 - struct synth_event *event = NULL; 1647 1476 int ret; 1648 1477 1649 1478 /* trace_run_command() ensures argc != 0 */ 1650 1479 if (name[0] == '!') { 1651 - mutex_lock(&event_mutex); 1652 - event = find_synth_event(name + 1); 1653 - if (event) { 1654 - if (event->ref) 1655 - ret = -EBUSY; 1656 - else { 1657 - ret = unregister_synth_event(event); 1658 - if (!ret) { 1659 - dyn_event_remove(&event->devent); 1660 - free_synth_event(event); 1661 - } 1662 - } 1663 - } else 1664 - ret = -ENOENT; 1665 - mutex_unlock(&event_mutex); 1480 + ret = synth_event_delete(name + 1); 1666 1481 return ret; 1667 1482 } 1668 1483 ··· 1764 1391 return ret == -ECANCELED ? -EINVAL : ret; 1765 1392 } 1766 1393 1767 - static int synth_event_create(int argc, const char **argv) 1394 + static int synth_event_run_command(struct dynevent_cmd *cmd) 1395 + { 1396 + struct synth_event *se; 1397 + int ret; 1398 + 1399 + ret = trace_run_command(cmd->seq.buffer, create_or_delete_synth_event); 1400 + if (ret) 1401 + return ret; 1402 + 1403 + se = find_synth_event(cmd->event_name); 1404 + if (WARN_ON(!se)) 1405 + return -ENOENT; 1406 + 1407 + se->mod = cmd->private_data; 1408 + 1409 + return ret; 1410 + } 1411 + 1412 + /** 1413 + * synth_event_cmd_init - Initialize a synthetic event command object 1414 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 1415 + * @buf: A pointer to the buffer used to build the command 1416 + * @maxlen: The length of the buffer passed in @buf 1417 + * 1418 + * Initialize a synthetic event command object. Use this before 1419 + * calling any of the other dyenvent_cmd functions. 1420 + */ 1421 + void synth_event_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen) 1422 + { 1423 + dynevent_cmd_init(cmd, buf, maxlen, DYNEVENT_TYPE_SYNTH, 1424 + synth_event_run_command); 1425 + } 1426 + EXPORT_SYMBOL_GPL(synth_event_cmd_init); 1427 + 1428 + /** 1429 + * synth_event_trace - Trace a synthetic event 1430 + * @file: The trace_event_file representing the synthetic event 1431 + * @n_vals: The number of values in vals 1432 + * @args: Variable number of args containing the event values 1433 + * 1434 + * Trace a synthetic event using the values passed in the variable 1435 + * argument list. 1436 + * 1437 + * The argument list should be a list 'n_vals' u64 values. The number 1438 + * of vals must match the number of field in the synthetic event, and 1439 + * must be in the same order as the synthetic event fields. 1440 + * 1441 + * All vals should be cast to u64, and string vals are just pointers 1442 + * to strings, cast to u64. Strings will be copied into space 1443 + * reserved in the event for the string, using these pointers. 1444 + * 1445 + * Return: 0 on success, err otherwise. 1446 + */ 1447 + int synth_event_trace(struct trace_event_file *file, unsigned int n_vals, ...) 1448 + { 1449 + struct trace_event_buffer fbuffer; 1450 + struct synth_trace_event *entry; 1451 + struct trace_buffer *buffer; 1452 + struct synth_event *event; 1453 + unsigned int i, n_u64; 1454 + int fields_size = 0; 1455 + va_list args; 1456 + int ret = 0; 1457 + 1458 + /* 1459 + * Normal event generation doesn't get called at all unless 1460 + * the ENABLED bit is set (which attaches the probe thus 1461 + * allowing this code to be called, etc). Because this is 1462 + * called directly by the user, we don't have that but we 1463 + * still need to honor not logging when disabled. 1464 + */ 1465 + if (!(file->flags & EVENT_FILE_FL_ENABLED)) 1466 + return 0; 1467 + 1468 + event = file->event_call->data; 1469 + 1470 + if (n_vals != event->n_fields) 1471 + return -EINVAL; 1472 + 1473 + if (trace_trigger_soft_disabled(file)) 1474 + return -EINVAL; 1475 + 1476 + fields_size = event->n_u64 * sizeof(u64); 1477 + 1478 + /* 1479 + * Avoid ring buffer recursion detection, as this event 1480 + * is being performed within another event. 1481 + */ 1482 + buffer = file->tr->array_buffer.buffer; 1483 + ring_buffer_nest_start(buffer); 1484 + 1485 + entry = trace_event_buffer_reserve(&fbuffer, file, 1486 + sizeof(*entry) + fields_size); 1487 + if (!entry) { 1488 + ret = -EINVAL; 1489 + goto out; 1490 + } 1491 + 1492 + va_start(args, n_vals); 1493 + for (i = 0, n_u64 = 0; i < event->n_fields; i++) { 1494 + u64 val; 1495 + 1496 + val = va_arg(args, u64); 1497 + 1498 + if (event->fields[i]->is_string) { 1499 + char *str_val = (char *)(long)val; 1500 + char *str_field = (char *)&entry->fields[n_u64]; 1501 + 1502 + strscpy(str_field, str_val, STR_VAR_LEN_MAX); 1503 + n_u64 += STR_VAR_LEN_MAX / sizeof(u64); 1504 + } else { 1505 + entry->fields[n_u64] = val; 1506 + n_u64++; 1507 + } 1508 + } 1509 + va_end(args); 1510 + 1511 + trace_event_buffer_commit(&fbuffer); 1512 + out: 1513 + ring_buffer_nest_end(buffer); 1514 + 1515 + return ret; 1516 + } 1517 + EXPORT_SYMBOL_GPL(synth_event_trace); 1518 + 1519 + /** 1520 + * synth_event_trace_array - Trace a synthetic event from an array 1521 + * @file: The trace_event_file representing the synthetic event 1522 + * @vals: Array of values 1523 + * @n_vals: The number of values in vals 1524 + * 1525 + * Trace a synthetic event using the values passed in as 'vals'. 1526 + * 1527 + * The 'vals' array is just an array of 'n_vals' u64. The number of 1528 + * vals must match the number of field in the synthetic event, and 1529 + * must be in the same order as the synthetic event fields. 1530 + * 1531 + * All vals should be cast to u64, and string vals are just pointers 1532 + * to strings, cast to u64. Strings will be copied into space 1533 + * reserved in the event for the string, using these pointers. 1534 + * 1535 + * Return: 0 on success, err otherwise. 1536 + */ 1537 + int synth_event_trace_array(struct trace_event_file *file, u64 *vals, 1538 + unsigned int n_vals) 1539 + { 1540 + struct trace_event_buffer fbuffer; 1541 + struct synth_trace_event *entry; 1542 + struct trace_buffer *buffer; 1543 + struct synth_event *event; 1544 + unsigned int i, n_u64; 1545 + int fields_size = 0; 1546 + int ret = 0; 1547 + 1548 + /* 1549 + * Normal event generation doesn't get called at all unless 1550 + * the ENABLED bit is set (which attaches the probe thus 1551 + * allowing this code to be called, etc). Because this is 1552 + * called directly by the user, we don't have that but we 1553 + * still need to honor not logging when disabled. 1554 + */ 1555 + if (!(file->flags & EVENT_FILE_FL_ENABLED)) 1556 + return 0; 1557 + 1558 + event = file->event_call->data; 1559 + 1560 + if (n_vals != event->n_fields) 1561 + return -EINVAL; 1562 + 1563 + if (trace_trigger_soft_disabled(file)) 1564 + return -EINVAL; 1565 + 1566 + fields_size = event->n_u64 * sizeof(u64); 1567 + 1568 + /* 1569 + * Avoid ring buffer recursion detection, as this event 1570 + * is being performed within another event. 1571 + */ 1572 + buffer = file->tr->array_buffer.buffer; 1573 + ring_buffer_nest_start(buffer); 1574 + 1575 + entry = trace_event_buffer_reserve(&fbuffer, file, 1576 + sizeof(*entry) + fields_size); 1577 + if (!entry) { 1578 + ret = -EINVAL; 1579 + goto out; 1580 + } 1581 + 1582 + for (i = 0, n_u64 = 0; i < event->n_fields; i++) { 1583 + if (event->fields[i]->is_string) { 1584 + char *str_val = (char *)(long)vals[i]; 1585 + char *str_field = (char *)&entry->fields[n_u64]; 1586 + 1587 + strscpy(str_field, str_val, STR_VAR_LEN_MAX); 1588 + n_u64 += STR_VAR_LEN_MAX / sizeof(u64); 1589 + } else { 1590 + entry->fields[n_u64] = vals[i]; 1591 + n_u64++; 1592 + } 1593 + } 1594 + 1595 + trace_event_buffer_commit(&fbuffer); 1596 + out: 1597 + ring_buffer_nest_end(buffer); 1598 + 1599 + return ret; 1600 + } 1601 + EXPORT_SYMBOL_GPL(synth_event_trace_array); 1602 + 1603 + /** 1604 + * synth_event_trace_start - Start piecewise synthetic event trace 1605 + * @file: The trace_event_file representing the synthetic event 1606 + * @trace_state: A pointer to object tracking the piecewise trace state 1607 + * 1608 + * Start the trace of a synthetic event field-by-field rather than all 1609 + * at once. 1610 + * 1611 + * This function 'opens' an event trace, which means space is reserved 1612 + * for the event in the trace buffer, after which the event's 1613 + * individual field values can be set through either 1614 + * synth_event_add_next_val() or synth_event_add_val(). 1615 + * 1616 + * A pointer to a trace_state object is passed in, which will keep 1617 + * track of the current event trace state until the event trace is 1618 + * closed (and the event finally traced) using 1619 + * synth_event_trace_end(). 1620 + * 1621 + * Note that synth_event_trace_end() must be called after all values 1622 + * have been added for each event trace, regardless of whether adding 1623 + * all field values succeeded or not. 1624 + * 1625 + * Note also that for a given event trace, all fields must be added 1626 + * using either synth_event_add_next_val() or synth_event_add_val() 1627 + * but not both together or interleaved. 1628 + * 1629 + * Return: 0 on success, err otherwise. 1630 + */ 1631 + int synth_event_trace_start(struct trace_event_file *file, 1632 + struct synth_event_trace_state *trace_state) 1633 + { 1634 + struct synth_trace_event *entry; 1635 + int fields_size = 0; 1636 + int ret = 0; 1637 + 1638 + if (!trace_state) { 1639 + ret = -EINVAL; 1640 + goto out; 1641 + } 1642 + 1643 + memset(trace_state, '\0', sizeof(*trace_state)); 1644 + 1645 + /* 1646 + * Normal event tracing doesn't get called at all unless the 1647 + * ENABLED bit is set (which attaches the probe thus allowing 1648 + * this code to be called, etc). Because this is called 1649 + * directly by the user, we don't have that but we still need 1650 + * to honor not logging when disabled. For the the iterated 1651 + * trace case, we save the enabed state upon start and just 1652 + * ignore the following data calls. 1653 + */ 1654 + if (!(file->flags & EVENT_FILE_FL_ENABLED)) { 1655 + trace_state->enabled = false; 1656 + goto out; 1657 + } 1658 + 1659 + trace_state->enabled = true; 1660 + 1661 + trace_state->event = file->event_call->data; 1662 + 1663 + if (trace_trigger_soft_disabled(file)) { 1664 + ret = -EINVAL; 1665 + goto out; 1666 + } 1667 + 1668 + fields_size = trace_state->event->n_u64 * sizeof(u64); 1669 + 1670 + /* 1671 + * Avoid ring buffer recursion detection, as this event 1672 + * is being performed within another event. 1673 + */ 1674 + trace_state->buffer = file->tr->array_buffer.buffer; 1675 + ring_buffer_nest_start(trace_state->buffer); 1676 + 1677 + entry = trace_event_buffer_reserve(&trace_state->fbuffer, file, 1678 + sizeof(*entry) + fields_size); 1679 + if (!entry) { 1680 + ret = -EINVAL; 1681 + goto out; 1682 + } 1683 + 1684 + trace_state->entry = entry; 1685 + out: 1686 + return ret; 1687 + } 1688 + EXPORT_SYMBOL_GPL(synth_event_trace_start); 1689 + 1690 + static int __synth_event_add_val(const char *field_name, u64 val, 1691 + struct synth_event_trace_state *trace_state) 1692 + { 1693 + struct synth_field *field = NULL; 1694 + struct synth_trace_event *entry; 1695 + struct synth_event *event; 1696 + int i, ret = 0; 1697 + 1698 + if (!trace_state) { 1699 + ret = -EINVAL; 1700 + goto out; 1701 + } 1702 + 1703 + /* can't mix add_next_synth_val() with add_synth_val() */ 1704 + if (field_name) { 1705 + if (trace_state->add_next) { 1706 + ret = -EINVAL; 1707 + goto out; 1708 + } 1709 + trace_state->add_name = true; 1710 + } else { 1711 + if (trace_state->add_name) { 1712 + ret = -EINVAL; 1713 + goto out; 1714 + } 1715 + trace_state->add_next = true; 1716 + } 1717 + 1718 + if (!trace_state->enabled) 1719 + goto out; 1720 + 1721 + event = trace_state->event; 1722 + if (trace_state->add_name) { 1723 + for (i = 0; i < event->n_fields; i++) { 1724 + field = event->fields[i]; 1725 + if (strcmp(field->name, field_name) == 0) 1726 + break; 1727 + } 1728 + if (!field) { 1729 + ret = -EINVAL; 1730 + goto out; 1731 + } 1732 + } else { 1733 + if (trace_state->cur_field >= event->n_fields) { 1734 + ret = -EINVAL; 1735 + goto out; 1736 + } 1737 + field = event->fields[trace_state->cur_field++]; 1738 + } 1739 + 1740 + entry = trace_state->entry; 1741 + if (field->is_string) { 1742 + char *str_val = (char *)(long)val; 1743 + char *str_field; 1744 + 1745 + if (!str_val) { 1746 + ret = -EINVAL; 1747 + goto out; 1748 + } 1749 + 1750 + str_field = (char *)&entry->fields[field->offset]; 1751 + strscpy(str_field, str_val, STR_VAR_LEN_MAX); 1752 + } else 1753 + entry->fields[field->offset] = val; 1754 + out: 1755 + return ret; 1756 + } 1757 + 1758 + /** 1759 + * synth_event_add_next_val - Add the next field's value to an open synth trace 1760 + * @val: The value to set the next field to 1761 + * @trace_state: A pointer to object tracking the piecewise trace state 1762 + * 1763 + * Set the value of the next field in an event that's been opened by 1764 + * synth_event_trace_start(). 1765 + * 1766 + * The val param should be the value cast to u64. If the value points 1767 + * to a string, the val param should be a char * cast to u64. 1768 + * 1769 + * This function assumes all the fields in an event are to be set one 1770 + * after another - successive calls to this function are made, one for 1771 + * each field, in the order of the fields in the event, until all 1772 + * fields have been set. If you'd rather set each field individually 1773 + * without regard to ordering, synth_event_add_val() can be used 1774 + * instead. 1775 + * 1776 + * Note however that synth_event_add_next_val() and 1777 + * synth_event_add_val() can't be intermixed for a given event trace - 1778 + * one or the other but not both can be used at the same time. 1779 + * 1780 + * Note also that synth_event_trace_end() must be called after all 1781 + * values have been added for each event trace, regardless of whether 1782 + * adding all field values succeeded or not. 1783 + * 1784 + * Return: 0 on success, err otherwise. 1785 + */ 1786 + int synth_event_add_next_val(u64 val, 1787 + struct synth_event_trace_state *trace_state) 1788 + { 1789 + return __synth_event_add_val(NULL, val, trace_state); 1790 + } 1791 + EXPORT_SYMBOL_GPL(synth_event_add_next_val); 1792 + 1793 + /** 1794 + * synth_event_add_val - Add a named field's value to an open synth trace 1795 + * @field_name: The name of the synthetic event field value to set 1796 + * @val: The value to set the next field to 1797 + * @trace_state: A pointer to object tracking the piecewise trace state 1798 + * 1799 + * Set the value of the named field in an event that's been opened by 1800 + * synth_event_trace_start(). 1801 + * 1802 + * The val param should be the value cast to u64. If the value points 1803 + * to a string, the val param should be a char * cast to u64. 1804 + * 1805 + * This function looks up the field name, and if found, sets the field 1806 + * to the specified value. This lookup makes this function more 1807 + * expensive than synth_event_add_next_val(), so use that or the 1808 + * none-piecewise synth_event_trace() instead if efficiency is more 1809 + * important. 1810 + * 1811 + * Note however that synth_event_add_next_val() and 1812 + * synth_event_add_val() can't be intermixed for a given event trace - 1813 + * one or the other but not both can be used at the same time. 1814 + * 1815 + * Note also that synth_event_trace_end() must be called after all 1816 + * values have been added for each event trace, regardless of whether 1817 + * adding all field values succeeded or not. 1818 + * 1819 + * Return: 0 on success, err otherwise. 1820 + */ 1821 + int synth_event_add_val(const char *field_name, u64 val, 1822 + struct synth_event_trace_state *trace_state) 1823 + { 1824 + return __synth_event_add_val(field_name, val, trace_state); 1825 + } 1826 + EXPORT_SYMBOL_GPL(synth_event_add_val); 1827 + 1828 + /** 1829 + * synth_event_trace_end - End piecewise synthetic event trace 1830 + * @trace_state: A pointer to object tracking the piecewise trace state 1831 + * 1832 + * End the trace of a synthetic event opened by 1833 + * synth_event_trace__start(). 1834 + * 1835 + * This function 'closes' an event trace, which basically means that 1836 + * it commits the reserved event and cleans up other loose ends. 1837 + * 1838 + * A pointer to a trace_state object is passed in, which will keep 1839 + * track of the current event trace state opened with 1840 + * synth_event_trace_start(). 1841 + * 1842 + * Note that this function must be called after all values have been 1843 + * added for each event trace, regardless of whether adding all field 1844 + * values succeeded or not. 1845 + * 1846 + * Return: 0 on success, err otherwise. 1847 + */ 1848 + int synth_event_trace_end(struct synth_event_trace_state *trace_state) 1849 + { 1850 + if (!trace_state) 1851 + return -EINVAL; 1852 + 1853 + trace_event_buffer_commit(&trace_state->fbuffer); 1854 + 1855 + ring_buffer_nest_end(trace_state->buffer); 1856 + 1857 + return 0; 1858 + } 1859 + EXPORT_SYMBOL_GPL(synth_event_trace_end); 1860 + 1861 + static int create_synth_event(int argc, const char **argv) 1768 1862 { 1769 1863 const char *name = argv[0]; 1770 1864 int len; ··· 2881 2041 unsigned long size, map_bits; 2882 2042 int ret; 2883 2043 2884 - strsep(&str, "="); 2885 - if (!str) { 2886 - ret = -EINVAL; 2887 - goto out; 2888 - } 2889 - 2890 2044 ret = kstrtoul(str, 0, &size); 2891 2045 if (ret) 2892 2046 goto out; ··· 2940 2106 static int parse_assignment(struct trace_array *tr, 2941 2107 char *str, struct hist_trigger_attrs *attrs) 2942 2108 { 2943 - int ret = 0; 2109 + int len, ret = 0; 2944 2110 2945 - if ((str_has_prefix(str, "key=")) || 2946 - (str_has_prefix(str, "keys="))) { 2947 - attrs->keys_str = kstrdup(str, GFP_KERNEL); 2111 + if ((len = str_has_prefix(str, "key=")) || 2112 + (len = str_has_prefix(str, "keys="))) { 2113 + attrs->keys_str = kstrdup(str + len, GFP_KERNEL); 2948 2114 if (!attrs->keys_str) { 2949 2115 ret = -ENOMEM; 2950 2116 goto out; 2951 2117 } 2952 - } else if ((str_has_prefix(str, "val=")) || 2953 - (str_has_prefix(str, "vals=")) || 2954 - (str_has_prefix(str, "values="))) { 2955 - attrs->vals_str = kstrdup(str, GFP_KERNEL); 2118 + } else if ((len = str_has_prefix(str, "val=")) || 2119 + (len = str_has_prefix(str, "vals=")) || 2120 + (len = str_has_prefix(str, "values="))) { 2121 + attrs->vals_str = kstrdup(str + len, GFP_KERNEL); 2956 2122 if (!attrs->vals_str) { 2957 2123 ret = -ENOMEM; 2958 2124 goto out; 2959 2125 } 2960 - } else if (str_has_prefix(str, "sort=")) { 2961 - attrs->sort_key_str = kstrdup(str, GFP_KERNEL); 2126 + } else if ((len = str_has_prefix(str, "sort="))) { 2127 + attrs->sort_key_str = kstrdup(str + len, GFP_KERNEL); 2962 2128 if (!attrs->sort_key_str) { 2963 2129 ret = -ENOMEM; 2964 2130 goto out; ··· 2969 2135 ret = -ENOMEM; 2970 2136 goto out; 2971 2137 } 2972 - } else if (str_has_prefix(str, "clock=")) { 2973 - strsep(&str, "="); 2974 - if (!str) { 2975 - ret = -EINVAL; 2976 - goto out; 2977 - } 2138 + } else if ((len = str_has_prefix(str, "clock="))) { 2139 + str += len; 2978 2140 2979 2141 str = strstrip(str); 2980 2142 attrs->clock = kstrdup(str, GFP_KERNEL); ··· 2978 2148 ret = -ENOMEM; 2979 2149 goto out; 2980 2150 } 2981 - } else if (str_has_prefix(str, "size=")) { 2982 - int map_bits = parse_map_size(str); 2151 + } else if ((len = str_has_prefix(str, "size="))) { 2152 + int map_bits = parse_map_size(str + len); 2983 2153 2984 2154 if (map_bits < 0) { 2985 2155 ret = map_bits; ··· 3019 2189 3020 2190 while (trigger_str) { 3021 2191 char *str = strsep(&trigger_str, ":"); 2192 + char *rhs; 3022 2193 3023 - if (strchr(str, '=')) { 2194 + rhs = strchr(str, '='); 2195 + if (rhs) { 2196 + if (!strlen(++rhs)) { 2197 + ret = -EINVAL; 2198 + hist_err(tr, HIST_ERR_EMPTY_ASSIGNMENT, errpos(str)); 2199 + goto free; 2200 + } 3024 2201 ret = parse_assignment(tr, str, attrs); 3025 2202 if (ret) 3026 2203 goto free; ··· 3496 2659 kfree(ref_field->name); 3497 2660 3498 2661 goto out; 2662 + } 2663 + 2664 + static int find_var_ref_idx(struct hist_trigger_data *hist_data, 2665 + struct hist_field *var_field) 2666 + { 2667 + struct hist_field *ref_field; 2668 + int i; 2669 + 2670 + for (i = 0; i < hist_data->n_var_refs; i++) { 2671 + ref_field = hist_data->var_refs[i]; 2672 + if (ref_field->var.idx == var_field->var.idx && 2673 + ref_field->var.hist_data == var_field->hist_data) 2674 + return i; 2675 + } 2676 + 2677 + return -ENOENT; 3499 2678 } 3500 2679 3501 2680 /** ··· 4999 4146 5000 4147 field = event->fields[field_pos]; 5001 4148 5002 - if (strcmp(field->type, hist_field->type) != 0) 5003 - return -EINVAL; 4149 + if (strcmp(field->type, hist_field->type) != 0) { 4150 + if (field->size != hist_field->size || 4151 + field->is_signed != hist_field->is_signed) 4152 + return -EINVAL; 4153 + } 5004 4154 5005 4155 return 0; 5006 4156 } ··· 5090 4234 struct trace_array *tr = hist_data->event_file->tr; 5091 4235 char *event_name, *param, *system = NULL; 5092 4236 struct hist_field *hist_field, *var_ref; 5093 - unsigned int i, var_ref_idx; 4237 + unsigned int i; 5094 4238 unsigned int field_pos = 0; 5095 4239 struct synth_event *event; 5096 4240 char *synth_event_name; 5097 - int ret = 0; 4241 + int var_ref_idx, ret = 0; 5098 4242 5099 4243 lockdep_assert_held(&event_mutex); 5100 4244 ··· 5110 4254 } 5111 4255 5112 4256 event->ref++; 5113 - 5114 - var_ref_idx = hist_data->n_var_refs; 5115 4257 5116 4258 for (i = 0; i < data->n_params; i++) { 5117 4259 char *p; ··· 5159 4305 goto err; 5160 4306 } 5161 4307 4308 + var_ref_idx = find_var_ref_idx(hist_data, var_ref); 4309 + if (WARN_ON(var_ref_idx < 0)) { 4310 + ret = var_ref_idx; 4311 + goto err; 4312 + } 4313 + 4314 + data->var_ref_idx[i] = var_ref_idx; 4315 + 5162 4316 field_pos++; 5163 4317 kfree(p); 5164 4318 continue; ··· 5185 4323 } 5186 4324 5187 4325 data->synth_event = event; 5188 - data->var_ref_idx = var_ref_idx; 5189 4326 out: 5190 4327 return ret; 5191 4328 err: ··· 5403 4542 if (!fields_str) 5404 4543 goto out; 5405 4544 5406 - strsep(&fields_str, "="); 5407 - if (!fields_str) 5408 - goto out; 5409 - 5410 4545 for (i = 0, j = 1; i < TRACING_MAP_VALS_MAX && 5411 4546 j < TRACING_MAP_VALS_MAX; i++) { 5412 4547 field_str = strsep(&fields_str, ","); ··· 5494 4637 int ret = -EINVAL; 5495 4638 5496 4639 fields_str = hist_data->attrs->keys_str; 5497 - if (!fields_str) 5498 - goto out; 5499 - 5500 - strsep(&fields_str, "="); 5501 4640 if (!fields_str) 5502 4641 goto out; 5503 4642 ··· 5628 4775 return ret; 5629 4776 } 5630 4777 5631 - static int is_descending(const char *str) 4778 + static int is_descending(struct trace_array *tr, const char *str) 5632 4779 { 5633 4780 if (!str) 5634 4781 return 0; ··· 5639 4786 if (strcmp(str, "ascending") == 0) 5640 4787 return 0; 5641 4788 4789 + hist_err(tr, HIST_ERR_INVALID_SORT_MODIFIER, errpos((char *)str)); 4790 + 5642 4791 return -EINVAL; 5643 4792 } 5644 4793 5645 4794 static int create_sort_keys(struct hist_trigger_data *hist_data) 5646 4795 { 4796 + struct trace_array *tr = hist_data->event_file->tr; 5647 4797 char *fields_str = hist_data->attrs->sort_key_str; 5648 4798 struct tracing_map_sort_key *sort_key; 5649 4799 int descending, ret = 0; ··· 5657 4801 if (!fields_str) 5658 4802 goto out; 5659 4803 5660 - strsep(&fields_str, "="); 5661 - if (!fields_str) { 5662 - ret = -EINVAL; 5663 - goto out; 5664 - } 5665 - 5666 4804 for (i = 0; i < TRACING_MAP_SORT_KEYS_MAX; i++) { 5667 4805 struct hist_field *hist_field; 5668 4806 char *field_str, *field_name; ··· 5665 4815 sort_key = &hist_data->sort_keys[i]; 5666 4816 5667 4817 field_str = strsep(&fields_str, ","); 5668 - if (!field_str) { 5669 - if (i == 0) 5670 - ret = -EINVAL; 4818 + if (!field_str) 4819 + break; 4820 + 4821 + if (!*field_str) { 4822 + ret = -EINVAL; 4823 + hist_err(tr, HIST_ERR_EMPTY_SORT_FIELD, errpos("sort=")); 5671 4824 break; 5672 4825 } 5673 4826 5674 4827 if ((i == TRACING_MAP_SORT_KEYS_MAX - 1) && fields_str) { 4828 + hist_err(tr, HIST_ERR_TOO_MANY_SORT_FIELDS, errpos("sort=")); 5675 4829 ret = -EINVAL; 5676 4830 break; 5677 4831 } 5678 4832 5679 4833 field_name = strsep(&field_str, "."); 5680 - if (!field_name) { 4834 + if (!field_name || !*field_name) { 5681 4835 ret = -EINVAL; 4836 + hist_err(tr, HIST_ERR_EMPTY_SORT_FIELD, errpos("sort=")); 5682 4837 break; 5683 4838 } 5684 4839 5685 4840 if (strcmp(field_name, "hitcount") == 0) { 5686 - descending = is_descending(field_str); 4841 + descending = is_descending(tr, field_str); 5687 4842 if (descending < 0) { 5688 4843 ret = descending; 5689 4844 break; ··· 5710 4855 5711 4856 if (strcmp(field_name, test_name) == 0) { 5712 4857 sort_key->field_idx = idx; 5713 - descending = is_descending(field_str); 4858 + descending = is_descending(tr, field_str); 5714 4859 if (descending < 0) { 5715 4860 ret = descending; 5716 4861 goto out; ··· 5721 4866 } 5722 4867 if (j == hist_data->n_fields) { 5723 4868 ret = -EINVAL; 4869 + hist_err(tr, HIST_ERR_INVALID_SORT_FIELD, errpos(field_name)); 5724 4870 break; 5725 4871 } 5726 4872 }
+4 -3
kernel/trace/trace_events_trigger.c
··· 116 116 { 117 117 struct trace_event_file *event_file = event_file_data(m->private); 118 118 119 - if (t == SHOW_AVAILABLE_TRIGGERS) 119 + if (t == SHOW_AVAILABLE_TRIGGERS) { 120 + (*pos)++; 120 121 return NULL; 121 - 122 + } 122 123 return seq_list_next(t, &event_file->triggers, pos); 123 124 } 124 125 ··· 214 213 return ret; 215 214 } 216 215 217 - static int trigger_process_regex(struct trace_event_file *file, char *buff) 216 + int trigger_process_regex(struct trace_event_file *file, char *buff) 218 217 { 219 218 char *command, *next = buff; 220 219 struct event_command *p;
+4 -4
kernel/trace/trace_functions.c
··· 101 101 102 102 ftrace_init_array_ops(tr, func); 103 103 104 - tr->trace_buffer.cpu = get_cpu(); 104 + tr->array_buffer.cpu = get_cpu(); 105 105 put_cpu(); 106 106 107 107 tracing_start_cmdline_record(); ··· 118 118 119 119 static void function_trace_start(struct trace_array *tr) 120 120 { 121 - tracing_reset_online_cpus(&tr->trace_buffer); 121 + tracing_reset_online_cpus(&tr->array_buffer); 122 122 } 123 123 124 124 static void ··· 143 143 goto out; 144 144 145 145 cpu = smp_processor_id(); 146 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 146 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 147 147 if (!atomic_read(&data->disabled)) { 148 148 local_save_flags(flags); 149 149 trace_function(tr, ip, parent_ip, flags, pc); ··· 192 192 */ 193 193 local_irq_save(flags); 194 194 cpu = raw_smp_processor_id(); 195 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 195 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 196 196 disabled = atomic_inc_return(&data->disabled); 197 197 198 198 if (likely(disabled == 1)) {
+7 -7
kernel/trace/trace_functions_graph.c
··· 101 101 { 102 102 struct trace_event_call *call = &event_funcgraph_entry; 103 103 struct ring_buffer_event *event; 104 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 104 + struct trace_buffer *buffer = tr->array_buffer.buffer; 105 105 struct ftrace_graph_ent_entry *entry; 106 106 107 107 event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT, ··· 171 171 172 172 local_irq_save(flags); 173 173 cpu = raw_smp_processor_id(); 174 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 174 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 175 175 disabled = atomic_inc_return(&data->disabled); 176 176 if (likely(disabled == 1)) { 177 177 pc = preempt_count(); ··· 221 221 { 222 222 struct trace_event_call *call = &event_funcgraph_exit; 223 223 struct ring_buffer_event *event; 224 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 224 + struct trace_buffer *buffer = tr->array_buffer.buffer; 225 225 struct ftrace_graph_ret_entry *entry; 226 226 227 227 event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET, ··· 252 252 253 253 local_irq_save(flags); 254 254 cpu = raw_smp_processor_id(); 255 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 255 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 256 256 disabled = atomic_inc_return(&data->disabled); 257 257 if (likely(disabled == 1)) { 258 258 pc = preempt_count(); ··· 444 444 * We need to consume the current entry to see 445 445 * the next one. 446 446 */ 447 - ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, 447 + ring_buffer_consume(iter->array_buffer->buffer, iter->cpu, 448 448 NULL, NULL); 449 - event = ring_buffer_peek(iter->trace_buffer->buffer, iter->cpu, 449 + event = ring_buffer_peek(iter->array_buffer->buffer, iter->cpu, 450 450 NULL, NULL); 451 451 } 452 452 ··· 503 503 { 504 504 unsigned long long usecs; 505 505 506 - usecs = iter->ts - iter->trace_buffer->time_start; 506 + usecs = iter->ts - iter->array_buffer->time_start; 507 507 do_div(usecs, NSEC_PER_USEC); 508 508 509 509 trace_seq_printf(s, "%9llu us | ", usecs);
+1 -1
kernel/trace/trace_hwlat.c
··· 104 104 { 105 105 struct trace_array *tr = hwlat_trace; 106 106 struct trace_event_call *call = &event_hwlat; 107 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 107 + struct trace_buffer *buffer = tr->array_buffer.buffer; 108 108 struct ring_buffer_event *event; 109 109 struct hwlat_entry *entry; 110 110 unsigned long flags;
+4 -4
kernel/trace/trace_irqsoff.c
··· 122 122 if (!irqs_disabled_flags(*flags) && !preempt_count()) 123 123 return 0; 124 124 125 - *data = per_cpu_ptr(tr->trace_buffer.data, cpu); 125 + *data = per_cpu_ptr(tr->array_buffer.data, cpu); 126 126 disabled = atomic_inc_return(&(*data)->disabled); 127 127 128 128 if (likely(disabled == 1)) ··· 167 167 per_cpu(tracing_cpu, cpu) = 0; 168 168 169 169 tr->max_latency = 0; 170 - tracing_reset_online_cpus(&irqsoff_trace->trace_buffer); 170 + tracing_reset_online_cpus(&irqsoff_trace->array_buffer); 171 171 172 172 return start_irqsoff_tracer(irqsoff_trace, set); 173 173 } ··· 382 382 if (per_cpu(tracing_cpu, cpu)) 383 383 return; 384 384 385 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 385 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 386 386 387 387 if (unlikely(!data) || atomic_read(&data->disabled)) 388 388 return; ··· 420 420 if (!tracer_enabled || !tracing_is_enabled()) 421 421 return; 422 422 423 - data = per_cpu_ptr(tr->trace_buffer.data, cpu); 423 + data = per_cpu_ptr(tr->array_buffer.data, cpu); 424 424 425 425 if (unlikely(!data) || 426 426 !data->critical_start || atomic_read(&data->disabled))
+4 -4
kernel/trace/trace_kdb.c
··· 43 43 if (cpu_file == RING_BUFFER_ALL_CPUS) { 44 44 for_each_tracing_cpu(cpu) { 45 45 iter.buffer_iter[cpu] = 46 - ring_buffer_read_prepare(iter.trace_buffer->buffer, 46 + ring_buffer_read_prepare(iter.array_buffer->buffer, 47 47 cpu, GFP_ATOMIC); 48 48 ring_buffer_read_start(iter.buffer_iter[cpu]); 49 49 tracing_iter_reset(&iter, cpu); ··· 51 51 } else { 52 52 iter.cpu_file = cpu_file; 53 53 iter.buffer_iter[cpu_file] = 54 - ring_buffer_read_prepare(iter.trace_buffer->buffer, 54 + ring_buffer_read_prepare(iter.array_buffer->buffer, 55 55 cpu_file, GFP_ATOMIC); 56 56 ring_buffer_read_start(iter.buffer_iter[cpu_file]); 57 57 tracing_iter_reset(&iter, cpu_file); ··· 124 124 iter.buffer_iter = buffer_iter; 125 125 126 126 for_each_tracing_cpu(cpu) { 127 - atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 127 + atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); 128 128 } 129 129 130 130 /* A negative skip_entries means skip all but the last entries */ ··· 139 139 ftrace_dump_buf(skip_entries, cpu_file); 140 140 141 141 for_each_tracing_cpu(cpu) { 142 - atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); 142 + atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); 143 143 } 144 144 145 145 kdb_trap_printk--;
+204 -34
kernel/trace/trace_kprobe.c
··· 22 22 23 23 #define KPROBE_EVENT_SYSTEM "kprobes" 24 24 #define KRETPROBE_MAXACTIVE_MAX 4096 25 - #define MAX_KPROBE_CMDLINE_SIZE 1024 26 25 27 26 /* Kprobe early definition from command line */ 28 27 static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata; ··· 901 902 return ret == -ECANCELED ? -EINVAL : ret; 902 903 } 903 904 905 + static int trace_kprobe_run_command(struct dynevent_cmd *cmd) 906 + { 907 + return trace_run_command(cmd->seq.buffer, create_or_delete_trace_kprobe); 908 + } 909 + 910 + /** 911 + * kprobe_event_cmd_init - Initialize a kprobe event command object 912 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 913 + * @buf: A pointer to the buffer used to build the command 914 + * @maxlen: The length of the buffer passed in @buf 915 + * 916 + * Initialize a synthetic event command object. Use this before 917 + * calling any of the other kprobe_event functions. 918 + */ 919 + void kprobe_event_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen) 920 + { 921 + dynevent_cmd_init(cmd, buf, maxlen, DYNEVENT_TYPE_KPROBE, 922 + trace_kprobe_run_command); 923 + } 924 + EXPORT_SYMBOL_GPL(kprobe_event_cmd_init); 925 + 926 + /** 927 + * __kprobe_event_gen_cmd_start - Generate a kprobe event command from arg list 928 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 929 + * @name: The name of the kprobe event 930 + * @loc: The location of the kprobe event 931 + * @kretprobe: Is this a return probe? 932 + * @args: Variable number of arg (pairs), one pair for each field 933 + * 934 + * NOTE: Users normally won't want to call this function directly, but 935 + * rather use the kprobe_event_gen_cmd_start() wrapper, which automatically 936 + * adds a NULL to the end of the arg list. If this function is used 937 + * directly, make sure the last arg in the variable arg list is NULL. 938 + * 939 + * Generate a kprobe event command to be executed by 940 + * kprobe_event_gen_cmd_end(). This function can be used to generate the 941 + * complete command or only the first part of it; in the latter case, 942 + * kprobe_event_add_fields() can be used to add more fields following this. 943 + * 944 + * Return: 0 if successful, error otherwise. 945 + */ 946 + int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe, 947 + const char *name, const char *loc, ...) 948 + { 949 + char buf[MAX_EVENT_NAME_LEN]; 950 + struct dynevent_arg arg; 951 + va_list args; 952 + int ret; 953 + 954 + if (cmd->type != DYNEVENT_TYPE_KPROBE) 955 + return -EINVAL; 956 + 957 + if (kretprobe) 958 + snprintf(buf, MAX_EVENT_NAME_LEN, "r:kprobes/%s", name); 959 + else 960 + snprintf(buf, MAX_EVENT_NAME_LEN, "p:kprobes/%s", name); 961 + 962 + ret = dynevent_str_add(cmd, buf); 963 + if (ret) 964 + return ret; 965 + 966 + dynevent_arg_init(&arg, 0); 967 + arg.str = loc; 968 + ret = dynevent_arg_add(cmd, &arg, NULL); 969 + if (ret) 970 + return ret; 971 + 972 + va_start(args, loc); 973 + for (;;) { 974 + const char *field; 975 + 976 + field = va_arg(args, const char *); 977 + if (!field) 978 + break; 979 + 980 + if (++cmd->n_fields > MAX_TRACE_ARGS) { 981 + ret = -EINVAL; 982 + break; 983 + } 984 + 985 + arg.str = field; 986 + ret = dynevent_arg_add(cmd, &arg, NULL); 987 + if (ret) 988 + break; 989 + } 990 + va_end(args); 991 + 992 + return ret; 993 + } 994 + EXPORT_SYMBOL_GPL(__kprobe_event_gen_cmd_start); 995 + 996 + /** 997 + * __kprobe_event_add_fields - Add probe fields to a kprobe command from arg list 998 + * @cmd: A pointer to the dynevent_cmd struct representing the new event 999 + * @args: Variable number of arg (pairs), one pair for each field 1000 + * 1001 + * NOTE: Users normally won't want to call this function directly, but 1002 + * rather use the kprobe_event_add_fields() wrapper, which 1003 + * automatically adds a NULL to the end of the arg list. If this 1004 + * function is used directly, make sure the last arg in the variable 1005 + * arg list is NULL. 1006 + * 1007 + * Add probe fields to an existing kprobe command using a variable 1008 + * list of args. Fields are added in the same order they're listed. 1009 + * 1010 + * Return: 0 if successful, error otherwise. 1011 + */ 1012 + int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...) 1013 + { 1014 + struct dynevent_arg arg; 1015 + va_list args; 1016 + int ret; 1017 + 1018 + if (cmd->type != DYNEVENT_TYPE_KPROBE) 1019 + return -EINVAL; 1020 + 1021 + dynevent_arg_init(&arg, 0); 1022 + 1023 + va_start(args, cmd); 1024 + for (;;) { 1025 + const char *field; 1026 + 1027 + field = va_arg(args, const char *); 1028 + if (!field) 1029 + break; 1030 + 1031 + if (++cmd->n_fields > MAX_TRACE_ARGS) { 1032 + ret = -EINVAL; 1033 + break; 1034 + } 1035 + 1036 + arg.str = field; 1037 + ret = dynevent_arg_add(cmd, &arg, NULL); 1038 + if (ret) 1039 + break; 1040 + } 1041 + va_end(args); 1042 + 1043 + return ret; 1044 + } 1045 + EXPORT_SYMBOL_GPL(__kprobe_event_add_fields); 1046 + 1047 + /** 1048 + * kprobe_event_delete - Delete a kprobe event 1049 + * @name: The name of the kprobe event to delete 1050 + * 1051 + * Delete a kprobe event with the give @name from kernel code rather 1052 + * than directly from the command line. 1053 + * 1054 + * Return: 0 if successful, error otherwise. 1055 + */ 1056 + int kprobe_event_delete(const char *name) 1057 + { 1058 + char buf[MAX_EVENT_NAME_LEN]; 1059 + 1060 + snprintf(buf, MAX_EVENT_NAME_LEN, "-:%s", name); 1061 + 1062 + return trace_run_command(buf, create_or_delete_trace_kprobe); 1063 + } 1064 + EXPORT_SYMBOL_GPL(kprobe_event_delete); 1065 + 904 1066 static int trace_kprobe_release(struct dyn_event *ev) 905 1067 { 906 1068 struct trace_kprobe *tk = to_trace_kprobe(ev); ··· 1335 1175 struct trace_event_file *trace_file) 1336 1176 { 1337 1177 struct kprobe_trace_entry_head *entry; 1338 - struct ring_buffer_event *event; 1339 - struct ring_buffer *buffer; 1340 - int size, dsize, pc; 1341 - unsigned long irq_flags; 1342 1178 struct trace_event_call *call = trace_probe_event_call(&tk->tp); 1179 + struct trace_event_buffer fbuffer; 1180 + int dsize; 1343 1181 1344 1182 WARN_ON(call != trace_file->event_call); 1345 1183 1346 1184 if (trace_trigger_soft_disabled(trace_file)) 1347 1185 return; 1348 1186 1349 - local_save_flags(irq_flags); 1350 - pc = preempt_count(); 1187 + local_save_flags(fbuffer.flags); 1188 + fbuffer.pc = preempt_count(); 1189 + fbuffer.trace_file = trace_file; 1351 1190 1352 1191 dsize = __get_data_size(&tk->tp, regs); 1353 - size = sizeof(*entry) + tk->tp.size + dsize; 1354 1192 1355 - event = trace_event_buffer_lock_reserve(&buffer, trace_file, 1356 - call->event.type, 1357 - size, irq_flags, pc); 1358 - if (!event) 1193 + fbuffer.event = 1194 + trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file, 1195 + call->event.type, 1196 + sizeof(*entry) + tk->tp.size + dsize, 1197 + fbuffer.flags, fbuffer.pc); 1198 + if (!fbuffer.event) 1359 1199 return; 1360 1200 1361 - entry = ring_buffer_event_data(event); 1201 + fbuffer.regs = regs; 1202 + entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); 1362 1203 entry->ip = (unsigned long)tk->rp.kp.addr; 1363 1204 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); 1364 1205 1365 - event_trigger_unlock_commit_regs(trace_file, buffer, event, 1366 - entry, irq_flags, pc, regs); 1206 + trace_event_buffer_commit(&fbuffer); 1367 1207 } 1368 1208 1369 1209 static void ··· 1383 1223 struct trace_event_file *trace_file) 1384 1224 { 1385 1225 struct kretprobe_trace_entry_head *entry; 1386 - struct ring_buffer_event *event; 1387 - struct ring_buffer *buffer; 1388 - int size, pc, dsize; 1389 - unsigned long irq_flags; 1226 + struct trace_event_buffer fbuffer; 1390 1227 struct trace_event_call *call = trace_probe_event_call(&tk->tp); 1228 + int dsize; 1391 1229 1392 1230 WARN_ON(call != trace_file->event_call); 1393 1231 1394 1232 if (trace_trigger_soft_disabled(trace_file)) 1395 1233 return; 1396 1234 1397 - local_save_flags(irq_flags); 1398 - pc = preempt_count(); 1235 + local_save_flags(fbuffer.flags); 1236 + fbuffer.pc = preempt_count(); 1237 + fbuffer.trace_file = trace_file; 1399 1238 1400 1239 dsize = __get_data_size(&tk->tp, regs); 1401 - size = sizeof(*entry) + tk->tp.size + dsize; 1402 - 1403 - event = trace_event_buffer_lock_reserve(&buffer, trace_file, 1404 - call->event.type, 1405 - size, irq_flags, pc); 1406 - if (!event) 1240 + fbuffer.event = 1241 + trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file, 1242 + call->event.type, 1243 + sizeof(*entry) + tk->tp.size + dsize, 1244 + fbuffer.flags, fbuffer.pc); 1245 + if (!fbuffer.event) 1407 1246 return; 1408 1247 1409 - entry = ring_buffer_event_data(event); 1248 + fbuffer.regs = regs; 1249 + entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); 1410 1250 entry->func = (unsigned long)tk->rp.kp.addr; 1411 1251 entry->ret_ip = (unsigned long)ri->ret_addr; 1412 1252 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); 1413 1253 1414 - event_trigger_unlock_commit_regs(trace_file, buffer, event, 1415 - entry, irq_flags, pc, regs); 1254 + trace_event_buffer_commit(&fbuffer); 1416 1255 } 1417 1256 1418 1257 static void ··· 1857 1698 enable_boot_kprobe_events(); 1858 1699 } 1859 1700 1860 - /* Make a tracefs interface for controlling probe points */ 1861 - static __init int init_kprobe_trace(void) 1701 + /* 1702 + * Register dynevent at subsys_initcall. This allows kernel to setup kprobe 1703 + * events in fs_initcall without tracefs. 1704 + */ 1705 + static __init int init_kprobe_trace_early(void) 1862 1706 { 1863 - struct dentry *d_tracer; 1864 - struct dentry *entry; 1865 1707 int ret; 1866 1708 1867 1709 ret = dyn_event_register(&trace_kprobe_ops); ··· 1871 1711 1872 1712 if (register_module_notifier(&trace_kprobe_module_nb)) 1873 1713 return -EINVAL; 1714 + 1715 + return 0; 1716 + } 1717 + subsys_initcall(init_kprobe_trace_early); 1718 + 1719 + /* Make a tracefs interface for controlling probe points */ 1720 + static __init int init_kprobe_trace(void) 1721 + { 1722 + struct dentry *d_tracer; 1723 + struct dentry *entry; 1874 1724 1875 1725 d_tracer = tracing_init_dentry(); 1876 1726 if (IS_ERR(d_tracer))
+6 -6
kernel/trace/trace_mmiotrace.c
··· 32 32 overrun_detected = false; 33 33 prev_overruns = 0; 34 34 35 - tracing_reset_online_cpus(&tr->trace_buffer); 35 + tracing_reset_online_cpus(&tr->array_buffer); 36 36 } 37 37 38 38 static int mmio_trace_init(struct trace_array *tr) ··· 122 122 static unsigned long count_overruns(struct trace_iterator *iter) 123 123 { 124 124 unsigned long cnt = atomic_xchg(&dropped_count, 0); 125 - unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer); 125 + unsigned long over = ring_buffer_overruns(iter->array_buffer->buffer); 126 126 127 127 if (over > prev_overruns) 128 128 cnt += over - prev_overruns; ··· 297 297 struct mmiotrace_rw *rw) 298 298 { 299 299 struct trace_event_call *call = &event_mmiotrace_rw; 300 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 300 + struct trace_buffer *buffer = tr->array_buffer.buffer; 301 301 struct ring_buffer_event *event; 302 302 struct trace_mmiotrace_rw *entry; 303 303 int pc = preempt_count(); ··· 318 318 void mmio_trace_rw(struct mmiotrace_rw *rw) 319 319 { 320 320 struct trace_array *tr = mmio_trace_array; 321 - struct trace_array_cpu *data = per_cpu_ptr(tr->trace_buffer.data, smp_processor_id()); 321 + struct trace_array_cpu *data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); 322 322 __trace_mmiotrace_rw(tr, data, rw); 323 323 } 324 324 ··· 327 327 struct mmiotrace_map *map) 328 328 { 329 329 struct trace_event_call *call = &event_mmiotrace_map; 330 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 330 + struct trace_buffer *buffer = tr->array_buffer.buffer; 331 331 struct ring_buffer_event *event; 332 332 struct trace_mmiotrace_map *entry; 333 333 int pc = preempt_count(); ··· 351 351 struct trace_array_cpu *data; 352 352 353 353 preempt_disable(); 354 - data = per_cpu_ptr(tr->trace_buffer.data, smp_processor_id()); 354 + data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); 355 355 __trace_mmiotrace_map(tr, data, map); 356 356 preempt_enable(); 357 357 }
+1 -1
kernel/trace/trace_output.c
··· 538 538 struct trace_array *tr = iter->tr; 539 539 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE; 540 540 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS; 541 - unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start; 541 + unsigned long long abs_ts = iter->ts - iter->array_buffer->time_start; 542 542 unsigned long long rel_ts = next_ts - iter->ts; 543 543 struct trace_seq *s = &iter->seq; 544 544
+3 -1
kernel/trace/trace_sched_switch.c
··· 89 89 90 90 static void tracing_start_sched_switch(int ops) 91 91 { 92 - bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref); 92 + bool sched_register; 93 + 93 94 mutex_lock(&sched_register_mutex); 95 + sched_register = (!sched_cmdline_ref && !sched_tgid_ref); 94 96 95 97 switch (ops) { 96 98 case RECORD_CMDLINE:
+10 -10
kernel/trace/trace_sched_wakeup.c
··· 82 82 if (cpu != wakeup_current_cpu) 83 83 goto out_enable; 84 84 85 - *data = per_cpu_ptr(tr->trace_buffer.data, cpu); 85 + *data = per_cpu_ptr(tr->array_buffer.data, cpu); 86 86 disabled = atomic_inc_return(&(*data)->disabled); 87 87 if (unlikely(disabled != 1)) 88 88 goto out; ··· 378 378 unsigned long flags, int pc) 379 379 { 380 380 struct trace_event_call *call = &event_context_switch; 381 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 381 + struct trace_buffer *buffer = tr->array_buffer.buffer; 382 382 struct ring_buffer_event *event; 383 383 struct ctx_switch_entry *entry; 384 384 ··· 408 408 struct trace_event_call *call = &event_wakeup; 409 409 struct ring_buffer_event *event; 410 410 struct ctx_switch_entry *entry; 411 - struct ring_buffer *buffer = tr->trace_buffer.buffer; 411 + struct trace_buffer *buffer = tr->array_buffer.buffer; 412 412 413 413 event = trace_buffer_lock_reserve(buffer, TRACE_WAKE, 414 414 sizeof(*entry), flags, pc); ··· 459 459 460 460 /* disable local data, not wakeup_cpu data */ 461 461 cpu = raw_smp_processor_id(); 462 - disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled); 462 + disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 463 463 if (likely(disabled != 1)) 464 464 goto out; 465 465 ··· 471 471 goto out_unlock; 472 472 473 473 /* The task we are waiting for is waking up */ 474 - data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu); 474 + data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu); 475 475 476 476 __trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc); 477 477 tracing_sched_switch_trace(wakeup_trace, prev, next, flags, pc); ··· 494 494 arch_spin_unlock(&wakeup_lock); 495 495 local_irq_restore(flags); 496 496 out: 497 - atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled); 497 + atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 498 498 } 499 499 500 500 static void __wakeup_reset(struct trace_array *tr) ··· 513 513 { 514 514 unsigned long flags; 515 515 516 - tracing_reset_online_cpus(&tr->trace_buffer); 516 + tracing_reset_online_cpus(&tr->array_buffer); 517 517 518 518 local_irq_save(flags); 519 519 arch_spin_lock(&wakeup_lock); ··· 551 551 return; 552 552 553 553 pc = preempt_count(); 554 - disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled); 554 + disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 555 555 if (unlikely(disabled != 1)) 556 556 goto out; 557 557 ··· 583 583 584 584 local_save_flags(flags); 585 585 586 - data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu); 586 + data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu); 587 587 data->preempt_timestamp = ftrace_now(cpu); 588 588 tracing_sched_wakeup_trace(wakeup_trace, p, current, flags, pc); 589 589 __trace_stack(wakeup_trace, flags, 0, pc); ··· 598 598 out_locked: 599 599 arch_spin_unlock(&wakeup_lock); 600 600 out: 601 - atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled); 601 + atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); 602 602 } 603 603 604 604 static void start_wakeup_tracer(struct trace_array *tr)
+13 -13
kernel/trace/trace_selftest.c
··· 23 23 return 0; 24 24 } 25 25 26 - static int trace_test_buffer_cpu(struct trace_buffer *buf, int cpu) 26 + static int trace_test_buffer_cpu(struct array_buffer *buf, int cpu) 27 27 { 28 28 struct ring_buffer_event *event; 29 29 struct trace_entry *entry; ··· 60 60 * Test the trace buffer to see if all the elements 61 61 * are still sane. 62 62 */ 63 - static int __maybe_unused trace_test_buffer(struct trace_buffer *buf, unsigned long *count) 63 + static int __maybe_unused trace_test_buffer(struct array_buffer *buf, unsigned long *count) 64 64 { 65 65 unsigned long flags, cnt = 0; 66 66 int cpu, ret = 0; ··· 362 362 msleep(100); 363 363 364 364 /* we should have nothing in the buffer */ 365 - ret = trace_test_buffer(&tr->trace_buffer, &count); 365 + ret = trace_test_buffer(&tr->array_buffer, &count); 366 366 if (ret) 367 367 goto out; 368 368 ··· 383 383 ftrace_enabled = 0; 384 384 385 385 /* check the trace buffer */ 386 - ret = trace_test_buffer(&tr->trace_buffer, &count); 386 + ret = trace_test_buffer(&tr->array_buffer, &count); 387 387 388 388 ftrace_enabled = 1; 389 389 tracing_start(); ··· 682 682 ftrace_enabled = 0; 683 683 684 684 /* check the trace buffer */ 685 - ret = trace_test_buffer(&tr->trace_buffer, &count); 685 + ret = trace_test_buffer(&tr->array_buffer, &count); 686 686 687 687 ftrace_enabled = 1; 688 688 trace->reset(tr); ··· 768 768 * Simulate the init() callback but we attach a watchdog callback 769 769 * to detect and recover from possible hangs 770 770 */ 771 - tracing_reset_online_cpus(&tr->trace_buffer); 771 + tracing_reset_online_cpus(&tr->array_buffer); 772 772 set_graph_array(tr); 773 773 ret = register_ftrace_graph(&fgraph_ops); 774 774 if (ret) { ··· 790 790 tracing_stop(); 791 791 792 792 /* check the trace buffer */ 793 - ret = trace_test_buffer(&tr->trace_buffer, &count); 793 + ret = trace_test_buffer(&tr->array_buffer, &count); 794 794 795 795 /* Need to also simulate the tr->reset to remove this fgraph_ops */ 796 796 tracing_stop_cmdline_record(); ··· 848 848 /* stop the tracing. */ 849 849 tracing_stop(); 850 850 /* check both trace buffers */ 851 - ret = trace_test_buffer(&tr->trace_buffer, NULL); 851 + ret = trace_test_buffer(&tr->array_buffer, NULL); 852 852 if (!ret) 853 853 ret = trace_test_buffer(&tr->max_buffer, &count); 854 854 trace->reset(tr); ··· 910 910 /* stop the tracing. */ 911 911 tracing_stop(); 912 912 /* check both trace buffers */ 913 - ret = trace_test_buffer(&tr->trace_buffer, NULL); 913 + ret = trace_test_buffer(&tr->array_buffer, NULL); 914 914 if (!ret) 915 915 ret = trace_test_buffer(&tr->max_buffer, &count); 916 916 trace->reset(tr); ··· 976 976 /* stop the tracing. */ 977 977 tracing_stop(); 978 978 /* check both trace buffers */ 979 - ret = trace_test_buffer(&tr->trace_buffer, NULL); 979 + ret = trace_test_buffer(&tr->array_buffer, NULL); 980 980 if (ret) 981 981 goto out; 982 982 ··· 1006 1006 /* stop the tracing. */ 1007 1007 tracing_stop(); 1008 1008 /* check both trace buffers */ 1009 - ret = trace_test_buffer(&tr->trace_buffer, NULL); 1009 + ret = trace_test_buffer(&tr->array_buffer, NULL); 1010 1010 if (ret) 1011 1011 goto out; 1012 1012 ··· 1136 1136 /* stop the tracing. */ 1137 1137 tracing_stop(); 1138 1138 /* check both trace buffers */ 1139 - ret = trace_test_buffer(&tr->trace_buffer, NULL); 1139 + ret = trace_test_buffer(&tr->array_buffer, NULL); 1140 1140 if (!ret) 1141 1141 ret = trace_test_buffer(&tr->max_buffer, &count); 1142 1142 ··· 1177 1177 /* stop the tracing. */ 1178 1178 tracing_stop(); 1179 1179 /* check the trace buffer */ 1180 - ret = trace_test_buffer(&tr->trace_buffer, &count); 1180 + ret = trace_test_buffer(&tr->array_buffer, &count); 1181 1181 trace->reset(tr); 1182 1182 tracing_start(); 1183 1183
-3
kernel/trace/trace_seq.c
··· 30 30 /* How much buffer is left on the trace_seq? */ 31 31 #define TRACE_SEQ_BUF_LEFT(s) seq_buf_buffer_left(&(s)->seq) 32 32 33 - /* How much buffer is written? */ 34 - #define TRACE_SEQ_BUF_USED(s) seq_buf_used(&(s)->seq) 35 - 36 33 /* 37 34 * trace_seq should work with being initialized with 0s. 38 35 */
+17 -14
kernel/trace/trace_stat.c
··· 280 280 281 281 d_tracing = tracing_init_dentry(); 282 282 if (IS_ERR(d_tracing)) 283 - return 0; 283 + return -ENODEV; 284 284 285 285 stat_dir = tracefs_create_dir("trace_stat", d_tracing); 286 - if (!stat_dir) 286 + if (!stat_dir) { 287 287 pr_warn("Could not create tracefs 'trace_stat' entry\n"); 288 + return -ENOMEM; 289 + } 288 290 return 0; 289 291 } 290 292 291 293 static int init_stat_file(struct stat_session *session) 292 294 { 293 - if (!stat_dir && tracing_stat_init()) 294 - return -ENODEV; 295 + int ret; 296 + 297 + if (!stat_dir && (ret = tracing_stat_init())) 298 + return ret; 295 299 296 300 session->file = tracefs_create_file(session->ts->name, 0644, 297 301 stat_dir, ··· 308 304 int register_stat_tracer(struct tracer_stat *trace) 309 305 { 310 306 struct stat_session *session, *node; 311 - int ret; 307 + int ret = -EINVAL; 312 308 313 309 if (!trace) 314 310 return -EINVAL; ··· 319 315 /* Already registered? */ 320 316 mutex_lock(&all_stat_sessions_mutex); 321 317 list_for_each_entry(node, &all_stat_sessions, session_list) { 322 - if (node->ts == trace) { 323 - mutex_unlock(&all_stat_sessions_mutex); 324 - return -EINVAL; 325 - } 318 + if (node->ts == trace) 319 + goto out; 326 320 } 327 - mutex_unlock(&all_stat_sessions_mutex); 328 321 322 + ret = -ENOMEM; 329 323 /* Init the session */ 330 324 session = kzalloc(sizeof(*session), GFP_KERNEL); 331 325 if (!session) 332 - return -ENOMEM; 326 + goto out; 333 327 334 328 session->ts = trace; 335 329 INIT_LIST_HEAD(&session->session_list); ··· 336 334 ret = init_stat_file(session); 337 335 if (ret) { 338 336 destroy_session(session); 339 - return ret; 337 + goto out; 340 338 } 341 339 340 + ret = 0; 342 341 /* Register */ 343 - mutex_lock(&all_stat_sessions_mutex); 344 342 list_add_tail(&session->session_list, &all_stat_sessions); 343 + out: 345 344 mutex_unlock(&all_stat_sessions_mutex); 346 345 347 - return 0; 346 + return ret; 348 347 } 349 348 350 349 void unregister_stat_tracer(struct tracer_stat *trace)
+4 -4
kernel/trace/trace_syscalls.c
··· 297 297 struct syscall_trace_enter *entry; 298 298 struct syscall_metadata *sys_data; 299 299 struct ring_buffer_event *event; 300 - struct ring_buffer *buffer; 300 + struct trace_buffer *buffer; 301 301 unsigned long irq_flags; 302 302 unsigned long args[6]; 303 303 int pc; ··· 325 325 local_save_flags(irq_flags); 326 326 pc = preempt_count(); 327 327 328 - buffer = tr->trace_buffer.buffer; 328 + buffer = tr->array_buffer.buffer; 329 329 event = trace_buffer_lock_reserve(buffer, 330 330 sys_data->enter_event->event.type, size, irq_flags, pc); 331 331 if (!event) ··· 347 347 struct syscall_trace_exit *entry; 348 348 struct syscall_metadata *sys_data; 349 349 struct ring_buffer_event *event; 350 - struct ring_buffer *buffer; 350 + struct trace_buffer *buffer; 351 351 unsigned long irq_flags; 352 352 int pc; 353 353 int syscall_nr; ··· 371 371 local_save_flags(irq_flags); 372 372 pc = preempt_count(); 373 373 374 - buffer = tr->trace_buffer.buffer; 374 + buffer = tr->array_buffer.buffer; 375 375 event = trace_buffer_lock_reserve(buffer, 376 376 sys_data->exit_event->event.type, sizeof(*entry), 377 377 irq_flags, pc);
+1 -1
kernel/trace/trace_uprobe.c
··· 931 931 struct trace_event_file *trace_file) 932 932 { 933 933 struct uprobe_trace_entry_head *entry; 934 + struct trace_buffer *buffer; 934 935 struct ring_buffer_event *event; 935 - struct ring_buffer *buffer; 936 936 void *data; 937 937 int size, esize; 938 938 struct trace_event_call *call = trace_probe_event_call(&tu->tp);
+3
lib/Kconfig
··· 573 573 config LIBFDT 574 574 bool 575 575 576 + config LIBXBC 577 + bool 578 + 576 579 config OID_REGISTRY 577 580 tristate 578 581 help
+2
lib/Makefile
··· 230 230 $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt)) 231 231 lib-$(CONFIG_LIBFDT) += $(libfdt_files) 232 232 233 + lib-$(CONFIG_LIBXBC) += bootconfig.o 234 + 233 235 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o 234 236 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o 235 237
+814
lib/bootconfig.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Extra Boot Config 4 + * Masami Hiramatsu <mhiramat@kernel.org> 5 + */ 6 + 7 + #define pr_fmt(fmt) "bootconfig: " fmt 8 + 9 + #include <linux/bug.h> 10 + #include <linux/ctype.h> 11 + #include <linux/errno.h> 12 + #include <linux/kernel.h> 13 + #include <linux/printk.h> 14 + #include <linux/bootconfig.h> 15 + #include <linux/string.h> 16 + 17 + /* 18 + * Extra Boot Config (XBC) is given as tree-structured ascii text of 19 + * key-value pairs on memory. 20 + * xbc_parse() parses the text to build a simple tree. Each tree node is 21 + * simply a key word or a value. A key node may have a next key node or/and 22 + * a child node (both key and value). A value node may have a next value 23 + * node (for array). 24 + */ 25 + 26 + static struct xbc_node xbc_nodes[XBC_NODE_MAX] __initdata; 27 + static int xbc_node_num __initdata; 28 + static char *xbc_data __initdata; 29 + static size_t xbc_data_size __initdata; 30 + static struct xbc_node *last_parent __initdata; 31 + 32 + static int __init xbc_parse_error(const char *msg, const char *p) 33 + { 34 + int pos = p - xbc_data; 35 + 36 + pr_err("Parse error at pos %d: %s\n", pos, msg); 37 + return -EINVAL; 38 + } 39 + 40 + /** 41 + * xbc_root_node() - Get the root node of extended boot config 42 + * 43 + * Return the address of root node of extended boot config. If the 44 + * extended boot config is not initiized, return NULL. 45 + */ 46 + struct xbc_node * __init xbc_root_node(void) 47 + { 48 + if (unlikely(!xbc_data)) 49 + return NULL; 50 + 51 + return xbc_nodes; 52 + } 53 + 54 + /** 55 + * xbc_node_index() - Get the index of XBC node 56 + * @node: A target node of getting index. 57 + * 58 + * Return the index number of @node in XBC node list. 59 + */ 60 + int __init xbc_node_index(struct xbc_node *node) 61 + { 62 + return node - &xbc_nodes[0]; 63 + } 64 + 65 + /** 66 + * xbc_node_get_parent() - Get the parent XBC node 67 + * @node: An XBC node. 68 + * 69 + * Return the parent node of @node. If the node is top node of the tree, 70 + * return NULL. 71 + */ 72 + struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node) 73 + { 74 + return node->parent == XBC_NODE_MAX ? NULL : &xbc_nodes[node->parent]; 75 + } 76 + 77 + /** 78 + * xbc_node_get_child() - Get the child XBC node 79 + * @node: An XBC node. 80 + * 81 + * Return the first child node of @node. If the node has no child, return 82 + * NULL. 83 + */ 84 + struct xbc_node * __init xbc_node_get_child(struct xbc_node *node) 85 + { 86 + return node->child ? &xbc_nodes[node->child] : NULL; 87 + } 88 + 89 + /** 90 + * xbc_node_get_next() - Get the next sibling XBC node 91 + * @node: An XBC node. 92 + * 93 + * Return the NEXT sibling node of @node. If the node has no next sibling, 94 + * return NULL. Note that even if this returns NULL, it doesn't mean @node 95 + * has no siblings. (You also has to check whether the parent's child node 96 + * is @node or not.) 97 + */ 98 + struct xbc_node * __init xbc_node_get_next(struct xbc_node *node) 99 + { 100 + return node->next ? &xbc_nodes[node->next] : NULL; 101 + } 102 + 103 + /** 104 + * xbc_node_get_data() - Get the data of XBC node 105 + * @node: An XBC node. 106 + * 107 + * Return the data (which is always a null terminated string) of @node. 108 + * If the node has invalid data, warn and return NULL. 109 + */ 110 + const char * __init xbc_node_get_data(struct xbc_node *node) 111 + { 112 + int offset = node->data & ~XBC_VALUE; 113 + 114 + if (WARN_ON(offset >= xbc_data_size)) 115 + return NULL; 116 + 117 + return xbc_data + offset; 118 + } 119 + 120 + static bool __init 121 + xbc_node_match_prefix(struct xbc_node *node, const char **prefix) 122 + { 123 + const char *p = xbc_node_get_data(node); 124 + int len = strlen(p); 125 + 126 + if (strncmp(*prefix, p, len)) 127 + return false; 128 + 129 + p = *prefix + len; 130 + if (*p == '.') 131 + p++; 132 + else if (*p != '\0') 133 + return false; 134 + *prefix = p; 135 + 136 + return true; 137 + } 138 + 139 + /** 140 + * xbc_node_find_child() - Find a child node which matches given key 141 + * @parent: An XBC node. 142 + * @key: A key string. 143 + * 144 + * Search a node under @parent which matches @key. The @key can contain 145 + * several words jointed with '.'. If @parent is NULL, this searches the 146 + * node from whole tree. Return NULL if no node is matched. 147 + */ 148 + struct xbc_node * __init 149 + xbc_node_find_child(struct xbc_node *parent, const char *key) 150 + { 151 + struct xbc_node *node; 152 + 153 + if (parent) 154 + node = xbc_node_get_child(parent); 155 + else 156 + node = xbc_root_node(); 157 + 158 + while (node && xbc_node_is_key(node)) { 159 + if (!xbc_node_match_prefix(node, &key)) 160 + node = xbc_node_get_next(node); 161 + else if (*key != '\0') 162 + node = xbc_node_get_child(node); 163 + else 164 + break; 165 + } 166 + 167 + return node; 168 + } 169 + 170 + /** 171 + * xbc_node_find_value() - Find a value node which matches given key 172 + * @parent: An XBC node. 173 + * @key: A key string. 174 + * @vnode: A container pointer of found XBC node. 175 + * 176 + * Search a value node under @parent whose (parent) key node matches @key, 177 + * store it in *@vnode, and returns the value string. 178 + * The @key can contain several words jointed with '.'. If @parent is NULL, 179 + * this searches the node from whole tree. Return the value string if a 180 + * matched key found, return NULL if no node is matched. 181 + * Note that this returns 0-length string and stores NULL in *@vnode if the 182 + * key has no value. And also it will return the value of the first entry if 183 + * the value is an array. 184 + */ 185 + const char * __init 186 + xbc_node_find_value(struct xbc_node *parent, const char *key, 187 + struct xbc_node **vnode) 188 + { 189 + struct xbc_node *node = xbc_node_find_child(parent, key); 190 + 191 + if (!node || !xbc_node_is_key(node)) 192 + return NULL; 193 + 194 + node = xbc_node_get_child(node); 195 + if (node && !xbc_node_is_value(node)) 196 + return NULL; 197 + 198 + if (vnode) 199 + *vnode = node; 200 + 201 + return node ? xbc_node_get_data(node) : ""; 202 + } 203 + 204 + /** 205 + * xbc_node_compose_key_after() - Compose partial key string of the XBC node 206 + * @root: Root XBC node 207 + * @node: Target XBC node. 208 + * @buf: A buffer to store the key. 209 + * @size: The size of the @buf. 210 + * 211 + * Compose the partial key of the @node into @buf, which is starting right 212 + * after @root (@root is not included.) If @root is NULL, this returns full 213 + * key words of @node. 214 + * Returns the total length of the key stored in @buf. Returns -EINVAL 215 + * if @node is NULL or @root is not the ancestor of @node or @root is @node, 216 + * or returns -ERANGE if the key depth is deeper than max depth. 217 + * This is expected to be used with xbc_find_node() to list up all (child) 218 + * keys under given key. 219 + */ 220 + int __init xbc_node_compose_key_after(struct xbc_node *root, 221 + struct xbc_node *node, 222 + char *buf, size_t size) 223 + { 224 + u16 keys[XBC_DEPTH_MAX]; 225 + int depth = 0, ret = 0, total = 0; 226 + 227 + if (!node || node == root) 228 + return -EINVAL; 229 + 230 + if (xbc_node_is_value(node)) 231 + node = xbc_node_get_parent(node); 232 + 233 + while (node && node != root) { 234 + keys[depth++] = xbc_node_index(node); 235 + if (depth == XBC_DEPTH_MAX) 236 + return -ERANGE; 237 + node = xbc_node_get_parent(node); 238 + } 239 + if (!node && root) 240 + return -EINVAL; 241 + 242 + while (--depth >= 0) { 243 + node = xbc_nodes + keys[depth]; 244 + ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node), 245 + depth ? "." : ""); 246 + if (ret < 0) 247 + return ret; 248 + if (ret > size) { 249 + size = 0; 250 + } else { 251 + size -= ret; 252 + buf += ret; 253 + } 254 + total += ret; 255 + } 256 + 257 + return total; 258 + } 259 + 260 + /** 261 + * xbc_node_find_next_leaf() - Find the next leaf node under given node 262 + * @root: An XBC root node 263 + * @node: An XBC node which starts from. 264 + * 265 + * Search the next leaf node (which means the terminal key node) of @node 266 + * under @root node (including @root node itself). 267 + * Return the next node or NULL if next leaf node is not found. 268 + */ 269 + struct xbc_node * __init xbc_node_find_next_leaf(struct xbc_node *root, 270 + struct xbc_node *node) 271 + { 272 + if (unlikely(!xbc_data)) 273 + return NULL; 274 + 275 + if (!node) { /* First try */ 276 + node = root; 277 + if (!node) 278 + node = xbc_nodes; 279 + } else { 280 + if (node == root) /* @root was a leaf, no child node. */ 281 + return NULL; 282 + 283 + while (!node->next) { 284 + node = xbc_node_get_parent(node); 285 + if (node == root) 286 + return NULL; 287 + /* User passed a node which is not uder parent */ 288 + if (WARN_ON(!node)) 289 + return NULL; 290 + } 291 + node = xbc_node_get_next(node); 292 + } 293 + 294 + while (node && !xbc_node_is_leaf(node)) 295 + node = xbc_node_get_child(node); 296 + 297 + return node; 298 + } 299 + 300 + /** 301 + * xbc_node_find_next_key_value() - Find the next key-value pair nodes 302 + * @root: An XBC root node 303 + * @leaf: A container pointer of XBC node which starts from. 304 + * 305 + * Search the next leaf node (which means the terminal key node) of *@leaf 306 + * under @root node. Returns the value and update *@leaf if next leaf node 307 + * is found, or NULL if no next leaf node is found. 308 + * Note that this returns 0-length string if the key has no value, or 309 + * the value of the first entry if the value is an array. 310 + */ 311 + const char * __init xbc_node_find_next_key_value(struct xbc_node *root, 312 + struct xbc_node **leaf) 313 + { 314 + /* tip must be passed */ 315 + if (WARN_ON(!leaf)) 316 + return NULL; 317 + 318 + *leaf = xbc_node_find_next_leaf(root, *leaf); 319 + if (!*leaf) 320 + return NULL; 321 + if ((*leaf)->child) 322 + return xbc_node_get_data(xbc_node_get_child(*leaf)); 323 + else 324 + return ""; /* No value key */ 325 + } 326 + 327 + /* XBC parse and tree build */ 328 + 329 + static struct xbc_node * __init xbc_add_node(char *data, u32 flag) 330 + { 331 + struct xbc_node *node; 332 + unsigned long offset; 333 + 334 + if (xbc_node_num == XBC_NODE_MAX) 335 + return NULL; 336 + 337 + node = &xbc_nodes[xbc_node_num++]; 338 + offset = data - xbc_data; 339 + node->data = (u16)offset; 340 + if (WARN_ON(offset >= XBC_DATA_MAX)) 341 + return NULL; 342 + node->data |= flag; 343 + node->child = 0; 344 + node->next = 0; 345 + 346 + return node; 347 + } 348 + 349 + static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node) 350 + { 351 + while (node->next) 352 + node = xbc_node_get_next(node); 353 + 354 + return node; 355 + } 356 + 357 + static struct xbc_node * __init xbc_add_sibling(char *data, u32 flag) 358 + { 359 + struct xbc_node *sib, *node = xbc_add_node(data, flag); 360 + 361 + if (node) { 362 + if (!last_parent) { 363 + node->parent = XBC_NODE_MAX; 364 + sib = xbc_last_sibling(xbc_nodes); 365 + sib->next = xbc_node_index(node); 366 + } else { 367 + node->parent = xbc_node_index(last_parent); 368 + if (!last_parent->child) { 369 + last_parent->child = xbc_node_index(node); 370 + } else { 371 + sib = xbc_node_get_child(last_parent); 372 + sib = xbc_last_sibling(sib); 373 + sib->next = xbc_node_index(node); 374 + } 375 + } 376 + } else 377 + xbc_parse_error("Too many nodes", data); 378 + 379 + return node; 380 + } 381 + 382 + static inline __init struct xbc_node *xbc_add_child(char *data, u32 flag) 383 + { 384 + struct xbc_node *node = xbc_add_sibling(data, flag); 385 + 386 + if (node) 387 + last_parent = node; 388 + 389 + return node; 390 + } 391 + 392 + static inline __init bool xbc_valid_keyword(char *key) 393 + { 394 + if (key[0] == '\0') 395 + return false; 396 + 397 + while (isalnum(*key) || *key == '-' || *key == '_') 398 + key++; 399 + 400 + return *key == '\0'; 401 + } 402 + 403 + static char *skip_comment(char *p) 404 + { 405 + char *ret; 406 + 407 + ret = strchr(p, '\n'); 408 + if (!ret) 409 + ret = p + strlen(p); 410 + else 411 + ret++; 412 + 413 + return ret; 414 + } 415 + 416 + static char *skip_spaces_until_newline(char *p) 417 + { 418 + while (isspace(*p) && *p != '\n') 419 + p++; 420 + return p; 421 + } 422 + 423 + static int __init __xbc_open_brace(void) 424 + { 425 + /* Mark the last key as open brace */ 426 + last_parent->next = XBC_NODE_MAX; 427 + 428 + return 0; 429 + } 430 + 431 + static int __init __xbc_close_brace(char *p) 432 + { 433 + struct xbc_node *node; 434 + 435 + if (!last_parent || last_parent->next != XBC_NODE_MAX) 436 + return xbc_parse_error("Unexpected closing brace", p); 437 + 438 + node = last_parent; 439 + node->next = 0; 440 + do { 441 + node = xbc_node_get_parent(node); 442 + } while (node && node->next != XBC_NODE_MAX); 443 + last_parent = node; 444 + 445 + return 0; 446 + } 447 + 448 + /* 449 + * Return delimiter or error, no node added. As same as lib/cmdline.c, 450 + * you can use " around spaces, but can't escape " for value. 451 + */ 452 + static int __init __xbc_parse_value(char **__v, char **__n) 453 + { 454 + char *p, *v = *__v; 455 + int c, quotes = 0; 456 + 457 + v = skip_spaces(v); 458 + while (*v == '#') { 459 + v = skip_comment(v); 460 + v = skip_spaces(v); 461 + } 462 + if (*v == '"' || *v == '\'') { 463 + quotes = *v; 464 + v++; 465 + } 466 + p = v - 1; 467 + while ((c = *++p)) { 468 + if (!isprint(c) && !isspace(c)) 469 + return xbc_parse_error("Non printable value", p); 470 + if (quotes) { 471 + if (c != quotes) 472 + continue; 473 + quotes = 0; 474 + *p++ = '\0'; 475 + p = skip_spaces_until_newline(p); 476 + c = *p; 477 + if (c && !strchr(",;\n#}", c)) 478 + return xbc_parse_error("No value delimiter", p); 479 + if (*p) 480 + p++; 481 + break; 482 + } 483 + if (strchr(",;\n#}", c)) { 484 + v = strim(v); 485 + *p++ = '\0'; 486 + break; 487 + } 488 + } 489 + if (quotes) 490 + return xbc_parse_error("No closing quotes", p); 491 + if (c == '#') { 492 + p = skip_comment(p); 493 + c = '\n'; /* A comment must be treated as a newline */ 494 + } 495 + *__n = p; 496 + *__v = v; 497 + 498 + return c; 499 + } 500 + 501 + static int __init xbc_parse_array(char **__v) 502 + { 503 + struct xbc_node *node; 504 + char *next; 505 + int c = 0; 506 + 507 + do { 508 + c = __xbc_parse_value(__v, &next); 509 + if (c < 0) 510 + return c; 511 + 512 + node = xbc_add_sibling(*__v, XBC_VALUE); 513 + if (!node) 514 + return -ENOMEM; 515 + *__v = next; 516 + } while (c == ','); 517 + node->next = 0; 518 + 519 + return c; 520 + } 521 + 522 + static inline __init 523 + struct xbc_node *find_match_node(struct xbc_node *node, char *k) 524 + { 525 + while (node) { 526 + if (!strcmp(xbc_node_get_data(node), k)) 527 + break; 528 + node = xbc_node_get_next(node); 529 + } 530 + return node; 531 + } 532 + 533 + static int __init __xbc_add_key(char *k) 534 + { 535 + struct xbc_node *node; 536 + 537 + if (!xbc_valid_keyword(k)) 538 + return xbc_parse_error("Invalid keyword", k); 539 + 540 + if (unlikely(xbc_node_num == 0)) 541 + goto add_node; 542 + 543 + if (!last_parent) /* the first level */ 544 + node = find_match_node(xbc_nodes, k); 545 + else 546 + node = find_match_node(xbc_node_get_child(last_parent), k); 547 + 548 + if (node) 549 + last_parent = node; 550 + else { 551 + add_node: 552 + node = xbc_add_child(k, XBC_KEY); 553 + if (!node) 554 + return -ENOMEM; 555 + } 556 + return 0; 557 + } 558 + 559 + static int __init __xbc_parse_keys(char *k) 560 + { 561 + char *p; 562 + int ret; 563 + 564 + k = strim(k); 565 + while ((p = strchr(k, '.'))) { 566 + *p++ = '\0'; 567 + ret = __xbc_add_key(k); 568 + if (ret) 569 + return ret; 570 + k = p; 571 + } 572 + 573 + return __xbc_add_key(k); 574 + } 575 + 576 + static int __init xbc_parse_kv(char **k, char *v) 577 + { 578 + struct xbc_node *prev_parent = last_parent; 579 + struct xbc_node *node; 580 + char *next; 581 + int c, ret; 582 + 583 + ret = __xbc_parse_keys(*k); 584 + if (ret) 585 + return ret; 586 + 587 + c = __xbc_parse_value(&v, &next); 588 + if (c < 0) 589 + return c; 590 + 591 + node = xbc_add_sibling(v, XBC_VALUE); 592 + if (!node) 593 + return -ENOMEM; 594 + 595 + if (c == ',') { /* Array */ 596 + c = xbc_parse_array(&next); 597 + if (c < 0) 598 + return c; 599 + } 600 + 601 + last_parent = prev_parent; 602 + 603 + if (c == '}') { 604 + ret = __xbc_close_brace(next - 1); 605 + if (ret < 0) 606 + return ret; 607 + } 608 + 609 + *k = next; 610 + 611 + return 0; 612 + } 613 + 614 + static int __init xbc_parse_key(char **k, char *n) 615 + { 616 + struct xbc_node *prev_parent = last_parent; 617 + int ret; 618 + 619 + *k = strim(*k); 620 + if (**k != '\0') { 621 + ret = __xbc_parse_keys(*k); 622 + if (ret) 623 + return ret; 624 + last_parent = prev_parent; 625 + } 626 + *k = n; 627 + 628 + return 0; 629 + } 630 + 631 + static int __init xbc_open_brace(char **k, char *n) 632 + { 633 + int ret; 634 + 635 + ret = __xbc_parse_keys(*k); 636 + if (ret) 637 + return ret; 638 + *k = n; 639 + 640 + return __xbc_open_brace(); 641 + } 642 + 643 + static int __init xbc_close_brace(char **k, char *n) 644 + { 645 + int ret; 646 + 647 + ret = xbc_parse_key(k, n); 648 + if (ret) 649 + return ret; 650 + /* k is updated in xbc_parse_key() */ 651 + 652 + return __xbc_close_brace(n - 1); 653 + } 654 + 655 + static int __init xbc_verify_tree(void) 656 + { 657 + int i, depth, len, wlen; 658 + struct xbc_node *n, *m; 659 + 660 + /* Empty tree */ 661 + if (xbc_node_num == 0) { 662 + xbc_parse_error("Empty config", xbc_data); 663 + return -ENOENT; 664 + } 665 + 666 + for (i = 0; i < xbc_node_num; i++) { 667 + if (xbc_nodes[i].next > xbc_node_num) { 668 + return xbc_parse_error("No closing brace", 669 + xbc_node_get_data(xbc_nodes + i)); 670 + } 671 + } 672 + 673 + /* Key tree limitation check */ 674 + n = &xbc_nodes[0]; 675 + depth = 1; 676 + len = 0; 677 + 678 + while (n) { 679 + wlen = strlen(xbc_node_get_data(n)) + 1; 680 + len += wlen; 681 + if (len > XBC_KEYLEN_MAX) 682 + return xbc_parse_error("Too long key length", 683 + xbc_node_get_data(n)); 684 + 685 + m = xbc_node_get_child(n); 686 + if (m && xbc_node_is_key(m)) { 687 + n = m; 688 + depth++; 689 + if (depth > XBC_DEPTH_MAX) 690 + return xbc_parse_error("Too many key words", 691 + xbc_node_get_data(n)); 692 + continue; 693 + } 694 + len -= wlen; 695 + m = xbc_node_get_next(n); 696 + while (!m) { 697 + n = xbc_node_get_parent(n); 698 + if (!n) 699 + break; 700 + len -= strlen(xbc_node_get_data(n)) + 1; 701 + depth--; 702 + m = xbc_node_get_next(n); 703 + } 704 + n = m; 705 + } 706 + 707 + return 0; 708 + } 709 + 710 + /** 711 + * xbc_destroy_all() - Clean up all parsed bootconfig 712 + * 713 + * This clears all data structures of parsed bootconfig on memory. 714 + * If you need to reuse xbc_init() with new boot config, you can 715 + * use this. 716 + */ 717 + void __init xbc_destroy_all(void) 718 + { 719 + xbc_data = NULL; 720 + xbc_data_size = 0; 721 + xbc_node_num = 0; 722 + memset(xbc_nodes, 0, sizeof(xbc_nodes)); 723 + } 724 + 725 + /** 726 + * xbc_init() - Parse given XBC file and build XBC internal tree 727 + * @buf: boot config text 728 + * 729 + * This parses the boot config text in @buf. @buf must be a 730 + * null terminated string and smaller than XBC_DATA_MAX. 731 + * Return the number of stored nodes (>0) if succeeded, or -errno 732 + * if there is any error. 733 + */ 734 + int __init xbc_init(char *buf) 735 + { 736 + char *p, *q; 737 + int ret, c; 738 + 739 + if (xbc_data) { 740 + pr_err("Error: bootconfig is already initialized.\n"); 741 + return -EBUSY; 742 + } 743 + 744 + ret = strlen(buf); 745 + if (ret > XBC_DATA_MAX - 1 || ret == 0) { 746 + pr_err("Error: Config data is %s.\n", 747 + ret ? "too big" : "empty"); 748 + return -ERANGE; 749 + } 750 + 751 + xbc_data = buf; 752 + xbc_data_size = ret + 1; 753 + last_parent = NULL; 754 + 755 + p = buf; 756 + do { 757 + q = strpbrk(p, "{}=;\n#"); 758 + if (!q) { 759 + p = skip_spaces(p); 760 + if (*p != '\0') 761 + ret = xbc_parse_error("No delimiter", p); 762 + break; 763 + } 764 + 765 + c = *q; 766 + *q++ = '\0'; 767 + switch (c) { 768 + case '=': 769 + ret = xbc_parse_kv(&p, q); 770 + break; 771 + case '{': 772 + ret = xbc_open_brace(&p, q); 773 + break; 774 + case '#': 775 + q = skip_comment(q); 776 + /* fall through */ 777 + case ';': 778 + case '\n': 779 + ret = xbc_parse_key(&p, q); 780 + break; 781 + case '}': 782 + ret = xbc_close_brace(&p, q); 783 + break; 784 + } 785 + } while (!ret); 786 + 787 + if (!ret) 788 + ret = xbc_verify_tree(); 789 + 790 + if (ret < 0) 791 + xbc_destroy_all(); 792 + else 793 + ret = xbc_node_num; 794 + 795 + return ret; 796 + } 797 + 798 + /** 799 + * xbc_debug_dump() - Dump current XBC node list 800 + * 801 + * Dump the current XBC node list on printk buffer for debug. 802 + */ 803 + void __init xbc_debug_dump(void) 804 + { 805 + int i; 806 + 807 + for (i = 0; i < xbc_node_num; i++) { 808 + pr_debug("[%d] %s (%s) .next=%d, .child=%d .parent=%d\n", i, 809 + xbc_node_get_data(xbc_nodes + i), 810 + xbc_node_is_value(xbc_nodes + i) ? "value" : "key", 811 + xbc_nodes[i].next, xbc_nodes[i].child, 812 + xbc_nodes[i].parent); 813 + } 814 + }
+6 -5
tools/Makefile
··· 28 28 @echo ' pci - PCI tools' 29 29 @echo ' perf - Linux performance measurement and analysis tool' 30 30 @echo ' selftests - various kernel selftests' 31 + @echo ' bootconfig - boot config tool' 31 32 @echo ' spi - spi tools' 32 33 @echo ' tmon - thermal monitoring and tuning tool' 33 34 @echo ' turbostat - Intel CPU idle stats and freq reporting tool' ··· 64 63 cpupower: FORCE 65 64 $(call descend,power/$@) 66 65 67 - cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE 66 + cgroup firewire hv guest bootconfig spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE 68 67 $(call descend,$@) 69 68 70 69 liblockdep: FORCE ··· 97 96 $(call descend,kvm/$@) 98 97 99 98 all: acpi cgroup cpupower gpio hv firewire liblockdep \ 100 - perf selftests spi turbostat usb \ 99 + perf selftests bootconfig spi turbostat usb \ 101 100 virtio vm bpf x86_energy_perf_policy \ 102 101 tmon freefall iio objtool kvm_stat wmi \ 103 102 pci debugging ··· 108 107 cpupower_install: 109 108 $(call descend,power/$(@:_install=),install) 110 109 111 - cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install: 110 + cgroup_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install: 112 111 $(call descend,$(@:_install=),install) 113 112 114 113 liblockdep_install: ··· 142 141 cpupower_clean: 143 142 $(call descend,power/cpupower,clean) 144 143 145 - cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean: 144 + cgroup_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean: 146 145 $(call descend,$(@:_clean=),clean) 147 146 148 147 liblockdep_clean: ··· 177 176 $(call descend,build,clean) 178 177 179 178 clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \ 180 - perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \ 179 + perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \ 181 180 vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ 182 181 freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \ 183 182 gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \
+1
tools/bootconfig/.gitignore
··· 1 + bootconfig
+23
tools/bootconfig/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # Makefile for bootconfig command 3 + 4 + bindir ?= /usr/bin 5 + 6 + HEADER = include/linux/bootconfig.h 7 + CFLAGS = -Wall -g -I./include 8 + 9 + PROGS = bootconfig 10 + 11 + all: $(PROGS) 12 + 13 + bootconfig: ../../lib/bootconfig.c main.c $(HEADER) 14 + $(CC) $(filter %.c,$^) $(CFLAGS) -o $@ 15 + 16 + install: $(PROGS) 17 + install bootconfig $(DESTDIR)$(bindir) 18 + 19 + test: bootconfig 20 + ./test-bootconfig.sh 21 + 22 + clean: 23 + $(RM) -f *.o bootconfig
+7
tools/bootconfig/include/linux/bootconfig.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _BOOTCONFIG_LINUX_BOOTCONFIG_H 3 + #define _BOOTCONFIG_LINUX_BOOTCONFIG_H 4 + 5 + #include "../../../../include/linux/bootconfig.h" 6 + 7 + #endif
+12
tools/bootconfig/include/linux/bug.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_BUG_H 3 + #define _SKC_LINUX_BUG_H 4 + 5 + #include <stdio.h> 6 + #include <stdlib.h> 7 + 8 + #define WARN_ON(cond) \ 9 + ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \ 10 + __FILE__, __LINE__, __func__, #cond) : 0) 11 + 12 + #endif
+7
tools/bootconfig/include/linux/ctype.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_CTYPE_H 3 + #define _SKC_LINUX_CTYPE_H 4 + 5 + #include <ctype.h> 6 + 7 + #endif
+7
tools/bootconfig/include/linux/errno.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_ERRNO_H 3 + #define _SKC_LINUX_ERRNO_H 4 + 5 + #include <asm/errno.h> 6 + 7 + #endif
+18
tools/bootconfig/include/linux/kernel.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_KERNEL_H 3 + #define _SKC_LINUX_KERNEL_H 4 + 5 + #include <stdlib.h> 6 + #include <stdbool.h> 7 + 8 + #include <linux/printk.h> 9 + 10 + typedef unsigned short u16; 11 + typedef unsigned int u32; 12 + 13 + #define unlikely(cond) (cond) 14 + 15 + #define __init 16 + #define __initdata 17 + 18 + #endif
+17
tools/bootconfig/include/linux/printk.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_PRINTK_H 3 + #define _SKC_LINUX_PRINTK_H 4 + 5 + #include <stdio.h> 6 + 7 + /* controllable printf */ 8 + extern int pr_output; 9 + #define printk(fmt, ...) \ 10 + (pr_output ? printf(fmt, __VA_ARGS__) : 0) 11 + 12 + #define pr_err printk 13 + #define pr_warn printk 14 + #define pr_info printk 15 + #define pr_debug printk 16 + 17 + #endif
+32
tools/bootconfig/include/linux/string.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _SKC_LINUX_STRING_H 3 + #define _SKC_LINUX_STRING_H 4 + 5 + #include <string.h> 6 + 7 + /* Copied from lib/string.c */ 8 + static inline char *skip_spaces(const char *str) 9 + { 10 + while (isspace(*str)) 11 + ++str; 12 + return (char *)str; 13 + } 14 + 15 + static inline char *strim(char *s) 16 + { 17 + size_t size; 18 + char *end; 19 + 20 + size = strlen(s); 21 + if (!size) 22 + return s; 23 + 24 + end = s + size - 1; 25 + while (end >= s && isspace(*end)) 26 + end--; 27 + *(end + 1) = '\0'; 28 + 29 + return skip_spaces(s); 30 + } 31 + 32 + #endif
+354
tools/bootconfig/main.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Boot config tool for initrd image 4 + */ 5 + #include <stdio.h> 6 + #include <stdlib.h> 7 + #include <sys/types.h> 8 + #include <sys/stat.h> 9 + #include <fcntl.h> 10 + #include <unistd.h> 11 + #include <string.h> 12 + #include <errno.h> 13 + 14 + #include <linux/kernel.h> 15 + #include <linux/bootconfig.h> 16 + 17 + int pr_output = 1; 18 + 19 + static int xbc_show_array(struct xbc_node *node) 20 + { 21 + const char *val; 22 + int i = 0; 23 + 24 + xbc_array_for_each_value(node, val) { 25 + printf("\"%s\"%s", val, node->next ? ", " : ";\n"); 26 + i++; 27 + } 28 + return i; 29 + } 30 + 31 + static void xbc_show_compact_tree(void) 32 + { 33 + struct xbc_node *node, *cnode; 34 + int depth = 0, i; 35 + 36 + node = xbc_root_node(); 37 + while (node && xbc_node_is_key(node)) { 38 + for (i = 0; i < depth; i++) 39 + printf("\t"); 40 + cnode = xbc_node_get_child(node); 41 + while (cnode && xbc_node_is_key(cnode) && !cnode->next) { 42 + printf("%s.", xbc_node_get_data(node)); 43 + node = cnode; 44 + cnode = xbc_node_get_child(node); 45 + } 46 + if (cnode && xbc_node_is_key(cnode)) { 47 + printf("%s {\n", xbc_node_get_data(node)); 48 + depth++; 49 + node = cnode; 50 + continue; 51 + } else if (cnode && xbc_node_is_value(cnode)) { 52 + printf("%s = ", xbc_node_get_data(node)); 53 + if (cnode->next) 54 + xbc_show_array(cnode); 55 + else 56 + printf("\"%s\";\n", xbc_node_get_data(cnode)); 57 + } else { 58 + printf("%s;\n", xbc_node_get_data(node)); 59 + } 60 + 61 + if (node->next) { 62 + node = xbc_node_get_next(node); 63 + continue; 64 + } 65 + while (!node->next) { 66 + node = xbc_node_get_parent(node); 67 + if (!node) 68 + return; 69 + if (!xbc_node_get_child(node)->next) 70 + continue; 71 + depth--; 72 + for (i = 0; i < depth; i++) 73 + printf("\t"); 74 + printf("}\n"); 75 + } 76 + node = xbc_node_get_next(node); 77 + } 78 + } 79 + 80 + /* Simple real checksum */ 81 + int checksum(unsigned char *buf, int len) 82 + { 83 + int i, sum = 0; 84 + 85 + for (i = 0; i < len; i++) 86 + sum += buf[i]; 87 + 88 + return sum; 89 + } 90 + 91 + #define PAGE_SIZE 4096 92 + 93 + int load_xbc_fd(int fd, char **buf, int size) 94 + { 95 + int ret; 96 + 97 + *buf = malloc(size + 1); 98 + if (!*buf) 99 + return -ENOMEM; 100 + 101 + ret = read(fd, *buf, size); 102 + if (ret < 0) 103 + return -errno; 104 + (*buf)[size] = '\0'; 105 + 106 + return ret; 107 + } 108 + 109 + /* Return the read size or -errno */ 110 + int load_xbc_file(const char *path, char **buf) 111 + { 112 + struct stat stat; 113 + int fd, ret; 114 + 115 + fd = open(path, O_RDONLY); 116 + if (fd < 0) 117 + return -errno; 118 + ret = fstat(fd, &stat); 119 + if (ret < 0) 120 + return -errno; 121 + 122 + ret = load_xbc_fd(fd, buf, stat.st_size); 123 + 124 + close(fd); 125 + 126 + return ret; 127 + } 128 + 129 + int load_xbc_from_initrd(int fd, char **buf) 130 + { 131 + struct stat stat; 132 + int ret; 133 + u32 size = 0, csum = 0, rcsum; 134 + 135 + ret = fstat(fd, &stat); 136 + if (ret < 0) 137 + return -errno; 138 + 139 + if (stat.st_size < 8) 140 + return 0; 141 + 142 + if (lseek(fd, -8, SEEK_END) < 0) { 143 + printf("Failed to lseek: %d\n", -errno); 144 + return -errno; 145 + } 146 + 147 + if (read(fd, &size, sizeof(u32)) < 0) 148 + return -errno; 149 + 150 + if (read(fd, &csum, sizeof(u32)) < 0) 151 + return -errno; 152 + 153 + /* Wrong size, maybe no boot config here */ 154 + if (stat.st_size < size + 8) 155 + return 0; 156 + 157 + if (lseek(fd, stat.st_size - 8 - size, SEEK_SET) < 0) { 158 + printf("Failed to lseek: %d\n", -errno); 159 + return -errno; 160 + } 161 + 162 + ret = load_xbc_fd(fd, buf, size); 163 + if (ret < 0) 164 + return ret; 165 + 166 + /* Wrong Checksum, maybe no boot config here */ 167 + rcsum = checksum((unsigned char *)*buf, size); 168 + if (csum != rcsum) { 169 + printf("checksum error: %d != %d\n", csum, rcsum); 170 + return 0; 171 + } 172 + 173 + ret = xbc_init(*buf); 174 + /* Wrong data, maybe no boot config here */ 175 + if (ret < 0) 176 + return 0; 177 + 178 + return size; 179 + } 180 + 181 + int show_xbc(const char *path) 182 + { 183 + int ret, fd; 184 + char *buf = NULL; 185 + 186 + fd = open(path, O_RDONLY); 187 + if (fd < 0) { 188 + printf("Failed to open initrd %s: %d\n", path, fd); 189 + return -errno; 190 + } 191 + 192 + ret = load_xbc_from_initrd(fd, &buf); 193 + if (ret < 0) 194 + printf("Failed to load a boot config from initrd: %d\n", ret); 195 + else 196 + xbc_show_compact_tree(); 197 + 198 + close(fd); 199 + free(buf); 200 + 201 + return ret; 202 + } 203 + 204 + int delete_xbc(const char *path) 205 + { 206 + struct stat stat; 207 + int ret = 0, fd, size; 208 + char *buf = NULL; 209 + 210 + fd = open(path, O_RDWR); 211 + if (fd < 0) { 212 + printf("Failed to open initrd %s: %d\n", path, fd); 213 + return -errno; 214 + } 215 + 216 + /* 217 + * Suppress error messages in xbc_init() because it can be just a 218 + * data which concidentally matches the size and checksum footer. 219 + */ 220 + pr_output = 0; 221 + size = load_xbc_from_initrd(fd, &buf); 222 + pr_output = 1; 223 + if (size < 0) { 224 + ret = size; 225 + printf("Failed to load a boot config from initrd: %d\n", ret); 226 + } else if (size > 0) { 227 + ret = fstat(fd, &stat); 228 + if (!ret) 229 + ret = ftruncate(fd, stat.st_size - size - 8); 230 + if (ret) 231 + ret = -errno; 232 + } /* Ignore if there is no boot config in initrd */ 233 + 234 + close(fd); 235 + free(buf); 236 + 237 + return ret; 238 + } 239 + 240 + int apply_xbc(const char *path, const char *xbc_path) 241 + { 242 + u32 size, csum; 243 + char *buf, *data; 244 + int ret, fd; 245 + 246 + ret = load_xbc_file(xbc_path, &buf); 247 + if (ret < 0) { 248 + printf("Failed to load %s : %d\n", xbc_path, ret); 249 + return ret; 250 + } 251 + size = strlen(buf) + 1; 252 + csum = checksum((unsigned char *)buf, size); 253 + 254 + /* Prepare xbc_path data */ 255 + data = malloc(size + 8); 256 + if (!data) 257 + return -ENOMEM; 258 + strcpy(data, buf); 259 + *(u32 *)(data + size) = size; 260 + *(u32 *)(data + size + 4) = csum; 261 + 262 + /* Check the data format */ 263 + ret = xbc_init(buf); 264 + if (ret < 0) { 265 + printf("Failed to parse %s: %d\n", xbc_path, ret); 266 + free(data); 267 + free(buf); 268 + return ret; 269 + } 270 + printf("Apply %s to %s\n", xbc_path, path); 271 + printf("\tNumber of nodes: %d\n", ret); 272 + printf("\tSize: %u bytes\n", (unsigned int)size); 273 + printf("\tChecksum: %d\n", (unsigned int)csum); 274 + 275 + /* TODO: Check the options by schema */ 276 + xbc_destroy_all(); 277 + free(buf); 278 + 279 + /* Remove old boot config if exists */ 280 + ret = delete_xbc(path); 281 + if (ret < 0) { 282 + printf("Failed to delete previous boot config: %d\n", ret); 283 + return ret; 284 + } 285 + 286 + /* Apply new one */ 287 + fd = open(path, O_RDWR | O_APPEND); 288 + if (fd < 0) { 289 + printf("Failed to open %s: %d\n", path, fd); 290 + return fd; 291 + } 292 + /* TODO: Ensure the @path is initramfs/initrd image */ 293 + ret = write(fd, data, size + 8); 294 + if (ret < 0) { 295 + printf("Failed to apply a boot config: %d\n", ret); 296 + return ret; 297 + } 298 + close(fd); 299 + free(data); 300 + 301 + return 0; 302 + } 303 + 304 + int usage(void) 305 + { 306 + printf("Usage: bootconfig [OPTIONS] <INITRD>\n" 307 + " Apply, delete or show boot config to initrd.\n" 308 + " Options:\n" 309 + " -a <config>: Apply boot config to initrd\n" 310 + " -d : Delete boot config file from initrd\n\n" 311 + " If no option is given, show current applied boot config.\n"); 312 + return -1; 313 + } 314 + 315 + int main(int argc, char **argv) 316 + { 317 + char *path = NULL; 318 + char *apply = NULL; 319 + bool delete = false; 320 + int opt; 321 + 322 + while ((opt = getopt(argc, argv, "hda:")) != -1) { 323 + switch (opt) { 324 + case 'd': 325 + delete = true; 326 + break; 327 + case 'a': 328 + apply = optarg; 329 + break; 330 + case 'h': 331 + default: 332 + return usage(); 333 + } 334 + } 335 + 336 + if (apply && delete) { 337 + printf("Error: You can not specify both -a and -d at once.\n"); 338 + return usage(); 339 + } 340 + 341 + if (optind >= argc) { 342 + printf("Error: No initrd is specified.\n"); 343 + return usage(); 344 + } 345 + 346 + path = argv[optind]; 347 + 348 + if (apply) 349 + return apply_xbc(path, apply); 350 + else if (delete) 351 + return delete_xbc(path); 352 + 353 + return show_xbc(path); 354 + }
+5
tools/bootconfig/samples/bad-array-space-comment.bconf
··· 1 + key = # comment 2 + "value1", # comment1 3 + "value2" # comment2 4 + , 5 + "value3"
+2
tools/bootconfig/samples/bad-array.bconf
··· 1 + # Array must be comma separated. 2 + key = "value1" "value2"
+4
tools/bootconfig/samples/bad-dotword.bconf
··· 1 + # do not start keyword with . 2 + key { 3 + .word = 1 4 + }
+1
tools/bootconfig/samples/bad-empty.bconf
··· 1 + # Wrong boot config: comment only
+2
tools/bootconfig/samples/bad-keyerror.bconf
··· 1 + # key word can not contain "," 2 + key,word
+1
tools/bootconfig/samples/bad-longkey.bconf
··· 1 + key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
+1
tools/bootconfig/samples/bad-manywords.bconf
··· 1 + key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
+2
tools/bootconfig/samples/bad-no-keyword.bconf
··· 1 + # No keyword 2 + {}
+2
tools/bootconfig/samples/bad-nonprintable.bconf
··· 1 + # Non printable 2 + key = ""
+2
tools/bootconfig/samples/bad-spaceword.bconf
··· 1 + # No space between words 2 + key . word
+5
tools/bootconfig/samples/bad-tree.bconf
··· 1 + # brace is not closing 2 + tree { 3 + node { 4 + value = 1 5 + }
+3
tools/bootconfig/samples/bad-value.bconf
··· 1 + # Quotes error 2 + value = "data 3 +
+3
tools/bootconfig/samples/escaped.bconf
··· 1 + key1 = "A\B\C" 2 + key2 = '\'\'' 3 + key3 = "\\"
+4
tools/bootconfig/samples/good-array-space-comment.bconf
··· 1 + key = # comment 2 + "value1", # comment1 3 + "value2" , # comment2 4 + "value3"
+1
tools/bootconfig/samples/good-comment-after-value.bconf
··· 1 + key = "value" # comment
+2
tools/bootconfig/samples/good-printables.bconf
··· 1 + key = " 2 + !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+11
tools/bootconfig/samples/good-simple.bconf
··· 1 + # A good simple bootconfig 2 + 3 + key.word1 = 1 4 + key.word2=2 5 + key.word3 = 3; 6 + 7 + key { 8 + word4 = 4 } 9 + 10 + key { word5 = 5; word6 = 6 } 11 +
+4
tools/bootconfig/samples/good-single.bconf
··· 1 + # single key style 2 + key = 1 3 + key2 = 2 4 + key3 = "alpha", "beta"
+1
tools/bootconfig/samples/good-space-after-value.bconf
··· 1 + key = "value"
+12
tools/bootconfig/samples/good-tree.bconf
··· 1 + key { 2 + word { 3 + tree { 4 + value = "0"} 5 + } 6 + word2 { 7 + tree { 8 + value = 1,2 } 9 + } 10 + } 11 + other.tree { 12 + value = 2; value2 = 3;}
+105
tools/bootconfig/test-bootconfig.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + echo "Boot config test script" 5 + 6 + BOOTCONF=./bootconfig 7 + INITRD=`mktemp initrd-XXXX` 8 + TEMPCONF=`mktemp temp-XXXX.bconf` 9 + NG=0 10 + 11 + cleanup() { 12 + rm -f $INITRD $TEMPCONF 13 + exit $NG 14 + } 15 + 16 + trap cleanup EXIT TERM 17 + 18 + NO=1 19 + 20 + xpass() { # pass test command 21 + echo "test case $NO ($3)... " 22 + if ! ($@ && echo "\t\t[OK]"); then 23 + echo "\t\t[NG]"; NG=$((NG + 1)) 24 + fi 25 + NO=$((NO + 1)) 26 + } 27 + 28 + xfail() { # fail test command 29 + echo "test case $NO ($3)... " 30 + if ! (! $@ && echo "\t\t[OK]"); then 31 + echo "\t\t[NG]"; NG=$((NG + 1)) 32 + fi 33 + NO=$((NO + 1)) 34 + } 35 + 36 + echo "Basic command test" 37 + xpass $BOOTCONF $INITRD 38 + 39 + echo "Delete command should success without bootconfig" 40 + xpass $BOOTCONF -d $INITRD 41 + 42 + dd if=/dev/zero of=$INITRD bs=4096 count=1 43 + echo "key = value;" > $TEMPCONF 44 + bconf_size=$(stat -c %s $TEMPCONF) 45 + initrd_size=$(stat -c %s $INITRD) 46 + 47 + echo "Apply command test" 48 + xpass $BOOTCONF -a $TEMPCONF $INITRD 49 + new_size=$(stat -c %s $INITRD) 50 + 51 + echo "File size check" 52 + xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9) 53 + 54 + echo "Apply command repeat test" 55 + xpass $BOOTCONF -a $TEMPCONF $INITRD 56 + 57 + echo "File size check" 58 + xpass test $new_size -eq $(stat -c %s $INITRD) 59 + 60 + echo "Delete command check" 61 + xpass $BOOTCONF -d $INITRD 62 + 63 + echo "File size check" 64 + new_size=$(stat -c %s $INITRD) 65 + xpass test $new_size -eq $initrd_size 66 + 67 + echo "Max node number check" 68 + 69 + echo -n > $TEMPCONF 70 + for i in `seq 1 1024` ; do 71 + echo "node$i" >> $TEMPCONF 72 + done 73 + xpass $BOOTCONF -a $TEMPCONF $INITRD 74 + 75 + echo "badnode" >> $TEMPCONF 76 + xfail $BOOTCONF -a $TEMPCONF $INITRD 77 + 78 + echo "Max filesize check" 79 + 80 + # Max size is 32767 (including terminal byte) 81 + echo -n "data = \"" > $TEMPCONF 82 + dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF 83 + echo "\"" >> $TEMPCONF 84 + xfail $BOOTCONF -a $TEMPCONF $INITRD 85 + 86 + truncate -s 32764 $TEMPCONF 87 + echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0') 88 + xpass $BOOTCONF -a $TEMPCONF $INITRD 89 + 90 + echo "=== expected failure cases ===" 91 + for i in samples/bad-* ; do 92 + xfail $BOOTCONF -a $i $INITRD 93 + done 94 + 95 + echo "=== expected success cases ===" 96 + for i in samples/good-* ; do 97 + xpass $BOOTCONF -a $i $INITRD 98 + done 99 + 100 + echo 101 + if [ $NG -eq 0 ]; then 102 + echo "All tests passed" 103 + else 104 + echo "$NG tests failed" 105 + fi
+32
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-syntax-errors.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: event trigger - test histogram parser errors 4 + 5 + if [ ! -f set_event -o ! -d events/kmem ]; then 6 + echo "event tracing is not supported" 7 + exit_unsupported 8 + fi 9 + 10 + if [ ! -f events/kmem/kmalloc/trigger ]; then 11 + echo "event trigger is not supported" 12 + exit_unsupported 13 + fi 14 + 15 + if [ ! -f events/kmem/kmalloc/hist ]; then 16 + echo "hist trigger is not supported" 17 + exit_unsupported 18 + fi 19 + 20 + [ -f error_log ] || exit_unsupported 21 + 22 + check_error() { # command-with-error-pos-by-^ 23 + ftrace_errlog_check 'hist:kmem:kmalloc' "$1" 'events/kmem/kmalloc/trigger' 24 + } 25 + 26 + check_error 'hist:keys=common_pid:vals=bytes_req:sort=common_pid,^junk' # INVALID_SORT_FIELD 27 + check_error 'hist:keys=common_pid:vals=bytes_req:^sort=' # EMPTY_ASSIGNMENT 28 + check_error 'hist:keys=common_pid:vals=bytes_req:^sort=common_pid,' # EMPTY_SORT_FIELD 29 + check_error 'hist:keys=common_pid:vals=bytes_req:sort=common_pid.^junk' # INVALID_SORT_MODIFIER 30 + check_error 'hist:keys=common_pid:vals=bytes_req,bytes_alloc:^sort=common_pid,bytes_req,bytes_alloc' # TOO_MANY_SORT_FIELDS 31 + 32 + exit 0