Skip to contentSkip to conversation

Reference count checker and related fixes

PATCH Applied Ian Rogers 4 participants 58 messages Feb 11, 2022 – Feb 16, 2022 perf events Page 2 of 3

lore
Share & tools
lore
#43 lore raw

Re: [PATCH v3 15/22] perf map: Use functions to access the variables in map

In reply to Ian Rogers

Em Fri, Feb 11, 2022 at 02:34:08AM -0800, Ian Rogers escreveu:

Quoted 7 lines

The use of functions enables easier reference count checking. Some minor changes to map_ip and unmap_ip to making the naming a little clearer. __maps_insert is modified to return the inserted map, which simplifies the reference checking wrapping. maps__fixup_overlappings has some minor tweaks so that puts occur on error paths. dso__process_kernel_symbol has the unused curr_mapp argument removed.

This one should be at the forefront of this patchset to reduce the possibility that it would clash with patches coming after it, lets see..

- Arnaldo

Quoted 3,207 lines
---
 tools/perf/arch/s390/annotate/instructions.c  |   4 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c      |   2 +-
 tools/perf/arch/x86/util/event.c              |   6 +-
 tools/perf/builtin-annotate.c                 |   8 +-
 tools/perf/builtin-inject.c                   |   8 +-
 tools/perf/builtin-kallsyms.c                 |   6 +-
 tools/perf/builtin-kmem.c                     |   4 +-
 tools/perf/builtin-mem.c                      |   4 +-
 tools/perf/builtin-report.c                   |  20 +--
 tools/perf/builtin-script.c                   |  26 ++--
 tools/perf/builtin-top.c                      |  12 +-
 tools/perf/builtin-trace.c                    |   2 +-
 .../scripts/python/Perf-Trace-Util/Context.c  |   7 +-
 tools/perf/tests/code-reading.c               |  32 ++---
 tools/perf/tests/hists_common.c               |   4 +-
 tools/perf/tests/vmlinux-kallsyms.c           |  35 +++---
 tools/perf/ui/browsers/annotate.c             |   7 +-
 tools/perf/ui/browsers/hists.c                |  18 +--
 tools/perf/ui/browsers/map.c                  |   4 +-
 tools/perf/util/annotate.c                    |  38 +++---
 tools/perf/util/auxtrace.c                    |   2 +-
 tools/perf/util/block-info.c                  |   4 +-
 tools/perf/util/bpf-event.c                   |   8 +-
 tools/perf/util/build-id.c                    |   2 +-
 tools/perf/util/callchain.c                   |  10 +-
 tools/perf/util/data-convert-json.c           |   4 +-
 tools/perf/util/db-export.c                   |   4 +-
 tools/perf/util/dlfilter.c                    |  21 ++--
 tools/perf/util/dso.c                         |   4 +-
 tools/perf/util/event.c                       |  14 +--
 tools/perf/util/evsel_fprintf.c               |   4 +-
 tools/perf/util/hist.c                        |  10 +-
 tools/perf/util/intel-pt.c                    |  48 +++----
 tools/perf/util/machine.c                     |  84 +++++++------
 tools/perf/util/map.c                         | 117 +++++++++---------
 tools/perf/util/map.h                         |  58 ++++++++-
 tools/perf/util/maps.c                        |  83 +++++++------
 tools/perf/util/probe-event.c                 |  44 +++----
 .../util/scripting-engines/trace-event-perl.c |   9 +-
 .../scripting-engines/trace-event-python.c    |  12 +-
 tools/perf/util/sort.c                        |  46 +++----
 tools/perf/util/symbol-elf.c                  |  39 +++---
 tools/perf/util/symbol.c                      |  96 +++++++-------
 tools/perf/util/symbol_fprintf.c              |   2 +-
 tools/perf/util/synthetic-events.c            |  28 ++---
 tools/perf/util/thread.c                      |  26 ++--
 tools/perf/util/unwind-libunwind-local.c      |  34 ++---
 tools/perf/util/unwind-libunwind.c            |   4 +-
 tools/perf/util/vdso.c                        |   2 +-
 49 files changed, 577 insertions(+), 489 deletions(-)
tools/perf/arch/s390/annotate/instructions.c +3 -1
index 0e136630659e..740f1a63bc04 100644
@@ -39,7 +39,9 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
 	target.addr = map__objdump_2mem(map, ops->target.addr);
 
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			     ) == ops->target.addr)
 		ops->target.sym = target.ms.sym;
 
 	return 0;
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index a54dea7c112f..497593be80f2 100644
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,
 		return -1;
 	}
 
-	stack_size = map->end - sp;
+	stack_size = map__end(map) - sp;
 	stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
 
 	memcpy(buf, (void *) sp, stack_size);
tools/perf/arch/x86/util/event.c +3 -3
index 7b6b0c98fb36..c790c682b76e 100644
@@ -57,9 +57,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
 
 		event->mmap.header.size = size;
 
-		event->mmap.start = map->start;
-		event->mmap.len   = map->end - map->start;
-		event->mmap.pgoff = map->pgoff;
+		event->mmap.start = map__start(map);
+		event->mmap.len   = map__size(map);
+		event->mmap.pgoff = map__pgoff(map);
 		event->mmap.pid   = machine->pid;
 
 		strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
tools/perf/builtin-annotate.c +4 -4
index 490bb9b8cf17..49d3ae36fd89 100644
@@ -199,7 +199,7 @@ static int process_branch_callback(struct evsel *evsel,
 		return 0;
 
 	if (a.map != NULL)
-		a.map->dso->hit = 1;
+		map__dso(a.map)->hit = 1;
 
 	hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
@@ -231,9 +231,9 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
 		 */
 		if (al->sym != NULL) {
 			rb_erase_cached(&al->sym->rb_node,
-				 &al->map->dso->symbols);
+					&map__dso(al->map)->symbols);
 			symbol__delete(al->sym);
-			dso__reset_find_symbol_cache(al->map->dso);
+			dso__reset_find_symbol_cache(map__dso(al->map));
 		}
 		return 0;
 	}
@@ -315,7 +315,7 @@ static void hists__find_annotations(struct hists *hists,
 		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
 		struct annotation *notes;
 
-		if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
+		if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
 			goto find_next;
 
 		if (ann->sym_hist_filter &&
tools/perf/builtin-inject.c +4 -4
index f7917c390e96..92a9dbc3d4cd 100644
@@ -600,10 +600,10 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
 	}
 
 	if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
-		if (!al.map->dso->hit) {
-			al.map->dso->hit = 1;
-			dso__inject_build_id(al.map->dso, tool, machine,
-					     sample->cpumode, al.map->flags);
+		if (!map__dso(al.map)->hit) {
+			map__dso(al.map)->hit = 1;
+			dso__inject_build_id(map__dso(al.map), tool, machine,
+					     sample->cpumode, map__flags(al.map));
 		}
 	}
 
tools/perf/builtin-kallsyms.c +4 -2
index c08ee81529e8..d940b60ce812 100644
@@ -36,8 +36,10 @@ static int __cmd_kallsyms(int argc, const char **argv)
 		}
 
 		printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
-			symbol->name, map->dso->short_name, map->dso->long_name,
-			map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
+			symbol->name, map__dso(map)->short_name,
+			map__dso(map)->long_name,
+			map__unmap_ip(map, symbol->start),
+			map__unmap_ip(map, symbol->end),
 			symbol->start, symbol->end);
 	}
 
tools/perf/builtin-kmem.c +2 -2
index 99d7ff9a8eff..d87d9c341a20 100644
@@ -410,7 +410,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
 		if (!caller) {
 			/* found */
 			if (node->ms.map)
-				addr = map__unmap_ip(node->ms.map, node->ip);
+				addr = map__dso_unmap_ip(node->ms.map, node->ip);
 			else
 				addr = node->ip;
 
@@ -1012,7 +1012,7 @@ static void __print_slab_result(struct rb_root *root,
 
 		if (sym != NULL)
 			snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
-				 addr - map->unmap_ip(map, sym->start));
+				 addr - map__unmap_ip(map, sym->start));
 		else
 			snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
 		printf(" %-34s |", buf);
tools/perf/builtin-mem.c +2 -2
index fcf65a59bea2..d18083f57303 100644
@@ -200,7 +200,7 @@ dump_raw_samples(struct perf_tool *tool,
 		goto out_put;
 
 	if (al.map != NULL)
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	field_sep = symbol_conf.field_sep;
 	if (field_sep) {
@@ -241,7 +241,7 @@ dump_raw_samples(struct perf_tool *tool,
 		symbol_conf.field_sep,
 		sample->data_src,
 		symbol_conf.field_sep,
-		al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+		al.map && map__dso(al.map) ? map__dso(al.map)->long_name : "???",
 		al.sym ? al.sym->name : "???");
 out_put:
 	addr_location__put(&al);
tools/perf/builtin-report.c +11 -9
index 57611ef725c3..9b92b2bbd7de 100644
@@ -304,7 +304,7 @@ static int process_sample_event(struct perf_tool *tool,
 	}
 
 	if (al.map != NULL)
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
 		hist__account_cycles(sample->branch_stack, &al, sample,
@@ -579,7 +579,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
 		return;
 
 	if (kernel_map == NULL ||
-	    (kernel_map->dso->hit &&
+	    (map__dso(kernel_map)->hit &&
 	     (kernel_kmap->ref_reloc_sym == NULL ||
 	      kernel_kmap->ref_reloc_sym->addr == 0))) {
 		const char *desc =
@@ -805,13 +805,15 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
 		struct map *map = rb_node->map;
 
 		printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
-				   indent, "", map->start, map->end,
-				   map->prot & PROT_READ ? 'r' : '-',
-				   map->prot & PROT_WRITE ? 'w' : '-',
-				   map->prot & PROT_EXEC ? 'x' : '-',
-				   map->flags & MAP_SHARED ? 's' : 'p',
-				   map->pgoff,
-				   map->dso->id.ino, map->dso->name);
+				   indent, "",
+				   map__start(map), map__end(map),
+				   map__prot(map) & PROT_READ ? 'r' : '-',
+				   map__prot(map) & PROT_WRITE ? 'w' : '-',
+				   map__prot(map) & PROT_EXEC ? 'x' : '-',
+				   map__flags(map) & MAP_SHARED ? 's' : 'p',
+				   map__pgoff(map),
+				   map__dso(map)->id.ino,
+				   map__dso(map)->name);
 	}
 
 	return printed;
tools/perf/builtin-script.c +13 -13
index abae8184e171..4edfce95e137 100644
@@ -972,12 +972,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
 		to   = entries[i].to;
 
 		if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
-		    !alf.map->dso->adjust_symbols)
-			from = map__map_ip(alf.map, from);
+		    !map__dso(alf.map)->adjust_symbols)
+			from = map__dso_map_ip(alf.map, from);
 
 		if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
-		    !alt.map->dso->adjust_symbols)
-			to = map__map_ip(alt.map, to);
+		    !map__dso(alt.map)->adjust_symbols)
+			to = map__dso_map_ip(alt.map, to);
 
 		printed += fprintf(fp, " 0x%"PRIx64, from);
 		if (PRINT_FIELD(DSO)) {
@@ -1039,11 +1039,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 		return 0;
 	}
 
-	if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
+	if (!thread__find_map(thread, *cpumode, start, &al) || !map__dso(al.map)) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
 	}
-	if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
+	if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
 	}
@@ -1051,11 +1051,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 	/* Load maps to ensure dso->is_64_bit has been updated */
 	map__load(al.map);
 
-	offset = al.map->map_ip(al.map, start);
-	len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
-				    end - start + MAXINSN);
+	offset = map__map_ip(al.map, start);
+	len = dso__data_read_offset(map__dso(al.map), machine, offset,
+				    (u8 *)buffer, end - start + MAXINSN);
 
-	*is64bit = al.map->dso->is_64_bit;
+	*is64bit = map__dso(al.map)->is_64_bit;
 	if (len <= 0)
 		pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
 			start, end);
@@ -1070,9 +1070,9 @@ static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srcc
 	int len;
 	char *srccode;
 
-	if (!map || !map->dso)
+	if (!map || !map__dso(map))
 		return 0;
-	srcfile = get_srcline_split(map->dso,
+	srcfile = get_srcline_split(map__dso(map),
 				    map__rip_2objdump(map, addr),
 				    &line);
 	if (!srcfile)
@@ -1164,7 +1164,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 	if (al.addr < al.sym->end)
 		off = al.addr - al.sym->start;
 	else
-		off = al.addr - al.map->start - al.sym->start;
+		off = al.addr - map__start(al.map) - al.sym->start;
 	printed += fprintf(fp, "\t%s", al.sym->name);
 	if (off)
 		printed += fprintf(fp, "%+d", off);
tools/perf/builtin-top.c +7 -5
index 1fc390f136dd..8db1df7bdabe 100644
@@ -127,8 +127,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
 	/*
 	 * We can't annotate with just /proc/kallsyms
 	 */
-	if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-	    !dso__is_kcore(map->dso)) {
+	if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+	    !dso__is_kcore(map__dso(map))) {
 		pr_err("Can't annotate %s: No vmlinux file was found in the "
 		       "path\n", sym->name);
 		sleep(1);
@@ -180,8 +180,9 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
 		    "Tools:  %s\n\n"
 		    "Not all samples will be on the annotation output.\n\n"
 		    "Please report to [email protected]\n",
-		    ip, map->dso->long_name, dso__symtab_origin(map->dso),
-		    map->start, map->end, sym->start, sym->end,
+		    ip, map__dso(map)->long_name,
+		    dso__symtab_origin(map__dso(map)),
+		    map__start(map), map__end(map), sym->start, sym->end,
 		    sym->binding == STB_GLOBAL ? 'g' :
 		    sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
 		    err ? "[unknown]" : uts.machine,
@@ -810,7 +811,8 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		    __map__is_kernel(al.map) && map__has_symbols(al.map)) {
 			if (symbol_conf.vmlinux_name) {
 				char serr[256];
-				dso__strerror_load(al.map->dso, serr, sizeof(serr));
+				dso__strerror_load(map__dso(al.map),
+						   serr, sizeof(serr));
 				ui__warning("The %s file can't be used: %s\n%s",
 					    symbol_conf.vmlinux_name, serr, msg);
 			} else {
tools/perf/builtin-trace.c +1 -1
index 32844d8a0ea5..0134f24da3e3 100644
@@ -2862,7 +2862,7 @@ static void print_location(FILE *f, struct perf_sample *sample,
 {
 
 	if ((verbose > 0 || print_dso) && al->map)
-		fprintf(f, "%s@", al->map->dso->long_name);
+		fprintf(f, "%s@", map__dso(al->map)->long_name);
 
 	if ((verbose > 0 || print_sym) && al->sym)
 		fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/scripts/python/Perf-Trace-Util/Context.c +4 -3
index b64013a87c54..b83b62d33945 100644
@@ -152,9 +152,10 @@ static PyObject *perf_sample_src(PyObject *obj, PyObject *args, bool get_srccode
 	map = c->al->map;
 	addr = c->al->addr;
 
-	if (map && map->dso)
-		srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+	if (map && map__dso(map)) {
+		srcfile = get_srcline_split(map__dso(map),
+					    map__rip_2objdump(map, addr), &line);
+	}
 	if (get_srccode) {
 		if (srcfile)
 			srccode = find_sourceline(srcfile, line, &len);
tools/perf/tests/code-reading.c +16 -16
index 6eafe36a8704..9cb7d3f577d7 100644
@@ -240,7 +240,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
 	pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-	if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
+	if (!thread__find_map(thread, cpumode, addr, &al) || !map__dso(al.map)) {
 		if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
 			pr_debug("Hypervisor address can not be resolved - skipping\n");
 			return 0;
@@ -250,10 +250,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		return -1;
 	}
 
-	pr_debug("File is: %s\n", al.map->dso->long_name);
+	pr_debug("File is: %s\n", map__dso(al.map)->long_name);
 
-	if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-	    !dso__is_kcore(al.map->dso)) {
+	if (map__dso(al.map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+	    !dso__is_kcore(map__dso(al.map))) {
 		pr_debug("Unexpected kernel address - skipping\n");
 		return 0;
 	}
@@ -264,11 +264,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		len = BUFSZ;
 
 	/* Do not go off the map */
-	if (addr + len > al.map->end)
-		len = al.map->end - addr;
+	if (addr + len > map__end(al.map))
+		len = map__end(al.map) - addr;
 
 	/* Read the object code using perf */
-	ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
+	ret_len = dso__data_read_offset(map__dso(al.map), maps__machine(thread->maps),
 					al.addr, buf1, len);
 	if (ret_len != len) {
 		pr_debug("dso__data_read_offset failed\n");
@@ -283,11 +283,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		return -1;
 
 	/* objdump struggles with kcore - try each map only once */
-	if (dso__is_kcore(al.map->dso)) {
+	if (dso__is_kcore(map__dso(al.map))) {
 		size_t d;
 
 		for (d = 0; d < state->done_cnt; d++) {
-			if (state->done[d] == al.map->start) {
+			if (state->done[d] == map__start(al.map)) {
 				pr_debug("kcore map tested already");
 				pr_debug(" - skipping\n");
 				return 0;
@@ -297,12 +297,12 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			pr_debug("Too many kcore maps - skipping\n");
 			return 0;
 		}
-		state->done[state->done_cnt++] = al.map->start;
+		state->done[state->done_cnt++] = map__start(al.map);
 	}
 
-	objdump_name = al.map->dso->long_name;
-	if (dso__needs_decompress(al.map->dso)) {
-		if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+	objdump_name = map__dso(al.map)->long_name;
+	if (dso__needs_decompress(map__dso(al.map))) {
+		if (dso__decompress_kmodule_path(map__dso(al.map), objdump_name,
 						 decomp_name,
 						 sizeof(decomp_name)) < 0) {
 			pr_debug("decompression failed\n");
@@ -330,7 +330,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			len -= ret;
 			if (len) {
 				pr_debug("Reducing len to %zu\n", len);
-			} else if (dso__is_kcore(al.map->dso)) {
+			} else if (dso__is_kcore(map__dso(al.map))) {
 				/*
 				 * objdump cannot handle very large segments
 				 * that may be found in kcore.
@@ -588,8 +588,8 @@ static int do_test_code_reading(bool try_kcore)
 		pr_debug("map__load failed\n");
 		goto out_err;
 	}
-	have_vmlinux = dso__is_vmlinux(map->dso);
-	have_kcore = dso__is_kcore(map->dso);
+	have_vmlinux = dso__is_vmlinux(map__dso(map));
+	have_kcore = dso__is_kcore(map__dso(map));
 
 	/* 2nd time through we just try kcore */
 	if (try_kcore && !have_kcore)
tools/perf/tests/hists_common.c +2 -2
index 6f34d08b84e5..40eccc659767 100644
@@ -181,7 +181,7 @@ void print_hists_in(struct hists *hists)
 		if (!he->filtered) {
 			pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
 				i, thread__comm_str(he->thread),
-				he->ms.map->dso->short_name,
+				map__dso(he->ms.map)->short_name,
 				he->ms.sym->name, he->stat.period);
 		}
 
@@ -208,7 +208,7 @@ void print_hists_out(struct hists *hists)
 		if (!he->filtered) {
 			pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
 				i, thread__comm_str(he->thread), he->thread->tid,
-				he->ms.map->dso->short_name,
+				map__dso(he->ms.map)->short_name,
 				he->ms.sym->name, he->stat.period,
 				he->stat_acc ? he->stat_acc->period : 0);
 		}
tools/perf/tests/vmlinux-kallsyms.c +19 -16
index 11a230ee5894..5afab21455f1 100644
@@ -13,7 +13,7 @@
 #include "debug.h"
 #include "machine.h"
 
-#define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
+#define UM(x) map__unmap_ip(kallsyms_map, (x))
 
 static bool is_ignored_symbol(const char *name, char type)
 {
@@ -216,8 +216,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 		if (sym->start == sym->end)
 			continue;
 
-		mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
-		mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
+		mem_start = map__unmap_ip(vmlinux_map, sym->start);
+		mem_end = map__unmap_ip(vmlinux_map, sym->end);
 
 		first_pair = machine__find_kernel_symbol(&kallsyms, mem_start, NULL);
 		pair = first_pair;
@@ -262,7 +262,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 
 				continue;
 			}
-		} else if (mem_start == kallsyms.vmlinux_map->end) {
+		} else if (mem_start == map__end(kallsyms.vmlinux_map)) {
 			/*
 			 * Ignore aliases to _etext, i.e. to the end of the kernel text area,
 			 * such as __indirect_thunk_end.
@@ -294,9 +294,10 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 		 * so use the short name, less descriptive but the same ("[kernel]" in
 		 * both cases.
 		 */
-		struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
-								map->dso->short_name :
-								map->dso->name));
+		struct map *pair = maps__find_by_name(kallsyms.kmaps,
+						map__dso(map)->kernel
+						? map__dso(map)->short_name
+						: map__dso(map)->name);
 		if (pair) {
 			pair->priv = 1;
 		} else {
@@ -313,25 +314,27 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 	maps__for_each_entry(maps, rb_node) {
 		struct map *pair, *map = rb_node->map;
 
-		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
-		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
+		mem_start = map__unmap_ip(vmlinux_map, map__start(map));
+		mem_end = map__unmap_ip(vmlinux_map, map__end(map));
 
 		pair = maps__find(kallsyms.kmaps, mem_start);
-		if (pair == NULL || pair->priv)
+		if (pair == NULL || map__priv(pair))
 			continue;
 
-		if (pair->start == mem_start) {
+		if (map__start(pair) == mem_start) {
 			if (!header_printed) {
 				pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
 				header_printed = true;
 			}
 
 			pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
-				map->start, map->end, map->pgoff, map->dso->name);
-			if (mem_end != pair->end)
+				map__start(map), map__end(map),
+				map__pgoff(map), map__dso(map)->name);
+			if (mem_end != map__end(pair))
 				pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
-					pair->start, pair->end, pair->pgoff);
-			pr_info(" %s\n", pair->dso->name);
+					map__start(pair), map__end(pair),
+					map__pgoff(pair));
+			pr_info(" %s\n", map__dso(pair)->name);
 			pair->priv = 1;
 		}
 	}
@@ -343,7 +346,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 	maps__for_each_entry(maps, rb_node) {
 		struct map *map = rb_node->map;
 
-		if (!map->priv) {
+		if (!map__priv(map)) {
 			if (!header_printed) {
 				pr_info("WARN: Maps only in kallsyms:\n");
 				header_printed = true;
tools/perf/ui/browsers/annotate.c +4 -3
index 44ba900828f6..7d51d92302dc 100644
@@ -446,7 +446,8 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 static int sym_title(struct symbol *sym, struct map *map, char *title,
 		     size_t sz, int percent_type)
 {
-	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+			map__dso(map)->long_name,
 			percent_type_str(percent_type));
 }
 
@@ -971,14 +972,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
 	if (sym == NULL)
 		return -1;
 
-	if (ms->map->dso->annotate_warned)
+	if (map__dso(ms->map)->annotate_warned)
 		return -1;
 
 	if (not_annotated) {
 		err = symbol__annotate2(ms, evsel, opts, &browser.arch);
 		if (err) {
 			char msg[BUFSIZ];
-			ms->map->dso->annotate_warned = true;
+			map__dso(ms->map)->annotate_warned = true;
 			symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
 			ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
 			goto out_free_offsets;
tools/perf/ui/browsers/hists.c +11 -7
index 572ff38ceb0f..2241447e9bfb 100644
@@ -2487,7 +2487,7 @@ static struct symbol *symbol__new_unresolved(u64 addr, struct map *map)
 			return NULL;
 		}
 
-		dso__insert_symbol(map->dso, sym);
+		dso__insert_symbol(map__dso(map), sym);
 	}
 
 	return sym;
@@ -2499,7 +2499,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
 		 struct map_symbol *ms,
 		 u64 addr)
 {
-	if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
+	if (!ms->map || !map__dso(ms->map) || map__dso(ms->map)->annotate_warned)
 		return 0;
 
 	if (!ms->sym)
@@ -2590,8 +2590,10 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map
 		ui_helpline__pop();
 	} else {
 		ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
-				   __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
-		browser->hists->dso_filter = map->dso;
+				   __map__is_kernel(map)
+				   ? "the Kernel"
+				   : map__dso(map)->short_name);
+		browser->hists->dso_filter = map__dso(map);
 		perf_hpp__set_elide(HISTC_DSO, true);
 		pstack__push(browser->pstack, &browser->hists->dso_filter);
 	}
@@ -2616,7 +2618,9 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,
 
 	if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
 		     browser->hists->dso_filter ? "out of" : "into",
-		     __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
+		     __map__is_kernel(map)
+		     ? "the Kernel"
+		     : map__dso(map)->short_name) < 0)
 		return 0;
 
 	act->ms.map = map;
@@ -3091,8 +3095,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
 
 			if (!browser->selection ||
 			    !browser->selection->map ||
-			    !browser->selection->map->dso ||
-			    browser->selection->map->dso->annotate_warned) {
+			    !map__dso(browser->selection->map) ||
+			    map__dso(browser->selection->map)->annotate_warned) {
 				continue;
 			}
 
tools/perf/ui/browsers/map.c +2 -2
index 3d49b916c9e4..3d1b958d8832 100644
@@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser)
 {
 	int key;
 
-	if (ui_browser__show(&browser->b, browser->map->dso->long_name,
+	if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name,
 			     "Press ESC to exit, %s / to search",
 			     verbose > 0 ? "" : "restart with -v to use") < 0)
 		return -1;
@@ -106,7 +106,7 @@ int map__browse(struct map *map)
 {
 	struct map_browser mb = {
 		.b = {
-			.entries = &map->dso->symbols,
+			.entries = &map__dso(map)->symbols,
 			.refresh = ui_browser__rb_tree_refresh,
 			.seek	 = ui_browser__rb_tree_seek,
 			.write	 = map_browser__write,
tools/perf/util/annotate.c +21 -17
index 01900689dc00..3a7433d3e48a 100644
@@ -280,7 +280,9 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	target.addr = map__objdump_2mem(map, ops->target.addr);
 
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			      ) == ops->target.addr)
 		ops->target.sym = target.ms.sym;
 
 	return 0;
@@ -384,8 +386,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	}
 
 	target.addr = map__objdump_2mem(map, ops->target.addr);
-	start = map->unmap_ip(map, sym->start),
-	end = map->unmap_ip(map, sym->end);
+	start = map__unmap_ip(map, sym->start),
+	end = map__unmap_ip(map, sym->end);
 
 	ops->target.outside = target.addr < start || target.addr > end;
 
@@ -408,7 +410,9 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	 * the symbol searching and disassembly should be done.
 	 */
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			      ) == ops->target.addr)
 		ops->target.sym = target.ms.sym;
 
 	if (!ops->target.outside) {
@@ -889,7 +893,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms,
 	unsigned offset;
 	struct sym_hist *h;
 
-	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, ms->map->unmap_ip(ms->map, addr));
+	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map__unmap_ip(ms->map, addr));
 
 	if ((addr < sym->start || addr >= sym->end) &&
 	    (addr != sym->end || sym->start != sym->end)) {
@@ -1016,13 +1020,13 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
 	if (start &&
 		(start->ms.sym == ams->ms.sym ||
 		 (ams->ms.sym &&
-		   start->addr == ams->ms.sym->start + ams->ms.map->start)))
+		  start->addr == ams->ms.sym->start + map__start(ams->ms.map))))
 		saddr = start->al_addr;
 	if (saddr == 0)
 		pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n",
 			ams->addr,
 			start ? start->addr : 0,
-			ams->ms.sym ? ams->ms.sym->start + ams->ms.map->start : 0,
+			ams->ms.sym ? ams->ms.sym->start + map__start(ams->ms.map) : 0,
 			saddr);
 	err = symbol__account_cycles(ams->al_addr, saddr, ams->ms.sym, cycles);
 	if (err)
@@ -1593,7 +1597,7 @@ static void delete_last_nop(struct symbol *sym)
 
 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 
 	BUG_ON(buflen == 0);
 
@@ -1723,7 +1727,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
 	struct map *map = args->ms.map;
 	struct perf_bpil *info_linear;
 	struct disassemble_info info;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	int pc = 0, count, sub_id;
 	struct btf *btf = NULL;
 	char tpath[PATH_MAX];
@@ -1946,7 +1950,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 {
 	struct annotation_options *opts = args->options;
 	struct map *map = args->ms.map;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	char *command;
 	FILE *file;
 	char symfs_filename[PATH_MAX];
@@ -1973,8 +1977,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 		return err;
 
 	pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
-		 symfs_filename, sym->name, map->unmap_ip(map, sym->start),
-		 map->unmap_ip(map, sym->end));
+		 symfs_filename, sym->name, map__unmap_ip(map, sym->start),
+		 map__unmap_ip(map, sym->end));
 
 	pr_debug("annotating [%p] %30s : [%p] %30s\n",
 		 dso, dso->long_name, sym, sym->name);
@@ -2386,7 +2390,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
 {
 	struct map *map = ms->map;
 	struct symbol *sym = ms->sym;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	char *filename;
 	const char *d_filename;
 	const char *evsel_name = evsel__name(evsel);
@@ -2569,7 +2573,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
 	}
 
 	fprintf(fp, "%s() %s\nEvent: %s\n\n",
-		ms->sym->name, ms->map->dso->long_name, ev_name);
+		ms->sym->name, map__dso(ms->map)->long_name, ev_name);
 	symbol__annotate_fprintf2(ms->sym, fp, opts);
 
 	fclose(fp);
@@ -2781,7 +2785,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		if (percent_max <= 0.5)
 			continue;
 
-		al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
+		al->path = get_srcline(map__dso(map), notes->start + al->offset, NULL,
 				       false, true, notes->start + al->offset);
 		insert_source_line(&tmp_root, al, opts);
 	}
@@ -2800,7 +2804,7 @@ static void symbol__calc_lines(struct map_symbol *ms, struct rb_root *root,
 int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 			  struct annotation_options *opts)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 	struct symbol *sym = ms->sym;
 	struct rb_root source_line = RB_ROOT;
 	struct hists *hists = evsel__hists(evsel);
@@ -2836,7 +2840,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel,
 			 struct annotation_options *opts)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 	struct symbol *sym = ms->sym;
 	struct rb_root source_line = RB_ROOT;
 	int err;
tools/perf/util/auxtrace.c +1 -1
index 825336304a37..2e864c9bdef3 100644
@@ -2478,7 +2478,7 @@ static struct dso *load_dso(const char *name)
 	if (map__load(map) < 0)
 		pr_err("File '%s' not found or has no symbols.\n", name);
 
-	dso = dso__get(map->dso);
+	dso = dso__get(map__dso(map));
 
 	map__put(map);
 
tools/perf/util/block-info.c +2 -2
index 5ecd4f401f32..16a7b4adcf18 100644
@@ -317,9 +317,9 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 	struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
 	struct map *map = he->ms.map;
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
-				 map->dso->short_name);
+				 map__dso(map)->short_name);
 	}
 
 	return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
tools/perf/util/bpf-event.c +4 -4
index 33257b594a71..5717933be116 100644
@@ -95,10 +95,10 @@ static int machine__process_bpf_event_load(struct machine *machine,
 		struct map *map = maps__find(machine__kernel_maps(machine), addr);
 
 		if (map) {
-			map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
-			map->dso->bpf_prog.id = id;
-			map->dso->bpf_prog.sub_id = i;
-			map->dso->bpf_prog.env = env;
+			map__dso(map)->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+			map__dso(map)->bpf_prog.id = id;
+			map__dso(map)->bpf_prog.sub_id = i;
+			map__dso(map)->bpf_prog.env = env;
 		}
 	}
 	return 0;
tools/perf/util/build-id.c +1 -1
index 7a5821c87f94..274b705dd941 100644
@@ -59,7 +59,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
 	}
 
 	if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	thread__put(thread);
 	return 0;
tools/perf/util/callchain.c +5 -5
index 61bb3fb2107a..a8cfd31a3ff0 100644
@@ -695,8 +695,8 @@ static enum match_result match_chain_strings(const char *left,
 static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
 						   struct map *right_map, u64 right_ip)
 {
-	struct dso *left_dso = left_map ? left_map->dso : NULL;
-	struct dso *right_dso = right_map ? right_map->dso : NULL;
+	struct dso *left_dso = left_map ? map__dso(left_map) : NULL;
+	struct dso *right_dso = right_map ? map__dso(right_map) : NULL;
 
 	if (left_dso != right_dso)
 		return left_dso < right_dso ? MATCH_LT : MATCH_GT;
@@ -1167,9 +1167,9 @@ char *callchain_list__sym_name(struct callchain_list *cl,
 
 	if (show_dso)
 		scnprintf(bf + printed, bfsize - printed, " %s",
-			  cl->ms.map ?
-			  cl->ms.map->dso->short_name :
-			  "unknown");
+			  cl->ms.map
+			  ? map__dso(cl->ms.map)->short_name
+			  : "unknown");
 
 	return bf;
 }
tools/perf/util/data-convert-json.c +2 -2
index f1ab6edba446..9c83228bb9f1 100644
@@ -127,8 +127,8 @@ static void output_sample_callchain_entry(struct perf_tool *tool,
 		fputc(',', out);
 		output_json_key_string(out, false, 5, "symbol", al->sym->name);
 
-		if (al->map && al->map->dso) {
-			const char *dso = al->map->dso->short_name;
+		if (al->map && map__dso(al->map)) {
+			const char *dso = map__dso(al->map)->short_name;
 
 			if (dso && strlen(dso) > 0) {
 				fputc(',', out);
tools/perf/util/db-export.c +2 -2
index 1cfcfdd3cf52..84c970c11794 100644
@@ -179,7 +179,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
 	int err;
 
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		err = db_export__dso(dbe, dso, maps__machine(al->maps));
 		if (err)
@@ -255,7 +255,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
 		al.addr = node->ip;
 
 		if (al.map && !al.sym)
-			al.sym = dso__find_symbol(al.map->dso, al.addr);
+			al.sym = dso__find_symbol(map__dso(al.map), al.addr);
 
 		db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
tools/perf/util/dlfilter.c +11 -10
index d59462af15f1..f1d9dd7065e6 100644
@@ -29,7 +29,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 
 	d_al->size = sizeof(*d_al);
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		if (symbol_conf.show_kernel_path && dso->long_name)
 			d_al->dso = dso->long_name;
@@ -51,7 +51,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 		if (al->addr < sym->end)
 			d_al->symoff = al->addr - sym->start;
 		else
-			d_al->symoff = al->addr - al->map->start - sym->start;
+			d_al->symoff = al->addr - map__start(al->map) - sym->start;
 		d_al->sym_binding = sym->binding;
 	} else {
 		d_al->sym = NULL;
@@ -232,9 +232,10 @@ static const char *dlfilter__srcline(void *ctx, __u32 *line_no)
 	map = al->map;
 	addr = al->addr;
 
-	if (map && map->dso)
-		srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+	if (map && map__dso(map)) {
+		srcfile = get_srcline_split(map__dso(map),
+					    map__rip_2objdump(map, addr), &line);
+	}
 	*line_no = line;
 	return srcfile;
 }
@@ -266,7 +267,7 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
 	map = al->map;
 
-	if (map && ip >= map->start && ip < map->end &&
+	if (map && ip >= map__start(map) && ip < map__end(map) &&
 	    machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
 		goto have_map;
 
@@ -276,10 +277,10 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
 	map = a.map;
 have_map:
-	offset = map->map_ip(map, ip);
-	if (ip + len >= map->end)
-		len = map->end - ip;
-	return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
+	offset = map__map_ip(map, ip);
+	if (ip + len >= map__end(map))
+		len = map__end(map) - ip;
+	return dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
 }
 
 static const struct perf_dlfilter_fns perf_dlfilter_fns = {
tools/perf/util/dso.c +2 -2
index b2f570adba35..1115bc51a261 100644
@@ -1109,7 +1109,7 @@ ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
 			    struct machine *machine, u64 addr,
 			    u8 *data, ssize_t size)
 {
-	u64 offset = map->map_ip(map, addr);
+	u64 offset = map__map_ip(map, addr);
 	return dso__data_read_offset(dso, machine, offset, data, size);
 }
 
@@ -1149,7 +1149,7 @@ ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
 				   struct machine *machine, u64 addr,
 				   const u8 *data, ssize_t size)
 {
-	u64 offset = map->map_ip(map, addr);
+	u64 offset = map__map_ip(map, addr);
 	return dso__data_write_cache_offs(dso, machine, offset, data, size);
 }
 
tools/perf/util/event.c +7 -7
index 40a3b1a35613..54a1d4df5f70 100644
@@ -486,7 +486,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
 
 		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.addr = map__map_ip(al.map, tp->addr);
 			al.sym = map__find_symbol(al.map, al.addr);
 			if (al.sym)
 				ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
@@ -621,7 +621,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		 */
 		if (load_map)
 			map__load(al->map);
-		al->addr = al->map->map_ip(al->map, al->addr);
+		al->addr = map__map_ip(al->map, al->addr);
 	}
 
 	return al->map;
@@ -692,8 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
 	thread__find_map(thread, sample->cpumode, sample->ip, al);
 	dump_printf(" ...... dso: %s\n",
-		    al->map ? al->map->dso->long_name :
-			al->level == 'H' ? "[hypervisor]" : "<not found>");
+		    al->map ? map__dso(al->map)->long_name
+			    : al->level == 'H' ? "[hypervisor]" : "<not found>");
 
 	if (thread__is_filtered(thread))
 		al->filtered |= (1 << HIST_FILTER__THREAD);
@@ -711,7 +711,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 	}
 
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		if (symbol_conf.dso_list &&
 		    (!dso || !(strlist__has_entry(symbol_conf.dso_list,
@@ -738,12 +738,12 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 		}
 		if (!ret && al->sym) {
 			snprintf(al_addr_str, sz, "0x%"PRIx64,
-				al->map->unmap_ip(al->map, al->sym->start));
+				 map__unmap_ip(al->map, al->sym->start));
 			ret = strlist__has_entry(symbol_conf.sym_list,
 						al_addr_str);
 		}
 		if (!ret && symbol_conf.addr_list && al->map) {
-			unsigned long addr = al->map->unmap_ip(al->map, al->addr);
+			unsigned long addr = map__unmap_ip(al->map, al->addr);
 
 			ret = intlist__has_entry(symbol_conf.addr_list, addr);
 			if (!ret && symbol_conf.addr_range) {
tools/perf/util/evsel_fprintf.c +2 -2
index 8c2ea8001329..ac6fef9d8906 100644
@@ -146,11 +146,11 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
 				printed += fprintf(fp, " <-");
 
 			if (map)
-				addr = map->map_ip(map, node->ip);
+				addr = map__map_ip(map, node->ip);
 
 			if (print_ip) {
 				/* Show binary offset for userspace addr */
-				if (map && !map->dso->kernel)
+				if (map && !map__dso(map)->kernel)
 					printed += fprintf(fp, "%c%16" PRIx64, s, addr);
 				else
 					printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
tools/perf/util/hist.c +5 -5
index 78f9fbb925a7..f19ac6eb4775 100644
@@ -105,7 +105,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		hists__set_col_len(hists, HISTC_THREAD, len + 8);
 
 	if (h->ms.map) {
-		len = dso__name_len(h->ms.map->dso);
+		len = dso__name_len(map__dso(h->ms.map));
 		hists__new_col_len(hists, HISTC_DSO, len);
 	}
 
@@ -119,7 +119,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
-			symlen = dso__name_len(h->branch_info->from.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->branch_info->from.ms.map));
 			hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
 		} else {
 			symlen = unresolved_col_width + 4 + 2;
@@ -133,7 +133,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
-			symlen = dso__name_len(h->branch_info->to.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->branch_info->to.ms.map));
 			hists__new_col_len(hists, HISTC_DSO_TO, symlen);
 		} else {
 			symlen = unresolved_col_width + 4 + 2;
@@ -177,7 +177,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		}
 
 		if (h->mem_info->daddr.ms.map) {
-			symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->mem_info->daddr.ms.map));
 			hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
 					   symlen);
 		} else {
@@ -2096,7 +2096,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
 				       struct hist_entry *he)
 {
 	if (hists->dso_filter != NULL &&
-	    (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
+	    (he->ms.map == NULL || map__dso(he->ms.map) != hists->dso_filter)) {
 		he->filtered |= (1 << HIST_FILTER__DSO);
 		return true;
 	}
tools/perf/util/intel-pt.c +24 -24
index e8613cbda331..c88f112c0a06 100644
@@ -731,20 +731,20 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	}
 
 	while (1) {
-		if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
+		if (!thread__find_map(thread, cpumode, *ip, &al) || !map__dso(al.map))
 			return -EINVAL;
 
-		if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-		    dso__data_status_seen(al.map->dso,
+		if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR &&
+		    dso__data_status_seen(map__dso(al.map),
 					  DSO_DATA_STATUS_SEEN_ITRACE))
 			return -ENOENT;
 
-		offset = al.map->map_ip(al.map, *ip);
+		offset = map__map_ip(al.map, *ip);
 
 		if (!to_ip && one_map) {
 			struct intel_pt_cache_entry *e;
 
-			e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+			e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
 			if (e &&
 			    (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) {
 				*insn_cnt_ptr = e->insn_cnt;
@@ -766,10 +766,10 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 		/* Load maps to ensure dso->is_64_bit has been updated */
 		map__load(al.map);
 
-		x86_64 = al.map->dso->is_64_bit;
+		x86_64 = map__dso(al.map)->is_64_bit;
 
 		while (1) {
-			len = dso__data_read_offset(al.map->dso, machine,
+			len = dso__data_read_offset(map__dso(al.map), machine,
 						    offset, buf,
 						    INTEL_PT_INSN_BUF_SZ);
 			if (len <= 0)
@@ -795,7 +795,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 				goto out_no_cache;
 			}
 
-			if (*ip >= al.map->end)
+			if (*ip >= map__end(al.map))
 				break;
 
 			offset += intel_pt_insn->length;
@@ -815,13 +815,13 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	if (to_ip) {
 		struct intel_pt_cache_entry *e;
 
-		e = intel_pt_cache_lookup(al.map->dso, machine, start_offset);
+		e = intel_pt_cache_lookup(map__dso(al.map), machine, start_offset);
 		if (e)
 			return 0;
 	}
 
 	/* Ignore cache errors */
-	intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt,
+	intel_pt_cache_add(map__dso(al.map), machine, start_offset, insn_cnt,
 			   *ip - start_ip, intel_pt_insn);
 
 	return 0;
@@ -892,13 +892,13 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
 	if (!thread)
 		return -EINVAL;
 
-	if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
+	if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map))
 		return -EINVAL;
 
-	offset = al.map->map_ip(al.map, ip);
+	offset = map__map_ip(al.map, ip);
 
 	return intel_pt_match_pgd_ip(ptq->pt, ip, offset,
-				     al.map->dso->long_name);
+				     map__dso(al.map)->long_name);
 }
 
 static bool intel_pt_pgd_ip(uint64_t ip, void *data)
@@ -2406,13 +2406,13 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 	if (map__load(map))
 		return 0;
 
-	start = dso__first_symbol(map->dso);
+	start = dso__first_symbol(map__dso(map));
 
 	for (sym = start; sym; sym = dso__next_symbol(sym)) {
 		if (sym->binding == STB_GLOBAL &&
 		    !strcmp(sym->name, "__switch_to")) {
-			ip = map->unmap_ip(map, sym->start);
-			if (ip >= map->start && ip < map->end) {
+			ip = map__unmap_ip(map, sym->start);
+			if (ip >= map__start(map) && ip < map__end(map)) {
 				switch_ip = ip;
 				break;
 			}
@@ -2429,8 +2429,8 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 
 	for (sym = start; sym; sym = dso__next_symbol(sym)) {
 		if (!strcmp(sym->name, ptss)) {
-			ip = map->unmap_ip(map, sym->start);
-			if (ip >= map->start && ip < map->end) {
+			ip = map__unmap_ip(map, sym->start);
+			if (ip >= map__start(map) && ip < map__end(map)) {
 				*ptss_ip = ip;
 				break;
 			}
@@ -2965,7 +2965,7 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt,
 static int intel_pt_find_map(struct thread *thread, u8 cpumode, u64 addr,
 			     struct addr_location *al)
 {
-	if (!al->map || addr < al->map->start || addr >= al->map->end) {
+	if (!al->map || addr < map__start(al->map) || addr >= map__end(al->map)) {
 		if (!thread__find_map(thread, cpumode, addr, al))
 			return -1;
 	}
@@ -2996,12 +2996,12 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
 			continue;
 		}
 
-		if (!al.map->dso || !al.map->dso->auxtrace_cache)
+		if (!map__dso(al.map) || !map__dso(al.map)->auxtrace_cache)
 			continue;
 
-		offset = al.map->map_ip(al.map, addr);
+		offset = map__map_ip(al.map, addr);
 
-		e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+		e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
 		if (!e)
 			continue;
 
@@ -3014,9 +3014,9 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
 			if (e->branch != INTEL_PT_BR_NO_BRANCH)
 				return 0;
 		} else {
-			intel_pt_cache_invalidate(al.map->dso, machine, offset);
+			intel_pt_cache_invalidate(map__dso(al.map), machine, offset);
 			intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n",
-				     al.map->dso->long_name, addr);
+				     map__dso(al.map)->long_name, addr);
 		}
 	}
 
tools/perf/util/machine.c +44 -40
index 88279008e761..940fb2a50dfd 100644
@@ -47,7 +47,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
 
 static struct dso *machine__kernel_dso(struct machine *machine)
 {
-	return machine->vmlinux_map->dso;
+	return map__dso(machine->vmlinux_map);
 }
 
 static void dsos__init(struct dsos *dsos)
@@ -842,9 +842,10 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
 	if (map != machine->vmlinux_map)
 		maps__remove(machine__kernel_maps(machine), map);
 	else {
-		sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+		sym = dso__find_symbol(map__dso(map),
+				map__map_ip(map, map__start(map)));
 		if (sym)
-			dso__delete_symbol(map->dso, sym);
+			dso__delete_symbol(map__dso(map), sym);
 	}
 
 	return 0;
@@ -880,7 +881,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
 		return 0;
 	}
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
 		int ret;
 
@@ -889,7 +890,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
 		 * must be done prior to using kernel maps.
 		 */
 		map__load(map);
-		ret = dso__data_write_cache_addr(map->dso, map, machine,
+		ret = dso__data_write_cache_addr(map__dso(map), map, machine,
 						 event->text_poke.addr,
 						 new_bytes,
 						 event->text_poke.new_len);
@@ -931,6 +932,7 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
 	/* If maps__insert failed, return NULL. */
 	if (err)
 		map = NULL;
+
 out:
 	/* put the dso here, corresponding to  machine__findnew_module_dso */
 	dso__put(dso);
@@ -1118,7 +1120,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
 	if (!err) {
 		pr_debug2("Added extra kernel map %s %" PRIx64 "-%" PRIx64 "\n",
-			kmap->name, map->start, map->end);
+			kmap->name, map__start(map), map__end(map));
 	}
 
 	map__put(map);
@@ -1178,9 +1180,9 @@ int machine__map_x86_64_entry_trampolines(struct machine *machine,
 		if (!kmap || !is_entry_trampoline(kmap->name))
 			continue;
 
-		dest_map = maps__find(kmaps, map->pgoff);
+		dest_map = maps__find(kmaps, map__pgoff(map));
 		if (dest_map != map)
-			map->pgoff = dest_map->map_ip(dest_map, map->pgoff);
+			map->pgoff = map__map_ip(dest_map, map__pgoff(map));
 		found = true;
 	}
 	if (found || machine->trampolines_mapped)
@@ -1230,7 +1232,8 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 	if (machine->vmlinux_map == NULL)
 		return -ENOMEM;
 
-	machine->vmlinux_map->map_ip = machine->vmlinux_map->unmap_ip = identity__map_ip;
+	machine->vmlinux_map->map_ip = map__identity_ip;
+	machine->vmlinux_map->unmap_ip = map__identity_ip;
 	return maps__insert(machine__kernel_maps(machine), machine->vmlinux_map);
 }
 
@@ -1329,10 +1332,10 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 int machine__load_kallsyms(struct machine *machine, const char *filename)
 {
 	struct map *map = machine__kernel_map(machine);
-	int ret = __dso__load_kallsyms(map->dso, filename, map, true);
+	int ret = __dso__load_kallsyms(map__dso(map), filename, map, true);
 
 	if (ret > 0) {
-		dso__set_loaded(map->dso);
+		dso__set_loaded(map__dso(map));
 		/*
 		 * Since /proc/kallsyms will have multiple sessions for the
 		 * kernel, with modules between them, fixup the end of all
@@ -1347,10 +1350,10 @@ int machine__load_kallsyms(struct machine *machine, const char *filename)
 int machine__load_vmlinux_path(struct machine *machine)
 {
 	struct map *map = machine__kernel_map(machine);
-	int ret = dso__load_vmlinux_path(map->dso, map);
+	int ret = dso__load_vmlinux_path(map__dso(map), map);
 
 	if (ret > 0)
-		dso__set_loaded(map->dso);
+		dso__set_loaded(map__dso(map));
 
 	return ret;
 }
@@ -1401,16 +1404,16 @@ static int maps__set_module_path(struct maps *maps, const char *path, struct kmo
 	if (long_name == NULL)
 		return -ENOMEM;
 
-	dso__set_long_name(map->dso, long_name, true);
-	dso__kernel_module_get_build_id(map->dso, "");
+	dso__set_long_name(map__dso(map), long_name, true);
+	dso__kernel_module_get_build_id(map__dso(map), "");
 
 	/*
 	 * Full name could reveal us kmod compression, so
 	 * we need to update the symtab_type if needed.
 	 */
-	if (m->comp && is_kmod_dso(map->dso)) {
-		map->dso->symtab_type++;
-		map->dso->comp = m->comp;
+	if (m->comp && is_kmod_dso(map__dso(map))) {
+		map__dso(map)->symtab_type++;
+		map__dso(map)->comp = m->comp;
 	}
 
 	return 0;
@@ -1509,8 +1512,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
 		return -1;
 	map->end = start + size;
 
-	dso__kernel_module_get_build_id(map->dso, machine->root_dir);
-
+	dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
 	return 0;
 }
 
@@ -1619,7 +1621,7 @@ int machine__create_kernel_maps(struct machine *machine)
 		struct map_rb_node *next = map_rb_node__next(rb_node);
 
 		if (next)
-			machine__set_kernel_mmap(machine, start, next->map->start);
+			machine__set_kernel_mmap(machine, start, map__start(next->map));
 	}
 
 out_put:
@@ -1683,10 +1685,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
 		if (map == NULL)
 			goto out_problem;
 
-		map->end = map->start + xm->end - xm->start;
+		map->end = map__start(map) + xm->end - xm->start;
 
 		if (build_id__is_defined(bid))
-			dso__set_build_id(map->dso, bid);
+			dso__set_build_id(map__dso(map), bid);
 
 	} else if (is_kernel_mmap) {
 		const char *symbol_name = (xm->name + strlen(machine->mmap_name));
@@ -2148,14 +2150,14 @@ static char *callchain_srcline(struct map_symbol *ms, u64 ip)
 	if (!map || callchain_param.key == CCKEY_FUNCTION)
 		return srcline;
 
-	srcline = srcline__tree_find(&map->dso->srclines, ip);
+	srcline = srcline__tree_find(&map__dso(map)->srclines, ip);
 	if (!srcline) {
 		bool show_sym = false;
 		bool show_addr = callchain_param.key == CCKEY_ADDRESS;
 
-		srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
+		srcline = get_srcline(map__dso(map), map__rip_2objdump(map, ip),
 				      ms->sym, show_sym, show_addr, ip);
-		srcline__tree_insert(&map->dso->srclines, ip, srcline);
+		srcline__tree_insert(&map__dso(map)->srclines, ip, srcline);
 	}
 
 	return srcline;
@@ -2179,7 +2181,7 @@ static int add_callchain_ip(struct thread *thread,
 {
 	struct map_symbol ms;
 	struct addr_location al;
-	int nr_loop_iter = 0;
+	int nr_loop_iter = 0, err;
 	u64 iter_cycles = 0;
 	const char *srcline = NULL;
 
@@ -2228,9 +2230,10 @@ static int add_callchain_ip(struct thread *thread,
 		}
 	}
 
-	if (symbol_conf.hide_unresolved && al.sym == NULL)
+	if (symbol_conf.hide_unresolved && al.sym == NULL) {
+		addr_location__put(&al);
 		return 0;
-
+	}
 	if (iter) {
 		nr_loop_iter = iter->nr_loop_iter;
 		iter_cycles = iter->cycles;
@@ -2240,9 +2243,10 @@ static int add_callchain_ip(struct thread *thread,
 	ms.map = al.map;
 	ms.sym = al.sym;
 	srcline = callchain_srcline(&ms, al.addr);
-	return callchain_cursor_append(cursor, ip, &ms,
-				       branch, flags, nr_loop_iter,
-				       iter_cycles, branch_from, srcline);
+	err = callchain_cursor_append(cursor, ip, &ms,
+				      branch, flags, nr_loop_iter,
+				      iter_cycles, branch_from, srcline);
+	return err;
 }
 
 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -2937,15 +2941,15 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
 	if (!symbol_conf.inline_name || !map || !sym)
 		return ret;
 
-	addr = map__map_ip(map, ip);
+	addr = map__dso_map_ip(map, ip);
 	addr = map__rip_2objdump(map, addr);
 
-	inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
+	inline_node = inlines__tree_find(&map__dso(map)->inlined_nodes, addr);
 	if (!inline_node) {
-		inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
+		inline_node = dso__parse_addr_inlines(map__dso(map), addr, sym);
 		if (!inline_node)
 			return ret;
-		inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
+		inlines__tree_insert(&map__dso(map)->inlined_nodes, inline_node);
 	}
 
 	list_for_each_entry(ilist, &inline_node->val, list) {
@@ -2981,7 +2985,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
 	 * its corresponding binary.
 	 */
 	if (entry->ms.map)
-		addr = map__map_ip(entry->ms.map, entry->ip);
+		addr = map__dso_map_ip(entry->ms.map, entry->ip);
 
 	srcline = callchain_srcline(&entry->ms, addr);
 	return callchain_cursor_append(cursor, entry->ip, &entry->ms,
@@ -3183,7 +3187,7 @@ int machine__get_kernel_start(struct machine *machine)
 		 * kernel_start = 1ULL << 63 for x86_64.
 		 */
 		if (!err && !machine__is(machine, "x86_64"))
-			machine->kernel_start = map->start;
+			machine->kernel_start = map__start(map);
 	}
 	return err;
 }
@@ -3234,8 +3238,8 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
 	if (sym == NULL)
 		return NULL;
 
-	*modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
-	*addrp = map->unmap_ip(map, sym->start);
+	*modp = __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NULL;
+	*addrp = map__unmap_ip(map, sym->start);
 	return sym->name;
 }
 
tools/perf/util/map.c +61 -56
index 57e926ce115f..47d81e361e29 100644
@@ -109,8 +109,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
 	map->pgoff    = pgoff;
 	map->reloc    = 0;
 	map->dso      = dso__get(dso);
-	map->map_ip   = map__map_ip;
-	map->unmap_ip = map__unmap_ip;
+	map->map_ip   = map__dso_map_ip;
+	map->unmap_ip = map__dso_unmap_ip;
 	map->erange_warned = false;
 	refcount_set(&map->refcnt, 1);
 }
@@ -120,10 +120,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		     u32 prot, u32 flags, struct build_id *bid,
 		     char *filename, struct thread *thread)
 {
-	struct map *map = malloc(sizeof(*map));
+	struct map *map;
 	struct nsinfo *nsi = NULL;
 	struct nsinfo *nnsi;
 
+	map = malloc(sizeof(*map));
 	if (map != NULL) {
 		char newfilename[PATH_MAX];
 		struct dso *dso;
@@ -170,7 +171,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		map__init(map, start, start + len, pgoff, dso);
 
 		if (anon || no_dso) {
-			map->map_ip = map->unmap_ip = identity__map_ip;
+			map->map_ip = map->unmap_ip = map__identity_ip;
 
 			/*
 			 * Set memory without DSO as loaded. All map__find_*
@@ -204,8 +205,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
  */
 struct map *map__new2(u64 start, struct dso *dso)
 {
-	struct map *map = calloc(1, (sizeof(*map) +
-				     (dso->kernel ? sizeof(struct kmap) : 0)));
+	struct map *map;
+
+	map = calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0));
 	if (map != NULL) {
 		/*
 		 * ->end will be filled after we load all the symbols
@@ -218,7 +220,7 @@ struct map *map__new2(u64 start, struct dso *dso)
 
 bool __map__is_kernel(const struct map *map)
 {
-	if (!map->dso->kernel)
+	if (!map__dso(map)->kernel)
 		return false;
 	return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
 }
@@ -234,7 +236,7 @@ bool __map__is_bpf_prog(const struct map *map)
 {
 	const char *name;
 
-	if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+	if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
 		return true;
 
 	/*
@@ -242,7 +244,7 @@ bool __map__is_bpf_prog(const struct map *map)
 	 * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
 	 * guess the type based on name.
 	 */
-	name = map->dso->short_name;
+	name = map__dso(map)->short_name;
 	return name && (strstr(name, "bpf_prog_") == name);
 }
 
@@ -250,7 +252,7 @@ bool __map__is_bpf_image(const struct map *map)
 {
 	const char *name;
 
-	if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+	if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
 		return true;
 
 	/*
@@ -258,18 +260,19 @@ bool __map__is_bpf_image(const struct map *map)
 	 * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
 	 * guess the type based on name.
 	 */
-	name = map->dso->short_name;
+	name = map__dso(map)->short_name;
 	return name && is_bpf_image(name);
 }
 
 bool __map__is_ool(const struct map *map)
 {
-	return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+	return map__dso(map) &&
+	       map__dso(map)->binary_type == DSO_BINARY_TYPE__OOL;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-	return dso__has_symbols(map->dso);
+	return dso__has_symbols(map__dso(map));
 }
 
 static void map__exit(struct map *map)
@@ -292,7 +295,7 @@ void map__put(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-	struct rb_root_cached *symbols = &map->dso->symbols;
+	struct rb_root_cached *symbols = &map__dso(map)->symbols;
 	struct rb_node *nd = rb_first_cached(symbols);
 	if (nd != NULL) {
 		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -302,7 +305,7 @@ void map__fixup_start(struct map *map)
 
 void map__fixup_end(struct map *map)
 {
-	struct rb_root_cached *symbols = &map->dso->symbols;
+	struct rb_root_cached *symbols = &map__dso(map)->symbols;
 	struct rb_node *nd = rb_last(&symbols->rb_root);
 	if (nd != NULL) {
 		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -314,18 +317,18 @@ void map__fixup_end(struct map *map)
 
 int map__load(struct map *map)
 {
-	const char *name = map->dso->long_name;
+	const char *name = map__dso(map)->long_name;
 	int nr;
 
-	if (dso__loaded(map->dso))
+	if (dso__loaded(map__dso(map)))
 		return 0;
 
-	nr = dso__load(map->dso, map);
+	nr = dso__load(map__dso(map), map);
 	if (nr < 0) {
-		if (map->dso->has_build_id) {
+		if (map__dso(map)->has_build_id) {
 			char sbuild_id[SBUILD_ID_SIZE];
 
-			build_id__sprintf(&map->dso->bid, sbuild_id);
+			build_id__sprintf(&map__dso(map)->bid, sbuild_id);
 			pr_debug("%s with build id %s not found", name, sbuild_id);
 		} else
 			pr_debug("Failed to open %s", name);
@@ -357,7 +360,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
 	if (map__load(map) < 0)
 		return NULL;
 
-	return dso__find_symbol(map->dso, addr);
+	return dso__find_symbol(map__dso(map), addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -365,24 +368,24 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
 	if (map__load(map) < 0)
 		return NULL;
 
-	if (!dso__sorted_by_name(map->dso))
-		dso__sort_by_name(map->dso);
+	if (!dso__sorted_by_name(map__dso(map)))
+		dso__sort_by_name(map__dso(map));
 
-	return dso__find_symbol_by_name(map->dso, name);
+	return dso__find_symbol_by_name(map__dso(map), name);
 }
 
 struct map *map__clone(struct map *from)
 {
-	size_t size = sizeof(struct map);
 	struct map *map;
+	size_t size = sizeof(struct map);
 
-	if (from->dso && from->dso->kernel)
+	if (map__dso(from) && map__dso(from)->kernel)
 		size += sizeof(struct kmap);
 
 	map = memdup(from, size);
 	if (map != NULL) {
 		refcount_set(&map->refcnt, 1);
-		dso__get(map->dso);
+		map->dso = dso__get(map->dso);
 	}
 
 	return map;
@@ -391,7 +394,8 @@ struct map *map__clone(struct map *from)
 size_t map__fprintf(struct map *map, FILE *fp)
 {
 	return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
-		       map->start, map->end, map->pgoff, map->dso->name);
+		       map__start(map), map__end(map),
+		       map__pgoff(map), map__dso(map)->name);
 }
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
@@ -399,11 +403,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 	char buf[symbol_conf.pad_output_len_dso + 1];
 	const char *dsoname = "[unknown]";
 
-	if (map && map->dso) {
-		if (symbol_conf.show_kernel_path && map->dso->long_name)
-			dsoname = map->dso->long_name;
+	if (map && map__dso(map)) {
+		if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+			dsoname = map__dso(map)->long_name;
 		else
-			dsoname = map->dso->name;
+			dsoname = map__dso(map)->name;
 	}
 
 	if (symbol_conf.pad_output_len_dso) {
@@ -418,7 +422,8 @@ char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
 {
 	if (map == NULL)
 		return SRCLINE_UNKNOWN;
-	return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+	return get_srcline(map__dso(map), map__rip_2objdump(map, addr),
+			   sym, true, true, addr);
 }
 
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
@@ -426,7 +431,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 {
 	int ret = 0;
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		char *srcline = map__srcline(map, addr, NULL);
 		if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
 			ret = fprintf(fp, "%s%s", prefix, srcline);
@@ -472,20 +477,20 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
 		}
 	}
 
-	if (!map->dso->adjust_symbols)
+	if (!map__dso(map)->adjust_symbols)
 		return rip;
 
-	if (map->dso->rel)
-		return rip - map->pgoff;
+	if (map__dso(map)->rel)
+		return rip - map__pgoff(map);
 
 	/*
 	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
 	 * but all kernel modules are ET_REL, so won't get here.
 	 */
-	if (map->dso->kernel == DSO_SPACE__USER)
-		return rip + map->dso->text_offset;
+	if (map__dso(map)->kernel == DSO_SPACE__USER)
+		return rip + map__dso(map)->text_offset;
 
-	return map->unmap_ip(map, rip) - map->reloc;
+	return map__unmap_ip(map, rip) - map__reloc(map);
 }
 
 /**
@@ -502,34 +507,34 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
  */
 u64 map__objdump_2mem(struct map *map, u64 ip)
 {
-	if (!map->dso->adjust_symbols)
-		return map->unmap_ip(map, ip);
+	if (!map__dso(map)->adjust_symbols)
+		return map__unmap_ip(map, ip);
 
-	if (map->dso->rel)
-		return map->unmap_ip(map, ip + map->pgoff);
+	if (map__dso(map)->rel)
+		return map__unmap_ip(map, ip + map__pgoff(map));
 
 	/*
 	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
 	 * but all kernel modules are ET_REL, so won't get here.
 	 */
-	if (map->dso->kernel == DSO_SPACE__USER)
-		return map->unmap_ip(map, ip - map->dso->text_offset);
+	if (map__dso(map)->kernel == DSO_SPACE__USER)
+		return map__unmap_ip(map, ip - map__dso(map)->text_offset);
 
-	return ip + map->reloc;
+	return ip + map__reloc(map);
 }
 
 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
 {
-	u64 ip = map->unmap_ip(map, sym->start);
+	u64 ip = map__unmap_ip(map, sym->start);
 
-	return ip >= map->start && ip < map->end;
+	return ip >= map__start(map) && ip < map__end(map);
 }
 
 struct kmap *__map__kmap(struct map *map)
 {
-	if (!map->dso || !map->dso->kernel)
+	if (!map__dso(map) || !map__dso(map)->kernel)
 		return NULL;
-	return (struct kmap *)(map + 1);
+	return (struct kmap *)(&map[1]);
 }
 
 struct kmap *map__kmap(struct map *map)
@@ -552,17 +557,17 @@ struct maps *map__kmaps(struct map *map)
 	return kmap->kmaps;
 }
 
-u64 map__map_ip(const struct map *map, u64 ip)
+u64 map__dso_map_ip(const struct map *map, u64 ip)
 {
-	return ip - map->start + map->pgoff;
+	return ip - map__start(map) + map__pgoff(map);
 }
 
-u64 map__unmap_ip(const struct map *map, u64 ip)
+u64 map__dso_unmap_ip(const struct map *map, u64 ip)
 {
-	return ip + map->start - map->pgoff;
+	return ip + map__start(map) - map__pgoff(map);
 }
 
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip)
 {
 	return ip;
 }
tools/perf/util/map.h +54 -4
index d1a6f85fd31d..99ef0464a357 100644
@@ -41,15 +41,65 @@ struct kmap *map__kmap(struct map *map);
 struct maps *map__kmaps(struct map *map);
 
 /* ip -> dso rip */
-u64 map__map_ip(const struct map *map, u64 ip);
+u64 map__dso_map_ip(const struct map *map, u64 ip);
 /* dso rip -> ip */
-u64 map__unmap_ip(const struct map *map, u64 ip);
+u64 map__dso_unmap_ip(const struct map *map, u64 ip);
 /* Returns ip */
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip);
+
+static inline struct dso *map__dso(const struct map *map)
+{
+	return map->dso;
+}
+
+static inline u64 map__map_ip(const struct map *map, u64 ip)
+{
+	return map->map_ip(map, ip);
+}
+
+static inline u64 map__unmap_ip(const struct map *map, u64 ip)
+{
+	return map->unmap_ip(map, ip);
+}
+
+static inline u64 map__start(const struct map *map)
+{
+	return map->start;
+}
+
+static inline u64 map__end(const struct map *map)
+{
+	return map->end;
+}
+
+static inline u64 map__pgoff(const struct map *map)
+{
+	return map->pgoff;
+}
+
+static inline u64 map__reloc(const struct map *map)
+{
+	return map->reloc;
+}
+
+static inline u32 map__flags(const struct map *map)
+{
+	return map->flags;
+}
+
+static inline u32 map__prot(const struct map *map)
+{
+	return map->prot;
+}
+
+static inline bool map__priv(const struct map *map)
+{
+	return map->priv;
+}
 
 static inline size_t map__size(const struct map *map)
 {
-	return map->end - map->start;
+	return map__end(map) - map__start(map);
 }
 
 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
tools/perf/util/maps.c +42 -41
index 9fc3e7186b8e..6efbcb79131c 100644
@@ -30,24 +30,24 @@ static void __maps__free_maps_by_name(struct maps *maps)
 	maps->nr_maps_allocated = 0;
 }
 
-static int __maps__insert(struct maps *maps, struct map *map)
+static struct map *__maps__insert(struct maps *maps, struct map *map)
 {
 	struct rb_node **p = &maps__entries(maps)->rb_node;
 	struct rb_node *parent = NULL;
-	const u64 ip = map->start;
+	const u64 ip = map__start(map);
 	struct map_rb_node *m, *new_rb_node;
 
 	new_rb_node = malloc(sizeof(*new_rb_node));
 	if (!new_rb_node)
-		return -ENOMEM;
+		return NULL;
 
 	RB_CLEAR_NODE(&new_rb_node->rb_node);
-	new_rb_node->map = map;
+	new_rb_node->map = map__get(map);
 
 	while (*p != NULL) {
 		parent = *p;
 		m = rb_entry(parent, struct map_rb_node, rb_node);
-		if (ip < m->map->start)
+		if (ip < map__start(m->map))
 			p = &(*p)->rb_left;
 		else
 			p = &(*p)->rb_right;
@@ -55,22 +55,23 @@ static int __maps__insert(struct maps *maps, struct map *map)
 
 	rb_link_node(&new_rb_node->rb_node, parent, p);
 	rb_insert_color(&new_rb_node->rb_node, maps__entries(maps));
-	map__get(map);
-	return 0;
+	return new_rb_node->map;
 }
 
 int maps__insert(struct maps *maps, struct map *map)
 {
-	int err;
+	int err = 0;
 
 	down_write(maps__lock(maps));
-	err = __maps__insert(maps, map);
-	if (err)
+	map = __maps__insert(maps, map);
+	if (!map) {
+		err = -ENOMEM;
 		goto out;
+	}
 
 	++maps->nr_maps;
 
-	if (map->dso && map->dso->kernel) {
+	if (map__dso(map) && map__dso(map)->kernel) {
 		struct kmap *kmap = map__kmap(map);
 
 		if (kmap)
@@ -193,7 +194,7 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
 	if (map != NULL && map__load(map) >= 0) {
 		if (mapp != NULL)
 			*mapp = map;
-		return map__find_symbol(map, map->map_ip(map, addr));
+		return map__find_symbol(map, map__map_ip(map, addr));
 	}
 
 	return NULL;
@@ -228,7 +229,8 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, st
 
 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 {
-	if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
+	if (ams->addr < map__start(ams->ms.map) ||
+	    ams->addr >= map__end(ams->ms.map)) {
 		if (maps == NULL)
 			return -1;
 		ams->ms.map = maps__find(maps, ams->addr);
@@ -236,7 +238,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 			return -1;
 	}
 
-	ams->al_addr = ams->ms.map->map_ip(ams->ms.map, ams->addr);
+	ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
 	ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
 
 	return ams->ms.sym ? 0 : -1;
@@ -253,7 +255,7 @@ size_t maps__fprintf(struct maps *maps, FILE *fp)
 		printed += fprintf(fp, "Map:");
 		printed += map__fprintf(pos->map, fp);
 		if (verbose > 2) {
-			printed += dso__fprintf(pos->map->dso, fp);
+			printed += dso__fprintf(map__dso(pos->map), fp);
 			printed += fprintf(fp, "--\n");
 		}
 	}
@@ -282,9 +284,9 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 	while (next) {
 		struct map_rb_node *pos = rb_entry(next, struct map_rb_node, rb_node);
 
-		if (pos->map->end > map->start) {
+		if (map__end(pos->map) > map__start(map)) {
 			first = next;
-			if (pos->map->start <= map->start)
+			if (map__start(pos->map) <= map__start(map))
 				break;
 			next = next->rb_left;
 		} else
@@ -300,14 +302,14 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 		 * Stop if current map starts after map->end.
 		 * Maps are ordered by start: next will not overlap for sure.
 		 */
-		if (pos->map->start >= map->end)
+		if (map__start(pos->map) >= map__end(map))
 			break;
 
 		if (verbose >= 2) {
 
 			if (use_browser) {
 				pr_debug("overlapping maps in %s (disable tui for more info)\n",
-					   map->dso->name);
+					   map__dso(map)->name);
 			} else {
 				fputs("overlapping maps:\n", fp);
 				map__fprintf(map, fp);
@@ -320,7 +322,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 		 * Now check if we need to create new maps for areas not
 		 * overlapped by the new map:
 		 */
-		if (map->start > pos->map->start) {
+		if (map__start(map) > map__start(pos->map)) {
 			struct map *before = map__clone(pos->map);
 
 			if (before == NULL) {
@@ -328,17 +330,19 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 				goto put_map;
 			}
 
-			before->end = map->start;
-			err = __maps__insert(maps, before);
-			if (err)
+			before->end = map__start(map);
+			if (!__maps__insert(maps, before)) {
+				map__put(before);
+				err = -ENOMEM;
 				goto put_map;
+			}
 
 			if (verbose >= 2 && !use_browser)
 				map__fprintf(before, fp);
 			map__put(before);
 		}
 
-		if (map->end < pos->map->end) {
+		if (map__end(map) < map__end(pos->map)) {
 			struct map *after = map__clone(pos->map);
 
 			if (after == NULL) {
@@ -346,14 +350,15 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 				goto put_map;
 			}
 
-			after->start = map->end;
-			after->pgoff += map->end - pos->map->start;
-			assert(pos->map->map_ip(pos->map, map->end) ==
-				after->map_ip(after, map->end));
-			err = __maps__insert(maps, after);
-			if (err)
+			after->start = map__end(map);
+			after->pgoff += map__end(map) - map__start(pos->map);
+			assert(map__map_ip(pos->map, map__end(map)) ==
+				map__map_ip(after, map__end(map)));
+			if (!__maps__insert(maps, after)) {
+				map__put(after);
+				err = -ENOMEM;
 				goto put_map;
-
+			}
 			if (verbose >= 2 && !use_browser)
 				map__fprintf(after, fp);
 			map__put(after);
@@ -377,7 +382,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err;
+	int err = 0;
 	struct map_rb_node *rb_node;
 
 	down_read(maps__lock(parent));
@@ -391,17 +396,13 @@ int maps__clone(struct thread *thread, struct maps *parent)
 		}
 
 		err = unwind__prepare_access(maps, new, NULL);
-		if (err)
-			goto out_unlock;
+		if (!err)
+			err = maps__insert(maps, new);
 
-		err = maps__insert(maps, new);
+		map__put(new);
 		if (err)
 			goto out_unlock;
-
-		map__put(new);
 	}
-
-	err = 0;
 out_unlock:
 	up_read(maps__lock(parent));
 	return err;
@@ -428,9 +429,9 @@ struct map *maps__find(struct maps *maps, u64 ip)
 	p = maps__entries(maps)->rb_node;
 	while (p != NULL) {
 		m = rb_entry(p, struct map_rb_node, rb_node);
-		if (ip < m->map->start)
+		if (ip < map__start(m->map))
 			p = p->rb_left;
-		else if (ip >= m->map->end)
+		else if (ip >= map__end(m->map))
 			p = p->rb_right;
 		else
 			goto out;
tools/perf/util/probe-event.c +22 -22
index f9fbf611f2bf..1a93dca50a4c 100644
@@ -134,15 +134,15 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
 	/* ref_reloc_sym is just a label. Need a special fix*/
 	reloc_sym = kernel_get_ref_reloc_sym(&map);
 	if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
-		*addr = (!map->reloc || reloc) ? reloc_sym->addr :
+		*addr = (!map__reloc(map) || reloc) ? reloc_sym->addr :
 			reloc_sym->unrelocated_addr;
 	else {
 		sym = machine__find_kernel_symbol_by_name(host_machine, name, &map);
 		if (!sym)
 			return -ENOENT;
-		*addr = map->unmap_ip(map, sym->start) -
-			((reloc) ? 0 : map->reloc) -
-			((reladdr) ? map->start : 0);
+		*addr = map__unmap_ip(map, sym->start) -
+			((reloc) ? 0 : map__reloc(map)) -
+			((reladdr) ? map__start(map) : 0);
 	}
 	return 0;
 }
@@ -164,8 +164,8 @@ static struct map *kernel_get_module_map(const char *module)
 
 	maps__for_each_entry(maps, pos) {
 		/* short_name is "[module]" */
-		const char *short_name = pos->map->dso->short_name;
-		u16 short_name_len =  pos->map->dso->short_name_len;
+		const char *short_name = map__dso(pos->map)->short_name;
+		u16 short_name_len =  map__dso(pos->map)->short_name_len;
 
 		if (strncmp(short_name + 1, module,
 			    short_name_len - 2) == 0 &&
@@ -183,11 +183,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)
 		struct map *map;
 
 		map = dso__new_map(target);
-		if (map && map->dso) {
-			BUG_ON(pthread_mutex_lock(&map->dso->lock) != 0);
-			nsinfo__put(map->dso->nsinfo);
-			map->dso->nsinfo = nsinfo__get(nsi);
-			pthread_mutex_unlock(&map->dso->lock);
+		if (map && map__dso(map)) {
+			BUG_ON(pthread_mutex_lock(&map__dso(map)->lock) != 0);
+			nsinfo__put(map__dso(map)->nsinfo);
+			map__dso(map)->nsinfo = nsinfo__get(nsi);
+			pthread_mutex_unlock(&map__dso(map)->lock);
 		}
 		return map;
 	} else {
@@ -253,7 +253,7 @@ static bool kprobe_warn_out_range(const char *symbol, u64 address)
 
 	map = kernel_get_module_map(NULL);
 	if (map) {
-		ret = address <= map->start || map->end < address;
+		ret = address <= map__start(map) || map__end(map) < address;
 		if (ret)
 			pr_warning("%s is out of .text, skip it.\n", symbol);
 		map__put(map);
@@ -340,7 +340,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
 		snprintf(module_name, sizeof(module_name), "[%s]", module);
 		map = maps__find_by_name(machine__kernel_maps(host_machine), module_name);
 		if (map) {
-			dso = map->dso;
+			dso = map__dso(map);
 			goto found;
 		}
 		pr_debug("Failed to find module %s.\n", module);
@@ -348,7 +348,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
 	}
 
 	map = machine__kernel_map(host_machine);
-	dso = map->dso;
+	dso = map__dso(map);
 	if (!dso->has_build_id)
 		dso__read_running_kernel_build_id(dso, host_machine);
 
@@ -396,7 +396,8 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
 					   "Consider identifying the final function used at run time and set the probe directly on that.\n",
 					   pp->function);
 		} else
-			address = map->unmap_ip(map, sym->start) - map->reloc;
+			address = map__unmap_ip(map, sym->start) -
+				  map__reloc(map);
 		break;
 	}
 	if (!address) {
@@ -862,8 +863,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
 			free(tevs[i].point.symbol);
 		tevs[i].point.symbol = tmp;
 		tevs[i].point.offset = tevs[i].point.address -
-			(map->reloc ? reloc_sym->unrelocated_addr :
-				      reloc_sym->addr);
+			(map__reloc(map) ? reloc_sym->unrelocated_addr : reloc_sym->addr);
 	}
 	return skipped;
 }
@@ -2243,7 +2243,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
 		goto out;
 
 	pp->retprobe = tp->retprobe;
-	pp->offset = addr - map->unmap_ip(map, sym->start);
+	pp->offset = addr - map__unmap_ip(map, sym->start);
 	pp->function = strdup(sym->name);
 	ret = pp->function ? 0 : -ENOMEM;
 
@@ -3117,7 +3117,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 			goto err_out;
 		}
 		/* Add one probe point */
-		tp->address = map->unmap_ip(map, sym->start) + pp->offset;
+		tp->address = map__unmap_ip(map, sym->start) + pp->offset;
 
 		/* Check the kprobe (not in module) is within .text  */
 		if (!pev->uprobes && !pev->target &&
@@ -3759,13 +3759,13 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
 			       (target) ? : "kernel");
 		goto end;
 	}
-	if (!dso__sorted_by_name(map->dso))
-		dso__sort_by_name(map->dso);
+	if (!dso__sorted_by_name(map__dso(map)))
+		dso__sort_by_name(map__dso(map));
 
 	/* Show all (filtered) symbols */
 	setup_pager();
 
-	for (nd = rb_first_cached(&map->dso->symbol_names); nd;
+	for (nd = rb_first_cached(&map__dso(map)->symbol_names); nd;
 	     nd = rb_next(nd)) {
 		struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
tools/perf/util/scripting-engines/trace-event-perl.c +5 -4
index a5d945415bbc..1282fb9b45e1 100644
@@ -315,11 +315,12 @@ static SV *perl_process_callchain(struct perf_sample *sample,
 		if (node->ms.map) {
 			struct map *map = node->ms.map;
 			const char *dsoname = "[unknown]";
-			if (map && map->dso) {
-				if (symbol_conf.show_kernel_path && map->dso->long_name)
-					dsoname = map->dso->long_name;
+			if (map && map__dso(map)) {
+				if (symbol_conf.show_kernel_path &&
+				    map__dso(map)->long_name)
+					dsoname = map__dso(map)->long_name;
 				else
-					dsoname = map->dso->name;
+					dsoname = map__dso(map)->name;
 			}
 			if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) {
 				hv_undef(elem);
tools/perf/util/scripting-engines/trace-event-python.c +6 -6
index 0290dc3a6258..559b2ac5cac3 100644
@@ -382,11 +382,11 @@ static const char *get_dsoname(struct map *map)
 {
 	const char *dsoname = "[unknown]";
 
-	if (map && map->dso) {
-		if (symbol_conf.show_kernel_path && map->dso->long_name)
-			dsoname = map->dso->long_name;
+	if (map && map__dso(map)) {
+		if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+			dsoname = map__dso(map)->long_name;
 		else
-			dsoname = map->dso->name;
+			dsoname = map__dso(map)->name;
 	}
 
 	return dsoname;
@@ -527,7 +527,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al)
 	if (al->addr < sym->end)
 		offset = al->addr - sym->start;
 	else
-		offset = al->addr - al->map->start - sym->start;
+		offset = al->addr - map__start(al->map) - sym->start;
 
 	return offset;
 }
@@ -741,7 +741,7 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 {
 	if (al->map) {
 		pydict_set_item_string_decref(dict, dso_field,
-			_PyUnicode_FromString(al->map->dso->name));
+			_PyUnicode_FromString(map__dso(al->map)->name));
 	}
 	if (al->sym) {
 		pydict_set_item_string_decref(dict, sym_field,
tools/perf/util/sort.c +23 -23
index 25686d67ee6f..6d19bbcd30df 100644
@@ -173,8 +173,8 @@ struct sort_entry sort_comm = {
 
 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
 {
-	struct dso *dso_l = map_l ? map_l->dso : NULL;
-	struct dso *dso_r = map_r ? map_r->dso : NULL;
+	struct dso *dso_l = map_l ? map__dso(map_l) : NULL;
+	struct dso *dso_r = map_r ? map__dso(map_r) : NULL;
 	const char *dso_name_l, *dso_name_r;
 
 	if (!dso_l || !dso_r)
@@ -200,9 +200,9 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
 				     size_t size, unsigned int width)
 {
-	if (map && map->dso) {
-		const char *dso_name = verbose > 0 ? map->dso->long_name :
-			map->dso->short_name;
+	if (map && map__dso(map)) {
+		const char *dso_name = verbose > 0 ? map__dso(map)->long_name :
+			map__dso(map)->short_name;
 		return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
 	}
 
@@ -222,7 +222,7 @@ static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *a
 	if (type != HIST_FILTER__DSO)
 		return -1;
 
-	return dso && (!he->ms.map || he->ms.map->dso != dso);
+	return dso && (!he->ms.map || map__dso(he->ms.map) != dso);
 }
 
 struct sort_entry sort_dso = {
@@ -302,12 +302,12 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
 	size_t ret = 0;
 
 	if (verbose > 0) {
-		char o = map ? dso__symtab_origin(map->dso) : '!';
+		char o = map ? dso__symtab_origin(map__dso(map)) : '!';
 		u64 rip = ip;
 
-		if (map && map->dso && map->dso->kernel
-		    && map->dso->adjust_symbols)
-			rip = map->unmap_ip(map, ip);
+		if (map && map__dso(map) && map__dso(map)->kernel
+		    && map__dso(map)->adjust_symbols)
+			rip = map__unmap_ip(map, ip);
 
 		ret += repsep_snprintf(bf, size, "%-#*llx %c ",
 				       BITS_PER_LONG / 4 + 2, rip, o);
@@ -318,7 +318,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
 		if (sym->type == STT_OBJECT) {
 			ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
 			ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
-					ip - map->unmap_ip(map, sym->start));
+					ip - map__unmap_ip(map, sym->start));
 		} else {
 			ret += repsep_snprintf(bf + ret, size - ret, "%.*s",
 					       width - ret,
@@ -517,7 +517,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)
 	if (!map)
 		return no_srcfile;
 
-	sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
+	sf = __get_srcline(map__dso(map), map__rip_2objdump(map, e->ip),
 			 e->ms.sym, false, true, true, e->ip);
 	if (!strcmp(sf, SRCLINE_UNKNOWN))
 		return no_srcfile;
@@ -838,7 +838,7 @@ static int hist_entry__dso_from_filter(struct hist_entry *he, int type,
 		return -1;
 
 	return dso && (!he->branch_info || !he->branch_info->from.ms.map ||
-		       he->branch_info->from.ms.map->dso != dso);
+		map__dso(he->branch_info->from.ms.map) != dso);
 }
 
 static int64_t
@@ -870,7 +870,7 @@ static int hist_entry__dso_to_filter(struct hist_entry *he, int type,
 		return -1;
 
 	return dso && (!he->branch_info || !he->branch_info->to.ms.map ||
-		       he->branch_info->to.ms.map->dso != dso);
+		map__dso(he->branch_info->to.ms.map) != dso);
 }
 
 static int64_t
@@ -1259,7 +1259,7 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 	if (!l_map) return -1;
 	if (!r_map) return 1;
 
-	rc = dso__cmp_id(l_map->dso, r_map->dso);
+	rc = dso__cmp_id(map__dso(l_map), map__dso(r_map));
 	if (rc)
 		return rc;
 	/*
@@ -1271,9 +1271,9 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 	 */
 
 	if ((left->cpumode != PERF_RECORD_MISC_KERNEL) &&
-	    (!(l_map->flags & MAP_SHARED)) &&
-	    !l_map->dso->id.maj && !l_map->dso->id.min &&
-	    !l_map->dso->id.ino && !l_map->dso->id.ino_generation) {
+	    (!(map__flags(l_map) & MAP_SHARED)) &&
+	    !map__dso(l_map)->id.maj && !map__dso(l_map)->id.min &&
+	    !map__dso(l_map)->id.ino && !map__dso(l_map)->id.ino_generation) {
 		/* userspace anonymous */
 
 		if (left->thread->pid_ > right->thread->pid_) return -1;
@@ -1307,10 +1307,10 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,
 
 		/* print [s] for shared data mmaps */
 		if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
-		     map && !(map->prot & PROT_EXEC) &&
-		    (map->flags & MAP_SHARED) &&
-		    (map->dso->id.maj || map->dso->id.min ||
-		     map->dso->id.ino || map->dso->id.ino_generation))
+		    map && !(map__prot(map) & PROT_EXEC) &&
+		    (map__flags(map) & MAP_SHARED) &&
+		    (map__dso(map)->id.maj || map__dso(map)->id.min ||
+		     map__dso(map)->id.ino || map__dso(map)->id.ino_generation))
 			level = 's';
 		else if (!map)
 			level = 'X';
@@ -1806,7 +1806,7 @@ sort__dso_size_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_size_snprintf(struct map *map, char *bf,
 					  size_t bf_size, unsigned int width)
 {
-	if (map && map->dso)
+	if (map && map__dso(map))
 		return repsep_snprintf(bf, bf_size, "%*d", width,
 				       map__size(map));
 
tools/perf/util/symbol-elf.c +19 -20
index 3ca9a0968345..056405d3d655 100644
@@ -970,7 +970,7 @@ void __weak arch__sym_update(struct symbol *s __maybe_unused,
 static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 				      GElf_Sym *sym, GElf_Shdr *shdr,
 				      struct maps *kmaps, struct kmap *kmap,
-				      struct dso **curr_dsop, struct map **curr_mapp,
+				      struct dso **curr_dsop,
 				      const char *section_name,
 				      bool adjust_kernel_syms, bool kmodule, bool *remap_kernel)
 {
@@ -994,18 +994,18 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		if (*remap_kernel && dso->kernel && !kmodule) {
 			*remap_kernel = false;
 			map->start = shdr->sh_addr + ref_reloc(kmap);
-			map->end = map->start + shdr->sh_size;
+			map->end = map__start(map) + shdr->sh_size;
 			map->pgoff = shdr->sh_offset;
-			map->map_ip = map__map_ip;
-			map->unmap_ip = map__unmap_ip;
+			map->map_ip = map__dso_map_ip;
+			map->unmap_ip = map__dso_unmap_ip;
 			/* Ensure maps are correctly ordered */
 			if (kmaps) {
 				int err;
+				struct map *updated = map__get(map);
 
-				map__get(map);
 				maps__remove(kmaps, map);
-				err = maps__insert(kmaps, map);
-				map__put(map);
+				err = maps__insert(kmaps, updated);
+				map__put(updated);
 				if (err)
 					return err;
 			}
@@ -1021,7 +1021,6 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 			map->pgoff = shdr->sh_offset;
 		}
 
-		*curr_mapp = map;
 		*curr_dsop = dso;
 		return 0;
 	}
@@ -1036,7 +1035,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		u64 start = sym->st_value;
 
 		if (kmodule)
-			start += map->start + shdr->sh_offset;
+			start += map__start(map) + shdr->sh_offset;
 
 		curr_dso = dso__new(dso_name);
 		if (curr_dso == NULL)
@@ -1054,10 +1053,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 
 		if (adjust_kernel_syms) {
 			curr_map->start  = shdr->sh_addr + ref_reloc(kmap);
-			curr_map->end	 = curr_map->start + shdr->sh_size;
-			curr_map->pgoff	 = shdr->sh_offset;
+			curr_map->end	= map__start(curr_map) + shdr->sh_size;
+			curr_map->pgoff	= shdr->sh_offset;
 		} else {
-			curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+			curr_map->map_ip = map__identity_ip;
+			curr_map->unmap_ip = map__identity_ip;
 		}
 		curr_dso->symtab_type = dso->symtab_type;
 		if (maps__insert(kmaps, curr_map))
@@ -1068,13 +1068,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		 * *curr_map->dso.
 		 */
 		dsos__add(&maps__machine(kmaps)->dsos, curr_dso);
-		/* kmaps already got it */
-		map__put(curr_map);
 		dso__set_loaded(curr_dso);
-		*curr_mapp = curr_map;
 		*curr_dsop = curr_dso;
+		map__put(curr_map);
 	} else
-		*curr_dsop = curr_map->dso;
+		*curr_dsop = map__dso(curr_map);
 
 	return 0;
 }
@@ -1085,7 +1083,6 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 {
 	struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
 	struct maps *kmaps = kmap ? map__kmaps(map) : NULL;
-	struct map *curr_map = map;
 	struct dso *curr_dso = dso;
 	Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym;
 	uint32_t nr_syms;
@@ -1175,7 +1172,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 	 * attempted to prelink vdso to its virtual address.
 	 */
 	if (dso__is_vdso(dso))
-		map->reloc = map->start - dso->text_offset;
+		map->reloc = map__start(map) - dso->text_offset;
 
 	dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
 	/*
@@ -1262,8 +1259,10 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 			--sym.st_value;
 
 		if (dso->kernel) {
-			if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map,
-						       section_name, adjust_kernel_syms, kmodule, &remap_kernel))
+			if (dso__process_kernel_symbol(dso, map, &sym, &shdr,
+						       kmaps, kmap, &curr_dso,
+						       section_name, adjust_kernel_syms,
+						       kmodule, &remap_kernel))
 				goto out_elf_end;
 		} else if ((used_opd && runtime_ss->adjust_symbols) ||
 			   (!used_opd && syms_ss->adjust_symbols)) {
tools/perf/util/symbol.c +51 -45
index 9b51e669a722..6289b3028b91 100644
@@ -252,8 +252,8 @@ void maps__fixup_end(struct maps *maps)
 	down_write(maps__lock(maps));
 
 	maps__for_each_entry(maps, curr) {
-		if (prev != NULL && !prev->map->end)
-			prev->map->end = curr->map->start;
+		if (prev != NULL && !map__end(prev->map))
+			prev->map->end = map__start(curr->map);
 
 		prev = curr;
 	}
@@ -262,7 +262,7 @@ void maps__fixup_end(struct maps *maps)
 	 * We still haven't the actual symbols, so guess the
 	 * last map final address.
 	 */
-	if (curr && !curr->map->end)
+	if (curr && !map__end(curr->map))
 		curr->map->end = ~0ULL;
 
 	up_write(maps__lock(maps));
@@ -778,12 +778,12 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
 			continue;
 		}
 
-		pos->start -= curr_map->start - curr_map->pgoff;
-		if (pos->end > curr_map->end)
-			pos->end = curr_map->end;
+		pos->start -= map__start(curr_map) - map__pgoff(curr_map);
+		if (pos->end > map__end(curr_map))
+			pos->end = map__end(curr_map);
 		if (pos->end)
-			pos->end -= curr_map->start - curr_map->pgoff;
-		symbols__insert(&curr_map->dso->symbols, pos);
+			pos->end -= map__start(curr_map) - map__pgoff(curr_map);
+		symbols__insert(&map__dso(curr_map)->symbols, pos);
 		++count;
 	}
 
@@ -830,7 +830,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 
 			*module++ = '\0';
 
-			if (strcmp(curr_map->dso->short_name, module)) {
+			if (strcmp(map__dso(curr_map)->short_name, module)) {
 				if (curr_map != initial_map &&
 				    dso->kernel == DSO_SPACE__KERNEL_GUEST &&
 				    machine__is_default_guest(machine)) {
@@ -841,7 +841,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 					 * symbols are in its kmap. Mark it as
 					 * loaded.
 					 */
-					dso__set_loaded(curr_map->dso);
+					dso__set_loaded(map__dso(curr_map));
 				}
 
 				curr_map = maps__find_by_name(kmaps, module);
@@ -854,7 +854,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 					goto discard_symbol;
 				}
 
-				if (curr_map->dso->loaded &&
+				if (map__dso(curr_map)->loaded &&
 				    !machine__is_default_guest(machine))
 					goto discard_symbol;
 			}
@@ -862,8 +862,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 			 * So that we look just like we get from .ko files,
 			 * i.e. not prelinked, relative to initial_map->start.
 			 */
-			pos->start = curr_map->map_ip(curr_map, pos->start);
-			pos->end   = curr_map->map_ip(curr_map, pos->end);
+			pos->start = map__map_ip(curr_map, pos->start);
+			pos->end   = map__map_ip(curr_map, pos->end);
 		} else if (x86_64 && is_entry_trampoline(pos->name)) {
 			/*
 			 * These symbols are not needed anymore since the
@@ -910,7 +910,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 				return -1;
 			}
 
-			curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+			curr_map->map_ip = map__identity_ip;
+			curr_map->unmap_ip = map__identity_ip;
 			if (maps__insert(kmaps, curr_map)) {
 				dso__put(ndso);
 				return -1;
@@ -924,7 +925,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 add_symbol:
 		if (curr_map != initial_map) {
 			rb_erase_cached(&pos->rb_node, root);
-			symbols__insert(&curr_map->dso->symbols, pos);
+			symbols__insert(&map__dso(curr_map)->symbols, pos);
 			++moved;
 		} else
 			++count;
@@ -938,7 +939,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 	if (curr_map != initial_map &&
 	    dso->kernel == DSO_SPACE__KERNEL_GUEST &&
 	    machine__is_default_guest(maps__machine(kmaps))) {
-		dso__set_loaded(curr_map->dso);
+		dso__set_loaded(map__dso(curr_map));
 	}
 
 	return count + moved;
@@ -1118,8 +1119,8 @@ static int do_validate_kcore_modules(const char *filename, struct maps *kmaps)
 		}
 
 		/* Module must be in memory at the same address */
-		mi = find_module(old_map->dso->short_name, &modules);
-		if (!mi || mi->start != old_map->start) {
+		mi = find_module(map__dso(old_map)->short_name, &modules);
+		if (!mi || mi->start != map__start(old_map)) {
 			err = -EINVAL;
 			goto out;
 		}
@@ -1214,7 +1215,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
 		return -ENOMEM;
 	}
 
-	list_node->map->end = list_node->map->start + len;
+	list_node->map->end = map__start(list_node->map) + len;
 	list_node->map->pgoff = pgoff;
 
 	list_add(&list_node->node, &md->maps);
@@ -1236,21 +1237,21 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 		struct map *old_map = rb_node->map;
 
 		/* no overload with this one */
-		if (new_map->end < old_map->start ||
-		    new_map->start >= old_map->end)
+		if (map__end(new_map) < map__start(old_map) ||
+		    map__start(new_map) >= map__end(old_map))
 			continue;
 
-		if (new_map->start < old_map->start) {
+		if (map__start(new_map) < map__start(old_map)) {
 			/*
 			 * |new......
 			 *       |old....
 			 */
-			if (new_map->end < old_map->end) {
+			if (map__end(new_map) < map__end(old_map)) {
 				/*
 				 * |new......|     -> |new..|
 				 *       |old....| ->       |old....|
 				 */
-				new_map->end = old_map->start;
+				new_map->end = map__start(old_map);
 			} else {
 				/*
 				 * |new.............| -> |new..|       |new..|
@@ -1271,17 +1272,18 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 					goto out;
 				}
 
-				m->map->end = old_map->start;
+				m->map->end = map__start(old_map);
 				list_add_tail(&m->node, &merged);
-				new_map->pgoff += old_map->end - new_map->start;
-				new_map->start = old_map->end;
+				new_map->pgoff +=
+					map__end(old_map) - map__start(new_map);
+				new_map->start = map__end(old_map);
 			}
 		} else {
 			/*
 			 *      |new......
 			 * |old....
 			 */
-			if (new_map->end < old_map->end) {
+			if (map__end(new_map) < map__end(old_map)) {
 				/*
 				 *      |new..|   -> x
 				 * |old.........| -> |old.........|
@@ -1294,8 +1296,9 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 				 *      |new......| ->         |new...|
 				 * |old....|        -> |old....|
 				 */
-				new_map->pgoff += old_map->end - new_map->start;
-				new_map->start = old_map->end;
+				new_map->pgoff +=
+					map__end(old_map) - map__start(new_map);
+				new_map->start = map__end(old_map);
 			}
 		}
 	}
@@ -1361,7 +1364,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	}
 
 	/* Read new maps into temporary lists */
-	err = file__read_maps(fd, map->prot & PROT_EXEC, kcore_mapfn, &md,
+	err = file__read_maps(fd, map__prot(map) & PROT_EXEC, kcore_mapfn, &md,
 			      &is_64_bit);
 	if (err)
 		goto out_err;
@@ -1391,7 +1394,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		struct map_list_node *new_node;
 
 		list_for_each_entry(new_node, &md.maps, node) {
-			if (stext >= new_node->map->start && stext < new_node->map->end) {
+			if (stext >= map__start(new_node->map) &&
+			    stext < map__end(new_node->map)) {
 				replacement_map = new_node->map;
 				break;
 			}
@@ -1408,16 +1412,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		new_node = list_entry(md.maps.next, struct map_list_node, node);
 		list_del_init(&new_node->node);
 		if (new_node->map == replacement_map) {
-			map->start	= new_node->map->start;
-			map->end	= new_node->map->end;
-			map->pgoff	= new_node->map->pgoff;
-			map->map_ip	= new_node->map->map_ip;
-			map->unmap_ip	= new_node->map->unmap_ip;
+			struct  map *updated;
+
+			map->start = map__start(new_node->map);
+			map->end   = map__end(new_node->map);
+			map->pgoff = map__pgoff(new_node->map);
+			map->map_ip = new_node->map->map_ip;
+			map->unmap_ip = new_node->map->unmap_ip;
 			/* Ensure maps are correctly ordered */
-			map__get(map);
+			updated = map__get(map);
 			maps__remove(kmaps, map);
-			err = maps__insert(kmaps, map);
-			map__put(map);
+			err = maps__insert(kmaps, updated);
+			map__put(updated);
 			map__put(new_node->map);
 			if (err)
 				goto out_err;
@@ -1460,7 +1466,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
 	close(fd);
 
-	if (map->prot & PROT_EXEC)
+	if (map__prot(map) & PROT_EXEC)
 		pr_debug("Using %s for kernel object code\n", kcore_filename);
 	else
 		pr_debug("Using %s for kernel data\n", kcore_filename);
@@ -1995,13 +2001,13 @@ int dso__load(struct dso *dso, struct map *map)
 static int map__strcmp(const void *a, const void *b)
 {
 	const struct map *ma = *(const struct map **)a, *mb = *(const struct map **)b;
-	return strcmp(ma->dso->short_name, mb->dso->short_name);
+	return strcmp(map__dso(ma)->short_name, map__dso(mb)->short_name);
 }
 
 static int map__strcmp_name(const void *name, const void *b)
 {
 	const struct map *map = *(const struct map **)b;
-	return strcmp(name, map->dso->short_name);
+	return strcmp(name, map__dso(map)->short_name);
 }
 
 void __maps__sort_by_name(struct maps *maps)
@@ -2052,7 +2058,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
 	down_read(maps__lock(maps));
 
 	if (maps->last_search_by_name &&
-	    strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
+	    strcmp(map__dso(maps->last_search_by_name)->short_name, name) == 0) {
 		map = maps->last_search_by_name;
 		goto out_unlock;
 	}
@@ -2068,7 +2074,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
 	/* Fallback to traversing the rbtree... */
 	maps__for_each_entry(maps, rb_node) {
 		map = rb_node->map;
-		if (strcmp(map->dso->short_name, name) == 0) {
+		if (strcmp(map__dso(map)->short_name, name) == 0) {
 			maps->last_search_by_name = map;
 			goto out_unlock;
 		}
tools/perf/util/symbol_fprintf.c +1 -1
index 2664fb65e47a..d9e5ad040b6a 100644
@@ -30,7 +30,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
 			if (al->addr < sym->end)
 				offset = al->addr - sym->start;
 			else
-				offset = al->addr - al->map->start - sym->start;
+				offset = al->addr - map__start(al->map) - sym->start;
 			length += fprintf(fp, "+0x%lx", offset);
 		}
 		return length;
tools/perf/util/synthetic-events.c +14 -14
index ed2d55d224aa..437fd57c2084 100644
@@ -668,33 +668,33 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
 			continue;
 
 		if (symbol_conf.buildid_mmap2) {
-			size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+			size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
 			event->mmap2.header.type = PERF_RECORD_MMAP2;
 			event->mmap2.header.size = (sizeof(event->mmap2) -
 						(sizeof(event->mmap2.filename) - size));
 			memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
 			event->mmap2.header.size += machine->id_hdr_size;
-			event->mmap2.start = map->start;
-			event->mmap2.len   = map->end - map->start;
+			event->mmap2.start = map__start(map);
+			event->mmap2.len   = map__end(map) - map__start(map);
 			event->mmap2.pid   = machine->pid;
 
-			memcpy(event->mmap2.filename, map->dso->long_name,
-			       map->dso->long_name_len + 1);
+			memcpy(event->mmap2.filename, map__dso(map)->long_name,
+			       map__dso(map)->long_name_len + 1);
 
 			perf_record_mmap2__read_build_id(&event->mmap2, false);
 		} else {
-			size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+			size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
 			event->mmap.header.type = PERF_RECORD_MMAP;
 			event->mmap.header.size = (sizeof(event->mmap) -
 						(sizeof(event->mmap.filename) - size));
 			memset(event->mmap.filename + size, 0, machine->id_hdr_size);
 			event->mmap.header.size += machine->id_hdr_size;
-			event->mmap.start = map->start;
-			event->mmap.len   = map->end - map->start;
+			event->mmap.start = map__start(map);
+			event->mmap.len   = map__end(map) - map__start(map);
 			event->mmap.pid   = machine->pid;
 
-			memcpy(event->mmap.filename, map->dso->long_name,
-			       map->dso->long_name_len + 1);
+			memcpy(event->mmap.filename, map__dso(map)->long_name,
+			       map__dso(map)->long_name_len + 1);
 		}
 
 		if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
@@ -1112,8 +1112,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 		event->mmap2.header.size = (sizeof(event->mmap2) -
 				(sizeof(event->mmap2.filename) - size) + machine->id_hdr_size);
 		event->mmap2.pgoff = kmap->ref_reloc_sym->addr;
-		event->mmap2.start = map->start;
-		event->mmap2.len   = map->end - event->mmap.start;
+		event->mmap2.start = map__start(map);
+		event->mmap2.len   = map__end(map) - event->mmap.start;
 		event->mmap2.pid   = machine->pid;
 
 		perf_record_mmap2__read_build_id(&event->mmap2, true);
@@ -1125,8 +1125,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 		event->mmap.header.size = (sizeof(event->mmap) -
 				(sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
 		event->mmap.pgoff = kmap->ref_reloc_sym->addr;
-		event->mmap.start = map->start;
-		event->mmap.len   = map->end - event->mmap.start;
+		event->mmap.start = map__start(map);
+		event->mmap.len   = map__end(map) - event->mmap.start;
 		event->mmap.pid   = machine->pid;
 	}
 
tools/perf/util/thread.c +13 -13
index c2256777b813..6fbcc115cc6d 100644
@@ -434,23 +434,23 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa
 int thread__memcpy(struct thread *thread, struct machine *machine,
 		   void *buf, u64 ip, int len, bool *is64bit)
 {
-       u8 cpumode = PERF_RECORD_MISC_USER;
-       struct addr_location al;
-       long offset;
+	u8 cpumode = PERF_RECORD_MISC_USER;
+	struct addr_location al;
+	long offset;
 
-       if (machine__kernel_ip(machine, ip))
-               cpumode = PERF_RECORD_MISC_KERNEL;
+	if (machine__kernel_ip(machine, ip))
+		cpumode = PERF_RECORD_MISC_KERNEL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
-	   al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
-	   map__load(al.map) < 0)
-               return -1;
+	if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map) ||
+		map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR ||
+		map__load(al.map) < 0)
+		return -1;
 
-       offset = al.map->map_ip(al.map, ip);
-       if (is64bit)
-               *is64bit = al.map->dso->is_64_bit;
+	offset = map__map_ip(al.map, ip);
+	if (is64bit)
+		*is64bit = map__dso(al.map)->is_64_bit;
 
-       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+	return dso__data_read_offset(map__dso(al.map), machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
tools/perf/util/unwind-libunwind-local.c +17 -17
index 7e6c59811292..841ac84a93ab 100644
@@ -381,20 +381,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 	int ret = -EINVAL;
 
 	map = find_map(ip, ui);
-	if (!map || !map->dso)
+	if (!map || !map__dso(map))
 		return -EINVAL;
 
-	pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
+	pr_debug("unwind: %s dso %s\n", __func__, map__dso(map)->name);
 
 	/* Check the .eh_frame section for unwinding info */
-	if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
+	if (!read_unwind_spec_eh_frame(map__dso(map), ui->machine,
 				       &table_data, &segbase, &fde_count)) {
 		memset(&di, 0, sizeof(di));
 		di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
-		di.start_ip = map->start;
-		di.end_ip   = map->end;
-		di.u.rti.segbase    = map->start + segbase - map->pgoff;
-		di.u.rti.table_data = map->start + table_data - map->pgoff;
+		di.start_ip = map__start(map);
+		di.end_ip   = map__end(map);
+		di.u.rti.segbase    = map__start(map) + segbase - map__pgoff(map);
+		di.u.rti.table_data = map__start(map) + table_data - map__pgoff(map);
 		di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
 				      / sizeof(unw_word_t);
 		ret = dwarf_search_unwind_table(as, ip, &di, pi,
@@ -404,20 +404,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 #ifndef NO_LIBUNWIND_DEBUG_FRAME
 	/* Check the .debug_frame section for unwinding info */
 	if (ret < 0 &&
-	    !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
-		int fd = dso__data_get_fd(map->dso, ui->machine);
-		int is_exec = elf_is_exec(fd, map->dso->name);
-		unw_word_t base = is_exec ? 0 : map->start;
+	    !read_unwind_spec_debug_frame(map__dso(map), ui->machine, &segbase)) {
+		int fd = dso__data_get_fd(map__dso(map), ui->machine);
+		int is_exec = elf_is_exec(fd, map__dso(map)->name);
+		unw_word_t base = is_exec ? 0 : map__start(map);
 		const char *symfile;
 
 		if (fd >= 0)
-			dso__data_put_fd(map->dso);
+			dso__data_put_fd(map__dso(map));
 
-		symfile = map->dso->symsrc_filename ?: map->dso->name;
+		symfile = map__dso(map)->symsrc_filename ?: map__dso(map)->name;
 
 		memset(&di, 0, sizeof(di));
 		if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
-					   map->start, map->end))
+					   map__start(map), map__end(map)))
 			return dwarf_search_unwind_table(as, ip, &di, pi,
 							 need_unwind_info, arg);
 	}
@@ -473,10 +473,10 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
 		return -1;
 	}
 
-	if (!map->dso)
+	if (!map__dso(map))
 		return -1;
 
-	size = dso__data_read_addr(map->dso, map, ui->machine,
+	size = dso__data_read_addr(map__dso(map), map, ui->machine,
 				   addr, (u8 *) data, sizeof(*data));
 
 	return !(size == sizeof(*data));
@@ -583,7 +583,7 @@ static int entry(u64 ip, struct thread *thread,
 	pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
 		 al.sym ? al.sym->name : "''",
 		 ip,
-		 al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
+		 al.map ? map__map_ip(al.map, ip) : (u64) 0);
 
 	return cb(&e, arg);
 }
tools/perf/util/unwind-libunwind.c +2 -2
index 7b797ffadd19..cece1ee89031 100644
@@ -30,7 +30,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 
 	if (maps__addr_space(maps)) {
 		pr_debug("unwind: thread map already set, dso=%s\n",
-			 map->dso->name);
+			 map__dso(map)->name);
 		if (initialized)
 			*initialized = true;
 		return 0;
@@ -41,7 +41,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 	if (!machine->env || !machine->env->arch)
 		goto out_register;
 
-	dso_type = dso__type(map->dso, machine);
+	dso_type = dso__type(map__dso(map), machine);
 	if (dso_type == DSO__TYPE_UNKNOWN)
 		return 0;
 
tools/perf/util/vdso.c +1 -1
index 835c39efb80d..ec777ee11493 100644
@@ -147,7 +147,7 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
 	struct map_rb_node *rb_node;
 
 	maps__for_each_entry(thread->maps, rb_node) {
-		struct dso *dso = rb_node->map->dso;
+		struct dso *dso = map__dso(rb_node->map);
 
 		if (!dso || dso->long_name[0] != '/')
 			continue;
Signature · 1 line
2.35.1.265.g69c8d7142f-goog
Signature · 1 line
- Arnaldo
#44 lore raw

Re: [PATCH v3 15/22] perf map: Use functions to access the variables in map

In reply to Ian Rogers

Em Fri, Feb 11, 2022 at 02:34:08AM -0800, Ian Rogers escreveu:

Quoted 66 lines

The use of functions enables easier reference count checking. Some minor changes to map_ip and unmap_ip to making the naming a little clearer. __maps_insert is modified to return the inserted map, which simplifies the reference checking wrapping. maps__fixup_overlappings has some minor tweaks so that puts occur on error paths. dso__process_kernel_symbol has the unused curr_mapp argument removed.

---
 tools/perf/arch/s390/annotate/instructions.c  |   4 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c      |   2 +-
 tools/perf/arch/x86/util/event.c              |   6 +-
 tools/perf/builtin-annotate.c                 |   8 +-
 tools/perf/builtin-inject.c                   |   8 +-
 tools/perf/builtin-kallsyms.c                 |   6 +-
 tools/perf/builtin-kmem.c                     |   4 +-
 tools/perf/builtin-mem.c                      |   4 +-
 tools/perf/builtin-report.c                   |  20 +--
 tools/perf/builtin-script.c                   |  26 ++--
 tools/perf/builtin-top.c                      |  12 +-
 tools/perf/builtin-trace.c                    |   2 +-
 .../scripts/python/Perf-Trace-Util/Context.c  |   7 +-
 tools/perf/tests/code-reading.c               |  32 ++---
 tools/perf/tests/hists_common.c               |   4 +-
 tools/perf/tests/vmlinux-kallsyms.c           |  35 +++---
 tools/perf/ui/browsers/annotate.c             |   7 +-
 tools/perf/ui/browsers/hists.c                |  18 +--
 tools/perf/ui/browsers/map.c                  |   4 +-
 tools/perf/util/annotate.c                    |  38 +++---
 tools/perf/util/auxtrace.c                    |   2 +-
 tools/perf/util/block-info.c                  |   4 +-
 tools/perf/util/bpf-event.c                   |   8 +-
 tools/perf/util/build-id.c                    |   2 +-
 tools/perf/util/callchain.c                   |  10 +-
 tools/perf/util/data-convert-json.c           |   4 +-
 tools/perf/util/db-export.c                   |   4 +-
 tools/perf/util/dlfilter.c                    |  21 ++--
 tools/perf/util/dso.c                         |   4 +-
 tools/perf/util/event.c                       |  14 +--
 tools/perf/util/evsel_fprintf.c               |   4 +-
 tools/perf/util/hist.c                        |  10 +-
 tools/perf/util/intel-pt.c                    |  48 +++----
 tools/perf/util/machine.c                     |  84 +++++++------
 tools/perf/util/map.c                         | 117 +++++++++---------
 tools/perf/util/map.h                         |  58 ++++++++-
 tools/perf/util/maps.c                        |  83 +++++++------
 tools/perf/util/probe-event.c                 |  44 +++----
 .../util/scripting-engines/trace-event-perl.c |   9 +-
 .../scripting-engines/trace-event-python.c    |  12 +-
 tools/perf/util/sort.c                        |  46 +++----
 tools/perf/util/symbol-elf.c                  |  39 +++---
 tools/perf/util/symbol.c                      |  96 +++++++-------
 tools/perf/util/symbol_fprintf.c              |   2 +-
 tools/perf/util/synthetic-events.c            |  28 ++---
 tools/perf/util/thread.c                      |  26 ++--
 tools/perf/util/unwind-libunwind-local.c      |  34 ++---
 tools/perf/util/unwind-libunwind.c            |   4 +-
 tools/perf/util/vdso.c                        |   2 +-
 49 files changed, 577 insertions(+), 489 deletions(-)
tools/perf/arch/s390/annotate/instructions.c +0 -0
index 0e136630659e..740f1a63bc04 100644

tools/perf/arch/s390/annotate/instructions.c static int s390_call__parse(struct arch *arch, struct ins_operands *ops, · line 44

Quoted 7 lines
tools/perf/arch/s390/annotate/instructions.c +3 -1
@@ -39,7 +39,9 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
 	target.addr = map__objdump_2mem(map, ops->target.addr);
 
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			     ) == ops->target.addr)

This changes nothing, right? Please try not to do this in the v2 for this patch.

- Arnaldo

Quoted 3,142 lines
tools/perf/arch/s390/annotate/instructions.c +0 -0
 		ops->target.sym = target.ms.sym;
 
 	return 0;
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index a54dea7c112f..497593be80f2 100644
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,
 		return -1;
 	}
 
-	stack_size = map->end - sp;
+	stack_size = map__end(map) - sp;
 	stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
 
 	memcpy(buf, (void *) sp, stack_size);
tools/perf/arch/x86/util/event.c +3 -3
index 7b6b0c98fb36..c790c682b76e 100644
@@ -57,9 +57,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
 
 		event->mmap.header.size = size;
 
-		event->mmap.start = map->start;
-		event->mmap.len   = map->end - map->start;
-		event->mmap.pgoff = map->pgoff;
+		event->mmap.start = map__start(map);
+		event->mmap.len   = map__size(map);
+		event->mmap.pgoff = map__pgoff(map);
 		event->mmap.pid   = machine->pid;
 
 		strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
tools/perf/builtin-annotate.c +4 -4
index 490bb9b8cf17..49d3ae36fd89 100644
@@ -199,7 +199,7 @@ static int process_branch_callback(struct evsel *evsel,
 		return 0;
 
 	if (a.map != NULL)
-		a.map->dso->hit = 1;
+		map__dso(a.map)->hit = 1;
 
 	hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
@@ -231,9 +231,9 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
 		 */
 		if (al->sym != NULL) {
 			rb_erase_cached(&al->sym->rb_node,
-				 &al->map->dso->symbols);
+					&map__dso(al->map)->symbols);
 			symbol__delete(al->sym);
-			dso__reset_find_symbol_cache(al->map->dso);
+			dso__reset_find_symbol_cache(map__dso(al->map));
 		}
 		return 0;
 	}
@@ -315,7 +315,7 @@ static void hists__find_annotations(struct hists *hists,
 		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
 		struct annotation *notes;
 
-		if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
+		if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
 			goto find_next;
 
 		if (ann->sym_hist_filter &&
tools/perf/builtin-inject.c +4 -4
index f7917c390e96..92a9dbc3d4cd 100644
@@ -600,10 +600,10 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
 	}
 
 	if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
-		if (!al.map->dso->hit) {
-			al.map->dso->hit = 1;
-			dso__inject_build_id(al.map->dso, tool, machine,
-					     sample->cpumode, al.map->flags);
+		if (!map__dso(al.map)->hit) {
+			map__dso(al.map)->hit = 1;
+			dso__inject_build_id(map__dso(al.map), tool, machine,
+					     sample->cpumode, map__flags(al.map));
 		}
 	}
 
tools/perf/builtin-kallsyms.c +4 -2
index c08ee81529e8..d940b60ce812 100644
@@ -36,8 +36,10 @@ static int __cmd_kallsyms(int argc, const char **argv)
 		}
 
 		printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
-			symbol->name, map->dso->short_name, map->dso->long_name,
-			map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
+			symbol->name, map__dso(map)->short_name,
+			map__dso(map)->long_name,
+			map__unmap_ip(map, symbol->start),
+			map__unmap_ip(map, symbol->end),
 			symbol->start, symbol->end);
 	}
 
tools/perf/builtin-kmem.c +2 -2
index 99d7ff9a8eff..d87d9c341a20 100644
@@ -410,7 +410,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
 		if (!caller) {
 			/* found */
 			if (node->ms.map)
-				addr = map__unmap_ip(node->ms.map, node->ip);
+				addr = map__dso_unmap_ip(node->ms.map, node->ip);
 			else
 				addr = node->ip;
 
@@ -1012,7 +1012,7 @@ static void __print_slab_result(struct rb_root *root,
 
 		if (sym != NULL)
 			snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
-				 addr - map->unmap_ip(map, sym->start));
+				 addr - map__unmap_ip(map, sym->start));
 		else
 			snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
 		printf(" %-34s |", buf);
tools/perf/builtin-mem.c +2 -2
index fcf65a59bea2..d18083f57303 100644
@@ -200,7 +200,7 @@ dump_raw_samples(struct perf_tool *tool,
 		goto out_put;
 
 	if (al.map != NULL)
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	field_sep = symbol_conf.field_sep;
 	if (field_sep) {
@@ -241,7 +241,7 @@ dump_raw_samples(struct perf_tool *tool,
 		symbol_conf.field_sep,
 		sample->data_src,
 		symbol_conf.field_sep,
-		al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+		al.map && map__dso(al.map) ? map__dso(al.map)->long_name : "???",
 		al.sym ? al.sym->name : "???");
 out_put:
 	addr_location__put(&al);
tools/perf/builtin-report.c +11 -9
index 57611ef725c3..9b92b2bbd7de 100644
@@ -304,7 +304,7 @@ static int process_sample_event(struct perf_tool *tool,
 	}
 
 	if (al.map != NULL)
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
 		hist__account_cycles(sample->branch_stack, &al, sample,
@@ -579,7 +579,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
 		return;
 
 	if (kernel_map == NULL ||
-	    (kernel_map->dso->hit &&
+	    (map__dso(kernel_map)->hit &&
 	     (kernel_kmap->ref_reloc_sym == NULL ||
 	      kernel_kmap->ref_reloc_sym->addr == 0))) {
 		const char *desc =
@@ -805,13 +805,15 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
 		struct map *map = rb_node->map;
 
 		printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
-				   indent, "", map->start, map->end,
-				   map->prot & PROT_READ ? 'r' : '-',
-				   map->prot & PROT_WRITE ? 'w' : '-',
-				   map->prot & PROT_EXEC ? 'x' : '-',
-				   map->flags & MAP_SHARED ? 's' : 'p',
-				   map->pgoff,
-				   map->dso->id.ino, map->dso->name);
+				   indent, "",
+				   map__start(map), map__end(map),
+				   map__prot(map) & PROT_READ ? 'r' : '-',
+				   map__prot(map) & PROT_WRITE ? 'w' : '-',
+				   map__prot(map) & PROT_EXEC ? 'x' : '-',
+				   map__flags(map) & MAP_SHARED ? 's' : 'p',
+				   map__pgoff(map),
+				   map__dso(map)->id.ino,
+				   map__dso(map)->name);
 	}
 
 	return printed;
tools/perf/builtin-script.c +13 -13
index abae8184e171..4edfce95e137 100644
@@ -972,12 +972,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
 		to   = entries[i].to;
 
 		if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
-		    !alf.map->dso->adjust_symbols)
-			from = map__map_ip(alf.map, from);
+		    !map__dso(alf.map)->adjust_symbols)
+			from = map__dso_map_ip(alf.map, from);
 
 		if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
-		    !alt.map->dso->adjust_symbols)
-			to = map__map_ip(alt.map, to);
+		    !map__dso(alt.map)->adjust_symbols)
+			to = map__dso_map_ip(alt.map, to);
 
 		printed += fprintf(fp, " 0x%"PRIx64, from);
 		if (PRINT_FIELD(DSO)) {
@@ -1039,11 +1039,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 		return 0;
 	}
 
-	if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
+	if (!thread__find_map(thread, *cpumode, start, &al) || !map__dso(al.map)) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
 	}
-	if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
+	if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
 	}
@@ -1051,11 +1051,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 	/* Load maps to ensure dso->is_64_bit has been updated */
 	map__load(al.map);
 
-	offset = al.map->map_ip(al.map, start);
-	len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
-				    end - start + MAXINSN);
+	offset = map__map_ip(al.map, start);
+	len = dso__data_read_offset(map__dso(al.map), machine, offset,
+				    (u8 *)buffer, end - start + MAXINSN);
 
-	*is64bit = al.map->dso->is_64_bit;
+	*is64bit = map__dso(al.map)->is_64_bit;
 	if (len <= 0)
 		pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
 			start, end);
@@ -1070,9 +1070,9 @@ static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srcc
 	int len;
 	char *srccode;
 
-	if (!map || !map->dso)
+	if (!map || !map__dso(map))
 		return 0;
-	srcfile = get_srcline_split(map->dso,
+	srcfile = get_srcline_split(map__dso(map),
 				    map__rip_2objdump(map, addr),
 				    &line);
 	if (!srcfile)
@@ -1164,7 +1164,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 	if (al.addr < al.sym->end)
 		off = al.addr - al.sym->start;
 	else
-		off = al.addr - al.map->start - al.sym->start;
+		off = al.addr - map__start(al.map) - al.sym->start;
 	printed += fprintf(fp, "\t%s", al.sym->name);
 	if (off)
 		printed += fprintf(fp, "%+d", off);
tools/perf/builtin-top.c +7 -5
index 1fc390f136dd..8db1df7bdabe 100644
@@ -127,8 +127,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
 	/*
 	 * We can't annotate with just /proc/kallsyms
 	 */
-	if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-	    !dso__is_kcore(map->dso)) {
+	if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+	    !dso__is_kcore(map__dso(map))) {
 		pr_err("Can't annotate %s: No vmlinux file was found in the "
 		       "path\n", sym->name);
 		sleep(1);
@@ -180,8 +180,9 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
 		    "Tools:  %s\n\n"
 		    "Not all samples will be on the annotation output.\n\n"
 		    "Please report to [email protected]\n",
-		    ip, map->dso->long_name, dso__symtab_origin(map->dso),
-		    map->start, map->end, sym->start, sym->end,
+		    ip, map__dso(map)->long_name,
+		    dso__symtab_origin(map__dso(map)),
+		    map__start(map), map__end(map), sym->start, sym->end,
 		    sym->binding == STB_GLOBAL ? 'g' :
 		    sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
 		    err ? "[unknown]" : uts.machine,
@@ -810,7 +811,8 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		    __map__is_kernel(al.map) && map__has_symbols(al.map)) {
 			if (symbol_conf.vmlinux_name) {
 				char serr[256];
-				dso__strerror_load(al.map->dso, serr, sizeof(serr));
+				dso__strerror_load(map__dso(al.map),
+						   serr, sizeof(serr));
 				ui__warning("The %s file can't be used: %s\n%s",
 					    symbol_conf.vmlinux_name, serr, msg);
 			} else {
tools/perf/builtin-trace.c +1 -1
index 32844d8a0ea5..0134f24da3e3 100644
@@ -2862,7 +2862,7 @@ static void print_location(FILE *f, struct perf_sample *sample,
 {
 
 	if ((verbose > 0 || print_dso) && al->map)
-		fprintf(f, "%s@", al->map->dso->long_name);
+		fprintf(f, "%s@", map__dso(al->map)->long_name);
 
 	if ((verbose > 0 || print_sym) && al->sym)
 		fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/scripts/python/Perf-Trace-Util/Context.c +4 -3
index b64013a87c54..b83b62d33945 100644
@@ -152,9 +152,10 @@ static PyObject *perf_sample_src(PyObject *obj, PyObject *args, bool get_srccode
 	map = c->al->map;
 	addr = c->al->addr;
 
-	if (map && map->dso)
-		srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+	if (map && map__dso(map)) {
+		srcfile = get_srcline_split(map__dso(map),
+					    map__rip_2objdump(map, addr), &line);
+	}
 	if (get_srccode) {
 		if (srcfile)
 			srccode = find_sourceline(srcfile, line, &len);
tools/perf/tests/code-reading.c +16 -16
index 6eafe36a8704..9cb7d3f577d7 100644
@@ -240,7 +240,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
 	pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-	if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
+	if (!thread__find_map(thread, cpumode, addr, &al) || !map__dso(al.map)) {
 		if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
 			pr_debug("Hypervisor address can not be resolved - skipping\n");
 			return 0;
@@ -250,10 +250,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		return -1;
 	}
 
-	pr_debug("File is: %s\n", al.map->dso->long_name);
+	pr_debug("File is: %s\n", map__dso(al.map)->long_name);
 
-	if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-	    !dso__is_kcore(al.map->dso)) {
+	if (map__dso(al.map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+	    !dso__is_kcore(map__dso(al.map))) {
 		pr_debug("Unexpected kernel address - skipping\n");
 		return 0;
 	}
@@ -264,11 +264,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		len = BUFSZ;
 
 	/* Do not go off the map */
-	if (addr + len > al.map->end)
-		len = al.map->end - addr;
+	if (addr + len > map__end(al.map))
+		len = map__end(al.map) - addr;
 
 	/* Read the object code using perf */
-	ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
+	ret_len = dso__data_read_offset(map__dso(al.map), maps__machine(thread->maps),
 					al.addr, buf1, len);
 	if (ret_len != len) {
 		pr_debug("dso__data_read_offset failed\n");
@@ -283,11 +283,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 		return -1;
 
 	/* objdump struggles with kcore - try each map only once */
-	if (dso__is_kcore(al.map->dso)) {
+	if (dso__is_kcore(map__dso(al.map))) {
 		size_t d;
 
 		for (d = 0; d < state->done_cnt; d++) {
-			if (state->done[d] == al.map->start) {
+			if (state->done[d] == map__start(al.map)) {
 				pr_debug("kcore map tested already");
 				pr_debug(" - skipping\n");
 				return 0;
@@ -297,12 +297,12 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			pr_debug("Too many kcore maps - skipping\n");
 			return 0;
 		}
-		state->done[state->done_cnt++] = al.map->start;
+		state->done[state->done_cnt++] = map__start(al.map);
 	}
 
-	objdump_name = al.map->dso->long_name;
-	if (dso__needs_decompress(al.map->dso)) {
-		if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+	objdump_name = map__dso(al.map)->long_name;
+	if (dso__needs_decompress(map__dso(al.map))) {
+		if (dso__decompress_kmodule_path(map__dso(al.map), objdump_name,
 						 decomp_name,
 						 sizeof(decomp_name)) < 0) {
 			pr_debug("decompression failed\n");
@@ -330,7 +330,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			len -= ret;
 			if (len) {
 				pr_debug("Reducing len to %zu\n", len);
-			} else if (dso__is_kcore(al.map->dso)) {
+			} else if (dso__is_kcore(map__dso(al.map))) {
 				/*
 				 * objdump cannot handle very large segments
 				 * that may be found in kcore.
@@ -588,8 +588,8 @@ static int do_test_code_reading(bool try_kcore)
 		pr_debug("map__load failed\n");
 		goto out_err;
 	}
-	have_vmlinux = dso__is_vmlinux(map->dso);
-	have_kcore = dso__is_kcore(map->dso);
+	have_vmlinux = dso__is_vmlinux(map__dso(map));
+	have_kcore = dso__is_kcore(map__dso(map));
 
 	/* 2nd time through we just try kcore */
 	if (try_kcore && !have_kcore)
tools/perf/tests/hists_common.c +2 -2
index 6f34d08b84e5..40eccc659767 100644
@@ -181,7 +181,7 @@ void print_hists_in(struct hists *hists)
 		if (!he->filtered) {
 			pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
 				i, thread__comm_str(he->thread),
-				he->ms.map->dso->short_name,
+				map__dso(he->ms.map)->short_name,
 				he->ms.sym->name, he->stat.period);
 		}
 
@@ -208,7 +208,7 @@ void print_hists_out(struct hists *hists)
 		if (!he->filtered) {
 			pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
 				i, thread__comm_str(he->thread), he->thread->tid,
-				he->ms.map->dso->short_name,
+				map__dso(he->ms.map)->short_name,
 				he->ms.sym->name, he->stat.period,
 				he->stat_acc ? he->stat_acc->period : 0);
 		}
tools/perf/tests/vmlinux-kallsyms.c +19 -16
index 11a230ee5894..5afab21455f1 100644
@@ -13,7 +13,7 @@
 #include "debug.h"
 #include "machine.h"
 
-#define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
+#define UM(x) map__unmap_ip(kallsyms_map, (x))
 
 static bool is_ignored_symbol(const char *name, char type)
 {
@@ -216,8 +216,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 		if (sym->start == sym->end)
 			continue;
 
-		mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
-		mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
+		mem_start = map__unmap_ip(vmlinux_map, sym->start);
+		mem_end = map__unmap_ip(vmlinux_map, sym->end);
 
 		first_pair = machine__find_kernel_symbol(&kallsyms, mem_start, NULL);
 		pair = first_pair;
@@ -262,7 +262,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 
 				continue;
 			}
-		} else if (mem_start == kallsyms.vmlinux_map->end) {
+		} else if (mem_start == map__end(kallsyms.vmlinux_map)) {
 			/*
 			 * Ignore aliases to _etext, i.e. to the end of the kernel text area,
 			 * such as __indirect_thunk_end.
@@ -294,9 +294,10 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 		 * so use the short name, less descriptive but the same ("[kernel]" in
 		 * both cases.
 		 */
-		struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
-								map->dso->short_name :
-								map->dso->name));
+		struct map *pair = maps__find_by_name(kallsyms.kmaps,
+						map__dso(map)->kernel
+						? map__dso(map)->short_name
+						: map__dso(map)->name);
 		if (pair) {
 			pair->priv = 1;
 		} else {
@@ -313,25 +314,27 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 	maps__for_each_entry(maps, rb_node) {
 		struct map *pair, *map = rb_node->map;
 
-		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
-		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
+		mem_start = map__unmap_ip(vmlinux_map, map__start(map));
+		mem_end = map__unmap_ip(vmlinux_map, map__end(map));
 
 		pair = maps__find(kallsyms.kmaps, mem_start);
-		if (pair == NULL || pair->priv)
+		if (pair == NULL || map__priv(pair))
 			continue;
 
-		if (pair->start == mem_start) {
+		if (map__start(pair) == mem_start) {
 			if (!header_printed) {
 				pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
 				header_printed = true;
 			}
 
 			pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
-				map->start, map->end, map->pgoff, map->dso->name);
-			if (mem_end != pair->end)
+				map__start(map), map__end(map),
+				map__pgoff(map), map__dso(map)->name);
+			if (mem_end != map__end(pair))
 				pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
-					pair->start, pair->end, pair->pgoff);
-			pr_info(" %s\n", pair->dso->name);
+					map__start(pair), map__end(pair),
+					map__pgoff(pair));
+			pr_info(" %s\n", map__dso(pair)->name);
 			pair->priv = 1;
 		}
 	}
@@ -343,7 +346,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 	maps__for_each_entry(maps, rb_node) {
 		struct map *map = rb_node->map;
 
-		if (!map->priv) {
+		if (!map__priv(map)) {
 			if (!header_printed) {
 				pr_info("WARN: Maps only in kallsyms:\n");
 				header_printed = true;
tools/perf/ui/browsers/annotate.c +4 -3
index 44ba900828f6..7d51d92302dc 100644
@@ -446,7 +446,8 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 static int sym_title(struct symbol *sym, struct map *map, char *title,
 		     size_t sz, int percent_type)
 {
-	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+			map__dso(map)->long_name,
 			percent_type_str(percent_type));
 }
 
@@ -971,14 +972,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
 	if (sym == NULL)
 		return -1;
 
-	if (ms->map->dso->annotate_warned)
+	if (map__dso(ms->map)->annotate_warned)
 		return -1;
 
 	if (not_annotated) {
 		err = symbol__annotate2(ms, evsel, opts, &browser.arch);
 		if (err) {
 			char msg[BUFSIZ];
-			ms->map->dso->annotate_warned = true;
+			map__dso(ms->map)->annotate_warned = true;
 			symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
 			ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
 			goto out_free_offsets;
tools/perf/ui/browsers/hists.c +11 -7
index 572ff38ceb0f..2241447e9bfb 100644
@@ -2487,7 +2487,7 @@ static struct symbol *symbol__new_unresolved(u64 addr, struct map *map)
 			return NULL;
 		}
 
-		dso__insert_symbol(map->dso, sym);
+		dso__insert_symbol(map__dso(map), sym);
 	}
 
 	return sym;
@@ -2499,7 +2499,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
 		 struct map_symbol *ms,
 		 u64 addr)
 {
-	if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
+	if (!ms->map || !map__dso(ms->map) || map__dso(ms->map)->annotate_warned)
 		return 0;
 
 	if (!ms->sym)
@@ -2590,8 +2590,10 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map
 		ui_helpline__pop();
 	} else {
 		ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
-				   __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
-		browser->hists->dso_filter = map->dso;
+				   __map__is_kernel(map)
+				   ? "the Kernel"
+				   : map__dso(map)->short_name);
+		browser->hists->dso_filter = map__dso(map);
 		perf_hpp__set_elide(HISTC_DSO, true);
 		pstack__push(browser->pstack, &browser->hists->dso_filter);
 	}
@@ -2616,7 +2618,9 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,
 
 	if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
 		     browser->hists->dso_filter ? "out of" : "into",
-		     __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
+		     __map__is_kernel(map)
+		     ? "the Kernel"
+		     : map__dso(map)->short_name) < 0)
 		return 0;
 
 	act->ms.map = map;
@@ -3091,8 +3095,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
 
 			if (!browser->selection ||
 			    !browser->selection->map ||
-			    !browser->selection->map->dso ||
-			    browser->selection->map->dso->annotate_warned) {
+			    !map__dso(browser->selection->map) ||
+			    map__dso(browser->selection->map)->annotate_warned) {
 				continue;
 			}
 
tools/perf/ui/browsers/map.c +2 -2
index 3d49b916c9e4..3d1b958d8832 100644
@@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser)
 {
 	int key;
 
-	if (ui_browser__show(&browser->b, browser->map->dso->long_name,
+	if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name,
 			     "Press ESC to exit, %s / to search",
 			     verbose > 0 ? "" : "restart with -v to use") < 0)
 		return -1;
@@ -106,7 +106,7 @@ int map__browse(struct map *map)
 {
 	struct map_browser mb = {
 		.b = {
-			.entries = &map->dso->symbols,
+			.entries = &map__dso(map)->symbols,
 			.refresh = ui_browser__rb_tree_refresh,
 			.seek	 = ui_browser__rb_tree_seek,
 			.write	 = map_browser__write,
tools/perf/util/annotate.c +21 -17
index 01900689dc00..3a7433d3e48a 100644
@@ -280,7 +280,9 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	target.addr = map__objdump_2mem(map, ops->target.addr);
 
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			      ) == ops->target.addr)
 		ops->target.sym = target.ms.sym;
 
 	return 0;
@@ -384,8 +386,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	}
 
 	target.addr = map__objdump_2mem(map, ops->target.addr);
-	start = map->unmap_ip(map, sym->start),
-	end = map->unmap_ip(map, sym->end);
+	start = map__unmap_ip(map, sym->start),
+	end = map__unmap_ip(map, sym->end);
 
 	ops->target.outside = target.addr < start || target.addr > end;
 
@@ -408,7 +410,9 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
 	 * the symbol searching and disassembly should be done.
 	 */
 	if (maps__find_ams(ms->maps, &target) == 0 &&
-	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+	    map__rip_2objdump(target.ms.map,
+			      map->map_ip(target.ms.map, target.addr)
+			      ) == ops->target.addr)
 		ops->target.sym = target.ms.sym;
 
 	if (!ops->target.outside) {
@@ -889,7 +893,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms,
 	unsigned offset;
 	struct sym_hist *h;
 
-	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, ms->map->unmap_ip(ms->map, addr));
+	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map__unmap_ip(ms->map, addr));
 
 	if ((addr < sym->start || addr >= sym->end) &&
 	    (addr != sym->end || sym->start != sym->end)) {
@@ -1016,13 +1020,13 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
 	if (start &&
 		(start->ms.sym == ams->ms.sym ||
 		 (ams->ms.sym &&
-		   start->addr == ams->ms.sym->start + ams->ms.map->start)))
+		  start->addr == ams->ms.sym->start + map__start(ams->ms.map))))
 		saddr = start->al_addr;
 	if (saddr == 0)
 		pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n",
 			ams->addr,
 			start ? start->addr : 0,
-			ams->ms.sym ? ams->ms.sym->start + ams->ms.map->start : 0,
+			ams->ms.sym ? ams->ms.sym->start + map__start(ams->ms.map) : 0,
 			saddr);
 	err = symbol__account_cycles(ams->al_addr, saddr, ams->ms.sym, cycles);
 	if (err)
@@ -1593,7 +1597,7 @@ static void delete_last_nop(struct symbol *sym)
 
 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 
 	BUG_ON(buflen == 0);
 
@@ -1723,7 +1727,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
 	struct map *map = args->ms.map;
 	struct perf_bpil *info_linear;
 	struct disassemble_info info;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	int pc = 0, count, sub_id;
 	struct btf *btf = NULL;
 	char tpath[PATH_MAX];
@@ -1946,7 +1950,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 {
 	struct annotation_options *opts = args->options;
 	struct map *map = args->ms.map;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	char *command;
 	FILE *file;
 	char symfs_filename[PATH_MAX];
@@ -1973,8 +1977,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 		return err;
 
 	pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
-		 symfs_filename, sym->name, map->unmap_ip(map, sym->start),
-		 map->unmap_ip(map, sym->end));
+		 symfs_filename, sym->name, map__unmap_ip(map, sym->start),
+		 map__unmap_ip(map, sym->end));
 
 	pr_debug("annotating [%p] %30s : [%p] %30s\n",
 		 dso, dso->long_name, sym, sym->name);
@@ -2386,7 +2390,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
 {
 	struct map *map = ms->map;
 	struct symbol *sym = ms->sym;
-	struct dso *dso = map->dso;
+	struct dso *dso = map__dso(map);
 	char *filename;
 	const char *d_filename;
 	const char *evsel_name = evsel__name(evsel);
@@ -2569,7 +2573,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
 	}
 
 	fprintf(fp, "%s() %s\nEvent: %s\n\n",
-		ms->sym->name, ms->map->dso->long_name, ev_name);
+		ms->sym->name, map__dso(ms->map)->long_name, ev_name);
 	symbol__annotate_fprintf2(ms->sym, fp, opts);
 
 	fclose(fp);
@@ -2781,7 +2785,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		if (percent_max <= 0.5)
 			continue;
 
-		al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
+		al->path = get_srcline(map__dso(map), notes->start + al->offset, NULL,
 				       false, true, notes->start + al->offset);
 		insert_source_line(&tmp_root, al, opts);
 	}
@@ -2800,7 +2804,7 @@ static void symbol__calc_lines(struct map_symbol *ms, struct rb_root *root,
 int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 			  struct annotation_options *opts)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 	struct symbol *sym = ms->sym;
 	struct rb_root source_line = RB_ROOT;
 	struct hists *hists = evsel__hists(evsel);
@@ -2836,7 +2840,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel,
 			 struct annotation_options *opts)
 {
-	struct dso *dso = ms->map->dso;
+	struct dso *dso = map__dso(ms->map);
 	struct symbol *sym = ms->sym;
 	struct rb_root source_line = RB_ROOT;
 	int err;
tools/perf/util/auxtrace.c +1 -1
index 825336304a37..2e864c9bdef3 100644
@@ -2478,7 +2478,7 @@ static struct dso *load_dso(const char *name)
 	if (map__load(map) < 0)
 		pr_err("File '%s' not found or has no symbols.\n", name);
 
-	dso = dso__get(map->dso);
+	dso = dso__get(map__dso(map));
 
 	map__put(map);
 
tools/perf/util/block-info.c +2 -2
index 5ecd4f401f32..16a7b4adcf18 100644
@@ -317,9 +317,9 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 	struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
 	struct map *map = he->ms.map;
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
-				 map->dso->short_name);
+				 map__dso(map)->short_name);
 	}
 
 	return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
tools/perf/util/bpf-event.c +4 -4
index 33257b594a71..5717933be116 100644
@@ -95,10 +95,10 @@ static int machine__process_bpf_event_load(struct machine *machine,
 		struct map *map = maps__find(machine__kernel_maps(machine), addr);
 
 		if (map) {
-			map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
-			map->dso->bpf_prog.id = id;
-			map->dso->bpf_prog.sub_id = i;
-			map->dso->bpf_prog.env = env;
+			map__dso(map)->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+			map__dso(map)->bpf_prog.id = id;
+			map__dso(map)->bpf_prog.sub_id = i;
+			map__dso(map)->bpf_prog.env = env;
 		}
 	}
 	return 0;
tools/perf/util/build-id.c +1 -1
index 7a5821c87f94..274b705dd941 100644
@@ -59,7 +59,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
 	}
 
 	if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
-		al.map->dso->hit = 1;
+		map__dso(al.map)->hit = 1;
 
 	thread__put(thread);
 	return 0;
tools/perf/util/callchain.c +5 -5
index 61bb3fb2107a..a8cfd31a3ff0 100644
@@ -695,8 +695,8 @@ static enum match_result match_chain_strings(const char *left,
 static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
 						   struct map *right_map, u64 right_ip)
 {
-	struct dso *left_dso = left_map ? left_map->dso : NULL;
-	struct dso *right_dso = right_map ? right_map->dso : NULL;
+	struct dso *left_dso = left_map ? map__dso(left_map) : NULL;
+	struct dso *right_dso = right_map ? map__dso(right_map) : NULL;
 
 	if (left_dso != right_dso)
 		return left_dso < right_dso ? MATCH_LT : MATCH_GT;
@@ -1167,9 +1167,9 @@ char *callchain_list__sym_name(struct callchain_list *cl,
 
 	if (show_dso)
 		scnprintf(bf + printed, bfsize - printed, " %s",
-			  cl->ms.map ?
-			  cl->ms.map->dso->short_name :
-			  "unknown");
+			  cl->ms.map
+			  ? map__dso(cl->ms.map)->short_name
+			  : "unknown");
 
 	return bf;
 }
tools/perf/util/data-convert-json.c +2 -2
index f1ab6edba446..9c83228bb9f1 100644
@@ -127,8 +127,8 @@ static void output_sample_callchain_entry(struct perf_tool *tool,
 		fputc(',', out);
 		output_json_key_string(out, false, 5, "symbol", al->sym->name);
 
-		if (al->map && al->map->dso) {
-			const char *dso = al->map->dso->short_name;
+		if (al->map && map__dso(al->map)) {
+			const char *dso = map__dso(al->map)->short_name;
 
 			if (dso && strlen(dso) > 0) {
 				fputc(',', out);
tools/perf/util/db-export.c +2 -2
index 1cfcfdd3cf52..84c970c11794 100644
@@ -179,7 +179,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
 	int err;
 
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		err = db_export__dso(dbe, dso, maps__machine(al->maps));
 		if (err)
@@ -255,7 +255,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
 		al.addr = node->ip;
 
 		if (al.map && !al.sym)
-			al.sym = dso__find_symbol(al.map->dso, al.addr);
+			al.sym = dso__find_symbol(map__dso(al.map), al.addr);
 
 		db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
tools/perf/util/dlfilter.c +11 -10
index d59462af15f1..f1d9dd7065e6 100644
@@ -29,7 +29,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 
 	d_al->size = sizeof(*d_al);
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		if (symbol_conf.show_kernel_path && dso->long_name)
 			d_al->dso = dso->long_name;
@@ -51,7 +51,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 		if (al->addr < sym->end)
 			d_al->symoff = al->addr - sym->start;
 		else
-			d_al->symoff = al->addr - al->map->start - sym->start;
+			d_al->symoff = al->addr - map__start(al->map) - sym->start;
 		d_al->sym_binding = sym->binding;
 	} else {
 		d_al->sym = NULL;
@@ -232,9 +232,10 @@ static const char *dlfilter__srcline(void *ctx, __u32 *line_no)
 	map = al->map;
 	addr = al->addr;
 
-	if (map && map->dso)
-		srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+	if (map && map__dso(map)) {
+		srcfile = get_srcline_split(map__dso(map),
+					    map__rip_2objdump(map, addr), &line);
+	}
 	*line_no = line;
 	return srcfile;
 }
@@ -266,7 +267,7 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
 	map = al->map;
 
-	if (map && ip >= map->start && ip < map->end &&
+	if (map && ip >= map__start(map) && ip < map__end(map) &&
 	    machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
 		goto have_map;
 
@@ -276,10 +277,10 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
 	map = a.map;
 have_map:
-	offset = map->map_ip(map, ip);
-	if (ip + len >= map->end)
-		len = map->end - ip;
-	return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
+	offset = map__map_ip(map, ip);
+	if (ip + len >= map__end(map))
+		len = map__end(map) - ip;
+	return dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
 }
 
 static const struct perf_dlfilter_fns perf_dlfilter_fns = {
tools/perf/util/dso.c +2 -2
index b2f570adba35..1115bc51a261 100644
@@ -1109,7 +1109,7 @@ ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
 			    struct machine *machine, u64 addr,
 			    u8 *data, ssize_t size)
 {
-	u64 offset = map->map_ip(map, addr);
+	u64 offset = map__map_ip(map, addr);
 	return dso__data_read_offset(dso, machine, offset, data, size);
 }
 
@@ -1149,7 +1149,7 @@ ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
 				   struct machine *machine, u64 addr,
 				   const u8 *data, ssize_t size)
 {
-	u64 offset = map->map_ip(map, addr);
+	u64 offset = map__map_ip(map, addr);
 	return dso__data_write_cache_offs(dso, machine, offset, data, size);
 }
 
tools/perf/util/event.c +7 -7
index 40a3b1a35613..54a1d4df5f70 100644
@@ -486,7 +486,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
 
 		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.addr = map__map_ip(al.map, tp->addr);
 			al.sym = map__find_symbol(al.map, al.addr);
 			if (al.sym)
 				ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
@@ -621,7 +621,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		 */
 		if (load_map)
 			map__load(al->map);
-		al->addr = al->map->map_ip(al->map, al->addr);
+		al->addr = map__map_ip(al->map, al->addr);
 	}
 
 	return al->map;
@@ -692,8 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
 	thread__find_map(thread, sample->cpumode, sample->ip, al);
 	dump_printf(" ...... dso: %s\n",
-		    al->map ? al->map->dso->long_name :
-			al->level == 'H' ? "[hypervisor]" : "<not found>");
+		    al->map ? map__dso(al->map)->long_name
+			    : al->level == 'H' ? "[hypervisor]" : "<not found>");
 
 	if (thread__is_filtered(thread))
 		al->filtered |= (1 << HIST_FILTER__THREAD);
@@ -711,7 +711,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 	}
 
 	if (al->map) {
-		struct dso *dso = al->map->dso;
+		struct dso *dso = map__dso(al->map);
 
 		if (symbol_conf.dso_list &&
 		    (!dso || !(strlist__has_entry(symbol_conf.dso_list,
@@ -738,12 +738,12 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 		}
 		if (!ret && al->sym) {
 			snprintf(al_addr_str, sz, "0x%"PRIx64,
-				al->map->unmap_ip(al->map, al->sym->start));
+				 map__unmap_ip(al->map, al->sym->start));
 			ret = strlist__has_entry(symbol_conf.sym_list,
 						al_addr_str);
 		}
 		if (!ret && symbol_conf.addr_list && al->map) {
-			unsigned long addr = al->map->unmap_ip(al->map, al->addr);
+			unsigned long addr = map__unmap_ip(al->map, al->addr);
 
 			ret = intlist__has_entry(symbol_conf.addr_list, addr);
 			if (!ret && symbol_conf.addr_range) {
tools/perf/util/evsel_fprintf.c +2 -2
index 8c2ea8001329..ac6fef9d8906 100644
@@ -146,11 +146,11 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
 				printed += fprintf(fp, " <-");
 
 			if (map)
-				addr = map->map_ip(map, node->ip);
+				addr = map__map_ip(map, node->ip);
 
 			if (print_ip) {
 				/* Show binary offset for userspace addr */
-				if (map && !map->dso->kernel)
+				if (map && !map__dso(map)->kernel)
 					printed += fprintf(fp, "%c%16" PRIx64, s, addr);
 				else
 					printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
tools/perf/util/hist.c +5 -5
index 78f9fbb925a7..f19ac6eb4775 100644
@@ -105,7 +105,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		hists__set_col_len(hists, HISTC_THREAD, len + 8);
 
 	if (h->ms.map) {
-		len = dso__name_len(h->ms.map->dso);
+		len = dso__name_len(map__dso(h->ms.map));
 		hists__new_col_len(hists, HISTC_DSO, len);
 	}
 
@@ -119,7 +119,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
-			symlen = dso__name_len(h->branch_info->from.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->branch_info->from.ms.map));
 			hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
 		} else {
 			symlen = unresolved_col_width + 4 + 2;
@@ -133,7 +133,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 				symlen += BITS_PER_LONG / 4 + 2 + 3;
 			hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
-			symlen = dso__name_len(h->branch_info->to.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->branch_info->to.ms.map));
 			hists__new_col_len(hists, HISTC_DSO_TO, symlen);
 		} else {
 			symlen = unresolved_col_width + 4 + 2;
@@ -177,7 +177,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		}
 
 		if (h->mem_info->daddr.ms.map) {
-			symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
+			symlen = dso__name_len(map__dso(h->mem_info->daddr.ms.map));
 			hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
 					   symlen);
 		} else {
@@ -2096,7 +2096,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
 				       struct hist_entry *he)
 {
 	if (hists->dso_filter != NULL &&
-	    (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
+	    (he->ms.map == NULL || map__dso(he->ms.map) != hists->dso_filter)) {
 		he->filtered |= (1 << HIST_FILTER__DSO);
 		return true;
 	}
tools/perf/util/intel-pt.c +24 -24
index e8613cbda331..c88f112c0a06 100644
@@ -731,20 +731,20 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	}
 
 	while (1) {
-		if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
+		if (!thread__find_map(thread, cpumode, *ip, &al) || !map__dso(al.map))
 			return -EINVAL;
 
-		if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-		    dso__data_status_seen(al.map->dso,
+		if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR &&
+		    dso__data_status_seen(map__dso(al.map),
 					  DSO_DATA_STATUS_SEEN_ITRACE))
 			return -ENOENT;
 
-		offset = al.map->map_ip(al.map, *ip);
+		offset = map__map_ip(al.map, *ip);
 
 		if (!to_ip && one_map) {
 			struct intel_pt_cache_entry *e;
 
-			e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+			e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
 			if (e &&
 			    (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) {
 				*insn_cnt_ptr = e->insn_cnt;
@@ -766,10 +766,10 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 		/* Load maps to ensure dso->is_64_bit has been updated */
 		map__load(al.map);
 
-		x86_64 = al.map->dso->is_64_bit;
+		x86_64 = map__dso(al.map)->is_64_bit;
 
 		while (1) {
-			len = dso__data_read_offset(al.map->dso, machine,
+			len = dso__data_read_offset(map__dso(al.map), machine,
 						    offset, buf,
 						    INTEL_PT_INSN_BUF_SZ);
 			if (len <= 0)
@@ -795,7 +795,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 				goto out_no_cache;
 			}
 
-			if (*ip >= al.map->end)
+			if (*ip >= map__end(al.map))
 				break;
 
 			offset += intel_pt_insn->length;
@@ -815,13 +815,13 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	if (to_ip) {
 		struct intel_pt_cache_entry *e;
 
-		e = intel_pt_cache_lookup(al.map->dso, machine, start_offset);
+		e = intel_pt_cache_lookup(map__dso(al.map), machine, start_offset);
 		if (e)
 			return 0;
 	}
 
 	/* Ignore cache errors */
-	intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt,
+	intel_pt_cache_add(map__dso(al.map), machine, start_offset, insn_cnt,
 			   *ip - start_ip, intel_pt_insn);
 
 	return 0;
@@ -892,13 +892,13 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
 	if (!thread)
 		return -EINVAL;
 
-	if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
+	if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map))
 		return -EINVAL;
 
-	offset = al.map->map_ip(al.map, ip);
+	offset = map__map_ip(al.map, ip);
 
 	return intel_pt_match_pgd_ip(ptq->pt, ip, offset,
-				     al.map->dso->long_name);
+				     map__dso(al.map)->long_name);
 }
 
 static bool intel_pt_pgd_ip(uint64_t ip, void *data)
@@ -2406,13 +2406,13 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 	if (map__load(map))
 		return 0;
 
-	start = dso__first_symbol(map->dso);
+	start = dso__first_symbol(map__dso(map));
 
 	for (sym = start; sym; sym = dso__next_symbol(sym)) {
 		if (sym->binding == STB_GLOBAL &&
 		    !strcmp(sym->name, "__switch_to")) {
-			ip = map->unmap_ip(map, sym->start);
-			if (ip >= map->start && ip < map->end) {
+			ip = map__unmap_ip(map, sym->start);
+			if (ip >= map__start(map) && ip < map__end(map)) {
 				switch_ip = ip;
 				break;
 			}
@@ -2429,8 +2429,8 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 
 	for (sym = start; sym; sym = dso__next_symbol(sym)) {
 		if (!strcmp(sym->name, ptss)) {
-			ip = map->unmap_ip(map, sym->start);
-			if (ip >= map->start && ip < map->end) {
+			ip = map__unmap_ip(map, sym->start);
+			if (ip >= map__start(map) && ip < map__end(map)) {
 				*ptss_ip = ip;
 				break;
 			}
@@ -2965,7 +2965,7 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt,
 static int intel_pt_find_map(struct thread *thread, u8 cpumode, u64 addr,
 			     struct addr_location *al)
 {
-	if (!al->map || addr < al->map->start || addr >= al->map->end) {
+	if (!al->map || addr < map__start(al->map) || addr >= map__end(al->map)) {
 		if (!thread__find_map(thread, cpumode, addr, al))
 			return -1;
 	}
@@ -2996,12 +2996,12 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
 			continue;
 		}
 
-		if (!al.map->dso || !al.map->dso->auxtrace_cache)
+		if (!map__dso(al.map) || !map__dso(al.map)->auxtrace_cache)
 			continue;
 
-		offset = al.map->map_ip(al.map, addr);
+		offset = map__map_ip(al.map, addr);
 
-		e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+		e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
 		if (!e)
 			continue;
 
@@ -3014,9 +3014,9 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
 			if (e->branch != INTEL_PT_BR_NO_BRANCH)
 				return 0;
 		} else {
-			intel_pt_cache_invalidate(al.map->dso, machine, offset);
+			intel_pt_cache_invalidate(map__dso(al.map), machine, offset);
 			intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n",
-				     al.map->dso->long_name, addr);
+				     map__dso(al.map)->long_name, addr);
 		}
 	}
 
tools/perf/util/machine.c +44 -40
index 88279008e761..940fb2a50dfd 100644
@@ -47,7 +47,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
 
 static struct dso *machine__kernel_dso(struct machine *machine)
 {
-	return machine->vmlinux_map->dso;
+	return map__dso(machine->vmlinux_map);
 }
 
 static void dsos__init(struct dsos *dsos)
@@ -842,9 +842,10 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
 	if (map != machine->vmlinux_map)
 		maps__remove(machine__kernel_maps(machine), map);
 	else {
-		sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+		sym = dso__find_symbol(map__dso(map),
+				map__map_ip(map, map__start(map)));
 		if (sym)
-			dso__delete_symbol(map->dso, sym);
+			dso__delete_symbol(map__dso(map), sym);
 	}
 
 	return 0;
@@ -880,7 +881,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
 		return 0;
 	}
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
 		int ret;
 
@@ -889,7 +890,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
 		 * must be done prior to using kernel maps.
 		 */
 		map__load(map);
-		ret = dso__data_write_cache_addr(map->dso, map, machine,
+		ret = dso__data_write_cache_addr(map__dso(map), map, machine,
 						 event->text_poke.addr,
 						 new_bytes,
 						 event->text_poke.new_len);
@@ -931,6 +932,7 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
 	/* If maps__insert failed, return NULL. */
 	if (err)
 		map = NULL;
+
 out:
 	/* put the dso here, corresponding to  machine__findnew_module_dso */
 	dso__put(dso);
@@ -1118,7 +1120,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
 	if (!err) {
 		pr_debug2("Added extra kernel map %s %" PRIx64 "-%" PRIx64 "\n",
-			kmap->name, map->start, map->end);
+			kmap->name, map__start(map), map__end(map));
 	}
 
 	map__put(map);
@@ -1178,9 +1180,9 @@ int machine__map_x86_64_entry_trampolines(struct machine *machine,
 		if (!kmap || !is_entry_trampoline(kmap->name))
 			continue;
 
-		dest_map = maps__find(kmaps, map->pgoff);
+		dest_map = maps__find(kmaps, map__pgoff(map));
 		if (dest_map != map)
-			map->pgoff = dest_map->map_ip(dest_map, map->pgoff);
+			map->pgoff = map__map_ip(dest_map, map__pgoff(map));
 		found = true;
 	}
 	if (found || machine->trampolines_mapped)
@@ -1230,7 +1232,8 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 	if (machine->vmlinux_map == NULL)
 		return -ENOMEM;
 
-	machine->vmlinux_map->map_ip = machine->vmlinux_map->unmap_ip = identity__map_ip;
+	machine->vmlinux_map->map_ip = map__identity_ip;
+	machine->vmlinux_map->unmap_ip = map__identity_ip;
 	return maps__insert(machine__kernel_maps(machine), machine->vmlinux_map);
 }
 
@@ -1329,10 +1332,10 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 int machine__load_kallsyms(struct machine *machine, const char *filename)
 {
 	struct map *map = machine__kernel_map(machine);
-	int ret = __dso__load_kallsyms(map->dso, filename, map, true);
+	int ret = __dso__load_kallsyms(map__dso(map), filename, map, true);
 
 	if (ret > 0) {
-		dso__set_loaded(map->dso);
+		dso__set_loaded(map__dso(map));
 		/*
 		 * Since /proc/kallsyms will have multiple sessions for the
 		 * kernel, with modules between them, fixup the end of all
@@ -1347,10 +1350,10 @@ int machine__load_kallsyms(struct machine *machine, const char *filename)
 int machine__load_vmlinux_path(struct machine *machine)
 {
 	struct map *map = machine__kernel_map(machine);
-	int ret = dso__load_vmlinux_path(map->dso, map);
+	int ret = dso__load_vmlinux_path(map__dso(map), map);
 
 	if (ret > 0)
-		dso__set_loaded(map->dso);
+		dso__set_loaded(map__dso(map));
 
 	return ret;
 }
@@ -1401,16 +1404,16 @@ static int maps__set_module_path(struct maps *maps, const char *path, struct kmo
 	if (long_name == NULL)
 		return -ENOMEM;
 
-	dso__set_long_name(map->dso, long_name, true);
-	dso__kernel_module_get_build_id(map->dso, "");
+	dso__set_long_name(map__dso(map), long_name, true);
+	dso__kernel_module_get_build_id(map__dso(map), "");
 
 	/*
 	 * Full name could reveal us kmod compression, so
 	 * we need to update the symtab_type if needed.
 	 */
-	if (m->comp && is_kmod_dso(map->dso)) {
-		map->dso->symtab_type++;
-		map->dso->comp = m->comp;
+	if (m->comp && is_kmod_dso(map__dso(map))) {
+		map__dso(map)->symtab_type++;
+		map__dso(map)->comp = m->comp;
 	}
 
 	return 0;
@@ -1509,8 +1512,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
 		return -1;
 	map->end = start + size;
 
-	dso__kernel_module_get_build_id(map->dso, machine->root_dir);
-
+	dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
 	return 0;
 }
 
@@ -1619,7 +1621,7 @@ int machine__create_kernel_maps(struct machine *machine)
 		struct map_rb_node *next = map_rb_node__next(rb_node);
 
 		if (next)
-			machine__set_kernel_mmap(machine, start, next->map->start);
+			machine__set_kernel_mmap(machine, start, map__start(next->map));
 	}
 
 out_put:
@@ -1683,10 +1685,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
 		if (map == NULL)
 			goto out_problem;
 
-		map->end = map->start + xm->end - xm->start;
+		map->end = map__start(map) + xm->end - xm->start;
 
 		if (build_id__is_defined(bid))
-			dso__set_build_id(map->dso, bid);
+			dso__set_build_id(map__dso(map), bid);
 
 	} else if (is_kernel_mmap) {
 		const char *symbol_name = (xm->name + strlen(machine->mmap_name));
@@ -2148,14 +2150,14 @@ static char *callchain_srcline(struct map_symbol *ms, u64 ip)
 	if (!map || callchain_param.key == CCKEY_FUNCTION)
 		return srcline;
 
-	srcline = srcline__tree_find(&map->dso->srclines, ip);
+	srcline = srcline__tree_find(&map__dso(map)->srclines, ip);
 	if (!srcline) {
 		bool show_sym = false;
 		bool show_addr = callchain_param.key == CCKEY_ADDRESS;
 
-		srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
+		srcline = get_srcline(map__dso(map), map__rip_2objdump(map, ip),
 				      ms->sym, show_sym, show_addr, ip);
-		srcline__tree_insert(&map->dso->srclines, ip, srcline);
+		srcline__tree_insert(&map__dso(map)->srclines, ip, srcline);
 	}
 
 	return srcline;
@@ -2179,7 +2181,7 @@ static int add_callchain_ip(struct thread *thread,
 {
 	struct map_symbol ms;
 	struct addr_location al;
-	int nr_loop_iter = 0;
+	int nr_loop_iter = 0, err;
 	u64 iter_cycles = 0;
 	const char *srcline = NULL;
 
@@ -2228,9 +2230,10 @@ static int add_callchain_ip(struct thread *thread,
 		}
 	}
 
-	if (symbol_conf.hide_unresolved && al.sym == NULL)
+	if (symbol_conf.hide_unresolved && al.sym == NULL) {
+		addr_location__put(&al);
 		return 0;
-
+	}
 	if (iter) {
 		nr_loop_iter = iter->nr_loop_iter;
 		iter_cycles = iter->cycles;
@@ -2240,9 +2243,10 @@ static int add_callchain_ip(struct thread *thread,
 	ms.map = al.map;
 	ms.sym = al.sym;
 	srcline = callchain_srcline(&ms, al.addr);
-	return callchain_cursor_append(cursor, ip, &ms,
-				       branch, flags, nr_loop_iter,
-				       iter_cycles, branch_from, srcline);
+	err = callchain_cursor_append(cursor, ip, &ms,
+				      branch, flags, nr_loop_iter,
+				      iter_cycles, branch_from, srcline);
+	return err;
 }
 
 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -2937,15 +2941,15 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
 	if (!symbol_conf.inline_name || !map || !sym)
 		return ret;
 
-	addr = map__map_ip(map, ip);
+	addr = map__dso_map_ip(map, ip);
 	addr = map__rip_2objdump(map, addr);
 
-	inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
+	inline_node = inlines__tree_find(&map__dso(map)->inlined_nodes, addr);
 	if (!inline_node) {
-		inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
+		inline_node = dso__parse_addr_inlines(map__dso(map), addr, sym);
 		if (!inline_node)
 			return ret;
-		inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
+		inlines__tree_insert(&map__dso(map)->inlined_nodes, inline_node);
 	}
 
 	list_for_each_entry(ilist, &inline_node->val, list) {
@@ -2981,7 +2985,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
 	 * its corresponding binary.
 	 */
 	if (entry->ms.map)
-		addr = map__map_ip(entry->ms.map, entry->ip);
+		addr = map__dso_map_ip(entry->ms.map, entry->ip);
 
 	srcline = callchain_srcline(&entry->ms, addr);
 	return callchain_cursor_append(cursor, entry->ip, &entry->ms,
@@ -3183,7 +3187,7 @@ int machine__get_kernel_start(struct machine *machine)
 		 * kernel_start = 1ULL << 63 for x86_64.
 		 */
 		if (!err && !machine__is(machine, "x86_64"))
-			machine->kernel_start = map->start;
+			machine->kernel_start = map__start(map);
 	}
 	return err;
 }
@@ -3234,8 +3238,8 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
 	if (sym == NULL)
 		return NULL;
 
-	*modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
-	*addrp = map->unmap_ip(map, sym->start);
+	*modp = __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NULL;
+	*addrp = map__unmap_ip(map, sym->start);
 	return sym->name;
 }
 
tools/perf/util/map.c +61 -56
index 57e926ce115f..47d81e361e29 100644
@@ -109,8 +109,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
 	map->pgoff    = pgoff;
 	map->reloc    = 0;
 	map->dso      = dso__get(dso);
-	map->map_ip   = map__map_ip;
-	map->unmap_ip = map__unmap_ip;
+	map->map_ip   = map__dso_map_ip;
+	map->unmap_ip = map__dso_unmap_ip;
 	map->erange_warned = false;
 	refcount_set(&map->refcnt, 1);
 }
@@ -120,10 +120,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		     u32 prot, u32 flags, struct build_id *bid,
 		     char *filename, struct thread *thread)
 {
-	struct map *map = malloc(sizeof(*map));
+	struct map *map;
 	struct nsinfo *nsi = NULL;
 	struct nsinfo *nnsi;
 
+	map = malloc(sizeof(*map));
 	if (map != NULL) {
 		char newfilename[PATH_MAX];
 		struct dso *dso;
@@ -170,7 +171,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		map__init(map, start, start + len, pgoff, dso);
 
 		if (anon || no_dso) {
-			map->map_ip = map->unmap_ip = identity__map_ip;
+			map->map_ip = map->unmap_ip = map__identity_ip;
 
 			/*
 			 * Set memory without DSO as loaded. All map__find_*
@@ -204,8 +205,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
  */
 struct map *map__new2(u64 start, struct dso *dso)
 {
-	struct map *map = calloc(1, (sizeof(*map) +
-				     (dso->kernel ? sizeof(struct kmap) : 0)));
+	struct map *map;
+
+	map = calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0));
 	if (map != NULL) {
 		/*
 		 * ->end will be filled after we load all the symbols
@@ -218,7 +220,7 @@ struct map *map__new2(u64 start, struct dso *dso)
 
 bool __map__is_kernel(const struct map *map)
 {
-	if (!map->dso->kernel)
+	if (!map__dso(map)->kernel)
 		return false;
 	return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
 }
@@ -234,7 +236,7 @@ bool __map__is_bpf_prog(const struct map *map)
 {
 	const char *name;
 
-	if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+	if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
 		return true;
 
 	/*
@@ -242,7 +244,7 @@ bool __map__is_bpf_prog(const struct map *map)
 	 * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
 	 * guess the type based on name.
 	 */
-	name = map->dso->short_name;
+	name = map__dso(map)->short_name;
 	return name && (strstr(name, "bpf_prog_") == name);
 }
 
@@ -250,7 +252,7 @@ bool __map__is_bpf_image(const struct map *map)
 {
 	const char *name;
 
-	if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+	if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
 		return true;
 
 	/*
@@ -258,18 +260,19 @@ bool __map__is_bpf_image(const struct map *map)
 	 * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
 	 * guess the type based on name.
 	 */
-	name = map->dso->short_name;
+	name = map__dso(map)->short_name;
 	return name && is_bpf_image(name);
 }
 
 bool __map__is_ool(const struct map *map)
 {
-	return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+	return map__dso(map) &&
+	       map__dso(map)->binary_type == DSO_BINARY_TYPE__OOL;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-	return dso__has_symbols(map->dso);
+	return dso__has_symbols(map__dso(map));
 }
 
 static void map__exit(struct map *map)
@@ -292,7 +295,7 @@ void map__put(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-	struct rb_root_cached *symbols = &map->dso->symbols;
+	struct rb_root_cached *symbols = &map__dso(map)->symbols;
 	struct rb_node *nd = rb_first_cached(symbols);
 	if (nd != NULL) {
 		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -302,7 +305,7 @@ void map__fixup_start(struct map *map)
 
 void map__fixup_end(struct map *map)
 {
-	struct rb_root_cached *symbols = &map->dso->symbols;
+	struct rb_root_cached *symbols = &map__dso(map)->symbols;
 	struct rb_node *nd = rb_last(&symbols->rb_root);
 	if (nd != NULL) {
 		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -314,18 +317,18 @@ void map__fixup_end(struct map *map)
 
 int map__load(struct map *map)
 {
-	const char *name = map->dso->long_name;
+	const char *name = map__dso(map)->long_name;
 	int nr;
 
-	if (dso__loaded(map->dso))
+	if (dso__loaded(map__dso(map)))
 		return 0;
 
-	nr = dso__load(map->dso, map);
+	nr = dso__load(map__dso(map), map);
 	if (nr < 0) {
-		if (map->dso->has_build_id) {
+		if (map__dso(map)->has_build_id) {
 			char sbuild_id[SBUILD_ID_SIZE];
 
-			build_id__sprintf(&map->dso->bid, sbuild_id);
+			build_id__sprintf(&map__dso(map)->bid, sbuild_id);
 			pr_debug("%s with build id %s not found", name, sbuild_id);
 		} else
 			pr_debug("Failed to open %s", name);
@@ -357,7 +360,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
 	if (map__load(map) < 0)
 		return NULL;
 
-	return dso__find_symbol(map->dso, addr);
+	return dso__find_symbol(map__dso(map), addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -365,24 +368,24 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
 	if (map__load(map) < 0)
 		return NULL;
 
-	if (!dso__sorted_by_name(map->dso))
-		dso__sort_by_name(map->dso);
+	if (!dso__sorted_by_name(map__dso(map)))
+		dso__sort_by_name(map__dso(map));
 
-	return dso__find_symbol_by_name(map->dso, name);
+	return dso__find_symbol_by_name(map__dso(map), name);
 }
 
 struct map *map__clone(struct map *from)
 {
-	size_t size = sizeof(struct map);
 	struct map *map;
+	size_t size = sizeof(struct map);
 
-	if (from->dso && from->dso->kernel)
+	if (map__dso(from) && map__dso(from)->kernel)
 		size += sizeof(struct kmap);
 
 	map = memdup(from, size);
 	if (map != NULL) {
 		refcount_set(&map->refcnt, 1);
-		dso__get(map->dso);
+		map->dso = dso__get(map->dso);
 	}
 
 	return map;
@@ -391,7 +394,8 @@ struct map *map__clone(struct map *from)
 size_t map__fprintf(struct map *map, FILE *fp)
 {
 	return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
-		       map->start, map->end, map->pgoff, map->dso->name);
+		       map__start(map), map__end(map),
+		       map__pgoff(map), map__dso(map)->name);
 }
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
@@ -399,11 +403,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 	char buf[symbol_conf.pad_output_len_dso + 1];
 	const char *dsoname = "[unknown]";
 
-	if (map && map->dso) {
-		if (symbol_conf.show_kernel_path && map->dso->long_name)
-			dsoname = map->dso->long_name;
+	if (map && map__dso(map)) {
+		if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+			dsoname = map__dso(map)->long_name;
 		else
-			dsoname = map->dso->name;
+			dsoname = map__dso(map)->name;
 	}
 
 	if (symbol_conf.pad_output_len_dso) {
@@ -418,7 +422,8 @@ char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
 {
 	if (map == NULL)
 		return SRCLINE_UNKNOWN;
-	return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+	return get_srcline(map__dso(map), map__rip_2objdump(map, addr),
+			   sym, true, true, addr);
 }
 
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
@@ -426,7 +431,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 {
 	int ret = 0;
 
-	if (map && map->dso) {
+	if (map && map__dso(map)) {
 		char *srcline = map__srcline(map, addr, NULL);
 		if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
 			ret = fprintf(fp, "%s%s", prefix, srcline);
@@ -472,20 +477,20 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
 		}
 	}
 
-	if (!map->dso->adjust_symbols)
+	if (!map__dso(map)->adjust_symbols)
 		return rip;
 
-	if (map->dso->rel)
-		return rip - map->pgoff;
+	if (map__dso(map)->rel)
+		return rip - map__pgoff(map);
 
 	/*
 	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
 	 * but all kernel modules are ET_REL, so won't get here.
 	 */
-	if (map->dso->kernel == DSO_SPACE__USER)
-		return rip + map->dso->text_offset;
+	if (map__dso(map)->kernel == DSO_SPACE__USER)
+		return rip + map__dso(map)->text_offset;
 
-	return map->unmap_ip(map, rip) - map->reloc;
+	return map__unmap_ip(map, rip) - map__reloc(map);
 }
 
 /**
@@ -502,34 +507,34 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
  */
 u64 map__objdump_2mem(struct map *map, u64 ip)
 {
-	if (!map->dso->adjust_symbols)
-		return map->unmap_ip(map, ip);
+	if (!map__dso(map)->adjust_symbols)
+		return map__unmap_ip(map, ip);
 
-	if (map->dso->rel)
-		return map->unmap_ip(map, ip + map->pgoff);
+	if (map__dso(map)->rel)
+		return map__unmap_ip(map, ip + map__pgoff(map));
 
 	/*
 	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
 	 * but all kernel modules are ET_REL, so won't get here.
 	 */
-	if (map->dso->kernel == DSO_SPACE__USER)
-		return map->unmap_ip(map, ip - map->dso->text_offset);
+	if (map__dso(map)->kernel == DSO_SPACE__USER)
+		return map__unmap_ip(map, ip - map__dso(map)->text_offset);
 
-	return ip + map->reloc;
+	return ip + map__reloc(map);
 }
 
 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
 {
-	u64 ip = map->unmap_ip(map, sym->start);
+	u64 ip = map__unmap_ip(map, sym->start);
 
-	return ip >= map->start && ip < map->end;
+	return ip >= map__start(map) && ip < map__end(map);
 }
 
 struct kmap *__map__kmap(struct map *map)
 {
-	if (!map->dso || !map->dso->kernel)
+	if (!map__dso(map) || !map__dso(map)->kernel)
 		return NULL;
-	return (struct kmap *)(map + 1);
+	return (struct kmap *)(&map[1]);
 }
 
 struct kmap *map__kmap(struct map *map)
@@ -552,17 +557,17 @@ struct maps *map__kmaps(struct map *map)
 	return kmap->kmaps;
 }
 
-u64 map__map_ip(const struct map *map, u64 ip)
+u64 map__dso_map_ip(const struct map *map, u64 ip)
 {
-	return ip - map->start + map->pgoff;
+	return ip - map__start(map) + map__pgoff(map);
 }
 
-u64 map__unmap_ip(const struct map *map, u64 ip)
+u64 map__dso_unmap_ip(const struct map *map, u64 ip)
 {
-	return ip + map->start - map->pgoff;
+	return ip + map__start(map) - map__pgoff(map);
 }
 
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip)
 {
 	return ip;
 }
tools/perf/util/map.h +54 -4
index d1a6f85fd31d..99ef0464a357 100644
@@ -41,15 +41,65 @@ struct kmap *map__kmap(struct map *map);
 struct maps *map__kmaps(struct map *map);
 
 /* ip -> dso rip */
-u64 map__map_ip(const struct map *map, u64 ip);
+u64 map__dso_map_ip(const struct map *map, u64 ip);
 /* dso rip -> ip */
-u64 map__unmap_ip(const struct map *map, u64 ip);
+u64 map__dso_unmap_ip(const struct map *map, u64 ip);
 /* Returns ip */
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip);
+
+static inline struct dso *map__dso(const struct map *map)
+{
+	return map->dso;
+}
+
+static inline u64 map__map_ip(const struct map *map, u64 ip)
+{
+	return map->map_ip(map, ip);
+}
+
+static inline u64 map__unmap_ip(const struct map *map, u64 ip)
+{
+	return map->unmap_ip(map, ip);
+}
+
+static inline u64 map__start(const struct map *map)
+{
+	return map->start;
+}
+
+static inline u64 map__end(const struct map *map)
+{
+	return map->end;
+}
+
+static inline u64 map__pgoff(const struct map *map)
+{
+	return map->pgoff;
+}
+
+static inline u64 map__reloc(const struct map *map)
+{
+	return map->reloc;
+}
+
+static inline u32 map__flags(const struct map *map)
+{
+	return map->flags;
+}
+
+static inline u32 map__prot(const struct map *map)
+{
+	return map->prot;
+}
+
+static inline bool map__priv(const struct map *map)
+{
+	return map->priv;
+}
 
 static inline size_t map__size(const struct map *map)
 {
-	return map->end - map->start;
+	return map__end(map) - map__start(map);
 }
 
 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
tools/perf/util/maps.c +42 -41
index 9fc3e7186b8e..6efbcb79131c 100644
@@ -30,24 +30,24 @@ static void __maps__free_maps_by_name(struct maps *maps)
 	maps->nr_maps_allocated = 0;
 }
 
-static int __maps__insert(struct maps *maps, struct map *map)
+static struct map *__maps__insert(struct maps *maps, struct map *map)
 {
 	struct rb_node **p = &maps__entries(maps)->rb_node;
 	struct rb_node *parent = NULL;
-	const u64 ip = map->start;
+	const u64 ip = map__start(map);
 	struct map_rb_node *m, *new_rb_node;
 
 	new_rb_node = malloc(sizeof(*new_rb_node));
 	if (!new_rb_node)
-		return -ENOMEM;
+		return NULL;
 
 	RB_CLEAR_NODE(&new_rb_node->rb_node);
-	new_rb_node->map = map;
+	new_rb_node->map = map__get(map);
 
 	while (*p != NULL) {
 		parent = *p;
 		m = rb_entry(parent, struct map_rb_node, rb_node);
-		if (ip < m->map->start)
+		if (ip < map__start(m->map))
 			p = &(*p)->rb_left;
 		else
 			p = &(*p)->rb_right;
@@ -55,22 +55,23 @@ static int __maps__insert(struct maps *maps, struct map *map)
 
 	rb_link_node(&new_rb_node->rb_node, parent, p);
 	rb_insert_color(&new_rb_node->rb_node, maps__entries(maps));
-	map__get(map);
-	return 0;
+	return new_rb_node->map;
 }
 
 int maps__insert(struct maps *maps, struct map *map)
 {
-	int err;
+	int err = 0;
 
 	down_write(maps__lock(maps));
-	err = __maps__insert(maps, map);
-	if (err)
+	map = __maps__insert(maps, map);
+	if (!map) {
+		err = -ENOMEM;
 		goto out;
+	}
 
 	++maps->nr_maps;
 
-	if (map->dso && map->dso->kernel) {
+	if (map__dso(map) && map__dso(map)->kernel) {
 		struct kmap *kmap = map__kmap(map);
 
 		if (kmap)
@@ -193,7 +194,7 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
 	if (map != NULL && map__load(map) >= 0) {
 		if (mapp != NULL)
 			*mapp = map;
-		return map__find_symbol(map, map->map_ip(map, addr));
+		return map__find_symbol(map, map__map_ip(map, addr));
 	}
 
 	return NULL;
@@ -228,7 +229,8 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, st
 
 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 {
-	if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
+	if (ams->addr < map__start(ams->ms.map) ||
+	    ams->addr >= map__end(ams->ms.map)) {
 		if (maps == NULL)
 			return -1;
 		ams->ms.map = maps__find(maps, ams->addr);
@@ -236,7 +238,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 			return -1;
 	}
 
-	ams->al_addr = ams->ms.map->map_ip(ams->ms.map, ams->addr);
+	ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
 	ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
 
 	return ams->ms.sym ? 0 : -1;
@@ -253,7 +255,7 @@ size_t maps__fprintf(struct maps *maps, FILE *fp)
 		printed += fprintf(fp, "Map:");
 		printed += map__fprintf(pos->map, fp);
 		if (verbose > 2) {
-			printed += dso__fprintf(pos->map->dso, fp);
+			printed += dso__fprintf(map__dso(pos->map), fp);
 			printed += fprintf(fp, "--\n");
 		}
 	}
@@ -282,9 +284,9 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 	while (next) {
 		struct map_rb_node *pos = rb_entry(next, struct map_rb_node, rb_node);
 
-		if (pos->map->end > map->start) {
+		if (map__end(pos->map) > map__start(map)) {
 			first = next;
-			if (pos->map->start <= map->start)
+			if (map__start(pos->map) <= map__start(map))
 				break;
 			next = next->rb_left;
 		} else
@@ -300,14 +302,14 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 		 * Stop if current map starts after map->end.
 		 * Maps are ordered by start: next will not overlap for sure.
 		 */
-		if (pos->map->start >= map->end)
+		if (map__start(pos->map) >= map__end(map))
 			break;
 
 		if (verbose >= 2) {
 
 			if (use_browser) {
 				pr_debug("overlapping maps in %s (disable tui for more info)\n",
-					   map->dso->name);
+					   map__dso(map)->name);
 			} else {
 				fputs("overlapping maps:\n", fp);
 				map__fprintf(map, fp);
@@ -320,7 +322,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 		 * Now check if we need to create new maps for areas not
 		 * overlapped by the new map:
 		 */
-		if (map->start > pos->map->start) {
+		if (map__start(map) > map__start(pos->map)) {
 			struct map *before = map__clone(pos->map);
 
 			if (before == NULL) {
@@ -328,17 +330,19 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 				goto put_map;
 			}
 
-			before->end = map->start;
-			err = __maps__insert(maps, before);
-			if (err)
+			before->end = map__start(map);
+			if (!__maps__insert(maps, before)) {
+				map__put(before);
+				err = -ENOMEM;
 				goto put_map;
+			}
 
 			if (verbose >= 2 && !use_browser)
 				map__fprintf(before, fp);
 			map__put(before);
 		}
 
-		if (map->end < pos->map->end) {
+		if (map__end(map) < map__end(pos->map)) {
 			struct map *after = map__clone(pos->map);
 
 			if (after == NULL) {
@@ -346,14 +350,15 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 				goto put_map;
 			}
 
-			after->start = map->end;
-			after->pgoff += map->end - pos->map->start;
-			assert(pos->map->map_ip(pos->map, map->end) ==
-				after->map_ip(after, map->end));
-			err = __maps__insert(maps, after);
-			if (err)
+			after->start = map__end(map);
+			after->pgoff += map__end(map) - map__start(pos->map);
+			assert(map__map_ip(pos->map, map__end(map)) ==
+				map__map_ip(after, map__end(map)));
+			if (!__maps__insert(maps, after)) {
+				map__put(after);
+				err = -ENOMEM;
 				goto put_map;
-
+			}
 			if (verbose >= 2 && !use_browser)
 				map__fprintf(after, fp);
 			map__put(after);
@@ -377,7 +382,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err;
+	int err = 0;
 	struct map_rb_node *rb_node;
 
 	down_read(maps__lock(parent));
@@ -391,17 +396,13 @@ int maps__clone(struct thread *thread, struct maps *parent)
 		}
 
 		err = unwind__prepare_access(maps, new, NULL);
-		if (err)
-			goto out_unlock;
+		if (!err)
+			err = maps__insert(maps, new);
 
-		err = maps__insert(maps, new);
+		map__put(new);
 		if (err)
 			goto out_unlock;
-
-		map__put(new);
 	}
-
-	err = 0;
 out_unlock:
 	up_read(maps__lock(parent));
 	return err;
@@ -428,9 +429,9 @@ struct map *maps__find(struct maps *maps, u64 ip)
 	p = maps__entries(maps)->rb_node;
 	while (p != NULL) {
 		m = rb_entry(p, struct map_rb_node, rb_node);
-		if (ip < m->map->start)
+		if (ip < map__start(m->map))
 			p = p->rb_left;
-		else if (ip >= m->map->end)
+		else if (ip >= map__end(m->map))
 			p = p->rb_right;
 		else
 			goto out;
tools/perf/util/probe-event.c +22 -22
index f9fbf611f2bf..1a93dca50a4c 100644
@@ -134,15 +134,15 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
 	/* ref_reloc_sym is just a label. Need a special fix*/
 	reloc_sym = kernel_get_ref_reloc_sym(&map);
 	if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
-		*addr = (!map->reloc || reloc) ? reloc_sym->addr :
+		*addr = (!map__reloc(map) || reloc) ? reloc_sym->addr :
 			reloc_sym->unrelocated_addr;
 	else {
 		sym = machine__find_kernel_symbol_by_name(host_machine, name, &map);
 		if (!sym)
 			return -ENOENT;
-		*addr = map->unmap_ip(map, sym->start) -
-			((reloc) ? 0 : map->reloc) -
-			((reladdr) ? map->start : 0);
+		*addr = map__unmap_ip(map, sym->start) -
+			((reloc) ? 0 : map__reloc(map)) -
+			((reladdr) ? map__start(map) : 0);
 	}
 	return 0;
 }
@@ -164,8 +164,8 @@ static struct map *kernel_get_module_map(const char *module)
 
 	maps__for_each_entry(maps, pos) {
 		/* short_name is "[module]" */
-		const char *short_name = pos->map->dso->short_name;
-		u16 short_name_len =  pos->map->dso->short_name_len;
+		const char *short_name = map__dso(pos->map)->short_name;
+		u16 short_name_len =  map__dso(pos->map)->short_name_len;
 
 		if (strncmp(short_name + 1, module,
 			    short_name_len - 2) == 0 &&
@@ -183,11 +183,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)
 		struct map *map;
 
 		map = dso__new_map(target);
-		if (map && map->dso) {
-			BUG_ON(pthread_mutex_lock(&map->dso->lock) != 0);
-			nsinfo__put(map->dso->nsinfo);
-			map->dso->nsinfo = nsinfo__get(nsi);
-			pthread_mutex_unlock(&map->dso->lock);
+		if (map && map__dso(map)) {
+			BUG_ON(pthread_mutex_lock(&map__dso(map)->lock) != 0);
+			nsinfo__put(map__dso(map)->nsinfo);
+			map__dso(map)->nsinfo = nsinfo__get(nsi);
+			pthread_mutex_unlock(&map__dso(map)->lock);
 		}
 		return map;
 	} else {
@@ -253,7 +253,7 @@ static bool kprobe_warn_out_range(const char *symbol, u64 address)
 
 	map = kernel_get_module_map(NULL);
 	if (map) {
-		ret = address <= map->start || map->end < address;
+		ret = address <= map__start(map) || map__end(map) < address;
 		if (ret)
 			pr_warning("%s is out of .text, skip it.\n", symbol);
 		map__put(map);
@@ -340,7 +340,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
 		snprintf(module_name, sizeof(module_name), "[%s]", module);
 		map = maps__find_by_name(machine__kernel_maps(host_machine), module_name);
 		if (map) {
-			dso = map->dso;
+			dso = map__dso(map);
 			goto found;
 		}
 		pr_debug("Failed to find module %s.\n", module);
@@ -348,7 +348,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
 	}
 
 	map = machine__kernel_map(host_machine);
-	dso = map->dso;
+	dso = map__dso(map);
 	if (!dso->has_build_id)
 		dso__read_running_kernel_build_id(dso, host_machine);
 
@@ -396,7 +396,8 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
 					   "Consider identifying the final function used at run time and set the probe directly on that.\n",
 					   pp->function);
 		} else
-			address = map->unmap_ip(map, sym->start) - map->reloc;
+			address = map__unmap_ip(map, sym->start) -
+				  map__reloc(map);
 		break;
 	}
 	if (!address) {
@@ -862,8 +863,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
 			free(tevs[i].point.symbol);
 		tevs[i].point.symbol = tmp;
 		tevs[i].point.offset = tevs[i].point.address -
-			(map->reloc ? reloc_sym->unrelocated_addr :
-				      reloc_sym->addr);
+			(map__reloc(map) ? reloc_sym->unrelocated_addr : reloc_sym->addr);
 	}
 	return skipped;
 }
@@ -2243,7 +2243,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
 		goto out;
 
 	pp->retprobe = tp->retprobe;
-	pp->offset = addr - map->unmap_ip(map, sym->start);
+	pp->offset = addr - map__unmap_ip(map, sym->start);
 	pp->function = strdup(sym->name);
 	ret = pp->function ? 0 : -ENOMEM;
 
@@ -3117,7 +3117,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 			goto err_out;
 		}
 		/* Add one probe point */
-		tp->address = map->unmap_ip(map, sym->start) + pp->offset;
+		tp->address = map__unmap_ip(map, sym->start) + pp->offset;
 
 		/* Check the kprobe (not in module) is within .text  */
 		if (!pev->uprobes && !pev->target &&
@@ -3759,13 +3759,13 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
 			       (target) ? : "kernel");
 		goto end;
 	}
-	if (!dso__sorted_by_name(map->dso))
-		dso__sort_by_name(map->dso);
+	if (!dso__sorted_by_name(map__dso(map)))
+		dso__sort_by_name(map__dso(map));
 
 	/* Show all (filtered) symbols */
 	setup_pager();
 
-	for (nd = rb_first_cached(&map->dso->symbol_names); nd;
+	for (nd = rb_first_cached(&map__dso(map)->symbol_names); nd;
 	     nd = rb_next(nd)) {
 		struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
tools/perf/util/scripting-engines/trace-event-perl.c +5 -4
index a5d945415bbc..1282fb9b45e1 100644
@@ -315,11 +315,12 @@ static SV *perl_process_callchain(struct perf_sample *sample,
 		if (node->ms.map) {
 			struct map *map = node->ms.map;
 			const char *dsoname = "[unknown]";
-			if (map && map->dso) {
-				if (symbol_conf.show_kernel_path && map->dso->long_name)
-					dsoname = map->dso->long_name;
+			if (map && map__dso(map)) {
+				if (symbol_conf.show_kernel_path &&
+				    map__dso(map)->long_name)
+					dsoname = map__dso(map)->long_name;
 				else
-					dsoname = map->dso->name;
+					dsoname = map__dso(map)->name;
 			}
 			if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) {
 				hv_undef(elem);
tools/perf/util/scripting-engines/trace-event-python.c +6 -6
index 0290dc3a6258..559b2ac5cac3 100644
@@ -382,11 +382,11 @@ static const char *get_dsoname(struct map *map)
 {
 	const char *dsoname = "[unknown]";
 
-	if (map && map->dso) {
-		if (symbol_conf.show_kernel_path && map->dso->long_name)
-			dsoname = map->dso->long_name;
+	if (map && map__dso(map)) {
+		if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+			dsoname = map__dso(map)->long_name;
 		else
-			dsoname = map->dso->name;
+			dsoname = map__dso(map)->name;
 	}
 
 	return dsoname;
@@ -527,7 +527,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al)
 	if (al->addr < sym->end)
 		offset = al->addr - sym->start;
 	else
-		offset = al->addr - al->map->start - sym->start;
+		offset = al->addr - map__start(al->map) - sym->start;
 
 	return offset;
 }
@@ -741,7 +741,7 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 {
 	if (al->map) {
 		pydict_set_item_string_decref(dict, dso_field,
-			_PyUnicode_FromString(al->map->dso->name));
+			_PyUnicode_FromString(map__dso(al->map)->name));
 	}
 	if (al->sym) {
 		pydict_set_item_string_decref(dict, sym_field,
tools/perf/util/sort.c +23 -23
index 25686d67ee6f..6d19bbcd30df 100644
@@ -173,8 +173,8 @@ struct sort_entry sort_comm = {
 
 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
 {
-	struct dso *dso_l = map_l ? map_l->dso : NULL;
-	struct dso *dso_r = map_r ? map_r->dso : NULL;
+	struct dso *dso_l = map_l ? map__dso(map_l) : NULL;
+	struct dso *dso_r = map_r ? map__dso(map_r) : NULL;
 	const char *dso_name_l, *dso_name_r;
 
 	if (!dso_l || !dso_r)
@@ -200,9 +200,9 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
 				     size_t size, unsigned int width)
 {
-	if (map && map->dso) {
-		const char *dso_name = verbose > 0 ? map->dso->long_name :
-			map->dso->short_name;
+	if (map && map__dso(map)) {
+		const char *dso_name = verbose > 0 ? map__dso(map)->long_name :
+			map__dso(map)->short_name;
 		return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
 	}
 
@@ -222,7 +222,7 @@ static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *a
 	if (type != HIST_FILTER__DSO)
 		return -1;
 
-	return dso && (!he->ms.map || he->ms.map->dso != dso);
+	return dso && (!he->ms.map || map__dso(he->ms.map) != dso);
 }
 
 struct sort_entry sort_dso = {
@@ -302,12 +302,12 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
 	size_t ret = 0;
 
 	if (verbose > 0) {
-		char o = map ? dso__symtab_origin(map->dso) : '!';
+		char o = map ? dso__symtab_origin(map__dso(map)) : '!';
 		u64 rip = ip;
 
-		if (map && map->dso && map->dso->kernel
-		    && map->dso->adjust_symbols)
-			rip = map->unmap_ip(map, ip);
+		if (map && map__dso(map) && map__dso(map)->kernel
+		    && map__dso(map)->adjust_symbols)
+			rip = map__unmap_ip(map, ip);
 
 		ret += repsep_snprintf(bf, size, "%-#*llx %c ",
 				       BITS_PER_LONG / 4 + 2, rip, o);
@@ -318,7 +318,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
 		if (sym->type == STT_OBJECT) {
 			ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
 			ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
-					ip - map->unmap_ip(map, sym->start));
+					ip - map__unmap_ip(map, sym->start));
 		} else {
 			ret += repsep_snprintf(bf + ret, size - ret, "%.*s",
 					       width - ret,
@@ -517,7 +517,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)
 	if (!map)
 		return no_srcfile;
 
-	sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
+	sf = __get_srcline(map__dso(map), map__rip_2objdump(map, e->ip),
 			 e->ms.sym, false, true, true, e->ip);
 	if (!strcmp(sf, SRCLINE_UNKNOWN))
 		return no_srcfile;
@@ -838,7 +838,7 @@ static int hist_entry__dso_from_filter(struct hist_entry *he, int type,
 		return -1;
 
 	return dso && (!he->branch_info || !he->branch_info->from.ms.map ||
-		       he->branch_info->from.ms.map->dso != dso);
+		map__dso(he->branch_info->from.ms.map) != dso);
 }
 
 static int64_t
@@ -870,7 +870,7 @@ static int hist_entry__dso_to_filter(struct hist_entry *he, int type,
 		return -1;
 
 	return dso && (!he->branch_info || !he->branch_info->to.ms.map ||
-		       he->branch_info->to.ms.map->dso != dso);
+		map__dso(he->branch_info->to.ms.map) != dso);
 }
 
 static int64_t
@@ -1259,7 +1259,7 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 	if (!l_map) return -1;
 	if (!r_map) return 1;
 
-	rc = dso__cmp_id(l_map->dso, r_map->dso);
+	rc = dso__cmp_id(map__dso(l_map), map__dso(r_map));
 	if (rc)
 		return rc;
 	/*
@@ -1271,9 +1271,9 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 	 */
 
 	if ((left->cpumode != PERF_RECORD_MISC_KERNEL) &&
-	    (!(l_map->flags & MAP_SHARED)) &&
-	    !l_map->dso->id.maj && !l_map->dso->id.min &&
-	    !l_map->dso->id.ino && !l_map->dso->id.ino_generation) {
+	    (!(map__flags(l_map) & MAP_SHARED)) &&
+	    !map__dso(l_map)->id.maj && !map__dso(l_map)->id.min &&
+	    !map__dso(l_map)->id.ino && !map__dso(l_map)->id.ino_generation) {
 		/* userspace anonymous */
 
 		if (left->thread->pid_ > right->thread->pid_) return -1;
@@ -1307,10 +1307,10 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,
 
 		/* print [s] for shared data mmaps */
 		if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
-		     map && !(map->prot & PROT_EXEC) &&
-		    (map->flags & MAP_SHARED) &&
-		    (map->dso->id.maj || map->dso->id.min ||
-		     map->dso->id.ino || map->dso->id.ino_generation))
+		    map && !(map__prot(map) & PROT_EXEC) &&
+		    (map__flags(map) & MAP_SHARED) &&
+		    (map__dso(map)->id.maj || map__dso(map)->id.min ||
+		     map__dso(map)->id.ino || map__dso(map)->id.ino_generation))
 			level = 's';
 		else if (!map)
 			level = 'X';
@@ -1806,7 +1806,7 @@ sort__dso_size_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_size_snprintf(struct map *map, char *bf,
 					  size_t bf_size, unsigned int width)
 {
-	if (map && map->dso)
+	if (map && map__dso(map))
 		return repsep_snprintf(bf, bf_size, "%*d", width,
 				       map__size(map));
 
tools/perf/util/symbol-elf.c +19 -20
index 3ca9a0968345..056405d3d655 100644
@@ -970,7 +970,7 @@ void __weak arch__sym_update(struct symbol *s __maybe_unused,
 static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 				      GElf_Sym *sym, GElf_Shdr *shdr,
 				      struct maps *kmaps, struct kmap *kmap,
-				      struct dso **curr_dsop, struct map **curr_mapp,
+				      struct dso **curr_dsop,
 				      const char *section_name,
 				      bool adjust_kernel_syms, bool kmodule, bool *remap_kernel)
 {
@@ -994,18 +994,18 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		if (*remap_kernel && dso->kernel && !kmodule) {
 			*remap_kernel = false;
 			map->start = shdr->sh_addr + ref_reloc(kmap);
-			map->end = map->start + shdr->sh_size;
+			map->end = map__start(map) + shdr->sh_size;
 			map->pgoff = shdr->sh_offset;
-			map->map_ip = map__map_ip;
-			map->unmap_ip = map__unmap_ip;
+			map->map_ip = map__dso_map_ip;
+			map->unmap_ip = map__dso_unmap_ip;
 			/* Ensure maps are correctly ordered */
 			if (kmaps) {
 				int err;
+				struct map *updated = map__get(map);
 
-				map__get(map);
 				maps__remove(kmaps, map);
-				err = maps__insert(kmaps, map);
-				map__put(map);
+				err = maps__insert(kmaps, updated);
+				map__put(updated);
 				if (err)
 					return err;
 			}
@@ -1021,7 +1021,6 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 			map->pgoff = shdr->sh_offset;
 		}
 
-		*curr_mapp = map;
 		*curr_dsop = dso;
 		return 0;
 	}
@@ -1036,7 +1035,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		u64 start = sym->st_value;
 
 		if (kmodule)
-			start += map->start + shdr->sh_offset;
+			start += map__start(map) + shdr->sh_offset;
 
 		curr_dso = dso__new(dso_name);
 		if (curr_dso == NULL)
@@ -1054,10 +1053,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 
 		if (adjust_kernel_syms) {
 			curr_map->start  = shdr->sh_addr + ref_reloc(kmap);
-			curr_map->end	 = curr_map->start + shdr->sh_size;
-			curr_map->pgoff	 = shdr->sh_offset;
+			curr_map->end	= map__start(curr_map) + shdr->sh_size;
+			curr_map->pgoff	= shdr->sh_offset;
 		} else {
-			curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+			curr_map->map_ip = map__identity_ip;
+			curr_map->unmap_ip = map__identity_ip;
 		}
 		curr_dso->symtab_type = dso->symtab_type;
 		if (maps__insert(kmaps, curr_map))
@@ -1068,13 +1068,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 		 * *curr_map->dso.
 		 */
 		dsos__add(&maps__machine(kmaps)->dsos, curr_dso);
-		/* kmaps already got it */
-		map__put(curr_map);
 		dso__set_loaded(curr_dso);
-		*curr_mapp = curr_map;
 		*curr_dsop = curr_dso;
+		map__put(curr_map);
 	} else
-		*curr_dsop = curr_map->dso;
+		*curr_dsop = map__dso(curr_map);
 
 	return 0;
 }
@@ -1085,7 +1083,6 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 {
 	struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
 	struct maps *kmaps = kmap ? map__kmaps(map) : NULL;
-	struct map *curr_map = map;
 	struct dso *curr_dso = dso;
 	Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym;
 	uint32_t nr_syms;
@@ -1175,7 +1172,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 	 * attempted to prelink vdso to its virtual address.
 	 */
 	if (dso__is_vdso(dso))
-		map->reloc = map->start - dso->text_offset;
+		map->reloc = map__start(map) - dso->text_offset;
 
 	dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
 	/*
@@ -1262,8 +1259,10 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 			--sym.st_value;
 
 		if (dso->kernel) {
-			if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map,
-						       section_name, adjust_kernel_syms, kmodule, &remap_kernel))
+			if (dso__process_kernel_symbol(dso, map, &sym, &shdr,
+						       kmaps, kmap, &curr_dso,
+						       section_name, adjust_kernel_syms,
+						       kmodule, &remap_kernel))
 				goto out_elf_end;
 		} else if ((used_opd && runtime_ss->adjust_symbols) ||
 			   (!used_opd && syms_ss->adjust_symbols)) {
tools/perf/util/symbol.c +51 -45
index 9b51e669a722..6289b3028b91 100644
@@ -252,8 +252,8 @@ void maps__fixup_end(struct maps *maps)
 	down_write(maps__lock(maps));
 
 	maps__for_each_entry(maps, curr) {
-		if (prev != NULL && !prev->map->end)
-			prev->map->end = curr->map->start;
+		if (prev != NULL && !map__end(prev->map))
+			prev->map->end = map__start(curr->map);
 
 		prev = curr;
 	}
@@ -262,7 +262,7 @@ void maps__fixup_end(struct maps *maps)
 	 * We still haven't the actual symbols, so guess the
 	 * last map final address.
 	 */
-	if (curr && !curr->map->end)
+	if (curr && !map__end(curr->map))
 		curr->map->end = ~0ULL;
 
 	up_write(maps__lock(maps));
@@ -778,12 +778,12 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
 			continue;
 		}
 
-		pos->start -= curr_map->start - curr_map->pgoff;
-		if (pos->end > curr_map->end)
-			pos->end = curr_map->end;
+		pos->start -= map__start(curr_map) - map__pgoff(curr_map);
+		if (pos->end > map__end(curr_map))
+			pos->end = map__end(curr_map);
 		if (pos->end)
-			pos->end -= curr_map->start - curr_map->pgoff;
-		symbols__insert(&curr_map->dso->symbols, pos);
+			pos->end -= map__start(curr_map) - map__pgoff(curr_map);
+		symbols__insert(&map__dso(curr_map)->symbols, pos);
 		++count;
 	}
 
@@ -830,7 +830,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 
 			*module++ = '\0';
 
-			if (strcmp(curr_map->dso->short_name, module)) {
+			if (strcmp(map__dso(curr_map)->short_name, module)) {
 				if (curr_map != initial_map &&
 				    dso->kernel == DSO_SPACE__KERNEL_GUEST &&
 				    machine__is_default_guest(machine)) {
@@ -841,7 +841,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 					 * symbols are in its kmap. Mark it as
 					 * loaded.
 					 */
-					dso__set_loaded(curr_map->dso);
+					dso__set_loaded(map__dso(curr_map));
 				}
 
 				curr_map = maps__find_by_name(kmaps, module);
@@ -854,7 +854,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 					goto discard_symbol;
 				}
 
-				if (curr_map->dso->loaded &&
+				if (map__dso(curr_map)->loaded &&
 				    !machine__is_default_guest(machine))
 					goto discard_symbol;
 			}
@@ -862,8 +862,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 			 * So that we look just like we get from .ko files,
 			 * i.e. not prelinked, relative to initial_map->start.
 			 */
-			pos->start = curr_map->map_ip(curr_map, pos->start);
-			pos->end   = curr_map->map_ip(curr_map, pos->end);
+			pos->start = map__map_ip(curr_map, pos->start);
+			pos->end   = map__map_ip(curr_map, pos->end);
 		} else if (x86_64 && is_entry_trampoline(pos->name)) {
 			/*
 			 * These symbols are not needed anymore since the
@@ -910,7 +910,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 				return -1;
 			}
 
-			curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+			curr_map->map_ip = map__identity_ip;
+			curr_map->unmap_ip = map__identity_ip;
 			if (maps__insert(kmaps, curr_map)) {
 				dso__put(ndso);
 				return -1;
@@ -924,7 +925,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 add_symbol:
 		if (curr_map != initial_map) {
 			rb_erase_cached(&pos->rb_node, root);
-			symbols__insert(&curr_map->dso->symbols, pos);
+			symbols__insert(&map__dso(curr_map)->symbols, pos);
 			++moved;
 		} else
 			++count;
@@ -938,7 +939,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 	if (curr_map != initial_map &&
 	    dso->kernel == DSO_SPACE__KERNEL_GUEST &&
 	    machine__is_default_guest(maps__machine(kmaps))) {
-		dso__set_loaded(curr_map->dso);
+		dso__set_loaded(map__dso(curr_map));
 	}
 
 	return count + moved;
@@ -1118,8 +1119,8 @@ static int do_validate_kcore_modules(const char *filename, struct maps *kmaps)
 		}
 
 		/* Module must be in memory at the same address */
-		mi = find_module(old_map->dso->short_name, &modules);
-		if (!mi || mi->start != old_map->start) {
+		mi = find_module(map__dso(old_map)->short_name, &modules);
+		if (!mi || mi->start != map__start(old_map)) {
 			err = -EINVAL;
 			goto out;
 		}
@@ -1214,7 +1215,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
 		return -ENOMEM;
 	}
 
-	list_node->map->end = list_node->map->start + len;
+	list_node->map->end = map__start(list_node->map) + len;
 	list_node->map->pgoff = pgoff;
 
 	list_add(&list_node->node, &md->maps);
@@ -1236,21 +1237,21 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 		struct map *old_map = rb_node->map;
 
 		/* no overload with this one */
-		if (new_map->end < old_map->start ||
-		    new_map->start >= old_map->end)
+		if (map__end(new_map) < map__start(old_map) ||
+		    map__start(new_map) >= map__end(old_map))
 			continue;
 
-		if (new_map->start < old_map->start) {
+		if (map__start(new_map) < map__start(old_map)) {
 			/*
 			 * |new......
 			 *       |old....
 			 */
-			if (new_map->end < old_map->end) {
+			if (map__end(new_map) < map__end(old_map)) {
 				/*
 				 * |new......|     -> |new..|
 				 *       |old....| ->       |old....|
 				 */
-				new_map->end = old_map->start;
+				new_map->end = map__start(old_map);
 			} else {
 				/*
 				 * |new.............| -> |new..|       |new..|
@@ -1271,17 +1272,18 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 					goto out;
 				}
 
-				m->map->end = old_map->start;
+				m->map->end = map__start(old_map);
 				list_add_tail(&m->node, &merged);
-				new_map->pgoff += old_map->end - new_map->start;
-				new_map->start = old_map->end;
+				new_map->pgoff +=
+					map__end(old_map) - map__start(new_map);
+				new_map->start = map__end(old_map);
 			}
 		} else {
 			/*
 			 *      |new......
 			 * |old....
 			 */
-			if (new_map->end < old_map->end) {
+			if (map__end(new_map) < map__end(old_map)) {
 				/*
 				 *      |new..|   -> x
 				 * |old.........| -> |old.........|
@@ -1294,8 +1296,9 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
 				 *      |new......| ->         |new...|
 				 * |old....|        -> |old....|
 				 */
-				new_map->pgoff += old_map->end - new_map->start;
-				new_map->start = old_map->end;
+				new_map->pgoff +=
+					map__end(old_map) - map__start(new_map);
+				new_map->start = map__end(old_map);
 			}
 		}
 	}
@@ -1361,7 +1364,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	}
 
 	/* Read new maps into temporary lists */
-	err = file__read_maps(fd, map->prot & PROT_EXEC, kcore_mapfn, &md,
+	err = file__read_maps(fd, map__prot(map) & PROT_EXEC, kcore_mapfn, &md,
 			      &is_64_bit);
 	if (err)
 		goto out_err;
@@ -1391,7 +1394,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		struct map_list_node *new_node;
 
 		list_for_each_entry(new_node, &md.maps, node) {
-			if (stext >= new_node->map->start && stext < new_node->map->end) {
+			if (stext >= map__start(new_node->map) &&
+			    stext < map__end(new_node->map)) {
 				replacement_map = new_node->map;
 				break;
 			}
@@ -1408,16 +1412,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		new_node = list_entry(md.maps.next, struct map_list_node, node);
 		list_del_init(&new_node->node);
 		if (new_node->map == replacement_map) {
-			map->start	= new_node->map->start;
-			map->end	= new_node->map->end;
-			map->pgoff	= new_node->map->pgoff;
-			map->map_ip	= new_node->map->map_ip;
-			map->unmap_ip	= new_node->map->unmap_ip;
+			struct  map *updated;
+
+			map->start = map__start(new_node->map);
+			map->end   = map__end(new_node->map);
+			map->pgoff = map__pgoff(new_node->map);
+			map->map_ip = new_node->map->map_ip;
+			map->unmap_ip = new_node->map->unmap_ip;
 			/* Ensure maps are correctly ordered */
-			map__get(map);
+			updated = map__get(map);
 			maps__remove(kmaps, map);
-			err = maps__insert(kmaps, map);
-			map__put(map);
+			err = maps__insert(kmaps, updated);
+			map__put(updated);
 			map__put(new_node->map);
 			if (err)
 				goto out_err;
@@ -1460,7 +1466,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
 	close(fd);
 
-	if (map->prot & PROT_EXEC)
+	if (map__prot(map) & PROT_EXEC)
 		pr_debug("Using %s for kernel object code\n", kcore_filename);
 	else
 		pr_debug("Using %s for kernel data\n", kcore_filename);
@@ -1995,13 +2001,13 @@ int dso__load(struct dso *dso, struct map *map)
 static int map__strcmp(const void *a, const void *b)
 {
 	const struct map *ma = *(const struct map **)a, *mb = *(const struct map **)b;
-	return strcmp(ma->dso->short_name, mb->dso->short_name);
+	return strcmp(map__dso(ma)->short_name, map__dso(mb)->short_name);
 }
 
 static int map__strcmp_name(const void *name, const void *b)
 {
 	const struct map *map = *(const struct map **)b;
-	return strcmp(name, map->dso->short_name);
+	return strcmp(name, map__dso(map)->short_name);
 }
 
 void __maps__sort_by_name(struct maps *maps)
@@ -2052,7 +2058,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
 	down_read(maps__lock(maps));
 
 	if (maps->last_search_by_name &&
-	    strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
+	    strcmp(map__dso(maps->last_search_by_name)->short_name, name) == 0) {
 		map = maps->last_search_by_name;
 		goto out_unlock;
 	}
@@ -2068,7 +2074,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
 	/* Fallback to traversing the rbtree... */
 	maps__for_each_entry(maps, rb_node) {
 		map = rb_node->map;
-		if (strcmp(map->dso->short_name, name) == 0) {
+		if (strcmp(map__dso(map)->short_name, name) == 0) {
 			maps->last_search_by_name = map;
 			goto out_unlock;
 		}
tools/perf/util/symbol_fprintf.c +1 -1
index 2664fb65e47a..d9e5ad040b6a 100644
@@ -30,7 +30,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
 			if (al->addr < sym->end)
 				offset = al->addr - sym->start;
 			else
-				offset = al->addr - al->map->start - sym->start;
+				offset = al->addr - map__start(al->map) - sym->start;
 			length += fprintf(fp, "+0x%lx", offset);
 		}
 		return length;
tools/perf/util/synthetic-events.c +14 -14
index ed2d55d224aa..437fd57c2084 100644
@@ -668,33 +668,33 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
 			continue;
 
 		if (symbol_conf.buildid_mmap2) {
-			size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+			size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
 			event->mmap2.header.type = PERF_RECORD_MMAP2;
 			event->mmap2.header.size = (sizeof(event->mmap2) -
 						(sizeof(event->mmap2.filename) - size));
 			memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
 			event->mmap2.header.size += machine->id_hdr_size;
-			event->mmap2.start = map->start;
-			event->mmap2.len   = map->end - map->start;
+			event->mmap2.start = map__start(map);
+			event->mmap2.len   = map__end(map) - map__start(map);
 			event->mmap2.pid   = machine->pid;
 
-			memcpy(event->mmap2.filename, map->dso->long_name,
-			       map->dso->long_name_len + 1);
+			memcpy(event->mmap2.filename, map__dso(map)->long_name,
+			       map__dso(map)->long_name_len + 1);
 
 			perf_record_mmap2__read_build_id(&event->mmap2, false);
 		} else {
-			size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+			size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
 			event->mmap.header.type = PERF_RECORD_MMAP;
 			event->mmap.header.size = (sizeof(event->mmap) -
 						(sizeof(event->mmap.filename) - size));
 			memset(event->mmap.filename + size, 0, machine->id_hdr_size);
 			event->mmap.header.size += machine->id_hdr_size;
-			event->mmap.start = map->start;
-			event->mmap.len   = map->end - map->start;
+			event->mmap.start = map__start(map);
+			event->mmap.len   = map__end(map) - map__start(map);
 			event->mmap.pid   = machine->pid;
 
-			memcpy(event->mmap.filename, map->dso->long_name,
-			       map->dso->long_name_len + 1);
+			memcpy(event->mmap.filename, map__dso(map)->long_name,
+			       map__dso(map)->long_name_len + 1);
 		}
 
 		if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
@@ -1112,8 +1112,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 		event->mmap2.header.size = (sizeof(event->mmap2) -
 				(sizeof(event->mmap2.filename) - size) + machine->id_hdr_size);
 		event->mmap2.pgoff = kmap->ref_reloc_sym->addr;
-		event->mmap2.start = map->start;
-		event->mmap2.len   = map->end - event->mmap.start;
+		event->mmap2.start = map__start(map);
+		event->mmap2.len   = map__end(map) - event->mmap.start;
 		event->mmap2.pid   = machine->pid;
 
 		perf_record_mmap2__read_build_id(&event->mmap2, true);
@@ -1125,8 +1125,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 		event->mmap.header.size = (sizeof(event->mmap) -
 				(sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
 		event->mmap.pgoff = kmap->ref_reloc_sym->addr;
-		event->mmap.start = map->start;
-		event->mmap.len   = map->end - event->mmap.start;
+		event->mmap.start = map__start(map);
+		event->mmap.len   = map__end(map) - event->mmap.start;
 		event->mmap.pid   = machine->pid;
 	}
 
tools/perf/util/thread.c +13 -13
index c2256777b813..6fbcc115cc6d 100644
@@ -434,23 +434,23 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa
 int thread__memcpy(struct thread *thread, struct machine *machine,
 		   void *buf, u64 ip, int len, bool *is64bit)
 {
-       u8 cpumode = PERF_RECORD_MISC_USER;
-       struct addr_location al;
-       long offset;
+	u8 cpumode = PERF_RECORD_MISC_USER;
+	struct addr_location al;
+	long offset;
 
-       if (machine__kernel_ip(machine, ip))
-               cpumode = PERF_RECORD_MISC_KERNEL;
+	if (machine__kernel_ip(machine, ip))
+		cpumode = PERF_RECORD_MISC_KERNEL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
-	   al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
-	   map__load(al.map) < 0)
-               return -1;
+	if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map) ||
+		map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR ||
+		map__load(al.map) < 0)
+		return -1;
 
-       offset = al.map->map_ip(al.map, ip);
-       if (is64bit)
-               *is64bit = al.map->dso->is_64_bit;
+	offset = map__map_ip(al.map, ip);
+	if (is64bit)
+		*is64bit = map__dso(al.map)->is_64_bit;
 
-       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+	return dso__data_read_offset(map__dso(al.map), machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
tools/perf/util/unwind-libunwind-local.c +17 -17
index 7e6c59811292..841ac84a93ab 100644
@@ -381,20 +381,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 	int ret = -EINVAL;
 
 	map = find_map(ip, ui);
-	if (!map || !map->dso)
+	if (!map || !map__dso(map))
 		return -EINVAL;
 
-	pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
+	pr_debug("unwind: %s dso %s\n", __func__, map__dso(map)->name);
 
 	/* Check the .eh_frame section for unwinding info */
-	if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
+	if (!read_unwind_spec_eh_frame(map__dso(map), ui->machine,
 				       &table_data, &segbase, &fde_count)) {
 		memset(&di, 0, sizeof(di));
 		di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
-		di.start_ip = map->start;
-		di.end_ip   = map->end;
-		di.u.rti.segbase    = map->start + segbase - map->pgoff;
-		di.u.rti.table_data = map->start + table_data - map->pgoff;
+		di.start_ip = map__start(map);
+		di.end_ip   = map__end(map);
+		di.u.rti.segbase    = map__start(map) + segbase - map__pgoff(map);
+		di.u.rti.table_data = map__start(map) + table_data - map__pgoff(map);
 		di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
 				      / sizeof(unw_word_t);
 		ret = dwarf_search_unwind_table(as, ip, &di, pi,
@@ -404,20 +404,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 #ifndef NO_LIBUNWIND_DEBUG_FRAME
 	/* Check the .debug_frame section for unwinding info */
 	if (ret < 0 &&
-	    !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
-		int fd = dso__data_get_fd(map->dso, ui->machine);
-		int is_exec = elf_is_exec(fd, map->dso->name);
-		unw_word_t base = is_exec ? 0 : map->start;
+	    !read_unwind_spec_debug_frame(map__dso(map), ui->machine, &segbase)) {
+		int fd = dso__data_get_fd(map__dso(map), ui->machine);
+		int is_exec = elf_is_exec(fd, map__dso(map)->name);
+		unw_word_t base = is_exec ? 0 : map__start(map);
 		const char *symfile;
 
 		if (fd >= 0)
-			dso__data_put_fd(map->dso);
+			dso__data_put_fd(map__dso(map));
 
-		symfile = map->dso->symsrc_filename ?: map->dso->name;
+		symfile = map__dso(map)->symsrc_filename ?: map__dso(map)->name;
 
 		memset(&di, 0, sizeof(di));
 		if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
-					   map->start, map->end))
+					   map__start(map), map__end(map)))
 			return dwarf_search_unwind_table(as, ip, &di, pi,
 							 need_unwind_info, arg);
 	}
@@ -473,10 +473,10 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
 		return -1;
 	}
 
-	if (!map->dso)
+	if (!map__dso(map))
 		return -1;
 
-	size = dso__data_read_addr(map->dso, map, ui->machine,
+	size = dso__data_read_addr(map__dso(map), map, ui->machine,
 				   addr, (u8 *) data, sizeof(*data));
 
 	return !(size == sizeof(*data));
@@ -583,7 +583,7 @@ static int entry(u64 ip, struct thread *thread,
 	pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
 		 al.sym ? al.sym->name : "''",
 		 ip,
-		 al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
+		 al.map ? map__map_ip(al.map, ip) : (u64) 0);
 
 	return cb(&e, arg);
 }
tools/perf/util/unwind-libunwind.c +2 -2
index 7b797ffadd19..cece1ee89031 100644
@@ -30,7 +30,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 
 	if (maps__addr_space(maps)) {
 		pr_debug("unwind: thread map already set, dso=%s\n",
-			 map->dso->name);
+			 map__dso(map)->name);
 		if (initialized)
 			*initialized = true;
 		return 0;
@@ -41,7 +41,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 	if (!machine->env || !machine->env->arch)
 		goto out_register;
 
-	dso_type = dso__type(map->dso, machine);
+	dso_type = dso__type(map__dso(map), machine);
 	if (dso_type == DSO__TYPE_UNKNOWN)
 		return 0;
 
tools/perf/util/vdso.c +1 -1
index 835c39efb80d..ec777ee11493 100644
@@ -147,7 +147,7 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
 	struct map_rb_node *rb_node;
 
 	maps__for_each_entry(thread->maps, rb_node) {
-		struct dso *dso = rb_node->map->dso;
+		struct dso *dso = map__dso(rb_node->map);
 
 		if (!dso || dso->long_name[0] != '/')
 			continue;
Signature · 1 line
2.35.1.265.g69c8d7142f-goog
Signature · 1 line
- Arnaldo
author reviewer
#45 lore raw

Re: [PATCH v3 15/22] perf map: Use functions to access the variables in map

Quoted 70 lines · Arnaldo Carvalho de Melo

Em Fri, Feb 11, 2022 at 02:34:08AM -0800, Ian Rogers escreveu:

Quoted 68 lines

The use of functions enables easier reference count checking. Some minor changes to map_ip and unmap_ip to making the naming a little clearer. __maps_insert is modified to return the inserted map, which simplifies the reference checking wrapping. maps__fixup_overlappings has some minor tweaks so that puts occur on error paths. dso__process_kernel_symbol has the unused curr_mapp argument removed.

---
 tools/perf/arch/s390/annotate/instructions.c  |   4 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c      |   2 +-
 tools/perf/arch/x86/util/event.c              |   6 +-
 tools/perf/builtin-annotate.c                 |   8 +-
 tools/perf/builtin-inject.c                   |   8 +-
 tools/perf/builtin-kallsyms.c                 |   6 +-
 tools/perf/builtin-kmem.c                     |   4 +-
 tools/perf/builtin-mem.c                      |   4 +-
 tools/perf/builtin-report.c                   |  20 +--
 tools/perf/builtin-script.c                   |  26 ++--
 tools/perf/builtin-top.c                      |  12 +-
 tools/perf/builtin-trace.c                    |   2 +-
 .../scripts/python/Perf-Trace-Util/Context.c  |   7 +-
 tools/perf/tests/code-reading.c               |  32 ++---
 tools/perf/tests/hists_common.c               |   4 +-
 tools/perf/tests/vmlinux-kallsyms.c           |  35 +++---
 tools/perf/ui/browsers/annotate.c             |   7 +-
 tools/perf/ui/browsers/hists.c                |  18 +--
 tools/perf/ui/browsers/map.c                  |   4 +-
 tools/perf/util/annotate.c                    |  38 +++---
 tools/perf/util/auxtrace.c                    |   2 +-
 tools/perf/util/block-info.c                  |   4 +-
 tools/perf/util/bpf-event.c                   |   8 +-
 tools/perf/util/build-id.c                    |   2 +-
 tools/perf/util/callchain.c                   |  10 +-
 tools/perf/util/data-convert-json.c           |   4 +-
 tools/perf/util/db-export.c                   |   4 +-
 tools/perf/util/dlfilter.c                    |  21 ++--
 tools/perf/util/dso.c                         |   4 +-
 tools/perf/util/event.c                       |  14 +--
 tools/perf/util/evsel_fprintf.c               |   4 +-
 tools/perf/util/hist.c                        |  10 +-
 tools/perf/util/intel-pt.c                    |  48 +++----
 tools/perf/util/machine.c                     |  84 +++++++------
 tools/perf/util/map.c                         | 117 +++++++++---------
 tools/perf/util/map.h                         |  58 ++++++++-
 tools/perf/util/maps.c                        |  83 +++++++------
 tools/perf/util/probe-event.c                 |  44 +++----
 .../util/scripting-engines/trace-event-perl.c |   9 +-
 .../scripting-engines/trace-event-python.c    |  12 +-
 tools/perf/util/sort.c                        |  46 +++----
 tools/perf/util/symbol-elf.c                  |  39 +++---
 tools/perf/util/symbol.c                      |  96 +++++++-------
 tools/perf/util/symbol_fprintf.c              |   2 +-
 tools/perf/util/synthetic-events.c            |  28 ++---
 tools/perf/util/thread.c                      |  26 ++--
 tools/perf/util/unwind-libunwind-local.c      |  34 ++---
 tools/perf/util/unwind-libunwind.c            |   4 +-
 tools/perf/util/vdso.c                        |   2 +-
 49 files changed, 577 insertions(+), 489 deletions(-)
tools/perf/arch/s390/annotate/instructions.c +0 -0
index 0e136630659e..740f1a63bc04 100644
@@ -39,7 +39,9 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
      target.addr = map__objdump_2mem(map, ops->target.addr);
 
Quoted 9 lines

tools/perf/arch/s390/annotate/instructions.c static int s390_call__parse(struct arch *arch, struct ins_operands *ops, · line 44

Quoted 5 lines
tools/perf/arch/s390/annotate/instructions.c +3 -1
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                          ) == ops->target.addr)

This changes nothing, right? Please try not to do this in the v2 for this patch.

Agreed. The original code here looks wrong to me. I would have translated this into map__map_ip, but that would have changed the function pointer from map->map_ip to target.ms.map->map_ip. The reformatting is so that when I add a reference count check here the lines aren't reformatted and that change is more minimal and obvious. I think the right thing is really to use map__map_ip. That goes beyond what this change was trying to do, and I lack a means to test this code. Could you investigate? If I switch this to map__map_ip in v2 then it resolves this issue and is most likely the right thing, its just that's a behavioral change that I was trying to avoid in this change.

Thanks,
Ian

Quoted 3,148 lines

- Arnaldo

Quoted 3,141 lines
tools/perf/arch/s390/annotate/instructions.c +0 -0
              ops->target.sym = target.ms.sym;
 
      return 0;
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index a54dea7c112f..497593be80f2 100644
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,
              return -1;
      }
 
-     stack_size = map->end - sp;
+     stack_size = map__end(map) - sp;
      stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
 
      memcpy(buf, (void *) sp, stack_size);
tools/perf/arch/x86/util/event.c +3 -3
index 7b6b0c98fb36..c790c682b76e 100644
@@ -57,9 +57,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
 
              event->mmap.header.size = size;
 
-             event->mmap.start = map->start;
-             event->mmap.len   = map->end - map->start;
-             event->mmap.pgoff = map->pgoff;
+             event->mmap.start = map__start(map);
+             event->mmap.len   = map__size(map);
+             event->mmap.pgoff = map__pgoff(map);
              event->mmap.pid   = machine->pid;
 
              strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
tools/perf/builtin-annotate.c +4 -4
index 490bb9b8cf17..49d3ae36fd89 100644
@@ -199,7 +199,7 @@ static int process_branch_callback(struct evsel *evsel,
              return 0;
 
      if (a.map != NULL)
-             a.map->dso->hit = 1;
+             map__dso(a.map)->hit = 1;
 
      hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
@@ -231,9 +231,9 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
               */
              if (al->sym != NULL) {
                      rb_erase_cached(&al->sym->rb_node,
-                              &al->map->dso->symbols);
+                                     &map__dso(al->map)->symbols);
                      symbol__delete(al->sym);
-                     dso__reset_find_symbol_cache(al->map->dso);
+                     dso__reset_find_symbol_cache(map__dso(al->map));
              }
              return 0;
      }
@@ -315,7 +315,7 @@ static void hists__find_annotations(struct hists *hists,
              struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
              struct annotation *notes;
 
-             if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
+             if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
                      goto find_next;
 
              if (ann->sym_hist_filter &&
tools/perf/builtin-inject.c +4 -4
index f7917c390e96..92a9dbc3d4cd 100644
@@ -600,10 +600,10 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
      }
 
      if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
-             if (!al.map->dso->hit) {
-                     al.map->dso->hit = 1;
-                     dso__inject_build_id(al.map->dso, tool, machine,
-                                          sample->cpumode, al.map->flags);
+             if (!map__dso(al.map)->hit) {
+                     map__dso(al.map)->hit = 1;
+                     dso__inject_build_id(map__dso(al.map), tool, machine,
+                                          sample->cpumode, map__flags(al.map));
              }
      }
 
tools/perf/builtin-kallsyms.c +4 -2
index c08ee81529e8..d940b60ce812 100644
@@ -36,8 +36,10 @@ static int __cmd_kallsyms(int argc, const char **argv)
              }
 
              printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
-                     symbol->name, map->dso->short_name, map->dso->long_name,
-                     map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
+                     symbol->name, map__dso(map)->short_name,
+                     map__dso(map)->long_name,
+                     map__unmap_ip(map, symbol->start),
+                     map__unmap_ip(map, symbol->end),
                      symbol->start, symbol->end);
      }
 
tools/perf/builtin-kmem.c +2 -2
index 99d7ff9a8eff..d87d9c341a20 100644
@@ -410,7 +410,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
              if (!caller) {
                      /* found */
                      if (node->ms.map)
-                             addr = map__unmap_ip(node->ms.map, node->ip);
+                             addr = map__dso_unmap_ip(node->ms.map, node->ip);
                      else
                              addr = node->ip;
 
@@ -1012,7 +1012,7 @@ static void __print_slab_result(struct rb_root *root,
 
              if (sym != NULL)
                      snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
-                              addr - map->unmap_ip(map, sym->start));
+                              addr - map__unmap_ip(map, sym->start));
              else
                      snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
              printf(" %-34s |", buf);
tools/perf/builtin-mem.c +2 -2
index fcf65a59bea2..d18083f57303 100644
@@ -200,7 +200,7 @@ dump_raw_samples(struct perf_tool *tool,
              goto out_put;
 
      if (al.map != NULL)
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      field_sep = symbol_conf.field_sep;
      if (field_sep) {
@@ -241,7 +241,7 @@ dump_raw_samples(struct perf_tool *tool,
              symbol_conf.field_sep,
              sample->data_src,
              symbol_conf.field_sep,
-             al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+             al.map && map__dso(al.map) ? map__dso(al.map)->long_name : "???",
              al.sym ? al.sym->name : "???");
 out_put:
      addr_location__put(&al);
tools/perf/builtin-report.c +11 -9
index 57611ef725c3..9b92b2bbd7de 100644
@@ -304,7 +304,7 @@ static int process_sample_event(struct perf_tool *tool,
      }
 
      if (al.map != NULL)
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
              hist__account_cycles(sample->branch_stack, &al, sample,
@@ -579,7 +579,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
              return;
 
      if (kernel_map == NULL ||
-         (kernel_map->dso->hit &&
+         (map__dso(kernel_map)->hit &&
           (kernel_kmap->ref_reloc_sym == NULL ||
            kernel_kmap->ref_reloc_sym->addr == 0))) {
              const char *desc =
@@ -805,13 +805,15 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
              struct map *map = rb_node->map;
 
              printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
-                                indent, "", map->start, map->end,
-                                map->prot & PROT_READ ? 'r' : '-',
-                                map->prot & PROT_WRITE ? 'w' : '-',
-                                map->prot & PROT_EXEC ? 'x' : '-',
-                                map->flags & MAP_SHARED ? 's' : 'p',
-                                map->pgoff,
-                                map->dso->id.ino, map->dso->name);
+                                indent, "",
+                                map__start(map), map__end(map),
+                                map__prot(map) & PROT_READ ? 'r' : '-',
+                                map__prot(map) & PROT_WRITE ? 'w' : '-',
+                                map__prot(map) & PROT_EXEC ? 'x' : '-',
+                                map__flags(map) & MAP_SHARED ? 's' : 'p',
+                                map__pgoff(map),
+                                map__dso(map)->id.ino,
+                                map__dso(map)->name);
      }
 
      return printed;
tools/perf/builtin-script.c +13 -13
index abae8184e171..4edfce95e137 100644
@@ -972,12 +972,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
              to   = entries[i].to;
 
              if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
-                 !alf.map->dso->adjust_symbols)
-                     from = map__map_ip(alf.map, from);
+                 !map__dso(alf.map)->adjust_symbols)
+                     from = map__dso_map_ip(alf.map, from);
 
              if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
-                 !alt.map->dso->adjust_symbols)
-                     to = map__map_ip(alt.map, to);
+                 !map__dso(alt.map)->adjust_symbols)
+                     to = map__dso_map_ip(alt.map, to);
 
              printed += fprintf(fp, " 0x%"PRIx64, from);
              if (PRINT_FIELD(DSO)) {
@@ -1039,11 +1039,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
              return 0;
      }
 
-     if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
+     if (!thread__find_map(thread, *cpumode, start, &al) || !map__dso(al.map)) {
              pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
              return 0;
      }
-     if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
+     if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR) {
              pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
              return 0;
      }
@@ -1051,11 +1051,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
      /* Load maps to ensure dso->is_64_bit has been updated */
      map__load(al.map);
 
-     offset = al.map->map_ip(al.map, start);
-     len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
-                                 end - start + MAXINSN);
+     offset = map__map_ip(al.map, start);
+     len = dso__data_read_offset(map__dso(al.map), machine, offset,
+                                 (u8 *)buffer, end - start + MAXINSN);
 
-     *is64bit = al.map->dso->is_64_bit;
+     *is64bit = map__dso(al.map)->is_64_bit;
      if (len <= 0)
              pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
                      start, end);
@@ -1070,9 +1070,9 @@ static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srcc
      int len;
      char *srccode;
 
-     if (!map || !map->dso)
+     if (!map || !map__dso(map))
              return 0;
-     srcfile = get_srcline_split(map->dso,
+     srcfile = get_srcline_split(map__dso(map),
                                  map__rip_2objdump(map, addr),
                                  &line);
      if (!srcfile)
@@ -1164,7 +1164,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
      if (al.addr < al.sym->end)
              off = al.addr - al.sym->start;
      else
-             off = al.addr - al.map->start - al.sym->start;
+             off = al.addr - map__start(al.map) - al.sym->start;
      printed += fprintf(fp, "\t%s", al.sym->name);
      if (off)
              printed += fprintf(fp, "%+d", off);
tools/perf/builtin-top.c +7 -5
index 1fc390f136dd..8db1df7bdabe 100644
@@ -127,8 +127,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
      /*
       * We can't annotate with just /proc/kallsyms
       */
-     if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-         !dso__is_kcore(map->dso)) {
+     if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+         !dso__is_kcore(map__dso(map))) {
              pr_err("Can't annotate %s: No vmlinux file was found in the "
                     "path\n", sym->name);
              sleep(1);
@@ -180,8 +180,9 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
                  "Tools:  %s\n\n"
                  "Not all samples will be on the annotation output.\n\n"
                  "Please report to [email protected]\n",
-                 ip, map->dso->long_name, dso__symtab_origin(map->dso),
-                 map->start, map->end, sym->start, sym->end,
+                 ip, map__dso(map)->long_name,
+                 dso__symtab_origin(map__dso(map)),
+                 map__start(map), map__end(map), sym->start, sym->end,
                  sym->binding == STB_GLOBAL ? 'g' :
                  sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
                  err ? "[unknown]" : uts.machine,
@@ -810,7 +811,8 @@ static void perf_event__process_sample(struct perf_tool *tool,
                  __map__is_kernel(al.map) && map__has_symbols(al.map)) {
                      if (symbol_conf.vmlinux_name) {
                              char serr[256];
-                             dso__strerror_load(al.map->dso, serr, sizeof(serr));
+                             dso__strerror_load(map__dso(al.map),
+                                                serr, sizeof(serr));
                              ui__warning("The %s file can't be used: %s\n%s",
                                          symbol_conf.vmlinux_name, serr, msg);
                      } else {
tools/perf/builtin-trace.c +1 -1
index 32844d8a0ea5..0134f24da3e3 100644
@@ -2862,7 +2862,7 @@ static void print_location(FILE *f, struct perf_sample *sample,
 {
 
      if ((verbose > 0 || print_dso) && al->map)
-             fprintf(f, "%s@", al->map->dso->long_name);
+             fprintf(f, "%s@", map__dso(al->map)->long_name);
 
      if ((verbose > 0 || print_sym) && al->sym)
              fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/scripts/python/Perf-Trace-Util/Context.c +4 -3
index b64013a87c54..b83b62d33945 100644
@@ -152,9 +152,10 @@ static PyObject *perf_sample_src(PyObject *obj, PyObject *args, bool get_srccode
      map = c->al->map;
      addr = c->al->addr;
 
-     if (map && map->dso)
-             srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+     if (map && map__dso(map)) {
+             srcfile = get_srcline_split(map__dso(map),
+                                         map__rip_2objdump(map, addr), &line);
+     }
      if (get_srccode) {
              if (srcfile)
                      srccode = find_sourceline(srcfile, line, &len);
tools/perf/tests/code-reading.c +16 -16
index 6eafe36a8704..9cb7d3f577d7 100644
@@ -240,7 +240,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
      pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-     if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
+     if (!thread__find_map(thread, cpumode, addr, &al) || !map__dso(al.map)) {
              if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
                      pr_debug("Hypervisor address can not be resolved - skipping\n");
                      return 0;
@@ -250,10 +250,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              return -1;
      }
 
-     pr_debug("File is: %s\n", al.map->dso->long_name);
+     pr_debug("File is: %s\n", map__dso(al.map)->long_name);
 
-     if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-         !dso__is_kcore(al.map->dso)) {
+     if (map__dso(al.map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+         !dso__is_kcore(map__dso(al.map))) {
              pr_debug("Unexpected kernel address - skipping\n");
              return 0;
      }
@@ -264,11 +264,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              len = BUFSZ;
 
      /* Do not go off the map */
-     if (addr + len > al.map->end)
-             len = al.map->end - addr;
+     if (addr + len > map__end(al.map))
+             len = map__end(al.map) - addr;
 
      /* Read the object code using perf */
-     ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
+     ret_len = dso__data_read_offset(map__dso(al.map), maps__machine(thread->maps),
                                      al.addr, buf1, len);
      if (ret_len != len) {
              pr_debug("dso__data_read_offset failed\n");
@@ -283,11 +283,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              return -1;
 
      /* objdump struggles with kcore - try each map only once */
-     if (dso__is_kcore(al.map->dso)) {
+     if (dso__is_kcore(map__dso(al.map))) {
              size_t d;
 
              for (d = 0; d < state->done_cnt; d++) {
-                     if (state->done[d] == al.map->start) {
+                     if (state->done[d] == map__start(al.map)) {
                              pr_debug("kcore map tested already");
                              pr_debug(" - skipping\n");
                              return 0;
@@ -297,12 +297,12 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
                      pr_debug("Too many kcore maps - skipping\n");
                      return 0;
              }
-             state->done[state->done_cnt++] = al.map->start;
+             state->done[state->done_cnt++] = map__start(al.map);
      }
 
-     objdump_name = al.map->dso->long_name;
-     if (dso__needs_decompress(al.map->dso)) {
-             if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+     objdump_name = map__dso(al.map)->long_name;
+     if (dso__needs_decompress(map__dso(al.map))) {
+             if (dso__decompress_kmodule_path(map__dso(al.map), objdump_name,
                                               decomp_name,
                                               sizeof(decomp_name)) < 0) {
                      pr_debug("decompression failed\n");
@@ -330,7 +330,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
                      len -= ret;
                      if (len) {
                              pr_debug("Reducing len to %zu\n", len);
-                     } else if (dso__is_kcore(al.map->dso)) {
+                     } else if (dso__is_kcore(map__dso(al.map))) {
                              /*
                               * objdump cannot handle very large segments
                               * that may be found in kcore.
@@ -588,8 +588,8 @@ static int do_test_code_reading(bool try_kcore)
              pr_debug("map__load failed\n");
              goto out_err;
      }
-     have_vmlinux = dso__is_vmlinux(map->dso);
-     have_kcore = dso__is_kcore(map->dso);
+     have_vmlinux = dso__is_vmlinux(map__dso(map));
+     have_kcore = dso__is_kcore(map__dso(map));
 
      /* 2nd time through we just try kcore */
      if (try_kcore && !have_kcore)
tools/perf/tests/hists_common.c +2 -2
index 6f34d08b84e5..40eccc659767 100644
@@ -181,7 +181,7 @@ void print_hists_in(struct hists *hists)
              if (!he->filtered) {
                      pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
                              i, thread__comm_str(he->thread),
-                             he->ms.map->dso->short_name,
+                             map__dso(he->ms.map)->short_name,
                              he->ms.sym->name, he->stat.period);
              }
 
@@ -208,7 +208,7 @@ void print_hists_out(struct hists *hists)
              if (!he->filtered) {
                      pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
                              i, thread__comm_str(he->thread), he->thread->tid,
-                             he->ms.map->dso->short_name,
+                             map__dso(he->ms.map)->short_name,
                              he->ms.sym->name, he->stat.period,
                              he->stat_acc ? he->stat_acc->period : 0);
              }
tools/perf/tests/vmlinux-kallsyms.c +19 -16
index 11a230ee5894..5afab21455f1 100644
@@ -13,7 +13,7 @@
 #include "debug.h"
 #include "machine.h"
 
-#define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
+#define UM(x) map__unmap_ip(kallsyms_map, (x))
 
 static bool is_ignored_symbol(const char *name, char type)
 {
@@ -216,8 +216,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
              if (sym->start == sym->end)
                      continue;
 
-             mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
-             mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
+             mem_start = map__unmap_ip(vmlinux_map, sym->start);
+             mem_end = map__unmap_ip(vmlinux_map, sym->end);
 
              first_pair = machine__find_kernel_symbol(&kallsyms, mem_start, NULL);
              pair = first_pair;
@@ -262,7 +262,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 
                              continue;
                      }
-             } else if (mem_start == kallsyms.vmlinux_map->end) {
+             } else if (mem_start == map__end(kallsyms.vmlinux_map)) {
                      /*
                       * Ignore aliases to _etext, i.e. to the end of the kernel text area,
                       * such as __indirect_thunk_end.
@@ -294,9 +294,10 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
               * so use the short name, less descriptive but the same ("[kernel]" in
               * both cases.
               */
-             struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
-                                                             map->dso->short_name :
-                                                             map->dso->name));
+             struct map *pair = maps__find_by_name(kallsyms.kmaps,
+                                             map__dso(map)->kernel
+                                             ? map__dso(map)->short_name
+                                             : map__dso(map)->name);
              if (pair) {
                      pair->priv = 1;
              } else {
@@ -313,25 +314,27 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
      maps__for_each_entry(maps, rb_node) {
              struct map *pair, *map = rb_node->map;
 
-             mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
-             mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
+             mem_start = map__unmap_ip(vmlinux_map, map__start(map));
+             mem_end = map__unmap_ip(vmlinux_map, map__end(map));
 
              pair = maps__find(kallsyms.kmaps, mem_start);
-             if (pair == NULL || pair->priv)
+             if (pair == NULL || map__priv(pair))
                      continue;
 
-             if (pair->start == mem_start) {
+             if (map__start(pair) == mem_start) {
                      if (!header_printed) {
                              pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
                              header_printed = true;
                      }
 
                      pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
-                             map->start, map->end, map->pgoff, map->dso->name);
-                     if (mem_end != pair->end)
+                             map__start(map), map__end(map),
+                             map__pgoff(map), map__dso(map)->name);
+                     if (mem_end != map__end(pair))
                              pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
-                                     pair->start, pair->end, pair->pgoff);
-                     pr_info(" %s\n", pair->dso->name);
+                                     map__start(pair), map__end(pair),
+                                     map__pgoff(pair));
+                     pr_info(" %s\n", map__dso(pair)->name);
                      pair->priv = 1;
              }
      }
@@ -343,7 +346,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
      maps__for_each_entry(maps, rb_node) {
              struct map *map = rb_node->map;
 
-             if (!map->priv) {
+             if (!map__priv(map)) {
                      if (!header_printed) {
                              pr_info("WARN: Maps only in kallsyms:\n");
                              header_printed = true;
tools/perf/ui/browsers/annotate.c +4 -3
index 44ba900828f6..7d51d92302dc 100644
@@ -446,7 +446,8 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 static int sym_title(struct symbol *sym, struct map *map, char *title,
                   size_t sz, int percent_type)
 {
-     return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+     return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+                     map__dso(map)->long_name,
                      percent_type_str(percent_type));
 }
 
@@ -971,14 +972,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
      if (sym == NULL)
              return -1;
 
-     if (ms->map->dso->annotate_warned)
+     if (map__dso(ms->map)->annotate_warned)
              return -1;
 
      if (not_annotated) {
              err = symbol__annotate2(ms, evsel, opts, &browser.arch);
              if (err) {
                      char msg[BUFSIZ];
-                     ms->map->dso->annotate_warned = true;
+                     map__dso(ms->map)->annotate_warned = true;
                      symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
                      ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
                      goto out_free_offsets;
tools/perf/ui/browsers/hists.c +11 -7
index 572ff38ceb0f..2241447e9bfb 100644
@@ -2487,7 +2487,7 @@ static struct symbol *symbol__new_unresolved(u64 addr, struct map *map)
                      return NULL;
              }
 
-             dso__insert_symbol(map->dso, sym);
+             dso__insert_symbol(map__dso(map), sym);
      }
 
      return sym;
@@ -2499,7 +2499,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
               struct map_symbol *ms,
               u64 addr)
 {
-     if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
+     if (!ms->map || !map__dso(ms->map) || map__dso(ms->map)->annotate_warned)
              return 0;
 
      if (!ms->sym)
@@ -2590,8 +2590,10 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map
              ui_helpline__pop();
      } else {
              ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
-                                __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
-             browser->hists->dso_filter = map->dso;
+                                __map__is_kernel(map)
+                                ? "the Kernel"
+                                : map__dso(map)->short_name);
+             browser->hists->dso_filter = map__dso(map);
              perf_hpp__set_elide(HISTC_DSO, true);
              pstack__push(browser->pstack, &browser->hists->dso_filter);
      }
@@ -2616,7 +2618,9 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,
 
      if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
                   browser->hists->dso_filter ? "out of" : "into",
-                  __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
+                  __map__is_kernel(map)
+                  ? "the Kernel"
+                  : map__dso(map)->short_name) < 0)
              return 0;
 
      act->ms.map = map;
@@ -3091,8 +3095,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
 
                      if (!browser->selection ||
                          !browser->selection->map ||
-                         !browser->selection->map->dso ||
-                         browser->selection->map->dso->annotate_warned) {
+                         !map__dso(browser->selection->map) ||
+                         map__dso(browser->selection->map)->annotate_warned) {
                              continue;
                      }
 
tools/perf/ui/browsers/map.c +2 -2
index 3d49b916c9e4..3d1b958d8832 100644
@@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser)
 {
      int key;
 
-     if (ui_browser__show(&browser->b, browser->map->dso->long_name,
+     if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name,
                           "Press ESC to exit, %s / to search",
                           verbose > 0 ? "" : "restart with -v to use") < 0)
              return -1;
@@ -106,7 +106,7 @@ int map__browse(struct map *map)
 {
      struct map_browser mb = {
              .b = {
-                     .entries = &map->dso->symbols,
+                     .entries = &map__dso(map)->symbols,
                      .refresh = ui_browser__rb_tree_refresh,
                      .seek    = ui_browser__rb_tree_seek,
                      .write   = map_browser__write,
tools/perf/util/annotate.c +21 -17
index 01900689dc00..3a7433d3e48a 100644
@@ -280,7 +280,9 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
      target.addr = map__objdump_2mem(map, ops->target.addr);
 
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                           ) == ops->target.addr)
              ops->target.sym = target.ms.sym;
 
      return 0;
@@ -384,8 +386,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
      }
 
      target.addr = map__objdump_2mem(map, ops->target.addr);
-     start = map->unmap_ip(map, sym->start),
-     end = map->unmap_ip(map, sym->end);
+     start = map__unmap_ip(map, sym->start),
+     end = map__unmap_ip(map, sym->end);
 
      ops->target.outside = target.addr < start || target.addr > end;
 
@@ -408,7 +410,9 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
       * the symbol searching and disassembly should be done.
       */
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                           ) == ops->target.addr)
              ops->target.sym = target.ms.sym;
 
      if (!ops->target.outside) {
@@ -889,7 +893,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms,
      unsigned offset;
      struct sym_hist *h;
 
-     pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, ms->map->unmap_ip(ms->map, addr));
+     pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map__unmap_ip(ms->map, addr));
 
      if ((addr < sym->start || addr >= sym->end) &&
          (addr != sym->end || sym->start != sym->end)) {
@@ -1016,13 +1020,13 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
      if (start &&
              (start->ms.sym == ams->ms.sym ||
               (ams->ms.sym &&
-                start->addr == ams->ms.sym->start + ams->ms.map->start)))
+               start->addr == ams->ms.sym->start + map__start(ams->ms.map))))
              saddr = start->al_addr;
      if (saddr == 0)
              pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n",
                      ams->addr,
                      start ? start->addr : 0,
-                     ams->ms.sym ? ams->ms.sym->start + ams->ms.map->start : 0,
+                     ams->ms.sym ? ams->ms.sym->start + map__start(ams->ms.map) : 0,
                      saddr);
      err = symbol__account_cycles(ams->al_addr, saddr, ams->ms.sym, cycles);
      if (err)
@@ -1593,7 +1597,7 @@ static void delete_last_nop(struct symbol *sym)
 
 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
 
      BUG_ON(buflen == 0);
 
@@ -1723,7 +1727,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
      struct map *map = args->ms.map;
      struct perf_bpil *info_linear;
      struct disassemble_info info;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      int pc = 0, count, sub_id;
      struct btf *btf = NULL;
      char tpath[PATH_MAX];
@@ -1946,7 +1950,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 {
      struct annotation_options *opts = args->options;
      struct map *map = args->ms.map;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      char *command;
      FILE *file;
      char symfs_filename[PATH_MAX];
@@ -1973,8 +1977,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
              return err;
 
      pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
-              symfs_filename, sym->name, map->unmap_ip(map, sym->start),
-              map->unmap_ip(map, sym->end));
+              symfs_filename, sym->name, map__unmap_ip(map, sym->start),
+              map__unmap_ip(map, sym->end));
 
      pr_debug("annotating [%p] %30s : [%p] %30s\n",
               dso, dso->long_name, sym, sym->name);
@@ -2386,7 +2390,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
 {
      struct map *map = ms->map;
      struct symbol *sym = ms->sym;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      char *filename;
      const char *d_filename;
      const char *evsel_name = evsel__name(evsel);
@@ -2569,7 +2573,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
      }
 
      fprintf(fp, "%s() %s\nEvent: %s\n\n",
-             ms->sym->name, ms->map->dso->long_name, ev_name);
+             ms->sym->name, map__dso(ms->map)->long_name, ev_name);
      symbol__annotate_fprintf2(ms->sym, fp, opts);
 
      fclose(fp);
@@ -2781,7 +2785,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
              if (percent_max <= 0.5)
                      continue;
 
-             al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
+             al->path = get_srcline(map__dso(map), notes->start + al->offset, NULL,
                                     false, true, notes->start + al->offset);
              insert_source_line(&tmp_root, al, opts);
      }
@@ -2800,7 +2804,7 @@ static void symbol__calc_lines(struct map_symbol *ms, struct rb_root *root,
 int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
                        struct annotation_options *opts)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
      struct symbol *sym = ms->sym;
      struct rb_root source_line = RB_ROOT;
      struct hists *hists = evsel__hists(evsel);
@@ -2836,7 +2840,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel,
                       struct annotation_options *opts)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
      struct symbol *sym = ms->sym;
      struct rb_root source_line = RB_ROOT;
      int err;
tools/perf/util/auxtrace.c +1 -1
index 825336304a37..2e864c9bdef3 100644
@@ -2478,7 +2478,7 @@ static struct dso *load_dso(const char *name)
      if (map__load(map) < 0)
              pr_err("File '%s' not found or has no symbols.\n", name);
 
-     dso = dso__get(map->dso);
+     dso = dso__get(map__dso(map));
 
      map__put(map);
 
tools/perf/util/block-info.c +2 -2
index 5ecd4f401f32..16a7b4adcf18 100644
@@ -317,9 +317,9 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
      struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
      struct map *map = he->ms.map;
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
-                              map->dso->short_name);
+                              map__dso(map)->short_name);
      }
 
      return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
tools/perf/util/bpf-event.c +4 -4
index 33257b594a71..5717933be116 100644
@@ -95,10 +95,10 @@ static int machine__process_bpf_event_load(struct machine *machine,
              struct map *map = maps__find(machine__kernel_maps(machine), addr);
 
              if (map) {
-                     map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
-                     map->dso->bpf_prog.id = id;
-                     map->dso->bpf_prog.sub_id = i;
-                     map->dso->bpf_prog.env = env;
+                     map__dso(map)->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+                     map__dso(map)->bpf_prog.id = id;
+                     map__dso(map)->bpf_prog.sub_id = i;
+                     map__dso(map)->bpf_prog.env = env;
              }
      }
      return 0;
tools/perf/util/build-id.c +1 -1
index 7a5821c87f94..274b705dd941 100644
@@ -59,7 +59,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
      }
 
      if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      thread__put(thread);
      return 0;
tools/perf/util/callchain.c +5 -5
index 61bb3fb2107a..a8cfd31a3ff0 100644
@@ -695,8 +695,8 @@ static enum match_result match_chain_strings(const char *left,
 static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
                                                 struct map *right_map, u64 right_ip)
 {
-     struct dso *left_dso = left_map ? left_map->dso : NULL;
-     struct dso *right_dso = right_map ? right_map->dso : NULL;
+     struct dso *left_dso = left_map ? map__dso(left_map) : NULL;
+     struct dso *right_dso = right_map ? map__dso(right_map) : NULL;
 
      if (left_dso != right_dso)
              return left_dso < right_dso ? MATCH_LT : MATCH_GT;
@@ -1167,9 +1167,9 @@ char *callchain_list__sym_name(struct callchain_list *cl,
 
      if (show_dso)
              scnprintf(bf + printed, bfsize - printed, " %s",
-                       cl->ms.map ?
-                       cl->ms.map->dso->short_name :
-                       "unknown");
+                       cl->ms.map
+                       ? map__dso(cl->ms.map)->short_name
+                       : "unknown");
 
      return bf;
 }
tools/perf/util/data-convert-json.c +2 -2
index f1ab6edba446..9c83228bb9f1 100644
@@ -127,8 +127,8 @@ static void output_sample_callchain_entry(struct perf_tool *tool,
              fputc(',', out);
              output_json_key_string(out, false, 5, "symbol", al->sym->name);
 
-             if (al->map && al->map->dso) {
-                     const char *dso = al->map->dso->short_name;
+             if (al->map && map__dso(al->map)) {
+                     const char *dso = map__dso(al->map)->short_name;
 
                      if (dso && strlen(dso) > 0) {
                              fputc(',', out);
tools/perf/util/db-export.c +2 -2
index 1cfcfdd3cf52..84c970c11794 100644
@@ -179,7 +179,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
      int err;
 
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              err = db_export__dso(dbe, dso, maps__machine(al->maps));
              if (err)
@@ -255,7 +255,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
              al.addr = node->ip;
 
              if (al.map && !al.sym)
-                     al.sym = dso__find_symbol(al.map->dso, al.addr);
+                     al.sym = dso__find_symbol(map__dso(al.map), al.addr);
 
              db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
tools/perf/util/dlfilter.c +11 -10
index d59462af15f1..f1d9dd7065e6 100644
@@ -29,7 +29,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 
      d_al->size = sizeof(*d_al);
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              if (symbol_conf.show_kernel_path && dso->long_name)
                      d_al->dso = dso->long_name;
@@ -51,7 +51,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
              if (al->addr < sym->end)
                      d_al->symoff = al->addr - sym->start;
              else
-                     d_al->symoff = al->addr - al->map->start - sym->start;
+                     d_al->symoff = al->addr - map__start(al->map) - sym->start;
              d_al->sym_binding = sym->binding;
      } else {
              d_al->sym = NULL;
@@ -232,9 +232,10 @@ static const char *dlfilter__srcline(void *ctx, __u32 *line_no)
      map = al->map;
      addr = al->addr;
 
-     if (map && map->dso)
-             srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+     if (map && map__dso(map)) {
+             srcfile = get_srcline_split(map__dso(map),
+                                         map__rip_2objdump(map, addr), &line);
+     }
      *line_no = line;
      return srcfile;
 }
@@ -266,7 +267,7 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
      map = al->map;
 
-     if (map && ip >= map->start && ip < map->end &&
+     if (map && ip >= map__start(map) && ip < map__end(map) &&
          machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
              goto have_map;
 
@@ -276,10 +277,10 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
      map = a.map;
 have_map:
-     offset = map->map_ip(map, ip);
-     if (ip + len >= map->end)
-             len = map->end - ip;
-     return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
+     offset = map__map_ip(map, ip);
+     if (ip + len >= map__end(map))
+             len = map__end(map) - ip;
+     return dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
 }
 
 static const struct perf_dlfilter_fns perf_dlfilter_fns = {
tools/perf/util/dso.c +2 -2
index b2f570adba35..1115bc51a261 100644
@@ -1109,7 +1109,7 @@ ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
                          struct machine *machine, u64 addr,
                          u8 *data, ssize_t size)
 {
-     u64 offset = map->map_ip(map, addr);
+     u64 offset = map__map_ip(map, addr);
      return dso__data_read_offset(dso, machine, offset, data, size);
 }
 
@@ -1149,7 +1149,7 @@ ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
                                 struct machine *machine, u64 addr,
                                 const u8 *data, ssize_t size)
 {
-     u64 offset = map->map_ip(map, addr);
+     u64 offset = map__map_ip(map, addr);
      return dso__data_write_cache_offs(dso, machine, offset, data, size);
 }
 
tools/perf/util/event.c +7 -7
index 40a3b1a35613..54a1d4df5f70 100644
@@ -486,7 +486,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
 
              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.addr = map__map_ip(al.map, tp->addr);
                      al.sym = map__find_symbol(al.map, al.addr);
                      if (al.sym)
                              ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
@@ -621,7 +621,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
               */
              if (load_map)
                      map__load(al->map);
-             al->addr = al->map->map_ip(al->map, al->addr);
+             al->addr = map__map_ip(al->map, al->addr);
      }
 
      return al->map;
@@ -692,8 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
      dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
      thread__find_map(thread, sample->cpumode, sample->ip, al);
      dump_printf(" ...... dso: %s\n",
-                 al->map ? al->map->dso->long_name :
-                     al->level == 'H' ? "[hypervisor]" : "<not found>");
+                 al->map ? map__dso(al->map)->long_name
+                         : al->level == 'H' ? "[hypervisor]" : "<not found>");
 
      if (thread__is_filtered(thread))
              al->filtered |= (1 << HIST_FILTER__THREAD);
@@ -711,7 +711,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
      }
 
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              if (symbol_conf.dso_list &&
                  (!dso || !(strlist__has_entry(symbol_conf.dso_list,
@@ -738,12 +738,12 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
              }
              if (!ret && al->sym) {
                      snprintf(al_addr_str, sz, "0x%"PRIx64,
-                             al->map->unmap_ip(al->map, al->sym->start));
+                              map__unmap_ip(al->map, al->sym->start));
                      ret = strlist__has_entry(symbol_conf.sym_list,
                                              al_addr_str);
              }
              if (!ret && symbol_conf.addr_list && al->map) {
-                     unsigned long addr = al->map->unmap_ip(al->map, al->addr);
+                     unsigned long addr = map__unmap_ip(al->map, al->addr);
 
                      ret = intlist__has_entry(symbol_conf.addr_list, addr);
                      if (!ret && symbol_conf.addr_range) {
tools/perf/util/evsel_fprintf.c +2 -2
index 8c2ea8001329..ac6fef9d8906 100644
@@ -146,11 +146,11 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
                              printed += fprintf(fp, " <-");
 
                      if (map)
-                             addr = map->map_ip(map, node->ip);
+                             addr = map__map_ip(map, node->ip);
 
                      if (print_ip) {
                              /* Show binary offset for userspace addr */
-                             if (map && !map->dso->kernel)
+                             if (map && !map__dso(map)->kernel)
                                      printed += fprintf(fp, "%c%16" PRIx64, s, addr);
                              else
                                      printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
tools/perf/util/hist.c +5 -5
index 78f9fbb925a7..f19ac6eb4775 100644
@@ -105,7 +105,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
              hists__set_col_len(hists, HISTC_THREAD, len + 8);
 
      if (h->ms.map) {
-             len = dso__name_len(h->ms.map->dso);
+             len = dso__name_len(map__dso(h->ms.map));
              hists__new_col_len(hists, HISTC_DSO, len);
      }
 
@@ -119,7 +119,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
                              symlen += BITS_PER_LONG / 4 + 2 + 3;
                      hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
-                     symlen = dso__name_len(h->branch_info->from.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->branch_info->from.ms.map));
                      hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
              } else {
                      symlen = unresolved_col_width + 4 + 2;
@@ -133,7 +133,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
                              symlen += BITS_PER_LONG / 4 + 2 + 3;
                      hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
-                     symlen = dso__name_len(h->branch_info->to.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->branch_info->to.ms.map));
                      hists__new_col_len(hists, HISTC_DSO_TO, symlen);
              } else {
                      symlen = unresolved_col_width + 4 + 2;
@@ -177,7 +177,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
              }
 
              if (h->mem_info->daddr.ms.map) {
-                     symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->mem_info->daddr.ms.map));
                      hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
                                         symlen);
              } else {
@@ -2096,7 +2096,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
                                     struct hist_entry *he)
 {
      if (hists->dso_filter != NULL &&
-         (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
+         (he->ms.map == NULL || map__dso(he->ms.map) != hists->dso_filter)) {
              he->filtered |= (1 << HIST_FILTER__DSO);
              return true;
      }
tools/perf/util/intel-pt.c +24 -24
index e8613cbda331..c88f112c0a06 100644
@@ -731,20 +731,20 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
      }
 
      while (1) {
-             if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
+             if (!thread__find_map(thread, cpumode, *ip, &al) || !map__dso(al.map))
                      return -EINVAL;
 
-             if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-                 dso__data_status_seen(al.map->dso,
+             if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR &&
+                 dso__data_status_seen(map__dso(al.map),
                                        DSO_DATA_STATUS_SEEN_ITRACE))
                      return -ENOENT;
 
-             offset = al.map->map_ip(al.map, *ip);
+             offset = map__map_ip(al.map, *ip);
 
              if (!to_ip && one_map) {
                      struct intel_pt_cache_entry *e;
 
-                     e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+                     e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
                      if (e &&
                          (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) {
                              *insn_cnt_ptr = e->insn_cnt;
@@ -766,10 +766,10 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
              /* Load maps to ensure dso->is_64_bit has been updated */
              map__load(al.map);
 
-             x86_64 = al.map->dso->is_64_bit;
+             x86_64 = map__dso(al.map)->is_64_bit;
 
              while (1) {
-                     len = dso__data_read_offset(al.map->dso, machine,
+                     len = dso__data_read_offset(map__dso(al.map), machine,
                                                  offset, buf,
                                                  INTEL_PT_INSN_BUF_SZ);
                      if (len <= 0)
@@ -795,7 +795,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
                              goto out_no_cache;
                      }
 
-                     if (*ip >= al.map->end)
+                     if (*ip >= map__end(al.map))
                              break;
 
                      offset += intel_pt_insn->length;
@@ -815,13 +815,13 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
      if (to_ip) {
              struct intel_pt_cache_entry *e;
 
-             e = intel_pt_cache_lookup(al.map->dso, machine, start_offset);
+             e = intel_pt_cache_lookup(map__dso(al.map), machine, start_offset);
              if (e)
                      return 0;
      }
 
      /* Ignore cache errors */
-     intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt,
+     intel_pt_cache_add(map__dso(al.map), machine, start_offset, insn_cnt,
                         *ip - start_ip, intel_pt_insn);
 
      return 0;
@@ -892,13 +892,13 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
      if (!thread)
              return -EINVAL;
 
-     if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
+     if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map))
              return -EINVAL;
 
-     offset = al.map->map_ip(al.map, ip);
+     offset = map__map_ip(al.map, ip);
 
      return intel_pt_match_pgd_ip(ptq->pt, ip, offset,
-                                  al.map->dso->long_name);
+                                  map__dso(al.map)->long_name);
 }
 
 static bool intel_pt_pgd_ip(uint64_t ip, void *data)
@@ -2406,13 +2406,13 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
      if (map__load(map))
              return 0;
 
-     start = dso__first_symbol(map->dso);
+     start = dso__first_symbol(map__dso(map));
 
      for (sym = start; sym; sym = dso__next_symbol(sym)) {
              if (sym->binding == STB_GLOBAL &&
                  !strcmp(sym->name, "__switch_to")) {
-                     ip = map->unmap_ip(map, sym->start);
-                     if (ip >= map->start && ip < map->end) {
+                     ip = map__unmap_ip(map, sym->start);
+                     if (ip >= map__start(map) && ip < map__end(map)) {
                              switch_ip = ip;
                              break;
                      }
@@ -2429,8 +2429,8 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 
      for (sym = start; sym; sym = dso__next_symbol(sym)) {
              if (!strcmp(sym->name, ptss)) {
-                     ip = map->unmap_ip(map, sym->start);
-                     if (ip >= map->start && ip < map->end) {
+                     ip = map__unmap_ip(map, sym->start);
+                     if (ip >= map__start(map) && ip < map__end(map)) {
                              *ptss_ip = ip;
                              break;
                      }
@@ -2965,7 +2965,7 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt,
 static int intel_pt_find_map(struct thread *thread, u8 cpumode, u64 addr,
                           struct addr_location *al)
 {
-     if (!al->map || addr < al->map->start || addr >= al->map->end) {
+     if (!al->map || addr < map__start(al->map) || addr >= map__end(al->map)) {
              if (!thread__find_map(thread, cpumode, addr, al))
                      return -1;
      }
@@ -2996,12 +2996,12 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
                      continue;
              }
 
-             if (!al.map->dso || !al.map->dso->auxtrace_cache)
+             if (!map__dso(al.map) || !map__dso(al.map)->auxtrace_cache)
                      continue;
 
-             offset = al.map->map_ip(al.map, addr);
+             offset = map__map_ip(al.map, addr);
 
-             e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+             e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
              if (!e)
                      continue;
 
@@ -3014,9 +3014,9 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
                      if (e->branch != INTEL_PT_BR_NO_BRANCH)
                              return 0;
              } else {
-                     intel_pt_cache_invalidate(al.map->dso, machine, offset);
+                     intel_pt_cache_invalidate(map__dso(al.map), machine, offset);
                      intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n",
-                                  al.map->dso->long_name, addr);
+                                  map__dso(al.map)->long_name, addr);
              }
      }
 
tools/perf/util/machine.c +44 -40
index 88279008e761..940fb2a50dfd 100644
@@ -47,7 +47,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
 
 static struct dso *machine__kernel_dso(struct machine *machine)
 {
-     return machine->vmlinux_map->dso;
+     return map__dso(machine->vmlinux_map);
 }
 
 static void dsos__init(struct dsos *dsos)
@@ -842,9 +842,10 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
      if (map != machine->vmlinux_map)
              maps__remove(machine__kernel_maps(machine), map);
      else {
-             sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+             sym = dso__find_symbol(map__dso(map),
+                             map__map_ip(map, map__start(map)));
              if (sym)
-                     dso__delete_symbol(map->dso, sym);
+                     dso__delete_symbol(map__dso(map), sym);
      }
 
      return 0;
@@ -880,7 +881,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
              return 0;
      }
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
              int ret;
 
@@ -889,7 +890,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
               * must be done prior to using kernel maps.
               */
              map__load(map);
-             ret = dso__data_write_cache_addr(map->dso, map, machine,
+             ret = dso__data_write_cache_addr(map__dso(map), map, machine,
                                               event->text_poke.addr,
                                               new_bytes,
                                               event->text_poke.new_len);
@@ -931,6 +932,7 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
      /* If maps__insert failed, return NULL. */
      if (err)
              map = NULL;
+
 out:
      /* put the dso here, corresponding to  machine__findnew_module_dso */
      dso__put(dso);
@@ -1118,7 +1120,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
      if (!err) {
              pr_debug2("Added extra kernel map %s %" PRIx64 "-%" PRIx64 "\n",
-                     kmap->name, map->start, map->end);
+                     kmap->name, map__start(map), map__end(map));
      }
 
      map__put(map);
@@ -1178,9 +1180,9 @@ int machine__map_x86_64_entry_trampolines(struct machine *machine,
              if (!kmap || !is_entry_trampoline(kmap->name))
                      continue;
 
-             dest_map = maps__find(kmaps, map->pgoff);
+             dest_map = maps__find(kmaps, map__pgoff(map));
              if (dest_map != map)
-                     map->pgoff = dest_map->map_ip(dest_map, map->pgoff);
+                     map->pgoff = map__map_ip(dest_map, map__pgoff(map));
              found = true;
      }
      if (found || machine->trampolines_mapped)
@@ -1230,7 +1232,8 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
      if (machine->vmlinux_map == NULL)
              return -ENOMEM;
 
-     machine->vmlinux_map->map_ip = machine->vmlinux_map->unmap_ip = identity__map_ip;
+     machine->vmlinux_map->map_ip = map__identity_ip;
+     machine->vmlinux_map->unmap_ip = map__identity_ip;
      return maps__insert(machine__kernel_maps(machine), machine->vmlinux_map);
 }
 
@@ -1329,10 +1332,10 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 int machine__load_kallsyms(struct machine *machine, const char *filename)
 {
      struct map *map = machine__kernel_map(machine);
-     int ret = __dso__load_kallsyms(map->dso, filename, map, true);
+     int ret = __dso__load_kallsyms(map__dso(map), filename, map, true);
 
      if (ret > 0) {
-             dso__set_loaded(map->dso);
+             dso__set_loaded(map__dso(map));
              /*
               * Since /proc/kallsyms will have multiple sessions for the
               * kernel, with modules between them, fixup the end of all
@@ -1347,10 +1350,10 @@ int machine__load_kallsyms(struct machine *machine, const char *filename)
 int machine__load_vmlinux_path(struct machine *machine)
 {
      struct map *map = machine__kernel_map(machine);
-     int ret = dso__load_vmlinux_path(map->dso, map);
+     int ret = dso__load_vmlinux_path(map__dso(map), map);
 
      if (ret > 0)
-             dso__set_loaded(map->dso);
+             dso__set_loaded(map__dso(map));
 
      return ret;
 }
@@ -1401,16 +1404,16 @@ static int maps__set_module_path(struct maps *maps, const char *path, struct kmo
      if (long_name == NULL)
              return -ENOMEM;
 
-     dso__set_long_name(map->dso, long_name, true);
-     dso__kernel_module_get_build_id(map->dso, "");
+     dso__set_long_name(map__dso(map), long_name, true);
+     dso__kernel_module_get_build_id(map__dso(map), "");
 
      /*
       * Full name could reveal us kmod compression, so
       * we need to update the symtab_type if needed.
       */
-     if (m->comp && is_kmod_dso(map->dso)) {
-             map->dso->symtab_type++;
-             map->dso->comp = m->comp;
+     if (m->comp && is_kmod_dso(map__dso(map))) {
+             map__dso(map)->symtab_type++;
+             map__dso(map)->comp = m->comp;
      }
 
      return 0;
@@ -1509,8 +1512,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
              return -1;
      map->end = start + size;
 
-     dso__kernel_module_get_build_id(map->dso, machine->root_dir);
-
+     dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
      return 0;
 }
 
@@ -1619,7 +1621,7 @@ int machine__create_kernel_maps(struct machine *machine)
              struct map_rb_node *next = map_rb_node__next(rb_node);
 
              if (next)
-                     machine__set_kernel_mmap(machine, start, next->map->start);
+                     machine__set_kernel_mmap(machine, start, map__start(next->map));
      }
 
 out_put:
@@ -1683,10 +1685,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
              if (map == NULL)
                      goto out_problem;
 
-             map->end = map->start + xm->end - xm->start;
+             map->end = map__start(map) + xm->end - xm->start;
 
              if (build_id__is_defined(bid))
-                     dso__set_build_id(map->dso, bid);
+                     dso__set_build_id(map__dso(map), bid);
 
      } else if (is_kernel_mmap) {
              const char *symbol_name = (xm->name + strlen(machine->mmap_name));
@@ -2148,14 +2150,14 @@ static char *callchain_srcline(struct map_symbol *ms, u64 ip)
      if (!map || callchain_param.key == CCKEY_FUNCTION)
              return srcline;
 
-     srcline = srcline__tree_find(&map->dso->srclines, ip);
+     srcline = srcline__tree_find(&map__dso(map)->srclines, ip);
      if (!srcline) {
              bool show_sym = false;
              bool show_addr = callchain_param.key == CCKEY_ADDRESS;
 
-             srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
+             srcline = get_srcline(map__dso(map), map__rip_2objdump(map, ip),
                                    ms->sym, show_sym, show_addr, ip);
-             srcline__tree_insert(&map->dso->srclines, ip, srcline);
+             srcline__tree_insert(&map__dso(map)->srclines, ip, srcline);
      }
 
      return srcline;
@@ -2179,7 +2181,7 @@ static int add_callchain_ip(struct thread *thread,
 {
      struct map_symbol ms;
      struct addr_location al;
-     int nr_loop_iter = 0;
+     int nr_loop_iter = 0, err;
      u64 iter_cycles = 0;
      const char *srcline = NULL;
 
@@ -2228,9 +2230,10 @@ static int add_callchain_ip(struct thread *thread,
              }
      }
 
-     if (symbol_conf.hide_unresolved && al.sym == NULL)
+     if (symbol_conf.hide_unresolved && al.sym == NULL) {
+             addr_location__put(&al);
              return 0;
-
+     }
      if (iter) {
              nr_loop_iter = iter->nr_loop_iter;
              iter_cycles = iter->cycles;
@@ -2240,9 +2243,10 @@ static int add_callchain_ip(struct thread *thread,
      ms.map = al.map;
      ms.sym = al.sym;
      srcline = callchain_srcline(&ms, al.addr);
-     return callchain_cursor_append(cursor, ip, &ms,
-                                    branch, flags, nr_loop_iter,
-                                    iter_cycles, branch_from, srcline);
+     err = callchain_cursor_append(cursor, ip, &ms,
+                                   branch, flags, nr_loop_iter,
+                                   iter_cycles, branch_from, srcline);
+     return err;
 }
 
 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -2937,15 +2941,15 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
      if (!symbol_conf.inline_name || !map || !sym)
              return ret;
 
-     addr = map__map_ip(map, ip);
+     addr = map__dso_map_ip(map, ip);
      addr = map__rip_2objdump(map, addr);
 
-     inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
+     inline_node = inlines__tree_find(&map__dso(map)->inlined_nodes, addr);
      if (!inline_node) {
-             inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
+             inline_node = dso__parse_addr_inlines(map__dso(map), addr, sym);
              if (!inline_node)
                      return ret;
-             inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
+             inlines__tree_insert(&map__dso(map)->inlined_nodes, inline_node);
      }
 
      list_for_each_entry(ilist, &inline_node->val, list) {
@@ -2981,7 +2985,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
       * its corresponding binary.
       */
      if (entry->ms.map)
-             addr = map__map_ip(entry->ms.map, entry->ip);
+             addr = map__dso_map_ip(entry->ms.map, entry->ip);
 
      srcline = callchain_srcline(&entry->ms, addr);
      return callchain_cursor_append(cursor, entry->ip, &entry->ms,
@@ -3183,7 +3187,7 @@ int machine__get_kernel_start(struct machine *machine)
               * kernel_start = 1ULL << 63 for x86_64.
               */
              if (!err && !machine__is(machine, "x86_64"))
-                     machine->kernel_start = map->start;
+                     machine->kernel_start = map__start(map);
      }
      return err;
 }
@@ -3234,8 +3238,8 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
      if (sym == NULL)
              return NULL;
 
-     *modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
-     *addrp = map->unmap_ip(map, sym->start);
+     *modp = __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NULL;
+     *addrp = map__unmap_ip(map, sym->start);
      return sym->name;
 }
 
tools/perf/util/map.c +61 -56
index 57e926ce115f..47d81e361e29 100644
@@ -109,8 +109,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
      map->pgoff    = pgoff;
      map->reloc    = 0;
      map->dso      = dso__get(dso);
-     map->map_ip   = map__map_ip;
-     map->unmap_ip = map__unmap_ip;
+     map->map_ip   = map__dso_map_ip;
+     map->unmap_ip = map__dso_unmap_ip;
      map->erange_warned = false;
      refcount_set(&map->refcnt, 1);
 }
@@ -120,10 +120,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
                   u32 prot, u32 flags, struct build_id *bid,
                   char *filename, struct thread *thread)
 {
-     struct map *map = malloc(sizeof(*map));
+     struct map *map;
      struct nsinfo *nsi = NULL;
      struct nsinfo *nnsi;
 
+     map = malloc(sizeof(*map));
      if (map != NULL) {
              char newfilename[PATH_MAX];
              struct dso *dso;
@@ -170,7 +171,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
              map__init(map, start, start + len, pgoff, dso);
 
              if (anon || no_dso) {
-                     map->map_ip = map->unmap_ip = identity__map_ip;
+                     map->map_ip = map->unmap_ip = map__identity_ip;
 
                      /*
                       * Set memory without DSO as loaded. All map__find_*
@@ -204,8 +205,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
  */
 struct map *map__new2(u64 start, struct dso *dso)
 {
-     struct map *map = calloc(1, (sizeof(*map) +
-                                  (dso->kernel ? sizeof(struct kmap) : 0)));
+     struct map *map;
+
+     map = calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0));
      if (map != NULL) {
              /*
               * ->end will be filled after we load all the symbols
@@ -218,7 +220,7 @@ struct map *map__new2(u64 start, struct dso *dso)
 
 bool __map__is_kernel(const struct map *map)
 {
-     if (!map->dso->kernel)
+     if (!map__dso(map)->kernel)
              return false;
      return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
 }
@@ -234,7 +236,7 @@ bool __map__is_bpf_prog(const struct map *map)
 {
      const char *name;
 
-     if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+     if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
              return true;
 
      /*
@@ -242,7 +244,7 @@ bool __map__is_bpf_prog(const struct map *map)
       * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
       * guess the type based on name.
       */
-     name = map->dso->short_name;
+     name = map__dso(map)->short_name;
      return name && (strstr(name, "bpf_prog_") == name);
 }
 
@@ -250,7 +252,7 @@ bool __map__is_bpf_image(const struct map *map)
 {
      const char *name;
 
-     if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+     if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
              return true;
 
      /*
@@ -258,18 +260,19 @@ bool __map__is_bpf_image(const struct map *map)
       * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
       * guess the type based on name.
       */
-     name = map->dso->short_name;
+     name = map__dso(map)->short_name;
      return name && is_bpf_image(name);
 }
 
 bool __map__is_ool(const struct map *map)
 {
-     return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+     return map__dso(map) &&
+            map__dso(map)->binary_type == DSO_BINARY_TYPE__OOL;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-     return dso__has_symbols(map->dso);
+     return dso__has_symbols(map__dso(map));
 }
 
 static void map__exit(struct map *map)
@@ -292,7 +295,7 @@ void map__put(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-     struct rb_root_cached *symbols = &map->dso->symbols;
+     struct rb_root_cached *symbols = &map__dso(map)->symbols;
      struct rb_node *nd = rb_first_cached(symbols);
      if (nd != NULL) {
              struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -302,7 +305,7 @@ void map__fixup_start(struct map *map)
 
 void map__fixup_end(struct map *map)
 {
-     struct rb_root_cached *symbols = &map->dso->symbols;
+     struct rb_root_cached *symbols = &map__dso(map)->symbols;
      struct rb_node *nd = rb_last(&symbols->rb_root);
      if (nd != NULL) {
              struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -314,18 +317,18 @@ void map__fixup_end(struct map *map)
 
 int map__load(struct map *map)
 {
-     const char *name = map->dso->long_name;
+     const char *name = map__dso(map)->long_name;
      int nr;
 
-     if (dso__loaded(map->dso))
+     if (dso__loaded(map__dso(map)))
              return 0;
 
-     nr = dso__load(map->dso, map);
+     nr = dso__load(map__dso(map), map);
      if (nr < 0) {
-             if (map->dso->has_build_id) {
+             if (map__dso(map)->has_build_id) {
                      char sbuild_id[SBUILD_ID_SIZE];
 
-                     build_id__sprintf(&map->dso->bid, sbuild_id);
+                     build_id__sprintf(&map__dso(map)->bid, sbuild_id);
                      pr_debug("%s with build id %s not found", name, sbuild_id);
              } else
                      pr_debug("Failed to open %s", name);
@@ -357,7 +360,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
      if (map__load(map) < 0)
              return NULL;
 
-     return dso__find_symbol(map->dso, addr);
+     return dso__find_symbol(map__dso(map), addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -365,24 +368,24 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
      if (map__load(map) < 0)
              return NULL;
 
-     if (!dso__sorted_by_name(map->dso))
-             dso__sort_by_name(map->dso);
+     if (!dso__sorted_by_name(map__dso(map)))
+             dso__sort_by_name(map__dso(map));
 
-     return dso__find_symbol_by_name(map->dso, name);
+     return dso__find_symbol_by_name(map__dso(map), name);
 }
 
 struct map *map__clone(struct map *from)
 {
-     size_t size = sizeof(struct map);
      struct map *map;
+     size_t size = sizeof(struct map);
 
-     if (from->dso && from->dso->kernel)
+     if (map__dso(from) && map__dso(from)->kernel)
              size += sizeof(struct kmap);
 
      map = memdup(from, size);
      if (map != NULL) {
              refcount_set(&map->refcnt, 1);
-             dso__get(map->dso);
+             map->dso = dso__get(map->dso);
      }
 
      return map;
@@ -391,7 +394,8 @@ struct map *map__clone(struct map *from)
 size_t map__fprintf(struct map *map, FILE *fp)
 {
      return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
-                    map->start, map->end, map->pgoff, map->dso->name);
+                    map__start(map), map__end(map),
+                    map__pgoff(map), map__dso(map)->name);
 }
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
@@ -399,11 +403,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
      char buf[symbol_conf.pad_output_len_dso + 1];
      const char *dsoname = "[unknown]";
 
-     if (map && map->dso) {
-             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                     dsoname = map->dso->long_name;
+     if (map && map__dso(map)) {
+             if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+                     dsoname = map__dso(map)->long_name;
              else
-                     dsoname = map->dso->name;
+                     dsoname = map__dso(map)->name;
      }
 
      if (symbol_conf.pad_output_len_dso) {
@@ -418,7 +422,8 @@ char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
 {
      if (map == NULL)
              return SRCLINE_UNKNOWN;
-     return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+     return get_srcline(map__dso(map), map__rip_2objdump(map, addr),
+                        sym, true, true, addr);
 }
 
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
@@ -426,7 +431,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 {
      int ret = 0;
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              char *srcline = map__srcline(map, addr, NULL);
              if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
                      ret = fprintf(fp, "%s%s", prefix, srcline);
@@ -472,20 +477,20 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
              }
      }
 
-     if (!map->dso->adjust_symbols)
+     if (!map__dso(map)->adjust_symbols)
              return rip;
 
-     if (map->dso->rel)
-             return rip - map->pgoff;
+     if (map__dso(map)->rel)
+             return rip - map__pgoff(map);
 
      /*
       * kernel modules also have DSO_TYPE_USER in dso->kernel,
       * but all kernel modules are ET_REL, so won't get here.
       */
-     if (map->dso->kernel == DSO_SPACE__USER)
-             return rip + map->dso->text_offset;
+     if (map__dso(map)->kernel == DSO_SPACE__USER)
+             return rip + map__dso(map)->text_offset;
 
-     return map->unmap_ip(map, rip) - map->reloc;
+     return map__unmap_ip(map, rip) - map__reloc(map);
 }
 
 /**
@@ -502,34 +507,34 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
  */
 u64 map__objdump_2mem(struct map *map, u64 ip)
 {
-     if (!map->dso->adjust_symbols)
-             return map->unmap_ip(map, ip);
+     if (!map__dso(map)->adjust_symbols)
+             return map__unmap_ip(map, ip);
 
-     if (map->dso->rel)
-             return map->unmap_ip(map, ip + map->pgoff);
+     if (map__dso(map)->rel)
+             return map__unmap_ip(map, ip + map__pgoff(map));
 
      /*
       * kernel modules also have DSO_TYPE_USER in dso->kernel,
       * but all kernel modules are ET_REL, so won't get here.
       */
-     if (map->dso->kernel == DSO_SPACE__USER)
-             return map->unmap_ip(map, ip - map->dso->text_offset);
+     if (map__dso(map)->kernel == DSO_SPACE__USER)
+             return map__unmap_ip(map, ip - map__dso(map)->text_offset);
 
-     return ip + map->reloc;
+     return ip + map__reloc(map);
 }
 
 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
 {
-     u64 ip = map->unmap_ip(map, sym->start);
+     u64 ip = map__unmap_ip(map, sym->start);
 
-     return ip >= map->start && ip < map->end;
+     return ip >= map__start(map) && ip < map__end(map);
 }
 
 struct kmap *__map__kmap(struct map *map)
 {
-     if (!map->dso || !map->dso->kernel)
+     if (!map__dso(map) || !map__dso(map)->kernel)
              return NULL;
-     return (struct kmap *)(map + 1);
+     return (struct kmap *)(&map[1]);
 }
 
 struct kmap *map__kmap(struct map *map)
@@ -552,17 +557,17 @@ struct maps *map__kmaps(struct map *map)
      return kmap->kmaps;
 }
 
-u64 map__map_ip(const struct map *map, u64 ip)
+u64 map__dso_map_ip(const struct map *map, u64 ip)
 {
-     return ip - map->start + map->pgoff;
+     return ip - map__start(map) + map__pgoff(map);
 }
 
-u64 map__unmap_ip(const struct map *map, u64 ip)
+u64 map__dso_unmap_ip(const struct map *map, u64 ip)
 {
-     return ip + map->start - map->pgoff;
+     return ip + map__start(map) - map__pgoff(map);
 }
 
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip)
 {
      return ip;
 }
tools/perf/util/map.h +54 -4
index d1a6f85fd31d..99ef0464a357 100644
@@ -41,15 +41,65 @@ struct kmap *map__kmap(struct map *map);
 struct maps *map__kmaps(struct map *map);
 
 /* ip -> dso rip */
-u64 map__map_ip(const struct map *map, u64 ip);
+u64 map__dso_map_ip(const struct map *map, u64 ip);
 /* dso rip -> ip */
-u64 map__unmap_ip(const struct map *map, u64 ip);
+u64 map__dso_unmap_ip(const struct map *map, u64 ip);
 /* Returns ip */
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip);
+
+static inline struct dso *map__dso(const struct map *map)
+{
+     return map->dso;
+}
+
+static inline u64 map__map_ip(const struct map *map, u64 ip)
+{
+     return map->map_ip(map, ip);
+}
+
+static inline u64 map__unmap_ip(const struct map *map, u64 ip)
+{
+     return map->unmap_ip(map, ip);
+}
+
+static inline u64 map__start(const struct map *map)
+{
+     return map->start;
+}
+
+static inline u64 map__end(const struct map *map)
+{
+     return map->end;
+}
+
+static inline u64 map__pgoff(const struct map *map)
+{
+     return map->pgoff;
+}
+
+static inline u64 map__reloc(const struct map *map)
+{
+     return map->reloc;
+}
+
+static inline u32 map__flags(const struct map *map)
+{
+     return map->flags;
+}
+
+static inline u32 map__prot(const struct map *map)
+{
+     return map->prot;
+}
+
+static inline bool map__priv(const struct map *map)
+{
+     return map->priv;
+}
 
 static inline size_t map__size(const struct map *map)
 {
-     return map->end - map->start;
+     return map__end(map) - map__start(map);
 }
 
 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
tools/perf/util/maps.c +42 -41
index 9fc3e7186b8e..6efbcb79131c 100644
@@ -30,24 +30,24 @@ static void __maps__free_maps_by_name(struct maps *maps)
      maps->nr_maps_allocated = 0;
 }
 
-static int __maps__insert(struct maps *maps, struct map *map)
+static struct map *__maps__insert(struct maps *maps, struct map *map)
 {
      struct rb_node **p = &maps__entries(maps)->rb_node;
      struct rb_node *parent = NULL;
-     const u64 ip = map->start;
+     const u64 ip = map__start(map);
      struct map_rb_node *m, *new_rb_node;
 
      new_rb_node = malloc(sizeof(*new_rb_node));
      if (!new_rb_node)
-             return -ENOMEM;
+             return NULL;
 
      RB_CLEAR_NODE(&new_rb_node->rb_node);
-     new_rb_node->map = map;
+     new_rb_node->map = map__get(map);
 
      while (*p != NULL) {
              parent = *p;
              m = rb_entry(parent, struct map_rb_node, rb_node);
-             if (ip < m->map->start)
+             if (ip < map__start(m->map))
                      p = &(*p)->rb_left;
              else
                      p = &(*p)->rb_right;
@@ -55,22 +55,23 @@ static int __maps__insert(struct maps *maps, struct map *map)
 
      rb_link_node(&new_rb_node->rb_node, parent, p);
      rb_insert_color(&new_rb_node->rb_node, maps__entries(maps));
-     map__get(map);
-     return 0;
+     return new_rb_node->map;
 }
 
 int maps__insert(struct maps *maps, struct map *map)
 {
-     int err;
+     int err = 0;
 
      down_write(maps__lock(maps));
-     err = __maps__insert(maps, map);
-     if (err)
+     map = __maps__insert(maps, map);
+     if (!map) {
+             err = -ENOMEM;
              goto out;
+     }
 
      ++maps->nr_maps;
 
-     if (map->dso && map->dso->kernel) {
+     if (map__dso(map) && map__dso(map)->kernel) {
              struct kmap *kmap = map__kmap(map);
 
              if (kmap)
@@ -193,7 +194,7 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
      if (map != NULL && map__load(map) >= 0) {
              if (mapp != NULL)
                      *mapp = map;
-             return map__find_symbol(map, map->map_ip(map, addr));
+             return map__find_symbol(map, map__map_ip(map, addr));
      }
 
      return NULL;
@@ -228,7 +229,8 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, st
 
 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 {
-     if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
+     if (ams->addr < map__start(ams->ms.map) ||
+         ams->addr >= map__end(ams->ms.map)) {
              if (maps == NULL)
                      return -1;
              ams->ms.map = maps__find(maps, ams->addr);
@@ -236,7 +238,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
                      return -1;
      }
 
-     ams->al_addr = ams->ms.map->map_ip(ams->ms.map, ams->addr);
+     ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
      ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
 
      return ams->ms.sym ? 0 : -1;
@@ -253,7 +255,7 @@ size_t maps__fprintf(struct maps *maps, FILE *fp)
              printed += fprintf(fp, "Map:");
              printed += map__fprintf(pos->map, fp);
              if (verbose > 2) {
-                     printed += dso__fprintf(pos->map->dso, fp);
+                     printed += dso__fprintf(map__dso(pos->map), fp);
                      printed += fprintf(fp, "--\n");
              }
      }
@@ -282,9 +284,9 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
      while (next) {
              struct map_rb_node *pos = rb_entry(next, struct map_rb_node, rb_node);
 
-             if (pos->map->end > map->start) {
+             if (map__end(pos->map) > map__start(map)) {
                      first = next;
-                     if (pos->map->start <= map->start)
+                     if (map__start(pos->map) <= map__start(map))
                              break;
                      next = next->rb_left;
              } else
@@ -300,14 +302,14 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
               * Stop if current map starts after map->end.
               * Maps are ordered by start: next will not overlap for sure.
               */
-             if (pos->map->start >= map->end)
+             if (map__start(pos->map) >= map__end(map))
                      break;
 
              if (verbose >= 2) {
 
                      if (use_browser) {
                              pr_debug("overlapping maps in %s (disable tui for more info)\n",
-                                        map->dso->name);
+                                        map__dso(map)->name);
                      } else {
                              fputs("overlapping maps:\n", fp);
                              map__fprintf(map, fp);
@@ -320,7 +322,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
               * Now check if we need to create new maps for areas not
               * overlapped by the new map:
               */
-             if (map->start > pos->map->start) {
+             if (map__start(map) > map__start(pos->map)) {
                      struct map *before = map__clone(pos->map);
 
                      if (before == NULL) {
@@ -328,17 +330,19 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
                              goto put_map;
                      }
 
-                     before->end = map->start;
-                     err = __maps__insert(maps, before);
-                     if (err)
+                     before->end = map__start(map);
+                     if (!__maps__insert(maps, before)) {
+                             map__put(before);
+                             err = -ENOMEM;
                              goto put_map;
+                     }
 
                      if (verbose >= 2 && !use_browser)
                              map__fprintf(before, fp);
                      map__put(before);
              }
 
-             if (map->end < pos->map->end) {
+             if (map__end(map) < map__end(pos->map)) {
                      struct map *after = map__clone(pos->map);
 
                      if (after == NULL) {
@@ -346,14 +350,15 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
                              goto put_map;
                      }
 
-                     after->start = map->end;
-                     after->pgoff += map->end - pos->map->start;
-                     assert(pos->map->map_ip(pos->map, map->end) ==
-                             after->map_ip(after, map->end));
-                     err = __maps__insert(maps, after);
-                     if (err)
+                     after->start = map__end(map);
+                     after->pgoff += map__end(map) - map__start(pos->map);
+                     assert(map__map_ip(pos->map, map__end(map)) ==
+                             map__map_ip(after, map__end(map)));
+                     if (!__maps__insert(maps, after)) {
+                             map__put(after);
+                             err = -ENOMEM;
                              goto put_map;
-
+                     }
                      if (verbose >= 2 && !use_browser)
                              map__fprintf(after, fp);
                      map__put(after);
@@ -377,7 +382,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
      struct maps *maps = thread->maps;
-     int err;
+     int err = 0;
      struct map_rb_node *rb_node;
 
      down_read(maps__lock(parent));
@@ -391,17 +396,13 @@ int maps__clone(struct thread *thread, struct maps *parent)
              }
 
              err = unwind__prepare_access(maps, new, NULL);
-             if (err)
-                     goto out_unlock;
+             if (!err)
+                     err = maps__insert(maps, new);
 
-             err = maps__insert(maps, new);
+             map__put(new);
              if (err)
                      goto out_unlock;
-
-             map__put(new);
      }
-
-     err = 0;
 out_unlock:
      up_read(maps__lock(parent));
      return err;
@@ -428,9 +429,9 @@ struct map *maps__find(struct maps *maps, u64 ip)
      p = maps__entries(maps)->rb_node;
      while (p != NULL) {
              m = rb_entry(p, struct map_rb_node, rb_node);
-             if (ip < m->map->start)
+             if (ip < map__start(m->map))
                      p = p->rb_left;
-             else if (ip >= m->map->end)
+             else if (ip >= map__end(m->map))
                      p = p->rb_right;
              else
                      goto out;
tools/perf/util/probe-event.c +22 -22
index f9fbf611f2bf..1a93dca50a4c 100644
@@ -134,15 +134,15 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
      /* ref_reloc_sym is just a label. Need a special fix*/
      reloc_sym = kernel_get_ref_reloc_sym(&map);
      if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
-             *addr = (!map->reloc || reloc) ? reloc_sym->addr :
+             *addr = (!map__reloc(map) || reloc) ? reloc_sym->addr :
                      reloc_sym->unrelocated_addr;
      else {
              sym = machine__find_kernel_symbol_by_name(host_machine, name, &map);
              if (!sym)
                      return -ENOENT;
-             *addr = map->unmap_ip(map, sym->start) -
-                     ((reloc) ? 0 : map->reloc) -
-                     ((reladdr) ? map->start : 0);
+             *addr = map__unmap_ip(map, sym->start) -
+                     ((reloc) ? 0 : map__reloc(map)) -
+                     ((reladdr) ? map__start(map) : 0);
      }
      return 0;
 }
@@ -164,8 +164,8 @@ static struct map *kernel_get_module_map(const char *module)
 
      maps__for_each_entry(maps, pos) {
              /* short_name is "[module]" */
-             const char *short_name = pos->map->dso->short_name;
-             u16 short_name_len =  pos->map->dso->short_name_len;
+             const char *short_name = map__dso(pos->map)->short_name;
+             u16 short_name_len =  map__dso(pos->map)->short_name_len;
 
              if (strncmp(short_name + 1, module,
                          short_name_len - 2) == 0 &&
@@ -183,11 +183,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)
              struct map *map;
 
              map = dso__new_map(target);
-             if (map && map->dso) {
-                     BUG_ON(pthread_mutex_lock(&map->dso->lock) != 0);
-                     nsinfo__put(map->dso->nsinfo);
-                     map->dso->nsinfo = nsinfo__get(nsi);
-                     pthread_mutex_unlock(&map->dso->lock);
+             if (map && map__dso(map)) {
+                     BUG_ON(pthread_mutex_lock(&map__dso(map)->lock) != 0);
+                     nsinfo__put(map__dso(map)->nsinfo);
+                     map__dso(map)->nsinfo = nsinfo__get(nsi);
+                     pthread_mutex_unlock(&map__dso(map)->lock);
              }
              return map;
      } else {
@@ -253,7 +253,7 @@ static bool kprobe_warn_out_range(const char *symbol, u64 address)
 
      map = kernel_get_module_map(NULL);
      if (map) {
-             ret = address <= map->start || map->end < address;
+             ret = address <= map__start(map) || map__end(map) < address;
              if (ret)
                      pr_warning("%s is out of .text, skip it.\n", symbol);
              map__put(map);
@@ -340,7 +340,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
              snprintf(module_name, sizeof(module_name), "[%s]", module);
              map = maps__find_by_name(machine__kernel_maps(host_machine), module_name);
              if (map) {
-                     dso = map->dso;
+                     dso = map__dso(map);
                      goto found;
              }
              pr_debug("Failed to find module %s.\n", module);
@@ -348,7 +348,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
      }
 
      map = machine__kernel_map(host_machine);
-     dso = map->dso;
+     dso = map__dso(map);
      if (!dso->has_build_id)
              dso__read_running_kernel_build_id(dso, host_machine);
 
@@ -396,7 +396,8 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
                                         "Consider identifying the final function used at run time and set the probe directly on that.\n",
                                         pp->function);
              } else
-                     address = map->unmap_ip(map, sym->start) - map->reloc;
+                     address = map__unmap_ip(map, sym->start) -
+                               map__reloc(map);
              break;
      }
      if (!address) {
@@ -862,8 +863,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
                      free(tevs[i].point.symbol);
              tevs[i].point.symbol = tmp;
              tevs[i].point.offset = tevs[i].point.address -
-                     (map->reloc ? reloc_sym->unrelocated_addr :
-                                   reloc_sym->addr);
+                     (map__reloc(map) ? reloc_sym->unrelocated_addr : reloc_sym->addr);
      }
      return skipped;
 }
@@ -2243,7 +2243,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
              goto out;
 
      pp->retprobe = tp->retprobe;
-     pp->offset = addr - map->unmap_ip(map, sym->start);
+     pp->offset = addr - map__unmap_ip(map, sym->start);
      pp->function = strdup(sym->name);
      ret = pp->function ? 0 : -ENOMEM;
 
@@ -3117,7 +3117,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
                      goto err_out;
              }
              /* Add one probe point */
-             tp->address = map->unmap_ip(map, sym->start) + pp->offset;
+             tp->address = map__unmap_ip(map, sym->start) + pp->offset;
 
              /* Check the kprobe (not in module) is within .text  */
              if (!pev->uprobes && !pev->target &&
@@ -3759,13 +3759,13 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
                             (target) ? : "kernel");
              goto end;
      }
-     if (!dso__sorted_by_name(map->dso))
-             dso__sort_by_name(map->dso);
+     if (!dso__sorted_by_name(map__dso(map)))
+             dso__sort_by_name(map__dso(map));
 
      /* Show all (filtered) symbols */
      setup_pager();
 
-     for (nd = rb_first_cached(&map->dso->symbol_names); nd;
+     for (nd = rb_first_cached(&map__dso(map)->symbol_names); nd;
           nd = rb_next(nd)) {
              struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
tools/perf/util/scripting-engines/trace-event-perl.c +5 -4
index a5d945415bbc..1282fb9b45e1 100644
@@ -315,11 +315,12 @@ static SV *perl_process_callchain(struct perf_sample *sample,
              if (node->ms.map) {
                      struct map *map = node->ms.map;
                      const char *dsoname = "[unknown]";
-                     if (map && map->dso) {
-                             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                                     dsoname = map->dso->long_name;
+                     if (map && map__dso(map)) {
+                             if (symbol_conf.show_kernel_path &&
+                                 map__dso(map)->long_name)
+                                     dsoname = map__dso(map)->long_name;
                              else
-                                     dsoname = map->dso->name;
+                                     dsoname = map__dso(map)->name;
                      }
                      if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) {
                              hv_undef(elem);
tools/perf/util/scripting-engines/trace-event-python.c +6 -6
index 0290dc3a6258..559b2ac5cac3 100644
@@ -382,11 +382,11 @@ static const char *get_dsoname(struct map *map)
 {
      const char *dsoname = "[unknown]";
 
-     if (map && map->dso) {
-             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                     dsoname = map->dso->long_name;
+     if (map && map__dso(map)) {
+             if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+                     dsoname = map__dso(map)->long_name;
              else
-                     dsoname = map->dso->name;
+                     dsoname = map__dso(map)->name;
      }
 
      return dsoname;
@@ -527,7 +527,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al)
      if (al->addr < sym->end)
              offset = al->addr - sym->start;
      else
-             offset = al->addr - al->map->start - sym->start;
+             offset = al->addr - map__start(al->map) - sym->start;
 
      return offset;
 }
@@ -741,7 +741,7 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 {
      if (al->map) {
              pydict_set_item_string_decref(dict, dso_field,
-                     _PyUnicode_FromString(al->map->dso->name));
+                     _PyUnicode_FromString(map__dso(al->map)->name));
      }
      if (al->sym) {
              pydict_set_item_string_decref(dict, sym_field,
tools/perf/util/sort.c +23 -23
index 25686d67ee6f..6d19bbcd30df 100644
@@ -173,8 +173,8 @@ struct sort_entry sort_comm = {
 
 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
 {
-     struct dso *dso_l = map_l ? map_l->dso : NULL;
-     struct dso *dso_r = map_r ? map_r->dso : NULL;
+     struct dso *dso_l = map_l ? map__dso(map_l) : NULL;
+     struct dso *dso_r = map_r ? map__dso(map_r) : NULL;
      const char *dso_name_l, *dso_name_r;
 
      if (!dso_l || !dso_r)
@@ -200,9 +200,9 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
                                   size_t size, unsigned int width)
 {
-     if (map && map->dso) {
-             const char *dso_name = verbose > 0 ? map->dso->long_name :
-                     map->dso->short_name;
+     if (map && map__dso(map)) {
+             const char *dso_name = verbose > 0 ? map__dso(map)->long_name :
+                     map__dso(map)->short_name;
              return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
      }
 
@@ -222,7 +222,7 @@ static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *a
      if (type != HIST_FILTER__DSO)
              return -1;
 
-     return dso && (!he->ms.map || he->ms.map->dso != dso);
+     return dso && (!he->ms.map || map__dso(he->ms.map) != dso);
 }
 
 struct sort_entry sort_dso = {
@@ -302,12 +302,12 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
      size_t ret = 0;
 
      if (verbose > 0) {
-             char o = map ? dso__symtab_origin(map->dso) : '!';
+             char o = map ? dso__symtab_origin(map__dso(map)) : '!';
              u64 rip = ip;
 
-             if (map && map->dso && map->dso->kernel
-                 && map->dso->adjust_symbols)
-                     rip = map->unmap_ip(map, ip);
+             if (map && map__dso(map) && map__dso(map)->kernel
+                 && map__dso(map)->adjust_symbols)
+                     rip = map__unmap_ip(map, ip);
 
              ret += repsep_snprintf(bf, size, "%-#*llx %c ",
                                     BITS_PER_LONG / 4 + 2, rip, o);
@@ -318,7 +318,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
              if (sym->type == STT_OBJECT) {
                      ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
                      ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
-                                     ip - map->unmap_ip(map, sym->start));
+                                     ip - map__unmap_ip(map, sym->start));
              } else {
                      ret += repsep_snprintf(bf + ret, size - ret, "%.*s",
                                             width - ret,
@@ -517,7 +517,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)
      if (!map)
              return no_srcfile;
 
-     sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
+     sf = __get_srcline(map__dso(map), map__rip_2objdump(map, e->ip),
                       e->ms.sym, false, true, true, e->ip);
      if (!strcmp(sf, SRCLINE_UNKNOWN))
              return no_srcfile;
@@ -838,7 +838,7 @@ static int hist_entry__dso_from_filter(struct hist_entry *he, int type,
              return -1;
 
      return dso && (!he->branch_info || !he->branch_info->from.ms.map ||
-                    he->branch_info->from.ms.map->dso != dso);
+             map__dso(he->branch_info->from.ms.map) != dso);
 }
 
 static int64_t
@@ -870,7 +870,7 @@ static int hist_entry__dso_to_filter(struct hist_entry *he, int type,
              return -1;
 
      return dso && (!he->branch_info || !he->branch_info->to.ms.map ||
-                    he->branch_info->to.ms.map->dso != dso);
+             map__dso(he->branch_info->to.ms.map) != dso);
 }
 
 static int64_t
@@ -1259,7 +1259,7 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
      if (!l_map) return -1;
      if (!r_map) return 1;
 
-     rc = dso__cmp_id(l_map->dso, r_map->dso);
+     rc = dso__cmp_id(map__dso(l_map), map__dso(r_map));
      if (rc)
              return rc;
      /*
@@ -1271,9 +1271,9 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
       */
 
      if ((left->cpumode != PERF_RECORD_MISC_KERNEL) &&
-         (!(l_map->flags & MAP_SHARED)) &&
-         !l_map->dso->id.maj && !l_map->dso->id.min &&
-         !l_map->dso->id.ino && !l_map->dso->id.ino_generation) {
+         (!(map__flags(l_map) & MAP_SHARED)) &&
+         !map__dso(l_map)->id.maj && !map__dso(l_map)->id.min &&
+         !map__dso(l_map)->id.ino && !map__dso(l_map)->id.ino_generation) {
              /* userspace anonymous */
 
              if (left->thread->pid_ > right->thread->pid_) return -1;
@@ -1307,10 +1307,10 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,
 
              /* print [s] for shared data mmaps */
              if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
-                  map && !(map->prot & PROT_EXEC) &&
-                 (map->flags & MAP_SHARED) &&
-                 (map->dso->id.maj || map->dso->id.min ||
-                  map->dso->id.ino || map->dso->id.ino_generation))
+                 map && !(map__prot(map) & PROT_EXEC) &&
+                 (map__flags(map) & MAP_SHARED) &&
+                 (map__dso(map)->id.maj || map__dso(map)->id.min ||
+                  map__dso(map)->id.ino || map__dso(map)->id.ino_generation))
                      level = 's';
              else if (!map)
                      level = 'X';
@@ -1806,7 +1806,7 @@ sort__dso_size_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_size_snprintf(struct map *map, char *bf,
                                        size_t bf_size, unsigned int width)
 {
-     if (map && map->dso)
+     if (map && map__dso(map))
              return repsep_snprintf(bf, bf_size, "%*d", width,
                                     map__size(map));
 
tools/perf/util/symbol-elf.c +19 -20
index 3ca9a0968345..056405d3d655 100644
@@ -970,7 +970,7 @@ void __weak arch__sym_update(struct symbol *s __maybe_unused,
 static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
                                    GElf_Sym *sym, GElf_Shdr *shdr,
                                    struct maps *kmaps, struct kmap *kmap,
-                                   struct dso **curr_dsop, struct map **curr_mapp,
+                                   struct dso **curr_dsop,
                                    const char *section_name,
                                    bool adjust_kernel_syms, bool kmodule, bool *remap_kernel)
 {
@@ -994,18 +994,18 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
              if (*remap_kernel && dso->kernel && !kmodule) {
                      *remap_kernel = false;
                      map->start = shdr->sh_addr + ref_reloc(kmap);
-                     map->end = map->start + shdr->sh_size;
+                     map->end = map__start(map) + shdr->sh_size;
                      map->pgoff = shdr->sh_offset;
-                     map->map_ip = map__map_ip;
-                     map->unmap_ip = map__unmap_ip;
+                     map->map_ip = map__dso_map_ip;
+                     map->unmap_ip = map__dso_unmap_ip;
                      /* Ensure maps are correctly ordered */
                      if (kmaps) {
                              int err;
+                             struct map *updated = map__get(map);
 
-                             map__get(map);
                              maps__remove(kmaps, map);
-                             err = maps__insert(kmaps, map);
-                             map__put(map);
+                             err = maps__insert(kmaps, updated);
+                             map__put(updated);
                              if (err)
                                      return err;
                      }
@@ -1021,7 +1021,6 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
                      map->pgoff = shdr->sh_offset;
              }
 
-             *curr_mapp = map;
              *curr_dsop = dso;
              return 0;
      }
@@ -1036,7 +1035,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
              u64 start = sym->st_value;
 
              if (kmodule)
-                     start += map->start + shdr->sh_offset;
+                     start += map__start(map) + shdr->sh_offset;
 
              curr_dso = dso__new(dso_name);
              if (curr_dso == NULL)
@@ -1054,10 +1053,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 
              if (adjust_kernel_syms) {
                      curr_map->start  = shdr->sh_addr + ref_reloc(kmap);
-                     curr_map->end    = curr_map->start + shdr->sh_size;
-                     curr_map->pgoff  = shdr->sh_offset;
+                     curr_map->end   = map__start(curr_map) + shdr->sh_size;
+                     curr_map->pgoff = shdr->sh_offset;
              } else {
-                     curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+                     curr_map->map_ip = map__identity_ip;
+                     curr_map->unmap_ip = map__identity_ip;
              }
              curr_dso->symtab_type = dso->symtab_type;
              if (maps__insert(kmaps, curr_map))
@@ -1068,13 +1068,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
               * *curr_map->dso.
               */
              dsos__add(&maps__machine(kmaps)->dsos, curr_dso);
-             /* kmaps already got it */
-             map__put(curr_map);
              dso__set_loaded(curr_dso);
-             *curr_mapp = curr_map;
              *curr_dsop = curr_dso;
+             map__put(curr_map);
      } else
-             *curr_dsop = curr_map->dso;
+             *curr_dsop = map__dso(curr_map);
 
      return 0;
 }
@@ -1085,7 +1083,6 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 {
      struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
      struct maps *kmaps = kmap ? map__kmaps(map) : NULL;
-     struct map *curr_map = map;
      struct dso *curr_dso = dso;
      Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym;
      uint32_t nr_syms;
@@ -1175,7 +1172,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
       * attempted to prelink vdso to its virtual address.
       */
      if (dso__is_vdso(dso))
-             map->reloc = map->start - dso->text_offset;
+             map->reloc = map__start(map) - dso->text_offset;
 
      dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
      /*
@@ -1262,8 +1259,10 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
                      --sym.st_value;
 
              if (dso->kernel) {
-                     if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map,
-                                                    section_name, adjust_kernel_syms, kmodule, &remap_kernel))
+                     if (dso__process_kernel_symbol(dso, map, &sym, &shdr,
+                                                    kmaps, kmap, &curr_dso,
+                                                    section_name, adjust_kernel_syms,
+                                                    kmodule, &remap_kernel))
                              goto out_elf_end;
              } else if ((used_opd && runtime_ss->adjust_symbols) ||
                         (!used_opd && syms_ss->adjust_symbols)) {
tools/perf/util/symbol.c +51 -45
index 9b51e669a722..6289b3028b91 100644
@@ -252,8 +252,8 @@ void maps__fixup_end(struct maps *maps)
      down_write(maps__lock(maps));
 
      maps__for_each_entry(maps, curr) {
-             if (prev != NULL && !prev->map->end)
-                     prev->map->end = curr->map->start;
+             if (prev != NULL && !map__end(prev->map))
+                     prev->map->end = map__start(curr->map);
 
              prev = curr;
      }
@@ -262,7 +262,7 @@ void maps__fixup_end(struct maps *maps)
       * We still haven't the actual symbols, so guess the
       * last map final address.
       */
-     if (curr && !curr->map->end)
+     if (curr && !map__end(curr->map))
              curr->map->end = ~0ULL;
 
      up_write(maps__lock(maps));
@@ -778,12 +778,12 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
                      continue;
              }
 
-             pos->start -= curr_map->start - curr_map->pgoff;
-             if (pos->end > curr_map->end)
-                     pos->end = curr_map->end;
+             pos->start -= map__start(curr_map) - map__pgoff(curr_map);
+             if (pos->end > map__end(curr_map))
+                     pos->end = map__end(curr_map);
              if (pos->end)
-                     pos->end -= curr_map->start - curr_map->pgoff;
-             symbols__insert(&curr_map->dso->symbols, pos);
+                     pos->end -= map__start(curr_map) - map__pgoff(curr_map);
+             symbols__insert(&map__dso(curr_map)->symbols, pos);
              ++count;
      }
 
@@ -830,7 +830,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 
                      *module++ = '\0';
 
-                     if (strcmp(curr_map->dso->short_name, module)) {
+                     if (strcmp(map__dso(curr_map)->short_name, module)) {
                              if (curr_map != initial_map &&
                                  dso->kernel == DSO_SPACE__KERNEL_GUEST &&
                                  machine__is_default_guest(machine)) {
@@ -841,7 +841,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                                       * symbols are in its kmap. Mark it as
                                       * loaded.
                                       */
-                                     dso__set_loaded(curr_map->dso);
+                                     dso__set_loaded(map__dso(curr_map));
                              }
 
                              curr_map = maps__find_by_name(kmaps, module);
@@ -854,7 +854,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                                      goto discard_symbol;
                              }
 
-                             if (curr_map->dso->loaded &&
+                             if (map__dso(curr_map)->loaded &&
                                  !machine__is_default_guest(machine))
                                      goto discard_symbol;
                      }
@@ -862,8 +862,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                       * So that we look just like we get from .ko files,
                       * i.e. not prelinked, relative to initial_map->start.
                       */
-                     pos->start = curr_map->map_ip(curr_map, pos->start);
-                     pos->end   = curr_map->map_ip(curr_map, pos->end);
+                     pos->start = map__map_ip(curr_map, pos->start);
+                     pos->end   = map__map_ip(curr_map, pos->end);
              } else if (x86_64 && is_entry_trampoline(pos->name)) {
                      /*
                       * These symbols are not needed anymore since the
@@ -910,7 +910,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                              return -1;
                      }
 
-                     curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+                     curr_map->map_ip = map__identity_ip;
+                     curr_map->unmap_ip = map__identity_ip;
                      if (maps__insert(kmaps, curr_map)) {
                              dso__put(ndso);
                              return -1;
@@ -924,7 +925,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 add_symbol:
              if (curr_map != initial_map) {
                      rb_erase_cached(&pos->rb_node, root);
-                     symbols__insert(&curr_map->dso->symbols, pos);
+                     symbols__insert(&map__dso(curr_map)->symbols, pos);
                      ++moved;
              } else
                      ++count;
@@ -938,7 +939,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
      if (curr_map != initial_map &&
          dso->kernel == DSO_SPACE__KERNEL_GUEST &&
          machine__is_default_guest(maps__machine(kmaps))) {
-             dso__set_loaded(curr_map->dso);
+             dso__set_loaded(map__dso(curr_map));
      }
 
      return count + moved;
@@ -1118,8 +1119,8 @@ static int do_validate_kcore_modules(const char *filename, struct maps *kmaps)
              }
 
              /* Module must be in memory at the same address */
-             mi = find_module(old_map->dso->short_name, &modules);
-             if (!mi || mi->start != old_map->start) {
+             mi = find_module(map__dso(old_map)->short_name, &modules);
+             if (!mi || mi->start != map__start(old_map)) {
                      err = -EINVAL;
                      goto out;
              }
@@ -1214,7 +1215,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
              return -ENOMEM;
      }
 
-     list_node->map->end = list_node->map->start + len;
+     list_node->map->end = map__start(list_node->map) + len;
      list_node->map->pgoff = pgoff;
 
      list_add(&list_node->node, &md->maps);
@@ -1236,21 +1237,21 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
              struct map *old_map = rb_node->map;
 
              /* no overload with this one */
-             if (new_map->end < old_map->start ||
-                 new_map->start >= old_map->end)
+             if (map__end(new_map) < map__start(old_map) ||
+                 map__start(new_map) >= map__end(old_map))
                      continue;
 
-             if (new_map->start < old_map->start) {
+             if (map__start(new_map) < map__start(old_map)) {
                      /*
                       * |new......
                       *       |old....
                       */
-                     if (new_map->end < old_map->end) {
+                     if (map__end(new_map) < map__end(old_map)) {
                              /*
                               * |new......|     -> |new..|
                               *       |old....| ->       |old....|
                               */
-                             new_map->end = old_map->start;
+                             new_map->end = map__start(old_map);
                      } else {
                              /*
                               * |new.............| -> |new..|       |new..|
@@ -1271,17 +1272,18 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
                                      goto out;
                              }
 
-                             m->map->end = old_map->start;
+                             m->map->end = map__start(old_map);
                              list_add_tail(&m->node, &merged);
-                             new_map->pgoff += old_map->end - new_map->start;
-                             new_map->start = old_map->end;
+                             new_map->pgoff +=
+                                     map__end(old_map) - map__start(new_map);
+                             new_map->start = map__end(old_map);
                      }
              } else {
                      /*
                       *      |new......
                       * |old....
                       */
-                     if (new_map->end < old_map->end) {
+                     if (map__end(new_map) < map__end(old_map)) {
                              /*
                               *      |new..|   -> x
                               * |old.........| -> |old.........|
@@ -1294,8 +1296,9 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
                               *      |new......| ->         |new...|
                               * |old....|        -> |old....|
                               */
-                             new_map->pgoff += old_map->end - new_map->start;
-                             new_map->start = old_map->end;
+                             new_map->pgoff +=
+                                     map__end(old_map) - map__start(new_map);
+                             new_map->start = map__end(old_map);
                      }
              }
      }
@@ -1361,7 +1364,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
      }
 
      /* Read new maps into temporary lists */
-     err = file__read_maps(fd, map->prot & PROT_EXEC, kcore_mapfn, &md,
+     err = file__read_maps(fd, map__prot(map) & PROT_EXEC, kcore_mapfn, &md,
                            &is_64_bit);
      if (err)
              goto out_err;
@@ -1391,7 +1394,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
              struct map_list_node *new_node;
 
              list_for_each_entry(new_node, &md.maps, node) {
-                     if (stext >= new_node->map->start && stext < new_node->map->end) {
+                     if (stext >= map__start(new_node->map) &&
+                         stext < map__end(new_node->map)) {
                              replacement_map = new_node->map;
                              break;
                      }
@@ -1408,16 +1412,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
              new_node = list_entry(md.maps.next, struct map_list_node, node);
              list_del_init(&new_node->node);
              if (new_node->map == replacement_map) {
-                     map->start      = new_node->map->start;
-                     map->end        = new_node->map->end;
-                     map->pgoff      = new_node->map->pgoff;
-                     map->map_ip     = new_node->map->map_ip;
-                     map->unmap_ip   = new_node->map->unmap_ip;
+                     struct  map *updated;
+
+                     map->start = map__start(new_node->map);
+                     map->end   = map__end(new_node->map);
+                     map->pgoff = map__pgoff(new_node->map);
+                     map->map_ip = new_node->map->map_ip;
+                     map->unmap_ip = new_node->map->unmap_ip;
                      /* Ensure maps are correctly ordered */
-                     map__get(map);
+                     updated = map__get(map);
                      maps__remove(kmaps, map);
-                     err = maps__insert(kmaps, map);
-                     map__put(map);
+                     err = maps__insert(kmaps, updated);
+                     map__put(updated);
                      map__put(new_node->map);
                      if (err)
                              goto out_err;
@@ -1460,7 +1466,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
      close(fd);
 
-     if (map->prot & PROT_EXEC)
+     if (map__prot(map) & PROT_EXEC)
              pr_debug("Using %s for kernel object code\n", kcore_filename);
      else
              pr_debug("Using %s for kernel data\n", kcore_filename);
@@ -1995,13 +2001,13 @@ int dso__load(struct dso *dso, struct map *map)
 static int map__strcmp(const void *a, const void *b)
 {
      const struct map *ma = *(const struct map **)a, *mb = *(const struct map **)b;
-     return strcmp(ma->dso->short_name, mb->dso->short_name);
+     return strcmp(map__dso(ma)->short_name, map__dso(mb)->short_name);
 }
 
 static int map__strcmp_name(const void *name, const void *b)
 {
      const struct map *map = *(const struct map **)b;
-     return strcmp(name, map->dso->short_name);
+     return strcmp(name, map__dso(map)->short_name);
 }
 
 void __maps__sort_by_name(struct maps *maps)
@@ -2052,7 +2058,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
      down_read(maps__lock(maps));
 
      if (maps->last_search_by_name &&
-         strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
+         strcmp(map__dso(maps->last_search_by_name)->short_name, name) == 0) {
              map = maps->last_search_by_name;
              goto out_unlock;
      }
@@ -2068,7 +2074,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
      /* Fallback to traversing the rbtree... */
      maps__for_each_entry(maps, rb_node) {
              map = rb_node->map;
-             if (strcmp(map->dso->short_name, name) == 0) {
+             if (strcmp(map__dso(map)->short_name, name) == 0) {
                      maps->last_search_by_name = map;
                      goto out_unlock;
              }
tools/perf/util/symbol_fprintf.c +1 -1
index 2664fb65e47a..d9e5ad040b6a 100644
@@ -30,7 +30,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
                      if (al->addr < sym->end)
                              offset = al->addr - sym->start;
                      else
-                             offset = al->addr - al->map->start - sym->start;
+                             offset = al->addr - map__start(al->map) - sym->start;
                      length += fprintf(fp, "+0x%lx", offset);
              }
              return length;
tools/perf/util/synthetic-events.c +14 -14
index ed2d55d224aa..437fd57c2084 100644
@@ -668,33 +668,33 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
                      continue;
 
              if (symbol_conf.buildid_mmap2) {
-                     size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                     size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
                      event->mmap2.header.type = PERF_RECORD_MMAP2;
                      event->mmap2.header.size = (sizeof(event->mmap2) -
                                              (sizeof(event->mmap2.filename) - size));
                      memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
                      event->mmap2.header.size += machine->id_hdr_size;
-                     event->mmap2.start = map->start;
-                     event->mmap2.len   = map->end - map->start;
+                     event->mmap2.start = map__start(map);
+                     event->mmap2.len   = map__end(map) - map__start(map);
                      event->mmap2.pid   = machine->pid;
 
-                     memcpy(event->mmap2.filename, map->dso->long_name,
-                            map->dso->long_name_len + 1);
+                     memcpy(event->mmap2.filename, map__dso(map)->long_name,
+                            map__dso(map)->long_name_len + 1);
 
                      perf_record_mmap2__read_build_id(&event->mmap2, false);
              } else {
-                     size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                     size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
                      event->mmap.header.type = PERF_RECORD_MMAP;
                      event->mmap.header.size = (sizeof(event->mmap) -
                                              (sizeof(event->mmap.filename) - size));
                      memset(event->mmap.filename + size, 0, machine->id_hdr_size);
                      event->mmap.header.size += machine->id_hdr_size;
-                     event->mmap.start = map->start;
-                     event->mmap.len   = map->end - map->start;
+                     event->mmap.start = map__start(map);
+                     event->mmap.len   = map__end(map) - map__start(map);
                      event->mmap.pid   = machine->pid;
 
-                     memcpy(event->mmap.filename, map->dso->long_name,
-                            map->dso->long_name_len + 1);
+                     memcpy(event->mmap.filename, map__dso(map)->long_name,
+                            map__dso(map)->long_name_len + 1);
              }
 
              if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
@@ -1112,8 +1112,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
              event->mmap2.header.size = (sizeof(event->mmap2) -
                              (sizeof(event->mmap2.filename) - size) + machine->id_hdr_size);
              event->mmap2.pgoff = kmap->ref_reloc_sym->addr;
-             event->mmap2.start = map->start;
-             event->mmap2.len   = map->end - event->mmap.start;
+             event->mmap2.start = map__start(map);
+             event->mmap2.len   = map__end(map) - event->mmap.start;
              event->mmap2.pid   = machine->pid;
 
              perf_record_mmap2__read_build_id(&event->mmap2, true);
@@ -1125,8 +1125,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
              event->mmap.header.size = (sizeof(event->mmap) -
                              (sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
              event->mmap.pgoff = kmap->ref_reloc_sym->addr;
-             event->mmap.start = map->start;
-             event->mmap.len   = map->end - event->mmap.start;
+             event->mmap.start = map__start(map);
+             event->mmap.len   = map__end(map) - event->mmap.start;
              event->mmap.pid   = machine->pid;
      }
 
tools/perf/util/thread.c +13 -13
index c2256777b813..6fbcc115cc6d 100644
@@ -434,23 +434,23 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa
 int thread__memcpy(struct thread *thread, struct machine *machine,
                 void *buf, u64 ip, int len, bool *is64bit)
 {
-       u8 cpumode = PERF_RECORD_MISC_USER;
-       struct addr_location al;
-       long offset;
+     u8 cpumode = PERF_RECORD_MISC_USER;
+     struct addr_location al;
+     long offset;
 
-       if (machine__kernel_ip(machine, ip))
-               cpumode = PERF_RECORD_MISC_KERNEL;
+     if (machine__kernel_ip(machine, ip))
+             cpumode = PERF_RECORD_MISC_KERNEL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
-        al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
-        map__load(al.map) < 0)
-               return -1;
+     if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map) ||
+             map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR ||
+             map__load(al.map) < 0)
+             return -1;
 
-       offset = al.map->map_ip(al.map, ip);
-       if (is64bit)
-               *is64bit = al.map->dso->is_64_bit;
+     offset = map__map_ip(al.map, ip);
+     if (is64bit)
+             *is64bit = map__dso(al.map)->is_64_bit;
 
-       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+     return dso__data_read_offset(map__dso(al.map), machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
tools/perf/util/unwind-libunwind-local.c +17 -17
index 7e6c59811292..841ac84a93ab 100644
@@ -381,20 +381,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
      int ret = -EINVAL;
 
      map = find_map(ip, ui);
-     if (!map || !map->dso)
+     if (!map || !map__dso(map))
              return -EINVAL;
 
-     pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
+     pr_debug("unwind: %s dso %s\n", __func__, map__dso(map)->name);
 
      /* Check the .eh_frame section for unwinding info */
-     if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
+     if (!read_unwind_spec_eh_frame(map__dso(map), ui->machine,
                                     &table_data, &segbase, &fde_count)) {
              memset(&di, 0, sizeof(di));
              di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
-             di.start_ip = map->start;
-             di.end_ip   = map->end;
-             di.u.rti.segbase    = map->start + segbase - map->pgoff;
-             di.u.rti.table_data = map->start + table_data - map->pgoff;
+             di.start_ip = map__start(map);
+             di.end_ip   = map__end(map);
+             di.u.rti.segbase    = map__start(map) + segbase - map__pgoff(map);
+             di.u.rti.table_data = map__start(map) + table_data - map__pgoff(map);
              di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
                                    / sizeof(unw_word_t);
              ret = dwarf_search_unwind_table(as, ip, &di, pi,
@@ -404,20 +404,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 #ifndef NO_LIBUNWIND_DEBUG_FRAME
      /* Check the .debug_frame section for unwinding info */
      if (ret < 0 &&
-         !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
-             int fd = dso__data_get_fd(map->dso, ui->machine);
-             int is_exec = elf_is_exec(fd, map->dso->name);
-             unw_word_t base = is_exec ? 0 : map->start;
+         !read_unwind_spec_debug_frame(map__dso(map), ui->machine, &segbase)) {
+             int fd = dso__data_get_fd(map__dso(map), ui->machine);
+             int is_exec = elf_is_exec(fd, map__dso(map)->name);
+             unw_word_t base = is_exec ? 0 : map__start(map);
              const char *symfile;
 
              if (fd >= 0)
-                     dso__data_put_fd(map->dso);
+                     dso__data_put_fd(map__dso(map));
 
-             symfile = map->dso->symsrc_filename ?: map->dso->name;
+             symfile = map__dso(map)->symsrc_filename ?: map__dso(map)->name;
 
              memset(&di, 0, sizeof(di));
              if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
-                                        map->start, map->end))
+                                        map__start(map), map__end(map)))
                      return dwarf_search_unwind_table(as, ip, &di, pi,
                                                       need_unwind_info, arg);
      }
@@ -473,10 +473,10 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
              return -1;
      }
 
-     if (!map->dso)
+     if (!map__dso(map))
              return -1;
 
-     size = dso__data_read_addr(map->dso, map, ui->machine,
+     size = dso__data_read_addr(map__dso(map), map, ui->machine,
                                 addr, (u8 *) data, sizeof(*data));
 
      return !(size == sizeof(*data));
@@ -583,7 +583,7 @@ static int entry(u64 ip, struct thread *thread,
      pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
               al.sym ? al.sym->name : "''",
               ip,
-              al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
+              al.map ? map__map_ip(al.map, ip) : (u64) 0);
 
      return cb(&e, arg);
 }
tools/perf/util/unwind-libunwind.c +2 -2
index 7b797ffadd19..cece1ee89031 100644
@@ -30,7 +30,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 
      if (maps__addr_space(maps)) {
              pr_debug("unwind: thread map already set, dso=%s\n",
-                      map->dso->name);
+                      map__dso(map)->name);
              if (initialized)
                      *initialized = true;
              return 0;
@@ -41,7 +41,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
      if (!machine->env || !machine->env->arch)
              goto out_register;
 
-     dso_type = dso__type(map->dso, machine);
+     dso_type = dso__type(map__dso(map), machine);
      if (dso_type == DSO__TYPE_UNKNOWN)
              return 0;
 
tools/perf/util/vdso.c +1 -2
index 835c39efb80d..ec777ee11493 100644
@@ -147,7 +147,7 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
      struct map_rb_node *rb_node;
 
      maps__for_each_entry(thread->maps, rb_node) {
-             struct dso *dso = rb_node->map->dso;
+             struct dso *dso = map__dso(rb_node->map);
 
              if (!dso || dso->long_name[0] != '/')
                      continue;
--
Quoted 1 line

2.35.1.265.g69c8d7142f-goog

--

- Arnaldo

#46 lore raw

Re: [PATCH v3 15/22] perf map: Use functions to access the variables in map

Em Fri, Feb 11, 2022 at 09:54:40AM -0800, Ian Rogers escreveu:

Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 5 lines

Em Fri, Feb 11, 2022 at 02:34:08AM -0800, Ian Rogers escreveu:

Quoted 4 lines

+++ b/tools/perf/arch/s390/annotate/instructions.c

(quoted diff) +0 -0
@@ -39,7 +39,9 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
      target.addr = map__objdump_2mem(map, ops->target.addr);
 
Quoted 9 lines

tools/perf/arch/s390/annotate/instructions.c static int s390_call__parse(struct arch *arch, struct ins_operands *ops, · line 44

Quoted 5 lines
tools/perf/arch/s390/annotate/instructions.c +3 -1
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                          ) == ops->target.addr)

This changes nothing, right? Please try not to do this in the v2 for this patch.

Quoted 1 line

Agreed. The original code here looks wrong to me. I would have

Then that merits a separate patch addressing that problem, my point here was not to add just reflowing to a patch series.

- Arnaldo

Quoted 3,162 lines

translated this into map__map_ip, but that would have changed the function pointer from map->map_ip to target.ms.map->map_ip. The reformatting is so that when I add a reference count check here the lines aren't reformatted and that change is more minimal and obvious. I think the right thing is really to use map__map_ip. That goes beyond what this change was trying to do, and I lack a means to test this code. Could you investigate? If I switch this to map__map_ip in v2 then it resolves this issue and is most likely the right thing, its just that's a behavioral change that I was trying to avoid in this change.

Thanks,
Ian

Quoted 3,148 lines

- Arnaldo

Quoted 3,141 lines
tools/perf/arch/s390/annotate/instructions.c +0 -0
              ops->target.sym = target.ms.sym;
 
      return 0;
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index a54dea7c112f..497593be80f2 100644
@@ -33,7 +33,7 @@ static int sample_ustack(struct perf_sample *sample,
              return -1;
      }
 
-     stack_size = map->end - sp;
+     stack_size = map__end(map) - sp;
      stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
 
      memcpy(buf, (void *) sp, stack_size);
tools/perf/arch/x86/util/event.c +3 -3
index 7b6b0c98fb36..c790c682b76e 100644
@@ -57,9 +57,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
 
              event->mmap.header.size = size;
 
-             event->mmap.start = map->start;
-             event->mmap.len   = map->end - map->start;
-             event->mmap.pgoff = map->pgoff;
+             event->mmap.start = map__start(map);
+             event->mmap.len   = map__size(map);
+             event->mmap.pgoff = map__pgoff(map);
              event->mmap.pid   = machine->pid;
 
              strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
tools/perf/builtin-annotate.c +4 -4
index 490bb9b8cf17..49d3ae36fd89 100644
@@ -199,7 +199,7 @@ static int process_branch_callback(struct evsel *evsel,
              return 0;
 
      if (a.map != NULL)
-             a.map->dso->hit = 1;
+             map__dso(a.map)->hit = 1;
 
      hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
@@ -231,9 +231,9 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
               */
              if (al->sym != NULL) {
                      rb_erase_cached(&al->sym->rb_node,
-                              &al->map->dso->symbols);
+                                     &map__dso(al->map)->symbols);
                      symbol__delete(al->sym);
-                     dso__reset_find_symbol_cache(al->map->dso);
+                     dso__reset_find_symbol_cache(map__dso(al->map));
              }
              return 0;
      }
@@ -315,7 +315,7 @@ static void hists__find_annotations(struct hists *hists,
              struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
              struct annotation *notes;
 
-             if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
+             if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
                      goto find_next;
 
              if (ann->sym_hist_filter &&
tools/perf/builtin-inject.c +4 -4
index f7917c390e96..92a9dbc3d4cd 100644
@@ -600,10 +600,10 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
      }
 
      if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
-             if (!al.map->dso->hit) {
-                     al.map->dso->hit = 1;
-                     dso__inject_build_id(al.map->dso, tool, machine,
-                                          sample->cpumode, al.map->flags);
+             if (!map__dso(al.map)->hit) {
+                     map__dso(al.map)->hit = 1;
+                     dso__inject_build_id(map__dso(al.map), tool, machine,
+                                          sample->cpumode, map__flags(al.map));
              }
      }
 
tools/perf/builtin-kallsyms.c +4 -2
index c08ee81529e8..d940b60ce812 100644
@@ -36,8 +36,10 @@ static int __cmd_kallsyms(int argc, const char **argv)
              }
 
              printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
-                     symbol->name, map->dso->short_name, map->dso->long_name,
-                     map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
+                     symbol->name, map__dso(map)->short_name,
+                     map__dso(map)->long_name,
+                     map__unmap_ip(map, symbol->start),
+                     map__unmap_ip(map, symbol->end),
                      symbol->start, symbol->end);
      }
 
tools/perf/builtin-kmem.c +2 -2
index 99d7ff9a8eff..d87d9c341a20 100644
@@ -410,7 +410,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
              if (!caller) {
                      /* found */
                      if (node->ms.map)
-                             addr = map__unmap_ip(node->ms.map, node->ip);
+                             addr = map__dso_unmap_ip(node->ms.map, node->ip);
                      else
                              addr = node->ip;
 
@@ -1012,7 +1012,7 @@ static void __print_slab_result(struct rb_root *root,
 
              if (sym != NULL)
                      snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
-                              addr - map->unmap_ip(map, sym->start));
+                              addr - map__unmap_ip(map, sym->start));
              else
                      snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
              printf(" %-34s |", buf);
tools/perf/builtin-mem.c +2 -2
index fcf65a59bea2..d18083f57303 100644
@@ -200,7 +200,7 @@ dump_raw_samples(struct perf_tool *tool,
              goto out_put;
 
      if (al.map != NULL)
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      field_sep = symbol_conf.field_sep;
      if (field_sep) {
@@ -241,7 +241,7 @@ dump_raw_samples(struct perf_tool *tool,
              symbol_conf.field_sep,
              sample->data_src,
              symbol_conf.field_sep,
-             al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+             al.map && map__dso(al.map) ? map__dso(al.map)->long_name : "???",
              al.sym ? al.sym->name : "???");
 out_put:
      addr_location__put(&al);
tools/perf/builtin-report.c +11 -9
index 57611ef725c3..9b92b2bbd7de 100644
@@ -304,7 +304,7 @@ static int process_sample_event(struct perf_tool *tool,
      }
 
      if (al.map != NULL)
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
              hist__account_cycles(sample->branch_stack, &al, sample,
@@ -579,7 +579,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
              return;
 
      if (kernel_map == NULL ||
-         (kernel_map->dso->hit &&
+         (map__dso(kernel_map)->hit &&
           (kernel_kmap->ref_reloc_sym == NULL ||
            kernel_kmap->ref_reloc_sym->addr == 0))) {
              const char *desc =
@@ -805,13 +805,15 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
              struct map *map = rb_node->map;
 
              printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
-                                indent, "", map->start, map->end,
-                                map->prot & PROT_READ ? 'r' : '-',
-                                map->prot & PROT_WRITE ? 'w' : '-',
-                                map->prot & PROT_EXEC ? 'x' : '-',
-                                map->flags & MAP_SHARED ? 's' : 'p',
-                                map->pgoff,
-                                map->dso->id.ino, map->dso->name);
+                                indent, "",
+                                map__start(map), map__end(map),
+                                map__prot(map) & PROT_READ ? 'r' : '-',
+                                map__prot(map) & PROT_WRITE ? 'w' : '-',
+                                map__prot(map) & PROT_EXEC ? 'x' : '-',
+                                map__flags(map) & MAP_SHARED ? 's' : 'p',
+                                map__pgoff(map),
+                                map__dso(map)->id.ino,
+                                map__dso(map)->name);
      }
 
      return printed;
tools/perf/builtin-script.c +13 -13
index abae8184e171..4edfce95e137 100644
@@ -972,12 +972,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
              to   = entries[i].to;
 
              if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
-                 !alf.map->dso->adjust_symbols)
-                     from = map__map_ip(alf.map, from);
+                 !map__dso(alf.map)->adjust_symbols)
+                     from = map__dso_map_ip(alf.map, from);
 
              if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
-                 !alt.map->dso->adjust_symbols)
-                     to = map__map_ip(alt.map, to);
+                 !map__dso(alt.map)->adjust_symbols)
+                     to = map__dso_map_ip(alt.map, to);
 
              printed += fprintf(fp, " 0x%"PRIx64, from);
              if (PRINT_FIELD(DSO)) {
@@ -1039,11 +1039,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
              return 0;
      }
 
-     if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
+     if (!thread__find_map(thread, *cpumode, start, &al) || !map__dso(al.map)) {
              pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
              return 0;
      }
-     if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
+     if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR) {
              pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
              return 0;
      }
@@ -1051,11 +1051,11 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
      /* Load maps to ensure dso->is_64_bit has been updated */
      map__load(al.map);
 
-     offset = al.map->map_ip(al.map, start);
-     len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
-                                 end - start + MAXINSN);
+     offset = map__map_ip(al.map, start);
+     len = dso__data_read_offset(map__dso(al.map), machine, offset,
+                                 (u8 *)buffer, end - start + MAXINSN);
 
-     *is64bit = al.map->dso->is_64_bit;
+     *is64bit = map__dso(al.map)->is_64_bit;
      if (len <= 0)
              pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
                      start, end);
@@ -1070,9 +1070,9 @@ static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srcc
      int len;
      char *srccode;
 
-     if (!map || !map->dso)
+     if (!map || !map__dso(map))
              return 0;
-     srcfile = get_srcline_split(map->dso,
+     srcfile = get_srcline_split(map__dso(map),
                                  map__rip_2objdump(map, addr),
                                  &line);
      if (!srcfile)
@@ -1164,7 +1164,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
      if (al.addr < al.sym->end)
              off = al.addr - al.sym->start;
      else
-             off = al.addr - al.map->start - al.sym->start;
+             off = al.addr - map__start(al.map) - al.sym->start;
      printed += fprintf(fp, "\t%s", al.sym->name);
      if (off)
              printed += fprintf(fp, "%+d", off);
tools/perf/builtin-top.c +7 -5
index 1fc390f136dd..8db1df7bdabe 100644
@@ -127,8 +127,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
      /*
       * We can't annotate with just /proc/kallsyms
       */
-     if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-         !dso__is_kcore(map->dso)) {
+     if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+         !dso__is_kcore(map__dso(map))) {
              pr_err("Can't annotate %s: No vmlinux file was found in the "
                     "path\n", sym->name);
              sleep(1);
@@ -180,8 +180,9 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
                  "Tools:  %s\n\n"
                  "Not all samples will be on the annotation output.\n\n"
                  "Please report to [email protected]\n",
-                 ip, map->dso->long_name, dso__symtab_origin(map->dso),
-                 map->start, map->end, sym->start, sym->end,
+                 ip, map__dso(map)->long_name,
+                 dso__symtab_origin(map__dso(map)),
+                 map__start(map), map__end(map), sym->start, sym->end,
                  sym->binding == STB_GLOBAL ? 'g' :
                  sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
                  err ? "[unknown]" : uts.machine,
@@ -810,7 +811,8 @@ static void perf_event__process_sample(struct perf_tool *tool,
                  __map__is_kernel(al.map) && map__has_symbols(al.map)) {
                      if (symbol_conf.vmlinux_name) {
                              char serr[256];
-                             dso__strerror_load(al.map->dso, serr, sizeof(serr));
+                             dso__strerror_load(map__dso(al.map),
+                                                serr, sizeof(serr));
                              ui__warning("The %s file can't be used: %s\n%s",
                                          symbol_conf.vmlinux_name, serr, msg);
                      } else {
tools/perf/builtin-trace.c +1 -1
index 32844d8a0ea5..0134f24da3e3 100644
@@ -2862,7 +2862,7 @@ static void print_location(FILE *f, struct perf_sample *sample,
 {
 
      if ((verbose > 0 || print_dso) && al->map)
-             fprintf(f, "%s@", al->map->dso->long_name);
+             fprintf(f, "%s@", map__dso(al->map)->long_name);
 
      if ((verbose > 0 || print_sym) && al->sym)
              fprintf(f, "%s+0x%" PRIx64, al->sym->name,
tools/perf/scripts/python/Perf-Trace-Util/Context.c +4 -3
index b64013a87c54..b83b62d33945 100644
@@ -152,9 +152,10 @@ static PyObject *perf_sample_src(PyObject *obj, PyObject *args, bool get_srccode
      map = c->al->map;
      addr = c->al->addr;
 
-     if (map && map->dso)
-             srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+     if (map && map__dso(map)) {
+             srcfile = get_srcline_split(map__dso(map),
+                                         map__rip_2objdump(map, addr), &line);
+     }
      if (get_srccode) {
              if (srcfile)
                      srccode = find_sourceline(srcfile, line, &len);
tools/perf/tests/code-reading.c +16 -16
index 6eafe36a8704..9cb7d3f577d7 100644
@@ -240,7 +240,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
      pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-     if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
+     if (!thread__find_map(thread, cpumode, addr, &al) || !map__dso(al.map)) {
              if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
                      pr_debug("Hypervisor address can not be resolved - skipping\n");
                      return 0;
@@ -250,10 +250,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              return -1;
      }
 
-     pr_debug("File is: %s\n", al.map->dso->long_name);
+     pr_debug("File is: %s\n", map__dso(al.map)->long_name);
 
-     if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-         !dso__is_kcore(al.map->dso)) {
+     if (map__dso(al.map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+         !dso__is_kcore(map__dso(al.map))) {
              pr_debug("Unexpected kernel address - skipping\n");
              return 0;
      }
@@ -264,11 +264,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              len = BUFSZ;
 
      /* Do not go off the map */
-     if (addr + len > al.map->end)
-             len = al.map->end - addr;
+     if (addr + len > map__end(al.map))
+             len = map__end(al.map) - addr;
 
      /* Read the object code using perf */
-     ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
+     ret_len = dso__data_read_offset(map__dso(al.map), maps__machine(thread->maps),
                                      al.addr, buf1, len);
      if (ret_len != len) {
              pr_debug("dso__data_read_offset failed\n");
@@ -283,11 +283,11 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
              return -1;
 
      /* objdump struggles with kcore - try each map only once */
-     if (dso__is_kcore(al.map->dso)) {
+     if (dso__is_kcore(map__dso(al.map))) {
              size_t d;
 
              for (d = 0; d < state->done_cnt; d++) {
-                     if (state->done[d] == al.map->start) {
+                     if (state->done[d] == map__start(al.map)) {
                              pr_debug("kcore map tested already");
                              pr_debug(" - skipping\n");
                              return 0;
@@ -297,12 +297,12 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
                      pr_debug("Too many kcore maps - skipping\n");
                      return 0;
              }
-             state->done[state->done_cnt++] = al.map->start;
+             state->done[state->done_cnt++] = map__start(al.map);
      }
 
-     objdump_name = al.map->dso->long_name;
-     if (dso__needs_decompress(al.map->dso)) {
-             if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+     objdump_name = map__dso(al.map)->long_name;
+     if (dso__needs_decompress(map__dso(al.map))) {
+             if (dso__decompress_kmodule_path(map__dso(al.map), objdump_name,
                                               decomp_name,
                                               sizeof(decomp_name)) < 0) {
                      pr_debug("decompression failed\n");
@@ -330,7 +330,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
                      len -= ret;
                      if (len) {
                              pr_debug("Reducing len to %zu\n", len);
-                     } else if (dso__is_kcore(al.map->dso)) {
+                     } else if (dso__is_kcore(map__dso(al.map))) {
                              /*
                               * objdump cannot handle very large segments
                               * that may be found in kcore.
@@ -588,8 +588,8 @@ static int do_test_code_reading(bool try_kcore)
              pr_debug("map__load failed\n");
              goto out_err;
      }
-     have_vmlinux = dso__is_vmlinux(map->dso);
-     have_kcore = dso__is_kcore(map->dso);
+     have_vmlinux = dso__is_vmlinux(map__dso(map));
+     have_kcore = dso__is_kcore(map__dso(map));
 
      /* 2nd time through we just try kcore */
      if (try_kcore && !have_kcore)
tools/perf/tests/hists_common.c +2 -2
index 6f34d08b84e5..40eccc659767 100644
@@ -181,7 +181,7 @@ void print_hists_in(struct hists *hists)
              if (!he->filtered) {
                      pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
                              i, thread__comm_str(he->thread),
-                             he->ms.map->dso->short_name,
+                             map__dso(he->ms.map)->short_name,
                              he->ms.sym->name, he->stat.period);
              }
 
@@ -208,7 +208,7 @@ void print_hists_out(struct hists *hists)
              if (!he->filtered) {
                      pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
                              i, thread__comm_str(he->thread), he->thread->tid,
-                             he->ms.map->dso->short_name,
+                             map__dso(he->ms.map)->short_name,
                              he->ms.sym->name, he->stat.period,
                              he->stat_acc ? he->stat_acc->period : 0);
              }
tools/perf/tests/vmlinux-kallsyms.c +19 -16
index 11a230ee5894..5afab21455f1 100644
@@ -13,7 +13,7 @@
 #include "debug.h"
 #include "machine.h"
 
-#define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
+#define UM(x) map__unmap_ip(kallsyms_map, (x))
 
 static bool is_ignored_symbol(const char *name, char type)
 {
@@ -216,8 +216,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
              if (sym->start == sym->end)
                      continue;
 
-             mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
-             mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
+             mem_start = map__unmap_ip(vmlinux_map, sym->start);
+             mem_end = map__unmap_ip(vmlinux_map, sym->end);
 
              first_pair = machine__find_kernel_symbol(&kallsyms, mem_start, NULL);
              pair = first_pair;
@@ -262,7 +262,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 
                              continue;
                      }
-             } else if (mem_start == kallsyms.vmlinux_map->end) {
+             } else if (mem_start == map__end(kallsyms.vmlinux_map)) {
                      /*
                       * Ignore aliases to _etext, i.e. to the end of the kernel text area,
                       * such as __indirect_thunk_end.
@@ -294,9 +294,10 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
               * so use the short name, less descriptive but the same ("[kernel]" in
               * both cases.
               */
-             struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
-                                                             map->dso->short_name :
-                                                             map->dso->name));
+             struct map *pair = maps__find_by_name(kallsyms.kmaps,
+                                             map__dso(map)->kernel
+                                             ? map__dso(map)->short_name
+                                             : map__dso(map)->name);
              if (pair) {
                      pair->priv = 1;
              } else {
@@ -313,25 +314,27 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
      maps__for_each_entry(maps, rb_node) {
              struct map *pair, *map = rb_node->map;
 
-             mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
-             mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
+             mem_start = map__unmap_ip(vmlinux_map, map__start(map));
+             mem_end = map__unmap_ip(vmlinux_map, map__end(map));
 
              pair = maps__find(kallsyms.kmaps, mem_start);
-             if (pair == NULL || pair->priv)
+             if (pair == NULL || map__priv(pair))
                      continue;
 
-             if (pair->start == mem_start) {
+             if (map__start(pair) == mem_start) {
                      if (!header_printed) {
                              pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
                              header_printed = true;
                      }
 
                      pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
-                             map->start, map->end, map->pgoff, map->dso->name);
-                     if (mem_end != pair->end)
+                             map__start(map), map__end(map),
+                             map__pgoff(map), map__dso(map)->name);
+                     if (mem_end != map__end(pair))
                              pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
-                                     pair->start, pair->end, pair->pgoff);
-                     pr_info(" %s\n", pair->dso->name);
+                                     map__start(pair), map__end(pair),
+                                     map__pgoff(pair));
+                     pr_info(" %s\n", map__dso(pair)->name);
                      pair->priv = 1;
              }
      }
@@ -343,7 +346,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
      maps__for_each_entry(maps, rb_node) {
              struct map *map = rb_node->map;
 
-             if (!map->priv) {
+             if (!map__priv(map)) {
                      if (!header_printed) {
                              pr_info("WARN: Maps only in kallsyms:\n");
                              header_printed = true;
tools/perf/ui/browsers/annotate.c +4 -3
index 44ba900828f6..7d51d92302dc 100644
@@ -446,7 +446,8 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 static int sym_title(struct symbol *sym, struct map *map, char *title,
                   size_t sz, int percent_type)
 {
-     return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+     return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+                     map__dso(map)->long_name,
                      percent_type_str(percent_type));
 }
 
@@ -971,14 +972,14 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
      if (sym == NULL)
              return -1;
 
-     if (ms->map->dso->annotate_warned)
+     if (map__dso(ms->map)->annotate_warned)
              return -1;
 
      if (not_annotated) {
              err = symbol__annotate2(ms, evsel, opts, &browser.arch);
              if (err) {
                      char msg[BUFSIZ];
-                     ms->map->dso->annotate_warned = true;
+                     map__dso(ms->map)->annotate_warned = true;
                      symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
                      ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
                      goto out_free_offsets;
tools/perf/ui/browsers/hists.c +11 -7
index 572ff38ceb0f..2241447e9bfb 100644
@@ -2487,7 +2487,7 @@ static struct symbol *symbol__new_unresolved(u64 addr, struct map *map)
                      return NULL;
              }
 
-             dso__insert_symbol(map->dso, sym);
+             dso__insert_symbol(map__dso(map), sym);
      }
 
      return sym;
@@ -2499,7 +2499,7 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
               struct map_symbol *ms,
               u64 addr)
 {
-     if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
+     if (!ms->map || !map__dso(ms->map) || map__dso(ms->map)->annotate_warned)
              return 0;
 
      if (!ms->sym)
@@ -2590,8 +2590,10 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map
              ui_helpline__pop();
      } else {
              ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
-                                __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
-             browser->hists->dso_filter = map->dso;
+                                __map__is_kernel(map)
+                                ? "the Kernel"
+                                : map__dso(map)->short_name);
+             browser->hists->dso_filter = map__dso(map);
              perf_hpp__set_elide(HISTC_DSO, true);
              pstack__push(browser->pstack, &browser->hists->dso_filter);
      }
@@ -2616,7 +2618,9 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act,
 
      if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
                   browser->hists->dso_filter ? "out of" : "into",
-                  __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
+                  __map__is_kernel(map)
+                  ? "the Kernel"
+                  : map__dso(map)->short_name) < 0)
              return 0;
 
      act->ms.map = map;
@@ -3091,8 +3095,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
 
                      if (!browser->selection ||
                          !browser->selection->map ||
-                         !browser->selection->map->dso ||
-                         browser->selection->map->dso->annotate_warned) {
+                         !map__dso(browser->selection->map) ||
+                         map__dso(browser->selection->map)->annotate_warned) {
                              continue;
                      }
 
tools/perf/ui/browsers/map.c +2 -2
index 3d49b916c9e4..3d1b958d8832 100644
@@ -76,7 +76,7 @@ static int map_browser__run(struct map_browser *browser)
 {
      int key;
 
-     if (ui_browser__show(&browser->b, browser->map->dso->long_name,
+     if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name,
                           "Press ESC to exit, %s / to search",
                           verbose > 0 ? "" : "restart with -v to use") < 0)
              return -1;
@@ -106,7 +106,7 @@ int map__browse(struct map *map)
 {
      struct map_browser mb = {
              .b = {
-                     .entries = &map->dso->symbols,
+                     .entries = &map__dso(map)->symbols,
                      .refresh = ui_browser__rb_tree_refresh,
                      .seek    = ui_browser__rb_tree_seek,
                      .write   = map_browser__write,
tools/perf/util/annotate.c +21 -17
index 01900689dc00..3a7433d3e48a 100644
@@ -280,7 +280,9 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
      target.addr = map__objdump_2mem(map, ops->target.addr);
 
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                           ) == ops->target.addr)
              ops->target.sym = target.ms.sym;
 
      return 0;
@@ -384,8 +386,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
      }
 
      target.addr = map__objdump_2mem(map, ops->target.addr);
-     start = map->unmap_ip(map, sym->start),
-     end = map->unmap_ip(map, sym->end);
+     start = map__unmap_ip(map, sym->start),
+     end = map__unmap_ip(map, sym->end);
 
      ops->target.outside = target.addr < start || target.addr > end;
 
@@ -408,7 +410,9 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
       * the symbol searching and disassembly should be done.
       */
      if (maps__find_ams(ms->maps, &target) == 0 &&
-         map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
+         map__rip_2objdump(target.ms.map,
+                           map->map_ip(target.ms.map, target.addr)
+                           ) == ops->target.addr)
              ops->target.sym = target.ms.sym;
 
      if (!ops->target.outside) {
@@ -889,7 +893,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms,
      unsigned offset;
      struct sym_hist *h;
 
-     pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, ms->map->unmap_ip(ms->map, addr));
+     pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map__unmap_ip(ms->map, addr));
 
      if ((addr < sym->start || addr >= sym->end) &&
          (addr != sym->end || sym->start != sym->end)) {
@@ -1016,13 +1020,13 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
      if (start &&
              (start->ms.sym == ams->ms.sym ||
               (ams->ms.sym &&
-                start->addr == ams->ms.sym->start + ams->ms.map->start)))
+               start->addr == ams->ms.sym->start + map__start(ams->ms.map))))
              saddr = start->al_addr;
      if (saddr == 0)
              pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n",
                      ams->addr,
                      start ? start->addr : 0,
-                     ams->ms.sym ? ams->ms.sym->start + ams->ms.map->start : 0,
+                     ams->ms.sym ? ams->ms.sym->start + map__start(ams->ms.map) : 0,
                      saddr);
      err = symbol__account_cycles(ams->al_addr, saddr, ams->ms.sym, cycles);
      if (err)
@@ -1593,7 +1597,7 @@ static void delete_last_nop(struct symbol *sym)
 
 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
 
      BUG_ON(buflen == 0);
 
@@ -1723,7 +1727,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
      struct map *map = args->ms.map;
      struct perf_bpil *info_linear;
      struct disassemble_info info;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      int pc = 0, count, sub_id;
      struct btf *btf = NULL;
      char tpath[PATH_MAX];
@@ -1946,7 +1950,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 {
      struct annotation_options *opts = args->options;
      struct map *map = args->ms.map;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      char *command;
      FILE *file;
      char symfs_filename[PATH_MAX];
@@ -1973,8 +1977,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
              return err;
 
      pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
-              symfs_filename, sym->name, map->unmap_ip(map, sym->start),
-              map->unmap_ip(map, sym->end));
+              symfs_filename, sym->name, map__unmap_ip(map, sym->start),
+              map__unmap_ip(map, sym->end));
 
      pr_debug("annotating [%p] %30s : [%p] %30s\n",
               dso, dso->long_name, sym, sym->name);
@@ -2386,7 +2390,7 @@ int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
 {
      struct map *map = ms->map;
      struct symbol *sym = ms->sym;
-     struct dso *dso = map->dso;
+     struct dso *dso = map__dso(map);
      char *filename;
      const char *d_filename;
      const char *evsel_name = evsel__name(evsel);
@@ -2569,7 +2573,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
      }
 
      fprintf(fp, "%s() %s\nEvent: %s\n\n",
-             ms->sym->name, ms->map->dso->long_name, ev_name);
+             ms->sym->name, map__dso(ms->map)->long_name, ev_name);
      symbol__annotate_fprintf2(ms->sym, fp, opts);
 
      fclose(fp);
@@ -2781,7 +2785,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
              if (percent_max <= 0.5)
                      continue;
 
-             al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
+             al->path = get_srcline(map__dso(map), notes->start + al->offset, NULL,
                                     false, true, notes->start + al->offset);
              insert_source_line(&tmp_root, al, opts);
      }
@@ -2800,7 +2804,7 @@ static void symbol__calc_lines(struct map_symbol *ms, struct rb_root *root,
 int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
                        struct annotation_options *opts)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
      struct symbol *sym = ms->sym;
      struct rb_root source_line = RB_ROOT;
      struct hists *hists = evsel__hists(evsel);
@@ -2836,7 +2840,7 @@ int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
 int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel,
                       struct annotation_options *opts)
 {
-     struct dso *dso = ms->map->dso;
+     struct dso *dso = map__dso(ms->map);
      struct symbol *sym = ms->sym;
      struct rb_root source_line = RB_ROOT;
      int err;
tools/perf/util/auxtrace.c +1 -1
index 825336304a37..2e864c9bdef3 100644
@@ -2478,7 +2478,7 @@ static struct dso *load_dso(const char *name)
      if (map__load(map) < 0)
              pr_err("File '%s' not found or has no symbols.\n", name);
 
-     dso = dso__get(map->dso);
+     dso = dso__get(map__dso(map));
 
      map__put(map);
 
tools/perf/util/block-info.c +2 -2
index 5ecd4f401f32..16a7b4adcf18 100644
@@ -317,9 +317,9 @@ static int block_dso_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
      struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
      struct map *map = he->ms.map;
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
-                              map->dso->short_name);
+                              map__dso(map)->short_name);
      }
 
      return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
tools/perf/util/bpf-event.c +4 -4
index 33257b594a71..5717933be116 100644
@@ -95,10 +95,10 @@ static int machine__process_bpf_event_load(struct machine *machine,
              struct map *map = maps__find(machine__kernel_maps(machine), addr);
 
              if (map) {
-                     map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
-                     map->dso->bpf_prog.id = id;
-                     map->dso->bpf_prog.sub_id = i;
-                     map->dso->bpf_prog.env = env;
+                     map__dso(map)->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+                     map__dso(map)->bpf_prog.id = id;
+                     map__dso(map)->bpf_prog.sub_id = i;
+                     map__dso(map)->bpf_prog.env = env;
              }
      }
      return 0;
tools/perf/util/build-id.c +1 -1
index 7a5821c87f94..274b705dd941 100644
@@ -59,7 +59,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
      }
 
      if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
-             al.map->dso->hit = 1;
+             map__dso(al.map)->hit = 1;
 
      thread__put(thread);
      return 0;
tools/perf/util/callchain.c +5 -5
index 61bb3fb2107a..a8cfd31a3ff0 100644
@@ -695,8 +695,8 @@ static enum match_result match_chain_strings(const char *left,
 static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
                                                 struct map *right_map, u64 right_ip)
 {
-     struct dso *left_dso = left_map ? left_map->dso : NULL;
-     struct dso *right_dso = right_map ? right_map->dso : NULL;
+     struct dso *left_dso = left_map ? map__dso(left_map) : NULL;
+     struct dso *right_dso = right_map ? map__dso(right_map) : NULL;
 
      if (left_dso != right_dso)
              return left_dso < right_dso ? MATCH_LT : MATCH_GT;
@@ -1167,9 +1167,9 @@ char *callchain_list__sym_name(struct callchain_list *cl,
 
      if (show_dso)
              scnprintf(bf + printed, bfsize - printed, " %s",
-                       cl->ms.map ?
-                       cl->ms.map->dso->short_name :
-                       "unknown");
+                       cl->ms.map
+                       ? map__dso(cl->ms.map)->short_name
+                       : "unknown");
 
      return bf;
 }
tools/perf/util/data-convert-json.c +2 -2
index f1ab6edba446..9c83228bb9f1 100644
@@ -127,8 +127,8 @@ static void output_sample_callchain_entry(struct perf_tool *tool,
              fputc(',', out);
              output_json_key_string(out, false, 5, "symbol", al->sym->name);
 
-             if (al->map && al->map->dso) {
-                     const char *dso = al->map->dso->short_name;
+             if (al->map && map__dso(al->map)) {
+                     const char *dso = map__dso(al->map)->short_name;
 
                      if (dso && strlen(dso) > 0) {
                              fputc(',', out);
tools/perf/util/db-export.c +2 -2
index 1cfcfdd3cf52..84c970c11794 100644
@@ -179,7 +179,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
      int err;
 
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              err = db_export__dso(dbe, dso, maps__machine(al->maps));
              if (err)
@@ -255,7 +255,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
              al.addr = node->ip;
 
              if (al.map && !al.sym)
-                     al.sym = dso__find_symbol(al.map->dso, al.addr);
+                     al.sym = dso__find_symbol(map__dso(al.map), al.addr);
 
              db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
tools/perf/util/dlfilter.c +11 -10
index d59462af15f1..f1d9dd7065e6 100644
@@ -29,7 +29,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 
      d_al->size = sizeof(*d_al);
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              if (symbol_conf.show_kernel_path && dso->long_name)
                      d_al->dso = dso->long_name;
@@ -51,7 +51,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
              if (al->addr < sym->end)
                      d_al->symoff = al->addr - sym->start;
              else
-                     d_al->symoff = al->addr - al->map->start - sym->start;
+                     d_al->symoff = al->addr - map__start(al->map) - sym->start;
              d_al->sym_binding = sym->binding;
      } else {
              d_al->sym = NULL;
@@ -232,9 +232,10 @@ static const char *dlfilter__srcline(void *ctx, __u32 *line_no)
      map = al->map;
      addr = al->addr;
 
-     if (map && map->dso)
-             srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
-
+     if (map && map__dso(map)) {
+             srcfile = get_srcline_split(map__dso(map),
+                                         map__rip_2objdump(map, addr), &line);
+     }
      *line_no = line;
      return srcfile;
 }
@@ -266,7 +267,7 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
      map = al->map;
 
-     if (map && ip >= map->start && ip < map->end &&
+     if (map && ip >= map__start(map) && ip < map__end(map) &&
          machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
              goto have_map;
 
@@ -276,10 +277,10 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
 
      map = a.map;
 have_map:
-     offset = map->map_ip(map, ip);
-     if (ip + len >= map->end)
-             len = map->end - ip;
-     return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
+     offset = map__map_ip(map, ip);
+     if (ip + len >= map__end(map))
+             len = map__end(map) - ip;
+     return dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
 }
 
 static const struct perf_dlfilter_fns perf_dlfilter_fns = {
tools/perf/util/dso.c +2 -2
index b2f570adba35..1115bc51a261 100644
@@ -1109,7 +1109,7 @@ ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
                          struct machine *machine, u64 addr,
                          u8 *data, ssize_t size)
 {
-     u64 offset = map->map_ip(map, addr);
+     u64 offset = map__map_ip(map, addr);
      return dso__data_read_offset(dso, machine, offset, data, size);
 }
 
@@ -1149,7 +1149,7 @@ ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
                                 struct machine *machine, u64 addr,
                                 const u8 *data, ssize_t size)
 {
-     u64 offset = map->map_ip(map, addr);
+     u64 offset = map__map_ip(map, addr);
      return dso__data_write_cache_offs(dso, machine, offset, data, size);
 }
 
tools/perf/util/event.c +7 -7
index 40a3b1a35613..54a1d4df5f70 100644
@@ -486,7 +486,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
 
              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.addr = map__map_ip(al.map, tp->addr);
                      al.sym = map__find_symbol(al.map, al.addr);
                      if (al.sym)
                              ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
@@ -621,7 +621,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
               */
              if (load_map)
                      map__load(al->map);
-             al->addr = al->map->map_ip(al->map, al->addr);
+             al->addr = map__map_ip(al->map, al->addr);
      }
 
      return al->map;
@@ -692,8 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
      dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
      thread__find_map(thread, sample->cpumode, sample->ip, al);
      dump_printf(" ...... dso: %s\n",
-                 al->map ? al->map->dso->long_name :
-                     al->level == 'H' ? "[hypervisor]" : "<not found>");
+                 al->map ? map__dso(al->map)->long_name
+                         : al->level == 'H' ? "[hypervisor]" : "<not found>");
 
      if (thread__is_filtered(thread))
              al->filtered |= (1 << HIST_FILTER__THREAD);
@@ -711,7 +711,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
      }
 
      if (al->map) {
-             struct dso *dso = al->map->dso;
+             struct dso *dso = map__dso(al->map);
 
              if (symbol_conf.dso_list &&
                  (!dso || !(strlist__has_entry(symbol_conf.dso_list,
@@ -738,12 +738,12 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
              }
              if (!ret && al->sym) {
                      snprintf(al_addr_str, sz, "0x%"PRIx64,
-                             al->map->unmap_ip(al->map, al->sym->start));
+                              map__unmap_ip(al->map, al->sym->start));
                      ret = strlist__has_entry(symbol_conf.sym_list,
                                              al_addr_str);
              }
              if (!ret && symbol_conf.addr_list && al->map) {
-                     unsigned long addr = al->map->unmap_ip(al->map, al->addr);
+                     unsigned long addr = map__unmap_ip(al->map, al->addr);
 
                      ret = intlist__has_entry(symbol_conf.addr_list, addr);
                      if (!ret && symbol_conf.addr_range) {
tools/perf/util/evsel_fprintf.c +2 -2
index 8c2ea8001329..ac6fef9d8906 100644
@@ -146,11 +146,11 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
                              printed += fprintf(fp, " <-");
 
                      if (map)
-                             addr = map->map_ip(map, node->ip);
+                             addr = map__map_ip(map, node->ip);
 
                      if (print_ip) {
                              /* Show binary offset for userspace addr */
-                             if (map && !map->dso->kernel)
+                             if (map && !map__dso(map)->kernel)
                                      printed += fprintf(fp, "%c%16" PRIx64, s, addr);
                              else
                                      printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
tools/perf/util/hist.c +5 -5
index 78f9fbb925a7..f19ac6eb4775 100644
@@ -105,7 +105,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
              hists__set_col_len(hists, HISTC_THREAD, len + 8);
 
      if (h->ms.map) {
-             len = dso__name_len(h->ms.map->dso);
+             len = dso__name_len(map__dso(h->ms.map));
              hists__new_col_len(hists, HISTC_DSO, len);
      }
 
@@ -119,7 +119,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
                              symlen += BITS_PER_LONG / 4 + 2 + 3;
                      hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
-                     symlen = dso__name_len(h->branch_info->from.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->branch_info->from.ms.map));
                      hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
              } else {
                      symlen = unresolved_col_width + 4 + 2;
@@ -133,7 +133,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
                              symlen += BITS_PER_LONG / 4 + 2 + 3;
                      hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
-                     symlen = dso__name_len(h->branch_info->to.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->branch_info->to.ms.map));
                      hists__new_col_len(hists, HISTC_DSO_TO, symlen);
              } else {
                      symlen = unresolved_col_width + 4 + 2;
@@ -177,7 +177,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
              }
 
              if (h->mem_info->daddr.ms.map) {
-                     symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
+                     symlen = dso__name_len(map__dso(h->mem_info->daddr.ms.map));
                      hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
                                         symlen);
              } else {
@@ -2096,7 +2096,7 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
                                     struct hist_entry *he)
 {
      if (hists->dso_filter != NULL &&
-         (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
+         (he->ms.map == NULL || map__dso(he->ms.map) != hists->dso_filter)) {
              he->filtered |= (1 << HIST_FILTER__DSO);
              return true;
      }
tools/perf/util/intel-pt.c +24 -24
index e8613cbda331..c88f112c0a06 100644
@@ -731,20 +731,20 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
      }
 
      while (1) {
-             if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
+             if (!thread__find_map(thread, cpumode, *ip, &al) || !map__dso(al.map))
                      return -EINVAL;
 
-             if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-                 dso__data_status_seen(al.map->dso,
+             if (map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR &&
+                 dso__data_status_seen(map__dso(al.map),
                                        DSO_DATA_STATUS_SEEN_ITRACE))
                      return -ENOENT;
 
-             offset = al.map->map_ip(al.map, *ip);
+             offset = map__map_ip(al.map, *ip);
 
              if (!to_ip && one_map) {
                      struct intel_pt_cache_entry *e;
 
-                     e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+                     e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
                      if (e &&
                          (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) {
                              *insn_cnt_ptr = e->insn_cnt;
@@ -766,10 +766,10 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
              /* Load maps to ensure dso->is_64_bit has been updated */
              map__load(al.map);
 
-             x86_64 = al.map->dso->is_64_bit;
+             x86_64 = map__dso(al.map)->is_64_bit;
 
              while (1) {
-                     len = dso__data_read_offset(al.map->dso, machine,
+                     len = dso__data_read_offset(map__dso(al.map), machine,
                                                  offset, buf,
                                                  INTEL_PT_INSN_BUF_SZ);
                      if (len <= 0)
@@ -795,7 +795,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
                              goto out_no_cache;
                      }
 
-                     if (*ip >= al.map->end)
+                     if (*ip >= map__end(al.map))
                              break;
 
                      offset += intel_pt_insn->length;
@@ -815,13 +815,13 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
      if (to_ip) {
              struct intel_pt_cache_entry *e;
 
-             e = intel_pt_cache_lookup(al.map->dso, machine, start_offset);
+             e = intel_pt_cache_lookup(map__dso(al.map), machine, start_offset);
              if (e)
                      return 0;
      }
 
      /* Ignore cache errors */
-     intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt,
+     intel_pt_cache_add(map__dso(al.map), machine, start_offset, insn_cnt,
                         *ip - start_ip, intel_pt_insn);
 
      return 0;
@@ -892,13 +892,13 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
      if (!thread)
              return -EINVAL;
 
-     if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
+     if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map))
              return -EINVAL;
 
-     offset = al.map->map_ip(al.map, ip);
+     offset = map__map_ip(al.map, ip);
 
      return intel_pt_match_pgd_ip(ptq->pt, ip, offset,
-                                  al.map->dso->long_name);
+                                  map__dso(al.map)->long_name);
 }
 
 static bool intel_pt_pgd_ip(uint64_t ip, void *data)
@@ -2406,13 +2406,13 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
      if (map__load(map))
              return 0;
 
-     start = dso__first_symbol(map->dso);
+     start = dso__first_symbol(map__dso(map));
 
      for (sym = start; sym; sym = dso__next_symbol(sym)) {
              if (sym->binding == STB_GLOBAL &&
                  !strcmp(sym->name, "__switch_to")) {
-                     ip = map->unmap_ip(map, sym->start);
-                     if (ip >= map->start && ip < map->end) {
+                     ip = map__unmap_ip(map, sym->start);
+                     if (ip >= map__start(map) && ip < map__end(map)) {
                              switch_ip = ip;
                              break;
                      }
@@ -2429,8 +2429,8 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 
      for (sym = start; sym; sym = dso__next_symbol(sym)) {
              if (!strcmp(sym->name, ptss)) {
-                     ip = map->unmap_ip(map, sym->start);
-                     if (ip >= map->start && ip < map->end) {
+                     ip = map__unmap_ip(map, sym->start);
+                     if (ip >= map__start(map) && ip < map__end(map)) {
                              *ptss_ip = ip;
                              break;
                      }
@@ -2965,7 +2965,7 @@ static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt,
 static int intel_pt_find_map(struct thread *thread, u8 cpumode, u64 addr,
                           struct addr_location *al)
 {
-     if (!al->map || addr < al->map->start || addr >= al->map->end) {
+     if (!al->map || addr < map__start(al->map) || addr >= map__end(al->map)) {
              if (!thread__find_map(thread, cpumode, addr, al))
                      return -1;
      }
@@ -2996,12 +2996,12 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
                      continue;
              }
 
-             if (!al.map->dso || !al.map->dso->auxtrace_cache)
+             if (!map__dso(al.map) || !map__dso(al.map)->auxtrace_cache)
                      continue;
 
-             offset = al.map->map_ip(al.map, addr);
+             offset = map__map_ip(al.map, addr);
 
-             e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+             e = intel_pt_cache_lookup(map__dso(al.map), machine, offset);
              if (!e)
                      continue;
 
@@ -3014,9 +3014,9 @@ static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event)
                      if (e->branch != INTEL_PT_BR_NO_BRANCH)
                              return 0;
              } else {
-                     intel_pt_cache_invalidate(al.map->dso, machine, offset);
+                     intel_pt_cache_invalidate(map__dso(al.map), machine, offset);
                      intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n",
-                                  al.map->dso->long_name, addr);
+                                  map__dso(al.map)->long_name, addr);
              }
      }
 
tools/perf/util/machine.c +44 -40
index 88279008e761..940fb2a50dfd 100644
@@ -47,7 +47,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
 
 static struct dso *machine__kernel_dso(struct machine *machine)
 {
-     return machine->vmlinux_map->dso;
+     return map__dso(machine->vmlinux_map);
 }
 
 static void dsos__init(struct dsos *dsos)
@@ -842,9 +842,10 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
      if (map != machine->vmlinux_map)
              maps__remove(machine__kernel_maps(machine), map);
      else {
-             sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+             sym = dso__find_symbol(map__dso(map),
+                             map__map_ip(map, map__start(map)));
              if (sym)
-                     dso__delete_symbol(map->dso, sym);
+                     dso__delete_symbol(map__dso(map), sym);
      }
 
      return 0;
@@ -880,7 +881,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
              return 0;
      }
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
              int ret;
 
@@ -889,7 +890,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
               * must be done prior to using kernel maps.
               */
              map__load(map);
-             ret = dso__data_write_cache_addr(map->dso, map, machine,
+             ret = dso__data_write_cache_addr(map__dso(map), map, machine,
                                               event->text_poke.addr,
                                               new_bytes,
                                               event->text_poke.new_len);
@@ -931,6 +932,7 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
      /* If maps__insert failed, return NULL. */
      if (err)
              map = NULL;
+
 out:
      /* put the dso here, corresponding to  machine__findnew_module_dso */
      dso__put(dso);
@@ -1118,7 +1120,7 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
      if (!err) {
              pr_debug2("Added extra kernel map %s %" PRIx64 "-%" PRIx64 "\n",
-                     kmap->name, map->start, map->end);
+                     kmap->name, map__start(map), map__end(map));
      }
 
      map__put(map);
@@ -1178,9 +1180,9 @@ int machine__map_x86_64_entry_trampolines(struct machine *machine,
              if (!kmap || !is_entry_trampoline(kmap->name))
                      continue;
 
-             dest_map = maps__find(kmaps, map->pgoff);
+             dest_map = maps__find(kmaps, map__pgoff(map));
              if (dest_map != map)
-                     map->pgoff = dest_map->map_ip(dest_map, map->pgoff);
+                     map->pgoff = map__map_ip(dest_map, map__pgoff(map));
              found = true;
      }
      if (found || machine->trampolines_mapped)
@@ -1230,7 +1232,8 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
      if (machine->vmlinux_map == NULL)
              return -ENOMEM;
 
-     machine->vmlinux_map->map_ip = machine->vmlinux_map->unmap_ip = identity__map_ip;
+     machine->vmlinux_map->map_ip = map__identity_ip;
+     machine->vmlinux_map->unmap_ip = map__identity_ip;
      return maps__insert(machine__kernel_maps(machine), machine->vmlinux_map);
 }
 
@@ -1329,10 +1332,10 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 int machine__load_kallsyms(struct machine *machine, const char *filename)
 {
      struct map *map = machine__kernel_map(machine);
-     int ret = __dso__load_kallsyms(map->dso, filename, map, true);
+     int ret = __dso__load_kallsyms(map__dso(map), filename, map, true);
 
      if (ret > 0) {
-             dso__set_loaded(map->dso);
+             dso__set_loaded(map__dso(map));
              /*
               * Since /proc/kallsyms will have multiple sessions for the
               * kernel, with modules between them, fixup the end of all
@@ -1347,10 +1350,10 @@ int machine__load_kallsyms(struct machine *machine, const char *filename)
 int machine__load_vmlinux_path(struct machine *machine)
 {
      struct map *map = machine__kernel_map(machine);
-     int ret = dso__load_vmlinux_path(map->dso, map);
+     int ret = dso__load_vmlinux_path(map__dso(map), map);
 
      if (ret > 0)
-             dso__set_loaded(map->dso);
+             dso__set_loaded(map__dso(map));
 
      return ret;
 }
@@ -1401,16 +1404,16 @@ static int maps__set_module_path(struct maps *maps, const char *path, struct kmo
      if (long_name == NULL)
              return -ENOMEM;
 
-     dso__set_long_name(map->dso, long_name, true);
-     dso__kernel_module_get_build_id(map->dso, "");
+     dso__set_long_name(map__dso(map), long_name, true);
+     dso__kernel_module_get_build_id(map__dso(map), "");
 
      /*
       * Full name could reveal us kmod compression, so
       * we need to update the symtab_type if needed.
       */
-     if (m->comp && is_kmod_dso(map->dso)) {
-             map->dso->symtab_type++;
-             map->dso->comp = m->comp;
+     if (m->comp && is_kmod_dso(map__dso(map))) {
+             map__dso(map)->symtab_type++;
+             map__dso(map)->comp = m->comp;
      }
 
      return 0;
@@ -1509,8 +1512,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
              return -1;
      map->end = start + size;
 
-     dso__kernel_module_get_build_id(map->dso, machine->root_dir);
-
+     dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
      return 0;
 }
 
@@ -1619,7 +1621,7 @@ int machine__create_kernel_maps(struct machine *machine)
              struct map_rb_node *next = map_rb_node__next(rb_node);
 
              if (next)
-                     machine__set_kernel_mmap(machine, start, next->map->start);
+                     machine__set_kernel_mmap(machine, start, map__start(next->map));
      }
 
 out_put:
@@ -1683,10 +1685,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
              if (map == NULL)
                      goto out_problem;
 
-             map->end = map->start + xm->end - xm->start;
+             map->end = map__start(map) + xm->end - xm->start;
 
              if (build_id__is_defined(bid))
-                     dso__set_build_id(map->dso, bid);
+                     dso__set_build_id(map__dso(map), bid);
 
      } else if (is_kernel_mmap) {
              const char *symbol_name = (xm->name + strlen(machine->mmap_name));
@@ -2148,14 +2150,14 @@ static char *callchain_srcline(struct map_symbol *ms, u64 ip)
      if (!map || callchain_param.key == CCKEY_FUNCTION)
              return srcline;
 
-     srcline = srcline__tree_find(&map->dso->srclines, ip);
+     srcline = srcline__tree_find(&map__dso(map)->srclines, ip);
      if (!srcline) {
              bool show_sym = false;
              bool show_addr = callchain_param.key == CCKEY_ADDRESS;
 
-             srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
+             srcline = get_srcline(map__dso(map), map__rip_2objdump(map, ip),
                                    ms->sym, show_sym, show_addr, ip);
-             srcline__tree_insert(&map->dso->srclines, ip, srcline);
+             srcline__tree_insert(&map__dso(map)->srclines, ip, srcline);
      }
 
      return srcline;
@@ -2179,7 +2181,7 @@ static int add_callchain_ip(struct thread *thread,
 {
      struct map_symbol ms;
      struct addr_location al;
-     int nr_loop_iter = 0;
+     int nr_loop_iter = 0, err;
      u64 iter_cycles = 0;
      const char *srcline = NULL;
 
@@ -2228,9 +2230,10 @@ static int add_callchain_ip(struct thread *thread,
              }
      }
 
-     if (symbol_conf.hide_unresolved && al.sym == NULL)
+     if (symbol_conf.hide_unresolved && al.sym == NULL) {
+             addr_location__put(&al);
              return 0;
-
+     }
      if (iter) {
              nr_loop_iter = iter->nr_loop_iter;
              iter_cycles = iter->cycles;
@@ -2240,9 +2243,10 @@ static int add_callchain_ip(struct thread *thread,
      ms.map = al.map;
      ms.sym = al.sym;
      srcline = callchain_srcline(&ms, al.addr);
-     return callchain_cursor_append(cursor, ip, &ms,
-                                    branch, flags, nr_loop_iter,
-                                    iter_cycles, branch_from, srcline);
+     err = callchain_cursor_append(cursor, ip, &ms,
+                                   branch, flags, nr_loop_iter,
+                                   iter_cycles, branch_from, srcline);
+     return err;
 }
 
 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -2937,15 +2941,15 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
      if (!symbol_conf.inline_name || !map || !sym)
              return ret;
 
-     addr = map__map_ip(map, ip);
+     addr = map__dso_map_ip(map, ip);
      addr = map__rip_2objdump(map, addr);
 
-     inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
+     inline_node = inlines__tree_find(&map__dso(map)->inlined_nodes, addr);
      if (!inline_node) {
-             inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
+             inline_node = dso__parse_addr_inlines(map__dso(map), addr, sym);
              if (!inline_node)
                      return ret;
-             inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
+             inlines__tree_insert(&map__dso(map)->inlined_nodes, inline_node);
      }
 
      list_for_each_entry(ilist, &inline_node->val, list) {
@@ -2981,7 +2985,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
       * its corresponding binary.
       */
      if (entry->ms.map)
-             addr = map__map_ip(entry->ms.map, entry->ip);
+             addr = map__dso_map_ip(entry->ms.map, entry->ip);
 
      srcline = callchain_srcline(&entry->ms, addr);
      return callchain_cursor_append(cursor, entry->ip, &entry->ms,
@@ -3183,7 +3187,7 @@ int machine__get_kernel_start(struct machine *machine)
               * kernel_start = 1ULL << 63 for x86_64.
               */
              if (!err && !machine__is(machine, "x86_64"))
-                     machine->kernel_start = map->start;
+                     machine->kernel_start = map__start(map);
      }
      return err;
 }
@@ -3234,8 +3238,8 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
      if (sym == NULL)
              return NULL;
 
-     *modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
-     *addrp = map->unmap_ip(map, sym->start);
+     *modp = __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NULL;
+     *addrp = map__unmap_ip(map, sym->start);
      return sym->name;
 }
 
tools/perf/util/map.c +61 -56
index 57e926ce115f..47d81e361e29 100644
@@ -109,8 +109,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
      map->pgoff    = pgoff;
      map->reloc    = 0;
      map->dso      = dso__get(dso);
-     map->map_ip   = map__map_ip;
-     map->unmap_ip = map__unmap_ip;
+     map->map_ip   = map__dso_map_ip;
+     map->unmap_ip = map__dso_unmap_ip;
      map->erange_warned = false;
      refcount_set(&map->refcnt, 1);
 }
@@ -120,10 +120,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
                   u32 prot, u32 flags, struct build_id *bid,
                   char *filename, struct thread *thread)
 {
-     struct map *map = malloc(sizeof(*map));
+     struct map *map;
      struct nsinfo *nsi = NULL;
      struct nsinfo *nnsi;
 
+     map = malloc(sizeof(*map));
      if (map != NULL) {
              char newfilename[PATH_MAX];
              struct dso *dso;
@@ -170,7 +171,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
              map__init(map, start, start + len, pgoff, dso);
 
              if (anon || no_dso) {
-                     map->map_ip = map->unmap_ip = identity__map_ip;
+                     map->map_ip = map->unmap_ip = map__identity_ip;
 
                      /*
                       * Set memory without DSO as loaded. All map__find_*
@@ -204,8 +205,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
  */
 struct map *map__new2(u64 start, struct dso *dso)
 {
-     struct map *map = calloc(1, (sizeof(*map) +
-                                  (dso->kernel ? sizeof(struct kmap) : 0)));
+     struct map *map;
+
+     map = calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0));
      if (map != NULL) {
              /*
               * ->end will be filled after we load all the symbols
@@ -218,7 +220,7 @@ struct map *map__new2(u64 start, struct dso *dso)
 
 bool __map__is_kernel(const struct map *map)
 {
-     if (!map->dso->kernel)
+     if (!map__dso(map)->kernel)
              return false;
      return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
 }
@@ -234,7 +236,7 @@ bool __map__is_bpf_prog(const struct map *map)
 {
      const char *name;
 
-     if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+     if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
              return true;
 
      /*
@@ -242,7 +244,7 @@ bool __map__is_bpf_prog(const struct map *map)
       * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
       * guess the type based on name.
       */
-     name = map->dso->short_name;
+     name = map__dso(map)->short_name;
      return name && (strstr(name, "bpf_prog_") == name);
 }
 
@@ -250,7 +252,7 @@ bool __map__is_bpf_image(const struct map *map)
 {
      const char *name;
 
-     if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+     if (map__dso(map)->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
              return true;
 
      /*
@@ -258,18 +260,19 @@ bool __map__is_bpf_image(const struct map *map)
       * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
       * guess the type based on name.
       */
-     name = map->dso->short_name;
+     name = map__dso(map)->short_name;
      return name && is_bpf_image(name);
 }
 
 bool __map__is_ool(const struct map *map)
 {
-     return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+     return map__dso(map) &&
+            map__dso(map)->binary_type == DSO_BINARY_TYPE__OOL;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-     return dso__has_symbols(map->dso);
+     return dso__has_symbols(map__dso(map));
 }
 
 static void map__exit(struct map *map)
@@ -292,7 +295,7 @@ void map__put(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-     struct rb_root_cached *symbols = &map->dso->symbols;
+     struct rb_root_cached *symbols = &map__dso(map)->symbols;
      struct rb_node *nd = rb_first_cached(symbols);
      if (nd != NULL) {
              struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -302,7 +305,7 @@ void map__fixup_start(struct map *map)
 
 void map__fixup_end(struct map *map)
 {
-     struct rb_root_cached *symbols = &map->dso->symbols;
+     struct rb_root_cached *symbols = &map__dso(map)->symbols;
      struct rb_node *nd = rb_last(&symbols->rb_root);
      if (nd != NULL) {
              struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -314,18 +317,18 @@ void map__fixup_end(struct map *map)
 
 int map__load(struct map *map)
 {
-     const char *name = map->dso->long_name;
+     const char *name = map__dso(map)->long_name;
      int nr;
 
-     if (dso__loaded(map->dso))
+     if (dso__loaded(map__dso(map)))
              return 0;
 
-     nr = dso__load(map->dso, map);
+     nr = dso__load(map__dso(map), map);
      if (nr < 0) {
-             if (map->dso->has_build_id) {
+             if (map__dso(map)->has_build_id) {
                      char sbuild_id[SBUILD_ID_SIZE];
 
-                     build_id__sprintf(&map->dso->bid, sbuild_id);
+                     build_id__sprintf(&map__dso(map)->bid, sbuild_id);
                      pr_debug("%s with build id %s not found", name, sbuild_id);
              } else
                      pr_debug("Failed to open %s", name);
@@ -357,7 +360,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
      if (map__load(map) < 0)
              return NULL;
 
-     return dso__find_symbol(map->dso, addr);
+     return dso__find_symbol(map__dso(map), addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -365,24 +368,24 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
      if (map__load(map) < 0)
              return NULL;
 
-     if (!dso__sorted_by_name(map->dso))
-             dso__sort_by_name(map->dso);
+     if (!dso__sorted_by_name(map__dso(map)))
+             dso__sort_by_name(map__dso(map));
 
-     return dso__find_symbol_by_name(map->dso, name);
+     return dso__find_symbol_by_name(map__dso(map), name);
 }
 
 struct map *map__clone(struct map *from)
 {
-     size_t size = sizeof(struct map);
      struct map *map;
+     size_t size = sizeof(struct map);
 
-     if (from->dso && from->dso->kernel)
+     if (map__dso(from) && map__dso(from)->kernel)
              size += sizeof(struct kmap);
 
      map = memdup(from, size);
      if (map != NULL) {
              refcount_set(&map->refcnt, 1);
-             dso__get(map->dso);
+             map->dso = dso__get(map->dso);
      }
 
      return map;
@@ -391,7 +394,8 @@ struct map *map__clone(struct map *from)
 size_t map__fprintf(struct map *map, FILE *fp)
 {
      return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
-                    map->start, map->end, map->pgoff, map->dso->name);
+                    map__start(map), map__end(map),
+                    map__pgoff(map), map__dso(map)->name);
 }
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
@@ -399,11 +403,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
      char buf[symbol_conf.pad_output_len_dso + 1];
      const char *dsoname = "[unknown]";
 
-     if (map && map->dso) {
-             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                     dsoname = map->dso->long_name;
+     if (map && map__dso(map)) {
+             if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+                     dsoname = map__dso(map)->long_name;
              else
-                     dsoname = map->dso->name;
+                     dsoname = map__dso(map)->name;
      }
 
      if (symbol_conf.pad_output_len_dso) {
@@ -418,7 +422,8 @@ char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
 {
      if (map == NULL)
              return SRCLINE_UNKNOWN;
-     return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+     return get_srcline(map__dso(map), map__rip_2objdump(map, addr),
+                        sym, true, true, addr);
 }
 
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
@@ -426,7 +431,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 {
      int ret = 0;
 
-     if (map && map->dso) {
+     if (map && map__dso(map)) {
              char *srcline = map__srcline(map, addr, NULL);
              if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
                      ret = fprintf(fp, "%s%s", prefix, srcline);
@@ -472,20 +477,20 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
              }
      }
 
-     if (!map->dso->adjust_symbols)
+     if (!map__dso(map)->adjust_symbols)
              return rip;
 
-     if (map->dso->rel)
-             return rip - map->pgoff;
+     if (map__dso(map)->rel)
+             return rip - map__pgoff(map);
 
      /*
       * kernel modules also have DSO_TYPE_USER in dso->kernel,
       * but all kernel modules are ET_REL, so won't get here.
       */
-     if (map->dso->kernel == DSO_SPACE__USER)
-             return rip + map->dso->text_offset;
+     if (map__dso(map)->kernel == DSO_SPACE__USER)
+             return rip + map__dso(map)->text_offset;
 
-     return map->unmap_ip(map, rip) - map->reloc;
+     return map__unmap_ip(map, rip) - map__reloc(map);
 }
 
 /**
@@ -502,34 +507,34 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
  */
 u64 map__objdump_2mem(struct map *map, u64 ip)
 {
-     if (!map->dso->adjust_symbols)
-             return map->unmap_ip(map, ip);
+     if (!map__dso(map)->adjust_symbols)
+             return map__unmap_ip(map, ip);
 
-     if (map->dso->rel)
-             return map->unmap_ip(map, ip + map->pgoff);
+     if (map__dso(map)->rel)
+             return map__unmap_ip(map, ip + map__pgoff(map));
 
      /*
       * kernel modules also have DSO_TYPE_USER in dso->kernel,
       * but all kernel modules are ET_REL, so won't get here.
       */
-     if (map->dso->kernel == DSO_SPACE__USER)
-             return map->unmap_ip(map, ip - map->dso->text_offset);
+     if (map__dso(map)->kernel == DSO_SPACE__USER)
+             return map__unmap_ip(map, ip - map__dso(map)->text_offset);
 
-     return ip + map->reloc;
+     return ip + map__reloc(map);
 }
 
 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
 {
-     u64 ip = map->unmap_ip(map, sym->start);
+     u64 ip = map__unmap_ip(map, sym->start);
 
-     return ip >= map->start && ip < map->end;
+     return ip >= map__start(map) && ip < map__end(map);
 }
 
 struct kmap *__map__kmap(struct map *map)
 {
-     if (!map->dso || !map->dso->kernel)
+     if (!map__dso(map) || !map__dso(map)->kernel)
              return NULL;
-     return (struct kmap *)(map + 1);
+     return (struct kmap *)(&map[1]);
 }
 
 struct kmap *map__kmap(struct map *map)
@@ -552,17 +557,17 @@ struct maps *map__kmaps(struct map *map)
      return kmap->kmaps;
 }
 
-u64 map__map_ip(const struct map *map, u64 ip)
+u64 map__dso_map_ip(const struct map *map, u64 ip)
 {
-     return ip - map->start + map->pgoff;
+     return ip - map__start(map) + map__pgoff(map);
 }
 
-u64 map__unmap_ip(const struct map *map, u64 ip)
+u64 map__dso_unmap_ip(const struct map *map, u64 ip)
 {
-     return ip + map->start - map->pgoff;
+     return ip + map__start(map) - map__pgoff(map);
 }
 
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip)
 {
      return ip;
 }
tools/perf/util/map.h +54 -4
index d1a6f85fd31d..99ef0464a357 100644
@@ -41,15 +41,65 @@ struct kmap *map__kmap(struct map *map);
 struct maps *map__kmaps(struct map *map);
 
 /* ip -> dso rip */
-u64 map__map_ip(const struct map *map, u64 ip);
+u64 map__dso_map_ip(const struct map *map, u64 ip);
 /* dso rip -> ip */
-u64 map__unmap_ip(const struct map *map, u64 ip);
+u64 map__dso_unmap_ip(const struct map *map, u64 ip);
 /* Returns ip */
-u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
+u64 map__identity_ip(const struct map *map __maybe_unused, u64 ip);
+
+static inline struct dso *map__dso(const struct map *map)
+{
+     return map->dso;
+}
+
+static inline u64 map__map_ip(const struct map *map, u64 ip)
+{
+     return map->map_ip(map, ip);
+}
+
+static inline u64 map__unmap_ip(const struct map *map, u64 ip)
+{
+     return map->unmap_ip(map, ip);
+}
+
+static inline u64 map__start(const struct map *map)
+{
+     return map->start;
+}
+
+static inline u64 map__end(const struct map *map)
+{
+     return map->end;
+}
+
+static inline u64 map__pgoff(const struct map *map)
+{
+     return map->pgoff;
+}
+
+static inline u64 map__reloc(const struct map *map)
+{
+     return map->reloc;
+}
+
+static inline u32 map__flags(const struct map *map)
+{
+     return map->flags;
+}
+
+static inline u32 map__prot(const struct map *map)
+{
+     return map->prot;
+}
+
+static inline bool map__priv(const struct map *map)
+{
+     return map->priv;
+}
 
 static inline size_t map__size(const struct map *map)
 {
-     return map->end - map->start;
+     return map__end(map) - map__start(map);
 }
 
 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
tools/perf/util/maps.c +42 -41
index 9fc3e7186b8e..6efbcb79131c 100644
@@ -30,24 +30,24 @@ static void __maps__free_maps_by_name(struct maps *maps)
      maps->nr_maps_allocated = 0;
 }
 
-static int __maps__insert(struct maps *maps, struct map *map)
+static struct map *__maps__insert(struct maps *maps, struct map *map)
 {
      struct rb_node **p = &maps__entries(maps)->rb_node;
      struct rb_node *parent = NULL;
-     const u64 ip = map->start;
+     const u64 ip = map__start(map);
      struct map_rb_node *m, *new_rb_node;
 
      new_rb_node = malloc(sizeof(*new_rb_node));
      if (!new_rb_node)
-             return -ENOMEM;
+             return NULL;
 
      RB_CLEAR_NODE(&new_rb_node->rb_node);
-     new_rb_node->map = map;
+     new_rb_node->map = map__get(map);
 
      while (*p != NULL) {
              parent = *p;
              m = rb_entry(parent, struct map_rb_node, rb_node);
-             if (ip < m->map->start)
+             if (ip < map__start(m->map))
                      p = &(*p)->rb_left;
              else
                      p = &(*p)->rb_right;
@@ -55,22 +55,23 @@ static int __maps__insert(struct maps *maps, struct map *map)
 
      rb_link_node(&new_rb_node->rb_node, parent, p);
      rb_insert_color(&new_rb_node->rb_node, maps__entries(maps));
-     map__get(map);
-     return 0;
+     return new_rb_node->map;
 }
 
 int maps__insert(struct maps *maps, struct map *map)
 {
-     int err;
+     int err = 0;
 
      down_write(maps__lock(maps));
-     err = __maps__insert(maps, map);
-     if (err)
+     map = __maps__insert(maps, map);
+     if (!map) {
+             err = -ENOMEM;
              goto out;
+     }
 
      ++maps->nr_maps;
 
-     if (map->dso && map->dso->kernel) {
+     if (map__dso(map) && map__dso(map)->kernel) {
              struct kmap *kmap = map__kmap(map);
 
              if (kmap)
@@ -193,7 +194,7 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
      if (map != NULL && map__load(map) >= 0) {
              if (mapp != NULL)
                      *mapp = map;
-             return map__find_symbol(map, map->map_ip(map, addr));
+             return map__find_symbol(map, map__map_ip(map, addr));
      }
 
      return NULL;
@@ -228,7 +229,8 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, st
 
 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
 {
-     if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
+     if (ams->addr < map__start(ams->ms.map) ||
+         ams->addr >= map__end(ams->ms.map)) {
              if (maps == NULL)
                      return -1;
              ams->ms.map = maps__find(maps, ams->addr);
@@ -236,7 +238,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
                      return -1;
      }
 
-     ams->al_addr = ams->ms.map->map_ip(ams->ms.map, ams->addr);
+     ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
      ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
 
      return ams->ms.sym ? 0 : -1;
@@ -253,7 +255,7 @@ size_t maps__fprintf(struct maps *maps, FILE *fp)
              printed += fprintf(fp, "Map:");
              printed += map__fprintf(pos->map, fp);
              if (verbose > 2) {
-                     printed += dso__fprintf(pos->map->dso, fp);
+                     printed += dso__fprintf(map__dso(pos->map), fp);
                      printed += fprintf(fp, "--\n");
              }
      }
@@ -282,9 +284,9 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
      while (next) {
              struct map_rb_node *pos = rb_entry(next, struct map_rb_node, rb_node);
 
-             if (pos->map->end > map->start) {
+             if (map__end(pos->map) > map__start(map)) {
                      first = next;
-                     if (pos->map->start <= map->start)
+                     if (map__start(pos->map) <= map__start(map))
                              break;
                      next = next->rb_left;
              } else
@@ -300,14 +302,14 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
               * Stop if current map starts after map->end.
               * Maps are ordered by start: next will not overlap for sure.
               */
-             if (pos->map->start >= map->end)
+             if (map__start(pos->map) >= map__end(map))
                      break;
 
              if (verbose >= 2) {
 
                      if (use_browser) {
                              pr_debug("overlapping maps in %s (disable tui for more info)\n",
-                                        map->dso->name);
+                                        map__dso(map)->name);
                      } else {
                              fputs("overlapping maps:\n", fp);
                              map__fprintf(map, fp);
@@ -320,7 +322,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
               * Now check if we need to create new maps for areas not
               * overlapped by the new map:
               */
-             if (map->start > pos->map->start) {
+             if (map__start(map) > map__start(pos->map)) {
                      struct map *before = map__clone(pos->map);
 
                      if (before == NULL) {
@@ -328,17 +330,19 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
                              goto put_map;
                      }
 
-                     before->end = map->start;
-                     err = __maps__insert(maps, before);
-                     if (err)
+                     before->end = map__start(map);
+                     if (!__maps__insert(maps, before)) {
+                             map__put(before);
+                             err = -ENOMEM;
                              goto put_map;
+                     }
 
                      if (verbose >= 2 && !use_browser)
                              map__fprintf(before, fp);
                      map__put(before);
              }
 
-             if (map->end < pos->map->end) {
+             if (map__end(map) < map__end(pos->map)) {
                      struct map *after = map__clone(pos->map);
 
                      if (after == NULL) {
@@ -346,14 +350,15 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
                              goto put_map;
                      }
 
-                     after->start = map->end;
-                     after->pgoff += map->end - pos->map->start;
-                     assert(pos->map->map_ip(pos->map, map->end) ==
-                             after->map_ip(after, map->end));
-                     err = __maps__insert(maps, after);
-                     if (err)
+                     after->start = map__end(map);
+                     after->pgoff += map__end(map) - map__start(pos->map);
+                     assert(map__map_ip(pos->map, map__end(map)) ==
+                             map__map_ip(after, map__end(map)));
+                     if (!__maps__insert(maps, after)) {
+                             map__put(after);
+                             err = -ENOMEM;
                              goto put_map;
-
+                     }
                      if (verbose >= 2 && !use_browser)
                              map__fprintf(after, fp);
                      map__put(after);
@@ -377,7 +382,7 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
      struct maps *maps = thread->maps;
-     int err;
+     int err = 0;
      struct map_rb_node *rb_node;
 
      down_read(maps__lock(parent));
@@ -391,17 +396,13 @@ int maps__clone(struct thread *thread, struct maps *parent)
              }
 
              err = unwind__prepare_access(maps, new, NULL);
-             if (err)
-                     goto out_unlock;
+             if (!err)
+                     err = maps__insert(maps, new);
 
-             err = maps__insert(maps, new);
+             map__put(new);
              if (err)
                      goto out_unlock;
-
-             map__put(new);
      }
-
-     err = 0;
 out_unlock:
      up_read(maps__lock(parent));
      return err;
@@ -428,9 +429,9 @@ struct map *maps__find(struct maps *maps, u64 ip)
      p = maps__entries(maps)->rb_node;
      while (p != NULL) {
              m = rb_entry(p, struct map_rb_node, rb_node);
-             if (ip < m->map->start)
+             if (ip < map__start(m->map))
                      p = p->rb_left;
-             else if (ip >= m->map->end)
+             else if (ip >= map__end(m->map))
                      p = p->rb_right;
              else
                      goto out;
tools/perf/util/probe-event.c +22 -22
index f9fbf611f2bf..1a93dca50a4c 100644
@@ -134,15 +134,15 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
      /* ref_reloc_sym is just a label. Need a special fix*/
      reloc_sym = kernel_get_ref_reloc_sym(&map);
      if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
-             *addr = (!map->reloc || reloc) ? reloc_sym->addr :
+             *addr = (!map__reloc(map) || reloc) ? reloc_sym->addr :
                      reloc_sym->unrelocated_addr;
      else {
              sym = machine__find_kernel_symbol_by_name(host_machine, name, &map);
              if (!sym)
                      return -ENOENT;
-             *addr = map->unmap_ip(map, sym->start) -
-                     ((reloc) ? 0 : map->reloc) -
-                     ((reladdr) ? map->start : 0);
+             *addr = map__unmap_ip(map, sym->start) -
+                     ((reloc) ? 0 : map__reloc(map)) -
+                     ((reladdr) ? map__start(map) : 0);
      }
      return 0;
 }
@@ -164,8 +164,8 @@ static struct map *kernel_get_module_map(const char *module)
 
      maps__for_each_entry(maps, pos) {
              /* short_name is "[module]" */
-             const char *short_name = pos->map->dso->short_name;
-             u16 short_name_len =  pos->map->dso->short_name_len;
+             const char *short_name = map__dso(pos->map)->short_name;
+             u16 short_name_len =  map__dso(pos->map)->short_name_len;
 
              if (strncmp(short_name + 1, module,
                          short_name_len - 2) == 0 &&
@@ -183,11 +183,11 @@ struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)
              struct map *map;
 
              map = dso__new_map(target);
-             if (map && map->dso) {
-                     BUG_ON(pthread_mutex_lock(&map->dso->lock) != 0);
-                     nsinfo__put(map->dso->nsinfo);
-                     map->dso->nsinfo = nsinfo__get(nsi);
-                     pthread_mutex_unlock(&map->dso->lock);
+             if (map && map__dso(map)) {
+                     BUG_ON(pthread_mutex_lock(&map__dso(map)->lock) != 0);
+                     nsinfo__put(map__dso(map)->nsinfo);
+                     map__dso(map)->nsinfo = nsinfo__get(nsi);
+                     pthread_mutex_unlock(&map__dso(map)->lock);
              }
              return map;
      } else {
@@ -253,7 +253,7 @@ static bool kprobe_warn_out_range(const char *symbol, u64 address)
 
      map = kernel_get_module_map(NULL);
      if (map) {
-             ret = address <= map->start || map->end < address;
+             ret = address <= map__start(map) || map__end(map) < address;
              if (ret)
                      pr_warning("%s is out of .text, skip it.\n", symbol);
              map__put(map);
@@ -340,7 +340,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
              snprintf(module_name, sizeof(module_name), "[%s]", module);
              map = maps__find_by_name(machine__kernel_maps(host_machine), module_name);
              if (map) {
-                     dso = map->dso;
+                     dso = map__dso(map);
                      goto found;
              }
              pr_debug("Failed to find module %s.\n", module);
@@ -348,7 +348,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
      }
 
      map = machine__kernel_map(host_machine);
-     dso = map->dso;
+     dso = map__dso(map);
      if (!dso->has_build_id)
              dso__read_running_kernel_build_id(dso, host_machine);
 
@@ -396,7 +396,8 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
                                         "Consider identifying the final function used at run time and set the probe directly on that.\n",
                                         pp->function);
              } else
-                     address = map->unmap_ip(map, sym->start) - map->reloc;
+                     address = map__unmap_ip(map, sym->start) -
+                               map__reloc(map);
              break;
      }
      if (!address) {
@@ -862,8 +863,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
                      free(tevs[i].point.symbol);
              tevs[i].point.symbol = tmp;
              tevs[i].point.offset = tevs[i].point.address -
-                     (map->reloc ? reloc_sym->unrelocated_addr :
-                                   reloc_sym->addr);
+                     (map__reloc(map) ? reloc_sym->unrelocated_addr : reloc_sym->addr);
      }
      return skipped;
 }
@@ -2243,7 +2243,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
              goto out;
 
      pp->retprobe = tp->retprobe;
-     pp->offset = addr - map->unmap_ip(map, sym->start);
+     pp->offset = addr - map__unmap_ip(map, sym->start);
      pp->function = strdup(sym->name);
      ret = pp->function ? 0 : -ENOMEM;
 
@@ -3117,7 +3117,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
                      goto err_out;
              }
              /* Add one probe point */
-             tp->address = map->unmap_ip(map, sym->start) + pp->offset;
+             tp->address = map__unmap_ip(map, sym->start) + pp->offset;
 
              /* Check the kprobe (not in module) is within .text  */
              if (!pev->uprobes && !pev->target &&
@@ -3759,13 +3759,13 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
                             (target) ? : "kernel");
              goto end;
      }
-     if (!dso__sorted_by_name(map->dso))
-             dso__sort_by_name(map->dso);
+     if (!dso__sorted_by_name(map__dso(map)))
+             dso__sort_by_name(map__dso(map));
 
      /* Show all (filtered) symbols */
      setup_pager();
 
-     for (nd = rb_first_cached(&map->dso->symbol_names); nd;
+     for (nd = rb_first_cached(&map__dso(map)->symbol_names); nd;
           nd = rb_next(nd)) {
              struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
tools/perf/util/scripting-engines/trace-event-perl.c +5 -4
index a5d945415bbc..1282fb9b45e1 100644
@@ -315,11 +315,12 @@ static SV *perl_process_callchain(struct perf_sample *sample,
              if (node->ms.map) {
                      struct map *map = node->ms.map;
                      const char *dsoname = "[unknown]";
-                     if (map && map->dso) {
-                             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                                     dsoname = map->dso->long_name;
+                     if (map && map__dso(map)) {
+                             if (symbol_conf.show_kernel_path &&
+                                 map__dso(map)->long_name)
+                                     dsoname = map__dso(map)->long_name;
                              else
-                                     dsoname = map->dso->name;
+                                     dsoname = map__dso(map)->name;
                      }
                      if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) {
                              hv_undef(elem);
tools/perf/util/scripting-engines/trace-event-python.c +6 -6
index 0290dc3a6258..559b2ac5cac3 100644
@@ -382,11 +382,11 @@ static const char *get_dsoname(struct map *map)
 {
      const char *dsoname = "[unknown]";
 
-     if (map && map->dso) {
-             if (symbol_conf.show_kernel_path && map->dso->long_name)
-                     dsoname = map->dso->long_name;
+     if (map && map__dso(map)) {
+             if (symbol_conf.show_kernel_path && map__dso(map)->long_name)
+                     dsoname = map__dso(map)->long_name;
              else
-                     dsoname = map->dso->name;
+                     dsoname = map__dso(map)->name;
      }
 
      return dsoname;
@@ -527,7 +527,7 @@ static unsigned long get_offset(struct symbol *sym, struct addr_location *al)
      if (al->addr < sym->end)
              offset = al->addr - sym->start;
      else
-             offset = al->addr - al->map->start - sym->start;
+             offset = al->addr - map__start(al->map) - sym->start;
 
      return offset;
 }
@@ -741,7 +741,7 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 {
      if (al->map) {
              pydict_set_item_string_decref(dict, dso_field,
-                     _PyUnicode_FromString(al->map->dso->name));
+                     _PyUnicode_FromString(map__dso(al->map)->name));
      }
      if (al->sym) {
              pydict_set_item_string_decref(dict, sym_field,
tools/perf/util/sort.c +23 -23
index 25686d67ee6f..6d19bbcd30df 100644
@@ -173,8 +173,8 @@ struct sort_entry sort_comm = {
 
 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
 {
-     struct dso *dso_l = map_l ? map_l->dso : NULL;
-     struct dso *dso_r = map_r ? map_r->dso : NULL;
+     struct dso *dso_l = map_l ? map__dso(map_l) : NULL;
+     struct dso *dso_r = map_r ? map__dso(map_r) : NULL;
      const char *dso_name_l, *dso_name_r;
 
      if (!dso_l || !dso_r)
@@ -200,9 +200,9 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
                                   size_t size, unsigned int width)
 {
-     if (map && map->dso) {
-             const char *dso_name = verbose > 0 ? map->dso->long_name :
-                     map->dso->short_name;
+     if (map && map__dso(map)) {
+             const char *dso_name = verbose > 0 ? map__dso(map)->long_name :
+                     map__dso(map)->short_name;
              return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
      }
 
@@ -222,7 +222,7 @@ static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *a
      if (type != HIST_FILTER__DSO)
              return -1;
 
-     return dso && (!he->ms.map || he->ms.map->dso != dso);
+     return dso && (!he->ms.map || map__dso(he->ms.map) != dso);
 }
 
 struct sort_entry sort_dso = {
@@ -302,12 +302,12 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
      size_t ret = 0;
 
      if (verbose > 0) {
-             char o = map ? dso__symtab_origin(map->dso) : '!';
+             char o = map ? dso__symtab_origin(map__dso(map)) : '!';
              u64 rip = ip;
 
-             if (map && map->dso && map->dso->kernel
-                 && map->dso->adjust_symbols)
-                     rip = map->unmap_ip(map, ip);
+             if (map && map__dso(map) && map__dso(map)->kernel
+                 && map__dso(map)->adjust_symbols)
+                     rip = map__unmap_ip(map, ip);
 
              ret += repsep_snprintf(bf, size, "%-#*llx %c ",
                                     BITS_PER_LONG / 4 + 2, rip, o);
@@ -318,7 +318,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
              if (sym->type == STT_OBJECT) {
                      ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
                      ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
-                                     ip - map->unmap_ip(map, sym->start));
+                                     ip - map__unmap_ip(map, sym->start));
              } else {
                      ret += repsep_snprintf(bf + ret, size - ret, "%.*s",
                                             width - ret,
@@ -517,7 +517,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)
      if (!map)
              return no_srcfile;
 
-     sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
+     sf = __get_srcline(map__dso(map), map__rip_2objdump(map, e->ip),
                       e->ms.sym, false, true, true, e->ip);
      if (!strcmp(sf, SRCLINE_UNKNOWN))
              return no_srcfile;
@@ -838,7 +838,7 @@ static int hist_entry__dso_from_filter(struct hist_entry *he, int type,
              return -1;
 
      return dso && (!he->branch_info || !he->branch_info->from.ms.map ||
-                    he->branch_info->from.ms.map->dso != dso);
+             map__dso(he->branch_info->from.ms.map) != dso);
 }
 
 static int64_t
@@ -870,7 +870,7 @@ static int hist_entry__dso_to_filter(struct hist_entry *he, int type,
              return -1;
 
      return dso && (!he->branch_info || !he->branch_info->to.ms.map ||
-                    he->branch_info->to.ms.map->dso != dso);
+             map__dso(he->branch_info->to.ms.map) != dso);
 }
 
 static int64_t
@@ -1259,7 +1259,7 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
      if (!l_map) return -1;
      if (!r_map) return 1;
 
-     rc = dso__cmp_id(l_map->dso, r_map->dso);
+     rc = dso__cmp_id(map__dso(l_map), map__dso(r_map));
      if (rc)
              return rc;
      /*
@@ -1271,9 +1271,9 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
       */
 
      if ((left->cpumode != PERF_RECORD_MISC_KERNEL) &&
-         (!(l_map->flags & MAP_SHARED)) &&
-         !l_map->dso->id.maj && !l_map->dso->id.min &&
-         !l_map->dso->id.ino && !l_map->dso->id.ino_generation) {
+         (!(map__flags(l_map) & MAP_SHARED)) &&
+         !map__dso(l_map)->id.maj && !map__dso(l_map)->id.min &&
+         !map__dso(l_map)->id.ino && !map__dso(l_map)->id.ino_generation) {
              /* userspace anonymous */
 
              if (left->thread->pid_ > right->thread->pid_) return -1;
@@ -1307,10 +1307,10 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,
 
              /* print [s] for shared data mmaps */
              if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
-                  map && !(map->prot & PROT_EXEC) &&
-                 (map->flags & MAP_SHARED) &&
-                 (map->dso->id.maj || map->dso->id.min ||
-                  map->dso->id.ino || map->dso->id.ino_generation))
+                 map && !(map__prot(map) & PROT_EXEC) &&
+                 (map__flags(map) & MAP_SHARED) &&
+                 (map__dso(map)->id.maj || map__dso(map)->id.min ||
+                  map__dso(map)->id.ino || map__dso(map)->id.ino_generation))
                      level = 's';
              else if (!map)
                      level = 'X';
@@ -1806,7 +1806,7 @@ sort__dso_size_cmp(struct hist_entry *left, struct hist_entry *right)
 static int _hist_entry__dso_size_snprintf(struct map *map, char *bf,
                                        size_t bf_size, unsigned int width)
 {
-     if (map && map->dso)
+     if (map && map__dso(map))
              return repsep_snprintf(bf, bf_size, "%*d", width,
                                     map__size(map));
 
tools/perf/util/symbol-elf.c +19 -20
index 3ca9a0968345..056405d3d655 100644
@@ -970,7 +970,7 @@ void __weak arch__sym_update(struct symbol *s __maybe_unused,
 static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
                                    GElf_Sym *sym, GElf_Shdr *shdr,
                                    struct maps *kmaps, struct kmap *kmap,
-                                   struct dso **curr_dsop, struct map **curr_mapp,
+                                   struct dso **curr_dsop,
                                    const char *section_name,
                                    bool adjust_kernel_syms, bool kmodule, bool *remap_kernel)
 {
@@ -994,18 +994,18 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
              if (*remap_kernel && dso->kernel && !kmodule) {
                      *remap_kernel = false;
                      map->start = shdr->sh_addr + ref_reloc(kmap);
-                     map->end = map->start + shdr->sh_size;
+                     map->end = map__start(map) + shdr->sh_size;
                      map->pgoff = shdr->sh_offset;
-                     map->map_ip = map__map_ip;
-                     map->unmap_ip = map__unmap_ip;
+                     map->map_ip = map__dso_map_ip;
+                     map->unmap_ip = map__dso_unmap_ip;
                      /* Ensure maps are correctly ordered */
                      if (kmaps) {
                              int err;
+                             struct map *updated = map__get(map);
 
-                             map__get(map);
                              maps__remove(kmaps, map);
-                             err = maps__insert(kmaps, map);
-                             map__put(map);
+                             err = maps__insert(kmaps, updated);
+                             map__put(updated);
                              if (err)
                                      return err;
                      }
@@ -1021,7 +1021,6 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
                      map->pgoff = shdr->sh_offset;
              }
 
-             *curr_mapp = map;
              *curr_dsop = dso;
              return 0;
      }
@@ -1036,7 +1035,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
              u64 start = sym->st_value;
 
              if (kmodule)
-                     start += map->start + shdr->sh_offset;
+                     start += map__start(map) + shdr->sh_offset;
 
              curr_dso = dso__new(dso_name);
              if (curr_dso == NULL)
@@ -1054,10 +1053,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 
              if (adjust_kernel_syms) {
                      curr_map->start  = shdr->sh_addr + ref_reloc(kmap);
-                     curr_map->end    = curr_map->start + shdr->sh_size;
-                     curr_map->pgoff  = shdr->sh_offset;
+                     curr_map->end   = map__start(curr_map) + shdr->sh_size;
+                     curr_map->pgoff = shdr->sh_offset;
              } else {
-                     curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+                     curr_map->map_ip = map__identity_ip;
+                     curr_map->unmap_ip = map__identity_ip;
              }
              curr_dso->symtab_type = dso->symtab_type;
              if (maps__insert(kmaps, curr_map))
@@ -1068,13 +1068,11 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
               * *curr_map->dso.
               */
              dsos__add(&maps__machine(kmaps)->dsos, curr_dso);
-             /* kmaps already got it */
-             map__put(curr_map);
              dso__set_loaded(curr_dso);
-             *curr_mapp = curr_map;
              *curr_dsop = curr_dso;
+             map__put(curr_map);
      } else
-             *curr_dsop = curr_map->dso;
+             *curr_dsop = map__dso(curr_map);
 
      return 0;
 }
@@ -1085,7 +1083,6 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 {
      struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
      struct maps *kmaps = kmap ? map__kmaps(map) : NULL;
-     struct map *curr_map = map;
      struct dso *curr_dso = dso;
      Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym;
      uint32_t nr_syms;
@@ -1175,7 +1172,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
       * attempted to prelink vdso to its virtual address.
       */
      if (dso__is_vdso(dso))
-             map->reloc = map->start - dso->text_offset;
+             map->reloc = map__start(map) - dso->text_offset;
 
      dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
      /*
@@ -1262,8 +1259,10 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
                      --sym.st_value;
 
              if (dso->kernel) {
-                     if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map,
-                                                    section_name, adjust_kernel_syms, kmodule, &remap_kernel))
+                     if (dso__process_kernel_symbol(dso, map, &sym, &shdr,
+                                                    kmaps, kmap, &curr_dso,
+                                                    section_name, adjust_kernel_syms,
+                                                    kmodule, &remap_kernel))
                              goto out_elf_end;
              } else if ((used_opd && runtime_ss->adjust_symbols) ||
                         (!used_opd && syms_ss->adjust_symbols)) {
tools/perf/util/symbol.c +51 -45
index 9b51e669a722..6289b3028b91 100644
@@ -252,8 +252,8 @@ void maps__fixup_end(struct maps *maps)
      down_write(maps__lock(maps));
 
      maps__for_each_entry(maps, curr) {
-             if (prev != NULL && !prev->map->end)
-                     prev->map->end = curr->map->start;
+             if (prev != NULL && !map__end(prev->map))
+                     prev->map->end = map__start(curr->map);
 
              prev = curr;
      }
@@ -262,7 +262,7 @@ void maps__fixup_end(struct maps *maps)
       * We still haven't the actual symbols, so guess the
       * last map final address.
       */
-     if (curr && !curr->map->end)
+     if (curr && !map__end(curr->map))
              curr->map->end = ~0ULL;
 
      up_write(maps__lock(maps));
@@ -778,12 +778,12 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
                      continue;
              }
 
-             pos->start -= curr_map->start - curr_map->pgoff;
-             if (pos->end > curr_map->end)
-                     pos->end = curr_map->end;
+             pos->start -= map__start(curr_map) - map__pgoff(curr_map);
+             if (pos->end > map__end(curr_map))
+                     pos->end = map__end(curr_map);
              if (pos->end)
-                     pos->end -= curr_map->start - curr_map->pgoff;
-             symbols__insert(&curr_map->dso->symbols, pos);
+                     pos->end -= map__start(curr_map) - map__pgoff(curr_map);
+             symbols__insert(&map__dso(curr_map)->symbols, pos);
              ++count;
      }
 
@@ -830,7 +830,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 
                      *module++ = '\0';
 
-                     if (strcmp(curr_map->dso->short_name, module)) {
+                     if (strcmp(map__dso(curr_map)->short_name, module)) {
                              if (curr_map != initial_map &&
                                  dso->kernel == DSO_SPACE__KERNEL_GUEST &&
                                  machine__is_default_guest(machine)) {
@@ -841,7 +841,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                                       * symbols are in its kmap. Mark it as
                                       * loaded.
                                       */
-                                     dso__set_loaded(curr_map->dso);
+                                     dso__set_loaded(map__dso(curr_map));
                              }
 
                              curr_map = maps__find_by_name(kmaps, module);
@@ -854,7 +854,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                                      goto discard_symbol;
                              }
 
-                             if (curr_map->dso->loaded &&
+                             if (map__dso(curr_map)->loaded &&
                                  !machine__is_default_guest(machine))
                                      goto discard_symbol;
                      }
@@ -862,8 +862,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                       * So that we look just like we get from .ko files,
                       * i.e. not prelinked, relative to initial_map->start.
                       */
-                     pos->start = curr_map->map_ip(curr_map, pos->start);
-                     pos->end   = curr_map->map_ip(curr_map, pos->end);
+                     pos->start = map__map_ip(curr_map, pos->start);
+                     pos->end   = map__map_ip(curr_map, pos->end);
              } else if (x86_64 && is_entry_trampoline(pos->name)) {
                      /*
                       * These symbols are not needed anymore since the
@@ -910,7 +910,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
                              return -1;
                      }
 
-                     curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+                     curr_map->map_ip = map__identity_ip;
+                     curr_map->unmap_ip = map__identity_ip;
                      if (maps__insert(kmaps, curr_map)) {
                              dso__put(ndso);
                              return -1;
@@ -924,7 +925,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 add_symbol:
              if (curr_map != initial_map) {
                      rb_erase_cached(&pos->rb_node, root);
-                     symbols__insert(&curr_map->dso->symbols, pos);
+                     symbols__insert(&map__dso(curr_map)->symbols, pos);
                      ++moved;
              } else
                      ++count;
@@ -938,7 +939,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
      if (curr_map != initial_map &&
          dso->kernel == DSO_SPACE__KERNEL_GUEST &&
          machine__is_default_guest(maps__machine(kmaps))) {
-             dso__set_loaded(curr_map->dso);
+             dso__set_loaded(map__dso(curr_map));
      }
 
      return count + moved;
@@ -1118,8 +1119,8 @@ static int do_validate_kcore_modules(const char *filename, struct maps *kmaps)
              }
 
              /* Module must be in memory at the same address */
-             mi = find_module(old_map->dso->short_name, &modules);
-             if (!mi || mi->start != old_map->start) {
+             mi = find_module(map__dso(old_map)->short_name, &modules);
+             if (!mi || mi->start != map__start(old_map)) {
                      err = -EINVAL;
                      goto out;
              }
@@ -1214,7 +1215,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
              return -ENOMEM;
      }
 
-     list_node->map->end = list_node->map->start + len;
+     list_node->map->end = map__start(list_node->map) + len;
      list_node->map->pgoff = pgoff;
 
      list_add(&list_node->node, &md->maps);
@@ -1236,21 +1237,21 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
              struct map *old_map = rb_node->map;
 
              /* no overload with this one */
-             if (new_map->end < old_map->start ||
-                 new_map->start >= old_map->end)
+             if (map__end(new_map) < map__start(old_map) ||
+                 map__start(new_map) >= map__end(old_map))
                      continue;
 
-             if (new_map->start < old_map->start) {
+             if (map__start(new_map) < map__start(old_map)) {
                      /*
                       * |new......
                       *       |old....
                       */
-                     if (new_map->end < old_map->end) {
+                     if (map__end(new_map) < map__end(old_map)) {
                              /*
                               * |new......|     -> |new..|
                               *       |old....| ->       |old....|
                               */
-                             new_map->end = old_map->start;
+                             new_map->end = map__start(old_map);
                      } else {
                              /*
                               * |new.............| -> |new..|       |new..|
@@ -1271,17 +1272,18 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
                                      goto out;
                              }
 
-                             m->map->end = old_map->start;
+                             m->map->end = map__start(old_map);
                              list_add_tail(&m->node, &merged);
-                             new_map->pgoff += old_map->end - new_map->start;
-                             new_map->start = old_map->end;
+                             new_map->pgoff +=
+                                     map__end(old_map) - map__start(new_map);
+                             new_map->start = map__end(old_map);
                      }
              } else {
                      /*
                       *      |new......
                       * |old....
                       */
-                     if (new_map->end < old_map->end) {
+                     if (map__end(new_map) < map__end(old_map)) {
                              /*
                               *      |new..|   -> x
                               * |old.........| -> |old.........|
@@ -1294,8 +1296,9 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
                               *      |new......| ->         |new...|
                               * |old....|        -> |old....|
                               */
-                             new_map->pgoff += old_map->end - new_map->start;
-                             new_map->start = old_map->end;
+                             new_map->pgoff +=
+                                     map__end(old_map) - map__start(new_map);
+                             new_map->start = map__end(old_map);
                      }
              }
      }
@@ -1361,7 +1364,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
      }
 
      /* Read new maps into temporary lists */
-     err = file__read_maps(fd, map->prot & PROT_EXEC, kcore_mapfn, &md,
+     err = file__read_maps(fd, map__prot(map) & PROT_EXEC, kcore_mapfn, &md,
                            &is_64_bit);
      if (err)
              goto out_err;
@@ -1391,7 +1394,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
              struct map_list_node *new_node;
 
              list_for_each_entry(new_node, &md.maps, node) {
-                     if (stext >= new_node->map->start && stext < new_node->map->end) {
+                     if (stext >= map__start(new_node->map) &&
+                         stext < map__end(new_node->map)) {
                              replacement_map = new_node->map;
                              break;
                      }
@@ -1408,16 +1412,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
              new_node = list_entry(md.maps.next, struct map_list_node, node);
              list_del_init(&new_node->node);
              if (new_node->map == replacement_map) {
-                     map->start      = new_node->map->start;
-                     map->end        = new_node->map->end;
-                     map->pgoff      = new_node->map->pgoff;
-                     map->map_ip     = new_node->map->map_ip;
-                     map->unmap_ip   = new_node->map->unmap_ip;
+                     struct  map *updated;
+
+                     map->start = map__start(new_node->map);
+                     map->end   = map__end(new_node->map);
+                     map->pgoff = map__pgoff(new_node->map);
+                     map->map_ip = new_node->map->map_ip;
+                     map->unmap_ip = new_node->map->unmap_ip;
                      /* Ensure maps are correctly ordered */
-                     map__get(map);
+                     updated = map__get(map);
                      maps__remove(kmaps, map);
-                     err = maps__insert(kmaps, map);
-                     map__put(map);
+                     err = maps__insert(kmaps, updated);
+                     map__put(updated);
                      map__put(new_node->map);
                      if (err)
                              goto out_err;
@@ -1460,7 +1466,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
      close(fd);
 
-     if (map->prot & PROT_EXEC)
+     if (map__prot(map) & PROT_EXEC)
              pr_debug("Using %s for kernel object code\n", kcore_filename);
      else
              pr_debug("Using %s for kernel data\n", kcore_filename);
@@ -1995,13 +2001,13 @@ int dso__load(struct dso *dso, struct map *map)
 static int map__strcmp(const void *a, const void *b)
 {
      const struct map *ma = *(const struct map **)a, *mb = *(const struct map **)b;
-     return strcmp(ma->dso->short_name, mb->dso->short_name);
+     return strcmp(map__dso(ma)->short_name, map__dso(mb)->short_name);
 }
 
 static int map__strcmp_name(const void *name, const void *b)
 {
      const struct map *map = *(const struct map **)b;
-     return strcmp(name, map->dso->short_name);
+     return strcmp(name, map__dso(map)->short_name);
 }
 
 void __maps__sort_by_name(struct maps *maps)
@@ -2052,7 +2058,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
      down_read(maps__lock(maps));
 
      if (maps->last_search_by_name &&
-         strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
+         strcmp(map__dso(maps->last_search_by_name)->short_name, name) == 0) {
              map = maps->last_search_by_name;
              goto out_unlock;
      }
@@ -2068,7 +2074,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
      /* Fallback to traversing the rbtree... */
      maps__for_each_entry(maps, rb_node) {
              map = rb_node->map;
-             if (strcmp(map->dso->short_name, name) == 0) {
+             if (strcmp(map__dso(map)->short_name, name) == 0) {
                      maps->last_search_by_name = map;
                      goto out_unlock;
              }
tools/perf/util/symbol_fprintf.c +1 -1
index 2664fb65e47a..d9e5ad040b6a 100644
@@ -30,7 +30,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
                      if (al->addr < sym->end)
                              offset = al->addr - sym->start;
                      else
-                             offset = al->addr - al->map->start - sym->start;
+                             offset = al->addr - map__start(al->map) - sym->start;
                      length += fprintf(fp, "+0x%lx", offset);
              }
              return length;
tools/perf/util/synthetic-events.c +14 -14
index ed2d55d224aa..437fd57c2084 100644
@@ -668,33 +668,33 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
                      continue;
 
              if (symbol_conf.buildid_mmap2) {
-                     size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                     size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
                      event->mmap2.header.type = PERF_RECORD_MMAP2;
                      event->mmap2.header.size = (sizeof(event->mmap2) -
                                              (sizeof(event->mmap2.filename) - size));
                      memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
                      event->mmap2.header.size += machine->id_hdr_size;
-                     event->mmap2.start = map->start;
-                     event->mmap2.len   = map->end - map->start;
+                     event->mmap2.start = map__start(map);
+                     event->mmap2.len   = map__end(map) - map__start(map);
                      event->mmap2.pid   = machine->pid;
 
-                     memcpy(event->mmap2.filename, map->dso->long_name,
-                            map->dso->long_name_len + 1);
+                     memcpy(event->mmap2.filename, map__dso(map)->long_name,
+                            map__dso(map)->long_name_len + 1);
 
                      perf_record_mmap2__read_build_id(&event->mmap2, false);
              } else {
-                     size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                     size = PERF_ALIGN(map__dso(map)->long_name_len + 1, sizeof(u64));
                      event->mmap.header.type = PERF_RECORD_MMAP;
                      event->mmap.header.size = (sizeof(event->mmap) -
                                              (sizeof(event->mmap.filename) - size));
                      memset(event->mmap.filename + size, 0, machine->id_hdr_size);
                      event->mmap.header.size += machine->id_hdr_size;
-                     event->mmap.start = map->start;
-                     event->mmap.len   = map->end - map->start;
+                     event->mmap.start = map__start(map);
+                     event->mmap.len   = map__end(map) - map__start(map);
                      event->mmap.pid   = machine->pid;
 
-                     memcpy(event->mmap.filename, map->dso->long_name,
-                            map->dso->long_name_len + 1);
+                     memcpy(event->mmap.filename, map__dso(map)->long_name,
+                            map__dso(map)->long_name_len + 1);
              }
 
              if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
@@ -1112,8 +1112,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
              event->mmap2.header.size = (sizeof(event->mmap2) -
                              (sizeof(event->mmap2.filename) - size) + machine->id_hdr_size);
              event->mmap2.pgoff = kmap->ref_reloc_sym->addr;
-             event->mmap2.start = map->start;
-             event->mmap2.len   = map->end - event->mmap.start;
+             event->mmap2.start = map__start(map);
+             event->mmap2.len   = map__end(map) - event->mmap.start;
              event->mmap2.pid   = machine->pid;
 
              perf_record_mmap2__read_build_id(&event->mmap2, true);
@@ -1125,8 +1125,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
              event->mmap.header.size = (sizeof(event->mmap) -
                              (sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
              event->mmap.pgoff = kmap->ref_reloc_sym->addr;
-             event->mmap.start = map->start;
-             event->mmap.len   = map->end - event->mmap.start;
+             event->mmap.start = map__start(map);
+             event->mmap.len   = map__end(map) - event->mmap.start;
              event->mmap.pid   = machine->pid;
      }
 
tools/perf/util/thread.c +13 -13
index c2256777b813..6fbcc115cc6d 100644
@@ -434,23 +434,23 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa
 int thread__memcpy(struct thread *thread, struct machine *machine,
                 void *buf, u64 ip, int len, bool *is64bit)
 {
-       u8 cpumode = PERF_RECORD_MISC_USER;
-       struct addr_location al;
-       long offset;
+     u8 cpumode = PERF_RECORD_MISC_USER;
+     struct addr_location al;
+     long offset;
 
-       if (machine__kernel_ip(machine, ip))
-               cpumode = PERF_RECORD_MISC_KERNEL;
+     if (machine__kernel_ip(machine, ip))
+             cpumode = PERF_RECORD_MISC_KERNEL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
-        al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
-        map__load(al.map) < 0)
-               return -1;
+     if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map) ||
+             map__dso(al.map)->data.status == DSO_DATA_STATUS_ERROR ||
+             map__load(al.map) < 0)
+             return -1;
 
-       offset = al.map->map_ip(al.map, ip);
-       if (is64bit)
-               *is64bit = al.map->dso->is_64_bit;
+     offset = map__map_ip(al.map, ip);
+     if (is64bit)
+             *is64bit = map__dso(al.map)->is_64_bit;
 
-       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+     return dso__data_read_offset(map__dso(al.map), machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
tools/perf/util/unwind-libunwind-local.c +17 -17
index 7e6c59811292..841ac84a93ab 100644
@@ -381,20 +381,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
      int ret = -EINVAL;
 
      map = find_map(ip, ui);
-     if (!map || !map->dso)
+     if (!map || !map__dso(map))
              return -EINVAL;
 
-     pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
+     pr_debug("unwind: %s dso %s\n", __func__, map__dso(map)->name);
 
      /* Check the .eh_frame section for unwinding info */
-     if (!read_unwind_spec_eh_frame(map->dso, ui->machine,
+     if (!read_unwind_spec_eh_frame(map__dso(map), ui->machine,
                                     &table_data, &segbase, &fde_count)) {
              memset(&di, 0, sizeof(di));
              di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
-             di.start_ip = map->start;
-             di.end_ip   = map->end;
-             di.u.rti.segbase    = map->start + segbase - map->pgoff;
-             di.u.rti.table_data = map->start + table_data - map->pgoff;
+             di.start_ip = map__start(map);
+             di.end_ip   = map__end(map);
+             di.u.rti.segbase    = map__start(map) + segbase - map__pgoff(map);
+             di.u.rti.table_data = map__start(map) + table_data - map__pgoff(map);
              di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
                                    / sizeof(unw_word_t);
              ret = dwarf_search_unwind_table(as, ip, &di, pi,
@@ -404,20 +404,20 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 #ifndef NO_LIBUNWIND_DEBUG_FRAME
      /* Check the .debug_frame section for unwinding info */
      if (ret < 0 &&
-         !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
-             int fd = dso__data_get_fd(map->dso, ui->machine);
-             int is_exec = elf_is_exec(fd, map->dso->name);
-             unw_word_t base = is_exec ? 0 : map->start;
+         !read_unwind_spec_debug_frame(map__dso(map), ui->machine, &segbase)) {
+             int fd = dso__data_get_fd(map__dso(map), ui->machine);
+             int is_exec = elf_is_exec(fd, map__dso(map)->name);
+             unw_word_t base = is_exec ? 0 : map__start(map);
              const char *symfile;
 
              if (fd >= 0)
-                     dso__data_put_fd(map->dso);
+                     dso__data_put_fd(map__dso(map));
 
-             symfile = map->dso->symsrc_filename ?: map->dso->name;
+             symfile = map__dso(map)->symsrc_filename ?: map__dso(map)->name;
 
              memset(&di, 0, sizeof(di));
              if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
-                                        map->start, map->end))
+                                        map__start(map), map__end(map)))
                      return dwarf_search_unwind_table(as, ip, &di, pi,
                                                       need_unwind_info, arg);
      }
@@ -473,10 +473,10 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
              return -1;
      }
 
-     if (!map->dso)
+     if (!map__dso(map))
              return -1;
 
-     size = dso__data_read_addr(map->dso, map, ui->machine,
+     size = dso__data_read_addr(map__dso(map), map, ui->machine,
                                 addr, (u8 *) data, sizeof(*data));
 
      return !(size == sizeof(*data));
@@ -583,7 +583,7 @@ static int entry(u64 ip, struct thread *thread,
      pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
               al.sym ? al.sym->name : "''",
               ip,
-              al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
+              al.map ? map__map_ip(al.map, ip) : (u64) 0);
 
      return cb(&e, arg);
 }
tools/perf/util/unwind-libunwind.c +2 -2
index 7b797ffadd19..cece1ee89031 100644
@@ -30,7 +30,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 
      if (maps__addr_space(maps)) {
              pr_debug("unwind: thread map already set, dso=%s\n",
-                      map->dso->name);
+                      map__dso(map)->name);
              if (initialized)
                      *initialized = true;
              return 0;
@@ -41,7 +41,7 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
      if (!machine->env || !machine->env->arch)
              goto out_register;
 
-     dso_type = dso__type(map->dso, machine);
+     dso_type = dso__type(map__dso(map), machine);
      if (dso_type == DSO__TYPE_UNKNOWN)
              return 0;
 
tools/perf/util/vdso.c +1 -2
index 835c39efb80d..ec777ee11493 100644
@@ -147,7 +147,7 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
      struct map_rb_node *rb_node;
 
      maps__for_each_entry(thread->maps, rb_node) {
-             struct dso *dso = rb_node->map->dso;
+             struct dso *dso = map__dso(rb_node->map);
 
              if (!dso || dso->long_name[0] != '/')
                      continue;
--
Quoted 1 line

2.35.1.265.g69c8d7142f-goog

--

- Arnaldo

Signature · 1 line
- Arnaldo
author reviewer
#47 lore raw

PATCH v3 16/22 perf test: Add extra diagnostics to maps test

In reply to Ian Rogers

Dump the resultant and comparison maps on failure.

---
 tools/perf/tests/maps.c | 51 +++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 15 deletions(-)
tools/perf/tests/maps.c +36 -15
index a58274598587..38c1ec0074d1 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <inttypes.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include "tests.h"
@@ -17,22 +18,42 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma
 {
 	struct map_rb_node *rb_node;
 	unsigned int i = 0;
-
-	maps__for_each_entry(maps, rb_node) {
-		struct map *map = rb_node->map;
-
-		if (i > 0)
-			TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));
-
-		TEST_ASSERT_VAL("wrong map start",  map->start == merged[i].start);
-		TEST_ASSERT_VAL("wrong map end",    map->end == merged[i].end);
-		TEST_ASSERT_VAL("wrong map name",  !strcmp(map->dso->name, merged[i].name));
-		TEST_ASSERT_VAL("wrong map refcnt", refcount_read(&map->refcnt) == 1);
-
-		i++;
+	bool failed = false;
+
+	if (maps__nr_maps(maps) != size) {
+		pr_debug("Expected %d maps, got %d", size, maps__nr_maps(maps));
+		failed = true;
+	} else {
+		maps__for_each_entry(maps, rb_node) {
+			struct map *map = rb_node->map;
+
+			if (map__start(map) != merged[i].start ||
+			    map__end(map) != merged[i].end ||
+			    strcmp(map__dso(map)->name, merged[i].name) ||
+			    refcount_read(&map->refcnt) != 1) {
+				failed = true;
+			}
+			i++;
+		}
 	}
-
-	return TEST_OK;
+	if (failed) {
+		pr_debug("Expected:\n");
+		for (i = 0; i < size; i++) {
+			pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: 1\n",
+				merged[i].start, merged[i].end, merged[i].name);
+		}
+		pr_debug("Got:\n");
+		maps__for_each_entry(maps, rb_node) {
+			struct map *map = rb_node->map;
+
+			pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n",
+				map__start(map),
+				map__end(map),
+				map__dso(map)->name,
+				refcount_read(&map->refcnt));
+		}
+	}
+	return failed ? TEST_FAIL : TEST_OK;
 }
 
 static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
Signature · 1 line
2.35.1.265.g69c8d7142f-goog
author reviewer
#48 lore raw

PATCH v3 17/22 perf map: Changes to reference counting

In reply to Ian Rogers

When a pointer to a map exists do a get, when that pointer is overwritten or freed, put the map. This avoids issues with gets and puts being inconsistently used causing, use after puts, etc. Reference count checking and address sanitizer were used to identify issues.

---
 tools/perf/tests/hists_cumulate.c     | 14 ++++-
 tools/perf/tests/hists_filter.c       | 14 ++++-
 tools/perf/tests/hists_link.c         | 18 +++++-
 tools/perf/tests/hists_output.c       | 12 +++-
 tools/perf/tests/mmap-thread-lookup.c |  3 +-
 tools/perf/util/callchain.c           |  9 +--
 tools/perf/util/event.c               |  8 ++-
 tools/perf/util/hist.c                | 10 ++--
 tools/perf/util/machine.c             | 80 ++++++++++++++++-----------
 9 files changed, 118 insertions(+), 50 deletions(-)
tools/perf/tests/hists_cumulate.c +12 -2
index 17f4fcd6bdce..28f5eb41eed9 100644
@@ -112,6 +112,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
 		}
 
 		fake_samples[i].thread = al.thread;
+		map__put(fake_samples[i].map);
 		fake_samples[i].map = al.map;
 		fake_samples[i].sym = al.sym;
 	}
@@ -147,15 +148,23 @@ static void del_hist_entries(struct hists *hists)
 	}
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 #define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl)  (cl->ms.map->dso->short_name)
+#define CDSO(cl)  (map__dso(cl->ms.map)->short_name)
 #define CSYM(cl)  (cl->ms.sym->name)
 
 struct result {
@@ -733,6 +742,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
 	/* tear down everything */
 	evlist__delete(evlist);
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_filter.c +12 -2
index 08cbeb9e39ae..bcd46244182a 100644
@@ -89,6 +89,7 @@ static int add_hist_entries(struct evlist *evlist,
 			}
 
 			fake_samples[i].thread = al.thread;
+			map__put(fake_samples[i].map);
 			fake_samples[i].map = al.map;
 			fake_samples[i].sym = al.sym;
 		}
@@ -101,6 +102,14 @@ static int add_hist_entries(struct evlist *evlist,
 	return TEST_FAIL;
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 static int test__hists_filter(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
 	int err = TEST_FAIL;
@@ -194,7 +203,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 		hists__filter_by_thread(hists);
 
 		/* now applying dso filter for 'kernel' */
-		hists->dso_filter = fake_samples[0].map->dso;
+		hists->dso_filter = map__dso(fake_samples[0].map);
 		hists__filter_by_dso(hists);
 
 		if (verbose > 2) {
@@ -288,7 +297,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 
 		/* now applying all filters at once. */
 		hists->thread_filter = fake_samples[1].thread;
-		hists->dso_filter = fake_samples[1].map->dso;
+		hists->dso_filter = map__dso(fake_samples[1].map);
 		hists__filter_by_thread(hists);
 		hists__filter_by_dso(hists);
 
@@ -322,6 +331,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 	evlist__delete(evlist);
 	reset_output_field();
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_link.c +17 -1
index c575e13a850d..060e8731feff 100644
@@ -6,6 +6,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include "machine.h"
+#include "map.h"
 #include "parse-events.h"
 #include "hists_common.h"
 #include "util/mmap.h"
@@ -94,6 +95,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
 			}
 
 			fake_common_samples[k].thread = al.thread;
+			map__put(fake_common_samples[k].map);
 			fake_common_samples[k].map = al.map;
 			fake_common_samples[k].sym = al.sym;
 		}
@@ -126,11 +128,24 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
 	return -1;
 }
 
+static void put_fake_samples(void)
+{
+	size_t i, j;
+
+	for (i = 0; i < ARRAY_SIZE(fake_common_samples); i++)
+		map__put(fake_common_samples[i].map);
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
+		for (j = 0; j < ARRAY_SIZE(fake_samples[0]); j++)
+			map__put(fake_samples[i][j].map);
+	}
+}
+
 static int find_sample(struct sample *samples, size_t nr_samples,
 		       struct thread *t, struct map *m, struct symbol *s)
 {
 	while (nr_samples--) {
-		if (samples->thread == t && samples->map == m &&
+		if (samples->thread == t &&
+		    samples->map == m &&
 		    samples->sym == s)
 			return 1;
 		samples++;
@@ -336,6 +351,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
 	evlist__delete(evlist);
 	reset_output_field();
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_output.c +11 -1
index 0bde4a768c15..4af6916491e5 100644
@@ -78,6 +78,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
 		}
 
 		fake_samples[i].thread = al.thread;
+		map__put(fake_samples[i].map);
 		fake_samples[i].map = al.map;
 		fake_samples[i].sym = al.sym;
 	}
@@ -113,10 +114,18 @@ static void del_hist_entries(struct hists *hists)
 	}
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
@@ -620,6 +629,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
 	/* tear down everything */
 	evlist__delete(evlist);
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/mmap-thread-lookup.c +2 -1
index a4301fc7b770..898eda55b7a8 100644
@@ -202,7 +202,8 @@ static int mmap_events(synth_cb synth)
 			break;
 		}
 
-		pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
+		pr_debug("map %p, addr %" PRIx64 "\n", al.map, map__start(al.map));
+		map__put(al.map);
 	}
 
 	machine__delete_threads(machine);
tools/perf/util/callchain.c +5 -4
index a8cfd31a3ff0..ae65b7bc9ab7 100644
@@ -583,7 +583,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
 		}
 		call->ip = cursor_node->ip;
 		call->ms = cursor_node->ms;
-		map__get(call->ms.map);
+		call->ms.map = map__get(call->ms.map);
 		call->srcline = cursor_node->srcline;
 
 		if (cursor_node->branch) {
@@ -1061,7 +1061,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
 	node->ip = ip;
 	map__zput(node->ms.map);
 	node->ms = *ms;
-	map__get(node->ms.map);
+	node->ms.map = map__get(node->ms.map);
 	node->branch = branch;
 	node->nr_loop_iter = nr_loop_iter;
 	node->iter_cycles = iter_cycles;
@@ -1109,7 +1109,8 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
 	struct machine *machine = maps__machine(node->ms.maps);
 
 	al->maps = node->ms.maps;
-	al->map = node->ms.map;
+	map__put(al->map);
+	al->map = map__get(node->ms.map);
 	al->sym = node->ms.sym;
 	al->srcline = node->srcline;
 	al->addr = node->ip;
@@ -1530,7 +1531,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
 				goto out;
 			*new = *chain;
 			new->has_children = false;
-			map__get(new->ms.map);
+			new->ms.map = map__get(new->ms.map);
 			list_add_tail(&new->list, &head);
 		}
 		parent = parent->parent;
tools/perf/util/event.c +6 -2
index 54a1d4df5f70..266318d5d006 100644
@@ -484,13 +484,14 @@ 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__kernel_maps(machine), tp->addr);
+		al.map = map__get(maps__find(machine__kernel_maps(machine), tp->addr));
 		if (al.map && map__load(al.map) >= 0) {
 			al.addr = map__map_ip(al.map, tp->addr);
 			al.sym = map__find_symbol(al.map, al.addr);
 			if (al.sym)
 				ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
 		}
+		map__put(al.map);
 	}
 	ret += fprintf(fp, " old len %u new len %u\n", tp->old_len, tp->new_len);
 	old = true;
@@ -581,6 +582,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 	al->filtered = 0;
 
 	if (machine == NULL) {
+		map__put(al->map);
 		al->map = NULL;
 		return NULL;
 	}
@@ -599,6 +601,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		al->level = 'u';
 	} else {
 		al->level = 'H';
+		map__put(al->map);
 		al->map = NULL;
 
 		if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
@@ -613,7 +616,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		return NULL;
 	}
 
-	al->map = maps__find(maps, al->addr);
+	al->map = map__get(maps__find(maps, al->addr));
 	if (al->map != NULL) {
 		/*
 		 * Kernel maps might be changed when loading symbols so loading
@@ -768,6 +771,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
  */
 void addr_location__put(struct addr_location *al)
 {
+	map__zput(al->map);
 	thread__zput(al->thread);
 }
 
tools/perf/util/hist.c +5 -5
index f19ac6eb4775..4dbb1dbf3679 100644
@@ -446,7 +446,7 @@ static int hist_entry__init(struct hist_entry *he,
 			memset(&he->stat, 0, sizeof(he->stat));
 	}
 
-	map__get(he->ms.map);
+	he->ms.map = map__get(he->ms.map);
 
 	if (he->branch_info) {
 		/*
@@ -461,13 +461,13 @@ static int hist_entry__init(struct hist_entry *he,
 		memcpy(he->branch_info, template->branch_info,
 		       sizeof(*he->branch_info));
 
-		map__get(he->branch_info->from.ms.map);
-		map__get(he->branch_info->to.ms.map);
+		he->branch_info->from.ms.map = map__get(he->branch_info->from.ms.map);
+		he->branch_info->to.ms.map = map__get(he->branch_info->to.ms.map);
 	}
 
 	if (he->mem_info) {
-		map__get(he->mem_info->iaddr.ms.map);
-		map__get(he->mem_info->daddr.ms.map);
+		he->mem_info->iaddr.ms.map = map__get(he->mem_info->iaddr.ms.map);
+		he->mem_info->daddr.ms.map = map__get(he->mem_info->daddr.ms.map);
 	}
 
 	if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
tools/perf/util/machine.c +48 -32

142 lines not on this page · raw message

Signature · 1 line
2.35.1.265.g69c8d7142f-goog
#49 lore raw

Re: [PATCH v3 17/22] perf map: Changes to reference counting

Hi Ian,

Quoted 4 lines · On Fri, 11 Feb 2022 02:34:10 -0800 Ian Rogers <[email protected]> wrote:

When a pointer to a map exists do a get, when that pointer is overwritten or freed, put the map. This avoids issues with gets and puts being inconsistently used causing, use after puts, etc. Reference count checking and address sanitizer were used to identify issues.

OK, and please add comments in the code what should be actually done so the others can understand it correctly, since this changes the map object handling model.

Previously;

  map__get(map);
  map_operations(map);
  map__put(map);

Now, we have to use the object returned from get() ops. This is more likely to the memdup()/free().

  new = map__get(map);
  map_operations(new);
  map__put(new);

To update the object in the other object (e.g. machine__update_kernel_mmap()) The original one must be put because it has the old copy.

Previous;

  map__get(parent_obj->map);
  update_operation(parent_obj->map);
  map__put(parent_obj->map;

Is now;

  orig = parent_obj->map;
  new = map__get(orig);
  update_operation(new);
  parent_obj->map = new;
  map__put(orig);

I think this change also should be documented with some concrete example patterns so that someone can program it correctly. :-)

(This is the reason why I asked you to introduce object-token instead
of modifying object pointer itself.)

Thank you,

Quoted 502 lines
---
 tools/perf/tests/hists_cumulate.c     | 14 ++++-
 tools/perf/tests/hists_filter.c       | 14 ++++-
 tools/perf/tests/hists_link.c         | 18 +++++-
 tools/perf/tests/hists_output.c       | 12 +++-
 tools/perf/tests/mmap-thread-lookup.c |  3 +-
 tools/perf/util/callchain.c           |  9 +--
 tools/perf/util/event.c               |  8 ++-
 tools/perf/util/hist.c                | 10 ++--
 tools/perf/util/machine.c             | 80 ++++++++++++++++-----------
 9 files changed, 118 insertions(+), 50 deletions(-)
tools/perf/tests/hists_cumulate.c +12 -2
index 17f4fcd6bdce..28f5eb41eed9 100644
@@ -112,6 +112,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
 		}
 
 		fake_samples[i].thread = al.thread;
+		map__put(fake_samples[i].map);
 		fake_samples[i].map = al.map;
 		fake_samples[i].sym = al.sym;
 	}
@@ -147,15 +148,23 @@ static void del_hist_entries(struct hists *hists)
 	}
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 #define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl)  (cl->ms.map->dso->short_name)
+#define CDSO(cl)  (map__dso(cl->ms.map)->short_name)
 #define CSYM(cl)  (cl->ms.sym->name)
 
 struct result {
@@ -733,6 +742,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
 	/* tear down everything */
 	evlist__delete(evlist);
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_filter.c +12 -2
index 08cbeb9e39ae..bcd46244182a 100644
@@ -89,6 +89,7 @@ static int add_hist_entries(struct evlist *evlist,
 			}
 
 			fake_samples[i].thread = al.thread;
+			map__put(fake_samples[i].map);
 			fake_samples[i].map = al.map;
 			fake_samples[i].sym = al.sym;
 		}
@@ -101,6 +102,14 @@ static int add_hist_entries(struct evlist *evlist,
 	return TEST_FAIL;
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 static int test__hists_filter(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
 	int err = TEST_FAIL;
@@ -194,7 +203,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 		hists__filter_by_thread(hists);
 
 		/* now applying dso filter for 'kernel' */
-		hists->dso_filter = fake_samples[0].map->dso;
+		hists->dso_filter = map__dso(fake_samples[0].map);
 		hists__filter_by_dso(hists);
 
 		if (verbose > 2) {
@@ -288,7 +297,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 
 		/* now applying all filters at once. */
 		hists->thread_filter = fake_samples[1].thread;
-		hists->dso_filter = fake_samples[1].map->dso;
+		hists->dso_filter = map__dso(fake_samples[1].map);
 		hists__filter_by_thread(hists);
 		hists__filter_by_dso(hists);
 
@@ -322,6 +331,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 	evlist__delete(evlist);
 	reset_output_field();
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_link.c +17 -1
index c575e13a850d..060e8731feff 100644
@@ -6,6 +6,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include "machine.h"
+#include "map.h"
 #include "parse-events.h"
 #include "hists_common.h"
 #include "util/mmap.h"
@@ -94,6 +95,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
 			}
 
 			fake_common_samples[k].thread = al.thread;
+			map__put(fake_common_samples[k].map);
 			fake_common_samples[k].map = al.map;
 			fake_common_samples[k].sym = al.sym;
 		}
@@ -126,11 +128,24 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
 	return -1;
 }
 
+static void put_fake_samples(void)
+{
+	size_t i, j;
+
+	for (i = 0; i < ARRAY_SIZE(fake_common_samples); i++)
+		map__put(fake_common_samples[i].map);
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
+		for (j = 0; j < ARRAY_SIZE(fake_samples[0]); j++)
+			map__put(fake_samples[i][j].map);
+	}
+}
+
 static int find_sample(struct sample *samples, size_t nr_samples,
 		       struct thread *t, struct map *m, struct symbol *s)
 {
 	while (nr_samples--) {
-		if (samples->thread == t && samples->map == m &&
+		if (samples->thread == t &&
+		    samples->map == m &&
 		    samples->sym == s)
 			return 1;
 		samples++;
@@ -336,6 +351,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
 	evlist__delete(evlist);
 	reset_output_field();
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/hists_output.c +11 -1
index 0bde4a768c15..4af6916491e5 100644
@@ -78,6 +78,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
 		}
 
 		fake_samples[i].thread = al.thread;
+		map__put(fake_samples[i].map);
 		fake_samples[i].map = al.map;
 		fake_samples[i].sym = al.sym;
 	}
@@ -113,10 +114,18 @@ static void del_hist_entries(struct hists *hists)
 	}
 }
 
+static void put_fake_samples(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+		map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
@@ -620,6 +629,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
 	/* tear down everything */
 	evlist__delete(evlist);
 	machines__exit(&machines);
+	put_fake_samples();
 
 	return err;
 }
tools/perf/tests/mmap-thread-lookup.c +2 -1
index a4301fc7b770..898eda55b7a8 100644
@@ -202,7 +202,8 @@ static int mmap_events(synth_cb synth)
 			break;
 		}
 
-		pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
+		pr_debug("map %p, addr %" PRIx64 "\n", al.map, map__start(al.map));
+		map__put(al.map);
 	}
 
 	machine__delete_threads(machine);
tools/perf/util/callchain.c +5 -4
index a8cfd31a3ff0..ae65b7bc9ab7 100644
@@ -583,7 +583,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
 		}
 		call->ip = cursor_node->ip;
 		call->ms = cursor_node->ms;
-		map__get(call->ms.map);
+		call->ms.map = map__get(call->ms.map);
 		call->srcline = cursor_node->srcline;
 
 		if (cursor_node->branch) {
@@ -1061,7 +1061,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
 	node->ip = ip;
 	map__zput(node->ms.map);
 	node->ms = *ms;
-	map__get(node->ms.map);
+	node->ms.map = map__get(node->ms.map);
 	node->branch = branch;
 	node->nr_loop_iter = nr_loop_iter;
 	node->iter_cycles = iter_cycles;
@@ -1109,7 +1109,8 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
 	struct machine *machine = maps__machine(node->ms.maps);
 
 	al->maps = node->ms.maps;
-	al->map = node->ms.map;
+	map__put(al->map);
+	al->map = map__get(node->ms.map);
 	al->sym = node->ms.sym;
 	al->srcline = node->srcline;
 	al->addr = node->ip;
@@ -1530,7 +1531,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
 				goto out;
 			*new = *chain;
 			new->has_children = false;
-			map__get(new->ms.map);
+			new->ms.map = map__get(new->ms.map);
 			list_add_tail(&new->list, &head);
 		}
 		parent = parent->parent;
tools/perf/util/event.c +6 -2
index 54a1d4df5f70..266318d5d006 100644
@@ -484,13 +484,14 @@ 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__kernel_maps(machine), tp->addr);
+		al.map = map__get(maps__find(machine__kernel_maps(machine), tp->addr));
 		if (al.map && map__load(al.map) >= 0) {
 			al.addr = map__map_ip(al.map, tp->addr);
 			al.sym = map__find_symbol(al.map, al.addr);
 			if (al.sym)
 				ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
 		}
+		map__put(al.map);
 	}
 	ret += fprintf(fp, " old len %u new len %u\n", tp->old_len, tp->new_len);
 	old = true;
@@ -581,6 +582,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 	al->filtered = 0;
 
 	if (machine == NULL) {
+		map__put(al->map);
 		al->map = NULL;
 		return NULL;
 	}
@@ -599,6 +601,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		al->level = 'u';
 	} else {
 		al->level = 'H';
+		map__put(al->map);
 		al->map = NULL;
 
 		if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
@@ -613,7 +616,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 		return NULL;
 	}
 
-	al->map = maps__find(maps, al->addr);
+	al->map = map__get(maps__find(maps, al->addr));
 	if (al->map != NULL) {
 		/*
 		 * Kernel maps might be changed when loading symbols so loading
@@ -768,6 +771,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
  */
 void addr_location__put(struct addr_location *al)
 {
+	map__zput(al->map);
 	thread__zput(al->thread);
 }
 
tools/perf/util/hist.c +5 -5
index f19ac6eb4775..4dbb1dbf3679 100644
@@ -446,7 +446,7 @@ static int hist_entry__init(struct hist_entry *he,
 			memset(&he->stat, 0, sizeof(he->stat));
 	}
 
-	map__get(he->ms.map);
+	he->ms.map = map__get(he->ms.map);
 
 	if (he->branch_info) {
 		/*
@@ -461,13 +461,13 @@ static int hist_entry__init(struct hist_entry *he,
 		memcpy(he->branch_info, template->branch_info,
 		       sizeof(*he->branch_info));
 
-		map__get(he->branch_info->from.ms.map);
-		map__get(he->branch_info->to.ms.map);
+		he->branch_info->from.ms.map = map__get(he->branch_info->from.ms.map);
+		he->branch_info->to.ms.map = map__get(he->branch_info->to.ms.map);
 	}
 
 	if (he->mem_info) {
-		map__get(he->mem_info->iaddr.ms.map);
-		map__get(he->mem_info->daddr.ms.map);
+		he->mem_info->iaddr.ms.map = map__get(he->mem_info->iaddr.ms.map);
+		he->mem_info->daddr.ms.map = map__get(he->mem_info->daddr.ms.map);
 	}
 
 	if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
tools/perf/util/machine.c +48 -32
index 940fb2a50dfd..49e4891e92b7 100644
@@ -783,33 +783,42 @@ static int machine__process_ksymbol_register(struct machine *machine,
 {
 	struct symbol *sym;
 	struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
+	bool put_map = false;
+	int err = 0;
 
 	if (!map) {
 		struct dso *dso = dso__new(event->ksymbol.name);
-		int err;
 
-		if (dso) {
-			dso->kernel = DSO_SPACE__KERNEL;
-			map = map__new2(0, dso);
-			dso__put(dso);
+		if (!dso) {
+			err = -ENOMEM;
+			goto out;
 		}
-
-		if (!dso || !map) {
-			return -ENOMEM;
+		dso->kernel = DSO_SPACE__KERNEL;
+		map = map__new2(0, dso);
+		dso__put(dso);
+		if (!map) {
+			err = -ENOMEM;
+			goto out;
 		}
-
+		/*
+		 * The inserted map has a get on it, we need to put to release
+		 * the reference count here, but do it after all accesses are
+		 * done.
+		 */
+		put_map = true;
 		if (event->ksymbol.ksym_type == PERF_RECORD_KSYMBOL_TYPE_OOL) {
-			map->dso->binary_type = DSO_BINARY_TYPE__OOL;
-			map->dso->data.file_size = event->ksymbol.len;
-			dso__set_loaded(map->dso);
+			map__dso(map)->binary_type = DSO_BINARY_TYPE__OOL;
+			map__dso(map)->data.file_size = event->ksymbol.len;
+			dso__set_loaded(map__dso(map));
 		}
 
 		map->start = event->ksymbol.addr;
-		map->end = map->start + event->ksymbol.len;
+		map->end = map__start(map) + event->ksymbol.len;
 		err = maps__insert(machine__kernel_maps(machine), map);
-		map__put(map);
-		if (err)
-			return err;
+		if (err) {
+			err = -ENOMEM;
+			goto out;
+		}
 
 		dso__set_loaded(dso);
 
@@ -819,13 +828,18 @@ static int machine__process_ksymbol_register(struct machine *machine,
 		}
 	}
 
-	sym = symbol__new(map->map_ip(map, map->start),
+	sym = symbol__new(map__map_ip(map, map__start(map)),
 			  event->ksymbol.len,
 			  0, 0, event->ksymbol.name);
-	if (!sym)
-		return -ENOMEM;
-	dso__insert_symbol(map->dso, sym);
-	return 0;
+	if (!sym) {
+		err = -ENOMEM;
+		goto out;
+	}
+	dso__insert_symbol(map__dso(map), sym);
+out:
+	if (put_map)
+		map__put(map);
+	return err;
 }
 
 static int machine__process_ksymbol_unregister(struct machine *machine,
@@ -925,14 +939,11 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
 		goto out;
 
 	err = maps__insert(machine__kernel_maps(machine), map);
-
-	/* Put the map here because maps__insert already got it */
-	map__put(map);
-
 	/* If maps__insert failed, return NULL. */
-	if (err)
+	if (err) {
+		map__put(map);
 		map = NULL;
-
+	}
 out:
 	/* put the dso here, corresponding to  machine__findnew_module_dso */
 	dso__put(dso);
@@ -1228,6 +1239,7 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 	/* In case of renewal the kernel map, destroy previous one */
 	machine__destroy_kernel_maps(machine);
 
+	map__put(machine->vmlinux_map);
 	machine->vmlinux_map = map__new2(0, kernel);
 	if (machine->vmlinux_map == NULL)
 		return -ENOMEM;
@@ -1513,6 +1525,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
 	map->end = start + size;
 
 	dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
+	map__put(map);
 	return 0;
 }
 
@@ -1558,16 +1571,18 @@ static void machine__set_kernel_mmap(struct machine *machine,
 static int machine__update_kernel_mmap(struct machine *machine,
 				     u64 start, u64 end)
 {
-	struct map *map = machine__kernel_map(machine);
+	struct map *orig, *updated;
 	int err;
 
-	map__get(map);
-	maps__remove(machine__kernel_maps(machine), map);
+	orig = machine->vmlinux_map;
+	updated = map__get(orig);
 
+	machine->vmlinux_map = updated;
 	machine__set_kernel_mmap(machine, start, end);
+	maps__remove(machine__kernel_maps(machine), orig);
+	err = maps__insert(machine__kernel_maps(machine), updated);
+	map__put(orig);
 
-	err = maps__insert(machine__kernel_maps(machine), map);
-	map__put(map);
 	return err;
 }
 
@@ -2246,6 +2261,7 @@ static int add_callchain_ip(struct thread *thread,
 	err = callchain_cursor_append(cursor, ip, &ms,
 				      branch, flags, nr_loop_iter,
 				      iter_cycles, branch_from, srcline);
+	map__put(al.map);
 	return err;
 }
 
Signature · 1 line
2.35.1.265.g69c8d7142f-goog
Signature · 1 line
Masami Hiramatsu <[email protected]>
author reviewer
#50 lore raw

Re: [PATCH v3 17/22] perf map: Changes to reference counting

Quoted 37 lines · Masami Hiramatsu

Hi Ian,

Quoted 4 lines · On Fri, 11 Feb 2022 02:34:10 -0800 Ian Rogers <[email protected]> wrote:

When a pointer to a map exists do a get, when that pointer is overwritten or freed, put the map. This avoids issues with gets and puts being inconsistently used causing, use after puts, etc. Reference count checking and address sanitizer were used to identify issues.

OK, and please add comments in the code what should be actually done so the others can understand it correctly, since this changes the map object handling model.

Previously;

  map__get(map);
  map_operations(map);
  map__put(map);

Now, we have to use the object returned from get() ops. This is more likely to the memdup()/free().

  new = map__get(map);
  map_operations(new);
  map__put(new);

To update the object in the other object (e.g. machine__update_kernel_mmap()) The original one must be put because it has the old copy.

Previous;

  map__get(parent_obj->map);
  update_operation(parent_obj->map);
  map__put(parent_obj->map;
Quoted 7 lines

Is now;

  orig = parent_obj->map;
  new = map__get(orig);
  update_operation(new);
  parent_obj->map = new;
  map__put(orig);

Hi Masami,

Thanks as always for the input! This is a top post and so I lack the context for what you are describing. The model should always be get, operation, put, but the map code does not follow this model. I suspect the map code at some point in time didn't have reference counts, someone added them for one use case and then didn't add gets and puts elsewhere. Because a crash is worse than a memory leak extra gets were added, or puts missed, and the code is pretty much spaghetti today. We now need to be able to pair gets with puts and hence the model that this change introduces. There are cases where the new code needs to distinguish between a reference that is put and a reference that will be kept alive and say returned, this is fiddly and adds extra state - this seems to be what you're describing. I don't see how having a concept of a token is clearing this matter up. We have one pointer that can't be used after a function has consumed it, we introduce another pointer via a get so that we can keep the value for the sake of future use. In C++ we'd have two smart pointers for this case.

Quoted 2 lines

I think this change also should be documented with some concrete example patterns so that someone can program it correctly. :-)

So the example change was the cpumap one (i.e. patch set v1). It is a literal patch set and so I'm not sure why it isn't a concrete example. In terms of motivation, the map code is about the worst thing that could try to be fixed and that's why I tackled it. It'd have been much easier to implement the approach in cpumap and ask someone else to do the map case :-) The problem I face is that in introducing the refactors and the approach, perf now crashes because of the technique working. That's why I've also had to fix the bugs in map the approach identifies - the code passes most of perf test enabled and with sanitizers. There are more issues. To be specific on one example, addr_location references a map but lacks any kind of init/exit protocol. The exit should put any map the addr_location has. There are 191 uses of addr_location that need to be looked at and a proper get/put, init/exit approach introduced. I've fixed the ones that are crashes and show stoppers. With this approach enabled we can catch more and avoid human error.

Thanks,
Ian

Quoted 511 lines

(This is the reason why I asked you to introduce object-token instead
of modifying object pointer itself.)

Thank you,

Quoted 500 lines
---
 tools/perf/tests/hists_cumulate.c     | 14 ++++-
 tools/perf/tests/hists_filter.c       | 14 ++++-
 tools/perf/tests/hists_link.c         | 18 +++++-
 tools/perf/tests/hists_output.c       | 12 +++-
 tools/perf/tests/mmap-thread-lookup.c |  3 +-
 tools/perf/util/callchain.c           |  9 +--
 tools/perf/util/event.c               |  8 ++-
 tools/perf/util/hist.c                | 10 ++--
 tools/perf/util/machine.c             | 80 ++++++++++++++++-----------
 9 files changed, 118 insertions(+), 50 deletions(-)
tools/perf/tests/hists_cumulate.c +12 -2
index 17f4fcd6bdce..28f5eb41eed9 100644
@@ -112,6 +112,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
              }
 
              fake_samples[i].thread = al.thread;
+             map__put(fake_samples[i].map);
              fake_samples[i].map = al.map;
              fake_samples[i].sym = al.sym;
      }
@@ -147,15 +148,23 @@ static void del_hist_entries(struct hists *hists)
      }
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 #define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl)  (cl->ms.map->dso->short_name)
+#define CDSO(cl)  (map__dso(cl->ms.map)->short_name)
 #define CSYM(cl)  (cl->ms.sym->name)
 
 struct result {
@@ -733,6 +742,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
      /* tear down everything */
      evlist__delete(evlist);
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_filter.c +12 -2
index 08cbeb9e39ae..bcd46244182a 100644
@@ -89,6 +89,7 @@ static int add_hist_entries(struct evlist *evlist,
                      }
 
                      fake_samples[i].thread = al.thread;
+                     map__put(fake_samples[i].map);
                      fake_samples[i].map = al.map;
                      fake_samples[i].sym = al.sym;
              }
@@ -101,6 +102,14 @@ static int add_hist_entries(struct evlist *evlist,
      return TEST_FAIL;
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 static int test__hists_filter(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
      int err = TEST_FAIL;
@@ -194,7 +203,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
              hists__filter_by_thread(hists);
 
              /* now applying dso filter for 'kernel' */
-             hists->dso_filter = fake_samples[0].map->dso;
+             hists->dso_filter = map__dso(fake_samples[0].map);
              hists__filter_by_dso(hists);
 
              if (verbose > 2) {
@@ -288,7 +297,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 
              /* now applying all filters at once. */
              hists->thread_filter = fake_samples[1].thread;
-             hists->dso_filter = fake_samples[1].map->dso;
+             hists->dso_filter = map__dso(fake_samples[1].map);
              hists__filter_by_thread(hists);
              hists__filter_by_dso(hists);
 
@@ -322,6 +331,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
      evlist__delete(evlist);
      reset_output_field();
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_link.c +17 -1
index c575e13a850d..060e8731feff 100644
@@ -6,6 +6,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include "machine.h"
+#include "map.h"
 #include "parse-events.h"
 #include "hists_common.h"
 #include "util/mmap.h"
@@ -94,6 +95,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
                      }
 
                      fake_common_samples[k].thread = al.thread;
+                     map__put(fake_common_samples[k].map);
                      fake_common_samples[k].map = al.map;
                      fake_common_samples[k].sym = al.sym;
              }
@@ -126,11 +128,24 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
      return -1;
 }
 
+static void put_fake_samples(void)
+{
+     size_t i, j;
+
+     for (i = 0; i < ARRAY_SIZE(fake_common_samples); i++)
+             map__put(fake_common_samples[i].map);
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
+             for (j = 0; j < ARRAY_SIZE(fake_samples[0]); j++)
+                     map__put(fake_samples[i][j].map);
+     }
+}
+
 static int find_sample(struct sample *samples, size_t nr_samples,
                     struct thread *t, struct map *m, struct symbol *s)
 {
      while (nr_samples--) {
-             if (samples->thread == t && samples->map == m &&
+             if (samples->thread == t &&
+                 samples->map == m &&
                  samples->sym == s)
                      return 1;
              samples++;
@@ -336,6 +351,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
      evlist__delete(evlist);
      reset_output_field();
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_output.c +11 -1
index 0bde4a768c15..4af6916491e5 100644
@@ -78,6 +78,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
              }
 
              fake_samples[i].thread = al.thread;
+             map__put(fake_samples[i].map);
              fake_samples[i].map = al.map;
              fake_samples[i].sym = al.sym;
      }
@@ -113,10 +114,18 @@ static void del_hist_entries(struct hists *hists)
      }
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
@@ -620,6 +629,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
      /* tear down everything */
      evlist__delete(evlist);
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/mmap-thread-lookup.c +2 -1
index a4301fc7b770..898eda55b7a8 100644
@@ -202,7 +202,8 @@ static int mmap_events(synth_cb synth)
                      break;
              }
 
-             pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
+             pr_debug("map %p, addr %" PRIx64 "\n", al.map, map__start(al.map));
+             map__put(al.map);
      }
 
      machine__delete_threads(machine);
tools/perf/util/callchain.c +5 -4
index a8cfd31a3ff0..ae65b7bc9ab7 100644
@@ -583,7 +583,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
              }
              call->ip = cursor_node->ip;
              call->ms = cursor_node->ms;
-             map__get(call->ms.map);
+             call->ms.map = map__get(call->ms.map);
              call->srcline = cursor_node->srcline;
 
              if (cursor_node->branch) {
@@ -1061,7 +1061,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
      node->ip = ip;
      map__zput(node->ms.map);
      node->ms = *ms;
-     map__get(node->ms.map);
+     node->ms.map = map__get(node->ms.map);
      node->branch = branch;
      node->nr_loop_iter = nr_loop_iter;
      node->iter_cycles = iter_cycles;
@@ -1109,7 +1109,8 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
      struct machine *machine = maps__machine(node->ms.maps);
 
      al->maps = node->ms.maps;
-     al->map = node->ms.map;
+     map__put(al->map);
+     al->map = map__get(node->ms.map);
      al->sym = node->ms.sym;
      al->srcline = node->srcline;
      al->addr = node->ip;
@@ -1530,7 +1531,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
                              goto out;
                      *new = *chain;
                      new->has_children = false;
-                     map__get(new->ms.map);
+                     new->ms.map = map__get(new->ms.map);
                      list_add_tail(&new->list, &head);
              }
              parent = parent->parent;
tools/perf/util/event.c +6 -2
index 54a1d4df5f70..266318d5d006 100644
@@ -484,13 +484,14 @@ 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__kernel_maps(machine), tp->addr);
+             al.map = map__get(maps__find(machine__kernel_maps(machine), tp->addr));
              if (al.map && map__load(al.map) >= 0) {
                      al.addr = map__map_ip(al.map, tp->addr);
                      al.sym = map__find_symbol(al.map, al.addr);
                      if (al.sym)
                              ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
              }
+             map__put(al.map);
      }
      ret += fprintf(fp, " old len %u new len %u\n", tp->old_len, tp->new_len);
      old = true;
@@ -581,6 +582,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
      al->filtered = 0;
 
      if (machine == NULL) {
+             map__put(al->map);
              al->map = NULL;
              return NULL;
      }
@@ -599,6 +601,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
              al->level = 'u';
      } else {
              al->level = 'H';
+             map__put(al->map);
              al->map = NULL;
 
              if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
@@ -613,7 +616,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
              return NULL;
      }
 
-     al->map = maps__find(maps, al->addr);
+     al->map = map__get(maps__find(maps, al->addr));
      if (al->map != NULL) {
              /*
               * Kernel maps might be changed when loading symbols so loading
@@ -768,6 +771,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
  */
 void addr_location__put(struct addr_location *al)
 {
+     map__zput(al->map);
      thread__zput(al->thread);
 }
 
tools/perf/util/hist.c +5 -5
index f19ac6eb4775..4dbb1dbf3679 100644
@@ -446,7 +446,7 @@ static int hist_entry__init(struct hist_entry *he,
                      memset(&he->stat, 0, sizeof(he->stat));
      }
 
-     map__get(he->ms.map);
+     he->ms.map = map__get(he->ms.map);
 
      if (he->branch_info) {
              /*
@@ -461,13 +461,13 @@ static int hist_entry__init(struct hist_entry *he,
              memcpy(he->branch_info, template->branch_info,
                     sizeof(*he->branch_info));
 
-             map__get(he->branch_info->from.ms.map);
-             map__get(he->branch_info->to.ms.map);
+             he->branch_info->from.ms.map = map__get(he->branch_info->from.ms.map);
+             he->branch_info->to.ms.map = map__get(he->branch_info->to.ms.map);
      }
 
      if (he->mem_info) {
-             map__get(he->mem_info->iaddr.ms.map);
-             map__get(he->mem_info->daddr.ms.map);
+             he->mem_info->iaddr.ms.map = map__get(he->mem_info->iaddr.ms.map);
+             he->mem_info->daddr.ms.map = map__get(he->mem_info->daddr.ms.map);
      }
 
      if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
tools/perf/util/machine.c +48 -33
index 940fb2a50dfd..49e4891e92b7 100644
@@ -783,33 +783,42 @@ static int machine__process_ksymbol_register(struct machine *machine,
 {
      struct symbol *sym;
      struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
+     bool put_map = false;
+     int err = 0;
 
      if (!map) {
              struct dso *dso = dso__new(event->ksymbol.name);
-             int err;
 
-             if (dso) {
-                     dso->kernel = DSO_SPACE__KERNEL;
-                     map = map__new2(0, dso);
-                     dso__put(dso);
+             if (!dso) {
+                     err = -ENOMEM;
+                     goto out;
              }
-
-             if (!dso || !map) {
-                     return -ENOMEM;
+             dso->kernel = DSO_SPACE__KERNEL;
+             map = map__new2(0, dso);
+             dso__put(dso);
+             if (!map) {
+                     err = -ENOMEM;
+                     goto out;
              }
-
+             /*
+              * The inserted map has a get on it, we need to put to release
+              * the reference count here, but do it after all accesses are
+              * done.
+              */
+             put_map = true;
              if (event->ksymbol.ksym_type == PERF_RECORD_KSYMBOL_TYPE_OOL) {
-                     map->dso->binary_type = DSO_BINARY_TYPE__OOL;
-                     map->dso->data.file_size = event->ksymbol.len;
-                     dso__set_loaded(map->dso);
+                     map__dso(map)->binary_type = DSO_BINARY_TYPE__OOL;
+                     map__dso(map)->data.file_size = event->ksymbol.len;
+                     dso__set_loaded(map__dso(map));
              }
 
              map->start = event->ksymbol.addr;
-             map->end = map->start + event->ksymbol.len;
+             map->end = map__start(map) + event->ksymbol.len;
              err = maps__insert(machine__kernel_maps(machine), map);
-             map__put(map);
-             if (err)
-                     return err;
+             if (err) {
+                     err = -ENOMEM;
+                     goto out;
+             }
 
              dso__set_loaded(dso);
 
@@ -819,13 +828,18 @@ static int machine__process_ksymbol_register(struct machine *machine,
              }
      }
 
-     sym = symbol__new(map->map_ip(map, map->start),
+     sym = symbol__new(map__map_ip(map, map__start(map)),
                        event->ksymbol.len,
                        0, 0, event->ksymbol.name);
-     if (!sym)
-             return -ENOMEM;
-     dso__insert_symbol(map->dso, sym);
-     return 0;
+     if (!sym) {
+             err = -ENOMEM;
+             goto out;
+     }
+     dso__insert_symbol(map__dso(map), sym);
+out:
+     if (put_map)
+             map__put(map);
+     return err;
 }
 
 static int machine__process_ksymbol_unregister(struct machine *machine,
@@ -925,14 +939,11 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
              goto out;
 
      err = maps__insert(machine__kernel_maps(machine), map);
-
-     /* Put the map here because maps__insert already got it */
-     map__put(map);
-
      /* If maps__insert failed, return NULL. */
-     if (err)
+     if (err) {
+             map__put(map);
              map = NULL;
-
+     }
 out:
      /* put the dso here, corresponding to  machine__findnew_module_dso */
      dso__put(dso);
@@ -1228,6 +1239,7 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
      /* In case of renewal the kernel map, destroy previous one */
      machine__destroy_kernel_maps(machine);
 
+     map__put(machine->vmlinux_map);
      machine->vmlinux_map = map__new2(0, kernel);
      if (machine->vmlinux_map == NULL)
              return -ENOMEM;
@@ -1513,6 +1525,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
      map->end = start + size;
 
      dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
+     map__put(map);
      return 0;
 }
 
@@ -1558,16 +1571,18 @@ static void machine__set_kernel_mmap(struct machine *machine,
 static int machine__update_kernel_mmap(struct machine *machine,
                                   u64 start, u64 end)
 {
-     struct map *map = machine__kernel_map(machine);
+     struct map *orig, *updated;
      int err;
 
-     map__get(map);
-     maps__remove(machine__kernel_maps(machine), map);
+     orig = machine->vmlinux_map;
+     updated = map__get(orig);
 
+     machine->vmlinux_map = updated;
      machine__set_kernel_mmap(machine, start, end);
+     maps__remove(machine__kernel_maps(machine), orig);
+     err = maps__insert(machine__kernel_maps(machine), updated);
+     map__put(orig);
 
-     err = maps__insert(machine__kernel_maps(machine), map);
-     map__put(map);
      return err;
 }
 
@@ -2246,6 +2261,7 @@ static int add_callchain_ip(struct thread *thread,
      err = callchain_cursor_append(cursor, ip, &ms,
                                    branch, flags, nr_loop_iter,
                                    iter_cycles, branch_from, srcline);
+     map__put(al.map);
      return err;
 }
 
--
Quoted 2 lines

2.35.1.265.g69c8d7142f-goog

--
Masami Hiramatsu <[email protected]>

#51 lore raw

Re: [PATCH v3 17/22] perf map: Changes to reference counting

Quoted 48 lines · On Sat, 12 Feb 2022 12:48:45 -0800 Ian Rogers <[email protected]> wrote:
Quoted 37 lines · Masami Hiramatsu

Hi Ian,

Quoted 4 lines · On Fri, 11 Feb 2022 02:34:10 -0800 Ian Rogers <[email protected]> wrote:

When a pointer to a map exists do a get, when that pointer is overwritten or freed, put the map. This avoids issues with gets and puts being inconsistently used causing, use after puts, etc. Reference count checking and address sanitizer were used to identify issues.

OK, and please add comments in the code what should be actually done so the others can understand it correctly, since this changes the map object handling model.

Previously;

  map__get(map);
  map_operations(map);
  map__put(map);

Now, we have to use the object returned from get() ops. This is more likely to the memdup()/free().

  new = map__get(map);
  map_operations(new);
  map__put(new);

To update the object in the other object (e.g. machine__update_kernel_mmap()) The original one must be put because it has the old copy.

Previous;

  map__get(parent_obj->map);
  update_operation(parent_obj->map);
  map__put(parent_obj->map;
Quoted 7 lines

Is now;

  orig = parent_obj->map;
  new = map__get(orig);
  update_operation(new);
  parent_obj->map = new;
  map__put(orig);

Hi Masami,

Quoted 9 lines

Thanks as always for the input! This is a top post and so I lack the context for what you are describing. The model should always be get, operation, put, but the map code does not follow this model. I suspect the map code at some point in time didn't have reference counts, someone added them for one use case and then didn't add gets and puts elsewhere. Because a crash is worse than a memory leak extra gets were added, or puts missed, and the code is pretty much spaghetti today. We now need to be able to pair gets with puts and hence the model that this change introduces.

Hi Ian,

Thanks for the reply.
And I agree there are some issues in the current code. I thought those are fixed in patches before this, because those are bugs.

Quoted 8 lines

There are cases where the new code needs to
distinguish between a reference that is put and a reference that will be kept alive and say returned, this is fiddly and adds extra state - this seems to be what you're describing. I don't see how having a concept of a token is clearing this matter up. We have one pointer that can't be used after a function has consumed it, we introduce another pointer via a get so that we can keep the value for the sake of future use. In C++ we'd have two smart pointers for this case.

Yeah, C++ has such smart pointer concept, but C doesn't. So I would suggest that leaving some comments will help followers. Imagine that if you see the smart pointer without any prerequisite knowledge.

Quoted 5 lines
Quoted 2 lines

I think this change also should be documented with some concrete example patterns so that someone can program it correctly. :-)

So the example change was the cpumap one (i.e. patch set v1). It is a literal patch set and so I'm not sure why it isn't a concrete example.

Of course these are the good examples, but I can not see any comment why this is done in the code or document. If this programming model is enough general, you don't need it, but first parson needs to leave why and how to.

Quoted 4 lines

In terms of motivation, the map code is about the worst thing that could try to be fixed and that's why I tackled it. It'd have been much easier to implement the approach in cpumap and ask someone else to do the map case :-)

Indeed, this approach can help others to find the issues, and would you think if there are more document and comments, followers can do it easier?

Quoted 9 lines

The problem I face is that in introducing the
refactors and the approach, perf now crashes because of the technique working. That's why I've also had to fix the bugs in map the approach identifies - the code passes most of perf test enabled and with sanitizers. There are more issues. To be specific on one example, addr_location references a map but lacks any kind of init/exit protocol. The exit should put any map the addr_location has. There are 191 uses of addr_location that need to be looked at and a proper get/put, init/exit approach introduced.

Yeah, I also felt that there are less API document in perf in general.

Quoted 3 lines

I've fixed the ones that are
crashes and show stoppers. With this approach enabled we can catch more and avoid human error.

I think just crashing without telling what is the correct way to handle it, is not kind (and may waste someone's time until they find the correct way.)

BTW, your approach can crash below pattern (but this is standard refcount'd object handling in C.)

map = map__new_and_get();
...
map__get(map);
map_operations(map);
map__put(map);
...
map__get(map); <- crash! because "map" is already freed.

This must be like the below now;

map = map__new_and_get();
...
cur = map__get(map);
map_operations(cur);
map__put(cur);
...
cur2 = map__get(map);

Can this find below case?

map = map__new_and_get();
...
/* Do not get map */
map_operations(map);

Thank you,

Quoted 515 lines

Thanks,
Ian

Quoted 511 lines

(This is the reason why I asked you to introduce object-token instead
of modifying object pointer itself.)

Thank you,

Quoted 500 lines
---
 tools/perf/tests/hists_cumulate.c     | 14 ++++-
 tools/perf/tests/hists_filter.c       | 14 ++++-
 tools/perf/tests/hists_link.c         | 18 +++++-
 tools/perf/tests/hists_output.c       | 12 +++-
 tools/perf/tests/mmap-thread-lookup.c |  3 +-
 tools/perf/util/callchain.c           |  9 +--
 tools/perf/util/event.c               |  8 ++-
 tools/perf/util/hist.c                | 10 ++--
 tools/perf/util/machine.c             | 80 ++++++++++++++++-----------
 9 files changed, 118 insertions(+), 50 deletions(-)
tools/perf/tests/hists_cumulate.c +12 -2
index 17f4fcd6bdce..28f5eb41eed9 100644
@@ -112,6 +112,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
              }
 
              fake_samples[i].thread = al.thread;
+             map__put(fake_samples[i].map);
              fake_samples[i].map = al.map;
              fake_samples[i].sym = al.sym;
      }
@@ -147,15 +148,23 @@ static void del_hist_entries(struct hists *hists)
      }
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 #define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl)  (cl->ms.map->dso->short_name)
+#define CDSO(cl)  (map__dso(cl->ms.map)->short_name)
 #define CSYM(cl)  (cl->ms.sym->name)
 
 struct result {
@@ -733,6 +742,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
      /* tear down everything */
      evlist__delete(evlist);
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_filter.c +12 -2
index 08cbeb9e39ae..bcd46244182a 100644
@@ -89,6 +89,7 @@ static int add_hist_entries(struct evlist *evlist,
                      }
 
                      fake_samples[i].thread = al.thread;
+                     map__put(fake_samples[i].map);
                      fake_samples[i].map = al.map;
                      fake_samples[i].sym = al.sym;
              }
@@ -101,6 +102,14 @@ static int add_hist_entries(struct evlist *evlist,
      return TEST_FAIL;
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 static int test__hists_filter(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
      int err = TEST_FAIL;
@@ -194,7 +203,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
              hists__filter_by_thread(hists);
 
              /* now applying dso filter for 'kernel' */
-             hists->dso_filter = fake_samples[0].map->dso;
+             hists->dso_filter = map__dso(fake_samples[0].map);
              hists__filter_by_dso(hists);
 
              if (verbose > 2) {
@@ -288,7 +297,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 
              /* now applying all filters at once. */
              hists->thread_filter = fake_samples[1].thread;
-             hists->dso_filter = fake_samples[1].map->dso;
+             hists->dso_filter = map__dso(fake_samples[1].map);
              hists__filter_by_thread(hists);
              hists__filter_by_dso(hists);
 
@@ -322,6 +331,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
      evlist__delete(evlist);
      reset_output_field();
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_link.c +17 -1
index c575e13a850d..060e8731feff 100644
@@ -6,6 +6,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include "machine.h"
+#include "map.h"
 #include "parse-events.h"
 #include "hists_common.h"
 #include "util/mmap.h"
@@ -94,6 +95,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
                      }
 
                      fake_common_samples[k].thread = al.thread;
+                     map__put(fake_common_samples[k].map);
                      fake_common_samples[k].map = al.map;
                      fake_common_samples[k].sym = al.sym;
              }
@@ -126,11 +128,24 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
      return -1;
 }
 
+static void put_fake_samples(void)
+{
+     size_t i, j;
+
+     for (i = 0; i < ARRAY_SIZE(fake_common_samples); i++)
+             map__put(fake_common_samples[i].map);
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
+             for (j = 0; j < ARRAY_SIZE(fake_samples[0]); j++)
+                     map__put(fake_samples[i][j].map);
+     }
+}
+
 static int find_sample(struct sample *samples, size_t nr_samples,
                     struct thread *t, struct map *m, struct symbol *s)
 {
      while (nr_samples--) {
-             if (samples->thread == t && samples->map == m &&
+             if (samples->thread == t &&
+                 samples->map == m &&
                  samples->sym == s)
                      return 1;
              samples++;
@@ -336,6 +351,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
      evlist__delete(evlist);
      reset_output_field();
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/hists_output.c +11 -1
index 0bde4a768c15..4af6916491e5 100644
@@ -78,6 +78,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
              }
 
              fake_samples[i].thread = al.thread;
+             map__put(fake_samples[i].map);
              fake_samples[i].map = al.map;
              fake_samples[i].sym = al.sym;
      }
@@ -113,10 +114,18 @@ static void del_hist_entries(struct hists *hists)
      }
 }
 
+static void put_fake_samples(void)
+{
+     size_t i;
+
+     for (i = 0; i < ARRAY_SIZE(fake_samples); i++)
+             map__put(fake_samples[i].map);
+}
+
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
@@ -620,6 +629,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
      /* tear down everything */
      evlist__delete(evlist);
      machines__exit(&machines);
+     put_fake_samples();
 
      return err;
 }
tools/perf/tests/mmap-thread-lookup.c +2 -1
index a4301fc7b770..898eda55b7a8 100644
@@ -202,7 +202,8 @@ static int mmap_events(synth_cb synth)
                      break;
              }
 
-             pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
+             pr_debug("map %p, addr %" PRIx64 "\n", al.map, map__start(al.map));
+             map__put(al.map);
      }
 
      machine__delete_threads(machine);
tools/perf/util/callchain.c +5 -4
index a8cfd31a3ff0..ae65b7bc9ab7 100644
@@ -583,7 +583,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
              }
              call->ip = cursor_node->ip;
              call->ms = cursor_node->ms;
-             map__get(call->ms.map);
+             call->ms.map = map__get(call->ms.map);
              call->srcline = cursor_node->srcline;
 
              if (cursor_node->branch) {
@@ -1061,7 +1061,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
      node->ip = ip;
      map__zput(node->ms.map);
      node->ms = *ms;
-     map__get(node->ms.map);
+     node->ms.map = map__get(node->ms.map);
      node->branch = branch;
      node->nr_loop_iter = nr_loop_iter;
      node->iter_cycles = iter_cycles;
@@ -1109,7 +1109,8 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
      struct machine *machine = maps__machine(node->ms.maps);
 
      al->maps = node->ms.maps;
-     al->map = node->ms.map;
+     map__put(al->map);
+     al->map = map__get(node->ms.map);
      al->sym = node->ms.sym;
      al->srcline = node->srcline;
      al->addr = node->ip;
@@ -1530,7 +1531,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
                              goto out;
                      *new = *chain;
                      new->has_children = false;
-                     map__get(new->ms.map);
+                     new->ms.map = map__get(new->ms.map);
                      list_add_tail(&new->list, &head);
              }
              parent = parent->parent;
tools/perf/util/event.c +6 -2
index 54a1d4df5f70..266318d5d006 100644
@@ -484,13 +484,14 @@ 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__kernel_maps(machine), tp->addr);
+             al.map = map__get(maps__find(machine__kernel_maps(machine), tp->addr));
              if (al.map && map__load(al.map) >= 0) {
                      al.addr = map__map_ip(al.map, tp->addr);
                      al.sym = map__find_symbol(al.map, al.addr);
                      if (al.sym)
                              ret += symbol__fprintf_symname_offs(al.sym, &al, fp);
              }
+             map__put(al.map);
      }
      ret += fprintf(fp, " old len %u new len %u\n", tp->old_len, tp->new_len);
      old = true;
@@ -581,6 +582,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
      al->filtered = 0;
 
      if (machine == NULL) {
+             map__put(al->map);
              al->map = NULL;
              return NULL;
      }
@@ -599,6 +601,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
              al->level = 'u';
      } else {
              al->level = 'H';
+             map__put(al->map);
              al->map = NULL;
 
              if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
@@ -613,7 +616,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
              return NULL;
      }
 
-     al->map = maps__find(maps, al->addr);
+     al->map = map__get(maps__find(maps, al->addr));
      if (al->map != NULL) {
              /*
               * Kernel maps might be changed when loading symbols so loading
@@ -768,6 +771,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
  */
 void addr_location__put(struct addr_location *al)
 {
+     map__zput(al->map);
      thread__zput(al->thread);
 }
 
tools/perf/util/hist.c +5 -5
index f19ac6eb4775..4dbb1dbf3679 100644
@@ -446,7 +446,7 @@ static int hist_entry__init(struct hist_entry *he,
                      memset(&he->stat, 0, sizeof(he->stat));
      }
 
-     map__get(he->ms.map);
+     he->ms.map = map__get(he->ms.map);
 
      if (he->branch_info) {
              /*
@@ -461,13 +461,13 @@ static int hist_entry__init(struct hist_entry *he,
              memcpy(he->branch_info, template->branch_info,
                     sizeof(*he->branch_info));
 
-             map__get(he->branch_info->from.ms.map);
-             map__get(he->branch_info->to.ms.map);
+             he->branch_info->from.ms.map = map__get(he->branch_info->from.ms.map);
+             he->branch_info->to.ms.map = map__get(he->branch_info->to.ms.map);
      }
 
      if (he->mem_info) {
-             map__get(he->mem_info->iaddr.ms.map);
-             map__get(he->mem_info->daddr.ms.map);
+             he->mem_info->iaddr.ms.map = map__get(he->mem_info->iaddr.ms.map);
+             he->mem_info->daddr.ms.map = map__get(he->mem_info->daddr.ms.map);
      }
 
      if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
tools/perf/util/machine.c +48 -33
index 940fb2a50dfd..49e4891e92b7 100644
@@ -783,33 +783,42 @@ static int machine__process_ksymbol_register(struct machine *machine,
 {
      struct symbol *sym;
      struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
+     bool put_map = false;
+     int err = 0;
 
      if (!map) {
              struct dso *dso = dso__new(event->ksymbol.name);
-             int err;
 
-             if (dso) {
-                     dso->kernel = DSO_SPACE__KERNEL;
-                     map = map__new2(0, dso);
-                     dso__put(dso);
+             if (!dso) {
+                     err = -ENOMEM;
+                     goto out;
              }
-
-             if (!dso || !map) {
-                     return -ENOMEM;
+             dso->kernel = DSO_SPACE__KERNEL;
+             map = map__new2(0, dso);
+             dso__put(dso);
+             if (!map) {
+                     err = -ENOMEM;
+                     goto out;
              }
-
+             /*
+              * The inserted map has a get on it, we need to put to release
+              * the reference count here, but do it after all accesses are
+              * done.
+              */
+             put_map = true;
              if (event->ksymbol.ksym_type == PERF_RECORD_KSYMBOL_TYPE_OOL) {
-                     map->dso->binary_type = DSO_BINARY_TYPE__OOL;
-                     map->dso->data.file_size = event->ksymbol.len;
-                     dso__set_loaded(map->dso);
+                     map__dso(map)->binary_type = DSO_BINARY_TYPE__OOL;
+                     map__dso(map)->data.file_size = event->ksymbol.len;
+                     dso__set_loaded(map__dso(map));
              }
 
              map->start = event->ksymbol.addr;
-             map->end = map->start + event->ksymbol.len;
+             map->end = map__start(map) + event->ksymbol.len;
              err = maps__insert(machine__kernel_maps(machine), map);
-             map__put(map);
-             if (err)
-                     return err;
+             if (err) {
+                     err = -ENOMEM;
+                     goto out;
+             }
 
              dso__set_loaded(dso);
 
@@ -819,13 +828,18 @@ static int machine__process_ksymbol_register(struct machine *machine,
              }
      }
 
-     sym = symbol__new(map->map_ip(map, map->start),
+     sym = symbol__new(map__map_ip(map, map__start(map)),
                        event->ksymbol.len,
                        0, 0, event->ksymbol.name);
-     if (!sym)
-             return -ENOMEM;
-     dso__insert_symbol(map->dso, sym);
-     return 0;
+     if (!sym) {
+             err = -ENOMEM;
+             goto out;
+     }
+     dso__insert_symbol(map__dso(map), sym);
+out:
+     if (put_map)
+             map__put(map);
+     return err;
 }
 
 static int machine__process_ksymbol_unregister(struct machine *machine,
@@ -925,14 +939,11 @@ static struct map *machine__addnew_module_map(struct machine *machine, u64 start
              goto out;
 
      err = maps__insert(machine__kernel_maps(machine), map);
-
-     /* Put the map here because maps__insert already got it */
-     map__put(map);
-
      /* If maps__insert failed, return NULL. */
-     if (err)
+     if (err) {
+             map__put(map);
              map = NULL;
-
+     }
 out:
      /* put the dso here, corresponding to  machine__findnew_module_dso */
      dso__put(dso);
@@ -1228,6 +1239,7 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
      /* In case of renewal the kernel map, destroy previous one */
      machine__destroy_kernel_maps(machine);
 
+     map__put(machine->vmlinux_map);
      machine->vmlinux_map = map__new2(0, kernel);
      if (machine->vmlinux_map == NULL)
              return -ENOMEM;
@@ -1513,6 +1525,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
      map->end = start + size;
 
      dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
+     map__put(map);
      return 0;
 }
 
@@ -1558,16 +1571,18 @@ static void machine__set_kernel_mmap(struct machine *machine,
 static int machine__update_kernel_mmap(struct machine *machine,
                                   u64 start, u64 end)
 {
-     struct map *map = machine__kernel_map(machine);
+     struct map *orig, *updated;
      int err;
 
-     map__get(map);
-     maps__remove(machine__kernel_maps(machine), map);
+     orig = machine->vmlinux_map;
+     updated = map__get(orig);
 
+     machine->vmlinux_map = updated;
      machine__set_kernel_mmap(machine, start, end);
+     maps__remove(machine__kernel_maps(machine), orig);
+     err = maps__insert(machine__kernel_maps(machine), updated);
+     map__put(orig);
 
-     err = maps__insert(machine__kernel_maps(machine), map);
-     map__put(map);
      return err;
 }
 
@@ -2246,6 +2261,7 @@ static int add_callchain_ip(struct thread *thread,
      err = callchain_cursor_append(cursor, ip, &ms,
                                    branch, flags, nr_loop_iter,
                                    iter_cycles, branch_from, srcline);
+     map__put(al.map);
      return err;
 }
 
--
Quoted 2 lines

2.35.1.265.g69c8d7142f-goog

--
Masami Hiramatsu <[email protected]>

Signature · 1 line
Masami Hiramatsu <[email protected]>