Re: perf object code reading test crashes

From: Steven Noonan
Date: Wed Feb 17 2016 - 20:14:08 EST


On Wed, Feb 17, 2016 at 6:27 AM, Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
> Em Tue, Feb 16, 2016 at 10:42:19PM -0800, Steven Noonan escreveu:
>> I oddly didn't run into this issue on every machine I tried, but
>> there's some issues here:
>>
>> $ sudo perf test 21
>> 21: Test object code reading :***
>> Error in `perf': corrupted double-linked list: 0x00000000023ffcd0 ***
>
>> FAILED!
>>
>> Valgrind seems to suggest that the cpu map is getting freed too early:
>>
>> ==11450== Address 0x875b8a0 is 0 bytes inside a block of size 136 free'd
>> ==11450== at 0x4C29D2A: free (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==11450== by 0x4CBD49: cpu_map__delete (cpumap.c:228)
>> ==11450== by 0x4CC690: cpu_map__put (cpumap.c:242)
>> ==11450== by 0x484DE3: __perf_evlist__propagate_maps (evlist.c:136)
>
>
>> I tried this, and the problem goes away:
>
>
>> +++ b/tools/perf/tests/code-reading.c
>> @@ -514,6 +514,7 @@ static int do_test_code_reading(bool try_kcore)
>> }
>> + cpu_map__get(cpus);
>>
>> while (1) {
>
> Yeah, we forgot to grab refcounts in perf_evlist__set_maps(), can you
> try this instead, if it works please let me know so that I can add a:
>
> Reported-and-Tested-by: you to this patch,
>
> Thanks for the nice report!
>
> - Arnaldo

That did the trick for the refcounting as far as valgrind/libc are concerned.

Reported-and-Tested-by: Steven Noonan <steven@xxxxxxxxxxxxxx>


Now to figure out why the test is failing. This same test works fine
on another system running the same kernel build:

$ ./perf test -v -v 21
21: Test object code reading :
--- start ---
test child forked, pid 19527
Looking at the vmlinux_path (7 entries long)
Using /usr/lib/debug/lib/modules/4.4.1-1-ec2/vmlinux for symbols
Parsing event 'cycles'
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
task 1
sample_id_all 1
exclude_guest 1
mmap2 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0x8
sys_perf_event_open failed, error -22
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
task 1
sample_id_all 1
exclude_guest 1
mmap2 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0
sys_perf_event_open failed, error -22
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
task 1
sample_id_all 1
exclude_guest 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0
sys_perf_event_open failed, error -22
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
task 1
sample_id_all 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0
sys_perf_event_open failed, error -22
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
task 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0
sys_perf_event_open failed, error -22
Parsing event 'cycles:u'
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|PERIOD
disabled 1
inherit 1
exclude_kernel 1
exclude_hv 1
mmap 1
comm 1
freq 1
task 1
comm_exec 1
------------------------------------------------------------
sys_perf_event_open: pid 19527 cpu 0 group_fd -1 flags 0
sys_perf_event_open failed, error -22
perf_evlist__open failed
test child finished with -1
---- end ----
Test object code reading: FAILED!


>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index d81f13de2476..a7eb0eae9938 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1181,12 +1181,12 @@ void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,
> */
> if (cpus != evlist->cpus) {
> cpu_map__put(evlist->cpus);
> - evlist->cpus = cpus;
> + evlist->cpus = cpu_map__get(cpus);
> }
>
> if (threads != evlist->threads) {
> thread_map__put(evlist->threads);
> - evlist->threads = threads;
> + evlist->threads = thread_map__get(threads);
> }
>
> perf_evlist__propagate_maps(evlist);