From: Sandipan Das <sandipan.das@amd.com>
To: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>, <tglx@linutronix.de>,
<mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>,
<x86@kernel.org>, <hpa@zytor.com>, <likexu@tencent.com>,
<dapeng1.mi@linux.intel.com>, <rkagan@amazon.de>,
<mizhang@google.com>, <tao1.su@linux.intel.com>,
<jmattson@google.com>, <andriy.shevchenko@linux.intel.com>,
<ravi.bangoria@amd.com>, <ananth.narayan@amd.com>,
<nikunj.dadhania@amd.com>, <santosh.shukla@amd.com>,
<manali.shukla@amd.com>, <babu.moger@amd.com>,
<sandipan.das@amd.com>
Subject: [PATCH] KVM: x86/svm/pmu: Set PerfMonV2 global control bits correctly
Date: Fri, 1 Mar 2024 13:20:07 +0530 [thread overview]
Message-ID: <20240301075007.644152-1-sandipan.das@amd.com> (raw)
With PerfMonV2, a performance monitoring counter will start operating
only when both the PERF_CTLx enable bit as well as the corresponding
PerfCntrGlobalCtl enable bit are set.
When the PerfMonV2 CPUID feature bit (leaf 0x80000022 EAX bit 0) is set
for a guest but the guest kernel does not support PerfMonV2 (such as
kernels older than v5.19), the guest counters do not count since the
PerfCntrGlobalCtl MSR is initialized to zero and the guest kernel never
writes to it.
This is not observed on bare-metal as the default value of the
PerfCntrGlobalCtl MSR after a reset is 0x3f (assuming there are six
counters) and the counters can still be operated by using the enable
bit in the PERF_CTLx MSRs. Replicate the same behaviour in guests for
compatibility with older kernels.
Before:
$ perf stat -e cycles:u true
Performance counter stats for 'true':
0 cycles:u
0.001074773 seconds time elapsed
0.001169000 seconds user
0.000000000 seconds sys
After:
$ perf stat -e cycles:u true
Performance counter stats for 'true':
227,850 cycles:u
0.037770758 seconds time elapsed
0.000000000 seconds user
0.037886000 seconds sys
Reported-by: Babu Moger <babu.moger@amd.com>
Fixes: 4a2771895ca6 ("KVM: x86/svm/pmu: Add AMD PerfMonV2 support")
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
---
arch/x86/kvm/svm/pmu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c
index b6a7ad4d6914..14709c564d6a 100644
--- a/arch/x86/kvm/svm/pmu.c
+++ b/arch/x86/kvm/svm/pmu.c
@@ -205,6 +205,7 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu)
if (pmu->version > 1) {
pmu->global_ctrl_mask = ~((1ull << pmu->nr_arch_gp_counters) - 1);
pmu->global_status_mask = pmu->global_ctrl_mask;
+ pmu->global_ctrl = ~pmu->global_ctrl_mask;
}
pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;
--
2.34.1
next reply other threads:[~2024-03-01 7:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 7:50 Sandipan Das [this message]
2024-03-01 8:37 ` [PATCH] KVM: x86/svm/pmu: Set PerfMonV2 global control bits correctly Like Xu
2024-03-01 9:00 ` Sandipan Das
2024-03-04 7:59 ` Mi, Dapeng
2024-03-04 19:46 ` Sean Christopherson
2024-03-04 20:17 ` Mingwei Zhang
2024-03-05 2:31 ` Like Xu
2024-03-05 17:22 ` Sean Christopherson
2024-03-05 18:04 ` Sean Christopherson
2024-03-05 18:31 ` Mingwei Zhang
2024-03-06 2:32 ` Mi, Dapeng
2024-03-06 3:23 ` Like Xu
2024-03-06 5:17 ` Sandipan Das
2024-03-06 2:48 ` Mi, Dapeng
2024-03-04 20:06 ` Mingwei Zhang
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=20240301075007.644152-1-sandipan.das@amd.com \
--to=sandipan.das@amd.com \
--cc=ananth.narayan@amd.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=babu.moger@amd.com \
--cc=bp@alien8.de \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=likexu@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manali.shukla@amd.com \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=nikunj.dadhania@amd.com \
--cc=pbonzini@redhat.com \
--cc=ravi.bangoria@amd.com \
--cc=rkagan@amazon.de \
--cc=santosh.shukla@amd.com \
--cc=seanjc@google.com \
--cc=tao1.su@linux.intel.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.