perf probe-event: Use function to add missing maps lock
authorIan Rogers <irogers@google.com>
Thu, 7 Dec 2023 01:16:41 +0000 (17:16 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 19 Dec 2023 00:35:07 +0000 (21:35 -0300)
Switch kernel_get_module_map from loop macro maps__for_each_entry to
maps__for_each_map function that takes a callback. The function holds
the maps lock, which should be held during iteration.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Guilherme Amadio <amadio@gentoo.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Li Dong <lidong@vivo.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Vincent Whitchurch <vincent.whitchurch@axis.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20231207011722.1220634-8-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/probe-event.c

index 1a5b7fa459b232043457f706b45c0b7a87d35643..a1a796043691f487fe901e9fafef5888913f4ec7 100644 (file)
@@ -149,10 +149,32 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
        return 0;
 }
 
+struct kernel_get_module_map_cb_args {
+       const char *module;
+       struct map *result;
+};
+
+static int kernel_get_module_map_cb(struct map *map, void *data)
+{
+       struct kernel_get_module_map_cb_args *args = data;
+       struct dso *dso = map__dso(map);
+       const char *short_name = dso->short_name; /* short_name is "[module]" */
+       u16 short_name_len =  dso->short_name_len;
+
+       if (strncmp(short_name + 1, args->module, short_name_len - 2) == 0 &&
+           args->module[short_name_len - 2] == '\0') {
+               args->result = map__get(map);
+               return 1;
+       }
+       return 0;
+}
+
 static struct map *kernel_get_module_map(const char *module)
 {
-       struct maps *maps = machine__kernel_maps(host_machine);
-       struct map_rb_node *pos;
+       struct kernel_get_module_map_cb_args args = {
+               .module = module,
+               .result = NULL,
+       };
 
        /* A file path -- this is an offline module */
        if (module && strchr(module, '/'))
@@ -164,19 +186,9 @@ static struct map *kernel_get_module_map(const char *module)
                return map__get(map);
        }
 
-       maps__for_each_entry(maps, pos) {
-               /* short_name is "[module]" */
-               struct dso *dso = map__dso(pos->map);
-               const char *short_name = dso->short_name;
-               u16 short_name_len =  dso->short_name_len;
+       maps__for_each_map(machine__kernel_maps(host_machine), kernel_get_module_map_cb, &args);
 
-               if (strncmp(short_name + 1, module,
-                           short_name_len - 2) == 0 &&
-                   module[short_name_len - 2] == '\0') {
-                       return map__get(pos->map);
-               }
-       }
-       return NULL;
+       return args.result;
 }
 
 struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)