]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
x86: Use more BIT_MASK macro for paging tasks
authorJan Kiszka <jan.kiszka@siemens.com>
Sun, 28 Feb 2016 19:48:55 +0000 (20:48 +0100)
committerJan Kiszka <jan.kiszka@siemens.com>
Mon, 7 Mar 2016 12:49:05 +0000 (13:49 +0100)
Instead of manually defining bitmasks, use the more readable BIT_MASK
macro. No constant value is changed.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/paging.c
hypervisor/arch/x86/svm.c
hypervisor/arch/x86/vmx.c
hypervisor/arch/x86/vtd.c

index 56ae244e108b70471b2d95900c72bb67137e4b26..952c0584f59ac8fa72d96962ee23e9776e5ca8a7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2014
+ * Copyright (c) Siemens AG, 2014-2016
  *
  * Authors:
  *  Jan Kiszka <jan.kiszka@siemens.com>
@@ -12,6 +12,7 @@
 
 #include <jailhouse/paging.h>
 #include <jailhouse/string.h>
+#include <jailhouse/utils.h>
 
 #define X86_FLAG_HUGEPAGE      0x80
 
@@ -24,12 +25,12 @@ static bool x86_64_entry_valid(pt_entry_t pte, unsigned long flags)
 
 static unsigned long x86_64_get_flags(pt_entry_t pte)
 {
-       return *pte & 0x7f;
+       return *pte & BIT_MASK(6, 0);
 }
 
 static void x86_64_set_next_pt(pt_entry_t pte, unsigned long next_pt)
 {
-       *pte = (next_pt & 0x000ffffffffff000UL) | PAGE_DEFAULT_FLAGS;
+       *pte = (next_pt & BIT_MASK(51, 12)) | PAGE_DEFAULT_FLAGS;
 }
 
 static void x86_64_clear_entry(pt_entry_t pte)
@@ -75,46 +76,43 @@ static pt_entry_t x86_64_get_entry_l1(page_table_t page_table,
 static void x86_64_set_terminal_l3(pt_entry_t pte, unsigned long phys,
                                   unsigned long flags)
 {
-       *pte = (phys & 0x000fffffc0000000UL) | X86_FLAG_HUGEPAGE | flags;
+       *pte = (phys & BIT_MASK(51, 30)) | X86_FLAG_HUGEPAGE | flags;
 }
 
 static void x86_64_set_terminal_l2(pt_entry_t pte, unsigned long phys,
                                   unsigned long flags)
 {
-       *pte = (phys & 0x000fffffffe00000UL) | X86_FLAG_HUGEPAGE | flags;
+       *pte = (phys & BIT_MASK(51, 21)) | X86_FLAG_HUGEPAGE | flags;
 }
 
 static void x86_64_set_terminal_l1(pt_entry_t pte, unsigned long phys,
                                   unsigned long flags)
 {
-       *pte = (phys & 0x000ffffffffff000UL) | flags;
+       *pte = (phys & BIT_MASK(51, 12)) | flags;
 }
 
 static unsigned long x86_64_get_phys_l3(pt_entry_t pte, unsigned long virt)
 {
        if (!(*pte & X86_FLAG_HUGEPAGE))
                return INVALID_PHYS_ADDR;
-       return (*pte & 0x000fffffc0000000UL) |
-              (virt & 0x000000003fffffffUL);
+       return (*pte & BIT_MASK(51, 30)) | (virt & BIT_MASK(29, 0));
 }
 
 static unsigned long x86_64_get_phys_l2(pt_entry_t pte, unsigned long virt)
 {
        if (!(*pte & X86_FLAG_HUGEPAGE))
                return INVALID_PHYS_ADDR;
-       return (*pte & 0x000fffffffe00000UL) |
-              (virt & 0x00000000001fffffUL);
+       return (*pte & BIT_MASK(51, 21)) | (virt & BIT_MASK(20, 0));
 }
 
 static unsigned long x86_64_get_phys_l1(pt_entry_t pte, unsigned long virt)
 {
-       return (*pte & 0x000ffffffffff000UL) |
-              (virt & 0x0000000000000fffUL);
+       return (*pte & BIT_MASK(51, 12)) | (virt & BIT_MASK(11, 0));
 }
 
 static unsigned long x86_64_get_next_pt(pt_entry_t pte)
 {
-       return *pte & 0x000ffffffffff000UL;
+       return *pte & BIT_MASK(51, 12);
 }
 
 #define X86_64_PAGING_COMMON                                   \
@@ -192,20 +190,18 @@ static unsigned long i386_get_phys_l2(pt_entry_t pte, unsigned long virt)
 
        if (!(pte32 & X86_FLAG_HUGEPAGE))
                return INVALID_PHYS_ADDR;
-       return ((unsigned long)(pte32 & 0x0001e000) << (32 - 13)) |
-               (pte32 & 0xffc00000) |
-                (virt & 0x003fffff);
+       return ((unsigned long)(pte32 & BIT_MASK(16, 13)) << (32 - 13)) |
+               (pte32 & BIT_MASK(31, 22)) | (virt & BIT_MASK(21, 0));
 }
 
 static unsigned long i386_get_phys_l1(pt_entry_t pte, unsigned long virt)
 {
-       return (*(u32 *)pte & 0xfffff000) |
-                     (virt & 0x00000fff);
+       return (*(u32 *)pte & BIT_MASK(31, 12)) | (virt & BIT_MASK(11, 0));
 }
 
 static unsigned long i386_get_next_pt(pt_entry_t pte)
 {
-       return *(u32 *)pte & 0xfffff000UL;
+       return *(u32 *)pte & BIT_MASK(31, 12);
 }
 
 /* read-only, no page table construction supported */
index 72df24b22c4ddee7e23e728aeb967129c70acd05..000370f1d74ccf5c3c238f3de950d15f32d385e2 100644 (file)
@@ -243,8 +243,7 @@ unsigned long arch_paging_gphys2phys(struct per_cpu *cpu_data,
 static void npt_set_next_pt(pt_entry_t pte, unsigned long next_pt)
 {
        /* See APMv2, Section 15.25.5 */
-       *pte = (next_pt & 0x000ffffffffff000UL) |
-               (PAGE_DEFAULT_FLAGS | PAGE_FLAG_US);
+       *pte = (next_pt & BIT_MASK(51, 12)) | PAGE_DEFAULT_FLAGS | PAGE_FLAG_US;
 }
 
 int vcpu_vendor_init(void)
@@ -628,13 +627,11 @@ bool vcpu_get_guest_paging_structs(struct guest_paging_structures *pg_structs)
 
        if (vmcb->efer & EFER_LMA) {
                pg_structs->root_paging = x86_64_paging;
-               pg_structs->root_table_gphys =
-                       vmcb->cr3 & 0x000ffffffffff000UL;
+               pg_structs->root_table_gphys = vmcb->cr3 & BIT_MASK(51, 12);
        } else if ((vmcb->cr0 & X86_CR0_PG) &&
                   !(vmcb->cr4 & X86_CR4_PAE)) {
                pg_structs->root_paging = i386_paging;
-               pg_structs->root_table_gphys =
-                       vmcb->cr3 & 0xfffff000UL;
+               pg_structs->root_table_gphys = vmcb->cr3 & BIT_MASK(31, 12);
        } else if (!(vmcb->cr0 & X86_CR0_PG)) {
                /*
                 * Can be in non-paged protected mode as well, but
index 9b57d8c5e6f0d159b4422d55ad348bfa52e41b14..f5cd8ca1de15b0d2a80f1449c93efdfe87aacf29 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013-2015
+ * Copyright (c) Siemens AG, 2013-2016
  * Copyright (c) Valentine Sinitsyn, 2014
  *
  * Authors:
@@ -283,8 +283,8 @@ static int vmx_check_features(void)
 
 static void ept_set_next_pt(pt_entry_t pte, unsigned long next_pt)
 {
-       *pte = (next_pt & 0x000ffffffffff000UL) | EPT_FLAG_READ |
-               EPT_FLAG_WRITE | EPT_FLAG_EXECUTE;
+       *pte = (next_pt & BIT_MASK(51, 12)) | EPT_FLAG_READ | EPT_FLAG_WRITE |
+               EPT_FLAG_EXECUTE;
 }
 
 int vcpu_vendor_init(void)
@@ -976,12 +976,12 @@ bool vcpu_get_guest_paging_structs(struct guest_paging_structures *pg_structs)
        if (vmcs_read32(VM_ENTRY_CONTROLS) & VM_ENTRY_IA32E_MODE) {
                pg_structs->root_paging = x86_64_paging;
                pg_structs->root_table_gphys =
-                       vmcs_read64(GUEST_CR3) & 0x000ffffffffff000UL;
+                       vmcs_read64(GUEST_CR3) & BIT_MASK(51, 12);
        } else if (vmcs_read64(GUEST_CR0) & X86_CR0_PG &&
                 !(vmcs_read64(GUEST_CR4) & X86_CR4_PAE)) {
                pg_structs->root_paging = i386_paging;
                pg_structs->root_table_gphys =
-                       vmcs_read64(GUEST_CR3) & 0xfffff000UL;
+                       vmcs_read64(GUEST_CR3) & BIT_MASK(31, 12);
        } else {
                printk("FATAL: Unsupported paging mode\n");
                return false;
index 6d36394c8196dd188cb3cc9469565579aa0d24fb..df67d6af7049e9eb0db96519991f0b52218d161f 100644 (file)
@@ -159,8 +159,7 @@ static void vtd_update_gcmd_reg(void *reg_base, u32 mask, unsigned int set)
 
 static void vtd_set_next_pt(pt_entry_t pte, unsigned long next_pt)
 {
-       *pte = (next_pt & 0x000ffffffffff000UL) | VTD_PAGE_READ |
-               VTD_PAGE_WRITE;
+       *pte = (next_pt & BIT_MASK(51, 12)) | VTD_PAGE_READ | VTD_PAGE_WRITE;
 }
 
 static void vtd_init_fault_nmi(void)