[PATCH v3 2/3] powerpc/perf: Update prev_count of event to get accurate values

From: Gautam Menghani

Date: Fri Nov 06 2026 - 10:35:55 EST


When vpa_pmu_read() is called twice while a vCPU is running on the same
host cpu, the "event->hw.prev_count" variable returns the same old value on
the 2nd read which results in a larger value getting added to
event->count.

Fix this by updating the event->hw.prev_count every time vpa_pmu_read()
is called.

Fixes: 176cda0619b6 ("powerpc/perf: Add perf interface to expose vpa counters")
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Gautam Menghani <gautam@xxxxxxxxxxxxx>
---
v2 -> v3:
1. Use local64_xchg for atomic update.

v1 -> v2:
1. Add stable/fixes tags.

arch/powerpc/perf/vpa-pmu.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/perf/vpa-pmu.c b/arch/powerpc/perf/vpa-pmu.c
index 01d9196fcb0f..3296877eb317 100644
--- a/arch/powerpc/perf/vpa-pmu.c
+++ b/arch/powerpc/perf/vpa-pmu.c
@@ -132,6 +132,7 @@ static void vpa_pmu_read(struct perf_event *event)

prev_data = local64_read(&event->hw.prev_count);
new_data = get_counter_data(event);
+ prev_data = local64_xchg(&event->hw.prev_count, new_data);
final_data = new_data - prev_data;

local64_add(final_data, &event->count);
--
2.56.0