Skip to content

Commit a1d3411

Browse files
committed
perf maps: Fixup maps_by_name when modifying maps_by_address
JIRA: https://issues.redhat.com/browse/RHEL-78197 upstream ======== commit 0d11fab Author: Namhyung Kim <namhyung@kernel.org> Date: Fri Feb 28 18:17:32 2025 -0300 description =========== We can't just replacing the map in the maps_by_address and not touching on the maps_by_name, that would leave the refcount as 1 and thus trip another consistency check, this one: perf: util/maps.c:110: check_invariants: Assertion `refcount_read(map__refcnt(map)) > 1' failed. 106 /* 107 * Maps by name maps should be in maps_by_address, so 108 * the reference count should be higher. 109 */ 110 assert(refcount_read(map__refcnt(map)) > 1); Committer notice: Initialize the newly added 'ni' variable, that really can't be accessed unitialized trips some gcc versions, like: 12 20.00 archlinux:base : FAIL gcc version 13.2.1 20230801 (GCC) util/maps.c: In function ‘__maps__fixup_overlap_and_insert’: util/maps.c:896:54: error: ‘ni’ may be used uninitialized [-Werror=maybe-uninitialized] 896 | map__put(maps_by_name[ni]); | ^ util/maps.c:816:25: note: ‘ni’ was declared here 816 | unsigned int i, ni; | ^~ cc1: all warnings being treated as errors make[3]: *** [/git/perf-6.14.0-rc1/tools/build/Makefile.build:138: util] Error 2 Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Reviewed-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/lkml/Z79std66tPq-nqsD@google.com Link: https://lore.kernel.org/r/20250228211734.33781-5-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 72ed256 commit a1d3411

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tools/perf/util/maps.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
813813
{
814814
int err = 0;
815815
FILE *fp = debug_file();
816-
unsigned int i;
816+
unsigned int i, ni = INT_MAX; // Some gcc complain, but depends on maps_by_name...
817817

818818
if (!maps__maps_by_address_sorted(maps))
819819
__maps__sort_by_address(maps);
@@ -824,6 +824,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
824824
*/
825825
for (i = first_ending_after(maps, new); i < maps__nr_maps(maps); ) {
826826
struct map **maps_by_address = maps__maps_by_address(maps);
827+
struct map **maps_by_name = maps__maps_by_name(maps);
827828
struct map *pos = maps_by_address[i];
828829
struct map *before = NULL, *after = NULL;
829830

@@ -843,6 +844,9 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
843844
map__fprintf(pos, fp);
844845
}
845846

847+
if (maps_by_name)
848+
ni = maps__by_name_index(maps, pos);
849+
846850
/*
847851
* Now check if we need to create new maps for areas not
848852
* overlapped by the new map:
@@ -887,6 +891,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
887891
if (before) {
888892
map__put(maps_by_address[i]);
889893
maps_by_address[i] = before;
894+
895+
if (maps_by_name) {
896+
map__put(maps_by_name[ni]);
897+
maps_by_name[ni] = map__get(before);
898+
}
899+
890900
/* Maps are still ordered, go to next one. */
891901
i++;
892902
if (after) {
@@ -908,6 +918,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
908918
*/
909919
map__put(maps_by_address[i]);
910920
maps_by_address[i] = map__get(new);
921+
922+
if (maps_by_name) {
923+
map__put(maps_by_name[ni]);
924+
maps_by_name[ni] = map__get(new);
925+
}
926+
911927
err = __maps__insert_sorted(maps, i + 1, after, NULL);
912928
map__put(after);
913929
check_invariants(maps);
@@ -926,6 +942,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
926942
*/
927943
map__put(maps_by_address[i]);
928944
maps_by_address[i] = map__get(new);
945+
946+
if (maps_by_name) {
947+
map__put(maps_by_name[ni]);
948+
maps_by_name[ni] = map__get(new);
949+
}
950+
929951
check_invariants(maps);
930952
return err;
931953
}

0 commit comments

Comments
 (0)