diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-23 13:28:57 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-23 13:28:57 -0700 |
| commit | 4352b8aee98005853aa63f57d6377282de17a33f (patch) | |
| tree | 27614d7a9ef05c32d089004e104364ce42324837 /tools/perf/util/trace-event-read.c | |
| download | linux-stable-4352b8aee98005853aa63f57d6377282de17a33f.tar.gz linux-stable-4352b8aee98005853aa63f57d6377282de17a33f.zip | |
Merge tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linuxgrafted
Pull I3C updates from Alexandre Belloni:
"A new driver this cycle, for the AMD AXI I3C controller.
There are also new features such as IBI wakeup support, SETAASA device
discovery and ACPI support for the the DAA methods, meaning we can now
communicate with the SPD devices on DDR5 modules.
New driver:
- AMD AXI I3C master controller
Subsystem:
- I3C Common Command Code (CCC) handling improvements, especially
around GET CCCs
- SETAASA device discovery support
- ACPI support for all existing DAA methods like SETDASA, SETNEWDA as
well as I2C devices on I3C bus
- IBI-based wakeup support
Drivers:
- dw: SETAASA support
- mipi-i3c-hci: advertise IBI wakeup capability, AMD_PT I3C
controller support, PIO queue management support for HCI v1.2
- renesas: improve suspend to RAM support, add runtime PM support"
* tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux: (70 commits)
i3c: dw: reduce do_daa time if there's no client
i3c: mipi-i3c-hci: Add support for AMD_PT I3C controller
i3c: mipi-i3c-hci: Add PIO queue management support for HCI v1.2
i3c: mipi-i3c-hci: Fix missing STAT_IBI_STATUS_THLD in PIO mode
i3c: dw: rename "pclk" to "apb" to match dt-binding
i3c: dw: make struct dw_i3c_cmd smaller
i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding
i3c: renesas: Don't register devices when ENTDAA times out
i3c: master: dw-i3c-master: fix OD timing for first broadcast
i3c: mipi-i3c-hci: Advertise IBI wakeup capability
i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev()
i3c: mipi-i3c-hci-pci: Propagate I3C wakeup requirements to PCI
i3c: master: Reject IBI requests from non-IBI-capable devices
i3c: master: Add helper to query bus wakeup requirements
i3c: master: Report wakeup events for IBIs
i3c: master: Support IBI-based wakeup capability
i3c: master: Fix potential UAF in i3c_device_match()
i3c: master: Fix potential UAF in i3c_device_uevent()
i3c: Make dev->desc locking assumptions explicit
i3c: master: Fix use-after-free of master->this
...
Diffstat (limited to 'tools/perf/util/trace-event-read.c')
| -rw-r--r-- | tools/perf/util/trace-event-read.c | 500 |
1 files changed, 500 insertions, 0 deletions
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c new file mode 100644 index 000000000..db1622fc9 --- /dev/null +++ b/tools/perf/util/trace-event-read.c @@ -0,0 +1,500 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com> + */ +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <sys/mman.h> +#include <event-parse.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <limits.h> + +#include "trace-event.h" +#include "debug.h" +#include "util.h" + +static int input_fd; + +static ssize_t trace_data_size; +static bool repipe; + +static ssize_t __do_read(int fd, void *buf, size_t size) +{ + size_t rsize = size; + + while (size) { + ssize_t ret = read(fd, buf, size); + + if (ret <= 0) + return -1; + + if (repipe) { + ssize_t retw = write(STDOUT_FILENO, buf, ret); + + if (retw <= 0 || retw != ret) { + pr_debug("repiping input file"); + return -1; + } + } + + size -= ret; + buf += ret; + } + + return rsize; +} + +static ssize_t do_read(void *data, size_t size) +{ + ssize_t r; + + r = __do_read(input_fd, data, size); + if (r <= 0) { + pr_debug("reading input file (size expected=%zu received=%zd)", + size, r); + return -1; + } + + trace_data_size += r; + + return r; +} + +/* If it fails, the next read will report it */ +static void skip(size_t size) +{ + char buf[BUFSIZ]; + ssize_t ret; + + while (size) { + size_t len = size > BUFSIZ ? BUFSIZ : size; + + ret = do_read(buf, len); + if (ret <= 0) + break; + + size -= ret; + } +} + +static unsigned int read4(struct tep_handle *pevent) +{ + unsigned int data; + + if (do_read(&data, 4) < 0) + return 0; + return tep_read_number(pevent, &data, 4); +} + +static unsigned long long read8(struct tep_handle *pevent) +{ + unsigned long long data; + + if (do_read(&data, 8) < 0) + return 0; + return tep_read_number(pevent, &data, 8); +} + +static char *read_string(void) +{ + char buf[BUFSIZ]; + char *str = NULL; + int size = 0; + off_t r; + char c; + + for (;;) { + r = read(input_fd, &c, 1); + if (r < 0) { + pr_debug("reading input file"); + goto out; + } + + if (!r) { + pr_debug("no data"); + goto out; + } + + if (repipe) { + int retw = write(STDOUT_FILENO, &c, 1); + + if (retw <= 0 || retw != r) { + pr_debug("repiping input file string"); + goto out; + } + } + + if (size >= (int)sizeof(buf) - 1) { + pr_debug("string too long (max %zu bytes)", sizeof(buf) - 1); + goto out; + } + + buf[size++] = c; + + if (!c) + break; + } + + trace_data_size += size; + + str = malloc(size); + if (str) + memcpy(str, buf, size); +out: + return str; +} + +static int read_proc_kallsyms(struct tep_handle *pevent) +{ + unsigned int size; + + size = read4(pevent); + if (!size) + return 0; + /* + * Just skip it, now that we configure libtraceevent to use the + * tools/perf/ symbol resolver. + * + * We need to skip it so that we can continue parsing old perf.data + * files, that contains this /proc/kallsyms payload. + * + * Newer perf.data files will have just the 4-bytes zeros "kallsyms + * payload", so that older tools can continue reading it and interpret + * it as "no kallsyms payload is present". + */ + lseek(input_fd, size, SEEK_CUR); + trace_data_size += size; + return 0; +} + +static int read_ftrace_printk(struct tep_handle *pevent) +{ + unsigned int size; + char *buf; + + /* it can have 0 size */ + size = read4(pevent); + if (!size) + return 0; + + if (size == UINT_MAX) { + pr_debug("invalid ftrace printk size\n"); + return -1; + } + + buf = malloc(size + 1); + if (buf == NULL) + return -1; + + if (do_read(buf, size) < 0) { + free(buf); + return -1; + } + + buf[size] = '\0'; + + parse_ftrace_printk(pevent, buf, size); + + free(buf); + return 0; +} + +static int read_header_files(struct tep_handle *pevent) +{ + unsigned long long size; + char *header_page; + char buf[BUFSIZ]; + ssize_t ret = 0; + + if (do_read(buf, 12) < 0) + return -1; + + if (memcmp(buf, "header_page", 12) != 0) { + pr_debug("did not read header page"); + return -1; + } + + size = read8(pevent); + + header_page = malloc(size); + if (header_page == NULL) + return -1; + + if (do_read(header_page, size) < 0) { + pr_debug("did not read header page"); + free(header_page); + return -1; + } + + if (!tep_parse_header_page(pevent, header_page, size, + tep_get_long_size(pevent))) { + /* + * The commit field in the page is of type long, + * use that instead, since it represents the kernel. + */ + tep_set_long_size(pevent, tep_get_header_page_size(pevent)); + } + free(header_page); + + if (do_read(buf, 13) < 0) + return -1; + + if (memcmp(buf, "header_event", 13) != 0) { + pr_debug("did not read header event"); + return -1; + } + + size = read8(pevent); + skip(size); + + return ret; +} + +static int read_ftrace_file(struct tep_handle *pevent, unsigned long long size) +{ + ssize_t ret; + char *buf; + + buf = malloc(size); + if (buf == NULL) { + pr_debug("memory allocation failure\n"); + return -1; + } + + ret = do_read(buf, size); + if (ret < 0) { + pr_debug("error reading ftrace file.\n"); + goto out; + } + + ret = parse_ftrace_file(pevent, buf, size); + if (ret < 0) + pr_debug("error parsing ftrace file.\n"); +out: + free(buf); + return ret; +} + +static int read_event_file(struct tep_handle *pevent, char *sys, + unsigned long long size) +{ + ssize_t ret; + char *buf; + + buf = malloc(size); + if (buf == NULL) { + pr_debug("memory allocation failure\n"); + return -1; + } + + ret = do_read(buf, size); + if (ret < 0) + goto out; + + ret = parse_event_file(pevent, buf, size, sys); + if (ret < 0) + pr_debug("error parsing event file.\n"); +out: + free(buf); + return ret; +} + +static int read_ftrace_files(struct tep_handle *pevent) +{ + unsigned long long size; + int count; + int i; + int ret; + + count = read4(pevent); + + for (i = 0; i < count; i++) { + size = read8(pevent); + ret = read_ftrace_file(pevent, size); + if (ret) + return ret; + } + return 0; +} + +static int read_event_files(struct tep_handle *pevent) +{ + unsigned long long size; + char *sys; + int systems; + int count; + int i,x; + ssize_t ret; + + systems = read4(pevent); + + for (i = 0; i < systems; i++) { + sys = read_string(); + if (sys == NULL) + return -1; + + count = read4(pevent); + + for (x=0; x < count; x++) { + size = read8(pevent); + ret = read_event_file(pevent, sys, size); + if (ret) { + free(sys); + return ret; + } + } + free(sys); + } + return 0; +} + +static int read_saved_cmdline(struct tep_handle *pevent) +{ + unsigned long long size; + char *buf; + ssize_t ret; + + /* it can have 0 size */ + size = read8(pevent); + if (!size) + return 0; + + if (size == ULLONG_MAX) { + pr_debug("invalid saved cmdline size"); + return -1; + } + + buf = malloc(size + 1); + if (buf == NULL) { + pr_debug("memory allocation failure\n"); + return -1; + } + + ret = do_read(buf, size); + if (ret < 0) { + pr_debug("error reading saved cmdlines\n"); + goto out; + } + buf[ret] = '\0'; + + parse_saved_cmdline(pevent, buf, size); + ret = 0; +out: + free(buf); + return ret; +} + +ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe) +{ + char buf[BUFSIZ]; + char test[] = { 23, 8, 68 }; + char *version; + int show_version = 0; + int show_funcs = 0; + int show_printk = 0; + ssize_t size = -1; + int file_bigendian; + int host_bigendian; + int file_long_size; + int file_page_size; + struct tep_handle *pevent = NULL; + int err; + + repipe = __repipe; + input_fd = fd; + + if (do_read(buf, 3) < 0) + return -1; + if (memcmp(buf, test, 3) != 0) { + pr_debug("no trace data in the file"); + return -1; + } + + if (do_read(buf, 7) < 0) + return -1; + if (memcmp(buf, "tracing", 7) != 0) { + pr_debug("not a trace file (missing 'tracing' tag)"); + return -1; + } + + version = read_string(); + if (version == NULL) + return -1; + if (show_version) + printf("version = %s\n", version); + + if (do_read(buf, 1) < 0) { + free(version); + return -1; + } + file_bigendian = buf[0]; + host_bigendian = host_is_bigendian() ? 1 : 0; + + if (trace_event__init(tevent)) { + pr_debug("trace_event__init failed"); + goto out; + } + + pevent = tevent->pevent; + + tep_set_flag(pevent, TEP_NSEC_OUTPUT); + tep_set_file_bigendian(pevent, file_bigendian); + tep_set_local_bigendian(pevent, host_bigendian); + + if (do_read(buf, 1) < 0) + goto out; + file_long_size = buf[0]; + + file_page_size = read4(pevent); + if (!file_page_size) + goto out; + + tep_set_long_size(pevent, file_long_size); + tep_set_page_size(pevent, file_page_size); + + err = read_header_files(pevent); + if (err) + goto out; + err = read_ftrace_files(pevent); + if (err) + goto out; + err = read_event_files(pevent); + if (err) + goto out; + err = read_proc_kallsyms(pevent); + if (err) + goto out; + err = read_ftrace_printk(pevent); + if (err) + goto out; + if (atof(version) >= 0.6) { + err = read_saved_cmdline(pevent); + if (err) + goto out; + } + + size = trace_data_size; + repipe = false; + + if (show_funcs) { + tep_print_funcs(pevent); + } else if (show_printk) { + tep_print_printk(pevent); + } + + pevent = NULL; + +out: + if (pevent) + trace_event__cleanup(tevent); + free(version); + return size; +} |
