linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Support register names from all architectures
@ 2021-12-01 12:33 German Gomez
  2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: German Gomez @ 2021-12-01 12:33 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: German Gomez, John Garry, Will Deacon, Mathieu Poirier, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-arm-kernel, linux-csky, linux-riscv

The following changeset applies some corrections to the way system
registers are processed and presented when reading perf.data files using
the various perf tools.

The commit message from [4/4] shows how register names aren't correctly
presented when performing x-arch analysis of perf.data files (i.e.
recording in one arch, then reading the file from a different arch).

Please let me know if there are any concerns with this approach, or if
any improvements can be made for subsequent re-rolls of the changeset.

  - [PATCH 1/4] Fixes a potential out-of-bounds access when reading the
    values of the registers in the perf.data file.
  - [PATCH 2/4] Modifies one of the callbacks in "struct scripting_ops"
    so that the python version can obtain the correct register names.
  - [PATCH 3/4] Adds header files with the register indices and names
    from all architectures, which are used by the next patch.
  - [PATCH 4/4] Refactors the function "perf_reg_name" so that it can
    support registers from all architectures, not just the local one.

Thanks,
German

German Gomez (4):
  perf tools: Prevent out-of-bounds access to registers
  perf script: Add "struct machine" parameter to process_event callback
  perf tools: Crete header files with register names
  perf tools: Support register names from all architectures

 tools/perf/arch/arm/include/perf_regs.h       |  42 --------
 tools/perf/arch/arm64/include/perf_regs.h     |  76 -------------
 tools/perf/arch/csky/include/perf_regs.h      |  82 --------------
 tools/perf/arch/mips/include/perf_regs.h      |  69 ------------
 tools/perf/arch/powerpc/include/perf_regs.h   |  66 ------------
 tools/perf/arch/riscv/include/perf_regs.h     |  74 -------------
 tools/perf/arch/s390/include/perf_regs.h      |  78 --------------
 tools/perf/arch/x86/include/perf_regs.h       |  82 --------------
 tools/perf/builtin-script.c                   |  26 ++---
 tools/perf/util/event.h                       |   5 +-
 tools/perf/util/perf_regs.c                   |   3 +
 tools/perf/util/perf_regs.h                   |  33 +++++-
 tools/perf/util/perf_regs_arm.h               |  57 ++++++++++
 tools/perf/util/perf_regs_arm64.h             |  83 ++++++++++++++
 tools/perf/util/perf_regs_csky.h              | 101 ++++++++++++++++++
 tools/perf/util/perf_regs_mips.h              |  76 +++++++++++++
 tools/perf/util/perf_regs_powerpc.h           |  74 +++++++++++++
 tools/perf/util/perf_regs_riscv.h             |  81 ++++++++++++++
 tools/perf/util/perf_regs_s390.h              |  85 +++++++++++++++
 tools/perf/util/perf_regs_x86.h               |  87 +++++++++++++++
 .../util/scripting-engines/trace-event-perl.c |   3 +-
 .../scripting-engines/trace-event-python.c    |  33 +++---
 tools/perf/util/session.c                     |  25 ++---
 tools/perf/util/trace-event-scripting.c       |   3 +-
 tools/perf/util/trace-event.h                 |   3 +-
 25 files changed, 733 insertions(+), 614 deletions(-)
 create mode 100644 tools/perf/util/perf_regs_arm.h
 create mode 100644 tools/perf/util/perf_regs_arm64.h
 create mode 100644 tools/perf/util/perf_regs_csky.h
 create mode 100644 tools/perf/util/perf_regs_mips.h
 create mode 100644 tools/perf/util/perf_regs_powerpc.h
 create mode 100644 tools/perf/util/perf_regs_riscv.h
 create mode 100644 tools/perf/util/perf_regs_s390.h
 create mode 100644 tools/perf/util/perf_regs_x86.h

-- 
2.25.1


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

* [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-01 12:33 [PATCH v1 0/4] Support register names from all architectures German Gomez
@ 2021-12-01 12:33 ` German Gomez
  2021-12-08 21:35   ` Jiri Olsa
  2021-12-10  9:17   ` kajoljain
  2021-12-01 12:33 ` [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback German Gomez
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: German Gomez @ 2021-12-01 12:33 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: German Gomez, John Garry, Will Deacon, Mathieu Poirier, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-arm-kernel, linux-csky, linux-riscv

The size of the cache of register values is arch-dependant
(PERF_REGS_MAX). This has the potential of causing an out-of-bounds
access in the function "perf_reg_value" if the local architecture
contains less registers than the one the perf.data file was recorded on.

Since the maximum number of registers is bound by the bitmask "u64
cache_mask", and the size of the cache when running under x86 systems is
64 already, fix the size to 64 and add a range-check to the function
"perf_reg_value" to prevent out-of-bounds access.

Signed-off-by: German Gomez <german.gomez@arm.com>
---
 tools/perf/util/event.h     | 5 ++++-
 tools/perf/util/perf_regs.c | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 95ffed663..c59331eea 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -44,13 +44,16 @@ struct perf_event_attr;
 /* perf sample has 16 bits size limit */
 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
 
+/* number of register is bound by the number of bits in regs_dump::mask (64) */
+#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
+
 struct regs_dump {
 	u64 abi;
 	u64 mask;
 	u64 *regs;
 
 	/* Cached values/mask filled by first register access. */
-	u64 cache_regs[PERF_REGS_MAX];
+	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
 	u64 cache_mask;
 };
 
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index 5ee47ae15..06a7461ba 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
 	int i, idx = 0;
 	u64 mask = regs->mask;
 
+	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
+		return -EINVAL;
+
 	if (regs->cache_mask & (1ULL << id))
 		goto out;
 
-- 
2.25.1


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

* [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-01 12:33 [PATCH v1 0/4] Support register names from all architectures German Gomez
  2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
@ 2021-12-01 12:33 ` German Gomez
  2021-12-02 16:03   ` Athira Rajeev
  2021-12-01 12:33 ` [PATCH v1 3/4] perf tools: Crete header files with register names German Gomez
  2021-12-01 12:33 ` [PATCH v1 4/4] perf tools: Support register names from all architectures German Gomez
  3 siblings, 1 reply; 16+ messages in thread
From: German Gomez @ 2021-12-01 12:33 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: German Gomez, John Garry, Will Deacon, Mathieu Poirier, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-arm-kernel, linux-csky, linux-riscv

Include a "struct machine*" parameter to the process_event callback in
the scripting layer. This will allow access to the perf_env from within
this callback.

Followup patches will build on top of this to report the correct name of
the registers in a perf.data file, consistently with the architecture
the file was recorded in.

Signed-off-by: German Gomez <german.gomez@arm.com>
---
 tools/perf/builtin-script.c                   |  2 +-
 .../util/scripting-engines/trace-event-perl.c |  3 ++-
 .../scripting-engines/trace-event-python.c    | 23 +++++++++++--------
 tools/perf/util/trace-event-scripting.c       |  3 ++-
 tools/perf/util/trace-event.h                 |  3 ++-
 5 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9434367af..711132f0b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2256,7 +2256,7 @@ static int process_sample_event(struct perf_tool *tool,
 				thread__resolve(al.thread, &addr_al, sample);
 			addr_al_ptr = &addr_al;
 		}
-		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr);
+		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr, machine);
 	} else {
 		process_event(scr, sample, evsel, &al, &addr_al, machine);
 	}
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 32a721b3e..6017c4660 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -454,7 +454,8 @@ static void perl_process_event(union perf_event *event,
 			       struct perf_sample *sample,
 			       struct evsel *evsel,
 			       struct addr_location *al,
-			       struct addr_location *addr_al)
+			       struct addr_location *addr_al,
+			       struct machine *machine __maybe_unused)
 {
 	scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
 	perl_process_tracepoint(sample, evsel, al);
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index c0c010350..e164f8d00 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -708,7 +708,8 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
 
 static void set_regs_in_dict(PyObject *dict,
 			     struct perf_sample *sample,
-			     struct evsel *evsel)
+			     struct evsel *evsel,
+			     struct machine *machine __maybe_unused)
 {
 	struct perf_event_attr *attr = &evsel->core.attr;
 
@@ -776,6 +777,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
 					 struct evsel *evsel,
 					 struct addr_location *al,
 					 struct addr_location *addr_al,
+					 struct machine *machine,
 					 PyObject *callchain)
 {
 	PyObject *dict, *dict_sample, *brstack, *brstacksym;
@@ -849,7 +851,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
 			PyLong_FromUnsignedLongLong(sample->cyc_cnt));
 	}
 
-	set_regs_in_dict(dict, sample, evsel);
+	set_regs_in_dict(dict, sample, evsel, machine);
 
 	return dict;
 }
@@ -857,7 +859,8 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
 static void python_process_tracepoint(struct perf_sample *sample,
 				      struct evsel *evsel,
 				      struct addr_location *al,
-				      struct addr_location *addr_al)
+				      struct addr_location *addr_al,
+				      struct machine *machine)
 {
 	struct tep_event *event = evsel->tp_format;
 	PyObject *handler, *context, *t, *obj = NULL, *callchain;
@@ -964,7 +967,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
 		PyTuple_SetItem(t, n++, dict);
 
 	if (get_argument_count(handler) == (int) n + 1) {
-		all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al,
+		all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, machine,
 			callchain);
 		PyTuple_SetItem(t, n++,	all_entries_dict);
 	} else {
@@ -1366,7 +1369,8 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id,
 static void python_process_general_event(struct perf_sample *sample,
 					 struct evsel *evsel,
 					 struct addr_location *al,
-					 struct addr_location *addr_al)
+					 struct addr_location *addr_al,
+					 struct machine *machine)
 {
 	PyObject *handler, *t, *dict, *callchain;
 	static char handler_name[64];
@@ -1388,7 +1392,7 @@ static void python_process_general_event(struct perf_sample *sample,
 
 	/* ip unwinding */
 	callchain = python_process_callchain(sample, evsel, al);
-	dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain);
+	dict = get_perf_sample_dict(sample, evsel, al, addr_al, machine, callchain);
 
 	PyTuple_SetItem(t, n++, dict);
 	if (_PyTuple_Resize(&t, n) == -1)
@@ -1403,7 +1407,8 @@ static void python_process_event(union perf_event *event,
 				 struct perf_sample *sample,
 				 struct evsel *evsel,
 				 struct addr_location *al,
-				 struct addr_location *addr_al)
+				 struct addr_location *addr_al,
+				 struct machine *machine)
 {
 	struct tables *tables = &tables_global;
 
@@ -1411,14 +1416,14 @@ static void python_process_event(union perf_event *event,
 
 	switch (evsel->core.attr.type) {
 	case PERF_TYPE_TRACEPOINT:
-		python_process_tracepoint(sample, evsel, al, addr_al);
+		python_process_tracepoint(sample, evsel, al, addr_al, machine);
 		break;
 	/* Reserve for future process_hw/sw/raw APIs */
 	default:
 		if (tables->db_export_mode)
 			db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al);
 		else
-			python_process_general_event(sample, evsel, al, addr_al);
+			python_process_general_event(sample, evsel, al, addr_al, machine);
 	}
 }
 
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 7172ca052..089a2c905 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -51,7 +51,8 @@ static void process_event_unsupported(union perf_event *event __maybe_unused,
 				      struct perf_sample *sample __maybe_unused,
 				      struct evsel *evsel __maybe_unused,
 				      struct addr_location *al __maybe_unused,
-				      struct addr_location *addr_al __maybe_unused)
+				      struct addr_location *addr_al __maybe_unused,
+				      struct machine *machine __maybe_unused)
 {
 }
 
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 640981105..6f5b1a6d5 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -81,7 +81,8 @@ struct scripting_ops {
 			       struct perf_sample *sample,
 			       struct evsel *evsel,
 			       struct addr_location *al,
-			       struct addr_location *addr_al);
+			       struct addr_location *addr_al,
+			       struct machine *machine);
 	void (*process_switch)(union perf_event *event,
 			       struct perf_sample *sample,
 			       struct machine *machine);
-- 
2.25.1


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

* [PATCH v1 3/4] perf tools: Crete header files with register names
  2021-12-01 12:33 [PATCH v1 0/4] Support register names from all architectures German Gomez
  2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
  2021-12-01 12:33 ` [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback German Gomez
@ 2021-12-01 12:33 ` German Gomez
  2021-12-01 12:33 ` [PATCH v1 4/4] perf tools: Support register names from all architectures German Gomez
  3 siblings, 0 replies; 16+ messages in thread
From: German Gomez @ 2021-12-01 12:33 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: German Gomez, John Garry, Will Deacon, Mathieu Poirier, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-arm-kernel, linux-csky, linux-riscv

This patch adds C headers containing the names of the registers of all
architectures (that currently support registers in perf).

A followup patch will re-implement the function "perf_reg_name" using
this headers to display register names consistent with the achitecture
of the perf.data files.

Signed-off-by: German Gomez <german.gomez@arm.com>
---
 tools/perf/util/perf_regs_arm.h     |  57 ++++++++++++++++
 tools/perf/util/perf_regs_arm64.h   |  83 +++++++++++++++++++++++
 tools/perf/util/perf_regs_csky.h    | 101 ++++++++++++++++++++++++++++
 tools/perf/util/perf_regs_mips.h    |  76 +++++++++++++++++++++
 tools/perf/util/perf_regs_powerpc.h |  74 ++++++++++++++++++++
 tools/perf/util/perf_regs_riscv.h   |  81 ++++++++++++++++++++++
 tools/perf/util/perf_regs_s390.h    |  85 +++++++++++++++++++++++
 tools/perf/util/perf_regs_x86.h     |  87 ++++++++++++++++++++++++
 8 files changed, 644 insertions(+)
 create mode 100644 tools/perf/util/perf_regs_arm.h
 create mode 100644 tools/perf/util/perf_regs_arm64.h
 create mode 100644 tools/perf/util/perf_regs_csky.h
 create mode 100644 tools/perf/util/perf_regs_mips.h
 create mode 100644 tools/perf/util/perf_regs_powerpc.h
 create mode 100644 tools/perf/util/perf_regs_riscv.h
 create mode 100644 tools/perf/util/perf_regs_s390.h
 create mode 100644 tools/perf/util/perf_regs_x86.h

diff --git a/tools/perf/util/perf_regs_arm.h b/tools/perf/util/perf_regs_arm.h
new file mode 100644
index 000000000..779b40d6c
--- /dev/null
+++ b/tools/perf/util/perf_regs_arm.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_ARM_H
+#define __PERF_REGS_ARM_H
+
+/*
+ * ARM and ARM64 registers are grouped under enums of the same name.
+ * Temporarily rename the name of the enum to prevent the naming collision.
+ */
+#define perf_event_arm_regs perf_event_arm_regs_workaround
+
+#include "../../arch/arm/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_arm(int id)
+{
+	switch (id) {
+	case PERF_REG_ARM_R0:
+		return "r0";
+	case PERF_REG_ARM_R1:
+		return "r1";
+	case PERF_REG_ARM_R2:
+		return "r2";
+	case PERF_REG_ARM_R3:
+		return "r3";
+	case PERF_REG_ARM_R4:
+		return "r4";
+	case PERF_REG_ARM_R5:
+		return "r5";
+	case PERF_REG_ARM_R6:
+		return "r6";
+	case PERF_REG_ARM_R7:
+		return "r7";
+	case PERF_REG_ARM_R8:
+		return "r8";
+	case PERF_REG_ARM_R9:
+		return "r9";
+	case PERF_REG_ARM_R10:
+		return "r10";
+	case PERF_REG_ARM_FP:
+		return "fp";
+	case PERF_REG_ARM_IP:
+		return "ip";
+	case PERF_REG_ARM_SP:
+		return "sp";
+	case PERF_REG_ARM_LR:
+		return "lr";
+	case PERF_REG_ARM_PC:
+		return "pc";
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#undef perf_event_arm_regs
+
+#endif /* __PERF_REGS_ARM_H */
diff --git a/tools/perf/util/perf_regs_arm64.h b/tools/perf/util/perf_regs_arm64.h
new file mode 100644
index 000000000..422a1db03
--- /dev/null
+++ b/tools/perf/util/perf_regs_arm64.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_ARM64_H
+#define __PERF_REGS_ARM64_H
+
+#include "../../arch/arm64/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_arm64(int id)
+{
+	switch (id) {
+	case PERF_REG_ARM64_X0:
+		return "x0";
+	case PERF_REG_ARM64_X1:
+		return "x1";
+	case PERF_REG_ARM64_X2:
+		return "x2";
+	case PERF_REG_ARM64_X3:
+		return "x3";
+	case PERF_REG_ARM64_X4:
+		return "x4";
+	case PERF_REG_ARM64_X5:
+		return "x5";
+	case PERF_REG_ARM64_X6:
+		return "x6";
+	case PERF_REG_ARM64_X7:
+		return "x7";
+	case PERF_REG_ARM64_X8:
+		return "x8";
+	case PERF_REG_ARM64_X9:
+		return "x9";
+	case PERF_REG_ARM64_X10:
+		return "x10";
+	case PERF_REG_ARM64_X11:
+		return "x11";
+	case PERF_REG_ARM64_X12:
+		return "x12";
+	case PERF_REG_ARM64_X13:
+		return "x13";
+	case PERF_REG_ARM64_X14:
+		return "x14";
+	case PERF_REG_ARM64_X15:
+		return "x15";
+	case PERF_REG_ARM64_X16:
+		return "x16";
+	case PERF_REG_ARM64_X17:
+		return "x17";
+	case PERF_REG_ARM64_X18:
+		return "x18";
+	case PERF_REG_ARM64_X19:
+		return "x19";
+	case PERF_REG_ARM64_X20:
+		return "x20";
+	case PERF_REG_ARM64_X21:
+		return "x21";
+	case PERF_REG_ARM64_X22:
+		return "x22";
+	case PERF_REG_ARM64_X23:
+		return "x23";
+	case PERF_REG_ARM64_X24:
+		return "x24";
+	case PERF_REG_ARM64_X25:
+		return "x25";
+	case PERF_REG_ARM64_X26:
+		return "x26";
+	case PERF_REG_ARM64_X27:
+		return "x27";
+	case PERF_REG_ARM64_X28:
+		return "x28";
+	case PERF_REG_ARM64_X29:
+		return "x29";
+	case PERF_REG_ARM64_SP:
+		return "sp";
+	case PERF_REG_ARM64_LR:
+		return "lr";
+	case PERF_REG_ARM64_PC:
+		return "pc";
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#endif /* __PERF_REGS_ARM64_H */
diff --git a/tools/perf/util/perf_regs_csky.h b/tools/perf/util/perf_regs_csky.h
new file mode 100644
index 000000000..aff603300
--- /dev/null
+++ b/tools/perf/util/perf_regs_csky.h
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_CSKY_H
+#define __PERF_REGS_CSKY_H
+
+/*
+ * Temporarily define __CSKYABIV2__ as some of the registers are defined under that macro
+ * The macro will be undefined at the end of the file.
+ */
+#ifndef __CSKYABIV2__
+#define __CSKYABIV2__
+#define __CSKYABIV2__PERF_REGS__
+#endif
+
+#include "../../arch/csky/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_csky(int id)
+{
+	switch (id) {
+	case PERF_REG_CSKY_A0:
+		return "a0";
+	case PERF_REG_CSKY_A1:
+		return "a1";
+	case PERF_REG_CSKY_A2:
+		return "a2";
+	case PERF_REG_CSKY_A3:
+		return "a3";
+	case PERF_REG_CSKY_REGS0:
+		return "regs0";
+	case PERF_REG_CSKY_REGS1:
+		return "regs1";
+	case PERF_REG_CSKY_REGS2:
+		return "regs2";
+	case PERF_REG_CSKY_REGS3:
+		return "regs3";
+	case PERF_REG_CSKY_REGS4:
+		return "regs4";
+	case PERF_REG_CSKY_REGS5:
+		return "regs5";
+	case PERF_REG_CSKY_REGS6:
+		return "regs6";
+	case PERF_REG_CSKY_REGS7:
+		return "regs7";
+	case PERF_REG_CSKY_REGS8:
+		return "regs8";
+	case PERF_REG_CSKY_REGS9:
+		return "regs9";
+	case PERF_REG_CSKY_SP:
+		return "sp";
+	case PERF_REG_CSKY_LR:
+		return "lr";
+	case PERF_REG_CSKY_PC:
+		return "pc";
+	case PERF_REG_CSKY_EXREGS0:
+		return "exregs0";
+	case PERF_REG_CSKY_EXREGS1:
+		return "exregs1";
+	case PERF_REG_CSKY_EXREGS2:
+		return "exregs2";
+	case PERF_REG_CSKY_EXREGS3:
+		return "exregs3";
+	case PERF_REG_CSKY_EXREGS4:
+		return "exregs4";
+	case PERF_REG_CSKY_EXREGS5:
+		return "exregs5";
+	case PERF_REG_CSKY_EXREGS6:
+		return "exregs6";
+	case PERF_REG_CSKY_EXREGS7:
+		return "exregs7";
+	case PERF_REG_CSKY_EXREGS8:
+		return "exregs8";
+	case PERF_REG_CSKY_EXREGS9:
+		return "exregs9";
+	case PERF_REG_CSKY_EXREGS10:
+		return "exregs10";
+	case PERF_REG_CSKY_EXREGS11:
+		return "exregs11";
+	case PERF_REG_CSKY_EXREGS12:
+		return "exregs12";
+	case PERF_REG_CSKY_EXREGS13:
+		return "exregs13";
+	case PERF_REG_CSKY_EXREGS14:
+		return "exregs14";
+	case PERF_REG_CSKY_TLS:
+		return "tls";
+	case PERF_REG_CSKY_HI:
+		return "hi";
+	case PERF_REG_CSKY_LO:
+		return "lo";
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#ifdef __CSKYABIV2__PERF_REGS__
+#undef __CSKYABIV2__
+#undef __CSKYABIV2__PERF_REGS__
+#endif
+
+#endif /* __PERF_REGS_CSKY_H */
diff --git a/tools/perf/util/perf_regs_mips.h b/tools/perf/util/perf_regs_mips.h
new file mode 100644
index 000000000..32f6ac8f8
--- /dev/null
+++ b/tools/perf/util/perf_regs_mips.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_MIPS_H
+#define __PERF_REGS_MIPS_H
+
+#include "../../arch/mips/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_mips(int id)
+{
+	switch (id) {
+	case PERF_REG_MIPS_PC:
+		return "PC";
+	case PERF_REG_MIPS_R1:
+		return "$1";
+	case PERF_REG_MIPS_R2:
+		return "$2";
+	case PERF_REG_MIPS_R3:
+		return "$3";
+	case PERF_REG_MIPS_R4:
+		return "$4";
+	case PERF_REG_MIPS_R5:
+		return "$5";
+	case PERF_REG_MIPS_R6:
+		return "$6";
+	case PERF_REG_MIPS_R7:
+		return "$7";
+	case PERF_REG_MIPS_R8:
+		return "$8";
+	case PERF_REG_MIPS_R9:
+		return "$9";
+	case PERF_REG_MIPS_R10:
+		return "$10";
+	case PERF_REG_MIPS_R11:
+		return "$11";
+	case PERF_REG_MIPS_R12:
+		return "$12";
+	case PERF_REG_MIPS_R13:
+		return "$13";
+	case PERF_REG_MIPS_R14:
+		return "$14";
+	case PERF_REG_MIPS_R15:
+		return "$15";
+	case PERF_REG_MIPS_R16:
+		return "$16";
+	case PERF_REG_MIPS_R17:
+		return "$17";
+	case PERF_REG_MIPS_R18:
+		return "$18";
+	case PERF_REG_MIPS_R19:
+		return "$19";
+	case PERF_REG_MIPS_R20:
+		return "$20";
+	case PERF_REG_MIPS_R21:
+		return "$21";
+	case PERF_REG_MIPS_R22:
+		return "$22";
+	case PERF_REG_MIPS_R23:
+		return "$23";
+	case PERF_REG_MIPS_R24:
+		return "$24";
+	case PERF_REG_MIPS_R25:
+		return "$25";
+	case PERF_REG_MIPS_R28:
+		return "$28";
+	case PERF_REG_MIPS_R29:
+		return "$29";
+	case PERF_REG_MIPS_R30:
+		return "$30";
+	case PERF_REG_MIPS_R31:
+		return "$31";
+	default:
+		break;
+	}
+	return NULL;
+}
+
+#endif /* __PERF_REGS_MIPS_H */
diff --git a/tools/perf/util/perf_regs_powerpc.h b/tools/perf/util/perf_regs_powerpc.h
new file mode 100644
index 000000000..ed6473f52
--- /dev/null
+++ b/tools/perf/util/perf_regs_powerpc.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_POWERPC_H
+#define __PERF_REGS_POWERPC_H
+
+#include "../../arch/powerpc/include/uapi/asm/perf_regs.h"
+
+static const char *perf_regs_powerpc_reg_names[] = {
+	[PERF_REG_POWERPC_R0] = "r0",
+	[PERF_REG_POWERPC_R1] = "r1",
+	[PERF_REG_POWERPC_R2] = "r2",
+	[PERF_REG_POWERPC_R3] = "r3",
+	[PERF_REG_POWERPC_R4] = "r4",
+	[PERF_REG_POWERPC_R5] = "r5",
+	[PERF_REG_POWERPC_R6] = "r6",
+	[PERF_REG_POWERPC_R7] = "r7",
+	[PERF_REG_POWERPC_R8] = "r8",
+	[PERF_REG_POWERPC_R9] = "r9",
+	[PERF_REG_POWERPC_R10] = "r10",
+	[PERF_REG_POWERPC_R11] = "r11",
+	[PERF_REG_POWERPC_R12] = "r12",
+	[PERF_REG_POWERPC_R13] = "r13",
+	[PERF_REG_POWERPC_R14] = "r14",
+	[PERF_REG_POWERPC_R15] = "r15",
+	[PERF_REG_POWERPC_R16] = "r16",
+	[PERF_REG_POWERPC_R17] = "r17",
+	[PERF_REG_POWERPC_R18] = "r18",
+	[PERF_REG_POWERPC_R19] = "r19",
+	[PERF_REG_POWERPC_R20] = "r20",
+	[PERF_REG_POWERPC_R21] = "r21",
+	[PERF_REG_POWERPC_R22] = "r22",
+	[PERF_REG_POWERPC_R23] = "r23",
+	[PERF_REG_POWERPC_R24] = "r24",
+	[PERF_REG_POWERPC_R25] = "r25",
+	[PERF_REG_POWERPC_R26] = "r26",
+	[PERF_REG_POWERPC_R27] = "r27",
+	[PERF_REG_POWERPC_R28] = "r28",
+	[PERF_REG_POWERPC_R29] = "r29",
+	[PERF_REG_POWERPC_R30] = "r30",
+	[PERF_REG_POWERPC_R31] = "r31",
+	[PERF_REG_POWERPC_NIP] = "nip",
+	[PERF_REG_POWERPC_MSR] = "msr",
+	[PERF_REG_POWERPC_ORIG_R3] = "orig_r3",
+	[PERF_REG_POWERPC_CTR] = "ctr",
+	[PERF_REG_POWERPC_LINK] = "link",
+	[PERF_REG_POWERPC_XER] = "xer",
+	[PERF_REG_POWERPC_CCR] = "ccr",
+	[PERF_REG_POWERPC_SOFTE] = "softe",
+	[PERF_REG_POWERPC_TRAP] = "trap",
+	[PERF_REG_POWERPC_DAR] = "dar",
+	[PERF_REG_POWERPC_DSISR] = "dsisr",
+	[PERF_REG_POWERPC_SIER] = "sier",
+	[PERF_REG_POWERPC_MMCRA] = "mmcra",
+	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
+	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
+	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
+	[PERF_REG_POWERPC_MMCR3] = "mmcr3",
+	[PERF_REG_POWERPC_SIER2] = "sier2",
+	[PERF_REG_POWERPC_SIER3] = "sier3",
+	[PERF_REG_POWERPC_PMC1] = "pmc1",
+	[PERF_REG_POWERPC_PMC2] = "pmc2",
+	[PERF_REG_POWERPC_PMC3] = "pmc3",
+	[PERF_REG_POWERPC_PMC4] = "pmc4",
+	[PERF_REG_POWERPC_PMC5] = "pmc5",
+	[PERF_REG_POWERPC_PMC6] = "pmc6",
+	[PERF_REG_POWERPC_SDAR] = "sdar",
+	[PERF_REG_POWERPC_SIAR] = "siar",
+};
+
+static inline const char *__perf_reg_name_powerpc(int id)
+{
+	return perf_regs_powerpc_reg_names[id];
+}
+
+#endif /* __PERF_REGS_POWERPC_H */
diff --git a/tools/perf/util/perf_regs_riscv.h b/tools/perf/util/perf_regs_riscv.h
new file mode 100644
index 000000000..6e784c40a
--- /dev/null
+++ b/tools/perf/util/perf_regs_riscv.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_RISCV_H
+#define __PERF_REGS_RISCV_H
+
+#include "../../arch/riscv/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_riscv(int id)
+{
+	switch (id) {
+	case PERF_REG_RISCV_PC:
+		return "pc";
+	case PERF_REG_RISCV_RA:
+		return "ra";
+	case PERF_REG_RISCV_SP:
+		return "sp";
+	case PERF_REG_RISCV_GP:
+		return "gp";
+	case PERF_REG_RISCV_TP:
+		return "tp";
+	case PERF_REG_RISCV_T0:
+		return "t0";
+	case PERF_REG_RISCV_T1:
+		return "t1";
+	case PERF_REG_RISCV_T2:
+		return "t2";
+	case PERF_REG_RISCV_S0:
+		return "s0";
+	case PERF_REG_RISCV_S1:
+		return "s1";
+	case PERF_REG_RISCV_A0:
+		return "a0";
+	case PERF_REG_RISCV_A1:
+		return "a1";
+	case PERF_REG_RISCV_A2:
+		return "a2";
+	case PERF_REG_RISCV_A3:
+		return "a3";
+	case PERF_REG_RISCV_A4:
+		return "a4";
+	case PERF_REG_RISCV_A5:
+		return "a5";
+	case PERF_REG_RISCV_A6:
+		return "a6";
+	case PERF_REG_RISCV_A7:
+		return "a7";
+	case PERF_REG_RISCV_S2:
+		return "s2";
+	case PERF_REG_RISCV_S3:
+		return "s3";
+	case PERF_REG_RISCV_S4:
+		return "s4";
+	case PERF_REG_RISCV_S5:
+		return "s5";
+	case PERF_REG_RISCV_S6:
+		return "s6";
+	case PERF_REG_RISCV_S7:
+		return "s7";
+	case PERF_REG_RISCV_S8:
+		return "s8";
+	case PERF_REG_RISCV_S9:
+		return "s9";
+	case PERF_REG_RISCV_S10:
+		return "s10";
+	case PERF_REG_RISCV_S11:
+		return "s11";
+	case PERF_REG_RISCV_T3:
+		return "t3";
+	case PERF_REG_RISCV_T4:
+		return "t4";
+	case PERF_REG_RISCV_T5:
+		return "t5";
+	case PERF_REG_RISCV_T6:
+		return "t6";
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#endif /* __PERF_REGS_RISCV_H */
diff --git a/tools/perf/util/perf_regs_s390.h b/tools/perf/util/perf_regs_s390.h
new file mode 100644
index 000000000..3b2397ece
--- /dev/null
+++ b/tools/perf/util/perf_regs_s390.h
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_S390_H
+#define __PERF_REGS_S390_H
+
+#include "../../arch/s390/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_s390(int id)
+{
+	switch (id) {
+	case PERF_REG_S390_R0:
+		return "R0";
+	case PERF_REG_S390_R1:
+		return "R1";
+	case PERF_REG_S390_R2:
+		return "R2";
+	case PERF_REG_S390_R3:
+		return "R3";
+	case PERF_REG_S390_R4:
+		return "R4";
+	case PERF_REG_S390_R5:
+		return "R5";
+	case PERF_REG_S390_R6:
+		return "R6";
+	case PERF_REG_S390_R7:
+		return "R7";
+	case PERF_REG_S390_R8:
+		return "R8";
+	case PERF_REG_S390_R9:
+		return "R9";
+	case PERF_REG_S390_R10:
+		return "R10";
+	case PERF_REG_S390_R11:
+		return "R11";
+	case PERF_REG_S390_R12:
+		return "R12";
+	case PERF_REG_S390_R13:
+		return "R13";
+	case PERF_REG_S390_R14:
+		return "R14";
+	case PERF_REG_S390_R15:
+		return "R15";
+	case PERF_REG_S390_FP0:
+		return "FP0";
+	case PERF_REG_S390_FP1:
+		return "FP1";
+	case PERF_REG_S390_FP2:
+		return "FP2";
+	case PERF_REG_S390_FP3:
+		return "FP3";
+	case PERF_REG_S390_FP4:
+		return "FP4";
+	case PERF_REG_S390_FP5:
+		return "FP5";
+	case PERF_REG_S390_FP6:
+		return "FP6";
+	case PERF_REG_S390_FP7:
+		return "FP7";
+	case PERF_REG_S390_FP8:
+		return "FP8";
+	case PERF_REG_S390_FP9:
+		return "FP9";
+	case PERF_REG_S390_FP10:
+		return "FP10";
+	case PERF_REG_S390_FP11:
+		return "FP11";
+	case PERF_REG_S390_FP12:
+		return "FP12";
+	case PERF_REG_S390_FP13:
+		return "FP13";
+	case PERF_REG_S390_FP14:
+		return "FP14";
+	case PERF_REG_S390_FP15:
+		return "FP15";
+	case PERF_REG_S390_MASK:
+		return "MASK";
+	case PERF_REG_S390_PC:
+		return "PC";
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#endif /* __PERF_REGS_S390_H */
diff --git a/tools/perf/util/perf_regs_x86.h b/tools/perf/util/perf_regs_x86.h
new file mode 100644
index 000000000..27432599a
--- /dev/null
+++ b/tools/perf/util/perf_regs_x86.h
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_X86_H
+#define __PERF_REGS_X86_H
+
+#include "../../arch/x86/include/uapi/asm/perf_regs.h"
+
+static inline const char *__perf_reg_name_x86(int id)
+{
+	switch (id) {
+	case PERF_REG_X86_AX:
+		return "AX";
+	case PERF_REG_X86_BX:
+		return "BX";
+	case PERF_REG_X86_CX:
+		return "CX";
+	case PERF_REG_X86_DX:
+		return "DX";
+	case PERF_REG_X86_SI:
+		return "SI";
+	case PERF_REG_X86_DI:
+		return "DI";
+	case PERF_REG_X86_BP:
+		return "BP";
+	case PERF_REG_X86_SP:
+		return "SP";
+	case PERF_REG_X86_IP:
+		return "IP";
+	case PERF_REG_X86_FLAGS:
+		return "FLAGS";
+	case PERF_REG_X86_CS:
+		return "CS";
+	case PERF_REG_X86_SS:
+		return "SS";
+	case PERF_REG_X86_DS:
+		return "DS";
+	case PERF_REG_X86_ES:
+		return "ES";
+	case PERF_REG_X86_FS:
+		return "FS";
+	case PERF_REG_X86_GS:
+		return "GS";
+	case PERF_REG_X86_R8:
+		return "R8";
+	case PERF_REG_X86_R9:
+		return "R9";
+	case PERF_REG_X86_R10:
+		return "R10";
+	case PERF_REG_X86_R11:
+		return "R11";
+	case PERF_REG_X86_R12:
+		return "R12";
+	case PERF_REG_X86_R13:
+		return "R13";
+	case PERF_REG_X86_R14:
+		return "R14";
+	case PERF_REG_X86_R15:
+		return "R15";
+
+#define XMM(x) \
+	case PERF_REG_X86_XMM ## x:	\
+	case PERF_REG_X86_XMM ## x + 1:	\
+		return "XMM" #x;
+	XMM(0)
+	XMM(1)
+	XMM(2)
+	XMM(3)
+	XMM(4)
+	XMM(5)
+	XMM(6)
+	XMM(7)
+	XMM(8)
+	XMM(9)
+	XMM(10)
+	XMM(11)
+	XMM(12)
+	XMM(13)
+	XMM(14)
+	XMM(15)
+#undef XMM
+	default:
+		return NULL;
+	}
+
+	return NULL;
+}
+
+#endif /* __PERF_REGS_X86_H */
\ No newline at end of file
-- 
2.25.1


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

* [PATCH v1 4/4] perf tools: Support register names from all architectures
  2021-12-01 12:33 [PATCH v1 0/4] Support register names from all architectures German Gomez
                   ` (2 preceding siblings ...)
  2021-12-01 12:33 ` [PATCH v1 3/4] perf tools: Crete header files with register names German Gomez
@ 2021-12-01 12:33 ` German Gomez
  2021-12-03  9:38   ` German Gomez
  3 siblings, 1 reply; 16+ messages in thread
From: German Gomez @ 2021-12-01 12:33 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: German Gomez, John Garry, Will Deacon, Mathieu Poirier, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-arm-kernel, linux-csky, linux-riscv

When reading a perf.data file with register values, there is a mismatch
between the names and the values of the registers because the tool is
built using only the register names from the local architecture.

Reading a perf.data file that was recorded on Arm64, gives the following
erroneous output on an x86 machine:

  # perf report -i perf_arm64.data -D
  [...]
  24661932634451 0x698 [0x21d0]: PERF_RECORD_SAMPLE(IP, 0x1): 43239/43239: 0xffffc5be8f100f98 period: 1 addr: 0
  ... user regs: mask 0x1ffffffff ABI 64-bit
  .... AX    0x0000ffffd1515817
  .... BX    0x0000ffffd1515480
  .... CX    0x0000aaaadabf6c80
  .... DX    0x000000000000002e
  .... SI    0x0000000040100401
  .... DI    0x0040600200000080
  .... BP    0x0000ffffd1510e10
  .... SP    0x0000000000000000
  .... IP    0x00000000000000dd
  .... FLAGS 0x0000ffffd1510cd0
  .... CS    0x0000000000000000
  .... SS    0x0000000000000030
  .... DS    0x0000ffffa569a208
  .... ES    0x0000000000000000
  .... FS    0x0000000000000000
  .... GS    0x0000000000000000
  .... R8    0x0000aaaad3de9650
  .... R9    0x0000ffffa57397f0
  .... R10   0x0000000000000001
  .... R11   0x0000ffffa57fd000
  .... R12   0x0000ffffd1515817
  .... R13   0x0000ffffd1515480
  .... R14   0x0000aaaadabf6c80
  .... R15   0x0000000000000000
  .... unknown 0x0000000000000001
  .... unknown 0x0000000000000000
  .... unknown 0x0000000000000000
  .... unknown 0x0000000000000000
  .... unknown 0x0000000000000000
  .... unknown 0x0000ffffd1510d90
  .... unknown 0x0000ffffa5739b90
  .... unknown 0x0000ffffd1510d80
  .... XMM0  0x0000ffffa57392c8
   ... thread: perf-exec:43239
   ...... dso: [kernel.kallsyms]

As can be seen, the register names correspond to x86 registers, even
though the perf.data file was recorded on an Arm64 system. After this
patch, the output of the command displays the correct register names:

  # perf report -i perf_arm64.data -D
  [...]
  24661932634451 0x698 [0x21d0]: PERF_RECORD_SAMPLE(IP, 0x1): 43239/43239: 0xffffc5be8f100f98 period: 1 addr: 0
  ... user regs: mask 0x1ffffffff ABI 64-bit
  .... x0    0x0000ffffd1515817
  .... x1    0x0000ffffd1515480
  .... x2    0x0000aaaadabf6c80
  .... x3    0x000000000000002e
  .... x4    0x0000000040100401
  .... x5    0x0040600200000080
  .... x6    0x0000ffffd1510e10
  .... x7    0x0000000000000000
  .... x8    0x00000000000000dd
  .... x9    0x0000ffffd1510cd0
  .... x10   0x0000000000000000
  .... x11   0x0000000000000030
  .... x12   0x0000ffffa569a208
  .... x13   0x0000000000000000
  .... x14   0x0000000000000000
  .... x15   0x0000000000000000
  .... x16   0x0000aaaad3de9650
  .... x17   0x0000ffffa57397f0
  .... x18   0x0000000000000001
  .... x19   0x0000ffffa57fd000
  .... x20   0x0000ffffd1515817
  .... x21   0x0000ffffd1515480
  .... x22   0x0000aaaadabf6c80
  .... x23   0x0000000000000000
  .... x24   0x0000000000000001
  .... x25   0x0000000000000000
  .... x26   0x0000000000000000
  .... x27   0x0000000000000000
  .... x28   0x0000000000000000
  .... x29   0x0000ffffd1510d90
  .... lr    0x0000ffffa5739b90
  .... sp    0x0000ffffd1510d80
  .... pc    0x0000ffffa57392c8
   ... thread: perf-exec:43239
   ...... dso: [kernel.kallsyms]

Signed-off-by: German Gomez <german.gomez@arm.com>
---
 tools/perf/arch/arm/include/perf_regs.h       | 42 ----------
 tools/perf/arch/arm64/include/perf_regs.h     | 76 -----------------
 tools/perf/arch/csky/include/perf_regs.h      | 82 -------------------
 tools/perf/arch/mips/include/perf_regs.h      | 69 ----------------
 tools/perf/arch/powerpc/include/perf_regs.h   | 66 ---------------
 tools/perf/arch/riscv/include/perf_regs.h     | 74 -----------------
 tools/perf/arch/s390/include/perf_regs.h      | 78 ------------------
 tools/perf/arch/x86/include/perf_regs.h       | 82 -------------------
 tools/perf/builtin-script.c                   | 24 +++---
 tools/perf/util/perf_regs.h                   | 33 +++++++-
 .../scripting-engines/trace-event-python.c    | 12 +--
 tools/perf/util/session.c                     | 25 +++---
 12 files changed, 62 insertions(+), 601 deletions(-)

diff --git a/tools/perf/arch/arm/include/perf_regs.h b/tools/perf/arch/arm/include/perf_regs.h
index 408541928..99a06550e 100644
--- a/tools/perf/arch/arm/include/perf_regs.h
+++ b/tools/perf/arch/arm/include/perf_regs.h
@@ -15,46 +15,4 @@ void perf_regs_load(u64 *regs);
 #define PERF_REG_IP	PERF_REG_ARM_PC
 #define PERF_REG_SP	PERF_REG_ARM_SP
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_ARM_R0:
-		return "r0";
-	case PERF_REG_ARM_R1:
-		return "r1";
-	case PERF_REG_ARM_R2:
-		return "r2";
-	case PERF_REG_ARM_R3:
-		return "r3";
-	case PERF_REG_ARM_R4:
-		return "r4";
-	case PERF_REG_ARM_R5:
-		return "r5";
-	case PERF_REG_ARM_R6:
-		return "r6";
-	case PERF_REG_ARM_R7:
-		return "r7";
-	case PERF_REG_ARM_R8:
-		return "r8";
-	case PERF_REG_ARM_R9:
-		return "r9";
-	case PERF_REG_ARM_R10:
-		return "r10";
-	case PERF_REG_ARM_FP:
-		return "fp";
-	case PERF_REG_ARM_IP:
-		return "ip";
-	case PERF_REG_ARM_SP:
-		return "sp";
-	case PERF_REG_ARM_LR:
-		return "lr";
-	case PERF_REG_ARM_PC:
-		return "pc";
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/arm64/include/perf_regs.h b/tools/perf/arch/arm64/include/perf_regs.h
index fa3e07459..c4eb1dcfa 100644
--- a/tools/perf/arch/arm64/include/perf_regs.h
+++ b/tools/perf/arch/arm64/include/perf_regs.h
@@ -15,80 +15,4 @@ void perf_regs_load(u64 *regs);
 #define PERF_REG_IP	PERF_REG_ARM64_PC
 #define PERF_REG_SP	PERF_REG_ARM64_SP
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_ARM64_X0:
-		return "x0";
-	case PERF_REG_ARM64_X1:
-		return "x1";
-	case PERF_REG_ARM64_X2:
-		return "x2";
-	case PERF_REG_ARM64_X3:
-		return "x3";
-	case PERF_REG_ARM64_X4:
-		return "x4";
-	case PERF_REG_ARM64_X5:
-		return "x5";
-	case PERF_REG_ARM64_X6:
-		return "x6";
-	case PERF_REG_ARM64_X7:
-		return "x7";
-	case PERF_REG_ARM64_X8:
-		return "x8";
-	case PERF_REG_ARM64_X9:
-		return "x9";
-	case PERF_REG_ARM64_X10:
-		return "x10";
-	case PERF_REG_ARM64_X11:
-		return "x11";
-	case PERF_REG_ARM64_X12:
-		return "x12";
-	case PERF_REG_ARM64_X13:
-		return "x13";
-	case PERF_REG_ARM64_X14:
-		return "x14";
-	case PERF_REG_ARM64_X15:
-		return "x15";
-	case PERF_REG_ARM64_X16:
-		return "x16";
-	case PERF_REG_ARM64_X17:
-		return "x17";
-	case PERF_REG_ARM64_X18:
-		return "x18";
-	case PERF_REG_ARM64_X19:
-		return "x19";
-	case PERF_REG_ARM64_X20:
-		return "x20";
-	case PERF_REG_ARM64_X21:
-		return "x21";
-	case PERF_REG_ARM64_X22:
-		return "x22";
-	case PERF_REG_ARM64_X23:
-		return "x23";
-	case PERF_REG_ARM64_X24:
-		return "x24";
-	case PERF_REG_ARM64_X25:
-		return "x25";
-	case PERF_REG_ARM64_X26:
-		return "x26";
-	case PERF_REG_ARM64_X27:
-		return "x27";
-	case PERF_REG_ARM64_X28:
-		return "x28";
-	case PERF_REG_ARM64_X29:
-		return "x29";
-	case PERF_REG_ARM64_SP:
-		return "sp";
-	case PERF_REG_ARM64_LR:
-		return "lr";
-	case PERF_REG_ARM64_PC:
-		return "pc";
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/csky/include/perf_regs.h b/tools/perf/arch/csky/include/perf_regs.h
index 25ac3bdcb..1afcc0e91 100644
--- a/tools/perf/arch/csky/include/perf_regs.h
+++ b/tools/perf/arch/csky/include/perf_regs.h
@@ -15,86 +15,4 @@
 #define PERF_REG_IP	PERF_REG_CSKY_PC
 #define PERF_REG_SP	PERF_REG_CSKY_SP
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_CSKY_A0:
-		return "a0";
-	case PERF_REG_CSKY_A1:
-		return "a1";
-	case PERF_REG_CSKY_A2:
-		return "a2";
-	case PERF_REG_CSKY_A3:
-		return "a3";
-	case PERF_REG_CSKY_REGS0:
-		return "regs0";
-	case PERF_REG_CSKY_REGS1:
-		return "regs1";
-	case PERF_REG_CSKY_REGS2:
-		return "regs2";
-	case PERF_REG_CSKY_REGS3:
-		return "regs3";
-	case PERF_REG_CSKY_REGS4:
-		return "regs4";
-	case PERF_REG_CSKY_REGS5:
-		return "regs5";
-	case PERF_REG_CSKY_REGS6:
-		return "regs6";
-	case PERF_REG_CSKY_REGS7:
-		return "regs7";
-	case PERF_REG_CSKY_REGS8:
-		return "regs8";
-	case PERF_REG_CSKY_REGS9:
-		return "regs9";
-	case PERF_REG_CSKY_SP:
-		return "sp";
-	case PERF_REG_CSKY_LR:
-		return "lr";
-	case PERF_REG_CSKY_PC:
-		return "pc";
-#if defined(__CSKYABIV2__)
-	case PERF_REG_CSKY_EXREGS0:
-		return "exregs0";
-	case PERF_REG_CSKY_EXREGS1:
-		return "exregs1";
-	case PERF_REG_CSKY_EXREGS2:
-		return "exregs2";
-	case PERF_REG_CSKY_EXREGS3:
-		return "exregs3";
-	case PERF_REG_CSKY_EXREGS4:
-		return "exregs4";
-	case PERF_REG_CSKY_EXREGS5:
-		return "exregs5";
-	case PERF_REG_CSKY_EXREGS6:
-		return "exregs6";
-	case PERF_REG_CSKY_EXREGS7:
-		return "exregs7";
-	case PERF_REG_CSKY_EXREGS8:
-		return "exregs8";
-	case PERF_REG_CSKY_EXREGS9:
-		return "exregs9";
-	case PERF_REG_CSKY_EXREGS10:
-		return "exregs10";
-	case PERF_REG_CSKY_EXREGS11:
-		return "exregs11";
-	case PERF_REG_CSKY_EXREGS12:
-		return "exregs12";
-	case PERF_REG_CSKY_EXREGS13:
-		return "exregs13";
-	case PERF_REG_CSKY_EXREGS14:
-		return "exregs14";
-	case PERF_REG_CSKY_TLS:
-		return "tls";
-	case PERF_REG_CSKY_HI:
-		return "hi";
-	case PERF_REG_CSKY_LO:
-		return "lo";
-#endif
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/mips/include/perf_regs.h b/tools/perf/arch/mips/include/perf_regs.h
index ee73b36a1..b8cd8bbb3 100644
--- a/tools/perf/arch/mips/include/perf_regs.h
+++ b/tools/perf/arch/mips/include/perf_regs.h
@@ -12,73 +12,4 @@
 
 #define PERF_REGS_MASK ((1ULL << PERF_REG_MIPS_MAX) - 1)
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_MIPS_PC:
-		return "PC";
-	case PERF_REG_MIPS_R1:
-		return "$1";
-	case PERF_REG_MIPS_R2:
-		return "$2";
-	case PERF_REG_MIPS_R3:
-		return "$3";
-	case PERF_REG_MIPS_R4:
-		return "$4";
-	case PERF_REG_MIPS_R5:
-		return "$5";
-	case PERF_REG_MIPS_R6:
-		return "$6";
-	case PERF_REG_MIPS_R7:
-		return "$7";
-	case PERF_REG_MIPS_R8:
-		return "$8";
-	case PERF_REG_MIPS_R9:
-		return "$9";
-	case PERF_REG_MIPS_R10:
-		return "$10";
-	case PERF_REG_MIPS_R11:
-		return "$11";
-	case PERF_REG_MIPS_R12:
-		return "$12";
-	case PERF_REG_MIPS_R13:
-		return "$13";
-	case PERF_REG_MIPS_R14:
-		return "$14";
-	case PERF_REG_MIPS_R15:
-		return "$15";
-	case PERF_REG_MIPS_R16:
-		return "$16";
-	case PERF_REG_MIPS_R17:
-		return "$17";
-	case PERF_REG_MIPS_R18:
-		return "$18";
-	case PERF_REG_MIPS_R19:
-		return "$19";
-	case PERF_REG_MIPS_R20:
-		return "$20";
-	case PERF_REG_MIPS_R21:
-		return "$21";
-	case PERF_REG_MIPS_R22:
-		return "$22";
-	case PERF_REG_MIPS_R23:
-		return "$23";
-	case PERF_REG_MIPS_R24:
-		return "$24";
-	case PERF_REG_MIPS_R25:
-		return "$25";
-	case PERF_REG_MIPS_R28:
-		return "$28";
-	case PERF_REG_MIPS_R29:
-		return "$29";
-	case PERF_REG_MIPS_R30:
-		return "$30";
-	case PERF_REG_MIPS_R31:
-		return "$31";
-	default:
-		break;
-	}
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/powerpc/include/perf_regs.h b/tools/perf/arch/powerpc/include/perf_regs.h
index 93339d17a..9bb17c3f3 100644
--- a/tools/perf/arch/powerpc/include/perf_regs.h
+++ b/tools/perf/arch/powerpc/include/perf_regs.h
@@ -19,70 +19,4 @@ void perf_regs_load(u64 *regs);
 #define PERF_REG_IP     PERF_REG_POWERPC_NIP
 #define PERF_REG_SP     PERF_REG_POWERPC_R1
 
-static const char *reg_names[] = {
-	[PERF_REG_POWERPC_R0] = "r0",
-	[PERF_REG_POWERPC_R1] = "r1",
-	[PERF_REG_POWERPC_R2] = "r2",
-	[PERF_REG_POWERPC_R3] = "r3",
-	[PERF_REG_POWERPC_R4] = "r4",
-	[PERF_REG_POWERPC_R5] = "r5",
-	[PERF_REG_POWERPC_R6] = "r6",
-	[PERF_REG_POWERPC_R7] = "r7",
-	[PERF_REG_POWERPC_R8] = "r8",
-	[PERF_REG_POWERPC_R9] = "r9",
-	[PERF_REG_POWERPC_R10] = "r10",
-	[PERF_REG_POWERPC_R11] = "r11",
-	[PERF_REG_POWERPC_R12] = "r12",
-	[PERF_REG_POWERPC_R13] = "r13",
-	[PERF_REG_POWERPC_R14] = "r14",
-	[PERF_REG_POWERPC_R15] = "r15",
-	[PERF_REG_POWERPC_R16] = "r16",
-	[PERF_REG_POWERPC_R17] = "r17",
-	[PERF_REG_POWERPC_R18] = "r18",
-	[PERF_REG_POWERPC_R19] = "r19",
-	[PERF_REG_POWERPC_R20] = "r20",
-	[PERF_REG_POWERPC_R21] = "r21",
-	[PERF_REG_POWERPC_R22] = "r22",
-	[PERF_REG_POWERPC_R23] = "r23",
-	[PERF_REG_POWERPC_R24] = "r24",
-	[PERF_REG_POWERPC_R25] = "r25",
-	[PERF_REG_POWERPC_R26] = "r26",
-	[PERF_REG_POWERPC_R27] = "r27",
-	[PERF_REG_POWERPC_R28] = "r28",
-	[PERF_REG_POWERPC_R29] = "r29",
-	[PERF_REG_POWERPC_R30] = "r30",
-	[PERF_REG_POWERPC_R31] = "r31",
-	[PERF_REG_POWERPC_NIP] = "nip",
-	[PERF_REG_POWERPC_MSR] = "msr",
-	[PERF_REG_POWERPC_ORIG_R3] = "orig_r3",
-	[PERF_REG_POWERPC_CTR] = "ctr",
-	[PERF_REG_POWERPC_LINK] = "link",
-	[PERF_REG_POWERPC_XER] = "xer",
-	[PERF_REG_POWERPC_CCR] = "ccr",
-	[PERF_REG_POWERPC_SOFTE] = "softe",
-	[PERF_REG_POWERPC_TRAP] = "trap",
-	[PERF_REG_POWERPC_DAR] = "dar",
-	[PERF_REG_POWERPC_DSISR] = "dsisr",
-	[PERF_REG_POWERPC_SIER] = "sier",
-	[PERF_REG_POWERPC_MMCRA] = "mmcra",
-	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
-	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
-	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
-	[PERF_REG_POWERPC_MMCR3] = "mmcr3",
-	[PERF_REG_POWERPC_SIER2] = "sier2",
-	[PERF_REG_POWERPC_SIER3] = "sier3",
-	[PERF_REG_POWERPC_PMC1] = "pmc1",
-	[PERF_REG_POWERPC_PMC2] = "pmc2",
-	[PERF_REG_POWERPC_PMC3] = "pmc3",
-	[PERF_REG_POWERPC_PMC4] = "pmc4",
-	[PERF_REG_POWERPC_PMC5] = "pmc5",
-	[PERF_REG_POWERPC_PMC6] = "pmc6",
-	[PERF_REG_POWERPC_SDAR] = "sdar",
-	[PERF_REG_POWERPC_SIAR] = "siar",
-};
-
-static inline const char *__perf_reg_name(int id)
-{
-	return reg_names[id];
-}
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/riscv/include/perf_regs.h b/tools/perf/arch/riscv/include/perf_regs.h
index 6b02a767c..6944bf0de 100644
--- a/tools/perf/arch/riscv/include/perf_regs.h
+++ b/tools/perf/arch/riscv/include/perf_regs.h
@@ -19,78 +19,4 @@
 #define PERF_REG_IP	PERF_REG_RISCV_PC
 #define PERF_REG_SP	PERF_REG_RISCV_SP
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_RISCV_PC:
-		return "pc";
-	case PERF_REG_RISCV_RA:
-		return "ra";
-	case PERF_REG_RISCV_SP:
-		return "sp";
-	case PERF_REG_RISCV_GP:
-		return "gp";
-	case PERF_REG_RISCV_TP:
-		return "tp";
-	case PERF_REG_RISCV_T0:
-		return "t0";
-	case PERF_REG_RISCV_T1:
-		return "t1";
-	case PERF_REG_RISCV_T2:
-		return "t2";
-	case PERF_REG_RISCV_S0:
-		return "s0";
-	case PERF_REG_RISCV_S1:
-		return "s1";
-	case PERF_REG_RISCV_A0:
-		return "a0";
-	case PERF_REG_RISCV_A1:
-		return "a1";
-	case PERF_REG_RISCV_A2:
-		return "a2";
-	case PERF_REG_RISCV_A3:
-		return "a3";
-	case PERF_REG_RISCV_A4:
-		return "a4";
-	case PERF_REG_RISCV_A5:
-		return "a5";
-	case PERF_REG_RISCV_A6:
-		return "a6";
-	case PERF_REG_RISCV_A7:
-		return "a7";
-	case PERF_REG_RISCV_S2:
-		return "s2";
-	case PERF_REG_RISCV_S3:
-		return "s3";
-	case PERF_REG_RISCV_S4:
-		return "s4";
-	case PERF_REG_RISCV_S5:
-		return "s5";
-	case PERF_REG_RISCV_S6:
-		return "s6";
-	case PERF_REG_RISCV_S7:
-		return "s7";
-	case PERF_REG_RISCV_S8:
-		return "s8";
-	case PERF_REG_RISCV_S9:
-		return "s9";
-	case PERF_REG_RISCV_S10:
-		return "s10";
-	case PERF_REG_RISCV_S11:
-		return "s11";
-	case PERF_REG_RISCV_T3:
-		return "t3";
-	case PERF_REG_RISCV_T4:
-		return "t4";
-	case PERF_REG_RISCV_T5:
-		return "t5";
-	case PERF_REG_RISCV_T6:
-		return "t6";
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/s390/include/perf_regs.h b/tools/perf/arch/s390/include/perf_regs.h
index ce3031526..52fcc0891 100644
--- a/tools/perf/arch/s390/include/perf_regs.h
+++ b/tools/perf/arch/s390/include/perf_regs.h
@@ -14,82 +14,4 @@ void perf_regs_load(u64 *regs);
 #define PERF_REG_IP PERF_REG_S390_PC
 #define PERF_REG_SP PERF_REG_S390_R15
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_S390_R0:
-		return "R0";
-	case PERF_REG_S390_R1:
-		return "R1";
-	case PERF_REG_S390_R2:
-		return "R2";
-	case PERF_REG_S390_R3:
-		return "R3";
-	case PERF_REG_S390_R4:
-		return "R4";
-	case PERF_REG_S390_R5:
-		return "R5";
-	case PERF_REG_S390_R6:
-		return "R6";
-	case PERF_REG_S390_R7:
-		return "R7";
-	case PERF_REG_S390_R8:
-		return "R8";
-	case PERF_REG_S390_R9:
-		return "R9";
-	case PERF_REG_S390_R10:
-		return "R10";
-	case PERF_REG_S390_R11:
-		return "R11";
-	case PERF_REG_S390_R12:
-		return "R12";
-	case PERF_REG_S390_R13:
-		return "R13";
-	case PERF_REG_S390_R14:
-		return "R14";
-	case PERF_REG_S390_R15:
-		return "R15";
-	case PERF_REG_S390_FP0:
-		return "FP0";
-	case PERF_REG_S390_FP1:
-		return "FP1";
-	case PERF_REG_S390_FP2:
-		return "FP2";
-	case PERF_REG_S390_FP3:
-		return "FP3";
-	case PERF_REG_S390_FP4:
-		return "FP4";
-	case PERF_REG_S390_FP5:
-		return "FP5";
-	case PERF_REG_S390_FP6:
-		return "FP6";
-	case PERF_REG_S390_FP7:
-		return "FP7";
-	case PERF_REG_S390_FP8:
-		return "FP8";
-	case PERF_REG_S390_FP9:
-		return "FP9";
-	case PERF_REG_S390_FP10:
-		return "FP10";
-	case PERF_REG_S390_FP11:
-		return "FP11";
-	case PERF_REG_S390_FP12:
-		return "FP12";
-	case PERF_REG_S390_FP13:
-		return "FP13";
-	case PERF_REG_S390_FP14:
-		return "FP14";
-	case PERF_REG_S390_FP15:
-		return "FP15";
-	case PERF_REG_S390_MASK:
-		return "MASK";
-	case PERF_REG_S390_PC:
-		return "PC";
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/x86/include/perf_regs.h b/tools/perf/arch/x86/include/perf_regs.h
index cddc4cdc0..16e23b722 100644
--- a/tools/perf/arch/x86/include/perf_regs.h
+++ b/tools/perf/arch/x86/include/perf_regs.h
@@ -23,86 +23,4 @@ void perf_regs_load(u64 *regs);
 #define PERF_REG_IP PERF_REG_X86_IP
 #define PERF_REG_SP PERF_REG_X86_SP
 
-static inline const char *__perf_reg_name(int id)
-{
-	switch (id) {
-	case PERF_REG_X86_AX:
-		return "AX";
-	case PERF_REG_X86_BX:
-		return "BX";
-	case PERF_REG_X86_CX:
-		return "CX";
-	case PERF_REG_X86_DX:
-		return "DX";
-	case PERF_REG_X86_SI:
-		return "SI";
-	case PERF_REG_X86_DI:
-		return "DI";
-	case PERF_REG_X86_BP:
-		return "BP";
-	case PERF_REG_X86_SP:
-		return "SP";
-	case PERF_REG_X86_IP:
-		return "IP";
-	case PERF_REG_X86_FLAGS:
-		return "FLAGS";
-	case PERF_REG_X86_CS:
-		return "CS";
-	case PERF_REG_X86_SS:
-		return "SS";
-	case PERF_REG_X86_DS:
-		return "DS";
-	case PERF_REG_X86_ES:
-		return "ES";
-	case PERF_REG_X86_FS:
-		return "FS";
-	case PERF_REG_X86_GS:
-		return "GS";
-#ifdef HAVE_ARCH_X86_64_SUPPORT
-	case PERF_REG_X86_R8:
-		return "R8";
-	case PERF_REG_X86_R9:
-		return "R9";
-	case PERF_REG_X86_R10:
-		return "R10";
-	case PERF_REG_X86_R11:
-		return "R11";
-	case PERF_REG_X86_R12:
-		return "R12";
-	case PERF_REG_X86_R13:
-		return "R13";
-	case PERF_REG_X86_R14:
-		return "R14";
-	case PERF_REG_X86_R15:
-		return "R15";
-#endif /* HAVE_ARCH_X86_64_SUPPORT */
-
-#define XMM(x) \
-	case PERF_REG_X86_XMM ## x:	\
-	case PERF_REG_X86_XMM ## x + 1:	\
-		return "XMM" #x;
-	XMM(0)
-	XMM(1)
-	XMM(2)
-	XMM(3)
-	XMM(4)
-	XMM(5)
-	XMM(6)
-	XMM(7)
-	XMM(8)
-	XMM(9)
-	XMM(10)
-	XMM(11)
-	XMM(12)
-	XMM(13)
-	XMM(14)
-	XMM(15)
-#undef XMM
-	default:
-		return NULL;
-	}
-
-	return NULL;
-}
-
 #endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 711132f0b..3da0c95c6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4,6 +4,7 @@
 #include "util/counts.h"
 #include "util/debug.h"
 #include "util/dso.h"
+#include "util/env.h"
 #include <subcmd/exec-cmd.h>
 #include "util/header.h"
 #include <subcmd/parse-options.h>
@@ -649,7 +650,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
 }
 
 static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask,
-				     FILE *fp)
+				     const char *arch, FILE *fp)
 {
 	unsigned i = 0, r;
 	int printed = 0;
@@ -661,7 +662,7 @@ static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask,
 
 	for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
 		u64 val = regs->regs[i++];
-		printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
+		printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r, arch), val);
 	}
 
 	return printed;
@@ -717,18 +718,16 @@ tod_scnprintf(struct perf_script *script, char *buf, int buflen,
 	return buf;
 }
 
-static int perf_sample__fprintf_iregs(struct perf_sample *sample,
-				      struct perf_event_attr *attr, FILE *fp)
+static int perf_sample__fprintf_iregs(struct perf_sample *sample, struct perf_event_attr *attr,
+				      const char *arch, FILE *fp)
 {
-	return perf_sample__fprintf_regs(&sample->intr_regs,
-					 attr->sample_regs_intr, fp);
+	return perf_sample__fprintf_regs(&sample->intr_regs, attr->sample_regs_intr, arch, fp);
 }
 
-static int perf_sample__fprintf_uregs(struct perf_sample *sample,
-				      struct perf_event_attr *attr, FILE *fp)
+static int perf_sample__fprintf_uregs(struct perf_sample *sample, struct perf_event_attr *attr,
+				      const char *arch, FILE *fp)
 {
-	return perf_sample__fprintf_regs(&sample->user_regs,
-					 attr->sample_regs_user, fp);
+	return perf_sample__fprintf_regs(&sample->user_regs, attr->sample_regs_user, arch, fp);
 }
 
 static int perf_sample__fprintf_start(struct perf_script *script,
@@ -2000,6 +1999,7 @@ static void process_event(struct perf_script *script,
 	struct evsel_script *es = evsel->priv;
 	FILE *fp = es->fp;
 	char str[PAGE_SIZE_NAME_LEN];
+	const char *arch = perf_env__arch(machine->env);
 
 	if (output[type].fields == 0)
 		return;
@@ -2066,10 +2066,10 @@ static void process_event(struct perf_script *script,
 	}
 
 	if (PRINT_FIELD(IREGS))
-		perf_sample__fprintf_iregs(sample, attr, fp);
+		perf_sample__fprintf_iregs(sample, attr, arch, fp);
 
 	if (PRINT_FIELD(UREGS))
-		perf_sample__fprintf_uregs(sample, attr, fp);
+		perf_sample__fprintf_uregs(sample, attr, arch, fp);
 
 	if (PRINT_FIELD(BRSTACK))
 		perf_sample__fprintf_brstack(sample, thread, attr, fp);
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index eeac181eb..a201181fc 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -27,15 +27,42 @@ uint64_t arch__user_reg_mask(void);
 #ifdef HAVE_PERF_REGS_SUPPORT
 extern const struct sample_reg sample_reg_masks[];
 
+#include <string.h>
 #include <perf_regs.h>
 
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
 
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
 
-static inline const char *perf_reg_name(int id)
+#include "perf_regs_csky.h"
+#include "perf_regs_mips.h"
+#include "perf_regs_powerpc.h"
+#include "perf_regs_riscv.h"
+#include "perf_regs_s390.h"
+#include "perf_regs_x86.h"
+#include "perf_regs_arm.h"
+#include "perf_regs_arm64.h"
+
+static inline const char *perf_reg_name(int id, const char *arch)
 {
-	const char *reg_name = __perf_reg_name(id);
+	const char *reg_name = NULL;
+
+	if (!strcmp(arch, "csky"))
+		reg_name = __perf_reg_name_csky(id);
+	else if (!strcmp(arch, "mips"))
+		reg_name = __perf_reg_name_mips(id);
+	else if (!strcmp(arch, "powerpc"))
+		reg_name = __perf_reg_name_powerpc(id);
+	else if (!strcmp(arch, "riscv"))
+		reg_name = __perf_reg_name_riscv(id);
+	else if (!strcmp(arch, "s390"))
+		reg_name = __perf_reg_name_s390(id);
+	else if (!strcmp(arch, "x86"))
+		reg_name = __perf_reg_name_x86(id);
+	else if (!strcmp(arch, "arm"))
+		reg_name = __perf_reg_name_arm(id);
+	else if (!strcmp(arch, "arm64"))
+		reg_name = __perf_reg_name_arm64(id);
 
 	return reg_name ?: "unknown";
 }
@@ -46,7 +73,7 @@ static inline const char *perf_reg_name(int id)
 
 #define DWARF_MINIMAL_REGS PERF_REGS_MASK
 
-static inline const char *perf_reg_name(int id __maybe_unused)
+static inline const char *perf_reg_name(int id __maybe_unused, const char *arch __maybe_unused)
 {
 	return "unknown";
 }
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index e164f8d00..373fdd798 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -36,6 +36,7 @@
 #include "../debug.h"
 #include "../dso.h"
 #include "../callchain.h"
+#include "../env.h"
 #include "../evsel.h"
 #include "../event.h"
 #include "../thread.h"
@@ -687,7 +688,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict,
 			_PyUnicode_FromString(decode));
 }
 
-static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
+static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, char *bf, int size)
 {
 	unsigned int i = 0, r;
 	int printed = 0;
@@ -702,16 +703,17 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
 
 		printed += scnprintf(bf + printed, size - printed,
 				     "%5s:0x%" PRIx64 " ",
-				     perf_reg_name(r), val);
+				     perf_reg_name(r, arch), val);
 	}
 }
 
 static void set_regs_in_dict(PyObject *dict,
 			     struct perf_sample *sample,
 			     struct evsel *evsel,
-			     struct machine *machine __maybe_unused)
+			     struct machine *machine)
 {
 	struct perf_event_attr *attr = &evsel->core.attr;
+	const char *arch = perf_env__arch(machine->env);
 
 	/*
 	 * Here value 28 is a constant size which can be used to print
@@ -723,12 +725,12 @@ static void set_regs_in_dict(PyObject *dict,
 	int size = __sw_hweight64(attr->sample_regs_intr) * 28;
 	char bf[size];
 
-	regs_map(&sample->intr_regs, attr->sample_regs_intr, bf, sizeof(bf));
+	regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
 
 	pydict_set_item_string_decref(dict, "iregs",
 			_PyUnicode_FromString(bf));
 
-	regs_map(&sample->user_regs, attr->sample_regs_user, bf, sizeof(bf));
+	regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
 
 	pydict_set_item_string_decref(dict, "uregs",
 			_PyUnicode_FromString(bf));
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d8857d1b6..e1a273048 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -15,6 +15,7 @@
 #include "map_symbol.h"
 #include "branch.h"
 #include "debug.h"
+#include "env.h"
 #include "evlist.h"
 #include "evsel.h"
 #include "memswap.h"
@@ -1168,7 +1169,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
 	}
 }
 
-static void regs_dump__printf(u64 mask, u64 *regs)
+static void regs_dump__printf(u64 mask, u64 *regs, const char *arch)
 {
 	unsigned rid, i = 0;
 
@@ -1176,7 +1177,7 @@ static void regs_dump__printf(u64 mask, u64 *regs)
 		u64 val = regs[i++];
 
 		printf(".... %-5s 0x%016" PRIx64 "\n",
-		       perf_reg_name(rid), val);
+		       perf_reg_name(rid, arch), val);
 	}
 }
 
@@ -1194,7 +1195,7 @@ static inline const char *regs_dump_abi(struct regs_dump *d)
 	return regs_abi[d->abi];
 }
 
-static void regs__printf(const char *type, struct regs_dump *regs)
+static void regs__printf(const char *type, struct regs_dump *regs, const char *arch)
 {
 	u64 mask = regs->mask;
 
@@ -1203,23 +1204,23 @@ static void regs__printf(const char *type, struct regs_dump *regs)
 	       mask,
 	       regs_dump_abi(regs));
 
-	regs_dump__printf(mask, regs->regs);
+	regs_dump__printf(mask, regs->regs, arch);
 }
 
-static void regs_user__printf(struct perf_sample *sample)
+static void regs_user__printf(struct perf_sample *sample, const char *arch)
 {
 	struct regs_dump *user_regs = &sample->user_regs;
 
 	if (user_regs->regs)
-		regs__printf("user", user_regs);
+		regs__printf("user", user_regs, arch);
 }
 
-static void regs_intr__printf(struct perf_sample *sample)
+static void regs_intr__printf(struct perf_sample *sample, const char *arch)
 {
 	struct regs_dump *intr_regs = &sample->intr_regs;
 
 	if (intr_regs->regs)
-		regs__printf("intr", intr_regs);
+		regs__printf("intr", intr_regs, arch);
 }
 
 static void stack_user__printf(struct stack_dump *dump)
@@ -1304,7 +1305,7 @@ char *get_page_size_name(u64 size, char *str)
 }
 
 static void dump_sample(struct evsel *evsel, union perf_event *event,
-			struct perf_sample *sample)
+			struct perf_sample *sample, const char *arch)
 {
 	u64 sample_type;
 	char str[PAGE_SIZE_NAME_LEN];
@@ -1325,10 +1326,10 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,
 		branch_stack__printf(sample, evsel__has_branch_callstack(evsel));
 
 	if (sample_type & PERF_SAMPLE_REGS_USER)
-		regs_user__printf(sample);
+		regs_user__printf(sample, arch);
 
 	if (sample_type & PERF_SAMPLE_REGS_INTR)
-		regs_intr__printf(sample);
+		regs_intr__printf(sample, arch);
 
 	if (sample_type & PERF_SAMPLE_STACK_USER)
 		stack_user__printf(&sample->user_stack);
@@ -1502,7 +1503,7 @@ static int machines__deliver_event(struct machines *machines,
 			++evlist->stats.nr_unknown_id;
 			return 0;
 		}
-		dump_sample(evsel, event, sample);
+		dump_sample(evsel, event, sample, perf_env__arch(machine->env));
 		if (machine == NULL) {
 			++evlist->stats.nr_unprocessable_samples;
 			return 0;
-- 
2.25.1


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

* Re: [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-01 12:33 ` [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback German Gomez
@ 2021-12-02 16:03   ` Athira Rajeev
  2021-12-03 12:00     ` German Gomez
  0 siblings, 1 reply; 16+ messages in thread
From: Athira Rajeev @ 2021-12-02 16:03 UTC (permalink / raw)
  To: German Gomez
  Cc: Linux Kernel Mailing List, linux-perf-users,
	Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Leo Yan, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-arm-kernel, linux-csky,
	linux-riscv



> On 01-Dec-2021, at 6:03 PM, German Gomez <german.gomez@arm.com> wrote:
> 
> Include a "struct machine*" parameter to the process_event callback in
> the scripting layer. This will allow access to the perf_env from within
> this callback.
> 
> Followup patches will build on top of this to report the correct name of
> the registers in a perf.data file, consistently with the architecture
> the file was recorded in.
> 
> Signed-off-by: German Gomez <german.gomez@arm.com>
> ---
> tools/perf/builtin-script.c                   |  2 +-
> .../util/scripting-engines/trace-event-perl.c |  3 ++-
> .../scripting-engines/trace-event-python.c    | 23 +++++++++++--------
> tools/perf/util/trace-event-scripting.c       |  3 ++-
> tools/perf/util/trace-event.h                 |  3 ++-
> 5 files changed, 21 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 9434367af..711132f0b 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -2256,7 +2256,7 @@ static int process_sample_event(struct perf_tool *tool,
> 				thread__resolve(al.thread, &addr_al, sample);
> 			addr_al_ptr = &addr_al;
> 		}
> -		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr);
> +		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr, machine);

Hi,

Looks like the patch is using “machine” to allow access to perf_env__arch and there by to get the “arch” value.
But can we use from evsel, like  "perf_env__arch(evsel__env(evsel))” to get arch value instead of including new parameter for “struct machine” ?

Thanks
Athira 
> 	} else {
> 		process_event(scr, sample, evsel, &al, &addr_al, machine);
> 	}
> diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
> index 32a721b3e..6017c4660 100644
> --- a/tools/perf/util/scripting-engines/trace-event-perl.c
> +++ b/tools/perf/util/scripting-engines/trace-event-perl.c
> @@ -454,7 +454,8 @@ static void perl_process_event(union perf_event *event,
> 			       struct perf_sample *sample,
> 			       struct evsel *evsel,
> 			       struct addr_location *al,
> -			       struct addr_location *addr_al)
> +			       struct addr_location *addr_al,
> +			       struct machine *machine __maybe_unused)
> {
> 	scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
> 	perl_process_tracepoint(sample, evsel, al);
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index c0c010350..e164f8d00 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -708,7 +708,8 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
> 
> static void set_regs_in_dict(PyObject *dict,
> 			     struct perf_sample *sample,
> -			     struct evsel *evsel)
> +			     struct evsel *evsel,
> +			     struct machine *machine __maybe_unused)
> {
> 	struct perf_event_attr *attr = &evsel->core.attr;
> 
> @@ -776,6 +777,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
> 					 struct evsel *evsel,
> 					 struct addr_location *al,
> 					 struct addr_location *addr_al,
> +					 struct machine *machine,
> 					 PyObject *callchain)
> {
> 	PyObject *dict, *dict_sample, *brstack, *brstacksym;
> @@ -849,7 +851,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
> 			PyLong_FromUnsignedLongLong(sample->cyc_cnt));
> 	}
> 
> -	set_regs_in_dict(dict, sample, evsel);
> +	set_regs_in_dict(dict, sample, evsel, machine);
> 
> 	return dict;
> }
> @@ -857,7 +859,8 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
> static void python_process_tracepoint(struct perf_sample *sample,
> 				      struct evsel *evsel,
> 				      struct addr_location *al,
> -				      struct addr_location *addr_al)
> +				      struct addr_location *addr_al,
> +				      struct machine *machine)
> {
> 	struct tep_event *event = evsel->tp_format;
> 	PyObject *handler, *context, *t, *obj = NULL, *callchain;
> @@ -964,7 +967,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
> 		PyTuple_SetItem(t, n++, dict);
> 
> 	if (get_argument_count(handler) == (int) n + 1) {
> -		all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al,
> +		all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, machine,
> 			callchain);
> 		PyTuple_SetItem(t, n++,	all_entries_dict);
> 	} else {
> @@ -1366,7 +1369,8 @@ static int python_process_call_return(struct call_return *cr, u64 *parent_db_id,
> static void python_process_general_event(struct perf_sample *sample,
> 					 struct evsel *evsel,
> 					 struct addr_location *al,
> -					 struct addr_location *addr_al)
> +					 struct addr_location *addr_al,
> +					 struct machine *machine)
> {
> 	PyObject *handler, *t, *dict, *callchain;
> 	static char handler_name[64];
> @@ -1388,7 +1392,7 @@ static void python_process_general_event(struct perf_sample *sample,
> 
> 	/* ip unwinding */
> 	callchain = python_process_callchain(sample, evsel, al);
> -	dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain);
> +	dict = get_perf_sample_dict(sample, evsel, al, addr_al, machine, callchain);
> 
> 	PyTuple_SetItem(t, n++, dict);
> 	if (_PyTuple_Resize(&t, n) == -1)
> @@ -1403,7 +1407,8 @@ static void python_process_event(union perf_event *event,
> 				 struct perf_sample *sample,
> 				 struct evsel *evsel,
> 				 struct addr_location *al,
> -				 struct addr_location *addr_al)
> +				 struct addr_location *addr_al,
> +				 struct machine *machine)
> {
> 	struct tables *tables = &tables_global;
> 
> @@ -1411,14 +1416,14 @@ static void python_process_event(union perf_event *event,
> 
> 	switch (evsel->core.attr.type) {
> 	case PERF_TYPE_TRACEPOINT:
> -		python_process_tracepoint(sample, evsel, al, addr_al);
> +		python_process_tracepoint(sample, evsel, al, addr_al, machine);
> 		break;
> 	/* Reserve for future process_hw/sw/raw APIs */
> 	default:
> 		if (tables->db_export_mode)
> 			db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al);
> 		else
> -			python_process_general_event(sample, evsel, al, addr_al);
> +			python_process_general_event(sample, evsel, al, addr_al, machine);
> 	}
> }
> 
> diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
> index 7172ca052..089a2c905 100644
> --- a/tools/perf/util/trace-event-scripting.c
> +++ b/tools/perf/util/trace-event-scripting.c
> @@ -51,7 +51,8 @@ static void process_event_unsupported(union perf_event *event __maybe_unused,
> 				      struct perf_sample *sample __maybe_unused,
> 				      struct evsel *evsel __maybe_unused,
> 				      struct addr_location *al __maybe_unused,
> -				      struct addr_location *addr_al __maybe_unused)
> +				      struct addr_location *addr_al __maybe_unused,
> +				      struct machine *machine __maybe_unused)
> {
> }
> 
> diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
> index 640981105..6f5b1a6d5 100644
> --- a/tools/perf/util/trace-event.h
> +++ b/tools/perf/util/trace-event.h
> @@ -81,7 +81,8 @@ struct scripting_ops {
> 			       struct perf_sample *sample,
> 			       struct evsel *evsel,
> 			       struct addr_location *al,
> -			       struct addr_location *addr_al);
> +			       struct addr_location *addr_al,
> +			       struct machine *machine);
> 	void (*process_switch)(union perf_event *event,
> 			       struct perf_sample *sample,
> 			       struct machine *machine);
> -- 
> 2.25.1
> 
> 


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

* Re: [PATCH v1 4/4] perf tools: Support register names from all architectures
  2021-12-01 12:33 ` [PATCH v1 4/4] perf tools: Support register names from all architectures German Gomez
@ 2021-12-03  9:38   ` German Gomez
  0 siblings, 0 replies; 16+ messages in thread
From: German Gomez @ 2021-12-03  9:38 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, acme
  Cc: John Garry, Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv


On 01/12/2021 12:33, German Gomez wrote:
> [...]
>
> diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
> index eeac181eb..a201181fc 100644
> --- a/tools/perf/util/perf_regs.h
> +++ b/tools/perf/util/perf_regs.h
> @@ -27,15 +27,42 @@ uint64_t arch__user_reg_mask(void);
>  #ifdef HAVE_PERF_REGS_SUPPORT
>  extern const struct sample_reg sample_reg_masks[];
>  
> +#include <string.h>
>  #include <perf_regs.h>
>  
>  #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
>  
>  int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
>  
> -static inline const char *perf_reg_name(int id)
> +#include "perf_regs_csky.h"
> +#include "perf_regs_mips.h"
> +#include "perf_regs_powerpc.h"
> +#include "perf_regs_riscv.h"
> +#include "perf_regs_s390.h"
> +#include "perf_regs_x86.h"
> +#include "perf_regs_arm.h"
> +#include "perf_regs_arm64.h"

Something that slipped through: this is failing to compile perf on ARM32
due to the order of the imports:

util/../../arch/arm64/include/uapi/asm/perf_regs.h:5:6: error: nested redefinition of ‘enum perf_event_arm_regs’
    5 | enum perf_event_arm_regs {
      |      ^~~~~~~~~~~~~~~~~~~

Both #import <perf_regs.h> and "perf_regs_arm.h" are importing the same
header (/tools/arch/arm/include/uapi/asm/perf_regs.h) so this part of
the [PATCH 3/4] isn't doing anything:

diff --git a/tools/perf/util/perf_regs_arm.h b/tools/perf/util/perf_regs_arm.h
new file mode 100644
index 000000000..779b40d6c
--- /dev/null
+++ b/tools/perf/util/perf_regs_arm.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __PERF_REGS_ARM_H
+#define __PERF_REGS_ARM_H
+
+/*
+ * ARM and ARM64 registers are grouped under enums of the same name.
+ * Temporarily rename the name of the enum to prevent the naming collision.
+ */
+#define perf_event_arm_regs perf_event_arm_regs_workaround
+
+#include "../../arch/arm/include/uapi/asm/perf_regs.h"

There is a similar workaround in the csky version. Although it should
compile, I think some of the register names might be missing (the ones
under #if defined(__CSKYABIV2__)).

I'm wondering if it would be wiser to update this changeset to only
consider a small number of platforms (maybe x86 and arm64) and see how
it goes.


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

* Re: [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-02 16:03   ` Athira Rajeev
@ 2021-12-03 12:00     ` German Gomez
  2021-12-13 18:22       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 16+ messages in thread
From: German Gomez @ 2021-12-03 12:00 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: Linux Kernel Mailing List, linux-perf-users,
	Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Leo Yan, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-arm-kernel, linux-csky,
	linux-riscv

Hi Athira,

On 02/12/2021 16:03, Athira Rajeev wrote:
>
>> On 01-Dec-2021, at 6:03 PM, German Gomez <german.gomez@arm.com> wrote:
>>
>> Include a "struct machine*" parameter to the process_event callback in
>> the scripting layer. This will allow access to the perf_env from within
>> this callback.
>>
>> Followup patches will build on top of this to report the correct name of
>> the registers in a perf.data file, consistently with the architecture
>> the file was recorded in.
>>
>> Signed-off-by: German Gomez <german.gomez@arm.com>
>> ---
>> tools/perf/builtin-script.c                   |  2 +-
>> .../util/scripting-engines/trace-event-perl.c |  3 ++-
>> .../scripting-engines/trace-event-python.c    | 23 +++++++++++--------
>> tools/perf/util/trace-event-scripting.c       |  3 ++-
>> tools/perf/util/trace-event.h                 |  3 ++-
>> 5 files changed, 21 insertions(+), 13 deletions(-)
>>
>> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
>> index 9434367af..711132f0b 100644
>> --- a/tools/perf/builtin-script.c
>> +++ b/tools/perf/builtin-script.c
>> @@ -2256,7 +2256,7 @@ static int process_sample_event(struct perf_tool *tool,
>> 				thread__resolve(al.thread, &addr_al, sample);
>> 			addr_al_ptr = &addr_al;
>> 		}
>> -		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr);
>> +		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr, machine);
> Hi,
>
> Looks like the patch is using “machine” to allow access to perf_env__arch and there by to get the “arch” value.
> But can we use from evsel, like  "perf_env__arch(evsel__env(evsel))” to get arch value instead of including new parameter for “struct machine” ?
>
> Thanks
> Athira

Thanks for the suggestion. It looks like we can skip this patch if we
can get the arch value that way.

Thanks!
German


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

* Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
@ 2021-12-08 21:35   ` Jiri Olsa
  2021-12-10  9:17   ` kajoljain
  1 sibling, 0 replies; 16+ messages in thread
From: Jiri Olsa @ 2021-12-08 21:35 UTC (permalink / raw)
  To: German Gomez
  Cc: linux-kernel, linux-perf-users, acme, John Garry, Will Deacon,
	Mathieu Poirier, Leo Yan, Mark Rutland, Alexander Shishkin,
	Namhyung Kim, linux-arm-kernel, linux-csky, linux-riscv

On Wed, Dec 01, 2021 at 12:33:29PM +0000, German Gomez wrote:
> The size of the cache of register values is arch-dependant
> (PERF_REGS_MAX). This has the potential of causing an out-of-bounds
> access in the function "perf_reg_value" if the local architecture
> contains less registers than the one the perf.data file was recorded on.
> 
> Since the maximum number of registers is bound by the bitmask "u64
> cache_mask", and the size of the cache when running under x86 systems is
> 64 already, fix the size to 64 and add a range-check to the function
> "perf_reg_value" to prevent out-of-bounds access.
> 
> Signed-off-by: German Gomez <german.gomez@arm.com>

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
>  tools/perf/util/event.h     | 5 ++++-
>  tools/perf/util/perf_regs.c | 3 +++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index 95ffed663..c59331eea 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -44,13 +44,16 @@ struct perf_event_attr;
>  /* perf sample has 16 bits size limit */
>  #define PERF_SAMPLE_MAX_SIZE (1 << 16)
>  
> +/* number of register is bound by the number of bits in regs_dump::mask (64) */
> +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
> +
>  struct regs_dump {
>  	u64 abi;
>  	u64 mask;
>  	u64 *regs;
>  
>  	/* Cached values/mask filled by first register access. */
> -	u64 cache_regs[PERF_REGS_MAX];
> +	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
>  	u64 cache_mask;
>  };
>  
> diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
> index 5ee47ae15..06a7461ba 100644
> --- a/tools/perf/util/perf_regs.c
> +++ b/tools/perf/util/perf_regs.c
> @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
>  	int i, idx = 0;
>  	u64 mask = regs->mask;
>  
> +	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
> +		return -EINVAL;
> +
>  	if (regs->cache_mask & (1ULL << id))
>  		goto out;
>  
> -- 
> 2.25.1
> 


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

* Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
  2021-12-08 21:35   ` Jiri Olsa
@ 2021-12-10  9:17   ` kajoljain
  2021-12-10 13:38     ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 16+ messages in thread
From: kajoljain @ 2021-12-10  9:17 UTC (permalink / raw)
  To: German Gomez, linux-kernel, linux-perf-users, acme
  Cc: John Garry, Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv



On 12/1/21 6:03 PM, German Gomez wrote:
> The size of the cache of register values is arch-dependant
> (PERF_REGS_MAX). This has the potential of causing an out-of-bounds
> access in the function "perf_reg_value" if the local architecture
> contains less registers than the one the perf.data file was recorded on.
> 
> Since the maximum number of registers is bound by the bitmask "u64
> cache_mask", and the size of the cache when running under x86 systems is
> 64 already, fix the size to 64 and add a range-check to the function
> "perf_reg_value" to prevent out-of-bounds access.
> 

Patch looks good to me.

Reviewed-by: Kajol Jain<kjain@linux.ibm.com>

Thanks,
Kajol Jain

> Signed-off-by: German Gomez <german.gomez@arm.com>
> ---
>  tools/perf/util/event.h     | 5 ++++-
>  tools/perf/util/perf_regs.c | 3 +++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index 95ffed663..c59331eea 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -44,13 +44,16 @@ struct perf_event_attr;
>  /* perf sample has 16 bits size limit */
>  #define PERF_SAMPLE_MAX_SIZE (1 << 16)
>  
> +/* number of register is bound by the number of bits in regs_dump::mask (64) */
> +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
> +
>  struct regs_dump {
>  	u64 abi;
>  	u64 mask;
>  	u64 *regs;
>  
>  	/* Cached values/mask filled by first register access. */
> -	u64 cache_regs[PERF_REGS_MAX];
> +	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
>  	u64 cache_mask;
>  };
>  
> diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
> index 5ee47ae15..06a7461ba 100644
> --- a/tools/perf/util/perf_regs.c
> +++ b/tools/perf/util/perf_regs.c
> @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
>  	int i, idx = 0;
>  	u64 mask = regs->mask;
>  
> +	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
> +		return -EINVAL;
> +
>  	if (regs->cache_mask & (1ULL << id))
>  		goto out;
>  
> 

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

* Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-10  9:17   ` kajoljain
@ 2021-12-10 13:38     ` Arnaldo Carvalho de Melo
  2021-12-10 15:28       ` German Gomez
  0 siblings, 1 reply; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-12-10 13:38 UTC (permalink / raw)
  To: kajoljain
  Cc: German Gomez, linux-kernel, linux-perf-users, John Garry,
	Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv

Em Fri, Dec 10, 2021 at 02:47:49PM +0530, kajoljain escreveu:
> 
> 
> On 12/1/21 6:03 PM, German Gomez wrote:
> > The size of the cache of register values is arch-dependant
> > (PERF_REGS_MAX). This has the potential of causing an out-of-bounds
> > access in the function "perf_reg_value" if the local architecture
> > contains less registers than the one the perf.data file was recorded on.
> > 
> > Since the maximum number of registers is bound by the bitmask "u64
> > cache_mask", and the size of the cache when running under x86 systems is
> > 64 already, fix the size to 64 and add a range-check to the function
> > "perf_reg_value" to prevent out-of-bounds access.
> > 
> 
> Patch looks good to me.
> 
> Reviewed-by: Kajol Jain<kjain@linux.ibm.com>

Thanks, applied.

- Arnaldo

 
> Thanks,
> Kajol Jain
> 
> > Signed-off-by: German Gomez <german.gomez@arm.com>
> > ---
> >  tools/perf/util/event.h     | 5 ++++-
> >  tools/perf/util/perf_regs.c | 3 +++
> >  2 files changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> > index 95ffed663..c59331eea 100644
> > --- a/tools/perf/util/event.h
> > +++ b/tools/perf/util/event.h
> > @@ -44,13 +44,16 @@ struct perf_event_attr;
> >  /* perf sample has 16 bits size limit */
> >  #define PERF_SAMPLE_MAX_SIZE (1 << 16)
> >  
> > +/* number of register is bound by the number of bits in regs_dump::mask (64) */
> > +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
> > +
> >  struct regs_dump {
> >  	u64 abi;
> >  	u64 mask;
> >  	u64 *regs;
> >  
> >  	/* Cached values/mask filled by first register access. */
> > -	u64 cache_regs[PERF_REGS_MAX];
> > +	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
> >  	u64 cache_mask;
> >  };
> >  
> > diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
> > index 5ee47ae15..06a7461ba 100644
> > --- a/tools/perf/util/perf_regs.c
> > +++ b/tools/perf/util/perf_regs.c
> > @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
> >  	int i, idx = 0;
> >  	u64 mask = regs->mask;
> >  
> > +	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
> > +		return -EINVAL;
> > +
> >  	if (regs->cache_mask & (1ULL << id))
> >  		goto out;
> >  
> > 

-- 

- Arnaldo

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

* Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-10 13:38     ` Arnaldo Carvalho de Melo
@ 2021-12-10 15:28       ` German Gomez
  2021-12-10 16:19         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 16+ messages in thread
From: German Gomez @ 2021-12-10 15:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, kajoljain
  Cc: linux-kernel, linux-perf-users, John Garry, Will Deacon,
	Mathieu Poirier, Leo Yan, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-arm-kernel, linux-csky,
	linux-riscv


On 10/12/2021 13:38, Arnaldo Carvalho de Melo wrote:
> Em Fri, Dec 10, 2021 at 02:47:49PM +0530, kajoljain escreveu:
>>
>> On 12/1/21 6:03 PM, German Gomez wrote:
>>> The size of the cache of register values is arch-dependant
>>> (PERF_REGS_MAX). This has the potential of causing an out-of-bounds
>>> access in the function "perf_reg_value" if the local architecture
>>> contains less registers than the one the perf.data file was recorded on.
>>>
>>> Since the maximum number of registers is bound by the bitmask "u64
>>> cache_mask", and the size of the cache when running under x86 systems is
>>> 64 already, fix the size to 64 and add a range-check to the function
>>> "perf_reg_value" to prevent out-of-bounds access.
>>>
>> Patch looks good to me.
>>
>> Reviewed-by: Kajol Jain<kjain@linux.ibm.com>
> Thanks, applied.
>
> - Arnaldo

Thanks Arnaldo, and the rest for the review.

I did send a v2 of this patch afterwards. The only difference was to
give credit to the reporter in the commit message with:

Reported-by: Alexandre Truong <alexandre.truong@arm.com>

Thanks,
German

>  
>> Thanks,
>> Kajol Jain
>>
>>> Signed-off-by: German Gomez <german.gomez@arm.com>
>>> ---
>>>  tools/perf/util/event.h     | 5 ++++-
>>>  tools/perf/util/perf_regs.c | 3 +++
>>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
>>> index 95ffed663..c59331eea 100644
>>> --- a/tools/perf/util/event.h
>>> +++ b/tools/perf/util/event.h
>>> @@ -44,13 +44,16 @@ struct perf_event_attr;
>>>  /* perf sample has 16 bits size limit */
>>>  #define PERF_SAMPLE_MAX_SIZE (1 << 16)
>>>  
>>> +/* number of register is bound by the number of bits in regs_dump::mask (64) */
>>> +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
>>> +
>>>  struct regs_dump {
>>>  	u64 abi;
>>>  	u64 mask;
>>>  	u64 *regs;
>>>  
>>>  	/* Cached values/mask filled by first register access. */
>>> -	u64 cache_regs[PERF_REGS_MAX];
>>> +	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
>>>  	u64 cache_mask;
>>>  };
>>>  
>>> diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
>>> index 5ee47ae15..06a7461ba 100644
>>> --- a/tools/perf/util/perf_regs.c
>>> +++ b/tools/perf/util/perf_regs.c
>>> @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
>>>  	int i, idx = 0;
>>>  	u64 mask = regs->mask;
>>>  
>>> +	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
>>> +		return -EINVAL;
>>> +
>>>  	if (regs->cache_mask & (1ULL << id))
>>>  		goto out;
>>>  
>>>

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

* Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers
  2021-12-10 15:28       ` German Gomez
@ 2021-12-10 16:19         ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-12-10 16:19 UTC (permalink / raw)
  To: German Gomez, Arnaldo Carvalho de Melo, kajoljain
  Cc: linux-kernel, linux-perf-users, John Garry, Will Deacon,
	Mathieu Poirier, Leo Yan, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-arm-kernel, linux-csky,
	linux-riscv



On December 10, 2021 12:28:56 PM GMT-03:00, German Gomez <german.gomez@arm.com> wrote:
>
>On 10/12/2021 13:38, Arnaldo Carvalho de Melo wrote:
>> Em Fri, Dec 10, 2021 at 02:47:49PM +0530, kajoljain escreveu:
>>>
>>> On 12/1/21 6:03 PM, German Gomez wrote:
>>>> The size of the cache of register values is arch-dependant
>>>> (PERF_REGS_MAX). This has the potential of causing an out-of-bounds
>>>> access in the function "perf_reg_value" if the local architecture
>>>> contains less registers than the one the perf.data file was recorded on.
>>>>
>>>> Since the maximum number of registers is bound by the bitmask "u64
>>>> cache_mask", and the size of the cache when running under x86 systems is
>>>> 64 already, fix the size to 64 and add a range-check to the function
>>>> "perf_reg_value" to prevent out-of-bounds access.
>>>>
>>> Patch looks good to me.
>>>
>>> Reviewed-by: Kajol Jain<kjain@linux.ibm.com>
>> Thanks, applied.
>>
>> - Arnaldo
>
>Thanks Arnaldo, and the rest for the review.
>
>I did send a v2 of this patch afterwards. The only difference was to
>give credit to the reporter in the commit message with:
>
>Reported-by: Alexandre Truong <alexandre.truong@arm.com>


I'll add it.

- Arnaldo
>
>Thanks,
>German
>
>>  
>>> Thanks,
>>> Kajol Jain
>>>
>>>> Signed-off-by: German Gomez <german.gomez@arm.com>
>>>> ---
>>>>  tools/perf/util/event.h     | 5 ++++-
>>>>  tools/perf/util/perf_regs.c | 3 +++
>>>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
>>>> index 95ffed663..c59331eea 100644
>>>> --- a/tools/perf/util/event.h
>>>> +++ b/tools/perf/util/event.h
>>>> @@ -44,13 +44,16 @@ struct perf_event_attr;
>>>>  /* perf sample has 16 bits size limit */
>>>>  #define PERF_SAMPLE_MAX_SIZE (1 << 16)
>>>>  
>>>> +/* number of register is bound by the number of bits in regs_dump::mask (64) */
>>>> +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
>>>> +
>>>>  struct regs_dump {
>>>>  	u64 abi;
>>>>  	u64 mask;
>>>>  	u64 *regs;
>>>>  
>>>>  	/* Cached values/mask filled by first register access. */
>>>> -	u64 cache_regs[PERF_REGS_MAX];
>>>> +	u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
>>>>  	u64 cache_mask;
>>>>  };
>>>>  
>>>> diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
>>>> index 5ee47ae15..06a7461ba 100644
>>>> --- a/tools/perf/util/perf_regs.c
>>>> +++ b/tools/perf/util/perf_regs.c
>>>> @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
>>>>  	int i, idx = 0;
>>>>  	u64 mask = regs->mask;
>>>>  
>>>> +	if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
>>>> +		return -EINVAL;
>>>> +
>>>>  	if (regs->cache_mask & (1ULL << id))
>>>>  		goto out;
>>>>  
>>>>

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

* Re: [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-03 12:00     ` German Gomez
@ 2021-12-13 18:22       ` Arnaldo Carvalho de Melo
  2021-12-13 18:31         ` German Gomez
  0 siblings, 1 reply; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-12-13 18:22 UTC (permalink / raw)
  To: German Gomez
  Cc: Athira Rajeev, Linux Kernel Mailing List, linux-perf-users,
	John Garry, Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv

Em Fri, Dec 03, 2021 at 12:00:26PM +0000, German Gomez escreveu:
> Hi Athira,
> 
> On 02/12/2021 16:03, Athira Rajeev wrote:
> >
> >> On 01-Dec-2021, at 6:03 PM, German Gomez <german.gomez@arm.com> wrote:
> >>
> >> Include a "struct machine*" parameter to the process_event callback in
> >> the scripting layer. This will allow access to the perf_env from within
> >> this callback.
> >>
> >> Followup patches will build on top of this to report the correct name of
> >> the registers in a perf.data file, consistently with the architecture
> >> the file was recorded in.
> >>
> >> Signed-off-by: German Gomez <german.gomez@arm.com>
> >> ---
> >> tools/perf/builtin-script.c                   |  2 +-
> >> .../util/scripting-engines/trace-event-perl.c |  3 ++-
> >> .../scripting-engines/trace-event-python.c    | 23 +++++++++++--------
> >> tools/perf/util/trace-event-scripting.c       |  3 ++-
> >> tools/perf/util/trace-event.h                 |  3 ++-
> >> 5 files changed, 21 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> >> index 9434367af..711132f0b 100644
> >> --- a/tools/perf/builtin-script.c
> >> +++ b/tools/perf/builtin-script.c
> >> @@ -2256,7 +2256,7 @@ static int process_sample_event(struct perf_tool *tool,
> >> 				thread__resolve(al.thread, &addr_al, sample);
> >> 			addr_al_ptr = &addr_al;
> >> 		}
> >> -		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr);
> >> +		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr, machine);
> > Hi,
> >
> > Looks like the patch is using “machine” to allow access to perf_env__arch and there by to get the “arch” value.
> > But can we use from evsel, like  "perf_env__arch(evsel__env(evsel))” to get arch value instead of including new parameter for “struct machine” ?
> >
> > Thanks
> > Athira
> 
> Thanks for the suggestion. It looks like we can skip this patch if we
> can get the arch value that way.

So the first one is already upstream, will you post a v2?

- Arnaldo

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

* Re: [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-13 18:22       ` Arnaldo Carvalho de Melo
@ 2021-12-13 18:31         ` German Gomez
  2021-12-13 19:59           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 16+ messages in thread
From: German Gomez @ 2021-12-13 18:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Athira Rajeev, Linux Kernel Mailing List, linux-perf-users,
	John Garry, Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv


On 13/12/2021 18:22, Arnaldo Carvalho de Melo wrote:
> [...]
>
>> Thanks for the suggestion. It looks like we can skip this patch if we
>> can get the arch value that way.
> So the first one is already upstream, will you post a v2?
>
> - Arnaldo

Hi Arnaldo,

I sent a v2 where this patch was removed. The upstreamed patch (1/4
here) remained the same.

https://lore.kernel.org/all/20211207180653.1147374-1-german.gomez@arm.com/

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

* Re: [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback
  2021-12-13 18:31         ` German Gomez
@ 2021-12-13 19:59           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-12-13 19:59 UTC (permalink / raw)
  To: German Gomez, Arnaldo Carvalho de Melo
  Cc: Athira Rajeev, Linux Kernel Mailing List, linux-perf-users,
	John Garry, Will Deacon, Mathieu Poirier, Leo Yan, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, linux-arm-kernel,
	linux-csky, linux-riscv



On December 13, 2021 3:31:47 PM GMT-03:00, German Gomez <german.gomez@arm.com> wrote:
>
>On 13/12/2021 18:22, Arnaldo Carvalho de Melo wrote:
>> [...]
>>
>>> Thanks for the suggestion. It looks like we can skip this patch if we
>>> can get the arch value that way.
>> So the first one is already upstream, will you post a v2?
>>
>> - Arnaldo
>
>Hi Arnaldo,
>
>I sent a v2 where this patch was removed. The upstreamed patch (1/4
>here) remained the same.

Thanks, I'll check.

- Arnaldo
>
>https://lore.kernel.org/all/20211207180653.1147374-1-german.gomez@arm.com/

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

end of thread, other threads:[~2021-12-13 19:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 12:33 [PATCH v1 0/4] Support register names from all architectures German Gomez
2021-12-01 12:33 ` [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers German Gomez
2021-12-08 21:35   ` Jiri Olsa
2021-12-10  9:17   ` kajoljain
2021-12-10 13:38     ` Arnaldo Carvalho de Melo
2021-12-10 15:28       ` German Gomez
2021-12-10 16:19         ` Arnaldo Carvalho de Melo
2021-12-01 12:33 ` [PATCH v1 2/4] perf script: Add "struct machine" parameter to process_event callback German Gomez
2021-12-02 16:03   ` Athira Rajeev
2021-12-03 12:00     ` German Gomez
2021-12-13 18:22       ` Arnaldo Carvalho de Melo
2021-12-13 18:31         ` German Gomez
2021-12-13 19:59           ` Arnaldo Carvalho de Melo
2021-12-01 12:33 ` [PATCH v1 3/4] perf tools: Crete header files with register names German Gomez
2021-12-01 12:33 ` [PATCH v1 4/4] perf tools: Support register names from all architectures German Gomez
2021-12-03  9:38   ` German Gomez

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).