Commit 1cc1a9f3 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert platform_info_test away from VCPU_ID

Convert platform_info_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 f323dbce
......@@ -21,7 +21,6 @@
#include "kvm_util.h"
#include "processor.h"
#define VCPU_ID 0
#define MSR_PLATFORM_INFO_MAX_TURBO_RATIO 0xff00
static void guest_code(void)
......@@ -35,18 +34,18 @@ static void guest_code(void)
}
}
static void test_msr_platform_info_enabled(struct kvm_vm *vm)
static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu_state(vm, VCPU_ID);
struct kvm_run *run = vcpu->run;
struct ucall uc;
vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, true);
vcpu_run(vm, VCPU_ID);
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Exit_reason other than KVM_EXIT_IO: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
get_ucall(vm, VCPU_ID, &uc);
get_ucall(vcpu->vm, vcpu->id, &uc);
TEST_ASSERT(uc.cmd == UCALL_SYNC,
"Received ucall other than UCALL_SYNC: %lu\n", uc.cmd);
TEST_ASSERT((uc.args[1] & MSR_PLATFORM_INFO_MAX_TURBO_RATIO) ==
......@@ -55,12 +54,12 @@ static void test_msr_platform_info_enabled(struct kvm_vm *vm)
MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
}
static void test_msr_platform_info_disabled(struct kvm_vm *vm)
static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu_state(vm, VCPU_ID);
struct kvm_run *run = vcpu->run;
vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, false);
vcpu_run(vm, VCPU_ID);
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false);
vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN,
"Exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
run->exit_reason,
......@@ -69,6 +68,7 @@ static void test_msr_platform_info_disabled(struct kvm_vm *vm)
int main(int argc, char *argv[])
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
int rv;
uint64_t msr_platform_info;
......@@ -82,14 +82,14 @@ int main(int argc, char *argv[])
exit(KSFT_SKIP);
}
vm = vm_create_default(VCPU_ID, 0, guest_code);
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
msr_platform_info = vcpu_get_msr(vm, VCPU_ID, MSR_PLATFORM_INFO);
vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO,
msr_platform_info = vcpu_get_msr(vm, vcpu->id, MSR_PLATFORM_INFO);
vcpu_set_msr(vm, vcpu->id, MSR_PLATFORM_INFO,
msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
test_msr_platform_info_enabled(vm);
test_msr_platform_info_disabled(vm);
vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO, msr_platform_info);
test_msr_platform_info_enabled(vcpu);
test_msr_platform_info_disabled(vcpu);
vcpu_set_msr(vm, vcpu->id, MSR_PLATFORM_INFO, msr_platform_info);
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