linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips
@ 2024-10-01  5:23 Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path Ian Rogers
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ian Rogers @ 2024-10-01  5:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
	linux-kernel

Fix some memory leaks that show up testing as !root. Lower some test
failures to skips for the !root case with a skip reason of
permissions.

v2: Rebase that also cleans up on the bpf_counter__load error path, as
    pointed out by Namhyung.
v1: https://lore.kernel.org/lkml/20240924202916.1560687-1-irogers@google.com/

Ian Rogers (4):
  perf stat: Fix affinity memory leaks on error path
  perf test: Fix memory leaks on event-times error paths
  perf test: Skip not fail tp fields test when insufficient permissions
  perf test: Skip not fail syscall tp fields test when insufficient
    permissions

 tools/perf/builtin-stat.c                   |  2 ++
 tools/perf/tests/event-times.c              |  5 +--
 tools/perf/tests/evsel-tp-sched.c           | 40 +++++++++++++--------
 tools/perf/tests/openat-syscall-tp-fields.c | 19 +++++++---
 4 files changed, 45 insertions(+), 21 deletions(-)

-- 
2.46.1.824.gd892dcdcdd-goog


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

* [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path
  2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
@ 2024-10-01  5:23 ` Ian Rogers
  2024-10-02  0:02   ` Namhyung Kim
  2024-10-01  5:23 ` [PATCH v2 2/4] perf test: Fix memory leaks on event-times error paths Ian Rogers
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2024-10-01  5:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
	linux-kernel

Missed cleanup when an error occurs.

Fixes: 49de179577e7 ("perf stat: No need to setup affinities when starting a workload")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/builtin-stat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1521b6df2606..3e6b9f216e80 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -827,6 +827,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 		}
 	}
 	affinity__cleanup(affinity);
+	affinity = NULL;
 
 	evlist__for_each_entry(evsel_list, counter) {
 		if (!counter->supported) {
@@ -965,6 +966,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 	if (forks)
 		evlist__cancel_workload(evsel_list);
 
+	affinity__cleanup(affinity);
 	return err;
 }
 
-- 
2.46.1.824.gd892dcdcdd-goog


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

* [PATCH v2 2/4] perf test: Fix memory leaks on event-times error paths
  2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path Ian Rogers
@ 2024-10-01  5:23 ` Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 3/4] perf test: Skip not fail tp fields test when insufficient permissions Ian Rogers
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2024-10-01  5:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
	linux-kernel

These error paths occur without sufficient permissions. Fix the memory
leaks to make leak sanitizer happier.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/event-times.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index e155f0e0e04d..deefe5003bfc 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -126,6 +126,7 @@ static int attach__cpu_disabled(struct evlist *evlist)
 	evsel->core.attr.disabled = 1;
 
 	err = evsel__open_per_cpu(evsel, cpus, -1);
+	perf_cpu_map__put(cpus);
 	if (err) {
 		if (err == -EACCES)
 			return TEST_SKIP;
@@ -134,7 +135,6 @@ static int attach__cpu_disabled(struct evlist *evlist)
 		return err;
 	}
 
-	perf_cpu_map__put(cpus);
 	return evsel__enable(evsel);
 }
 
@@ -153,10 +153,10 @@ static int attach__cpu_enabled(struct evlist *evlist)
 	}
 
 	err = evsel__open_per_cpu(evsel, cpus, -1);
+	perf_cpu_map__put(cpus);
 	if (err == -EACCES)
 		return TEST_SKIP;
 
-	perf_cpu_map__put(cpus);
 	return err ? TEST_FAIL : TEST_OK;
 }
 
@@ -188,6 +188,7 @@ static int test_times(int (attach)(struct evlist *),
 	err = attach(evlist);
 	if (err == TEST_SKIP) {
 		pr_debug("  SKIP  : not enough rights\n");
+		evlist__delete(evlist);
 		return err;
 	}
 
-- 
2.46.1.824.gd892dcdcdd-goog


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

* [PATCH v2 3/4] perf test: Skip not fail tp fields test when insufficient permissions
  2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 2/4] perf test: Fix memory leaks on event-times error paths Ian Rogers
@ 2024-10-01  5:23 ` Ian Rogers
  2024-10-01  5:23 ` [PATCH v2 4/4] perf test: Skip not fail syscall " Ian Rogers
  2024-10-02 22:04 ` [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2024-10-01  5:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
	linux-kernel

Clean up return value to be TEST_* rather than unspecific integer. Add
test case skip reason. Skip test if EACCES comes back from
evsel__newtp.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/evsel-tp-sched.c | 40 +++++++++++++++++++------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c
index cf4da3d748c2..3da6a76eac38 100644
--- a/tools/perf/tests/evsel-tp-sched.c
+++ b/tools/perf/tests/evsel-tp-sched.c
@@ -36,33 +36,33 @@ static int test__perf_evsel__tp_sched_test(struct test_suite *test __maybe_unuse
 					   int subtest __maybe_unused)
 {
 	struct evsel *evsel = evsel__newtp("sched", "sched_switch");
-	int ret = 0;
+	int ret = TEST_OK;
 
 	if (IS_ERR(evsel)) {
 		pr_debug("evsel__newtp failed with %ld\n", PTR_ERR(evsel));
-		return -1;
+		return PTR_ERR(evsel) == -EACCES ? TEST_SKIP : TEST_FAIL;
 	}
 
 	if (evsel__test_field(evsel, "prev_comm", 16, false))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "prev_pid", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "prev_prio", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "prev_state", sizeof(long), true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "next_comm", 16, false))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "next_pid", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "next_prio", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	evsel__delete(evsel);
 
@@ -70,23 +70,33 @@ static int test__perf_evsel__tp_sched_test(struct test_suite *test __maybe_unuse
 
 	if (IS_ERR(evsel)) {
 		pr_debug("evsel__newtp failed with %ld\n", PTR_ERR(evsel));
-		return -1;
+		return TEST_FAIL;
 	}
 
 	if (evsel__test_field(evsel, "comm", 16, false))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "pid", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "prio", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	if (evsel__test_field(evsel, "target_cpu", 4, true))
-		ret = -1;
+		ret = TEST_FAIL;
 
 	evsel__delete(evsel);
 	return ret;
 }
 
-DEFINE_SUITE("Parse sched tracepoints fields", perf_evsel__tp_sched_test);
+static struct test_case tests__perf_evsel__tp_sched_test[] = {
+	TEST_CASE_REASON("Parse sched tracepoints fields",
+			 perf_evsel__tp_sched_test,
+			 "permissions"),
+	{	.name = NULL, }
+};
+
+struct test_suite suite__perf_evsel__tp_sched_test = {
+	.desc = "Parse sched tracepoints fields",
+	.test_cases = tests__perf_evsel__tp_sched_test,
+};
-- 
2.46.1.824.gd892dcdcdd-goog


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

* [PATCH v2 4/4] perf test: Skip not fail syscall tp fields test when insufficient permissions
  2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
                   ` (2 preceding siblings ...)
  2024-10-01  5:23 ` [PATCH v2 3/4] perf test: Skip not fail tp fields test when insufficient permissions Ian Rogers
@ 2024-10-01  5:23 ` Ian Rogers
  2024-10-02 22:04 ` [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2024-10-01  5:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
	linux-kernel

Clean up return value to be TEST_* rather than unspecific integer. Add
test case skip reason. Skip test if EACCES comes back from
evsel__newtp.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/openat-syscall-tp-fields.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 888df8eca981..3943da441979 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -40,7 +40,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 	int flags = O_RDONLY | O_DIRECTORY;
 	struct evlist *evlist = evlist__new();
 	struct evsel *evsel;
-	int err = -1, i, nr_events = 0, nr_polls = 0;
+	int ret = TEST_FAIL, err, i, nr_events = 0, nr_polls = 0;
 	char sbuf[STRERR_BUFSIZE];
 
 	if (evlist == NULL) {
@@ -51,6 +51,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 	evsel = evsel__newtp("syscalls", "sys_enter_openat");
 	if (IS_ERR(evsel)) {
 		pr_debug("%s: evsel__newtp\n", __func__);
+		ret = PTR_ERR(evsel) == -EACCES ? TEST_SKIP : TEST_FAIL;
 		goto out_delete_evlist;
 	}
 
@@ -138,11 +139,21 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 		}
 	}
 out_ok:
-	err = 0;
+	ret = TEST_OK;
 out_delete_evlist:
 	evlist__delete(evlist);
 out:
-	return err;
+	return ret;
 }
 
-DEFINE_SUITE("syscalls:sys_enter_openat event fields", syscall_openat_tp_fields);
+static struct test_case tests__syscall_openat_tp_fields[] = {
+	TEST_CASE_REASON("syscalls:sys_enter_openat event fields",
+			 syscall_openat_tp_fields,
+			 "permissions"),
+	{	.name = NULL, }
+};
+
+struct test_suite suite__syscall_openat_tp_fields = {
+	.desc = "syscalls:sys_enter_openat event fields",
+	.test_cases = tests__syscall_openat_tp_fields,
+};
-- 
2.46.1.824.gd892dcdcdd-goog


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

* Re: [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path
  2024-10-01  5:23 ` [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path Ian Rogers
@ 2024-10-02  0:02   ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2024-10-02  0:02 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
	Kan Liang, linux-perf-users, linux-kernel

On Mon, Sep 30, 2024 at 10:23:24PM -0700, Ian Rogers wrote:
> Missed cleanup when an error occurs.
> 
> Fixes: 49de179577e7 ("perf stat: No need to setup affinities when starting a workload")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/builtin-stat.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 1521b6df2606..3e6b9f216e80 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -827,6 +827,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
>  		}
>  	}
>  	affinity__cleanup(affinity);
> +	affinity = NULL;
>  
>  	evlist__for_each_entry(evsel_list, counter) {
>  		if (!counter->supported) {
> @@ -965,6 +966,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
>  	if (forks)
>  		evlist__cancel_workload(evsel_list);
>  
> +	affinity__cleanup(affinity);
>  	return err;

Much better now, thanks!
Namhyung


>  }
>  
> -- 
> 2.46.1.824.gd892dcdcdd-goog
> 

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

* Re: [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips
  2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
                   ` (3 preceding siblings ...)
  2024-10-01  5:23 ` [PATCH v2 4/4] perf test: Skip not fail syscall " Ian Rogers
@ 2024-10-02 22:04 ` Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2024-10-02 22:04 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
	Kan Liang, linux-perf-users, linux-kernel, Ian Rogers

On Mon, 30 Sep 2024 22:23:23 -0700, Ian Rogers wrote:

> Fix some memory leaks that show up testing as !root. Lower some test
> failures to skips for the !root case with a skip reason of
> permissions.
> 
> v2: Rebase that also cleans up on the bpf_counter__load error path, as
>     pointed out by Namhyung.
> v1: https://lore.kernel.org/lkml/20240924202916.1560687-1-irogers@google.com/
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung

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

end of thread, other threads:[~2024-10-02 22:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01  5:23 [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Ian Rogers
2024-10-01  5:23 ` [PATCH v2 1/4] perf stat: Fix affinity memory leaks on error path Ian Rogers
2024-10-02  0:02   ` Namhyung Kim
2024-10-01  5:23 ` [PATCH v2 2/4] perf test: Fix memory leaks on event-times error paths Ian Rogers
2024-10-01  5:23 ` [PATCH v2 3/4] perf test: Skip not fail tp fields test when insufficient permissions Ian Rogers
2024-10-01  5:23 ` [PATCH v2 4/4] perf test: Skip not fail syscall " Ian Rogers
2024-10-02 22:04 ` [PATCH v2 0/4] 2 leak fixes and lower 2 test fails to skips Namhyung Kim

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