Commit 87f1b5b3 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert cpuid_test away from VCPU_ID

Convert cpuid_test to use vm_create_with_one_vcpu() and pass around a
'struct kvm_vcpu' object instead of using a global VCPU_ID.

Opportunistically use vcpu_run() instead of _vcpu_run(), the test expects
KVM_RUN to succeed.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 50630b80
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#define VCPU_ID 0
/* CPUIDs known to differ */ /* CPUIDs known to differ */
struct { struct {
u32 function; u32 function;
...@@ -118,13 +116,13 @@ static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *cpuid2) ...@@ -118,13 +116,13 @@ static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *cpuid2)
check_cpuid(cpuid1, &cpuid2->entries[i]); check_cpuid(cpuid1, &cpuid2->entries[i]);
} }
static void run_vcpu(struct kvm_vm *vm, uint32_t vcpuid, int stage) static void run_vcpu(struct kvm_vcpu *vcpu, int stage)
{ {
struct ucall uc; struct ucall uc;
_vcpu_run(vm, vcpuid); vcpu_run(vcpu->vm, vcpu->id);
switch (get_ucall(vm, vcpuid, &uc)) { switch (get_ucall(vcpu->vm, vcpu->id, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
TEST_ASSERT(!strcmp((const char *)uc.args[0], "hello") && TEST_ASSERT(!strcmp((const char *)uc.args[0], "hello") &&
uc.args[1] == stage + 1, uc.args[1] == stage + 1,
...@@ -138,7 +136,7 @@ static void run_vcpu(struct kvm_vm *vm, uint32_t vcpuid, int stage) ...@@ -138,7 +136,7 @@ static void run_vcpu(struct kvm_vm *vm, uint32_t vcpuid, int stage)
__FILE__, uc.args[1], uc.args[2], uc.args[3]); __FILE__, uc.args[1], uc.args[2], uc.args[3]);
default: default:
TEST_ASSERT(false, "Unexpected exit: %s", TEST_ASSERT(false, "Unexpected exit: %s",
exit_reason_str(vcpu_state(vm, vcpuid)->exit_reason)); exit_reason_str(vcpu->run->exit_reason));
} }
} }
...@@ -154,21 +152,21 @@ struct kvm_cpuid2 *vcpu_alloc_cpuid(struct kvm_vm *vm, vm_vaddr_t *p_gva, struct ...@@ -154,21 +152,21 @@ struct kvm_cpuid2 *vcpu_alloc_cpuid(struct kvm_vm *vm, vm_vaddr_t *p_gva, struct
return guest_cpuids; return guest_cpuids;
} }
static void set_cpuid_after_run(struct kvm_vm *vm, struct kvm_cpuid2 *cpuid) static void set_cpuid_after_run(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid)
{ {
struct kvm_cpuid_entry2 *ent; struct kvm_cpuid_entry2 *ent;
int rc; int rc;
u32 eax, ebx, x; u32 eax, ebx, x;
/* Setting unmodified CPUID is allowed */ /* Setting unmodified CPUID is allowed */
rc = __vcpu_set_cpuid(vm, VCPU_ID, cpuid); rc = __vcpu_set_cpuid(vcpu->vm, vcpu->id, cpuid);
TEST_ASSERT(!rc, "Setting unmodified CPUID after KVM_RUN failed: %d", rc); TEST_ASSERT(!rc, "Setting unmodified CPUID after KVM_RUN failed: %d", rc);
/* Changing CPU features is forbidden */ /* Changing CPU features is forbidden */
ent = get_cpuid(cpuid, 0x7, 0); ent = get_cpuid(cpuid, 0x7, 0);
ebx = ent->ebx; ebx = ent->ebx;
ent->ebx--; ent->ebx--;
rc = __vcpu_set_cpuid(vm, VCPU_ID, cpuid); rc = __vcpu_set_cpuid(vcpu->vm, vcpu->id, cpuid);
TEST_ASSERT(rc, "Changing CPU features should fail"); TEST_ASSERT(rc, "Changing CPU features should fail");
ent->ebx = ebx; ent->ebx = ebx;
...@@ -177,7 +175,7 @@ static void set_cpuid_after_run(struct kvm_vm *vm, struct kvm_cpuid2 *cpuid) ...@@ -177,7 +175,7 @@ static void set_cpuid_after_run(struct kvm_vm *vm, struct kvm_cpuid2 *cpuid)
eax = ent->eax; eax = ent->eax;
x = eax & 0xff; x = eax & 0xff;
ent->eax = (eax & ~0xffu) | (x - 1); ent->eax = (eax & ~0xffu) | (x - 1);
rc = __vcpu_set_cpuid(vm, VCPU_ID, cpuid); rc = __vcpu_set_cpuid(vcpu->vm, vcpu->id, cpuid);
TEST_ASSERT(rc, "Changing MAXPHYADDR should fail"); TEST_ASSERT(rc, "Changing MAXPHYADDR should fail");
ent->eax = eax; ent->eax = eax;
} }
...@@ -185,25 +183,26 @@ static void set_cpuid_after_run(struct kvm_vm *vm, struct kvm_cpuid2 *cpuid) ...@@ -185,25 +183,26 @@ static void set_cpuid_after_run(struct kvm_vm *vm, struct kvm_cpuid2 *cpuid)
int main(void) int main(void)
{ {
struct kvm_cpuid2 *supp_cpuid, *cpuid2; struct kvm_cpuid2 *supp_cpuid, *cpuid2;
struct kvm_vcpu *vcpu;
vm_vaddr_t cpuid_gva; vm_vaddr_t cpuid_gva;
struct kvm_vm *vm; struct kvm_vm *vm;
int stage; int stage;
vm = vm_create_default(VCPU_ID, 0, guest_main); vm = vm_create_with_one_vcpu(&vcpu, guest_main);
supp_cpuid = kvm_get_supported_cpuid(); supp_cpuid = kvm_get_supported_cpuid();
cpuid2 = vcpu_get_cpuid(vm, VCPU_ID); cpuid2 = vcpu_get_cpuid(vm, vcpu->id);
compare_cpuids(supp_cpuid, cpuid2); compare_cpuids(supp_cpuid, cpuid2);
vcpu_alloc_cpuid(vm, &cpuid_gva, cpuid2); vcpu_alloc_cpuid(vm, &cpuid_gva, cpuid2);
vcpu_args_set(vm, VCPU_ID, 1, cpuid_gva); vcpu_args_set(vm, vcpu->id, 1, cpuid_gva);
for (stage = 0; stage < 3; stage++) for (stage = 0; stage < 3; stage++)
run_vcpu(vm, VCPU_ID, stage); run_vcpu(vcpu, stage);
set_cpuid_after_run(vm, cpuid2); set_cpuid_after_run(vcpu, cpuid2);
kvm_vm_free(vm); kvm_vm_free(vm);
} }
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