[PATCH v2] perf tools: Fix compile error on sample->user_regs

Namhyung Kim posted 1 patch 10 months, 1 week ago
tools/perf/arch/arm/tests/dwarf-unwind.c      | 2 +-
tools/perf/arch/arm/util/unwind-libdw.c       | 2 +-
tools/perf/arch/csky/util/unwind-libdw.c      | 2 +-
tools/perf/arch/loongarch/util/unwind-libdw.c | 2 +-
tools/perf/arch/powerpc/tests/dwarf-unwind.c  | 2 +-
tools/perf/arch/powerpc/util/unwind-libdw.c   | 2 +-
tools/perf/arch/riscv/util/unwind-libdw.c     | 2 +-
tools/perf/arch/s390/util/unwind-libdw.c      | 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)
[PATCH v2] perf tools: Fix compile error on sample->user_regs
Posted by Namhyung Kim 10 months, 1 week ago
It's recently changed to allocate dynamically but misses to update some
arch-dependent codes to use perf_sample__user_regs().

Fixes: dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
v2) fix arm (32-bit) as well

 tools/perf/arch/arm/tests/dwarf-unwind.c      | 2 +-
 tools/perf/arch/arm/util/unwind-libdw.c       | 2 +-
 tools/perf/arch/csky/util/unwind-libdw.c      | 2 +-
 tools/perf/arch/loongarch/util/unwind-libdw.c | 2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c  | 2 +-
 tools/perf/arch/powerpc/util/unwind-libdw.c   | 2 +-
 tools/perf/arch/riscv/util/unwind-libdw.c     | 2 +-
 tools/perf/arch/s390/util/unwind-libdw.c      | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/arch/arm/tests/dwarf-unwind.c b/tools/perf/arch/arm/tests/dwarf-unwind.c
index 9bc304cb7762b5d1..f421910e07097152 100644
--- a/tools/perf/arch/arm/tests/dwarf-unwind.c
+++ b/tools/perf/arch/arm/tests/dwarf-unwind.c
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
 			     struct thread *thread)
 {
-	struct regs_dump *regs = &sample->user_regs;
+	struct regs_dump *regs = perf_sample__user_regs(sample);
 	u64 *buf;
 
 	buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c
index 4e02cef461e3af34..fbb643f224ec4b27 100644
--- a/tools/perf/arch/arm/util/unwind-libdw.c
+++ b/tools/perf/arch/arm/util/unwind-libdw.c
@@ -8,7 +8,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_ARM_MAX];
 
 #define REG(r) ({						\
diff --git a/tools/perf/arch/csky/util/unwind-libdw.c b/tools/perf/arch/csky/util/unwind-libdw.c
index 79df4374ab18dc36..b20b1569783d7e98 100644
--- a/tools/perf/arch/csky/util/unwind-libdw.c
+++ b/tools/perf/arch/csky/util/unwind-libdw.c
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX];
 
 #define REG(r) ({						\
diff --git a/tools/perf/arch/loongarch/util/unwind-libdw.c b/tools/perf/arch/loongarch/util/unwind-libdw.c
index 7b3b9a4b21f8f482..60b1144bedd5f325 100644
--- a/tools/perf/arch/loongarch/util/unwind-libdw.c
+++ b/tools/perf/arch/loongarch/util/unwind-libdw.c
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_LOONGARCH_MAX];
 
 #define REG(r) ({							\
diff --git a/tools/perf/arch/powerpc/tests/dwarf-unwind.c b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
index 5ecf82893b84d5c0..66af884baa660389 100644
--- a/tools/perf/arch/powerpc/tests/dwarf-unwind.c
+++ b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
 			     struct thread *thread)
 {
-	struct regs_dump *regs = &sample->user_regs;
+	struct regs_dump *regs = perf_sample__user_regs(sample);
 	u64 *buf;
 
 	buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
diff --git a/tools/perf/arch/powerpc/util/unwind-libdw.c b/tools/perf/arch/powerpc/util/unwind-libdw.c
index e9a5a8bb67d9186e..82d0c28ae3459ecd 100644
--- a/tools/perf/arch/powerpc/util/unwind-libdw.c
+++ b/tools/perf/arch/powerpc/util/unwind-libdw.c
@@ -16,7 +16,7 @@ static const int special_regs[3][2] = {
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[32], dwarf_nip;
 	size_t i;
 
diff --git a/tools/perf/arch/riscv/util/unwind-libdw.c b/tools/perf/arch/riscv/util/unwind-libdw.c
index 5c98010d8b59777f..dc1476e16321736d 100644
--- a/tools/perf/arch/riscv/util/unwind-libdw.c
+++ b/tools/perf/arch/riscv/util/unwind-libdw.c
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[32];
 
 #define REG(r) ({						\
diff --git a/tools/perf/arch/s390/util/unwind-libdw.c b/tools/perf/arch/s390/util/unwind-libdw.c
index f50fb6dbb35c5dc6..c27c7a0d1076c890 100644
--- a/tools/perf/arch/s390/util/unwind-libdw.c
+++ b/tools/perf/arch/s390/util/unwind-libdw.c
@@ -11,7 +11,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[ARRAY_SIZE(s390_dwarf_regs)];
 
 #define REG(r) ({						\
-- 
2.48.1.601.g30ceb7b040-goog
Re: [PATCH v2] perf tools: Fix compile error on sample->user_regs
Posted by Namhyung Kim 10 months, 1 week ago
On Fri, 14 Feb 2025 11:16:41 -0800, Namhyung Kim wrote:
> It's recently changed to allocate dynamically but misses to update some
> arch-dependent codes to use perf_sample__user_regs().
> 
> 
Applied to perf-tools-next, thanks!

Best regards,
Namhyung
Re: [PATCH v2] perf tools: Fix compile error on sample->user_regs
Posted by Ian Rogers 10 months, 1 week ago
On Fri, Feb 14, 2025 at 11:16 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> It's recently changed to allocate dynamically but misses to update some
> arch-dependent codes to use perf_sample__user_regs().
>
> Fixes: dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Thanks for this! My tag in case it is useful:
Reviewed-by: Ian Rogers <irogers@google.com>

Would be nice to have asan testing to make sure there are arch
dependent memory leaks, less arch code would be nice.

Thanks,
Ian

> ---
> v2) fix arm (32-bit) as well
>
>  tools/perf/arch/arm/tests/dwarf-unwind.c      | 2 +-
>  tools/perf/arch/arm/util/unwind-libdw.c       | 2 +-
>  tools/perf/arch/csky/util/unwind-libdw.c      | 2 +-
>  tools/perf/arch/loongarch/util/unwind-libdw.c | 2 +-
>  tools/perf/arch/powerpc/tests/dwarf-unwind.c  | 2 +-
>  tools/perf/arch/powerpc/util/unwind-libdw.c   | 2 +-
>  tools/perf/arch/riscv/util/unwind-libdw.c     | 2 +-
>  tools/perf/arch/s390/util/unwind-libdw.c      | 2 +-
>  8 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/arch/arm/tests/dwarf-unwind.c b/tools/perf/arch/arm/tests/dwarf-unwind.c
> index 9bc304cb7762b5d1..f421910e07097152 100644
> --- a/tools/perf/arch/arm/tests/dwarf-unwind.c
> +++ b/tools/perf/arch/arm/tests/dwarf-unwind.c
> @@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
>  int test__arch_unwind_sample(struct perf_sample *sample,
>                              struct thread *thread)
>  {
> -       struct regs_dump *regs = &sample->user_regs;
> +       struct regs_dump *regs = perf_sample__user_regs(sample);
>         u64 *buf;
>
>         buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
> diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c
> index 4e02cef461e3af34..fbb643f224ec4b27 100644
> --- a/tools/perf/arch/arm/util/unwind-libdw.c
> +++ b/tools/perf/arch/arm/util/unwind-libdw.c
> @@ -8,7 +8,7 @@
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[PERF_REG_ARM_MAX];
>
>  #define REG(r) ({                                              \
> diff --git a/tools/perf/arch/csky/util/unwind-libdw.c b/tools/perf/arch/csky/util/unwind-libdw.c
> index 79df4374ab18dc36..b20b1569783d7e98 100644
> --- a/tools/perf/arch/csky/util/unwind-libdw.c
> +++ b/tools/perf/arch/csky/util/unwind-libdw.c
> @@ -10,7 +10,7 @@
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX];
>
>  #define REG(r) ({                                              \
> diff --git a/tools/perf/arch/loongarch/util/unwind-libdw.c b/tools/perf/arch/loongarch/util/unwind-libdw.c
> index 7b3b9a4b21f8f482..60b1144bedd5f325 100644
> --- a/tools/perf/arch/loongarch/util/unwind-libdw.c
> +++ b/tools/perf/arch/loongarch/util/unwind-libdw.c
> @@ -10,7 +10,7 @@
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[PERF_REG_LOONGARCH_MAX];
>
>  #define REG(r) ({                                                      \
> diff --git a/tools/perf/arch/powerpc/tests/dwarf-unwind.c b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
> index 5ecf82893b84d5c0..66af884baa660389 100644
> --- a/tools/perf/arch/powerpc/tests/dwarf-unwind.c
> +++ b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
> @@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
>  int test__arch_unwind_sample(struct perf_sample *sample,
>                              struct thread *thread)
>  {
> -       struct regs_dump *regs = &sample->user_regs;
> +       struct regs_dump *regs = perf_sample__user_regs(sample);
>         u64 *buf;
>
>         buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
> diff --git a/tools/perf/arch/powerpc/util/unwind-libdw.c b/tools/perf/arch/powerpc/util/unwind-libdw.c
> index e9a5a8bb67d9186e..82d0c28ae3459ecd 100644
> --- a/tools/perf/arch/powerpc/util/unwind-libdw.c
> +++ b/tools/perf/arch/powerpc/util/unwind-libdw.c
> @@ -16,7 +16,7 @@ static const int special_regs[3][2] = {
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[32], dwarf_nip;
>         size_t i;
>
> diff --git a/tools/perf/arch/riscv/util/unwind-libdw.c b/tools/perf/arch/riscv/util/unwind-libdw.c
> index 5c98010d8b59777f..dc1476e16321736d 100644
> --- a/tools/perf/arch/riscv/util/unwind-libdw.c
> +++ b/tools/perf/arch/riscv/util/unwind-libdw.c
> @@ -10,7 +10,7 @@
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[32];
>
>  #define REG(r) ({                                              \
> diff --git a/tools/perf/arch/s390/util/unwind-libdw.c b/tools/perf/arch/s390/util/unwind-libdw.c
> index f50fb6dbb35c5dc6..c27c7a0d1076c890 100644
> --- a/tools/perf/arch/s390/util/unwind-libdw.c
> +++ b/tools/perf/arch/s390/util/unwind-libdw.c
> @@ -11,7 +11,7 @@
>  bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
>  {
>         struct unwind_info *ui = arg;
> -       struct regs_dump *user_regs = &ui->sample->user_regs;
> +       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
>         Dwarf_Word dwarf_regs[ARRAY_SIZE(s390_dwarf_regs)];
>
>  #define REG(r) ({                                              \
> --
> 2.48.1.601.g30ceb7b040-goog
>
Re: [PATCH v2] perf tools: Fix compile error on sample->user_regs
Posted by Namhyung Kim 10 months, 1 week ago
On Fri, Feb 14, 2025 at 11:50:42AM -0800, Ian Rogers wrote:
> On Fri, Feb 14, 2025 at 11:16 AM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > It's recently changed to allocate dynamically but misses to update some
> > arch-dependent codes to use perf_sample__user_regs().
> >
> > Fixes: dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> 
> Thanks for this! My tag in case it is useful:
> Reviewed-by: Ian Rogers <irogers@google.com>

Sure, thanks for the review.

> 
> Would be nice to have asan testing to make sure there are arch
> dependent memory leaks, less arch code would be nice.

Right, I need cross-arch or native non-x86 testing.

Thanks,
Namhyung