From: Jan Kiszka Date: Sun, 28 Feb 2016 19:48:55 +0000 (+0100) Subject: x86: Use more BIT_MASK macro for paging tasks X-Git-Url: http://rtime.felk.cvut.cz/gitweb/jailhouse.git/commitdiff_plain/ab6b2b4f84739f3947e528c29eeeceaa37f9b42e x86: Use more BIT_MASK macro for paging tasks Instead of manually defining bitmasks, use the more readable BIT_MASK macro. No constant value is changed. Signed-off-by: Jan Kiszka --- diff --git a/hypervisor/arch/x86/paging.c b/hypervisor/arch/x86/paging.c index 56ae244..952c058 100644 --- a/hypervisor/arch/x86/paging.c +++ b/hypervisor/arch/x86/paging.c @@ -1,7 +1,7 @@ /* * Jailhouse, a Linux-based partitioning hypervisor * - * Copyright (c) Siemens AG, 2014 + * Copyright (c) Siemens AG, 2014-2016 * * Authors: * Jan Kiszka @@ -12,6 +12,7 @@ #include #include +#include #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 */ diff --git a/hypervisor/arch/x86/svm.c b/hypervisor/arch/x86/svm.c index 72df24b..000370f 100644 --- a/hypervisor/arch/x86/svm.c +++ b/hypervisor/arch/x86/svm.c @@ -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 diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 9b57d8c..f5cd8ca 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -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; diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index 6d36394..df67d6a 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -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)