Skip to content

Commit

Permalink
kvm: selftest: pass in extra memory when create vm
Browse files Browse the repository at this point in the history
This information can be used to decide the size of the default memory
slot, which will need to cover the extra pages with page tables.

Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Peter Xu authored and Paolo Bonzini committed Aug 22, 2018
1 parent bc8eb2f commit aee41be
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);

/* Create VM */
vm = vm_create_default(VCPU_ID, guest_code);
vm = vm_create_default(VCPU_ID, 0, guest_code);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
run = vcpu_state(vm, VCPU_ID);

Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/kvm/include/kvm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ kvm_get_supported_cpuid_entry(uint32_t function)
return kvm_get_supported_cpuid_index(function, 0);
}

struct kvm_vm *vm_create_default(uint32_t vcpuid, void *guest_code);
struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_size,
void *guest_code);
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code);

typedef void (*vmx_guest_code_t)(vm_vaddr_t vmxon_vaddr,
Expand Down
18 changes: 16 additions & 2 deletions tools/testing/selftests/kvm/lib/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,19 +702,33 @@ void vcpu_set_cpuid(struct kvm_vm *vm,
*
* Input Args:
* vcpuid - The id of the single VCPU to add to the VM.
* extra_mem_pages - The size of extra memories to add (this will
* decide how much extra space we will need to
* setup the page tables using mem slot 0)
* guest_code - The vCPU's entry point
*
* Output Args: None
*
* Return:
* Pointer to opaque structure that describes the created VM.
*/
struct kvm_vm *vm_create_default(uint32_t vcpuid, void *guest_code)
struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
void *guest_code)
{
struct kvm_vm *vm;
/*
* For x86 the maximum page table size for a memory region
* will be when only 4K pages are used. In that case the
* total extra size for page tables (for extra N pages) will
* be: N/512+N/512^2+N/512^3+... which is definitely smaller
* than N/512*2.
*/
uint64_t extra_pg_pages = extra_mem_pages / 512 * 2;

/* Create VM */
vm = vm_create(VM_MODE_FLAT48PG, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
vm = vm_create(VM_MODE_FLAT48PG,
DEFAULT_GUEST_PHY_PAGES + extra_pg_pages,
O_RDWR);

/* Setup guest code */
kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/set_sregs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);

/* Create VM */
vm = vm_create_default(VCPU_ID, NULL);
vm = vm_create_default(VCPU_ID, 0, NULL);

vcpu_sregs_get(vm, VCPU_ID, &sregs);
sregs.apic_base = 1 << 10;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/state_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int main(int argc, char *argv[])
struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);

/* Create VM */
vm = vm_create_default(VCPU_ID, guest_code);
vm = vm_create_default(VCPU_ID, 0, guest_code);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
run = vcpu_state(vm, VCPU_ID);

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/sync_regs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(int argc, char *argv[])
}

/* Create VM */
vm = vm_create_default(VCPU_ID, guest_code);
vm = vm_create_default(VCPU_ID, 0, guest_code);

run = vcpu_state(vm, VCPU_ID);

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/vmx_tsc_adjust_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int main(int argc, char *argv[])
exit(KSFT_SKIP);
}

vm = vm_create_default(VCPU_ID, (void *) l1_guest_code);
vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());

/* Allocate VMX pages and shared descriptors (vmx_pages). */
Expand Down

0 comments on commit aee41be

Please sign in to comment.