Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aee41be5 authored by Peter Xu's avatar Peter Xu Committed by Paolo Bonzini
Browse files

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: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent bc8eb2fe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);

+2 −1
Original line number Diff line number Diff line
@@ -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,
+16 −2
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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);

Loading