Skip to content

Commit 0fb0d61

Browse files
captain5050acmel
authored andcommitted
perf test: Initialize memory in dwarf-unwind
Avoid a false positive caused by assembly code in arch/x86. In tests, zero the perf_event to avoid uninitialized memory uses. Warnings were caught using clang with -fsanitize=memory. Signed-off-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Monnet <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8617e2e commit 0fb0d61

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tools/perf/arch/x86/tests/dwarf-unwind.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ int test__arch_unwind_sample(struct perf_sample *sample,
5555
return -1;
5656
}
5757

58+
#ifdef MEMORY_SANITIZER
59+
/*
60+
* Assignments to buf in the assembly function perf_regs_load aren't
61+
* seen by memory sanitizer. Zero the memory to convince memory
62+
* sanitizer the memory is initialized.
63+
*/
64+
memset(buf, 0, sizeof(u64) * PERF_REGS_MAX);
65+
#endif
5866
perf_regs_load(buf);
5967
regs->abi = PERF_SAMPLE_REGS_ABI;
6068
regs->regs = buf;

tools/perf/tests/dwarf-unwind.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int init_live_machine(struct machine *machine)
3737
union perf_event event;
3838
pid_t pid = getpid();
3939

40+
memset(&event, 0, sizeof(event));
4041
return perf_event__synthesize_mmap_events(NULL, &event, pid, pid,
4142
mmap_handler, machine, true);
4243
}

0 commit comments

Comments
 (0)