mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gautam Menghani <gautam@linux.ibm.com>
To: maddy@linux.ibm.com, npiggin@gmail.com, mpe@ellerman.id.au,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	atrajeev@linux.ibm.com, tshah@linux.ibm.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH v3 3/3] KVM: PPC: Book3s HV: Ensure reliable usage of latency counters
Date: Fri,  6 Nov 2026 21:01:34 +0530	[thread overview]
Message-ID: <20261106153136.330165-4-gautam@linux.ibm.com> (raw)
In-Reply-To: <20261106153136.330165-1-gautam@linux.ibm.com>

The kvmppc_vcpu_stats tracepoint and the vpa-pmu driver can both enable
and disable the latency counters in the VPA. When both are used
together, they can step on each other and produce unreliable numbers.
Since the VPA element for enabling/disabling counters
(l2_counters_enable) continues counting with any value > 0, introduce a
spinlock to ensure that the tracepoint and vpa-pmu driver can work
correctly together.

Fixes: e1f288d2f9c6 ("KVM: PPC: Book3S HV nestedv2: Add support for reading VPA counters for pseries guests")
Cc: stable@vger.kernel.org
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
 arch/powerpc/kvm/book3s_hv.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 5fa6f93548ad..e1bde3c6b0c4 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -4142,14 +4142,19 @@ int kvmhv_get_l2_counters_status(void)
 		get_lppaca()->l2_counters_enable;
 }
 
+static DEFINE_RAW_SPINLOCK(l2_counters_lock);
 void kvmhv_set_l2_counters_status(int cpu, bool status)
 {
+	unsigned long flags;
+
 	if (!firmware_has_feature(FW_FEATURE_LPAR))
 		return;
+	raw_spin_lock_irqsave(&l2_counters_lock, flags);
 	if (status)
-		lppaca_of(cpu).l2_counters_enable = 1;
+		lppaca_of(cpu).l2_counters_enable++;
 	else
-		lppaca_of(cpu).l2_counters_enable = 0;
+		lppaca_of(cpu).l2_counters_enable--;
+	raw_spin_unlock_irqrestore(&l2_counters_lock, flags);
 }
 EXPORT_SYMBOL(kvmhv_set_l2_counters_status);
 
-- 
2.56.0


  parent reply	other threads:[~2026-11-06 15:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 15:31 [PATCH v3 0/3] powerpc/perf: Fix vpa-pmu driver to report correct numbers Gautam Menghani
2026-11-06 15:31 ` [PATCH v3 1/3] Revert "powerpc/perf: Add per-task/process monitoring to vpa_pmu driver" Gautam Menghani
2026-11-06 15:31 ` [PATCH v3 2/3] powerpc/perf: Update prev_count of event to get accurate values Gautam Menghani
2026-11-06 15:31 ` Gautam Menghani [this message]
2026-11-06 16:02 ` [PATCH v3 0/3] powerpc/perf: Fix vpa-pmu driver to report correct numbers Gautam Menghani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261106153136.330165-4-gautam@linux.ibm.com \
    --to=gautam@linux.ibm.com \
    --cc=atrajeev@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=tshah@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®