perf symbol: Use function to add missing maps lock

Switch do_validate_kcore_modules 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-9-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2023-12-06 17:16:42 -08:00 committed by Arnaldo Carvalho de Melo
parent 300b53d5b8
commit 111350c67d
1 changed files with 19 additions and 17 deletions

View File

@ -1114,33 +1114,35 @@ out_delete_from:
return ret;
}
static int do_validate_kcore_modules_cb(struct map *old_map, void *data)
{
struct rb_root *modules = data;
struct module_info *mi;
struct dso *dso;
if (!__map__is_kmodule(old_map))
return 0;
dso = map__dso(old_map);
/* Module must be in memory at the same address */
mi = find_module(dso->short_name, modules);
if (!mi || mi->start != map__start(old_map))
return -EINVAL;
return 0;
}
static int do_validate_kcore_modules(const char *filename, struct maps *kmaps)
{
struct rb_root modules = RB_ROOT;
struct map_rb_node *old_node;
int err;
err = read_proc_modules(filename, &modules);
if (err)
return err;
maps__for_each_entry(kmaps, old_node) {
struct map *old_map = old_node->map;
struct module_info *mi;
struct dso *dso;
err = maps__for_each_map(kmaps, do_validate_kcore_modules_cb, &modules);
if (!__map__is_kmodule(old_map)) {
continue;
}
dso = map__dso(old_map);
/* Module must be in memory at the same address */
mi = find_module(dso->short_name, &modules);
if (!mi || mi->start != map__start(old_map)) {
err = -EINVAL;
goto out;
}
}
out:
delete_modules(&modules);
return err;
}