All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] perf arm64: Support SDT
@ 2020-12-25  5:27 ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

This patch is to enable SDT on Arm64.

Since Arm64 SDT marker in ELF file is different from other archs,
especially for using stack pointer (sp) to retrieve data for local
variables, patch 01 is used to fixup the arguments for this special
case.  Patch 02 is to add argument support for Arm64 SDT.

This patch set has been verified on Arm64/x86_64 platforms with a
testing program usdt_test.  The testing approach is described in the
patch set v1 [1].

Changes from v1:
* Added Arnaldo's patch for fixing memory leak (Arnaldo);
* Refined patch "perf probe: Fixup Arm64 SDT arguments" to use
  asprintf() and check pointer is valid or not (Arnaldo);
* Minor changes in patch "perf arm64: Add argument support for SDT"
  for the regular expression;
* Added Masami's Ack tag for patch 03.

[1] https://lore.kernel.org/patchwork/cover/1356212/


Arnaldo Carvalho de Melo (1):
  perf probe: Fix memory leak in synthesize_sdt_probe_command()

Leo Yan (2):
  perf probe: Fixup Arm64 SDT arguments
  perf arm64: Add argument support for SDT

 tools/perf/arch/arm64/util/perf_regs.c | 94 ++++++++++++++++++++++++++
 tools/perf/util/probe-file.c           | 49 ++++++++++++--
 2 files changed, 139 insertions(+), 4 deletions(-)

-- 
2.17.1


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

* [PATCH v2 0/3] perf arm64: Support SDT
@ 2020-12-25  5:27 ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

This patch is to enable SDT on Arm64.

Since Arm64 SDT marker in ELF file is different from other archs,
especially for using stack pointer (sp) to retrieve data for local
variables, patch 01 is used to fixup the arguments for this special
case.  Patch 02 is to add argument support for Arm64 SDT.

This patch set has been verified on Arm64/x86_64 platforms with a
testing program usdt_test.  The testing approach is described in the
patch set v1 [1].

Changes from v1:
* Added Arnaldo's patch for fixing memory leak (Arnaldo);
* Refined patch "perf probe: Fixup Arm64 SDT arguments" to use
  asprintf() and check pointer is valid or not (Arnaldo);
* Minor changes in patch "perf arm64: Add argument support for SDT"
  for the regular expression;
* Added Masami's Ack tag for patch 03.

[1] https://lore.kernel.org/patchwork/cover/1356212/


Arnaldo Carvalho de Melo (1):
  perf probe: Fix memory leak in synthesize_sdt_probe_command()

Leo Yan (2):
  perf probe: Fixup Arm64 SDT arguments
  perf arm64: Add argument support for SDT

 tools/perf/arch/arm64/util/perf_regs.c | 94 ++++++++++++++++++++++++++
 tools/perf/util/probe-file.c           | 49 ++++++++++++--
 2 files changed, 139 insertions(+), 4 deletions(-)

-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command()
  2020-12-25  5:27 ` Leo Yan
@ 2020-12-25  5:27   ` Leo Yan
  -1 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Arnaldo Carvalho de Melo, Leo Yan, stable

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

In synthesize_sdt_probe_command(), it gets argument array from
argv_split() but forgets to free it.  This patch calls argv_free() to
free the argument array to avoid memory leak.

Fixes: 3b1f8311f696 ("perf probe: Add sdt probes arguments into the uprobe cmd string")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: stable@vger.kernel.org
---
 tools/perf/util/probe-file.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 064b63a6a3f3..bbecb449ea94 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -791,7 +791,7 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 					const char *sdtgrp)
 {
 	struct strbuf buf;
-	char *ret = NULL, **args;
+	char *ret = NULL;
 	int i, args_count, err;
 	unsigned long long ref_ctr_offset;
 
@@ -813,12 +813,19 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 		goto out;
 
 	if (note->args) {
-		args = argv_split(note->args, &args_count);
+		char **args = argv_split(note->args, &args_count);
+
+		if (args == NULL)
+			goto error;
 
 		for (i = 0; i < args_count; ++i) {
-			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
+			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
+				argv_free(args);
 				goto error;
+			}
 		}
+
+		argv_free(args);
 	}
 
 out:
-- 
2.17.1


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

* [PATCH v2 1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command()
@ 2020-12-25  5:27   ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Arnaldo Carvalho de Melo, stable, Leo Yan

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

In synthesize_sdt_probe_command(), it gets argument array from
argv_split() but forgets to free it.  This patch calls argv_free() to
free the argument array to avoid memory leak.

Fixes: 3b1f8311f696 ("perf probe: Add sdt probes arguments into the uprobe cmd string")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: stable@vger.kernel.org
---
 tools/perf/util/probe-file.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 064b63a6a3f3..bbecb449ea94 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -791,7 +791,7 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 					const char *sdtgrp)
 {
 	struct strbuf buf;
-	char *ret = NULL, **args;
+	char *ret = NULL;
 	int i, args_count, err;
 	unsigned long long ref_ctr_offset;
 
@@ -813,12 +813,19 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 		goto out;
 
 	if (note->args) {
-		args = argv_split(note->args, &args_count);
+		char **args = argv_split(note->args, &args_count);
+
+		if (args == NULL)
+			goto error;
 
 		for (i = 0; i < args_count; ++i) {
-			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
+			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
+				argv_free(args);
 				goto error;
+			}
 		}
+
+		argv_free(args);
 	}
 
 out:
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 2/3] perf probe: Fixup Arm64 SDT arguments
  2020-12-25  5:27 ` Leo Yan
@ 2020-12-25  5:27   ` Leo Yan
  -1 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

Arm64 ELF section '.note.stapsdt' uses string format "-4@[sp, NUM]" if
the probe is to access data in stack, e.g. below is an example for
dumping Arm64 ELF file and shows the argument format:

  Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4]

Comparing against other archs' argument format, Arm64's argument
introduces an extra space character in the middle of square brackets,
due to argv_split() uses space as splitter, the argument is wrongly
divided into two items.

To support Arm64 SDT, this patch fixes up for this case, if any item
contains sub string "[sp", concatenates the two continuous items.  And
adds the detailed explaination in comment.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/probe-file.c | 38 ++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index bbecb449ea94..52273542e6ef 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -794,6 +794,8 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 	char *ret = NULL;
 	int i, args_count, err;
 	unsigned long long ref_ctr_offset;
+	char *arg;
+	int arg_idx = 0;
 
 	if (strbuf_init(&buf, 32) < 0)
 		return NULL;
@@ -818,11 +820,43 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 		if (args == NULL)
 			goto error;
 
-		for (i = 0; i < args_count; ++i) {
-			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
+		for (i = 0; i < args_count; ) {
+			/*
+			 * FIXUP: Arm64 ELF section '.note.stapsdt' uses string
+			 * format "-4@[sp, NUM]" if a probe is to access data in
+			 * the stack, e.g. below is an example for the SDT
+			 * Arguments:
+			 *
+			 *   Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4]
+			 *
+			 * Since the string introduces an extra space character
+			 * in the middle of square brackets, the argument is
+			 * divided into two items.  Fixup for this case, if an
+			 * item contains sub string "[sp,", need to concatenate
+			 * the two items.
+			 */
+			if (strstr(args[i], "[sp,") && (i+1) < args_count) {
+				err = asprintf(&arg, "%s %s", args[i], args[i+1]);
+				i += 2;
+			} else {
+				err = asprintf(&arg, "%s", args[i]);
+				i += 1;
+			}
+
+			/* Failed to allocate memory */
+			if (err < 0) {
 				argv_free(args);
 				goto error;
 			}
+
+			if (synthesize_sdt_probe_arg(&buf, arg_idx, arg) < 0) {
+				free(arg);
+				argv_free(args);
+				goto error;
+			}
+
+			free(arg);
+			arg_idx++;
 		}
 
 		argv_free(args);
-- 
2.17.1


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

* [PATCH v2 2/3] perf probe: Fixup Arm64 SDT arguments
@ 2020-12-25  5:27   ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

Arm64 ELF section '.note.stapsdt' uses string format "-4@[sp, NUM]" if
the probe is to access data in stack, e.g. below is an example for
dumping Arm64 ELF file and shows the argument format:

  Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4]

Comparing against other archs' argument format, Arm64's argument
introduces an extra space character in the middle of square brackets,
due to argv_split() uses space as splitter, the argument is wrongly
divided into two items.

To support Arm64 SDT, this patch fixes up for this case, if any item
contains sub string "[sp", concatenates the two continuous items.  And
adds the detailed explaination in comment.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/probe-file.c | 38 ++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index bbecb449ea94..52273542e6ef 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -794,6 +794,8 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 	char *ret = NULL;
 	int i, args_count, err;
 	unsigned long long ref_ctr_offset;
+	char *arg;
+	int arg_idx = 0;
 
 	if (strbuf_init(&buf, 32) < 0)
 		return NULL;
@@ -818,11 +820,43 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
 		if (args == NULL)
 			goto error;
 
-		for (i = 0; i < args_count; ++i) {
-			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
+		for (i = 0; i < args_count; ) {
+			/*
+			 * FIXUP: Arm64 ELF section '.note.stapsdt' uses string
+			 * format "-4@[sp, NUM]" if a probe is to access data in
+			 * the stack, e.g. below is an example for the SDT
+			 * Arguments:
+			 *
+			 *   Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4]
+			 *
+			 * Since the string introduces an extra space character
+			 * in the middle of square brackets, the argument is
+			 * divided into two items.  Fixup for this case, if an
+			 * item contains sub string "[sp,", need to concatenate
+			 * the two items.
+			 */
+			if (strstr(args[i], "[sp,") && (i+1) < args_count) {
+				err = asprintf(&arg, "%s %s", args[i], args[i+1]);
+				i += 2;
+			} else {
+				err = asprintf(&arg, "%s", args[i]);
+				i += 1;
+			}
+
+			/* Failed to allocate memory */
+			if (err < 0) {
 				argv_free(args);
 				goto error;
 			}
+
+			if (synthesize_sdt_probe_arg(&buf, arg_idx, arg) < 0) {
+				free(arg);
+				argv_free(args);
+				goto error;
+			}
+
+			free(arg);
+			arg_idx++;
 		}
 
 		argv_free(args);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 3/3] perf arm64: Add argument support for SDT
  2020-12-25  5:27 ` Leo Yan
@ 2020-12-25  5:27   ` Leo Yan
  -1 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

Now the two OP formats are used for SDT marker argument in Arm64 ELF,
one format is general register xNUM (e.g. x1, x2, etc), another is for
using stack pointer to access local variables (e.g. [sp], [sp, 8]).

This patch adds support SDT marker argument for Arm64, it parses OP and
converts to uprobe compatible format.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/arch/arm64/util/perf_regs.c | 94 ++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c
index 54efa12fdbea..2518cde18b34 100644
--- a/tools/perf/arch/arm64/util/perf_regs.c
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -1,4 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <regex.h>
+#include <string.h>
+#include <linux/kernel.h>
+#include <linux/zalloc.h>
+
+#include "../../../util/debug.h"
+#include "../../../util/event.h"
 #include "../../../util/perf_regs.h"
 
 const struct sample_reg sample_reg_masks[] = {
@@ -37,3 +45,89 @@ const struct sample_reg sample_reg_masks[] = {
 	SMPL_REG(pc, PERF_REG_ARM64_PC),
 	SMPL_REG_END
 };
+
+/* %xNUM */
+#define SDT_OP_REGEX1  "^(x[1-2]?[0-9]|3[0-1])$"
+
+/* [sp], [sp, NUM] */
+#define SDT_OP_REGEX2  "^\\[sp(, )?([0-9]+)?\\]$"
+
+static regex_t sdt_op_regex1, sdt_op_regex2;
+
+static int sdt_init_op_regex(void)
+{
+	static int initialized;
+	int ret = 0;
+
+	if (initialized)
+		return 0;
+
+	ret = regcomp(&sdt_op_regex1, SDT_OP_REGEX1, REG_EXTENDED);
+	if (ret)
+		goto error;
+
+	ret = regcomp(&sdt_op_regex2, SDT_OP_REGEX2, REG_EXTENDED);
+	if (ret)
+		goto free_regex1;
+
+	initialized = 1;
+	return 0;
+
+free_regex1:
+	regfree(&sdt_op_regex1);
+error:
+	pr_debug4("Regex compilation error.\n");
+	return ret;
+}
+
+/*
+ * SDT marker arguments on Arm64 uses %xREG or [sp, NUM], currently
+ * support these two formats.
+ */
+int arch_sdt_arg_parse_op(char *old_op, char **new_op)
+{
+	int ret, new_len;
+	regmatch_t rm[5];
+
+	ret = sdt_init_op_regex();
+	if (ret < 0)
+		return ret;
+
+	if (!regexec(&sdt_op_regex1, old_op, 3, rm, 0)) {
+		/* Extract xNUM */
+		new_len = 2;	/* % NULL */
+		new_len += (int)(rm[1].rm_eo - rm[1].rm_so);
+
+		*new_op = zalloc(new_len);
+		if (!*new_op)
+			return -ENOMEM;
+
+		scnprintf(*new_op, new_len, "%%%.*s",
+			(int)(rm[1].rm_eo - rm[1].rm_so), old_op + rm[1].rm_so);
+	} else if (!regexec(&sdt_op_regex2, old_op, 5, rm, 0)) {
+		/* [sp], [sp, NUM] or [sp,NUM] */
+		new_len = 7;	/* + ( % s p ) NULL */
+
+		/* If the arugment is [sp], need to fill offset '0' */
+		if (rm[2].rm_so == -1)
+			new_len += 1;
+		else
+			new_len += (int)(rm[2].rm_eo - rm[2].rm_so);
+
+		*new_op = zalloc(new_len);
+		if (!*new_op)
+			return -ENOMEM;
+
+		if (rm[2].rm_so == -1)
+			scnprintf(*new_op, new_len, "+0(%%sp)");
+		else
+			scnprintf(*new_op, new_len, "+%.*s(%%sp)",
+				  (int)(rm[2].rm_eo - rm[2].rm_so),
+				  old_op + rm[2].rm_so);
+	} else {
+		pr_debug4("Skipping unsupported SDT argument: %s\n", old_op);
+		return SDT_ARG_SKIP;
+	}
+
+	return SDT_ARG_VALID;
+}
-- 
2.17.1


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

* [PATCH v2 3/3] perf arm64: Add argument support for SDT
@ 2020-12-25  5:27   ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-25  5:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, John Garry, Will Deacon,
	Mathieu Poirier, Masami Hiramatsu, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexandre Truong, Ian Rogers, Thomas Richter, He Zhe,
	Sumanth Korikkar, Alexis Berlemont, linux-arm-kernel,
	linux-kernel
  Cc: Leo Yan

Now the two OP formats are used for SDT marker argument in Arm64 ELF,
one format is general register xNUM (e.g. x1, x2, etc), another is for
using stack pointer to access local variables (e.g. [sp], [sp, 8]).

This patch adds support SDT marker argument for Arm64, it parses OP and
converts to uprobe compatible format.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/arch/arm64/util/perf_regs.c | 94 ++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c
index 54efa12fdbea..2518cde18b34 100644
--- a/tools/perf/arch/arm64/util/perf_regs.c
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -1,4 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <regex.h>
+#include <string.h>
+#include <linux/kernel.h>
+#include <linux/zalloc.h>
+
+#include "../../../util/debug.h"
+#include "../../../util/event.h"
 #include "../../../util/perf_regs.h"
 
 const struct sample_reg sample_reg_masks[] = {
@@ -37,3 +45,89 @@ const struct sample_reg sample_reg_masks[] = {
 	SMPL_REG(pc, PERF_REG_ARM64_PC),
 	SMPL_REG_END
 };
+
+/* %xNUM */
+#define SDT_OP_REGEX1  "^(x[1-2]?[0-9]|3[0-1])$"
+
+/* [sp], [sp, NUM] */
+#define SDT_OP_REGEX2  "^\\[sp(, )?([0-9]+)?\\]$"
+
+static regex_t sdt_op_regex1, sdt_op_regex2;
+
+static int sdt_init_op_regex(void)
+{
+	static int initialized;
+	int ret = 0;
+
+	if (initialized)
+		return 0;
+
+	ret = regcomp(&sdt_op_regex1, SDT_OP_REGEX1, REG_EXTENDED);
+	if (ret)
+		goto error;
+
+	ret = regcomp(&sdt_op_regex2, SDT_OP_REGEX2, REG_EXTENDED);
+	if (ret)
+		goto free_regex1;
+
+	initialized = 1;
+	return 0;
+
+free_regex1:
+	regfree(&sdt_op_regex1);
+error:
+	pr_debug4("Regex compilation error.\n");
+	return ret;
+}
+
+/*
+ * SDT marker arguments on Arm64 uses %xREG or [sp, NUM], currently
+ * support these two formats.
+ */
+int arch_sdt_arg_parse_op(char *old_op, char **new_op)
+{
+	int ret, new_len;
+	regmatch_t rm[5];
+
+	ret = sdt_init_op_regex();
+	if (ret < 0)
+		return ret;
+
+	if (!regexec(&sdt_op_regex1, old_op, 3, rm, 0)) {
+		/* Extract xNUM */
+		new_len = 2;	/* % NULL */
+		new_len += (int)(rm[1].rm_eo - rm[1].rm_so);
+
+		*new_op = zalloc(new_len);
+		if (!*new_op)
+			return -ENOMEM;
+
+		scnprintf(*new_op, new_len, "%%%.*s",
+			(int)(rm[1].rm_eo - rm[1].rm_so), old_op + rm[1].rm_so);
+	} else if (!regexec(&sdt_op_regex2, old_op, 5, rm, 0)) {
+		/* [sp], [sp, NUM] or [sp,NUM] */
+		new_len = 7;	/* + ( % s p ) NULL */
+
+		/* If the arugment is [sp], need to fill offset '0' */
+		if (rm[2].rm_so == -1)
+			new_len += 1;
+		else
+			new_len += (int)(rm[2].rm_eo - rm[2].rm_so);
+
+		*new_op = zalloc(new_len);
+		if (!*new_op)
+			return -ENOMEM;
+
+		if (rm[2].rm_so == -1)
+			scnprintf(*new_op, new_len, "+0(%%sp)");
+		else
+			scnprintf(*new_op, new_len, "+%.*s(%%sp)",
+				  (int)(rm[2].rm_eo - rm[2].rm_so),
+				  old_op + rm[2].rm_so);
+	} else {
+		pr_debug4("Skipping unsupported SDT argument: %s\n", old_op);
+		return SDT_ARG_SKIP;
+	}
+
+	return SDT_ARG_VALID;
+}
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 0/3] perf arm64: Support SDT
  2020-12-25  5:27 ` Leo Yan
@ 2020-12-28 12:54   ` Arnaldo Carvalho de Melo
  -1 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-12-28 12:54 UTC (permalink / raw)
  To: Leo Yan
  Cc: John Garry, Will Deacon, Mathieu Poirier, Masami Hiramatsu,
	Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexandre Truong, Ian Rogers,
	Thomas Richter, He Zhe, Sumanth Korikkar, Alexis Berlemont,
	linux-arm-kernel, linux-kernel

Em Fri, Dec 25, 2020 at 01:27:48PM +0800, Leo Yan escreveu:
> This patch is to enable SDT on Arm64.
> 
> Since Arm64 SDT marker in ELF file is different from other archs,
> especially for using stack pointer (sp) to retrieve data for local
> variables, patch 01 is used to fixup the arguments for this special
> case.  Patch 02 is to add argument support for Arm64 SDT.
> 
> This patch set has been verified on Arm64/x86_64 platforms with a
> testing program usdt_test.  The testing approach is described in the
> patch set v1 [1].
> 
> Changes from v1:
> * Added Arnaldo's patch for fixing memory leak (Arnaldo);
> * Refined patch "perf probe: Fixup Arm64 SDT arguments" to use
>   asprintf() and check pointer is valid or not (Arnaldo);
> * Minor changes in patch "perf arm64: Add argument support for SDT"
>   for the regular expression;
> * Added Masami's Ack tag for patch 03.
> 
> [1] https://lore.kernel.org/patchwork/cover/1356212/
> 

This one made it into 5.11
 
> Arnaldo Carvalho de Melo (1):
>   perf probe: Fix memory leak in synthesize_sdt_probe_command()
 
These were now merged in perf/core.

> Leo Yan (2):
>   perf probe: Fixup Arm64 SDT arguments
>   perf arm64: Add argument support for SDT

Thanks,

- Arnaldo

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

* Re: [PATCH v2 0/3] perf arm64: Support SDT
@ 2020-12-28 12:54   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-12-28 12:54 UTC (permalink / raw)
  To: Leo Yan
  Cc: Mark Rutland, Ian Rogers, Thomas Richter, Mathieu Poirier,
	Peter Zijlstra, Jiri Olsa, John Garry, linux-kernel,
	Alexander Shishkin, Alexandre Truong, Ingo Molnar,
	Masami Hiramatsu, Namhyung Kim, Sumanth Korikkar,
	Alexis Berlemont, Will Deacon, He Zhe, linux-arm-kernel

Em Fri, Dec 25, 2020 at 01:27:48PM +0800, Leo Yan escreveu:
> This patch is to enable SDT on Arm64.
> 
> Since Arm64 SDT marker in ELF file is different from other archs,
> especially for using stack pointer (sp) to retrieve data for local
> variables, patch 01 is used to fixup the arguments for this special
> case.  Patch 02 is to add argument support for Arm64 SDT.
> 
> This patch set has been verified on Arm64/x86_64 platforms with a
> testing program usdt_test.  The testing approach is described in the
> patch set v1 [1].
> 
> Changes from v1:
> * Added Arnaldo's patch for fixing memory leak (Arnaldo);
> * Refined patch "perf probe: Fixup Arm64 SDT arguments" to use
>   asprintf() and check pointer is valid or not (Arnaldo);
> * Minor changes in patch "perf arm64: Add argument support for SDT"
>   for the regular expression;
> * Added Masami's Ack tag for patch 03.
> 
> [1] https://lore.kernel.org/patchwork/cover/1356212/
> 

This one made it into 5.11
 
> Arnaldo Carvalho de Melo (1):
>   perf probe: Fix memory leak in synthesize_sdt_probe_command()
 
These were now merged in perf/core.

> Leo Yan (2):
>   perf probe: Fixup Arm64 SDT arguments
>   perf arm64: Add argument support for SDT

Thanks,

- Arnaldo

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 0/3] perf arm64: Support SDT
  2020-12-28 12:54   ` Arnaldo Carvalho de Melo
@ 2020-12-29  1:26     ` Leo Yan
  -1 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-29  1:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: John Garry, Will Deacon, Mathieu Poirier, Masami Hiramatsu,
	Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexandre Truong, Ian Rogers,
	Thomas Richter, He Zhe, Sumanth Korikkar, Alexis Berlemont,
	linux-arm-kernel, linux-kernel

On Mon, Dec 28, 2020 at 09:54:43AM -0300, Arnaldo Carvalho de Melo wrote:

[...]

> This one made it into 5.11
>  
> > Arnaldo Carvalho de Melo (1):
> >   perf probe: Fix memory leak in synthesize_sdt_probe_command()
>  
> These were now merged in perf/core.
> 
> > Leo Yan (2):
> >   perf probe: Fixup Arm64 SDT arguments
> >   perf arm64: Add argument support for SDT

Thanks, Arnaldo.

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

* Re: [PATCH v2 0/3] perf arm64: Support SDT
@ 2020-12-29  1:26     ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2020-12-29  1:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Mark Rutland, Ian Rogers, Thomas Richter, Mathieu Poirier,
	Peter Zijlstra, Jiri Olsa, John Garry, linux-kernel,
	Alexander Shishkin, Alexandre Truong, Ingo Molnar,
	Masami Hiramatsu, Namhyung Kim, Sumanth Korikkar,
	Alexis Berlemont, Will Deacon, He Zhe, linux-arm-kernel

On Mon, Dec 28, 2020 at 09:54:43AM -0300, Arnaldo Carvalho de Melo wrote:

[...]

> This one made it into 5.11
>  
> > Arnaldo Carvalho de Melo (1):
> >   perf probe: Fix memory leak in synthesize_sdt_probe_command()
>  
> These were now merged in perf/core.
> 
> > Leo Yan (2):
> >   perf probe: Fixup Arm64 SDT arguments
> >   perf arm64: Add argument support for SDT

Thanks, Arnaldo.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-12-29  1:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-25  5:27 [PATCH v2 0/3] perf arm64: Support SDT Leo Yan
2020-12-25  5:27 ` Leo Yan
2020-12-25  5:27 ` [PATCH v2 1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command() Leo Yan
2020-12-25  5:27   ` Leo Yan
2020-12-25  5:27 ` [PATCH v2 2/3] perf probe: Fixup Arm64 SDT arguments Leo Yan
2020-12-25  5:27   ` Leo Yan
2020-12-25  5:27 ` [PATCH v2 3/3] perf arm64: Add argument support for SDT Leo Yan
2020-12-25  5:27   ` Leo Yan
2020-12-28 12:54 ` [PATCH v2 0/3] perf arm64: Support SDT Arnaldo Carvalho de Melo
2020-12-28 12:54   ` Arnaldo Carvalho de Melo
2020-12-29  1:26   ` Leo Yan
2020-12-29  1:26     ` Leo Yan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.