Commit e852be8b authored by Paolo Bonzini's avatar Paolo Bonzini

kvm: selftests: introduce and use more page size-related constants

Clean up code that was hardcoding masks for various fields,
now that the masks are included in processor.h.

For more cleanup, define PAGE_SIZE and PAGE_MASK just like in Linux.
PAGE_SIZE in particular was defined by several tests.
Suggested-by: default avatarSean Christopherson <seanjc@google.com>
Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent f18b4aeb
...@@ -71,6 +71,8 @@ ...@@ -71,6 +71,8 @@
#define PTE_NX_MASK BIT_ULL(63) #define PTE_NX_MASK BIT_ULL(63)
#define PAGE_SHIFT 12 #define PAGE_SHIFT 12
#define PAGE_SIZE (1ULL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
#define PHYSICAL_PAGE_MASK GENMASK_ULL(51, 12) #define PHYSICAL_PAGE_MASK GENMASK_ULL(51, 12)
#define PTE_GET_PFN(pte) (((pte) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT) #define PTE_GET_PFN(pte) (((pte) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
......
...@@ -255,13 +255,13 @@ static uint64_t *_vm_get_page_table_entry(struct kvm_vm *vm, int vcpuid, ...@@ -255,13 +255,13 @@ static uint64_t *_vm_get_page_table_entry(struct kvm_vm *vm, int vcpuid,
struct kvm_cpuid_entry2 *entry; struct kvm_cpuid_entry2 *entry;
struct kvm_sregs sregs; struct kvm_sregs sregs;
int max_phy_addr; int max_phy_addr;
/* Set the bottom 52 bits. */ uint64_t rsvd_mask = 0;
uint64_t rsvd_mask = 0x000fffffffffffff;
entry = kvm_get_supported_cpuid_index(0x80000008, 0); entry = kvm_get_supported_cpuid_index(0x80000008, 0);
max_phy_addr = entry->eax & 0x000000ff; max_phy_addr = entry->eax & 0x000000ff;
/* Clear the bottom bits of the reserved mask. */ /* Set the high bits in the reserved mask. */
rsvd_mask = (rsvd_mask >> max_phy_addr) << max_phy_addr; if (max_phy_addr < 52)
rsvd_mask = GENMASK_ULL(51, max_phy_addr);
/* /*
* SDM vol 3, fig 4-11 "Formats of CR3 and Paging-Structure Entries * SDM vol 3, fig 4-11 "Formats of CR3 and Paging-Structure Entries
...@@ -271,7 +271,7 @@ static uint64_t *_vm_get_page_table_entry(struct kvm_vm *vm, int vcpuid, ...@@ -271,7 +271,7 @@ static uint64_t *_vm_get_page_table_entry(struct kvm_vm *vm, int vcpuid,
*/ */
vcpu_sregs_get(vm, vcpuid, &sregs); vcpu_sregs_get(vm, vcpuid, &sregs);
if ((sregs.efer & EFER_NX) == 0) { if ((sregs.efer & EFER_NX) == 0) {
rsvd_mask |= (1ull << 63); rsvd_mask |= PTE_NX_MASK;
} }
TEST_ASSERT(vm->mode == VM_MODE_PXXV48_4K, "Attempt to use " TEST_ASSERT(vm->mode == VM_MODE_PXXV48_4K, "Attempt to use "
...@@ -549,7 +549,7 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) ...@@ -549,7 +549,7 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
if (!(pte[index[0]] & PTE_PRESENT_MASK)) if (!(pte[index[0]] & PTE_PRESENT_MASK))
goto unmapped_gva; goto unmapped_gva;
return (PTE_GET_PFN(pte[index[0]]) * vm->page_size) + (gva & 0xfffu); return (PTE_GET_PFN(pte[index[0]]) * vm->page_size) + (gva & ~PAGE_MASK);
unmapped_gva: unmapped_gva:
TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva); TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva);
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#define X86_FEATURE_XSAVE (1 << 26) #define X86_FEATURE_XSAVE (1 << 26)
#define X86_FEATURE_OSXSAVE (1 << 27) #define X86_FEATURE_OSXSAVE (1 << 27)
#define PAGE_SIZE (1 << 12)
#define NUM_TILES 8 #define NUM_TILES 8
#define TILE_SIZE 1024 #define TILE_SIZE 1024
#define XSAVE_SIZE ((NUM_TILES * TILE_SIZE) + PAGE_SIZE) #define XSAVE_SIZE ((NUM_TILES * TILE_SIZE) + PAGE_SIZE)
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "vmx.h" #include "vmx.h"
#define VCPU_ID 1 #define VCPU_ID 1
#define PAGE_SIZE 4096
#define MAXPHYADDR 36 #define MAXPHYADDR 36
#define MEM_REGION_GVA 0x0000123456789000 #define MEM_REGION_GVA 0x0000123456789000
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#define VCPU_ID 1 #define VCPU_ID 1
#define PAGE_SIZE 4096
#define SMRAM_SIZE 65536 #define SMRAM_SIZE 65536
#define SMRAM_MEMSLOT ((1 << 16) | 1) #define SMRAM_MEMSLOT ((1 << 16) | 1)
#define SMRAM_PAGES (SMRAM_SIZE / PAGE_SIZE) #define SMRAM_PAGES (SMRAM_SIZE / PAGE_SIZE)
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#define MSR_IA32_TSC_ADJUST 0x3b #define MSR_IA32_TSC_ADJUST 0x3b
#endif #endif
#define PAGE_SIZE 4096
#define VCPU_ID 5 #define VCPU_ID 5
#define TSC_ADJUST_VALUE (1ll << 32) #define TSC_ADJUST_VALUE (1ll << 32)
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#define SHINFO_REGION_GVA 0xc0000000ULL #define SHINFO_REGION_GVA 0xc0000000ULL
#define SHINFO_REGION_GPA 0xc0000000ULL #define SHINFO_REGION_GPA 0xc0000000ULL
#define SHINFO_REGION_SLOT 10 #define SHINFO_REGION_SLOT 10
#define PAGE_SIZE 4096
#define DUMMY_REGION_GPA (SHINFO_REGION_GPA + (2 * PAGE_SIZE)) #define DUMMY_REGION_GPA (SHINFO_REGION_GPA + (2 * PAGE_SIZE))
#define DUMMY_REGION_SLOT 11 #define DUMMY_REGION_SLOT 11
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#define HCALL_REGION_GPA 0xc0000000ULL #define HCALL_REGION_GPA 0xc0000000ULL
#define HCALL_REGION_SLOT 10 #define HCALL_REGION_SLOT 10
#define PAGE_SIZE 4096
static struct kvm_vm *vm; static struct kvm_vm *vm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment