* [PATCH 1/2] perf kvm: Don't pass an ERR_PTR to perf_session__delete()
2026-11-25 15:12 [PATCH 0/2] perf kvm: Don't create an empty perf.data in live mode James Clark
@ 2026-11-25 15:12 ` James Clark
2026-11-25 15:12 ` [PATCH 2/2] perf kvm: Don't create an empty perf.data in live mode James Clark
2026-11-25 15:18 ` [PATCH 0/2] " sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2026-11-25 15:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Ravi Bangoria, Mukesh Ojha,
Mamatha Inamdar, Leo Yan
Cc: Arnaldo Carvalho de Melo, linux-perf-users, linux-kernel,
James Clark
If perf_session__new() fails, kvm->session is left holding the ERR_PTR
value when jumping to the out label. The cleanup then calls
perf_session__delete() on it, which only checks for NULL and goes on to
dereference the error pointer.
Fix it by clearing kvm->session before the goto. builtin-top.c and
builtin-lock.c already follow the exact same pattern.
Fixes: 6ef81c55a2b6 ("perf session: Return error code for perf_session__new() function on failure")
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/builtin-kvm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 67eb3f667c99..785b761fb951 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1926,6 +1926,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
kvm->session = perf_session__new(&data, &kvm->tool);
if (IS_ERR(kvm->session)) {
err = PTR_ERR(kvm->session);
+ kvm->session = NULL;
goto out;
}
kvm->session->evlist = kvm->evlist;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] perf kvm: Don't create an empty perf.data in live mode
2026-11-25 15:12 [PATCH 0/2] perf kvm: Don't create an empty perf.data in live mode James Clark
2026-11-25 15:12 ` [PATCH 1/2] perf kvm: Don't pass an ERR_PTR to perf_session__delete() James Clark
@ 2026-11-25 15:12 ` James Clark
2026-11-25 15:18 ` [PATCH 0/2] " sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2026-11-25 15:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Ravi Bangoria, Mukesh Ojha,
Mamatha Inamdar, Leo Yan
Cc: Arnaldo Carvalho de Melo, linux-perf-users, linux-kernel,
James Clark
'perf kvm stat live' creates its session with a perf_data in write mode
but with no path, so perf_data__open() defaults to "perf.data" and
creates an empty file in the current directory. This is visible when
running the "perf kvm tests" test.
Do the same thing as 'perf top' and create the session without a
perf_data, passing a host env instead. Live mode never writes anything
to the file anyway.
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/builtin-kvm.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 785b761fb951..c48d56b18487 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1855,9 +1855,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
"perf kvm stat live [<options>]",
NULL
};
- struct perf_data data = {
- .mode = PERF_DATA_MODE_WRITE,
- };
+ struct perf_env host_env;
/* event handling */
@@ -1911,6 +1909,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
return err;
}
+ perf_env__init(&host_env);
kvm->evlist = kvm_live_event_list();
if (kvm->evlist == NULL) {
err = -1;
@@ -1923,7 +1922,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
/*
* perf session
*/
- kvm->session = perf_session__new(&data, &kvm->tool);
+ kvm->session = __perf_session__new(/*data=*/NULL, &kvm->tool,
+ /*trace_event_repipe=*/false,
+ &host_env);
if (IS_ERR(kvm->session)) {
err = PTR_ERR(kvm->session);
kvm->session = NULL;
@@ -1944,6 +1945,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
perf_session__delete(kvm->session);
kvm->session = NULL;
evlist__put(kvm->evlist);
+ perf_env__exit(&host_env);
return err;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread