Ubuntu-focal-kernel/tools/perf/util
Namhyung Kim 77e45cf939 perf tools: Handle old data in PERF_RECORD_ATTR
BugLink: https://bugs.launchpad.net/bugs/2040284

commit 9bf63282ea77a531ea58acb42fb3f40d2d1e4497 upstream.

The PERF_RECORD_ATTR is used for a pipe mode to describe an event with
attribute and IDs.  The ID table comes after the attr and it calculate
size of the table using the total record size and the attr size.

  n_ids = (total_record_size - end_of_the_attr_field) / sizeof(u64)

This is fine for most use cases, but sometimes it saves the pipe output
in a file and then process it later.  And it becomes a problem if there
is a change in attr size between the record and report.

  $ perf record -o- > perf-pipe.data  # old version
  $ perf report -i- < perf-pipe.data  # new version

For example, if the attr size is 128 and it has 4 IDs, then it would
save them in 168 byte like below:

   8 byte: perf event header { .type = PERF_RECORD_ATTR, .size = 168 },
 128 byte: perf event attr { .size = 128, ... },
  32 byte: event IDs [] = { 1234, 1235, 1236, 1237 },

But when report later, it thinks the attr size is 136 then it only read
the last 3 entries as ID.

   8 byte: perf event header { .type = PERF_RECORD_ATTR, .size = 168 },
 136 byte: perf event attr { .size = 136, ... },
  24 byte: event IDs [] = { 1235, 1236, 1237 },  // 1234 is missing

So it should use the recorded version of the attr.  The attr has the
size field already then it should honor the size when reading data.

Fixes: 2c46dbb517 ("perf: Convert perf header attrs into attr events")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tom Zanussi <zanussi@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230825152552.112913-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2023-10-30 11:42:20 +01:00
..
c++ perf clang: Delete needless util-cxx.h header 2019-08-28 18:14:57 -03:00
cs-etm-decoder perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
include
intel-pt-decoder perf intel-pt: Fix CYC timestamps after standalone CBR 2023-08-09 12:25:23 +02:00
libunwind perf tools: Remove debug.h from places where it is not needed 2019-09-20 09:19:20 -03:00
scripting-engines perf scripting python: Avoid declaring function pointers with a visibility attribute 2020-12-10 12:06:42 +01:00
Build perf evsel: Introduce evsel_fprintf.h 2019-09-25 16:26:34 -03:00
PERF-VERSION-GEN
annotate.c perf annotate bpf: Don't enclose non-debug code with an assert() 2023-10-30 11:42:18 +01:00
annotate.h perf annotate: Don't return -1 for error when doing BPF disassembly 2019-09-30 17:30:06 -03:00
archinsn.h
arm-spe-pkt-decoder.c
arm-spe-pkt-decoder.h
arm-spe.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
arm-spe.h
auxtrace.c perf auxtrace: Fix address filter entire kernel size 2023-08-09 12:25:23 +02:00
auxtrace.h perf tools: Rename 'struct perf_mmap' to 'struct mmap' 2019-09-25 09:51:44 -03:00
block-range.c
block-range.h
bpf-event.c perf bpf: Avoid memory leak from perf_env__insert_btf() 2022-01-13 18:42:57 +01:00
bpf-event.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
bpf-loader.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
bpf-loader.h
bpf-prologue.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
bpf-prologue.h
bpf_map.c
bpf_map.h
branch.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
branch.h perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
build-id.c perf copyfile: Move copyfile routines to separate files 2019-09-25 09:51:49 -03:00
build-id.h
cache.h
cacheline.c perf tools: Remove perf.h from source files not needing it 2019-08-29 17:38:32 -03:00
cacheline.h
call-path.c
call-path.h
callchain.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
callchain.h perf callchain: Remove needless event.h include 2019-09-20 09:19:21 -03:00
cap.c
cap.h
cgroup.c perf auxtrace: Uninline functions that touch perf_session 2019-08-31 22:24:10 -03:00
cgroup.h
cloexec.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
cloexec.h
color.c perf tools: Remove needless evlist.h include directives 2019-08-31 22:24:10 -03:00
color.h
color_config.c perf tools: Remove needless evlist.h include directives 2019-08-31 22:24:10 -03:00
comm.c
comm.h
compress.h
config.c perf auxtrace: Uninline functions that touch perf_session 2019-08-31 22:24:10 -03:00
config.h
copyfile.c perf tools: Fix mode setting in copyfile_mode_ns() 2019-10-15 12:05:18 -03:00
copyfile.h perf copyfile: Move copyfile routines to separate files 2019-09-25 09:51:49 -03:00
counts.c
counts.h
cpu-set-sched.h
cpumap.c perf cpumap: Fix snprintf overflow check 2020-11-09 14:47:40 +01:00
cpumap.h libperf: Rename the PERF_RECORD_ structs to have a "perf" prefix 2019-08-29 08:36:12 -03:00
cputopo.c
cputopo.h perf env: Remove env.h from other headers where just a fwd decl is needed 2019-08-31 19:10:40 -03:00
cs-etm.c perf cs-etm: Move definition of 'traceid_list' global variable from header file 2020-11-09 14:48:26 +01:00
cs-etm.h perf cs-etm: Move definition of 'traceid_list' global variable from header file 2020-11-09 14:48:26 +01:00
data-convert-bt.c perf session: Return error code for perf_session__new() function on failure 2019-09-20 15:58:11 -03:00
data-convert-bt.h
data-convert.h
data.c perf tools: Fix resources leak in perf_data__open_dir() 2023-02-01 15:23:40 +01:00
data.h perf tools: Add missing headers needed by util/data.h 2022-08-26 11:07:45 +02:00
db-export.c perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
db-export.h
debug.c perf script: Fix hex dump character output 2022-03-07 16:36:58 +01:00
debug.h perf debug: No need to include ui/util.h 2019-09-20 09:19:20 -03:00
demangle-java.c perf tools: Remove debug.h from places where it is not needed 2019-09-20 09:19:20 -03:00
demangle-java.h
demangle-rust.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
demangle-rust.h
dso.c perf dso: Fix memory leak in dso__new_map() 2021-09-20 18:49:27 +02:00
dso.h perf symbols: Fix debuginfo search for Ubuntu 2020-08-08 01:53:12 -04:00
dsos.c perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
dsos.h perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
dump-insn.c
dump-insn.h
dwarf-aux.c perf dwarf-aux: Fix off-by-one in die_get_varname() 2023-10-02 12:12:05 +02:00
dwarf-aux.h perf probe: Fix to show function entry line as probe-able 2020-01-06 08:16:48 -06:00
dwarf-regs.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
env.c perf bpf: Avoid memory leak from perf_env__insert_btf() 2022-01-13 18:42:57 +01:00
env.h perf bpf: Avoid memory leak from perf_env__insert_btf() 2022-01-13 18:42:57 +01:00
event.c perf tools: Fix DSO filtering when not finding a map for a sampled address 2021-04-14 18:31:32 +02:00
event.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
events_stats.h perf tools: Move 'struct events_stats' and prototypes to separate header 2019-08-31 22:24:10 -03:00
evlist.c perf evlist: Fix cpu/thread map leak 2020-11-09 14:46:56 +01:00
evlist.h perf evlist: Remove unused perf_evlist__fprintf() method 2019-09-25 16:26:40 -03:00
evsel.c perf evsel: Fix 2 memory leaks 2020-11-09 14:47:52 +01:00
evsel.h perf evsel: Move config terms to a separate header 2019-09-25 16:26:40 -03:00
evsel_config.h perf evsel: Move config terms to a separate header 2019-09-25 16:26:40 -03:00
evsel_fprintf.c perf evsel: Introduce evsel_fprintf.h 2019-09-25 16:26:34 -03:00
evsel_fprintf.h perf evsel: Introduce evsel_fprintf.h 2019-09-25 16:26:34 -03:00
evswitch.c
evswitch.h
expr.h
expr.y perf tools: Use %define api.pure full instead of %pure-parser 2021-05-04 16:11:22 +02:00
find-map.c
genelf.c perf jit: Include program header in ELF files 2022-11-24 10:28:49 +01:00
genelf.h perf jit: Include program header in ELF files 2022-11-24 10:28:49 +01:00
genelf_debug.c perf tools: Remove perf.h from source files not needing it 2019-08-29 17:38:32 -03:00
generate-cmdlist.sh
get_current_dir_name.c perf tools: Fixup get_current_dir_name() compilation 2022-11-24 10:29:16 +01:00
get_current_dir_name.h
group.h
header.c perf tools: Handle old data in PERF_RECORD_ATTR 2023-10-30 11:42:20 +01:00
header.h perf tools: Move event synthesizing routines to separate .c file 2019-09-20 10:28:21 -03:00
help-unknown-cmd.c
help-unknown-cmd.h
hist.c perf tools: Fix time sorting 2019-11-05 08:49:14 -03:00
hist.h perf hist: Fix memory leak of a perf_hpp_fmt 2022-02-03 18:57:21 +01:00
intel-bts.c libperf: Move 'ids' from 'struct evsel' to 'struct perf_evsel' 2019-09-25 09:51:47 -03:00
intel-bts.h
intel-pt.c perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc 2023-01-06 08:44:06 -08:00
intel-pt.h
intlist.c
intlist.h
jit.h
jitdump.c perf inject jit: Fix JIT_CODE_MOVE filename 2019-09-30 17:29:49 -03:00
jitdump.h
kvm-stat.h perf kvm: Add arch neutral function to choose event for perf kvm record 2019-09-20 10:28:26 -03:00
levenshtein.c
levenshtein.h
llvm-utils.c perf llvm: Fix inadvertent file creation 2023-05-12 17:15:05 +02:00
llvm-utils.h perf tools: Remove debug.h from header files not needing it 2019-08-29 17:38:32 -03:00
lzma.c perf lzma: Close lzma stream on exit 2021-09-20 18:49:27 +02:00
machine.c perf machine: Initialize srcline string member in add_location struct 2021-10-12 16:31:42 -06:00
machine.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
map.c perf map: Tighten snprintf() string precision to pass gcc check on some 32-bit arches 2021-05-04 16:11:22 +02:00
map.h
map_groups.h
map_symbol.h
mem-events.c perf symbols: Move mem_info and branch_info out of symbol.h 2019-08-31 22:27:48 -03:00
mem-events.h perf symbols: Move mem_info and branch_info out of symbol.h 2019-08-31 22:27:48 -03:00
mem2node.c perf mem2node: Avoid double free related to realloc 2020-11-09 14:47:48 +01:00
mem2node.h perf env: Remove env.h from other headers where just a fwd decl is needed 2019-08-31 19:10:40 -03:00
memswap.c
memswap.h perf memswap: Adopt 'struct u64_swap' from evsel.h 2019-09-20 09:19:22 -03:00
metricgroup.c perf metricgroup: Free metric_events on error 2020-11-09 14:47:53 +01:00
metricgroup.h perf metricgroup: Scale the metric result 2019-08-31 22:27:52 -03:00
mmap.c libperf: Use sys/types.h to get ssize_t, not unistd.h 2019-09-25 09:51:49 -03:00
mmap.h libperf: Add 'flush' to 'struct perf_mmap' 2019-09-25 09:51:46 -03:00
namespaces.c perf tools: Move event synthesizing routines to separate .c file 2019-09-20 10:28:21 -03:00
namespaces.h perf tools: Move event synthesizing routines to separate .c file 2019-09-20 10:28:21 -03:00
ordered-events.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
ordered-events.h
parse-branch-options.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
parse-branch-options.h
parse-events.c perf parse-events: Use strcmp() to compare the PMU name 2020-11-09 14:47:56 +01:00
parse-events.h
parse-events.l
parse-events.y perf tools: Use %define api.pure full instead of %pure-parser 2021-05-04 16:11:22 +02:00
parse-regs-options.c perf record: Fix memory leak when using '--user-regs=?' to list registers 2021-01-20 14:26:11 +01:00
parse-regs-options.h
path.c perf tools: Remove needless evlist.h include directives 2019-08-31 22:24:10 -03:00
path.h perf tools: Remove needless evlist.h include directives 2019-08-31 22:24:10 -03:00
perf-hooks-list.h
perf-hooks.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
perf-hooks.h
perf_event_attr_fprintf.c perf evsel: Introduce evsel_fprintf.h 2019-09-25 16:26:34 -03:00
perf_regs.c
perf_regs.h perf regs: Make perf_reg_name() return "unknown" instead of NULL 2020-01-06 10:11:48 -06:00
pmu.c perf test: Free formats for perf pmu parse test 2020-11-09 14:46:57 +01:00
pmu.h perf test: Free formats for perf pmu parse test 2020-11-09 14:46:57 +01:00
pmu.l
pmu.y
print_binary.c perf python scripting: Fix printable strings in python3 scripts 2020-12-10 12:03:21 +01:00
print_binary.h
probe-event.c perf probe: Fix ppc64 'perf probe add events failed' case 2022-04-14 11:32:02 +02:00
probe-event.h
probe-file.c perf probe-file: Delete namelist in del_events() on the error path 2021-09-20 18:49:27 +02:00
probe-file.h
probe-finder.c perf probe: Fix memory leakage when the probe point is not found 2020-09-16 05:13:26 -04:00
probe-finder.h
pstack.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
pstack.h
python-ext-sources perf evsel: Introduce evsel_fprintf.h 2019-09-25 16:26:34 -03:00
python.c perf evsel: Fall back to global 'perf_env' in perf_evsel__env() 2019-09-30 17:29:57 -03:00
rb_resort.h
rblist.c
rblist.h
record.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
record.h
rlimit.c
rlimit.h
rwsem.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
rwsem.h
s390-cpumcf-kernel.h
s390-cpumsf-kernel.h
s390-cpumsf.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
s390-cpumsf.h
s390-sample-raw.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
sample-raw.c
sample-raw.h
session.c perf session: Remap buf if there is no space for event 2022-05-20 15:20:00 +02:00
session.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
setns.c
setup.py
smt.c
smt.h
sort.c perf map: Delete two variable initialisations before null pointer checks in sort__sym_from_cmp() 2023-08-09 12:25:25 +02:00
sort.h perf tools: Move 'struct events_stats' and prototypes to separate header 2019-08-31 22:24:10 -03:00
srccode.c libperf: Move 'page_size' global variable to libperf 2019-09-25 09:51:48 -03:00
srccode.h
srcline.c perf: Make perf able to build with latest libbfd 2020-06-22 17:23:46 -03:00
srcline.h
stat-display.c perf stat: Fix printing os->prefix in CSV metrics output 2023-02-01 15:20:58 +01:00
stat-shadow.c perf stat: Don't report a null stalled cycles per insn metric 2020-02-20 08:35:36 -06:00
stat.c perf stat: Zero all the 'ena' and 'run' array slot stats for interval mode 2020-08-08 01:53:12 -04:00
stat.h perf stat: Reset previous counts on repeat with interval 2019-09-20 10:28:26 -03:00
strbuf.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
strbuf.h
strfilter.c
strfilter.h
string.c
string2.h
strlist.c
strlist.h
svghelper.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
svghelper.h perf timechart: Refactor svg_build_topology_map() 2019-08-29 17:38:31 -03:00
symbol-elf.c perf symbols: Fix return incorrect build_id size in elf_read_build_id() 2023-08-09 12:25:25 +02:00
symbol-minimal.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
symbol.c perf symbols: Fix symbol size calculation condition 2022-05-20 15:18:02 +02:00
symbol.h perf symbols: Move mem_info and branch_info out of symbol.h 2019-08-31 22:27:48 -03:00
symbol_conf.h
symbol_fprintf.c perf symbols: Fix dso__fprintf_symbols_by_name() to return the number of printed chars 2021-05-26 15:39:18 +02:00
symsrc.h perf symbols: Move symsrc prototypes to a separate header 2019-08-31 22:24:05 -03:00
synthetic-events.c libperf: Move 'page_size' global variable to libperf 2019-09-25 09:51:48 -03:00
synthetic-events.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
syscalltbl.c
syscalltbl.h
target.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
target.h
term.c
term.h
thread-stack.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
thread-stack.h
thread.c perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
thread.h libperf: Rename the PERF_RECORD_ structs to have a "perf" suffix 2019-08-26 19:39:11 -03:00
thread_map.c libperf: Rename the PERF_RECORD_ structs to have a "perf" prefix 2019-08-29 08:36:12 -03:00
thread_map.h libperf: Rename the PERF_RECORD_ structs to have a "perf" prefix 2019-08-29 08:36:12 -03:00
time-utils.c perf script: Fix --reltime with --time 2020-01-30 16:27:04 +01:00
time-utils.h perf script: Fix --reltime with --time 2020-01-30 16:27:04 +01:00
tool.h perf tool: Rename perf_tool::bpf_event to bpf 2019-08-26 19:39:11 -03:00
top.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
top.h perf auxtrace: Uninline functions that touch perf_session 2019-08-31 22:24:10 -03:00
trace-event-info.c libperf: Move 'page_size' global variable to libperf 2019-09-25 09:51:48 -03:00
trace-event-parse.c perf tools: Remove unused trace_find_next_event() 2019-11-05 08:39:27 -03:00
trace-event-read.c perf traceevent: Ensure read cmdlines are null terminated. 2021-04-14 18:31:54 +02:00
trace-event-scripting.c perf tools: Remove perf.h from source files not needing it 2019-08-29 17:38:32 -03:00
trace-event.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
trace-event.h perf tools: Remove unused trace_find_next_event() 2019-11-05 08:39:27 -03:00
trigger.h perf tools: Remove debug.h from header files not needing it 2019-08-29 17:38:32 -03:00
tsc.c
tsc.h perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
units.c
units.h
unwind-libdw.c perf unwind: Set userdata for all __report_module() paths 2021-06-18 15:02:39 +02:00
unwind-libdw.h
unwind-libunwind-local.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
unwind-libunwind.c perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
unwind.h
usage.c perf tools: Remove debug.h from places where it is not needed 2019-09-20 09:19:20 -03:00
util.c perf report: Fix memory leaks around perf_tip() 2022-02-03 18:57:21 +01:00
util.h perf report: Fix memory leaks around perf_tip() 2022-02-03 18:57:21 +01:00
values.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
values.h
vdso.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
vdso.h
xyarray.c
zlib.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
zstd.c perf tools: Use %zd for size_t printf formats on 32-bit 2021-05-04 16:11:22 +02:00