linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf machine: Update kernel map address and re-order properly
@ 2019-02-28  9:20 Wei Li
  2019-02-28 11:28 ` Jiri Olsa
  2019-03-29 20:41 ` [tip:perf/urgent] " tip-bot for Wei Li
  0 siblings, 2 replies; 6+ messages in thread
From: Wei Li @ 2019-02-28  9:20 UTC (permalink / raw)
  To: jolsa, alexander.shishkin, dsahern, namhyung, peterz, acme
  Cc: linux-kernel, kim.phillips, guohanjun, huawei.libin

Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
just create a map what start and end are both zero. Though the address will be
updated later, the order of map in the rbtree may be incorrect.

The commit ee05d21791db ("perf machine: Set main kernel end address properly")
fixed the logic in machine__create_kernel_maps(), but it's still wrong in
function machine__process_kernel_mmap_event().

To reproduce this issue, we need an environment which the module address
is before the kernel text segment. I tested it on an aarch64 machine with
kernel 4.19.25:

[root@localhost hulk]# grep _stext /proc/kallsyms 
ffff000008081000 T _stext
[root@localhost hulk]# grep _etext /proc/kallsyms 
ffff000009780000 R _etext
[root@localhost hulk]# tail /proc/modules 
hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
nvme_core 126976 7 nvme, Live 0xffff0000018b6000
mdio 20480 1 ixgbe, Live 0xffff0000018ab000
hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
hns_mdio 20480 2 - Live 0xffff000001822000
hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
dm_mirror 40960 0 - Live 0xffff000001804000
dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
[root@localhost hulk]# 

Before fix:

[root@localhost bin]# perf record sleep 3
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
[root@localhost bin]# perf buildid-list -i perf.data 
4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
[root@localhost bin]# perf buildid-list -i perf.data -H
0000000000000000000000000000000000000000 /proc/kcore
[root@localhost bin]# 

After fix:

[root@localhost tools]# ./perf/perf record sleep 3
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
[root@localhost tools]# ./perf/perf buildid-list -i perf.data 
28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
[root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore

Signed-off-by: Wei Li <liwei391@huawei.com>
---
 tools/perf/util/machine.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index b1508ce3e412..076718a7b3ea 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1358,6 +1358,20 @@ static void machine__set_kernel_mmap(struct machine *machine,
 		machine->vmlinux_map->end = ~0ULL;
 }
 
+static void machine__update_kernel_mmap(struct machine *machine,
+				     u64 start, u64 end)
+{
+	struct map *map = machine__kernel_map(machine);
+
+	map__get(map);
+	map_groups__remove(&machine->kmaps, map);
+
+	machine__set_kernel_mmap(machine, start, end);
+
+	map_groups__insert(&machine->kmaps, map);
+	map__put(map);
+}
+
 int machine__create_kernel_maps(struct machine *machine)
 {
 	struct dso *kernel = machine__get_kernel(machine);
@@ -1390,17 +1404,11 @@ int machine__create_kernel_maps(struct machine *machine)
 			goto out_put;
 		}
 
-		/* we have a real start address now, so re-order the kmaps */
-		map = machine__kernel_map(machine);
-
-		map__get(map);
-		map_groups__remove(&machine->kmaps, map);
-
-		/* assume it's the last in the kmaps */
-		machine__set_kernel_mmap(machine, addr, ~0ULL);
-
-		map_groups__insert(&machine->kmaps, map);
-		map__put(map);
+		/*
+		 * we have a real start address now, so re-order the kmaps
+		 * assume it's the last in the kmaps
+		 */
+		machine__update_kernel_mmap(machine, addr, ~0ULL);
 	}
 
 	if (machine__create_extra_kernel_maps(machine, kernel))
@@ -1536,7 +1544,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
 		if (strstr(kernel->long_name, "vmlinux"))
 			dso__set_short_name(kernel, "[kernel.vmlinux]", false);
 
-		machine__set_kernel_mmap(machine, event->mmap.start,
+		machine__update_kernel_mmap(machine, event->mmap.start,
 					 event->mmap.start + event->mmap.len);
 
 		/*
-- 
2.17.1


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

* Re: [PATCH] perf machine: Update kernel map address and re-order properly
  2019-02-28  9:20 [PATCH] perf machine: Update kernel map address and re-order properly Wei Li
@ 2019-02-28 11:28 ` Jiri Olsa
  2019-03-26  9:11   ` liwei (GF)
  2019-03-29 20:41 ` [tip:perf/urgent] " tip-bot for Wei Li
  1 sibling, 1 reply; 6+ messages in thread
From: Jiri Olsa @ 2019-02-28 11:28 UTC (permalink / raw)
  To: Wei Li
  Cc: jolsa, alexander.shishkin, dsahern, namhyung, peterz, acme,
	linux-kernel, kim.phillips, guohanjun, huawei.libin

On Thu, Feb 28, 2019 at 05:20:03PM +0800, Wei Li wrote:
> Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
> start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
> just create a map what start and end are both zero. Though the address will be
> updated later, the order of map in the rbtree may be incorrect.
> 
> The commit ee05d21791db ("perf machine: Set main kernel end address properly")
> fixed the logic in machine__create_kernel_maps(), but it's still wrong in
> function machine__process_kernel_mmap_event().
> 
> To reproduce this issue, we need an environment which the module address
> is before the kernel text segment. I tested it on an aarch64 machine with
> kernel 4.19.25:

so that was the missing piece.. nice

> 
> [root@localhost hulk]# grep _stext /proc/kallsyms 
> ffff000008081000 T _stext
> [root@localhost hulk]# grep _etext /proc/kallsyms 
> ffff000009780000 R _etext
> [root@localhost hulk]# tail /proc/modules 
> hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
> nvme_core 126976 7 nvme, Live 0xffff0000018b6000
> mdio 20480 1 ixgbe, Live 0xffff0000018ab000
> hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
> hns_mdio 20480 2 - Live 0xffff000001822000
> hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
> dm_mirror 40960 0 - Live 0xffff000001804000
> dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
> dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
> dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
> [root@localhost hulk]# 
> 
> Before fix:
> 
> [root@localhost bin]# perf record sleep 3
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> [root@localhost bin]# perf buildid-list -i perf.data 
> 4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
> [root@localhost bin]# perf buildid-list -i perf.data -H
> 0000000000000000000000000000000000000000 /proc/kcore
> [root@localhost bin]# 
> 
> After fix:
> 
> [root@localhost tools]# ./perf/perf record sleep 3
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> [root@localhost tools]# ./perf/perf buildid-list -i perf.data 
> 28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
> 106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
> [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
> 28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore
> 
> Signed-off-by: Wei Li <liwei391@huawei.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

good catch, thanks
jirka

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

* Re: [PATCH] perf machine: Update kernel map address and re-order properly
  2019-02-28 11:28 ` Jiri Olsa
@ 2019-03-26  9:11   ` liwei (GF)
  2019-03-26 14:03     ` Namhyung Kim
  0 siblings, 1 reply; 6+ messages in thread
From: liwei (GF) @ 2019-03-26  9:11 UTC (permalink / raw)
  To: acme
  Cc: Jiri Olsa, jolsa, alexander.shishkin, dsahern, namhyung, peterz,
	linux-kernel, kim.phillips, guohanjun, huawei.libin

Hi Arnaldo,

Please shoot a glance at this modification, i think this issue is influential.

On 2019/2/28 19:28, Jiri Olsa Wrote:
> On Thu, Feb 28, 2019 at 05:20:03PM +0800, Wei Li wrote:
>> Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
>> start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
>> just create a map what start and end are both zero. Though the address will be
>> updated later, the order of map in the rbtree may be incorrect.
>>
>> The commit ee05d21791db ("perf machine: Set main kernel end address properly")
>> fixed the logic in machine__create_kernel_maps(), but it's still wrong in
>> function machine__process_kernel_mmap_event().
>>
>> To reproduce this issue, we need an environment which the module address
>> is before the kernel text segment. I tested it on an aarch64 machine with
>> kernel 4.19.25:
> 
> so that was the missing piece.. nice
> 
>>
>> [root@localhost hulk]# grep _stext /proc/kallsyms 
>> ffff000008081000 T _stext
>> [root@localhost hulk]# grep _etext /proc/kallsyms 
>> ffff000009780000 R _etext
>> [root@localhost hulk]# tail /proc/modules 
>> hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
>> nvme_core 126976 7 nvme, Live 0xffff0000018b6000
>> mdio 20480 1 ixgbe, Live 0xffff0000018ab000
>> hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
>> hns_mdio 20480 2 - Live 0xffff000001822000
>> hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
>> dm_mirror 40960 0 - Live 0xffff000001804000
>> dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
>> dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
>> dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
>> [root@localhost hulk]# 
>>
>> Before fix:
>>
>> [root@localhost bin]# perf record sleep 3
>> [ perf record: Woken up 1 times to write data ]
>> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
>> [root@localhost bin]# perf buildid-list -i perf.data 
>> 4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
>> [root@localhost bin]# perf buildid-list -i perf.data -H
>> 0000000000000000000000000000000000000000 /proc/kcore
>> [root@localhost bin]# 
>>
>> After fix:
>>
>> [root@localhost tools]# ./perf/perf record sleep 3
>> [ perf record: Woken up 1 times to write data ]
>> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
>> [root@localhost tools]# ./perf/perf buildid-list -i perf.data 
>> 28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
>> 106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
>> [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
>> 28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore
>>
>> Signed-off-by: Wei Li <liwei391@huawei.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> good catch, thanks
> jirka
> 

Thanks,
Wei


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

* Re: [PATCH] perf machine: Update kernel map address and re-order properly
  2019-03-26  9:11   ` liwei (GF)
@ 2019-03-26 14:03     ` Namhyung Kim
  2019-03-26 18:19       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 6+ messages in thread
From: Namhyung Kim @ 2019-03-26 14:03 UTC (permalink / raw)
  To: liwei (GF)
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Jiri Olsa,
	Alexander Shishkin, David Ahern, Peter Zijlstra, linux-kernel,
	Kim Phillips, guohanjun, Li Bin

Hello,

On Tue, Mar 26, 2019 at 6:12 PM liwei (GF) <liwei391@huawei.com> wrote:
>
> Hi Arnaldo,
>
> Please shoot a glance at this modification, i think this issue is influential.
>
> On 2019/2/28 19:28, Jiri Olsa Wrote:
> > On Thu, Feb 28, 2019 at 05:20:03PM +0800, Wei Li wrote:
> >> Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
> >> start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
> >> just create a map what start and end are both zero. Though the address will be
> >> updated later, the order of map in the rbtree may be incorrect.
> >>
> >> The commit ee05d21791db ("perf machine: Set main kernel end address properly")
> >> fixed the logic in machine__create_kernel_maps(), but it's still wrong in
> >> function machine__process_kernel_mmap_event().
> >>
> >> To reproduce this issue, we need an environment which the module address
> >> is before the kernel text segment. I tested it on an aarch64 machine with
> >> kernel 4.19.25:
> >
> > so that was the missing piece.. nice
> >
> >>
> >> [root@localhost hulk]# grep _stext /proc/kallsyms
> >> ffff000008081000 T _stext
> >> [root@localhost hulk]# grep _etext /proc/kallsyms
> >> ffff000009780000 R _etext
> >> [root@localhost hulk]# tail /proc/modules
> >> hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
> >> nvme_core 126976 7 nvme, Live 0xffff0000018b6000
> >> mdio 20480 1 ixgbe, Live 0xffff0000018ab000
> >> hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
> >> hns_mdio 20480 2 - Live 0xffff000001822000
> >> hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
> >> dm_mirror 40960 0 - Live 0xffff000001804000
> >> dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
> >> dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
> >> dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
> >> [root@localhost hulk]#
> >>
> >> Before fix:
> >>
> >> [root@localhost bin]# perf record sleep 3
> >> [ perf record: Woken up 1 times to write data ]
> >> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> >> [root@localhost bin]# perf buildid-list -i perf.data
> >> 4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
> >> [root@localhost bin]# perf buildid-list -i perf.data -H
> >> 0000000000000000000000000000000000000000 /proc/kcore
> >> [root@localhost bin]#
> >>
> >> After fix:
> >>
> >> [root@localhost tools]# ./perf/perf record sleep 3
> >> [ perf record: Woken up 1 times to write data ]
> >> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> >> [root@localhost tools]# ./perf/perf buildid-list -i perf.data
> >> 28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
> >> 106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
> >> [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
> >> 28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore
> >>
> >> Signed-off-by: Wei Li <liwei391@huawei.com>
> >
> > Acked-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

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

* Re: [PATCH] perf machine: Update kernel map address and re-order properly
  2019-03-26 14:03     ` Namhyung Kim
@ 2019-03-26 18:19       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-03-26 18:19 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: liwei (GF),
	Jiri Olsa, Jiri Olsa, Alexander Shishkin, David Ahern,
	Peter Zijlstra, linux-kernel, Kim Phillips, guohanjun, Li Bin

Em Tue, Mar 26, 2019 at 11:03:14PM +0900, Namhyung Kim escreveu:
> Hello,
> 
> On Tue, Mar 26, 2019 at 6:12 PM liwei (GF) <liwei391@huawei.com> wrote:
> >
> > Hi Arnaldo,
> >
> > Please shoot a glance at this modification, i think this issue is influential.
> >
> > On 2019/2/28 19:28, Jiri Olsa Wrote:
> > > On Thu, Feb 28, 2019 at 05:20:03PM +0800, Wei Li wrote:
> > >> Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
> > >> start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
> > >> just create a map what start and end are both zero. Though the address will be
> > >> updated later, the order of map in the rbtree may be incorrect.
> > >>
> > >> The commit ee05d21791db ("perf machine: Set main kernel end address properly")
> > >> fixed the logic in machine__create_kernel_maps(), but it's still wrong in
> > >> function machine__process_kernel_mmap_event().
> > >>
> > >> To reproduce this issue, we need an environment which the module address
> > >> is before the kernel text segment. I tested it on an aarch64 machine with
> > >> kernel 4.19.25:
> > >
> > > so that was the missing piece.. nice
> > >
> > >>
> > >> [root@localhost hulk]# grep _stext /proc/kallsyms
> > >> ffff000008081000 T _stext
> > >> [root@localhost hulk]# grep _etext /proc/kallsyms
> > >> ffff000009780000 R _etext
> > >> [root@localhost hulk]# tail /proc/modules
> > >> hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
> > >> nvme_core 126976 7 nvme, Live 0xffff0000018b6000
> > >> mdio 20480 1 ixgbe, Live 0xffff0000018ab000
> > >> hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
> > >> hns_mdio 20480 2 - Live 0xffff000001822000
> > >> hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
> > >> dm_mirror 40960 0 - Live 0xffff000001804000
> > >> dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
> > >> dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
> > >> dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
> > >> [root@localhost hulk]#
> > >>
> > >> Before fix:
> > >>
> > >> [root@localhost bin]# perf record sleep 3
> > >> [ perf record: Woken up 1 times to write data ]
> > >> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> > >> [root@localhost bin]# perf buildid-list -i perf.data
> > >> 4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
> > >> [root@localhost bin]# perf buildid-list -i perf.data -H
> > >> 0000000000000000000000000000000000000000 /proc/kcore
> > >> [root@localhost bin]#
> > >>
> > >> After fix:
> > >>
> > >> [root@localhost tools]# ./perf/perf record sleep 3
> > >> [ perf record: Woken up 1 times to write data ]
> > >> [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
> > >> [root@localhost tools]# ./perf/perf buildid-list -i perf.data
> > >> 28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
> > >> 106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
> > >> [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
> > >> 28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore
> > >>
> > >> Signed-off-by: Wei Li <liwei391@huawei.com>
> > >
> > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, applied to perf/urgent.

- Arnaldo

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

* [tip:perf/urgent] perf machine: Update kernel map address and re-order properly
  2019-02-28  9:20 [PATCH] perf machine: Update kernel map address and re-order properly Wei Li
  2019-02-28 11:28 ` Jiri Olsa
@ 2019-03-29 20:41 ` tip-bot for Wei Li
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Wei Li @ 2019-03-29 20:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, namhyung, jolsa, huawei.libin, guohanjun,
	alexander.shishkin, liwei391, kim.phillips, tglx, hpa, dsahern,
	linux-kernel, peterz, acme

Commit-ID:  977c7a6d1e263ff1d755f28595b99e4bc0c48a9f
Gitweb:     https://git.kernel.org/tip/977c7a6d1e263ff1d755f28595b99e4bc0c48a9f
Author:     Wei Li <liwei391@huawei.com>
AuthorDate: Thu, 28 Feb 2019 17:20:03 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Mar 2019 14:41:21 -0300

perf machine: Update kernel map address and re-order properly

Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel
start in __machine__create_kernel_maps"), the __machine__create_kernel_maps()
just create a map what start and end are both zero. Though the address will be
updated later, the order of map in the rbtree may be incorrect.

The commit ee05d21791db ("perf machine: Set main kernel end address properly")
fixed the logic in machine__create_kernel_maps(), but it's still wrong in
function machine__process_kernel_mmap_event().

To reproduce this issue, we need an environment which the module address
is before the kernel text segment. I tested it on an aarch64 machine with
kernel 4.19.25:

  [root@localhost hulk]# grep _stext /proc/kallsyms
  ffff000008081000 T _stext
  [root@localhost hulk]# grep _etext /proc/kallsyms
  ffff000009780000 R _etext
  [root@localhost hulk]# tail /proc/modules
  hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000
  nvme_core 126976 7 nvme, Live 0xffff0000018b6000
  mdio 20480 1 ixgbe, Live 0xffff0000018ab000
  hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000
  hns_mdio 20480 2 - Live 0xffff000001822000
  hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000
  dm_mirror 40960 0 - Live 0xffff000001804000
  dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000
  dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000
  dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000
  [root@localhost hulk]#

Before fix:

  [root@localhost bin]# perf record sleep 3
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
  [root@localhost bin]# perf buildid-list -i perf.data
  4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso]
  [root@localhost bin]# perf buildid-list -i perf.data -H
  0000000000000000000000000000000000000000 /proc/kcore
  [root@localhost bin]#

After fix:

  [root@localhost tools]# ./perf/perf record sleep 3
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ]
  [root@localhost tools]# ./perf/perf buildid-list -i perf.data
  28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms]
  106c14ce6e4acea3453e484dc604d66666f08a2f [vdso]
  [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H
  28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore

Signed-off-by: Wei Li <liwei391@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Li Bin <huawei.libin@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190228092003.34071-1-liwei391@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 61959aba7e27..3c520baa198c 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1421,6 +1421,20 @@ static void machine__set_kernel_mmap(struct machine *machine,
 		machine->vmlinux_map->end = ~0ULL;
 }
 
+static void machine__update_kernel_mmap(struct machine *machine,
+				     u64 start, u64 end)
+{
+	struct map *map = machine__kernel_map(machine);
+
+	map__get(map);
+	map_groups__remove(&machine->kmaps, map);
+
+	machine__set_kernel_mmap(machine, start, end);
+
+	map_groups__insert(&machine->kmaps, map);
+	map__put(map);
+}
+
 int machine__create_kernel_maps(struct machine *machine)
 {
 	struct dso *kernel = machine__get_kernel(machine);
@@ -1453,17 +1467,11 @@ int machine__create_kernel_maps(struct machine *machine)
 			goto out_put;
 		}
 
-		/* we have a real start address now, so re-order the kmaps */
-		map = machine__kernel_map(machine);
-
-		map__get(map);
-		map_groups__remove(&machine->kmaps, map);
-
-		/* assume it's the last in the kmaps */
-		machine__set_kernel_mmap(machine, addr, ~0ULL);
-
-		map_groups__insert(&machine->kmaps, map);
-		map__put(map);
+		/*
+		 * we have a real start address now, so re-order the kmaps
+		 * assume it's the last in the kmaps
+		 */
+		machine__update_kernel_mmap(machine, addr, ~0ULL);
 	}
 
 	if (machine__create_extra_kernel_maps(machine, kernel))
@@ -1599,7 +1607,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
 		if (strstr(kernel->long_name, "vmlinux"))
 			dso__set_short_name(kernel, "[kernel.vmlinux]", false);
 
-		machine__set_kernel_mmap(machine, event->mmap.start,
+		machine__update_kernel_mmap(machine, event->mmap.start,
 					 event->mmap.start + event->mmap.len);
 
 		/*

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

end of thread, other threads:[~2019-03-29 20:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-28  9:20 [PATCH] perf machine: Update kernel map address and re-order properly Wei Li
2019-02-28 11:28 ` Jiri Olsa
2019-03-26  9:11   ` liwei (GF)
2019-03-26 14:03     ` Namhyung Kim
2019-03-26 18:19       ` Arnaldo Carvalho de Melo
2019-03-29 20:41 ` [tip:perf/urgent] " tip-bot for Wei Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).