Skip to contentSkip to conversation

x86: PCID test adjustments

PATCH Applied Sean Christopherson 2 participants 6 messages Feb 12, 2021 – Feb 15, 2021 KVM

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

cover x86: PCID test adjustments

Adjust the PCID test to remove the enforment that INVPCID is enabled iff PCID is enabled, and add explicit coverage of the newly allowed scneario.

Sean Christopherson (4):
x86: Remove PCID test that INVPCID isn't enabled without PCID
x86: Iterate over all INVPCID types in the enabled test
x86: Add a testcase for !PCID && INVPCID
x86: Add a 'pcid' group for the various PCID+INVPCID permutations

 x86/pcid.c        | 35 ++++++++++++++++++-----------------
 x86/unittests.cfg | 10 +++++++++-
 2 files changed, 27 insertions(+), 18 deletions(-)
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
author reviewer
#1 lore raw

PATCH 1/4 x86: Remove PCID test that INVPCID isn't enabled without PCID

Drop the test that verifies INVPCID isn't enabled in the guest without PCID also being enabled. SVM allows !PCID && INVPCID, and VMX will soon follow.

https://lkml.kernel.org/r/[email protected]

---
 x86/pcid.c | 8 --------
 1 file changed, 8 deletions(-)
x86/pcid.c +0 -8
index a8dc8cb..ee0b726 100644
@@ -26,12 +26,6 @@ static int invpcid_checking(unsigned long type, void *desc)
     return exception_vector();
 }
 
-static void test_cpuid_consistency(int pcid_enabled, int invpcid_enabled)
-{
-    int passed = !(!pcid_enabled && invpcid_enabled);
-    report(passed, "CPUID consistency");
-}
-
 static void test_pcid_enabled(void)
 {
     int passed = 0;
@@ -135,8 +129,6 @@ int main(int ac, char **av)
     if (this_cpu_has(X86_FEATURE_INVPCID))
         invpcid_enabled = 1;
 
-    test_cpuid_consistency(pcid_enabled, invpcid_enabled);
-
     if (pcid_enabled)
         test_pcid_enabled();
     else
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
author reviewer
#2 lore raw

PATCH 2/4 x86: Iterate over all INVPCID types in the enabled test

In reply to Sean Christopherson

Verify that INVPCID works with all types, even those that take a PCID, when CR4.PCIDE=0. So long as the target PCID=0, INVPCID is legal even if CR4.PCIDE=0.

---
 x86/pcid.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
x86/pcid.c +11 -7
index ee0b726..64efd05 100644
@@ -70,24 +70,28 @@ report:
 
 static void test_invpcid_enabled(void)
 {
-    int passed = 0;
+    int passed = 0, i;
     ulong cr4 = read_cr4();
     struct invpcid_desc desc;
     desc.rsv = 0;
 
-    /* try executing invpcid when CR4.PCIDE=0, desc.pcid=0 and type=1
+    /* try executing invpcid when CR4.PCIDE=0, desc.pcid=0 and type=0..3
      * no exception expected
      */
     desc.pcid = 0;
-    if (invpcid_checking(1, &desc) != 0)
-        goto report;
+    for (i = 0; i < 4; i++) {
+        if (invpcid_checking(i, &desc) != 0)
+            goto report;
+    }
 
-    /* try executing invpcid when CR4.PCIDE=0, desc.pcid=1 and type=1
+    /* try executing invpcid when CR4.PCIDE=0, desc.pcid=1 and type=0..1
      * #GP expected
      */
     desc.pcid = 1;
-    if (invpcid_checking(1, &desc) != GP_VECTOR)
-        goto report;
+    for (i = 0; i < 2; i++) {
+        if (invpcid_checking(i, &desc) != GP_VECTOR)
+            goto report;
+    }
 
     if (write_cr4_checking(cr4 | X86_CR4_PCIDE) != 0)
         goto report;
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
author reviewer
#3 lore raw

PATCH 3/4 x86: Add a testcase for !PCID && INVPCID

In reply to Sean Christopherson

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.

---
 x86/pcid.c        | 9 +++++++--
 x86/unittests.cfg | 5 +++++
 2 files changed, 12 insertions(+), 2 deletions(-)
x86/pcid.c +7 -2
index 64efd05..527a4a9 100644
@@ -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();
 
x86/unittests.cfg +5 -0
index c3a4ee0..d8ef717 100644
@@ -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
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
author reviewer
#4 lore raw

PATCH 4/4 x86: Add a 'pcid' group for the various PCID+INVPCID permutations

In reply to Sean Christopherson

Rename the 'pcid' test to 'pcid-enabled' and add a 'pcid' group to allow easily running all three tests.

---
 x86/unittests.cfg | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
x86/unittests.cfg +4 -1
index d8ef717..0698d15 100644
@@ -242,20 +242,23 @@ file = kvmclock_test.flat
 smp = 2
 extra_params = --append "10000000 `date +%s`"
 
-[pcid]
+[pcid-enabled]
 file = pcid.flat
 extra_params = -cpu qemu64,+pcid,+invpcid
 arch = x86_64
+groups = pcid
 
 [pcid-disabled]
 file = pcid.flat
 extra_params = -cpu qemu64,-pcid,-invpcid
 arch = x86_64
+groups = pcid
 
 [pcid-asymmetric]
 file = pcid.flat
 extra_params = -cpu qemu64,-pcid,+invpcid
 arch = x86_64
+groups = pcid
 
 [rdpru]
 file = rdpru.flat
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
maintainer Applied
#5 lore raw
In reply to Sean Christopherson
Quoted 9 lines · Sean Christopherson

Adjust the PCID test to remove the enforment that INVPCID is enabled iff PCID is enabled, and add explicit coverage of the newly allowed scneario.

Sean Christopherson (4):
x86: Remove PCID test that INVPCID isn't enabled without PCID
x86: Iterate over all INVPCID types in the enabled test
x86: Add a testcase for !PCID && INVPCID
x86: Add a 'pcid' group for the various PCID+INVPCID permutations

Quoted 4 lines
  x86/pcid.c        | 35 ++++++++++++++++++-----------------
  x86/unittests.cfg | 10 +++++++++-
  2 files changed, 27 insertions(+), 18 deletions(-)

Queued, thanks.

Paolo