[PATCH kvm-unit-tests] access: use write_cr4_checking to verify support for SMEP or PKE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Free set_cr4_smep from having to report failure to set CR4.SMEP,
so that it can report instead whether CR4 was changed.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
 x86/access.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index 7dc9eb6..66bd466 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -192,26 +192,23 @@ static void set_cr0_wp(int wp)
     }
 }
 
-static unsigned set_cr4_smep(int smep)
+static void set_cr4_smep(int smep)
 {
     unsigned long cr4 = shadow_cr4;
     extern u64 ptl2[];
-    unsigned r;
 
     cr4 &= ~CR4_SMEP_MASK;
     if (smep)
 	cr4 |= CR4_SMEP_MASK;
     if (cr4 == shadow_cr4)
-        return 0;
+        return;
 
     if (smep)
         ptl2[2] &= ~PT_USER_MASK;
-    r = write_cr4_checking(cr4);
-    if (r || !smep)
+    write_cr4(cr4);
+    if (!smep)
         ptl2[2] |= PT_USER_MASK;
-    if (!r)
-        shadow_cr4 = cr4;
-    return r;
+    shadow_cr4 = cr4;
 }
 
 static void set_cr4_pke(int pke)
@@ -988,19 +985,19 @@ static int ac_test_run(void)
             printf("CR4.PKE not available, disabling PKE tests\n");
 	} else {
             printf("Set PKE in CR4 - expect #GP: FAIL!\n");
-            set_cr4_pke(0);
+            write_cr4_checking(shadow_cr4);
 	}
     }
 
     if (!this_cpu_has(X86_FEATURE_SMEP)) {
 	tests++;
-	if (set_cr4_smep(1) == GP_VECTOR) {
+	if (write_cr4_checking(shadow_cr4 | X86_CR4_SMEP) == GP_VECTOR) {
             successes++;
             invalid_mask |= AC_CPU_CR4_SMEP_MASK;
             printf("CR4.SMEP not available, disabling SMEP tests\n");
 	} else {
             printf("Set SMEP in CR4 - expect #GP: FAIL!\n");
-            set_cr4_smep(0);
+            write_cr4_checking(shadow_cr4);
 	}
     }
 
-- 
2.30.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux