Skip to content

Commit 75275d7

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
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) Signed-off-by: Ricardo Koller <ricarkol@google.com> Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210611011020.3420067-4-ricarkol@google.com
1 parent b7326c0 commit 75275d7

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ enum {
349349
UCALL_SYNC,
350350
UCALL_ABORT,
351351
UCALL_DONE,
352+
UCALL_UNHANDLED,
352353
};
353354

354355
#define UCALL_MAX_ARGS 6

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
#define CPUID_PKU (1ul << 3)
5454
#define CPUID_LA57 (1ul << 16)
5555

56-
#define UNEXPECTED_VECTOR_PORT 0xfff0u
57-
5856
/* General Registers in 64-Bit Mode */
5957
struct gpr64_regs {
6058
u64 rax;

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ static void set_idt_entry(struct kvm_vm *vm, int vector, unsigned long addr,
12011201

12021202
void kvm_exit_unexpected_vector(uint32_t value)
12031203
{
1204-
outl(UNEXPECTED_VECTOR_PORT, value);
1204+
ucall(UCALL_UNHANDLED, 1, value);
12051205
}
12061206

12071207
void route_exception(struct ex_regs *regs)
@@ -1254,16 +1254,13 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector,
12541254

12551255
void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid)
12561256
{
1257-
if (vcpu_state(vm, vcpuid)->exit_reason == KVM_EXIT_IO
1258-
&& vcpu_state(vm, vcpuid)->io.port == UNEXPECTED_VECTOR_PORT
1259-
&& vcpu_state(vm, vcpuid)->io.size == 4) {
1260-
/* Grab pointer to io data */
1261-
uint32_t *data = (void *)vcpu_state(vm, vcpuid)
1262-
+ vcpu_state(vm, vcpuid)->io.data_offset;
1263-
1264-
TEST_ASSERT(false,
1265-
"Unexpected vectored event in guest (vector:0x%x)",
1266-
*data);
1257+
struct ucall uc;
1258+
1259+
if (get_ucall(vm, vcpuid, &uc) == UCALL_UNHANDLED) {
1260+
uint64_t vector = uc.args[0];
1261+
1262+
TEST_FAIL("Unexpected vectored event in guest (vector:0x%lx)",
1263+
vector);
12671264
}
12681265
}
12691266

0 commit comments

Comments
 (0)