[PATCH kvm-unit-tests 11/13] x86: access: remove leaf argument to ac_test_permissions

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

 



By merging the W, U and NX bits, the tests before the "if (!leaf)" check
can be done just once, on the leaf entry (the PDE for large pages,
otherwise the PTE.

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

diff --git a/x86/access.c b/x86/access.c
index b2c77e2..89273d4 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -337,7 +337,7 @@ void ac_test_reset_pt_pool(ac_pool_t *pool)
 }
 
 pt_element_t ac_test_permissions(ac_test_t *at, unsigned flags, bool writable,
-                                 bool user, bool executable, bool leaf)
+                                 bool user, bool executable)
 {
     bool kwritable = !F(AC_CPU_CR0_WP) && !F(AC_ACCESS_USER);
     pt_element_t expected = 0;
@@ -351,9 +351,6 @@ pt_element_t ac_test_permissions(ac_test_t *at, unsigned flags, bool writable,
     if (F(AC_ACCESS_FETCH) && !executable)
 	at->expected_fault = 1;
 
-    if (!leaf)
-        goto done;
-
     if (F(AC_ACCESS_FETCH) && user && F(AC_CPU_CR4_SMEP))
         at->expected_fault = 1;
 
@@ -369,12 +366,11 @@ pt_element_t ac_test_permissions(ac_test_t *at, unsigned flags, bool writable,
         }
     }
 
-    if (F(AC_ACCESS_WRITE) && !at->expected_fault)
-        expected |= PT_DIRTY_MASK;
-
-done:
-    if (!at->expected_fault)
+    if (!at->expected_fault) {
         expected |= PT_ACCESSED_MASK;
+        if (F(AC_ACCESS_WRITE))
+            expected |= PT_DIRTY_MASK;
+    }
 
     return expected;
 }
@@ -414,12 +410,14 @@ void ac_emulate_access(ac_test_t *at, unsigned flags)
     user = F(AC_PDE_USER);
     executable = !F(AC_PDE_NX);
 
-    at->expected_pde |= ac_test_permissions(at, flags, writable, user,
-                                            executable, F(AC_PDE_PSE));
     if (F(AC_PDE_PSE)) {
+        at->expected_pde |= ac_test_permissions(at, flags, writable, user,
+                                                executable);
 	goto no_pte;
     }
 
+    at->expected_pde |= PT_ACCESSED_MASK;
+
     pte_valid = F(AC_PTE_PRESENT)
         && !F(AC_PTE_BIT51)
         && !(F(AC_PTE_NX) && !F(AC_CPU_EFER_NX));
@@ -439,7 +437,7 @@ void ac_emulate_access(ac_test_t *at, unsigned flags)
     executable &= !F(AC_PTE_NX);
 
     at->expected_pte |= ac_test_permissions(at, flags, writable, user,
-                                            executable, true);
+                                            executable);
 
 no_pte:
 fault:
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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