diff mbox series

[kvm-unit-tests,3/4] x86: Add a testcase for !PCID && INVPCID

Message ID 20210212010606.1118184-4-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86: PCID test adjustments | expand

Commit Message

Sean Christopherson Feb. 12, 2021, 1:06 a.m. UTC
Add an "official" testcase for a guest with PCID disabled but INVPCID
enabled, which is supported by SVM and will soon be supported by VMX.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/pcid.c        | 9 +++++++--
 x86/unittests.cfg | 5 +++++
 2 files changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/x86/pcid.c b/x86/pcid.c
index 64efd05..527a4a9 100644
--- a/x86/pcid.c
+++ b/x86/pcid.c
@@ -68,7 +68,7 @@  report:
     report(passed, "Test on PCID when disabled");
 }
 
-static void test_invpcid_enabled(void)
+static void test_invpcid_enabled(int pcid_enabled)
 {
     int passed = 0, i;
     ulong cr4 = read_cr4();
@@ -93,6 +93,10 @@  static void test_invpcid_enabled(void)
             goto report;
     }
 
+    /* Skip tests that require the PCIDE=1 if PCID isn't supported. */
+    if (!pcid_enabled)
+        goto success;
+
     if (write_cr4_checking(cr4 | X86_CR4_PCIDE) != 0)
         goto report;
 
@@ -103,6 +107,7 @@  static void test_invpcid_enabled(void)
     if (invpcid_checking(2, &desc) != 0)
         goto report;
 
+success:
     passed = 1;
 
 report:
@@ -139,7 +144,7 @@  int main(int ac, char **av)
         test_pcid_disabled();
 
     if (invpcid_enabled)
-        test_invpcid_enabled();
+        test_invpcid_enabled(pcid_enabled);
     else
         test_invpcid_disabled();
 
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index c3a4ee0..d8ef717 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -252,6 +252,11 @@  file = pcid.flat
 extra_params = -cpu qemu64,-pcid,-invpcid
 arch = x86_64
 
+[pcid-asymmetric]
+file = pcid.flat
+extra_params = -cpu qemu64,-pcid,+invpcid
+arch = x86_64
+
 [rdpru]
 file = rdpru.flat
 extra_params = -cpu max