Commit 2dc549b1 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf machine: Use function to add missing maps lock

Switch machine__map_x86_64_entry_trampolines and
machine__for_each_kernel_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: default avatarIan 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-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b1928ca9
......@@ -1285,33 +1285,46 @@ static u64 find_entry_trampoline(struct dso *dso)
#define X86_64_CPU_ENTRY_AREA_SIZE 0x2c000
#define X86_64_ENTRY_TRAMPOLINE 0x6000
struct machine__map_x86_64_entry_trampolines_args {
struct maps *kmaps;
bool found;
};
static int machine__map_x86_64_entry_trampolines_cb(struct map *map, void *data)
{
struct machine__map_x86_64_entry_trampolines_args *args = data;
struct map *dest_map;
struct kmap *kmap = __map__kmap(map);
if (!kmap || !is_entry_trampoline(kmap->name))
return 0;
dest_map = maps__find(args->kmaps, map__pgoff(map));
if (dest_map != map)
map__set_pgoff(map, map__map_ip(dest_map, map__pgoff(map)));
args->found = true;
return 0;
}
/* Map x86_64 PTI entry trampolines */
int machine__map_x86_64_entry_trampolines(struct machine *machine,
struct dso *kernel)
{
struct maps *kmaps = machine__kernel_maps(machine);
struct machine__map_x86_64_entry_trampolines_args args = {
.kmaps = machine__kernel_maps(machine),
.found = false,
};
int nr_cpus_avail, cpu;
bool found = false;
struct map_rb_node *rb_node;
u64 pgoff;
/*
* In the vmlinux case, pgoff is a virtual address which must now be
* mapped to a vmlinux offset.
*/
maps__for_each_entry(kmaps, rb_node) {
struct map *dest_map, *map = rb_node->map;
struct kmap *kmap = __map__kmap(map);
if (!kmap || !is_entry_trampoline(kmap->name))
continue;
maps__for_each_map(args.kmaps, machine__map_x86_64_entry_trampolines_cb, &args);
dest_map = maps__find(kmaps, map__pgoff(map));
if (dest_map != map)
map__set_pgoff(map, map__map_ip(dest_map, map__pgoff(map)));
found = true;
}
if (found || machine->trampolines_mapped)
if (args.found || machine->trampolines_mapped)
return 0;
pgoff = find_entry_trampoline(kernel);
......@@ -3398,16 +3411,8 @@ int machine__for_each_dso(struct machine *machine, machine__dso_t fn, void *priv
int machine__for_each_kernel_map(struct machine *machine, machine__map_t fn, void *priv)
{
struct maps *maps = machine__kernel_maps(machine);
struct map_rb_node *pos;
int err = 0;
maps__for_each_entry(maps, pos) {
err = fn(pos->map, priv);
if (err != 0) {
break;
}
}
return err;
return maps__for_each_map(maps, fn, priv);
}
bool machine__is_lock_function(struct machine *machine, u64 addr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment