kvm: selftest: pass in extra memory when create vm

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>
This commit is contained in:
Peter Xu 2018-08-22 15:19:59 +08:00 committed by Paolo Bonzini
parent bc8eb2fe2e
commit aee41be593
7 changed files with 23 additions and 8 deletions

View File

@ -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);

View File

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

View File

@ -702,6 +702,9 @@ 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
@ -709,12 +712,23 @@ void vcpu_set_cpuid(struct kvm_vm *vm,
* 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);

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -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). */