From: Zide Chen <zide.chen@intel.com>
To: kvm@vger.kernel.org
Cc: Zide Chen <zide.chen@intel.com>, Zhenyu Wang <zhenyuw@linux.intel.com>
Subject: [kvm-unit-test PATCH 1/3] nVMX: fixed-function performance counters could be not contiguous
Date: Mon, 18 Nov 2024 14:52:05 -0800 [thread overview]
Message-ID: <20241118225207.16596-1-zide.chen@intel.com> (raw)
The fixed counters may not be contiguous. Intel SDM recommends how to
use CPUID.0AH to determine if a Fixed Counter is supported:
FxCtr[i]_is_supported := ECX[i] || (EDX[4:0] > i);
For example, it's perfectly valid to have CPUID.0AH.EDX[4:0] == 3 and
CPUID.0AH.ECX == 0x77, but checking the fixed counter index against
CPUID.0AH.EDX[4:0] only, will deem that FxCtr[6:4] are not supported.
Additionally, according to the latest Intel SDM, changed the definition
of cpuidA_edx and renamed num_counters_fixed to num_contiguous_fixed.
Signed-off-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
---
x86/vmx_tests.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index ffe7064c9221..5261927ad2a4 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7332,11 +7332,17 @@ union cpuidA_eax {
unsigned int full;
};
+union cpuidA_ecx {
+ unsigned int fixed_mask;
+};
+
union cpuidA_edx {
struct {
- unsigned int num_counters_fixed:5;
+ unsigned int num_contiguous_fixed:5;
unsigned int bit_width_fixed:8;
- unsigned int reserved:9;
+ unsigned int reserved1:2;
+ unsigned int anythread_deprecated:1;
+ unsigned int reserved2:16;
} split;
unsigned int full;
};
@@ -7345,14 +7351,19 @@ static bool valid_pgc(u64 val)
{
struct cpuid id;
union cpuidA_eax eax;
+ union cpuidA_ecx ecx;
union cpuidA_edx edx;
u64 mask;
id = cpuid(0xA);
eax.full = id.a;
+ ecx.fixed_mask = id.c;
edx.full = id.d;
+
+ /* FxCtr[i]_is_supported := ECX[i] || (EDX[4:0] > i); */
mask = ~(((1ull << eax.split.num_counters_gp) - 1) |
- (((1ull << edx.split.num_counters_fixed) - 1) << 32));
+ (((1ull << edx.split.num_contiguous_fixed) - 1) << 32) |
+ ((u64)ecx.fixed_mask << 32));
return !(val & mask);
}
--
2.34.1
next reply other threads:[~2024-11-18 22:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 22:52 Zide Chen [this message]
2024-11-18 22:52 ` [kvm-unit-test PATCH 2/3] x86/pmu: Fixed PEBS basic record parsing issue Zide Chen
2024-11-18 22:52 ` [kvm-unit-test PATCH 3/3] x86/pmu: Execute PEBS test only if PEBSRecordFormat >= 4 Zide Chen
2025-02-24 17:24 ` [kvm-unit-test PATCH 1/3] nVMX: fixed-function performance counters could be not contiguous Sean Christopherson
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=20241118225207.16596-1-zide.chen@intel.com \
--to=zide.chen@intel.com \
--cc=kvm@vger.kernel.org \
--cc=zhenyuw@linux.intel.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 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.