Skip to content

Commit 20c9ccf

Browse files
captain5050namhyung
authored andcommitted
perf maps: Ensure kmap is set up for all inserts
__maps__fixup_overlap_and_insert may split or directly insert a map, when doing this the map may need to have a kmap set up for the sake of the kmaps. The missing kmap set up fails the check_invariants test in maps, later "Internal error" reports from map__kmap and ultimately causes segfaults. Similar fixes were added in commit e0e4e0b ("perf maps: Add missing map__set_kmap_maps() when replacing a kernel map") and commit 25d9c03 ("perf maps: Set the kmaps for newly created/added kernel maps") but they missed cases. To try to reduce the risk of this, update the kmap directly following any manual insert. This identified another problem in maps__copy_from. Fixes: e0e4e0b ("perf maps: Add missing map__set_kmap_maps() when replacing a kernel map") Fixes: 25d9c03 ("perf maps: Set the kmaps for newly created/added kernel maps") Signed-off-by: Ian Rogers <[email protected]> Signed-off-by: Namhyung Kim <[email protected]>
1 parent 7947ad1 commit 20c9ccf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/perf/util/maps.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ static int __maps__insert(struct maps *maps, struct map *new)
477477
}
478478
/* Insert the value at the end. */
479479
maps_by_address[nr_maps] = map__get(new);
480+
map__set_kmap_maps(new, maps);
480481
if (maps_by_name)
481482
maps_by_name[nr_maps] = map__get(new);
482483

@@ -502,8 +503,6 @@ static int __maps__insert(struct maps *maps, struct map *new)
502503
if (map__end(new) < map__start(new))
503504
RC_CHK_ACCESS(maps)->ends_broken = true;
504505

505-
map__set_kmap_maps(new, maps);
506-
507506
return 0;
508507
}
509508

@@ -891,6 +890,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
891890
if (before) {
892891
map__put(maps_by_address[i]);
893892
maps_by_address[i] = before;
893+
map__set_kmap_maps(before, maps);
894894

895895
if (maps_by_name) {
896896
map__put(maps_by_name[ni]);
@@ -918,6 +918,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
918918
*/
919919
map__put(maps_by_address[i]);
920920
maps_by_address[i] = map__get(new);
921+
map__set_kmap_maps(new, maps);
921922

922923
if (maps_by_name) {
923924
map__put(maps_by_name[ni]);
@@ -942,14 +943,13 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
942943
*/
943944
map__put(maps_by_address[i]);
944945
maps_by_address[i] = map__get(new);
946+
map__set_kmap_maps(new, maps);
945947

946948
if (maps_by_name) {
947949
map__put(maps_by_name[ni]);
948950
maps_by_name[ni] = map__get(new);
949951
}
950952

951-
map__set_kmap_maps(new, maps);
952-
953953
check_invariants(maps);
954954
return err;
955955
}
@@ -1019,6 +1019,7 @@ int maps__copy_from(struct maps *dest, struct maps *parent)
10191019
err = unwind__prepare_access(dest, new, NULL);
10201020
if (!err) {
10211021
dest_maps_by_address[i] = new;
1022+
map__set_kmap_maps(new, dest);
10221023
if (dest_maps_by_name)
10231024
dest_maps_by_name[i] = map__get(new);
10241025
RC_CHK_ACCESS(dest)->nr_maps = i + 1;

0 commit comments

Comments
 (0)