Commit afcda3dc authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert fix_hypercall_test away from VCPU_ID

Convert fix_hypercall_test to use vm_create_with_one_vcpu() and pass
around a 'struct kvm_vcpu' object instead of using a global VCPU_ID.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent e5d86c7a
......@@ -14,8 +14,6 @@
#include "kvm_util.h"
#include "processor.h"
#define VCPU_ID 0
static bool ud_expected;
static void guest_ud_handler(struct ex_regs *regs)
......@@ -94,22 +92,20 @@ static void guest_main(void)
GUEST_DONE();
}
static void setup_ud_vector(struct kvm_vm *vm)
static void setup_ud_vector(struct kvm_vcpu *vcpu)
{
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vm, VCPU_ID);
vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
vm_init_descriptor_tables(vcpu->vm);
vcpu_init_descriptor_tables(vcpu->vm, vcpu->id);
vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler);
}
static void enter_guest(struct kvm_vm *vm)
static void enter_guest(struct kvm_vcpu *vcpu)
{
struct kvm_run *run;
struct kvm_run *run = vcpu->run;
struct ucall uc;
run = vcpu_state(vm, VCPU_ID);
vcpu_run(vm, VCPU_ID);
switch (get_ucall(vm, VCPU_ID, &uc)) {
vcpu_run(vcpu->vm, vcpu->id);
switch (get_ucall(vcpu->vm, vcpu->id, &uc)) {
case UCALL_SYNC:
pr_info("%s: %016lx\n", (const char *)uc.args[2], uc.args[3]);
break;
......@@ -125,25 +121,27 @@ static void enter_guest(struct kvm_vm *vm)
static void test_fix_hypercall(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
vm = vm_create_default(VCPU_ID, 0, guest_main);
setup_ud_vector(vm);
vm = vm_create_with_one_vcpu(&vcpu, guest_main);
setup_ud_vector(vcpu);
ud_expected = false;
sync_global_to_guest(vm, ud_expected);
virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
enter_guest(vm);
enter_guest(vcpu);
}
static void test_fix_hypercall_disabled(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
vm = vm_create_default(VCPU_ID, 0, guest_main);
setup_ud_vector(vm);
vm = vm_create_with_one_vcpu(&vcpu, guest_main);
setup_ud_vector(vcpu);
vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2,
KVM_X86_QUIRK_FIX_HYPERCALL_INSN);
......@@ -153,7 +151,7 @@ static void test_fix_hypercall_disabled(void)
virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
enter_guest(vm);
enter_guest(vcpu);
}
int main(void)
......
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