public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* Re: 6.1-stable backport request
       [not found] <CAM9d7cgVCqYVirivv3ApCq18eSCUuJjUoq7hbhw7X9AaTwNf+w@mail.gmail.com>
@ 2024-05-07 23:10 ` Namhyung Kim
  2024-05-08 20:18   ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2024-05-07 23:10 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman, sashal
  Cc: Arnaldo Carvalho de Melo, Pablo Galindo Salgado, stable

Hello,

On Fri, Feb 2, 2024 at 3:29 PM Namhyung Kim <namhyung@gmail.com> wrote:
>
> Hello,
>
> Please queue up these commits for 6.1-stable:
>
> * commit: 4fb54994b2360ab5029ee3a959161f6fe6bbb349
>   ("perf unwind-libunwind: Fix base address for .eh_frame")
>
> * commit: c966d23a351a33f8a977fd7efbb6f467132f7383
>   ("perf unwind-libdw: Handle JIT-generated DSOs properly")
>
> They are needed to support JIT code in the perf tools.
> I think there will be some conflicts, I will send backports soon.

Have you received my backport patches?  I'm wondering if
they're missing or have other problems.

Thanks,
Namhyung

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

* Re: 6.1-stable backport request
  2024-05-07 23:10 ` 6.1-stable backport request Namhyung Kim
@ 2024-05-08 20:18   ` Sasha Levin
  2024-05-08 21:00     ` [PATCH for-v6.1 1/2] perf unwind-libunwind: Fix base address for .eh_frame Namhyung Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2024-05-08 20:18 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: stable, Greg Kroah-Hartman, Arnaldo Carvalho de Melo,
	Pablo Galindo Salgado, stable

On Tue, May 07, 2024 at 04:10:50PM -0700, Namhyung Kim wrote:
>Hello,
>
>On Fri, Feb 2, 2024 at 3:29 PM Namhyung Kim <namhyung@gmail.com> wrote:
>>
>> Hello,
>>
>> Please queue up these commits for 6.1-stable:
>>
>> * commit: 4fb54994b2360ab5029ee3a959161f6fe6bbb349
>>   ("perf unwind-libunwind: Fix base address for .eh_frame")
>>
>> * commit: c966d23a351a33f8a977fd7efbb6f467132f7383
>>   ("perf unwind-libdw: Handle JIT-generated DSOs properly")
>>
>> They are needed to support JIT code in the perf tools.
>> I think there will be some conflicts, I will send backports soon.
>
>Have you received my backport patches?  I'm wondering if
>they're missing or have other problems.

I haven't, nor do I see them on the list. Could you resend please?

-- 
Thanks,
Sasha

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

* [PATCH for-v6.1 1/2] perf unwind-libunwind: Fix base address for .eh_frame
  2024-05-08 20:18   ` Sasha Levin
@ 2024-05-08 21:00     ` Namhyung Kim
  2024-05-08 21:00       ` [PATCH for-v6.1 2/2] perf unwind-libdw: Handle JIT-generated DSOs properly Namhyung Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2024-05-08 21:00 UTC (permalink / raw)
  To: stable, Sasha Levin, Greg Kroah-Hartman
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Pablo Galindo Salgado,
	stable, Ian Rogers, Adrian Hunter, Fangrui Song, Ingo Molnar,
	Jiri Olsa, Milian Wolff, Peter Zijlstra, Arnaldo Carvalho de Melo

[ Upstream commit 4fb54994b2360ab5029ee3a959161f6fe6bbb349 ]

The base address of a DSO mapping should start at the start of the file.
Usually DSOs are mapped from the pgoff 0 so it doesn't matter when it
uses the start of the map address.

But generated DSOs for JIT codes doesn't start from the 0 so it should
subtract the offset to calculate the .eh_frame table offsets correctly.

Fixes: dc2cf4ca866f5715 ("perf unwind: Fix segbase for ld.lld linked objects")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Pablo Galindo <pablogsal@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231212070547.612536-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libunwind-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 81b6bd6e1536..b276e36e3fb4 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -327,7 +327,7 @@ static int read_unwind_spec_eh_frame(struct dso *dso, struct unwind_info *ui,
 
 	maps__for_each_entry(ui->thread->maps, map) {
 		if (map->dso == dso && map->start < base_addr)
-			base_addr = map->start;
+			base_addr = map->start - map->pgoff;
 	}
 	base_addr -= dso->data.elf_base_addr;
 	/* Address of .eh_frame_hdr */
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog


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

* [PATCH for-v6.1 2/2] perf unwind-libdw: Handle JIT-generated DSOs properly
  2024-05-08 21:00     ` [PATCH for-v6.1 1/2] perf unwind-libunwind: Fix base address for .eh_frame Namhyung Kim
@ 2024-05-08 21:00       ` Namhyung Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2024-05-08 21:00 UTC (permalink / raw)
  To: stable, Sasha Levin, Greg Kroah-Hartman
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Pablo Galindo Salgado,
	stable, Adrian Hunter, Fangrui Song, Ian Rogers, Ingo Molnar,
	Jiri Olsa, Milian Wolff, Peter Zijlstra, Arnaldo Carvalho de Melo

[ Upstream commit c966d23a351a33f8a977fd7efbb6f467132f7383 ]

Usually DSOs are mapped from the beginning of the file, so the base
address of the DSO can be calculated by map->start - map->pgoff.

However, JIT DSOs which are generated by `perf inject -j`, are mapped
only the code segment.  This makes unwind-libdw code confusing and
rejects processing unwinds in the JIT DSOs.  It should use the map
start address as base for them to fix the confusion.

Fixes: 1fe627da30331024 ("perf unwind: Take pgoff into account when reporting elf to libdwfl")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Pablo Galindo <pablogsal@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231212070547.612536-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libdw.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 94aa40f6e348..9a7bdc0e14cc 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -45,6 +45,7 @@ static int __report_module(struct addr_location *al, u64 ip,
 {
 	Dwfl_Module *mod;
 	struct dso *dso = NULL;
+	Dwarf_Addr base;
 	/*
 	 * Some callers will use al->sym, so we can't just use the
 	 * cheaper thread__find_map() here.
@@ -57,24 +58,36 @@ static int __report_module(struct addr_location *al, u64 ip,
 	if (!dso)
 		return 0;
 
+	/*
+	 * The generated JIT DSO files only map the code segment without
+	 * ELF headers.  Since JIT codes used to be packed in a memory
+	 * segment, calculating the base address using pgoff falls info
+	 * a different code in another DSO.  So just use the map->start
+	 * directly to pick the correct one.
+	 */
+	if (!strncmp(dso->long_name, "/tmp/jitted-", 12))
+		base = al->map->start;
+	else
+		base = al->map->start - al->map->pgoff;
+
 	mod = dwfl_addrmodule(ui->dwfl, ip);
 	if (mod) {
 		Dwarf_Addr s;
 
 		dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL);
-		if (s != al->map->start - al->map->pgoff)
-			mod = 0;
+		if (s != base)
+			mod = NULL;
 	}
 
 	if (!mod)
 		mod = dwfl_report_elf(ui->dwfl, dso->short_name, dso->long_name, -1,
-				      al->map->start - al->map->pgoff, false);
+				      base, false);
 	if (!mod) {
 		char filename[PATH_MAX];
 
 		if (dso__build_id_filename(dso, filename, sizeof(filename), false))
 			mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1,
-					      al->map->start - al->map->pgoff, false);
+					      base, false);
 	}
 
 	if (mod) {
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog


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

end of thread, other threads:[~2024-05-08 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAM9d7cgVCqYVirivv3ApCq18eSCUuJjUoq7hbhw7X9AaTwNf+w@mail.gmail.com>
2024-05-07 23:10 ` 6.1-stable backport request Namhyung Kim
2024-05-08 20:18   ` Sasha Levin
2024-05-08 21:00     ` [PATCH for-v6.1 1/2] perf unwind-libunwind: Fix base address for .eh_frame Namhyung Kim
2024-05-08 21:00       ` [PATCH for-v6.1 2/2] perf unwind-libdw: Handle JIT-generated DSOs properly Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox