[PATCH v4 05/22] perf symbol: Sort names under write lock

From: Ian Rogers
Date: Sun Mar 19 2023 - 23:40:01 EST


If finding a name doesn't find the sorted names then they are
allocated and sorted. This shouldn't be done under a read lock as
another reader may access it. Release the read lock and acquire the
write lock, then release the write lock and reacquire the read lock.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/symbol.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 317c0706852f..a458aa8b87bb 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2018,6 +2018,9 @@ static int map__groups__sort_by_name_from_rbtree(struct maps *maps)
if (maps_by_name == NULL)
return -1;

+ up_read(&maps->lock);
+ down_write(&maps->lock);
+
maps->maps_by_name = maps_by_name;
maps->nr_maps_allocated = maps->nr_maps;

@@ -2025,6 +2028,10 @@ static int map__groups__sort_by_name_from_rbtree(struct maps *maps)
maps_by_name[i++] = map;

__maps__sort_by_name(maps);
+
+ up_write(&maps->lock);
+ down_read(&maps->lock);
+
return 0;
}

--
2.40.0.rc1.284.g88254d51c5-goog