KVM: selftests: Convert vmx_apic_access_test away from VCPU_ID

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

Opportunistically make the "vm" variable local, it is unused outside of
main().

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Sean Christopherson 2022-02-15 16:27:47 -08:00 коммит произвёл Paolo Bonzini
Родитель 706aaa4fed
Коммит 21c602e671
1 изменённых файлов: 8 добавлений и 10 удалений

Просмотреть файл

@ -28,11 +28,6 @@
#include "kselftest.h"
#define VCPU_ID 0
/* The virtual machine object. */
static struct kvm_vm *vm;
static void l2_guest_code(void)
{
/* Exit to L1 */
@ -84,9 +79,12 @@ int main(int argc, char *argv[])
struct vmx_pages *vmx;
bool done = false;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
nested_vmx_check_supported();
vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
kvm_get_cpu_address_width(&paddr_width, &vaddr_width);
high_gpa = (1ul << paddr_width) - getpagesize();
@ -97,13 +95,13 @@ int main(int argc, char *argv[])
vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva);
prepare_virtualize_apic_accesses(vmx, vm);
vcpu_args_set(vm, VCPU_ID, 2, vmx_pages_gva, high_gpa);
vcpu_args_set(vm, vcpu->id, 2, vmx_pages_gva, high_gpa);
while (!done) {
volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID);
volatile struct kvm_run *run = vcpu->run;
struct ucall uc;
vcpu_run(vm, VCPU_ID);
vcpu_run(vm, vcpu->id);
if (apic_access_addr == high_gpa) {
TEST_ASSERT(run->exit_reason ==
KVM_EXIT_INTERNAL_ERROR,
@ -121,7 +119,7 @@ int main(int argc, char *argv[])
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:
TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
__FILE__, uc.args[1]);