* [PATCH 0/2] perf kvm: Don't create an empty perf.data in live mode
@ 2026-11-25 15:12 James Clark
2026-11-25 15:12 ` [PATCH 1/2] perf kvm: Don't pass an ERR_PTR to perf_session__delete() James Clark
` (2 more replies)
0 siblings, 3 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
Running the perf tests drops an empty perf.data file in the cwd which
gets in the way sometimes, especially when the tests are run as root.
Fix an existing error path bug to appease Sashiko, then fix the empty
data file.
Assisted by Claude Opus 5.5.
Signed-off-by: James Clark <james.clark@linaro.org>
---
James Clark (2):
perf kvm: Don't pass an ERR_PTR to perf_session__delete()
perf kvm: Don't create an empty perf.data in live mode
tools/perf/builtin-kvm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
---
base-commit: 148690b95cc425950dbba79d73eb4f7938347fce
change-id: 20261125-james-perf-kvm-live-file-520dbff37b4f
Best regards,
--
James Clark <james.clark@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [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
* Re: [PATCH 0/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 ` [PATCH 2/2] perf kvm: Don't create an empty perf.data in live mode James Clark
@ 2026-11-25 15:18 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-25 15:18 UTC (permalink / raw)
To: James Clark; +Cc: linux-perf-users
Sashiko has reviewed this 2-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-james-perf-kvm-live-file-v1-0-946f478ce2a1@linaro.org
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 15:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox