Commit 2b5e1a46 authored by Ian Rogers's avatar Ian Rogers Committed by langfei
Browse files

perf maps: Use a pointer for kmaps

mainline inclusion
from mainline-v5.18
commit 1a97cee6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBBJ27

Reference: https://github.com/torvalds/linux/commit/1a97cee604dcbdba6c75984b7227223d599ddf32



--------------------------------

struct maps is reference counted, using a pointer is more idiomatic.

Committer notes:

Delay:

  maps = machine__kernel_maps(&vmlinux);

To after:

  machine__init(&vmlinux, "", HOST_KERNEL_ID);

To avoid this on f34:

  In file included
    from /var/home/acme/git/perf/tools/perf/util/build-id.h:10,
    from /var/home/acme/git/perf/tools/perf/util/dso.h:13,
    from tests/vmlinux-kallsyms.c:8:
  In function ‘machine__kernel_maps’,
      inlined from ‘test__vmlinux_matches_kallsyms’ at
        tests/vmlinux-kallsyms.c:122:22:
  /var/home/acme/git/perf/tools/perf/util/machine.h:86:23:
    error: ‘vmlinux.kmaps’ is used uninitialized [-Werror=uninitialized]
     86 |         return machine->kmaps;
        |                ~~~~~~~^~~~~~~
  tests/vmlinux-kallsyms.c: In function ‘test__vmlinux_matches_kallsyms’:
  tests/vmlinux-kallsyms.c:121:34: note: ‘vmlinux’ declared here
    121 |         struct machine kallsyms, vmlinux;
        |                                  ^~~~~~~
  cc1: all warnings being treated as errors

Conflict: modified tools/perf/util/machine.c context due to c087e948 not merge.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarlangfei <langfei@huawei.com>
parent 36ade961
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
{
	int rc = 0;
	struct map *pos;
	struct maps *kmaps = &machine->kmaps;
	struct maps *kmaps = machine__kernel_maps(machine);
	union perf_event *event = zalloc(sizeof(event->mmap) +
					 machine->id_hdr_size);

+5 −3
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
	struct symbol *sym;
	struct map *kallsyms_map, *vmlinux_map, *map;
	struct machine kallsyms, vmlinux;
	struct maps *maps = machine__kernel_maps(&vmlinux);
	struct maps *maps;
	u64 mem_start, mem_end;
	bool header_printed;

@@ -34,6 +34,8 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
	machine__init(&kallsyms, "", HOST_KERNEL_ID);
	machine__init(&vmlinux, "", HOST_KERNEL_ID);

	maps = machine__kernel_maps(&vmlinux);

	/*
	 * Step 2:
	 *
@@ -190,7 +192,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
		 * so use the short name, less descriptive but the same ("[kernel]" in
		 * both cases.
		 */
		pair = maps__find_by_name(&kallsyms.kmaps, (map->dso->kernel ?
		pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
								map->dso->short_name :
								map->dso->name));
		if (pair) {
@@ -212,7 +214,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);

		pair = maps__find(&kallsyms.kmaps, mem_start);
		pair = maps__find(kallsyms.kmaps, mem_start);
		if (pair == NULL || pair->priv)
			continue;

+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ static int machine__process_bpf_event_load(struct machine *machine,
	for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
		u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
		u64 addr = addrs[i];
		struct map *map = maps__find(&machine->kmaps, addr);
		struct map *map = maps__find(machine__kernel_maps(machine), addr);

		if (map) {
			map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+1 −1
Original line number Diff line number Diff line
@@ -1119,7 +1119,7 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
			goto out;
	}

	if (al->maps == &al->maps->machine->kmaps) {
	if (al->maps == machine__kernel_maps(al->maps->machine)) {
		if (machine__is_host(al->maps->machine)) {
			al->cpumode = PERF_RECORD_MISC_KERNEL;
			al->level = 'k';
+3 −3
Original line number Diff line number Diff line
@@ -450,7 +450,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
	if (machine) {
		struct addr_location al;

		al.map = maps__find(&machine->kmaps, tp->addr);
		al.map = maps__find(machine__kernel_maps(machine), tp->addr);
		if (al.map && map__load(al.map) >= 0) {
			al.addr = al.map->map_ip(al.map, tp->addr);
			al.sym = map__find_symbol(al.map, al.addr);
@@ -550,13 +550,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,

	if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
		al->level = 'k';
		al->maps = maps = &machine->kmaps;
		al->maps = maps = machine__kernel_maps(machine);
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
		al->level = '.';
	} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
		al->level = 'g';
		al->maps = maps = &machine->kmaps;
		al->maps = maps = machine__kernel_maps(machine);
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
		al->level = 'u';
Loading