linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps
  2025-02-27 21:54 [PATCH 0/6] " Arnaldo Carvalho de Melo
@ 2025-02-27 21:54 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-27 21:54 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Namhyung Kim <namhyung@kernel.org>

This was detected at the end of a 'perf record' session when build-id
collection was enabled and thus the BPF programs put in place while the
session was running, some even put in place by perf itself were
processed and inserted, with some overlaps related to BPF trampolines
and programs took place.

Using maps__fixup_overlap_and_insert() instead of maps__insert() "fixes"
the problem, in the sense that overlaps will be dealt with and then the
consistency will be kept, but it would be interesting to fully
understand why such overlaps take place and how to deal with them when
doing symbol resolution.

Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Suggested-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/CAP-5=fXEEMFgPF2aZhKsfrY_En+qoqX20dWfuE_ad73Uxf0ZHQ@mail.gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index f7df01adad61ceea..a81ffd2d1a054d60 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -718,7 +718,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
 
 		map__set_start(map, event->ksymbol.addr);
 		map__set_end(map, map__start(map) + event->ksymbol.len);
-		err = maps__insert(machine__kernel_maps(machine), map);
+		err = maps__fixup_overlap_and_insert(machine__kernel_maps(machine), map);
 		if (err) {
 			err = -ENOMEM;
 			goto out;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 0/6 v2] Fixups for kernel maps insertion
@ 2025-02-28 21:17 Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 1/6] perf maps: Introduce map__set_kmap_maps() for kernel maps Arnaldo Carvalho de Melo
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Hi Namhyung,

        Here are the patches from the recent session on fixing the build
when DEBUG=1 is used, please take a look.

        I think that since there are no reported problems and ended up
being a sizeable series, we better apply it to perf-tools-next,

Best Regards,

- Arnaldo

v2: Use map__set_kmap_maps() as suggested by Ian.

Arnaldo Carvalho de Melo (3):
  perf maps: Introduce map__set_kmap_maps() for kernel maps
  perf maps: Set the kmaps for newly created/added kernel maps
  perf maps: Add missing map__set_kmap_maps() when replacing a kernel map

Namhyung Kim (3):
  perf machine: Fixup kernel maps ends after adding extra maps
  perf maps: Fixup maps_by_name when modifying maps_by_address
  perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps

 tools/perf/util/machine.c |  6 ++--
 tools/perf/util/maps.c    | 58 +++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 12 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/6] perf maps: Introduce map__set_kmap_maps() for kernel maps
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 2/6] perf maps: Set the kmaps for newly created/added " Arnaldo Carvalho de Melo
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Arnaldo Carvalho de Melo <acme@redhat.com>

We need to set it in other places than __maps__insert(), so that we can
have access to the 'struct maps' from a kernel 'struct map'.

When building perf with 'DEBUG=1' we can notice it failing a consistency
check done in the check_invariants() function:

  root@number:~# perf record -- perf test -w offcpu
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.040 MB perf.data (23 samples) ]
  perf: util/maps.c:95: check_invariants: Assertion `map__end(prev) <= map__end(map)' failed.
  Aborted (core dumped)
  root@number:~#

The investigation on that was happening bisected to 876e80cf83d10585
("perf tools: Fixup end address of modules"), and the following patches
will plug the problems found, this patch is just legwork on that
direction.

Use the map__set_kmap_maps() name as per a review comment from Ian
Rogers, later there are further suggestions from him on getting rid of
the kmaps variable, see the thread referenced in the Link below.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z74V0hZXrTLM6VIJ@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/maps.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 09c9cc326c08d435..51b507233269d8b4 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -428,11 +428,29 @@ static unsigned int maps__by_name_index(const struct maps *maps, const struct ma
 	return -1;
 }
 
+static void map__set_kmap_maps(struct map *map, struct maps *maps)
+{
+	struct dso *dso;
+
+	if (map == NULL)
+		return;
+
+	dso = map__dso(map);
+
+	if (dso && dso__kernel(dso)) {
+                struct kmap *kmap = map__kmap(map);
+
+                if (kmap)
+                        kmap->kmaps = maps;
+                else
+                        pr_err("Internal error: kernel dso with non kernel map\n");
+        }
+}
+
 static int __maps__insert(struct maps *maps, struct map *new)
 {
 	struct map **maps_by_address = maps__maps_by_address(maps);
 	struct map **maps_by_name = maps__maps_by_name(maps);
-	const struct dso *dso = map__dso(new);
 	unsigned int nr_maps = maps__nr_maps(maps);
 	unsigned int nr_allocate = RC_CHK_ACCESS(maps)->nr_maps_allocated;
 
@@ -483,14 +501,9 @@ static int __maps__insert(struct maps *maps, struct map *new)
 	}
 	if (map__end(new) < map__start(new))
 		RC_CHK_ACCESS(maps)->ends_broken = true;
-	if (dso && dso__kernel(dso)) {
-		struct kmap *kmap = map__kmap(new);
 
-		if (kmap)
-			kmap->kmaps = maps;
-		else
-			pr_err("Internal error: kernel dso with non kernel map\n");
-	}
+	map__set_kmap_maps(new, maps);
+
 	return 0;
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/6] perf maps: Set the kmaps for newly created/added kernel maps
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 1/6] perf maps: Introduce map__set_kmap_maps() for kernel maps Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 3/6] perf machine: Fixup kernel maps ends after adding extra maps Arnaldo Carvalho de Melo
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Arnaldo Carvalho de Melo <acme@redhat.com>

When using __maps__insert_sorted() the map kmaps field needs to be
initialized, as we need kernel maps to work with map__kmap().

Fix it by using the newly introduced map__set_kmap() method.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z74V0hZXrTLM6VIJ@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/maps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 51b507233269d8b4..8c5f5d79cd24a6bc 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -798,6 +798,9 @@ static int __maps__insert_sorted(struct maps *maps, unsigned int first_after_ind
 	}
 	RC_CHK_ACCESS(maps)->nr_maps = nr_maps + to_add;
 	maps__set_maps_by_name_sorted(maps, false);
+	map__set_kmap_maps(new1, maps);
+	map__set_kmap_maps(new2, maps);
+
 	check_invariants(maps);
 	return 0;
 }
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/6] perf machine: Fixup kernel maps ends after adding extra maps
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 1/6] perf maps: Introduce map__set_kmap_maps() for kernel maps Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 2/6] perf maps: Set the kmaps for newly created/added " Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 4/6] perf maps: Fixup maps_by_name when modifying maps_by_address Arnaldo Carvalho de Melo
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Namhyung Kim <namhyung@kernel.org>

I just noticed it would add extra kernel maps after modules.  I think it
should fixup end address of the kernel maps after adding all maps first.

Fixes: 876e80cf83d10585 ("perf tools: Fixup end address of modules")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z7TvZGjVix2asYWI@x1
Link: https://lore.kernel.org/lkml/Z712hzvv22Ni63f1@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3f1faf94198dbe56..f7df01adad61ceea 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1462,8 +1462,6 @@ static int machine__create_modules(struct machine *machine)
 	if (modules__parse(modules, machine, machine__create_module))
 		return -1;
 
-	maps__fixup_end(machine__kernel_maps(machine));
-
 	if (!machine__set_modules_path(machine))
 		return 0;
 
@@ -1557,6 +1555,8 @@ int machine__create_kernel_maps(struct machine *machine)
 		}
 	}
 
+	maps__fixup_end(machine__kernel_maps(machine));
+
 out_put:
 	dso__put(kernel);
 	return ret;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/6] perf maps: Fixup maps_by_name when modifying maps_by_address
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2025-02-28 21:17 ` [PATCH 3/6] perf machine: Fixup kernel maps ends after adding extra maps Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 5/6] perf maps: Add missing map__set_kmap_maps() when replacing a kernel map Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Namhyung Kim <namhyung@kernel.org>

We can't just replacing the map in the maps_by_address and not touching
on the maps_by_name, that would leave the refcount as 1 and thus trip
another consistency check, this one:

  perf: util/maps.c:110: check_invariants:
  	Assertion `refcount_read(map__refcnt(map)) > 1' failed.

  106         /*
  107          * Maps by name maps should be in maps_by_address, so
  108          * the reference count should be higher.
  109          */
  110         assert(refcount_read(map__refcnt(map)) > 1);

Committer notice:

Initialize the newly added 'ni' variable, that really can't be
accessed unitialized trips some gcc versions, like:

  12    20.00 archlinux:base                : FAIL gcc version 13.2.1 20230801 (GCC)
    util/maps.c: In function ‘__maps__fixup_overlap_and_insert’:
    util/maps.c:896:54: error: ‘ni’ may be used uninitialized [-Werror=maybe-uninitialized]
      896 |                                 map__put(maps_by_name[ni]);
          |                                                      ^
    util/maps.c:816:25: note: ‘ni’ was declared here
      816 |         unsigned int i, ni;
          |                         ^~
    cc1: all warnings being treated as errors
    make[3]: *** [/git/perf-6.14.0-rc1/tools/build/Makefile.build:138: util] Error 2

Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z79std66tPq-nqsD@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/maps.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 8c5f5d79cd24a6bc..77df9701d5ad7de3 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -813,7 +813,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 {
 	int err = 0;
 	FILE *fp = debug_file();
-	unsigned int i;
+	unsigned int i, ni = INT_MAX; // Some gcc complain, but depends on maps_by_name...
 
 	if (!maps__maps_by_address_sorted(maps))
 		__maps__sort_by_address(maps);
@@ -824,6 +824,7 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 	 */
 	for (i = first_ending_after(maps, new); i < maps__nr_maps(maps); ) {
 		struct map **maps_by_address = maps__maps_by_address(maps);
+		struct map **maps_by_name = maps__maps_by_name(maps);
 		struct map *pos = maps_by_address[i];
 		struct map *before = NULL, *after = NULL;
 
@@ -843,6 +844,9 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 			map__fprintf(pos, fp);
 		}
 
+		if (maps_by_name)
+			ni = maps__by_name_index(maps, pos);
+
 		/*
 		 * Now check if we need to create new maps for areas not
 		 * overlapped by the new map:
@@ -887,6 +891,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 		if (before) {
 			map__put(maps_by_address[i]);
 			maps_by_address[i] = before;
+
+			if (maps_by_name) {
+				map__put(maps_by_name[ni]);
+				maps_by_name[ni] = map__get(before);
+			}
+
 			/* Maps are still ordered, go to next one. */
 			i++;
 			if (after) {
@@ -908,6 +918,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 			 */
 			map__put(maps_by_address[i]);
 			maps_by_address[i] = map__get(new);
+
+			if (maps_by_name) {
+				map__put(maps_by_name[ni]);
+				maps_by_name[ni] = map__get(new);
+			}
+
 			err = __maps__insert_sorted(maps, i + 1, after, NULL);
 			map__put(after);
 			check_invariants(maps);
@@ -926,6 +942,12 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 				 */
 				map__put(maps_by_address[i]);
 				maps_by_address[i] = map__get(new);
+
+				if (maps_by_name) {
+					map__put(maps_by_name[ni]);
+					maps_by_name[ni] = map__get(new);
+				}
+
 				check_invariants(maps);
 				return err;
 			}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/6] perf maps: Add missing map__set_kmap_maps() when replacing a kernel map
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2025-02-28 21:17 ` [PATCH 4/6] perf maps: Fixup maps_by_name when modifying maps_by_address Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-02-28 21:17 ` [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Since in this case __maps__insert_sorted() is not called and thus
doesn't have the opportunity to do the needed map__set_kmap_maps() calls on
the new map.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z7-May5w9VQd5QD0@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/maps.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 77df9701d5ad7de3..0b40d901675ed57e 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -948,6 +948,8 @@ static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map *new)
 					maps_by_name[ni] = map__get(new);
 				}
 
+				map__set_kmap_maps(new, maps);
+
 				check_invariants(maps);
 				return err;
 			}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
                   ` (4 preceding siblings ...)
  2025-02-28 21:17 ` [PATCH 5/6] perf maps: Add missing map__set_kmap_maps() when replacing a kernel map Arnaldo Carvalho de Melo
@ 2025-02-28 21:17 ` Arnaldo Carvalho de Melo
  2025-03-01  0:03 ` [PATCH 0/6 v2] Fixups for kernel maps insertion Namhyung Kim
  2025-03-06 17:14 ` Namhyung Kim
  7 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-02-28 21:17 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

From: Namhyung Kim <namhyung@kernel.org>

This was detected at the end of a 'perf record' session when build-id
collection was enabled and thus the BPF programs put in place while the
session was running, some even put in place by perf itself were
processed and inserted, with some overlaps related to BPF trampolines
and programs took place.

Using maps__fixup_overlap_and_insert() instead of maps__insert() "fixes"
the problem, in the sense that overlaps will be dealt with and then the
consistency will be kept, but it would be interesting to fully
understand why such overlaps take place and how to deal with them when
doing symbol resolution.

Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Suggested-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/CAP-5=fXEEMFgPF2aZhKsfrY_En+qoqX20dWfuE_ad73Uxf0ZHQ@mail.gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index f7df01adad61ceea..a81ffd2d1a054d60 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -718,7 +718,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
 
 		map__set_start(map, event->ksymbol.addr);
 		map__set_end(map, map__start(map) + event->ksymbol.len);
-		err = maps__insert(machine__kernel_maps(machine), map);
+		err = maps__fixup_overlap_and_insert(machine__kernel_maps(machine), map);
 		if (err) {
 			err = -ENOMEM;
 			goto out;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/6 v2] Fixups for kernel maps insertion
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
                   ` (5 preceding siblings ...)
  2025-02-28 21:17 ` [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps Arnaldo Carvalho de Melo
@ 2025-03-01  0:03 ` Namhyung Kim
  2025-03-03 20:45   ` Namhyung Kim
  2025-03-06 17:14 ` Namhyung Kim
  7 siblings, 1 reply; 12+ messages in thread
From: Namhyung Kim @ 2025-03-01  0:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

On Fri, Feb 28, 2025 at 06:17:28PM -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Hi Namhyung,
> 
>         Here are the patches from the recent session on fixing the build
> when DEBUG=1 is used, please take a look.

Looks good.  It's more fine-grained than I expected. :)

> 
>         I think that since there are no reported problems and ended up
> being a sizeable series, we better apply it to perf-tools-next,

Sure, will add there.

Thanks,
Namhyung

> 
> Best Regards,
> 
> - Arnaldo
> 
> v2: Use map__set_kmap_maps() as suggested by Ian.
> 
> Arnaldo Carvalho de Melo (3):
>   perf maps: Introduce map__set_kmap_maps() for kernel maps
>   perf maps: Set the kmaps for newly created/added kernel maps
>   perf maps: Add missing map__set_kmap_maps() when replacing a kernel map
> 
> Namhyung Kim (3):
>   perf machine: Fixup kernel maps ends after adding extra maps
>   perf maps: Fixup maps_by_name when modifying maps_by_address
>   perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps
> 
>  tools/perf/util/machine.c |  6 ++--
>  tools/perf/util/maps.c    | 58 +++++++++++++++++++++++++++++++++------
>  2 files changed, 52 insertions(+), 12 deletions(-)
> 
> -- 
> 2.48.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/6 v2] Fixups for kernel maps insertion
  2025-03-01  0:03 ` [PATCH 0/6 v2] Fixups for kernel maps insertion Namhyung Kim
@ 2025-03-03 20:45   ` Namhyung Kim
  2025-03-05 22:55     ` Ian Rogers
  0 siblings, 1 reply; 12+ messages in thread
From: Namhyung Kim @ 2025-03-03 20:45 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

On Fri, Feb 28, 2025 at 04:03:48PM -0800, Namhyung Kim wrote:
> On Fri, Feb 28, 2025 at 06:17:28PM -0300, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > 
> > Hi Namhyung,
> > 
> >         Here are the patches from the recent session on fixing the build
> > when DEBUG=1 is used, please take a look.
> 
> Looks good.  It's more fine-grained than I expected. :)
> 
> > 
> >         I think that since there are no reported problems and ended up
> > being a sizeable series, we better apply it to perf-tools-next,
> 
> Sure, will add there.

Ian, are you ok with this now?

Thanks,
Namhyung


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/6 v2] Fixups for kernel maps insertion
  2025-03-03 20:45   ` Namhyung Kim
@ 2025-03-05 22:55     ` Ian Rogers
  0 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2025-03-05 22:55 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Thomas Gleixner,
	James Clark, Jiri Olsa, Adrian Hunter, Kan Liang, Clark Williams,
	linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo,
	Peter Zijlstra, Stephane Eranian

On Mon, Mar 3, 2025 at 12:45 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Fri, Feb 28, 2025 at 04:03:48PM -0800, Namhyung Kim wrote:
> > On Fri, Feb 28, 2025 at 06:17:28PM -0300, Arnaldo Carvalho de Melo wrote:
> > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > >
> > > Hi Namhyung,
> > >
> > >         Here are the patches from the recent session on fixing the build
> > > when DEBUG=1 is used, please take a look.
> >
> > Looks good.  It's more fine-grained than I expected. :)
> >
> > >
> > >         I think that since there are no reported problems and ended up
> > > being a sizeable series, we better apply it to perf-tools-next,
> >
> > Sure, will add there.
>
> Ian, are you ok with this now?

Yep, sorry for the delay.

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> Thanks,
> Namhyung
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/6 v2] Fixups for kernel maps insertion
  2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
                   ` (6 preceding siblings ...)
  2025-03-01  0:03 ` [PATCH 0/6 v2] Fixups for kernel maps insertion Namhyung Kim
@ 2025-03-06 17:14 ` Namhyung Kim
  7 siblings, 0 replies; 12+ messages in thread
From: Namhyung Kim @ 2025-03-06 17:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Stephane Eranian

On Fri, 28 Feb 2025 18:17:28 -0300, Arnaldo Carvalho de Melo wrote:
>         Here are the patches from the recent session on fixing the build
> when DEBUG=1 is used, please take a look.
> 
>         I think that since there are no reported problems and ended up
> being a sizeable series, we better apply it to perf-tools-next,
> 
> Best Regards,
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-03-06 17:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 21:17 [PATCH 0/6 v2] Fixups for kernel maps insertion Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 1/6] perf maps: Introduce map__set_kmap_maps() for kernel maps Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 2/6] perf maps: Set the kmaps for newly created/added " Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 3/6] perf machine: Fixup kernel maps ends after adding extra maps Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 4/6] perf maps: Fixup maps_by_name when modifying maps_by_address Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 5/6] perf maps: Add missing map__set_kmap_maps() when replacing a kernel map Arnaldo Carvalho de Melo
2025-02-28 21:17 ` [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps Arnaldo Carvalho de Melo
2025-03-01  0:03 ` [PATCH 0/6 v2] Fixups for kernel maps insertion Namhyung Kim
2025-03-03 20:45   ` Namhyung Kim
2025-03-05 22:55     ` Ian Rogers
2025-03-06 17:14 ` Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2025-02-27 21:54 [PATCH 0/6] " Arnaldo Carvalho de Melo
2025-02-27 21:54 ` [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).