summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWei Li <liwei391@huawei.com>2019-02-28 04:20:03 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-03-28 13:41:21 -0400
commit977c7a6d1e263ff1d755f28595b99e4bc0c48a9f (patch)
tree5f40661736faa2a4b261b2856b1c9e2cb971dda4 /tools
parent707c373c846cf6e27a47a2c093d243a35c691b62 (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/machine.c32
1 files 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,
1421 machine->vmlinux_map->end = ~0ULL; 1421 machine->vmlinux_map->end = ~0ULL;
1422} 1422}
1423 1423
1424static void machine__update_kernel_mmap(struct machine *machine,
1425 u64 start, u64 end)
1426{
1427 struct map *map = machine__kernel_map(machine);
1428
1429 map__get(map);
1430 map_groups__remove(&machine->kmaps, map);
1431
1432 machine__set_kernel_mmap(machine, start, end);
1433
1434 map_groups__insert(&machine->kmaps, map);
1435 map__put(map);
1436}
1437
1424int machine__create_kernel_maps(struct machine *machine) 1438int machine__create_kernel_maps(struct machine *machine)
1425{ 1439{
1426 struct dso *kernel = machine__get_kernel(machine); 1440 struct dso *kernel = machine__get_kernel(machine);
@@ -1453,17 +1467,11 @@ int machine__create_kernel_maps(struct machine *machine)
1453 goto out_put; 1467 goto out_put;
1454 } 1468 }
1455 1469
1456 /* we have a real start address now, so re-order the kmaps */ 1470 /*
1457 map = machine__kernel_map(machine); 1471 * we have a real start address now, so re-order the kmaps
1458 1472 * assume it's the last in the kmaps
1459 map__get(map); 1473 */
1460 map_groups__remove(&machine->kmaps, map); 1474 machine__update_kernel_mmap(machine, addr, ~0ULL);
1461
1462 /* assume it's the last in the kmaps */
1463 machine__set_kernel_mmap(machine, addr, ~0ULL);
1464
1465 map_groups__insert(&machine->kmaps, map);
1466 map__put(map);
1467 } 1475 }
1468 1476
1469 if (machine__create_extra_kernel_maps(machine, kernel)) 1477 if (machine__create_extra_kernel_maps(machine, kernel))
@@ -1599,7 +1607,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
1599 if (strstr(kernel->long_name, "vmlinux")) 1607 if (strstr(kernel->long_name, "vmlinux"))
1600 dso__set_short_name(kernel, "[kernel.vmlinux]", false); 1608 dso__set_short_name(kernel, "[kernel.vmlinux]", false);
1601 1609
1602 machine__set_kernel_mmap(machine, event->mmap.start, 1610 machine__update_kernel_mmap(machine, event->mmap.start,
1603 event->mmap.start + event->mmap.len); 1611 event->mmap.start + event->mmap.len);
1604 1612
1605 /* 1613 /*