[PATCH v2 0/2] perf maps: Improve the kcore maps merging

Leo Yan posted 2 patches 1 year, 9 months ago
There is a newer version of this series
tools/perf/util/symbol.c | 117 +++++++++++++++++++--------------------
1 file changed, 57 insertions(+), 60 deletions(-)
[PATCH v2 0/2] perf maps: Improve the kcore maps merging
Posted by Leo Yan 1 year, 9 months ago
This patch series follows up on the patch [1] to improve the sorting and
merging of kcore maps.

Since the kcore maps are not sorted, merging them into the kernel maps
causes difficulty, e.g. some kcore maps might be ignored. This is why
the dso__load_kcore() function handles the kernel text section
particularly for replacement a complete kernel section.

This patch sorts the kcore maps and ensures the subset region is placed
ahead of the superset region in the list. With this change, merging
these maps becomes easier - no need the special handling for the kernel
text section.

This patch series is based on the latest acme's perf-tool-next branch
and tested on Arm64 Hikey960 board.

[1] https://lore.kernel.org/linux-perf-users/438f8725-ef3f-462f-90e2-840cab478ee5@arm.com/T/#m7c86a69d43103cd0cb446b0993e47c36df0f40f2

Leo Yan (2):
  perf maps: Sort kcore maps
  perf maps: Remove the replacement of kernel map

 tools/perf/util/symbol.c | 117 +++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 60 deletions(-)

-- 
2.34.1
Re: [PATCH v2 0/2] perf maps: Improve the kcore maps merging
Posted by Ian Rogers 1 year, 9 months ago
On Wed, May 15, 2024 at 2:11 PM Leo Yan <leo.yan@arm.com> wrote:
>
> This patch series follows up on the patch [1] to improve the sorting and
> merging of kcore maps.
>
> Since the kcore maps are not sorted, merging them into the kernel maps
> causes difficulty, e.g. some kcore maps might be ignored. This is why
> the dso__load_kcore() function handles the kernel text section
> particularly for replacement a complete kernel section.
>
> This patch sorts the kcore maps and ensures the subset region is placed
> ahead of the superset region in the list. With this change, merging
> these maps becomes easier - no need the special handling for the kernel
> text section.
>
> This patch series is based on the latest acme's perf-tool-next branch
> and tested on Arm64 Hikey960 board.
>
> [1] https://lore.kernel.org/linux-perf-users/438f8725-ef3f-462f-90e2-840cab478ee5@arm.com/T/#m7c86a69d43103cd0cb446b0993e47c36df0f40f2

Thanks Leo, testing this change on perf-tools-next with an x86 debian
laptop I see:
```
$ perf test 24 -v
24: Object code reading:
--- start ---
test child forked, pid 3407499
Looking at the vmlinux_path (8 entries long)
symsrc__init: build id mismatch for vmlinux.
symsrc__init: cannot get elf header.
overlapping maps in [kernel.kallsyms] (disable tui for more info)
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
Parsing event 'cycles'
Using CPUID GenuineIntel-6-8D-1
mmap size 528384B
Reading object code for memory address: 0xfffffffface8d64a
File is: /proc/kcore
On file address is: 0xfffffffface8d64a
dso__data_read_offset failed
---- end(-1) ----
24: Object code reading                                             : FAILED!
```
The test passes without the changes. Let me know if you need me to dig deeper.

Thanks,
Ian

> Leo Yan (2):
>   perf maps: Sort kcore maps
>   perf maps: Remove the replacement of kernel map
>
>  tools/perf/util/symbol.c | 117 +++++++++++++++++++--------------------
>  1 file changed, 57 insertions(+), 60 deletions(-)
>
> --
> 2.34.1
>
Re: [PATCH v2 0/2] perf maps: Improve the kcore maps merging
Posted by Leo Yan 1 year, 8 months ago
On 5/15/24 22:39, Ian Rogers wrote:

[...]

> Thanks Leo, testing this change on perf-tools-next with an x86 debian
> laptop I see:
> ```
> $ perf test 24 -v
> 24: Object code reading:
> --- start ---
> test child forked, pid 3407499
> Looking at the vmlinux_path (8 entries long)
> symsrc__init: build id mismatch for vmlinux.
> symsrc__init: cannot get elf header.
> overlapping maps in [kernel.kallsyms] (disable tui for more info)
> Using /proc/kcore for kernel data
> Using /proc/kallsyms for symbols
> Parsing event 'cycles'
> Using CPUID GenuineIntel-6-8D-1
> mmap size 528384B
> Reading object code for memory address: 0xfffffffface8d64a
> File is: /proc/kcore
> On file address is: 0xfffffffface8d64a
> dso__data_read_offset failed
> ---- end(-1) ----
> 24: Object code reading                                             : FAILED!
> ```
> The test passes without the changes. Let me know if you need me to dig deeper.

Just update for the test failure.

The failure is caused by the memory map's attribute is not updated after 
I removed the map replacement related code in patch 02. This means the 
old (identical) kernel map (generated by '/proc/kallsyms') still keeps 
some stale info for 'pgoff', 'mapping_type', etc.

To fix this issue, in the new patch, it removes the old kernel map (to 
avoid any stale info) and update 'machine->vmlinux_map'.

Just one concern. I saw the kcore exposes kernel text section which is 
dependent on the CONFIG_ARCH_PROC_KCORE_TEXT config, but some arches 
(e.g. PowerPC, etc) are absent for this config. But you can see even the 
current code doesn't handle this case, if the replacement map is not 
found, it is arbitrarily assigned to the first map in kcore [1]. An 
option is to rollback to use the old identical kernel map, this is not 
addressed in my latest patch, which is simply report failure in this 
case. Please review it and let me know how you think.

Thanks,
Leo

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/symbol.c?h=v6.9#n1366
Re: [PATCH v2 0/2] perf maps: Improve the kcore maps merging
Posted by Leo Yan 1 year, 9 months ago
Hi Ian,

On 5/15/24 22:39, Ian Rogers wrote:

[...]

> Thanks Leo, testing this change on perf-tools-next with an x86 debian
> laptop I see:
> ```
> $ perf test 24 -v
> 24: Object code reading:
> --- start ---
> test child forked, pid 3407499
> Looking at the vmlinux_path (8 entries long)
> symsrc__init: build id mismatch for vmlinux.
> symsrc__init: cannot get elf header.
> overlapping maps in [kernel.kallsyms] (disable tui for more info)
> Using /proc/kcore for kernel data
> Using /proc/kallsyms for symbols
> Parsing event 'cycles'
> Using CPUID GenuineIntel-6-8D-1
> mmap size 528384B
> Reading object code for memory address: 0xfffffffface8d64a
> File is: /proc/kcore
> On file address is: 0xfffffffface8d64a
> dso__data_read_offset failed
> ---- end(-1) ----
> 24: Object code reading                                             : FAILED!
> ```
> The test passes without the changes. Let me know if you need me to dig deeper.

I can reproduce this test failure at my side. I will look into it.

Thanks for testing!

Leo