]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
authorRicardo Koller <ricarkol@google.com>
Thu, 13 May 2021 00:27:59 +0000 (17:27 -0700)
committerMarc Zyngier <maz@kernel.org>
Tue, 1 Jun 2021 08:48:33 +0000 (09:48 +0100)
x86, the only arch implementing exception handling, reports unhandled
vectors using port IO at a specific port number. This replicates what
ucall already does.

Introduce a new ucall type, UCALL_UNHANDLED, for guests to report
unhandled exceptions. Then replace the x86 unhandled vector exception
reporting to use it instead of port IO.  This new ucall type will be
used in the next commits by arm64 to report unhandled vectors as well.

Tested: Forcing a page fault in the ./x86_64/xapic_ipi_test
halter_guest_code() shows this:

$ ./x86_64/xapic_ipi_test
...
  Unexpected vectored event in guest (vector:0xe)

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210513002802.3671838-3-ricarkol@google.com
tools/testing/selftests/kvm/include/kvm_util.h
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/lib/x86_64/processor.c

index fcd8e3855111c1e56e57de389dc5ef32ccb6a786..beb76d6deaa9548e5c175b2c3eb81a78fc365254 100644 (file)
@@ -349,6 +349,7 @@ enum {
        UCALL_SYNC,
        UCALL_ABORT,
        UCALL_DONE,
+       UCALL_UNHANDLED,
 };
 
 #define UCALL_MAX_ARGS 6
index 12889d3e894804ba98ec50f0e4bb75c62006f04f..ff4da2f95b13752dcb6dcf632a9542f281486eef 100644 (file)
@@ -53,8 +53,6 @@
 #define CPUID_PKU              (1ul << 3)
 #define CPUID_LA57             (1ul << 16)
 
-#define UNEXPECTED_VECTOR_PORT 0xfff0u
-
 /* General Registers in 64-Bit Mode */
 struct gpr64_regs {
        u64 rax;
index 1f3161a6a0dba484dfe3783c22741704babd4003..a800270fb9a1c4999212ec1e1b4b8fa5719ce7b1 100644 (file)
@@ -1201,7 +1201,7 @@ static void set_idt_entry(struct kvm_vm *vm, int vector, unsigned long addr,
 
 void kvm_exit_unexpected_vector(uint32_t value)
 {
-       outl(UNEXPECTED_VECTOR_PORT, value);
+       ucall(UCALL_UNHANDLED, 1, value);
 }
 
 void route_exception(struct ex_regs *regs)
@@ -1254,16 +1254,12 @@ void vm_install_vector_handler(struct kvm_vm *vm, int vector,
 
 void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid)
 {
-       if (vcpu_state(vm, vcpuid)->exit_reason == KVM_EXIT_IO
-               && vcpu_state(vm, vcpuid)->io.port == UNEXPECTED_VECTOR_PORT
-               && vcpu_state(vm, vcpuid)->io.size == 4) {
-               /* Grab pointer to io data */
-               uint32_t *data = (void *)vcpu_state(vm, vcpuid)
-                       + vcpu_state(vm, vcpuid)->io.data_offset;
-
-               TEST_ASSERT(false,
-                           "Unexpected vectored event in guest (vector:0x%x)",
-                           *data);
+       struct ucall uc;
+
+       if (get_ucall(vm, vcpuid, &uc) == UCALL_UNHANDLED) {
+               uint64_t vector = uc.args[0];
+               TEST_FAIL("Unexpected vectored event in guest (vector:0x%lx)",
+                         vector);
        }
 }