[PATCH] perf kvm: Fix arm64 VM-exit duration accounting

From: lirongqing

Date: Sat Oct 31 2026 - 08:02:52 EST


From: Li RongQing <lirongqing@xxxxxxxxx>

Use kvm_exit as the start event and the following kvm_entry as the
end event for arm64 VM-exit statistics. Keep decoding ret and esr_ec
from the exit sample.

Before this change, arm64 measured guest runtime as VM-exit time.

Fixes: 1218838d68f5 ("perf kvm: Add kvm-stat for arm64")
Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c
index 018b0db..ff853ef 100644
--- a/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c
+++ b/tools/perf/util/kvm-stat-arch/kvm-stat-arm64.c
@@ -36,13 +36,7 @@ static void event_get_key(struct perf_sample *sample,
}

static bool event_begin(struct perf_sample *sample,
- struct event_key *key __maybe_unused)
-{
- return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64));
-}
-
-static bool event_end(struct perf_sample *sample,
- struct event_key *key)
+ struct event_key *key)
{
if (evsel__name_is(sample->evsel, kvm_exit_trace(EM_AARCH64))) {
event_get_key(sample, key);
@@ -51,6 +45,12 @@ static bool event_end(struct perf_sample *sample,
return false;
}

+static bool event_end(struct perf_sample *sample,
+ struct event_key *key __maybe_unused)
+{
+ return evsel__name_is(sample->evsel, kvm_entry_trace(EM_AARCH64));
+}
+
static const struct kvm_events_ops exit_events = {
.is_begin_event = event_begin,
.is_end_event = event_end,
--
2.9.4