All of lore.kernel.org
 help / color / mirror / Atom feed
* Question: perf dso support for /proc/kallsyms
@ 2018-11-02  2:55 leo.yan
  2018-11-02 12:08 ` Al Grant
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: leo.yan @ 2018-11-02  2:55 UTC (permalink / raw)
  To: acme, Jiri Olsa, Mathieu Poirier; +Cc: Coresight ML, linux-kernel

Hi all,

Now I found that if use the command 'perf script' for Arm CoreSight trace
data, it fails to parse kernel symbols if we don't specify kernel vmlinux
file.   So when we don't specify kernel symbol files then perf tool will
roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
run into below flow:

  thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
  map__load(al.map);
  dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
    `-> data_read_offset()

I can observe the function data_read_offset() returns failure, this is caused
by checking the offset sanity "if (offset > dso->data.file_size)"  (I pasted
the whole function code at below in case you want to get more context for it),
but if perf use "/proc/kallsyms" to load kernel symbols, the variable
'dso->data.file_size' will be set to zero thus the sanity checking always
thinks the offset is out of the file size bound.

Now I still don't understand how the dso/map support "/proc/kallsyms" and
have no idea to fix this issue, though I spent some time to look into it.

Could you give some suggestion for this?  Or even better if you have fixing
for this, I am glad to test at my side.

static ssize_t data_read_offset(struct dso *dso, struct machine *machine,
                                u64 offset, u8 *data, ssize_t size)
{
        if (data_file_size(dso, machine))
                return -1;

        /* Check the offset sanity. */
        if (offset > dso->data.file_size)
                return -1;

        if (offset + size < offset)
                return -1;

        return cached_read(dso, machine, offset, data, size);
}

Thanks,
Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Question: perf dso support for /proc/kallsyms
  2018-11-02  2:55 Question: perf dso support for /proc/kallsyms leo.yan
@ 2018-11-02 12:08 ` Al Grant
  2018-11-02 13:46   ` leo.yan
  2018-11-02 13:08 ` Mike Leach
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Al Grant @ 2018-11-02 12:08 UTC (permalink / raw)
  To: leo.yan, acme, Jiri Olsa, Mathieu Poirier; +Cc: Coresight ML, linux-kernel

> Now I still don't understand how the dso/map support "/proc/kallsyms" and
> have no idea to fix this issue, though I spent some time to look into it.

The way this is supported is that at record time, pseudo mmap records
are created for the kernel. But depending on permissions these might
not get created. This isn't just an ETM issue, it can happen on Intel too.

What do you see in "perf report -D", do you see a PERF_RECORD_MMAP
record for "[kernel.kallsyms]_text" and possibly some others for loadable
kernel modules in /lib/modules?

Does it all work if you run perf record as sudo? Or if you do

   sudo sysctl kernel.kptr_restrict=0

before you run perf record?

Al
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02  2:55 Question: perf dso support for /proc/kallsyms leo.yan
  2018-11-02 12:08 ` Al Grant
@ 2018-11-02 13:08 ` Mike Leach
  2018-11-02 14:02   ` leo.yan
  2018-11-07  3:33 ` leo.yan
  2018-11-07 14:10 ` Jiri Olsa
  3 siblings, 1 reply; 11+ messages in thread
From: Mike Leach @ 2018-11-02 13:08 UTC (permalink / raw)
  To: Leo Yan; +Cc: acme, jolsa, Mathieu Poirier, coresight, linux-kernel

Hi Leo,

My understanding is that when we decode CoreSight trace - be it on the
system that generated it, or off target device on a separate host
system, we are using the dso files in .debug/ as these represent the
memory layout at the time trace was recorded.

If I look into a recent session copied up to my linux box from DB410,
is see ~/.debug/\[kernel.kallsyms\]/ee80c1f3a434469f6174e1cf4bb5583d83a013dc/kallsyms
- which seems to me to be the relevant symbol file to use rather than
the live one generated by /proc/kallsyms. I don't really want to use
the local /proc/kallsyms on my x86 linux box when decoding an ARM
trace captured elsewhere.

So perhaps the problem to be solved is not how to use /proc/kallsyms
if no vmlinux is supplied to the script, but ensure that the
[kernel.kallsyms] is used?

Regards

Mike
On Fri, 2 Nov 2018 at 02:55, <leo.yan@linaro.org> wrote:
>
> Hi all,
>
> Now I found that if use the command 'perf script' for Arm CoreSight trace
> data, it fails to parse kernel symbols if we don't specify kernel vmlinux
> file.   So when we don't specify kernel symbol files then perf tool will
> roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
> run into below flow:
>
>   thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
>   map__load(al.map);
>   dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
>     `-> data_read_offset()
>
> I can observe the function data_read_offset() returns failure, this is caused
> by checking the offset sanity "if (offset > dso->data.file_size)"  (I pasted
> the whole function code at below in case you want to get more context for it),
> but if perf use "/proc/kallsyms" to load kernel symbols, the variable
> 'dso->data.file_size' will be set to zero thus the sanity checking always
> thinks the offset is out of the file size bound.
>
> Now I still don't understand how the dso/map support "/proc/kallsyms" and
> have no idea to fix this issue, though I spent some time to look into it.
>
> Could you give some suggestion for this?  Or even better if you have fixing
> for this, I am glad to test at my side.
>
> static ssize_t data_read_offset(struct dso *dso, struct machine *machine,
>                                 u64 offset, u8 *data, ssize_t size)
> {
>         if (data_file_size(dso, machine))
>                 return -1;
>
>         /* Check the offset sanity. */
>         if (offset > dso->data.file_size)
>                 return -1;
>
>         if (offset + size < offset)
>                 return -1;
>
>         return cached_read(dso, machine, offset, data, size);
> }
>
> Thanks,
> Leo Yan
> _______________________________________________
> CoreSight mailing list
> CoreSight@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/coresight



-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02 12:08 ` Al Grant
@ 2018-11-02 13:46   ` leo.yan
  2018-11-02 14:12     ` Al Grant
  0 siblings, 1 reply; 11+ messages in thread
From: leo.yan @ 2018-11-02 13:46 UTC (permalink / raw)
  To: Al Grant; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

Hi Al,

On Fri, Nov 02, 2018 at 12:08:04PM +0000, Al Grant wrote:
> > Now I still don't understand how the dso/map support "/proc/kallsyms" and
> > have no idea to fix this issue, though I spent some time to look into it.
> 
> The way this is supported is that at record time, pseudo mmap records
> are created for the kernel. But depending on permissions these might
> not get created. This isn't just an ETM issue, it can happen on Intel too.

Agree, I also think this is not a specific issue only for Arm platform,
this should be one common issue for how to parse kernel symbols with
kallsyms file.

> What do you see in "perf report -D", do you see a PERF_RECORD_MMAP
> record for "[kernel.kallsyms]_text" and possibly some others for loadable
> kernel modules in /lib/modules?

Yes, I can see PERF_RECORD_MMAP for "[kernel.kallsyms]_text".

0x350 [0x50]: event: 1
.
. ... raw event: size 80 bytes
.  0000:  01 00 00 00 01 00 50 00 ff ff ff ff 00 00 00 00  ......P.........
.  0010:  00 00 08 08 00 00 ff ff ff ff f7 f7 ff ff 00 00  ................
.  0020:  00 00 08 08 00 00 ff ff 5b 6b 65 72 6e 65 6c 2e  ........[kernel.
.  0030:  6b 61 6c 6c 73 79 6d 73 5d 5f 74 65 78 74 00 00  kallsyms]_text..
.  0040:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

0x350 [0x50]: PERF_RECORD_MMAP -1/0: [0xffff000008080000(0xfffff7f7ffff) @ 0xffff000008080000]: x [kernel.kallsyms]_text

Below is the infor for checking buildid:

root@debian:~/coresight_test# perf buildid-list
0242d9154c78df1d8fe1d0512c36a236d0861a18 [kernel.kallsyms]
b8c89e8ba41a2ea486c66a50c29c60d38c34a759 /root/coresight_test/main
26b12a9d1a54ed2b0478cb0203435b76aabab3fb /usr/lib/aarch64-linux-gnu/ld-2.27.so
8fca7ed524c9469b065af83bc8a529fe72858f53 [vdso]
25829a59e21012cfde7850b30a310cd3a58f531c /root/coresight_test/libcstest.so
70512527439ef76c8802a7a2a546bde6a5a6e967 /usr/lib/aarch64-linux-gnu/libc-2.27.so
root@debian:~/coresight_test# ls ~/.debug/\[kernel.kallsyms\]/0242d9154c78df1d8fe1d0512c36a236d0861a18/
kallsyms

> Does it all work if you run perf record as sudo? Or if you do
> 
>    sudo sysctl kernel.kptr_restrict=0
> 
> before you run perf record?

Yes, tested this on Juno board with Debian rootFS and logined in
with 'root' user.  I suspected the pointer permission issue so
checked with below command:

root@debian:~/coresight_test# cat /proc/sys/kernel/kptr_restrict 
0

Thanks,
Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02 13:08 ` Mike Leach
@ 2018-11-02 14:02   ` leo.yan
  0 siblings, 0 replies; 11+ messages in thread
From: leo.yan @ 2018-11-02 14:02 UTC (permalink / raw)
  To: Mike Leach; +Cc: acme, jolsa, Mathieu Poirier, coresight, linux-kernel

Hi Mike,

On Fri, Nov 02, 2018 at 01:08:40PM +0000, Mike Leach wrote:
> Hi Leo,
> 
> My understanding is that when we decode CoreSight trace - be it on the
> system that generated it, or off target device on a separate host
> system, we are using the dso files in .debug/ as these represent the
> memory layout at the time trace was recorded.
> 
> If I look into a recent session copied up to my linux box from DB410,
> is see ~/.debug/\[kernel.kallsyms\]/ee80c1f3a434469f6174e1cf4bb5583d83a013dc/kallsyms
> - which seems to me to be the relevant symbol file to use rather than
> the live one generated by /proc/kallsyms. I don't really want to use
> the local /proc/kallsyms on my x86 linux box when decoding an ARM
> trace captured elsewhere.
> 
> So perhaps the problem to be solved is not how to use /proc/kallsyms
> if no vmlinux is supplied to the script, but ensure that the
> [kernel.kallsyms] is used?

Yes, this is good point, the subject should be changed to:
"Question: perf dso support for kallsyms".

I think I made a mistake in my previous email, so clarify it:

~/.debug/\[kernel.kallsyms\]/$BUILDID/kallsyms should has higher
priority than /proc/kallsyms, by default the perf tool should use
kallsyms file under ~/.debug folder.  I also tried to manually specify
the kallsyms file with the command "perf script --kallsyms ./kallsyms",
for both cases perf fails to parse symbols for any kernel address.

Thanks,
Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Question: perf dso support for /proc/kallsyms
  2018-11-02 13:46   ` leo.yan
@ 2018-11-02 14:12     ` Al Grant
  2018-11-02 14:43       ` leo.yan
  0 siblings, 1 reply; 11+ messages in thread
From: Al Grant @ 2018-11-02 14:12 UTC (permalink / raw)
  To: leo.yan; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

> root@debian:~/coresight_test# perf buildid-list
> 0242d9154c78df1d8fe1d0512c36a236d0861a18 [kernel.kallsyms]
> b8c89e8ba41a2ea486c66a50c29c60d38c34a759 /root/coresight_test/main
> 26b12a9d1a54ed2b0478cb0203435b76aabab3fb /usr/lib/aarch64-linux-gnu/ld-
> 2.27.so
> 8fca7ed524c9469b065af83bc8a529fe72858f53 [vdso]
> 25829a59e21012cfde7850b30a310cd3a58f531c
> /root/coresight_test/libcstest.so
> 70512527439ef76c8802a7a2a546bde6a5a6e967 /usr/lib/aarch64-linux-
> gnu/libc-2.27.so
> root@debian:~/coresight_test# ls
> ~/.debug/\[kernel.kallsyms\]/0242d9154c78df1d8fe1d0512c36a236d0861a18/
> kallsyms

What's in that last file? I've seen it happen that the copy of kallsyms
in ~/.debug has the symbol addresses as zeroes - possibly because it
was created when you didn't have permissions. That's really a bug
in perf, as cacheing a copy of this file with the addresses zeroed out
is kind of pointless. Again, this happens on Intel too.

Then, you can give yourself permissions - but perf's already cached
the file and won't update it!

If you delete it, and then rerun perf record (either as sudo or now
that you've got kptr_restrict=0) you should see it reappear, with
correct kernel addresses.

Perhaps nobody spotted this on Intel because perf report goes directly
to /proc/kallsyms. But it would be an issue if you ran a perf report
on a perf.data from an older kernel and it had to go to ~/.debug.
At that point the fact that ~/.debug/[kernel.kallsyms] had zeroes would
mean you couldn't symbolicate any addresses.

Al



>
> > Does it all work if you run perf record as sudo? Or if you do
> >
> >    sudo sysctl kernel.kptr_restrict=0
> >
> > before you run perf record?
>
> Yes, tested this on Juno board with Debian rootFS and logined in with 'root' user.
> I suspected the pointer permission issue so checked with below command:
>
> root@debian:~/coresight_test# cat /proc/sys/kernel/kptr_restrict
> 0
>
> Thanks,
> Leo Yan
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02 14:12     ` Al Grant
@ 2018-11-02 14:43       ` leo.yan
  0 siblings, 0 replies; 11+ messages in thread
From: leo.yan @ 2018-11-02 14:43 UTC (permalink / raw)
  To: Al Grant; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

On Fri, Nov 02, 2018 at 02:12:28PM +0000, Al Grant wrote:
> > root@debian:~/coresight_test# perf buildid-list
> > 0242d9154c78df1d8fe1d0512c36a236d0861a18 [kernel.kallsyms]
> > b8c89e8ba41a2ea486c66a50c29c60d38c34a759 /root/coresight_test/main
> > 26b12a9d1a54ed2b0478cb0203435b76aabab3fb /usr/lib/aarch64-linux-gnu/ld-
> > 2.27.so
> > 8fca7ed524c9469b065af83bc8a529fe72858f53 [vdso]
> > 25829a59e21012cfde7850b30a310cd3a58f531c
> > /root/coresight_test/libcstest.so
> > 70512527439ef76c8802a7a2a546bde6a5a6e967 /usr/lib/aarch64-linux-
> > gnu/libc-2.27.so
> > root@debian:~/coresight_test# ls
> > ~/.debug/\[kernel.kallsyms\]/0242d9154c78df1d8fe1d0512c36a236d0861a18/
> > kallsyms
> 
> What's in that last file?

I can see the correct symbol infos in this file:

root@debian:~/coresight_test# cat ~/.debug/\[kernel.kallsyms\]/0242d9154c78df1d8fe1d0512c36a236d0861a18/kallsyms | head -20
ffff000008080000 t _head
ffff000008080000 T _text
ffff000008080040 t pe_header
ffff000008080044 t coff_header
ffff000008080058 t optional_header
ffff000008080070 t extra_header_fields
ffff0000080800f8 t section_table
ffff000008081000 T do_undefinstr
ffff000008081000 t efi_header_end
ffff000008081000 T _stext
ffff000008081000 T __exception_text_start
ffff000008081268 T do_cp15instr
ffff000008081380 T do_sysinstr
ffff000008081410 T do_debug_exception
ffff000008081550 T do_mem_abort
ffff000008081600 T do_el0_irq_bp_hardening
ffff000008081650 T do_el0_ia_bp_hardening
ffff0000080816f8 T do_sp_pc_abort
ffff0000080817c4 T __exception_text_end
ffff0000080817c8 t bcm2835_handle_irq

> I've seen it happen that the copy of kallsyms
> in ~/.debug has the symbol addresses as zeroes - possibly because it
> was created when you didn't have permissions. That's really a bug
> in perf, as cacheing a copy of this file with the addresses zeroed out
> is kind of pointless. Again, this happens on Intel too.
> 
> Then, you can give yourself permissions - but perf's already cached
> the file and won't update it!
> 
> If you delete it, and then rerun perf record (either as sudo or now
> that you've got kptr_restrict=0) you should see it reappear, with
> correct kernel addresses.
> 
> Perhaps nobody spotted this on Intel because perf report goes directly
> to /proc/kallsyms. But it would be an issue if you ran a perf report
> on a perf.data from an older kernel and it had to go to ~/.debug.
> At that point the fact that ~/.debug/[kernel.kallsyms] had zeroes would
> mean you couldn't symbolicate any addresses.

This is another issue related with permission for accessing kernel
pointer values and this will bother much for cross platforms usage
(e.g. 'perf record' on Arm platform and 'perf script' on x86
platform).

At my side, I executed all commands on Arm Juno board and simply to
say the kallsyms support is broken in perf.

Thanks,
Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02  2:55 Question: perf dso support for /proc/kallsyms leo.yan
  2018-11-02 12:08 ` Al Grant
  2018-11-02 13:08 ` Mike Leach
@ 2018-11-07  3:33 ` leo.yan
  2018-11-07 14:10 ` Jiri Olsa
  3 siblings, 0 replies; 11+ messages in thread
From: leo.yan @ 2018-11-07  3:33 UTC (permalink / raw)
  To: acme, Jiri Olsa, Mathieu Poirier; +Cc: Coresight ML, linux-kernel

On Fri, Nov 02, 2018 at 10:55:16AM +0800, Leo Yan wrote:
> Hi all,
> 
> Now I found that if use the command 'perf script' for Arm CoreSight trace
> data, it fails to parse kernel symbols if we don't specify kernel vmlinux
> file.   So when we don't specify kernel symbol files then perf tool will
> roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
> run into below flow:
> 
>   thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
>   map__load(al.map);
>   dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
>     `-> data_read_offset()
> 
> I can observe the function data_read_offset() returns failure, this is caused
> by checking the offset sanity "if (offset > dso->data.file_size)"  (I pasted
> the whole function code at below in case you want to get more context for it),
> but if perf use "/proc/kallsyms" to load kernel symbols, the variable
> 'dso->data.file_size' will be set to zero thus the sanity checking always
> thinks the offset is out of the file size bound.
> 
> Now I still don't understand how the dso/map support "/proc/kallsyms" and
> have no idea to fix this issue, though I spent some time to look into it.
> 
> Could you give some suggestion for this?  Or even better if you have fixing
> for this, I am glad to test at my side.

Hi Jiri, Arnaldo,

Could you give some suggestion for this question?  Thanks!

> static ssize_t data_read_offset(struct dso *dso, struct machine *machine,
>                                 u64 offset, u8 *data, ssize_t size)
> {
>         if (data_file_size(dso, machine))
>                 return -1;
> 
>         /* Check the offset sanity. */
>         if (offset > dso->data.file_size)
>                 return -1;
> 
>         if (offset + size < offset)
>                 return -1;
> 
>         return cached_read(dso, machine, offset, data, size);
> }
> 
> Thanks,
> Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-02  2:55 Question: perf dso support for /proc/kallsyms leo.yan
                   ` (2 preceding siblings ...)
  2018-11-07  3:33 ` leo.yan
@ 2018-11-07 14:10 ` Jiri Olsa
  2018-11-08  8:51   ` leo.yan
  3 siblings, 1 reply; 11+ messages in thread
From: Jiri Olsa @ 2018-11-07 14:10 UTC (permalink / raw)
  To: leo.yan; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

On Fri, Nov 02, 2018 at 10:55:16AM +0800, leo.yan@linaro.org wrote:
> Hi all,
> 
> Now I found that if use the command 'perf script' for Arm CoreSight trace
> data, it fails to parse kernel symbols if we don't specify kernel vmlinux
> file.   So when we don't specify kernel symbol files then perf tool will
> roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
> run into below flow:

yep, AFAIK if there's no vmlinux found we fallback to /proc/kallsyms

> 
>   thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
>   map__load(al.map);
>   dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
>     `-> data_read_offset()

so what is the actual error you see in the perf script?
unresolved samples? could you please describe your config
and workload?

thanks,
jirka

> 
> I can observe the function data_read_offset() returns failure, this is caused
> by checking the offset sanity "if (offset > dso->data.file_size)"  (I pasted
> the whole function code at below in case you want to get more context for it),
> but if perf use "/proc/kallsyms" to load kernel symbols, the variable
> 'dso->data.file_size' will be set to zero thus the sanity checking always
> thinks the offset is out of the file size bound.
> 
> Now I still don't understand how the dso/map support "/proc/kallsyms" and
> have no idea to fix this issue, though I spent some time to look into it.
> 
> Could you give some suggestion for this?  Or even better if you have fixing
> for this, I am glad to test at my side.
> 
> static ssize_t data_read_offset(struct dso *dso, struct machine *machine,
>                                 u64 offset, u8 *data, ssize_t size)
> {
>         if (data_file_size(dso, machine))
>                 return -1;
> 
>         /* Check the offset sanity. */
>         if (offset > dso->data.file_size)
>                 return -1;
> 
>         if (offset + size < offset)
>                 return -1;
> 
>         return cached_read(dso, machine, offset, data, size);
> }
> 
> Thanks,
> Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-07 14:10 ` Jiri Olsa
@ 2018-11-08  8:51   ` leo.yan
  2018-11-09  8:11     ` Jiri Olsa
  0 siblings, 1 reply; 11+ messages in thread
From: leo.yan @ 2018-11-08  8:51 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

Hi Jiri,

On Wed, Nov 07, 2018 at 03:10:06PM +0100, Jiri Olsa wrote:
> On Fri, Nov 02, 2018 at 10:55:16AM +0800, leo.yan@linaro.org wrote:
> > Hi all,
> > 
> > Now I found that if use the command 'perf script' for Arm CoreSight trace
> > data, it fails to parse kernel symbols if we don't specify kernel vmlinux
> > file.   So when we don't specify kernel symbol files then perf tool will
> > roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
> > run into below flow:
> 
> yep, AFAIK if there's no vmlinux found we fallback to /proc/kallsyms
> 
> > 
> >   thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
> >   map__load(al.map);
> >   dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
> >     `-> data_read_offset()
> 
> so what is the actual error you see in the perf script?
> unresolved samples? could you please describe your config
> and workload?

So at my side the error is the CoreSight trace decoder fails to
generate samples if the sample has kernel address, thus the decoder
doesn't generate any kernel sample if use kallsyms as dso.

For more detailed info is: the CoreSight decoder needs firstly to get
dso related info by calling dso__data_read_offset() [1], if we use
kallsyms then this function always returns failure then this leads the
docoder to discard all kernel samples.

Regarding to testing case, I can simply run 'uname' program so it can
produce kernel and user space trace data, if I use 'perf script -k
vmlinux' then I can see perf generate samples for kernel related traces,
but if use 'perf script' then only can see samples for user space.

Thanks,
Leo Yan

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/cs-etm.c#n302

> > I can observe the function data_read_offset() returns failure, this is caused
> > by checking the offset sanity "if (offset > dso->data.file_size)"  (I pasted
> > the whole function code at below in case you want to get more context for it),
> > but if perf use "/proc/kallsyms" to load kernel symbols, the variable
> > 'dso->data.file_size' will be set to zero thus the sanity checking always
> > thinks the offset is out of the file size bound.
> > 
> > Now I still don't understand how the dso/map support "/proc/kallsyms" and
> > have no idea to fix this issue, though I spent some time to look into it.
> > 
> > Could you give some suggestion for this?  Or even better if you have fixing
> > for this, I am glad to test at my side.
> > 
> > static ssize_t data_read_offset(struct dso *dso, struct machine *machine,
> >                                 u64 offset, u8 *data, ssize_t size)
> > {
> >         if (data_file_size(dso, machine))
> >                 return -1;
> > 
> >         /* Check the offset sanity. */
> >         if (offset > dso->data.file_size)
> >                 return -1;
> > 
> >         if (offset + size < offset)
> >                 return -1;
> > 
> >         return cached_read(dso, machine, offset, data, size);
> > }
> > 
> > Thanks,
> > Leo Yan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Question: perf dso support for /proc/kallsyms
  2018-11-08  8:51   ` leo.yan
@ 2018-11-09  8:11     ` Jiri Olsa
  0 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2018-11-09  8:11 UTC (permalink / raw)
  To: leo.yan; +Cc: acme, Jiri Olsa, Mathieu Poirier, Coresight ML, linux-kernel

On Thu, Nov 08, 2018 at 04:51:52PM +0800, leo.yan@linaro.org wrote:
> Hi Jiri,
> 
> On Wed, Nov 07, 2018 at 03:10:06PM +0100, Jiri Olsa wrote:
> > On Fri, Nov 02, 2018 at 10:55:16AM +0800, leo.yan@linaro.org wrote:
> > > Hi all,
> > > 
> > > Now I found that if use the command 'perf script' for Arm CoreSight trace
> > > data, it fails to parse kernel symbols if we don't specify kernel vmlinux
> > > file.   So when we don't specify kernel symbol files then perf tool will
> > > roll back to use /proc/kallsyms for kernel symbols parsing, as result it will
> > > run into below flow:
> > 
> > yep, AFAIK if there's no vmlinux found we fallback to /proc/kallsyms
> > 
> > > 
> > >   thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
> > >   map__load(al.map);
> > >   dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
> > >     `-> data_read_offset()
> > 
> > so what is the actual error you see in the perf script?
> > unresolved samples? could you please describe your config
> > and workload?
> 
> So at my side the error is the CoreSight trace decoder fails to
> generate samples if the sample has kernel address, thus the decoder
> doesn't generate any kernel sample if use kallsyms as dso.
> 
> For more detailed info is: the CoreSight decoder needs firstly to get
> dso related info by calling dso__data_read_offset() [1], if we use
> kallsyms then this function always returns failure then this leads the
> docoder to discard all kernel samples.

I haven't checked on this code for some time but AFAICS
before you call dso__data_read_offset you need to check
  dso->data.status != DSO_DATA_STATUS_ERROR

map__load call ahead should take care on setting this and
find the source of the data

check the intel_pt code (intel_pt_walk_next_insn)
or for example grab_bb in perf script

I guess you need to have either vmlinux or kcore in place
to get some data out of it

jirka

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-11-09  8:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02  2:55 Question: perf dso support for /proc/kallsyms leo.yan
2018-11-02 12:08 ` Al Grant
2018-11-02 13:46   ` leo.yan
2018-11-02 14:12     ` Al Grant
2018-11-02 14:43       ` leo.yan
2018-11-02 13:08 ` Mike Leach
2018-11-02 14:02   ` leo.yan
2018-11-07  3:33 ` leo.yan
2018-11-07 14:10 ` Jiri Olsa
2018-11-08  8:51   ` leo.yan
2018-11-09  8:11     ` Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.