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

KVM: selftests: Convert hyperv_clock away from VCPU_ID

Convert hyperv_clock 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() with an open
coded assert that KVM_RUN succeeded.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent d96b9596
...@@ -173,23 +173,21 @@ static void guest_main(struct ms_hyperv_tsc_page *tsc_page, vm_paddr_t tsc_page_ ...@@ -173,23 +173,21 @@ static void guest_main(struct ms_hyperv_tsc_page *tsc_page, vm_paddr_t tsc_page_
GUEST_DONE(); GUEST_DONE();
} }
#define VCPU_ID 0 static void host_check_tsc_msr_rdtsc(struct kvm_vcpu *vcpu)
static void host_check_tsc_msr_rdtsc(struct kvm_vm *vm)
{ {
u64 tsc_freq, r1, r2, t1, t2; u64 tsc_freq, r1, r2, t1, t2;
s64 delta_ns; s64 delta_ns;
tsc_freq = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TSC_FREQUENCY); tsc_freq = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TSC_FREQUENCY);
TEST_ASSERT(tsc_freq > 0, "TSC frequency must be nonzero"); TEST_ASSERT(tsc_freq > 0, "TSC frequency must be nonzero");
/* For increased accuracy, take mean rdtsc() before and afrer ioctl */ /* For increased accuracy, take mean rdtsc() before and afrer ioctl */
r1 = rdtsc(); r1 = rdtsc();
t1 = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TIME_REF_COUNT); t1 = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TIME_REF_COUNT);
r1 = (r1 + rdtsc()) / 2; r1 = (r1 + rdtsc()) / 2;
nop_loop(); nop_loop();
r2 = rdtsc(); r2 = rdtsc();
t2 = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TIME_REF_COUNT); t2 = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TIME_REF_COUNT);
r2 = (r2 + rdtsc()) / 2; r2 = (r2 + rdtsc()) / 2;
TEST_ASSERT(t2 > t1, "Time reference MSR is not monotonic (%ld <= %ld)", t1, t2); TEST_ASSERT(t2 > t1, "Time reference MSR is not monotonic (%ld <= %ld)", t1, t2);
...@@ -207,33 +205,34 @@ static void host_check_tsc_msr_rdtsc(struct kvm_vm *vm) ...@@ -207,33 +205,34 @@ static void host_check_tsc_msr_rdtsc(struct kvm_vm *vm)
int main(void) int main(void)
{ {
struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run; struct kvm_run *run;
struct ucall uc; struct ucall uc;
vm_vaddr_t tsc_page_gva; vm_vaddr_t tsc_page_gva;
int stage; int stage;
vm = vm_create_default(VCPU_ID, 0, guest_main); vm = vm_create_with_one_vcpu(&vcpu, guest_main);
run = vcpu_state(vm, VCPU_ID); run = vcpu->run;
vcpu_set_hv_cpuid(vm, VCPU_ID); vcpu_set_hv_cpuid(vm, vcpu->id);
tsc_page_gva = vm_vaddr_alloc_page(vm); tsc_page_gva = vm_vaddr_alloc_page(vm);
memset(addr_gva2hva(vm, tsc_page_gva), 0x0, getpagesize()); memset(addr_gva2hva(vm, tsc_page_gva), 0x0, getpagesize());
TEST_ASSERT((addr_gva2gpa(vm, tsc_page_gva) & (getpagesize() - 1)) == 0, TEST_ASSERT((addr_gva2gpa(vm, tsc_page_gva) & (getpagesize() - 1)) == 0,
"TSC page has to be page aligned\n"); "TSC page has to be page aligned\n");
vcpu_args_set(vm, VCPU_ID, 2, tsc_page_gva, addr_gva2gpa(vm, tsc_page_gva)); vcpu_args_set(vm, vcpu->id, 2, tsc_page_gva, addr_gva2gpa(vm, tsc_page_gva));
host_check_tsc_msr_rdtsc(vm); host_check_tsc_msr_rdtsc(vcpu);
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
_vcpu_run(vm, VCPU_ID); vcpu_run(vm, vcpu->id);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Stage %d: unexpected exit reason: %u (%s),\n", "Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason, stage, run->exit_reason,
exit_reason_str(run->exit_reason)); exit_reason_str(run->exit_reason));
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, vcpu->id, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
__FILE__, uc.args[1]); __FILE__, uc.args[1]);
......
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