[kvm-unit-tests PATCH v4 10/12] x86: Cleanup PTE_* flags

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

 



Cc: Andrew Jones <drjones@xxxxxxxxxx>
Cc: Thomas Huth <thuth@xxxxxxxxxx>
Cc: Radim Krčmář <rkrcmar@xxxxxxxxxx>
Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx>
---
 lib/x86/asm/page.h |  3 +++
 lib/x86/vm.c       |  4 ++--
 x86/access.c       | 48 ++++++++++++++++++++----------------------------
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h
index bd7f676..825065a 100644
--- a/lib/x86/asm/page.h
+++ b/lib/x86/asm/page.h
@@ -22,7 +22,10 @@
 #define PTE_PRESENT	(1ull << 0)
 #define PTE_WRITE	(1ull << 1)
 #define PTE_USER	(1ull << 2)
+#define PTE_ACCESSED	(1ull << 5)
+#define PTE_DIRTY	(1ull << 6)
 #define PTE_PSE		(1ull << 7)
+#define PTE_NX		(1ull << 63)
 #define PTE_ADDR	(0xffffffffff000ull)
 
 #ifdef __x86_64__
diff --git a/lib/x86/vm.c b/lib/x86/vm.c
index 9c94ca5..2018a83 100644
--- a/lib/x86/vm.c
+++ b/lib/x86/vm.c
@@ -58,7 +58,7 @@ unsigned long *install_pte(unsigned long *cr3,
 	    memset(new_pt, 0, PAGE_SIZE);
 	    pt[offset] = virt_to_phys(new_pt) | PTE_PRESENT | PTE_WRITE | PTE_USER;
 	}
-	pt = phys_to_virt(pt[offset] & 0xffffffffff000ull);
+	pt = phys_to_virt(pt[offset] & PTE_ADDR);
     }
     offset = ((unsigned long)virt >> ((level-1) * PGDIR_WIDTH + 12)) & PGDIR_MASK;
     pt[offset] = pte;
@@ -78,7 +78,7 @@ unsigned long *get_pte(unsigned long *cr3, void *virt)
 	    return NULL;
 	if (level == 2 && (pte & PTE_PSE))
 	    return &pt[offset];
-	pt = phys_to_virt(pte & 0xffffffffff000ull);
+	pt = phys_to_virt(pte & PTE_ADDR);
     }
     offset = ((unsigned long)virt >> (((level-1) * PGDIR_WIDTH) + 12)) & PGDIR_MASK;
     return &pt[offset];
diff --git a/x86/access.c b/x86/access.c
index aaf805d..b6127aa 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -19,14 +19,6 @@ static int invalid_mask;
 #define PT_BASE_ADDR_MASK ((pt_element_t)((((pt_element_t)1 << 40) - 1) & PAGE_MASK))
 #define PT_PSE_BASE_ADDR_MASK (PT_BASE_ADDR_MASK & ~(1ull << 21))
 
-#define PT_PRESENT_MASK    ((pt_element_t)1 << 0)
-#define PT_WRITABLE_MASK   ((pt_element_t)1 << 1)
-#define PT_USER_MASK       ((pt_element_t)1 << 2)
-#define PT_ACCESSED_MASK   ((pt_element_t)1 << 5)
-#define PT_DIRTY_MASK      ((pt_element_t)1 << 6)
-#define PT_PSE_MASK        ((pt_element_t)1 << 7)
-#define PT_NX_MASK         ((pt_element_t)1 << 63)
-
 #define CR0_WP_MASK (1UL << 16)
 #define CR4_SMEP_MASK (1UL << 20)
 
@@ -210,10 +202,10 @@ void set_cr4_smep(int smep)
         return;
 
     if (smep)
-        ptl2[2] &= ~PT_USER_MASK;
+        ptl2[2] &= ~PTE_USER;
     write_cr4(cr4);
     if (!smep)
-        ptl2[2] |= PT_USER_MASK;
+        ptl2[2] |= PTE_USER;
 }
 
 void set_cr4_pke(int pke)
@@ -362,9 +354,9 @@ pt_element_t ac_test_permissions(ac_test_t *at, unsigned flags, bool writable,
     }
 
     if (!at->expected_fault) {
-        expected |= PT_ACCESSED_MASK;
+        expected |= PTE_ACCESSED;
         if (F(AC_ACCESS_WRITE))
-            expected |= PT_DIRTY_MASK;
+            expected |= PTE_DIRTY;
     }
 
     return expected;
@@ -385,7 +377,7 @@ void ac_emulate_access(ac_test_t *at, unsigned flags)
 	at->expected_error |= PFERR_FETCH_MASK;
 
     if (!F(AC_PDE_ACCESSED))
-        at->ignore_pde = PT_ACCESSED_MASK;
+        at->ignore_pde = PTE_ACCESSED;
 
     pde_valid = F(AC_PDE_PRESENT)
         && !F(AC_PDE_BIT51) && !F(AC_PDE_BIT13)
@@ -411,7 +403,7 @@ void ac_emulate_access(ac_test_t *at, unsigned flags)
 	goto no_pte;
     }
 
-    at->expected_pde |= PT_ACCESSED_MASK;
+    at->expected_pde |= PTE_ACCESSED;
 
     pte_valid = F(AC_PTE_PRESENT)
         && !F(AC_PTE_BIT51)
@@ -483,7 +475,7 @@ void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page,
 	case 4:
 	case 3:
 	    pte = pd_page ? pd_page : ac_test_alloc_pt(pool);
-	    pte |= PT_PRESENT_MASK | PT_WRITABLE_MASK | PT_USER_MASK;
+	    pte |= PTE_PRESENT | PTE_WRITE | PTE_USER;
 	    break;
 	case 2:
 	    if (!F(AC_PDE_PSE)) {
@@ -493,22 +485,22 @@ void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page,
                     pte |= 2ull << 59;
 	    } else {
 		pte = at->phys & PT_PSE_BASE_ADDR_MASK;
-		pte |= PT_PSE_MASK;
+		pte |= PTE_PSE;
                 if (F(AC_PKU_PKEY))
                     pte |= 1ull << 59;
 	    }
 	    if (F(AC_PDE_PRESENT))
-		pte |= PT_PRESENT_MASK;
+		pte |= PTE_PRESENT;
 	    if (F(AC_PDE_WRITABLE))
-		pte |= PT_WRITABLE_MASK;
+		pte |= PTE_WRITE;
 	    if (F(AC_PDE_USER))
-		pte |= PT_USER_MASK;
+		pte |= PTE_USER;
 	    if (F(AC_PDE_ACCESSED))
-		pte |= PT_ACCESSED_MASK;
+		pte |= PTE_ACCESSED;
 	    if (F(AC_PDE_DIRTY))
-		pte |= PT_DIRTY_MASK;
+		pte |= PTE_DIRTY;
 	    if (F(AC_PDE_NX))
-		pte |= PT_NX_MASK;
+		pte |= PTE_NX;
 	    if (F(AC_PDE_BIT51))
 		pte |= 1ull << 51;
 	    if (F(AC_PDE_BIT13))
@@ -520,17 +512,17 @@ void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page,
 	    if (F(AC_PKU_PKEY))
 		pte |= 1ull << 59;
 	    if (F(AC_PTE_PRESENT))
-		pte |= PT_PRESENT_MASK;
+		pte |= PTE_PRESENT;
 	    if (F(AC_PTE_WRITABLE))
-		pte |= PT_WRITABLE_MASK;
+		pte |= PTE_WRITE;
 	    if (F(AC_PTE_USER))
-		pte |= PT_USER_MASK;
+		pte |= PTE_USER;
 	    if (F(AC_PTE_ACCESSED))
-		pte |= PT_ACCESSED_MASK;
+		pte |= PTE_ACCESSED;
 	    if (F(AC_PTE_DIRTY))
-		pte |= PT_DIRTY_MASK;
+		pte |= PTE_DIRTY;
 	    if (F(AC_PTE_NX))
-		pte |= PT_NX_MASK;
+		pte |= PTE_NX;
 	    if (F(AC_PTE_BIT51))
 		pte |= 1ull << 51;
 	    at->ptep = &vroot[index];
-- 
1.8.3.1

--
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