Commit 10f0b222 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert system_counter_offset_test away from VCPU_ID

Convert system_counter_offset_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 d7828144
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#define VCPU_ID 0
#ifdef __x86_64__ #ifdef __x86_64__
struct test_case { struct test_case {
...@@ -28,18 +26,19 @@ static struct test_case test_cases[] = { ...@@ -28,18 +26,19 @@ static struct test_case test_cases[] = {
{ -180 * NSEC_PER_SEC }, { -180 * NSEC_PER_SEC },
}; };
static void check_preconditions(struct kvm_vm *vm) static void check_preconditions(struct kvm_vcpu *vcpu)
{ {
if (!__vcpu_has_device_attr(vm, VCPU_ID, KVM_VCPU_TSC_CTRL, KVM_VCPU_TSC_OFFSET)) if (!__vcpu_has_device_attr(vcpu->vm, vcpu->id, KVM_VCPU_TSC_CTRL,
KVM_VCPU_TSC_OFFSET))
return; return;
print_skip("KVM_VCPU_TSC_OFFSET not supported; skipping test"); print_skip("KVM_VCPU_TSC_OFFSET not supported; skipping test");
exit(KSFT_SKIP); exit(KSFT_SKIP);
} }
static void setup_system_counter(struct kvm_vm *vm, struct test_case *test) static void setup_system_counter(struct kvm_vcpu *vcpu, struct test_case *test)
{ {
vcpu_device_attr_set(vm, VCPU_ID, KVM_VCPU_TSC_CTRL, vcpu_device_attr_set(vcpu->vm, vcpu->id, KVM_VCPU_TSC_CTRL,
KVM_VCPU_TSC_OFFSET, &test->tsc_offset); KVM_VCPU_TSC_OFFSET, &test->tsc_offset);
} }
...@@ -91,7 +90,7 @@ static void handle_abort(struct ucall *uc) ...@@ -91,7 +90,7 @@ static void handle_abort(struct ucall *uc)
__FILE__, uc->args[1]); __FILE__, uc->args[1]);
} }
static void enter_guest(struct kvm_vm *vm) static void enter_guest(struct kvm_vcpu *vcpu)
{ {
uint64_t start, end; uint64_t start, end;
struct ucall uc; struct ucall uc;
...@@ -100,12 +99,12 @@ static void enter_guest(struct kvm_vm *vm) ...@@ -100,12 +99,12 @@ static void enter_guest(struct kvm_vm *vm)
for (i = 0; i < ARRAY_SIZE(test_cases); i++) { for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
struct test_case *test = &test_cases[i]; struct test_case *test = &test_cases[i];
setup_system_counter(vm, test); setup_system_counter(vcpu, test);
start = host_read_guest_system_counter(test); start = host_read_guest_system_counter(test);
vcpu_run(vm, VCPU_ID); vcpu_run(vcpu->vm, vcpu->id);
end = host_read_guest_system_counter(test); end = host_read_guest_system_counter(test);
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vcpu->vm, vcpu->id, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
handle_sync(&uc, start, end); handle_sync(&uc, start, end);
break; break;
...@@ -114,19 +113,20 @@ static void enter_guest(struct kvm_vm *vm) ...@@ -114,19 +113,20 @@ static void enter_guest(struct kvm_vm *vm)
return; return;
default: default:
TEST_ASSERT(0, "unhandled ucall %ld\n", TEST_ASSERT(0, "unhandled ucall %ld\n",
get_ucall(vm, VCPU_ID, &uc)); get_ucall(vcpu->vm, vcpu->id, &uc));
} }
} }
} }
int main(void) int main(void)
{ {
struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
vm = vm_create_default(VCPU_ID, 0, guest_main); vm = vm_create_with_one_vcpu(&vcpu, guest_main);
check_preconditions(vm); check_preconditions(vcpu);
ucall_init(vm, NULL); ucall_init(vm, NULL);
enter_guest(vm); enter_guest(vcpu);
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