Commit 39839c1a authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert amx_test away from VCPU_ID

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

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 2571bcdb
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
# error This test is 64-bit only # error This test is 64-bit only
#endif #endif
#define VCPU_ID 0
#define X86_FEATURE_XSAVE (1 << 26) #define X86_FEATURE_XSAVE (1 << 26)
#define X86_FEATURE_OSXSAVE (1 << 27) #define X86_FEATURE_OSXSAVE (1 << 27)
...@@ -319,6 +318,7 @@ int main(int argc, char *argv[]) ...@@ -319,6 +318,7 @@ int main(int argc, char *argv[])
struct kvm_cpuid_entry2 *entry; struct kvm_cpuid_entry2 *entry;
struct kvm_regs regs1, regs2; struct kvm_regs regs1, regs2;
bool amx_supported = false; bool amx_supported = false;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run; struct kvm_run *run;
struct kvm_x86_state *state; struct kvm_x86_state *state;
...@@ -331,7 +331,7 @@ int main(int argc, char *argv[]) ...@@ -331,7 +331,7 @@ int main(int argc, char *argv[])
vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT); vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT);
/* Create VM */ /* Create VM */
vm = vm_create_default(VCPU_ID, 0, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
entry = kvm_get_supported_cpuid_entry(1); entry = kvm_get_supported_cpuid_entry(1);
if (!(entry->ecx & X86_FEATURE_XSAVE)) { if (!(entry->ecx & X86_FEATURE_XSAVE)) {
...@@ -350,12 +350,12 @@ int main(int argc, char *argv[]) ...@@ -350,12 +350,12 @@ int main(int argc, char *argv[])
xsave_restore_size = entry->ecx; xsave_restore_size = entry->ecx;
} }
run = vcpu_state(vm, VCPU_ID); run = vcpu->run;
vcpu_regs_get(vm, VCPU_ID, &regs1); vcpu_regs_get(vm, vcpu->id, &regs1);
/* Register #NM handler */ /* Register #NM handler */
vm_init_descriptor_tables(vm); vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vm, VCPU_ID); vcpu_init_descriptor_tables(vm, vcpu->id);
vm_install_exception_handler(vm, NM_VECTOR, guest_nm_handler); vm_install_exception_handler(vm, NM_VECTOR, guest_nm_handler);
/* amx cfg for guest_code */ /* amx cfg for guest_code */
...@@ -369,16 +369,16 @@ int main(int argc, char *argv[]) ...@@ -369,16 +369,16 @@ int main(int argc, char *argv[])
/* xsave data for guest_code */ /* xsave data for guest_code */
xsavedata = vm_vaddr_alloc_pages(vm, 3); xsavedata = vm_vaddr_alloc_pages(vm, 3);
memset(addr_gva2hva(vm, xsavedata), 0, 3 * getpagesize()); memset(addr_gva2hva(vm, xsavedata), 0, 3 * getpagesize());
vcpu_args_set(vm, VCPU_ID, 3, amx_cfg, tiledata, xsavedata); vcpu_args_set(vm, vcpu->id, 3, amx_cfg, tiledata, xsavedata);
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]);
...@@ -403,7 +403,7 @@ int main(int argc, char *argv[]) ...@@ -403,7 +403,7 @@ int main(int argc, char *argv[])
* size subtract 8K amx size. * size subtract 8K amx size.
*/ */
amx_offset = xsave_restore_size - NUM_TILES*TILE_SIZE; amx_offset = xsave_restore_size - NUM_TILES*TILE_SIZE;
state = vcpu_save_state(vm, VCPU_ID); state = vcpu_save_state(vm, vcpu->id);
void *amx_start = (void *)state->xsave + amx_offset; void *amx_start = (void *)state->xsave + amx_offset;
void *tiles_data = (void *)addr_gva2hva(vm, tiledata); void *tiles_data = (void *)addr_gva2hva(vm, tiledata);
/* Only check TMM0 register, 1 tile */ /* Only check TMM0 register, 1 tile */
...@@ -424,22 +424,21 @@ int main(int argc, char *argv[]) ...@@ -424,22 +424,21 @@ int main(int argc, char *argv[])
TEST_FAIL("Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
state = vcpu_save_state(vm, VCPU_ID); state = vcpu_save_state(vm, vcpu->id);
memset(&regs1, 0, sizeof(regs1)); memset(&regs1, 0, sizeof(regs1));
vcpu_regs_get(vm, VCPU_ID, &regs1); vcpu_regs_get(vm, vcpu->id, &regs1);
kvm_vm_release(vm); kvm_vm_release(vm);
/* Restore state in a new VM. */ /* Restore state in a new VM. */
kvm_vm_restart(vm); vcpu = vm_recreate_with_one_vcpu(vm);
vm_vcpu_add(vm, VCPU_ID); vcpu_set_cpuid(vm, vcpu->id, kvm_get_supported_cpuid());
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); vcpu_load_state(vm, vcpu->id, state);
vcpu_load_state(vm, VCPU_ID, state); run = vcpu->run;
run = vcpu_state(vm, VCPU_ID);
kvm_x86_state_cleanup(state); kvm_x86_state_cleanup(state);
memset(&regs2, 0, sizeof(regs2)); memset(&regs2, 0, sizeof(regs2));
vcpu_regs_get(vm, VCPU_ID, &regs2); vcpu_regs_get(vm, vcpu->id, &regs2);
TEST_ASSERT(!memcmp(&regs1, &regs2, sizeof(regs2)), TEST_ASSERT(!memcmp(&regs1, &regs2, sizeof(regs2)),
"Unexpected register values after vcpu_load_state; rdi: %lx rsi: %lx", "Unexpected register values after vcpu_load_state; rdi: %lx rsi: %lx",
(ulong) regs2.rdi, (ulong) regs2.rsi); (ulong) regs2.rdi, (ulong) regs2.rsi);
......
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