From: Yang Weijiang <weijiang.yang@intel.com>
To: seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org
Cc: Yang Weijiang <weijiang.yang@intel.com>
Subject: [kvm-unit-tests PATCH 3/4] x86: Skip perf related tests when platform cannot support
Date: Mon, 11 Jul 2022 00:18:40 -0400 [thread overview]
Message-ID: <20220711041841.126648-4-weijiang.yang@intel.com> (raw)
In-Reply-To: <20220711041841.126648-1-weijiang.yang@intel.com>
Add helpers to check whether MSR_CORE_PERF_GLOBAL_CTRL and rdpmc are
supported in KVM. When pmu is disabled with enable_pmu=0, reading
MSR_CORE_PERF_GLOBAL_CTRL or executing rdpmc leads to #GP, so skip
related tests in this case to avoid test failure.
Opportunistically hoist mwait support check function as helper and
change related code.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
lib/x86/processor.h | 15 +++++++++++++++
x86/vmx_tests.c | 21 +++++++++++++--------
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index d071aba..b772cf3 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -744,4 +744,19 @@ static inline u8 pmu_fixed_counter_width(void)
else
return 0;
}
+
+static inline bool cpu_has_perf_global_ctrl(void)
+{
+ return pmu_version() > 1;
+}
+
+static inline bool cpu_has_pmu(void)
+{
+ return !!pmu_version();
+}
+
+static inline bool cpu_has_mwait(void)
+{
+ return this_cpu_has(X86_FEATURE_MWAIT);
+}
#endif
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index d5868a3..3afc8b8 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -847,11 +847,6 @@ u64 cr3;
typedef bool (*supported_fn)(void);
-static bool monitor_supported(void)
-{
- return this_cpu_has(X86_FEATURE_MWAIT);
-}
-
struct insn_table {
const char *name;
u32 flag;
@@ -880,8 +875,8 @@ static struct insn_table insn_table[] = {
{"HLT", CPU_HLT, insn_hlt, INSN_CPU0, 12, 0, 0, 0},
{"INVLPG", CPU_INVLPG, insn_invlpg, INSN_CPU0, 14,
0x12345678, 0, FIELD_EXIT_QUAL},
- {"MWAIT", CPU_MWAIT, insn_mwait, INSN_CPU0, 36, 0, 0, 0, &monitor_supported},
- {"RDPMC", CPU_RDPMC, insn_rdpmc, INSN_CPU0, 15, 0, 0, 0},
+ {"MWAIT", CPU_MWAIT, insn_mwait, INSN_CPU0, 36, 0, 0, 0, &cpu_has_mwait},
+ {"RDPMC", CPU_RDPMC, insn_rdpmc, INSN_CPU0, 15, 0, 0, 0, &cpu_has_pmu},
{"RDTSC", CPU_RDTSC, insn_rdtsc, INSN_CPU0, 16, 0, 0, 0},
{"CR3 load", CPU_CR3_LOAD, insn_cr3_load, INSN_CPU0, 28, 0x3, 0,
FIELD_EXIT_QUAL},
@@ -891,7 +886,7 @@ static struct insn_table insn_table[] = {
FIELD_EXIT_QUAL},
{"CR8 store", CPU_CR8_STORE, insn_cr8_store, INSN_CPU0, 28, 0x18, 0,
FIELD_EXIT_QUAL},
- {"MONITOR", CPU_MONITOR, insn_monitor, INSN_CPU0, 39, 0, 0, 0, &monitor_supported},
+ {"MONITOR", CPU_MONITOR, insn_monitor, INSN_CPU0, 39, 0, 0, 0, &cpu_has_mwait},
{"PAUSE", CPU_PAUSE, insn_pause, INSN_CPU0, 40, 0, 0, 0},
// Flags for Secondary Processor-Based VM-Execution Controls
{"WBINVD", CPU_WBINVD, insn_wbinvd, INSN_CPU1, 54, 0, 0, 0},
@@ -7490,6 +7485,11 @@ static void test_perf_global_ctrl(u32 nr, const char *name, u32 ctrl_nr,
static void test_load_host_perf_global_ctrl(void)
{
+ if (!cpu_has_perf_global_ctrl()) {
+ report_skip("%s :IA32_PERF_GLOBAL_CTRL MSR not supported", __func__);
+ return;
+ }
+
if (!(ctrl_exit_rev.clr & EXI_LOAD_PERF)) {
report_skip("%s :\"Load IA32_PERF_GLOBAL_CTRL\" exit control not supported", __func__);
return;
@@ -7502,6 +7502,11 @@ static void test_load_host_perf_global_ctrl(void)
static void test_load_guest_perf_global_ctrl(void)
{
+ if (!cpu_has_perf_global_ctrl()) {
+ report_skip("%s :IA32_PERF_GLOBAL_CTRL MSR not supported", __func__);
+ return;
+ }
+
if (!(ctrl_enter_rev.clr & ENT_LOAD_PERF)) {
report_skip("%s :\"Load IA32_PERF_GLOBAL_CTRL\" entry control not supported", __func__);
return;
--
2.31.1
next prev parent reply other threads:[~2022-07-11 7:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 4:18 [kvm-unit-tests PATCH 0/4] Fixup and cleanup to pmu test applications Yang Weijiang
2022-07-11 4:18 ` [kvm-unit-tests PATCH 1/4] x86: Use report_skip to print messages when tests are skipped Yang Weijiang
2022-07-11 4:18 ` [kvm-unit-tests PATCH 2/4] x86: Use helpers to fetch supported perf capabilities Yang Weijiang
2022-07-21 21:21 ` Sean Christopherson
2022-07-22 0:58 ` Yang, Weijiang
2022-07-11 4:18 ` Yang Weijiang [this message]
2022-07-11 4:18 ` [kvm-unit-tests PATCH 4/4] x86: Check platform pmu capabilities before run lbr tests Yang Weijiang
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=20220711041841.126648-4-weijiang.yang@intel.com \
--to=weijiang.yang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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