mirror of https://gitee.com/openkylin/linux.git
kvm: selftests: hide vcpu_setup in processor code
This removes the processor-dependent arguments from vm_vcpu_add. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
2c7c5d3d39
commit
837ec79b4c
|
@ -88,8 +88,7 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
|
|||
void *arg);
|
||||
void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
|
||||
void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
|
||||
void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
|
||||
int gdt_memslot);
|
||||
void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
|
||||
vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
|
||||
uint32_t data_memslot, uint32_t pgd_memslot);
|
||||
void virt_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
|
||||
|
|
|
@ -235,21 +235,7 @@ struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
|
|||
return vm;
|
||||
}
|
||||
|
||||
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
|
||||
{
|
||||
size_t stack_size = vm->page_size == 4096 ?
|
||||
DEFAULT_STACK_PGS * vm->page_size :
|
||||
vm->page_size;
|
||||
uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
|
||||
DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
|
||||
|
||||
vm_vcpu_add(vm, vcpuid, 0, 0);
|
||||
|
||||
set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
|
||||
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
|
||||
}
|
||||
|
||||
void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
|
||||
static void vcpu_setup(struct kvm_vm *vm, int vcpuid)
|
||||
{
|
||||
struct kvm_vcpu_init init;
|
||||
uint64_t sctlr_el1, tcr_el1;
|
||||
|
@ -316,3 +302,19 @@ void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent)
|
|||
fprintf(stream, "%*spstate: 0x%.16lx pc: 0x%.16lx\n",
|
||||
indent, "", pstate, pc);
|
||||
}
|
||||
|
||||
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
|
||||
{
|
||||
size_t stack_size = vm->page_size == 4096 ?
|
||||
DEFAULT_STACK_PGS * vm->page_size :
|
||||
vm->page_size;
|
||||
uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
|
||||
DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
|
||||
|
||||
vm_vcpu_add(vm, vcpuid);
|
||||
vcpu_setup(vm, vcpuid);
|
||||
|
||||
set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
|
||||
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
|
||||
}
|
||||
|
||||
|
|
|
@ -764,11 +764,10 @@ static int vcpu_mmap_sz(void)
|
|||
*
|
||||
* Return: None
|
||||
*
|
||||
* Creates and adds to the VM specified by vm and virtual CPU with
|
||||
* the ID given by vcpuid.
|
||||
* Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid.
|
||||
* No additional VCPU setup is done.
|
||||
*/
|
||||
void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
|
||||
int gdt_memslot)
|
||||
void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
|
@ -802,8 +801,6 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
|
|||
vm->vcpu_head->prev = vcpu;
|
||||
vcpu->next = vm->vcpu_head;
|
||||
vm->vcpu_head = vcpu;
|
||||
|
||||
vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -65,8 +65,6 @@ struct kvm_vm {
|
|||
};
|
||||
|
||||
struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
|
||||
void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot,
|
||||
int gdt_memslot);
|
||||
void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
|
||||
void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
|
||||
void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
|
||||
|
|
|
@ -610,7 +610,7 @@ static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp,
|
|||
kvm_seg_fill_gdt_64bit(vm, segp);
|
||||
}
|
||||
|
||||
void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
|
||||
static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
|
||||
{
|
||||
struct kvm_sregs sregs;
|
||||
|
||||
|
@ -656,7 +656,8 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
|
|||
DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0);
|
||||
|
||||
/* Create VCPU */
|
||||
vm_vcpu_add(vm, vcpuid, 0, 0);
|
||||
vm_vcpu_add(vm, vcpuid);
|
||||
vcpu_setup(vm, vcpuid, 0, 0);
|
||||
|
||||
/* Setup guest general purpose registers */
|
||||
vcpu_regs_get(vm, vcpuid, ®s);
|
||||
|
|
|
@ -144,7 +144,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Restore state in a new VM. */
|
||||
kvm_vm_restart(vm, O_RDWR);
|
||||
vm_vcpu_add(vm, VCPU_ID, 0, 0);
|
||||
vm_vcpu_add(vm, VCPU_ID);
|
||||
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
|
||||
vcpu_load_state(vm, VCPU_ID, state);
|
||||
run = vcpu_state(vm, VCPU_ID);
|
||||
|
|
|
@ -34,7 +34,7 @@ void test_vcpu_creation(int first_vcpu_id, int num_vcpus)
|
|||
int vcpu_id = first_vcpu_id + i;
|
||||
|
||||
/* This asserts that the vCPU was created. */
|
||||
vm_vcpu_add(vm, vcpu_id, 0, 0);
|
||||
vm_vcpu_add(vm, vcpu_id);
|
||||
}
|
||||
|
||||
kvm_vm_free(vm);
|
||||
|
|
|
@ -144,7 +144,7 @@ int main(int argc, char *argv[])
|
|||
state = vcpu_save_state(vm, VCPU_ID);
|
||||
kvm_vm_release(vm);
|
||||
kvm_vm_restart(vm, O_RDWR);
|
||||
vm_vcpu_add(vm, VCPU_ID, 0, 0);
|
||||
vm_vcpu_add(vm, VCPU_ID);
|
||||
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
|
||||
vcpu_load_state(vm, VCPU_ID, state);
|
||||
run = vcpu_state(vm, VCPU_ID);
|
||||
|
|
|
@ -177,7 +177,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Restore state in a new VM. */
|
||||
kvm_vm_restart(vm, O_RDWR);
|
||||
vm_vcpu_add(vm, VCPU_ID, 0, 0);
|
||||
vm_vcpu_add(vm, VCPU_ID);
|
||||
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
|
||||
vcpu_load_state(vm, VCPU_ID, state);
|
||||
run = vcpu_state(vm, VCPU_ID);
|
||||
|
|
Loading…
Reference in New Issue