KVM: selftests: Map x86's exception_handlers at VM creation, not vCPU setup
authorSean Christopherson <seanjc@google.com>
Thu, 14 Mar 2024 23:26:30 +0000 (16:26 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 29 Apr 2024 19:55:16 +0000 (12:55 -0700)
Map x86's exception handlers at VM creation, not vCPU setup, as the
mapping is per-VM, i.e. doesn't need to be (re)done for every vCPU.

Reviewed-by: Ackerley Tng <ackerleytng@google.com>
Link: https://lore.kernel.org/r/20240314232637.2538648-12-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/lib/x86_64/processor.c

index f3d9ac7e86925587b51a057bc070fb4bb51ba705..ff800b8609135afe45e268995535ff3602b5809e 100644 (file)
@@ -553,7 +553,6 @@ static void vcpu_init_descriptor_tables(struct kvm_vcpu *vcpu)
        sregs.gdt.limit = getpagesize() - 1;
        kvm_seg_set_kernel_data_64bit(NULL, DEFAULT_DATA_SELECTOR, &sregs.gs);
        vcpu_sregs_set(vcpu, &sregs);
-       *(vm_vaddr_t *)addr_gva2hva(vm, (vm_vaddr_t)(&exception_handlers)) = vm->handlers;
 }
 
 static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
@@ -652,6 +651,8 @@ static void vm_init_descriptor_tables(struct kvm_vm *vm)
        for (i = 0; i < NUM_INTERRUPTS; i++)
                set_idt_entry(vm, i, (unsigned long)(&idt_handlers)[i], 0,
                        DEFAULT_CODE_SELECTOR);
+
+       *(vm_vaddr_t *)addr_gva2hva(vm, (vm_vaddr_t)(&exception_handlers)) = vm->handlers;
 }
 
 void vm_install_exception_handler(struct kvm_vm *vm, int vector,