KVM: selftests: arm64 exception handling and debug test
v4 cover KVM: selftests: arm64 exception handling and debug test
Hi,
These patches add a debug exception test in aarch64 KVM selftests while also adding basic exception handling support.
The structure of the exception handling is based on its x86 counterpart. Tests use the same calls to initialize exception handling and both architectures allow tests to override the handler for a particular vector, or (vector, ec) for synchronous exceptions in the arm64 case.
The debug test is similar to x86_64/debug_regs, except that the x86 one controls the debugging from outside the VM. This proposed arm64 test controls and handles debug exceptions from the inside.
Thanks,
Ricardo
v3 -> v4:
V3 was dropped because it was breaking x86 selftests builds (reported by the kernel test robot).
- rename vm_handle_exception to vm_install_sync_handler instead of vm_install_vector_handlers. [Sean]
- use a single level of routing for exception handling. [Sean]
- fix issue in x86_64/sync_regs_test when switching to ucalls for unhandled exceptions reporting.
v2 -> v3:
Addressed comments from Andrew and Marc (thanks again). Also, many thanks for the reviews and tests from Eric and Zenghui.
- add missing ISBs after writing into debug registers.
- not store/restore of sp_el0 on exceptions.
- add default handlers for Error and FIQ.
- change multiple TEST_ASSERT(false, ...) to TEST_FAIL.
- use Andrew's suggestion regarding __GUEST_ASSERT modifications in order to easier implement GUEST_ASSERT_EQ (Thanks Andrew).
v1 -> v2:
Addressed comments from Andrew and Marc (thank you very much):
- rename vm_handle_exception in all tests.
- introduce UCALL_UNHANDLED in x86 first.
- move GUEST_ASSERT_EQ to common utils header.
- handle sync and other exceptions separately: use two tables (like kvm-unit-tests).
- add two separate functions for installing sync versus other exceptions
- changes in handlers.S: use the same layout as user_pt_regs, treat the EL1t vectors as invalid, refactor the vector table creation to not use manual numbering, add comments, remove LR from the stored registers.
- changes in debug-exceptions.c: remove unused headers, use the common GUEST_ASSERT_EQ, use vcpu_run instead of _vcpu_run.
- changes in processor.h: write_sysreg with support for xzr, replace EL1 with current in macro names, define ESR_EC_MASK as ESR_EC_NUM-1.
Ricardo Koller (6):
KVM: selftests: Rename vm_handle_exception
KVM: selftests: Complete x86_64/sync_regs_test ucall
KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector
reporting
KVM: selftests: Move GUEST_ASSERT_EQ to utils header
KVM: selftests: Add exception handling support for aarch64
KVM: selftests: Add aarch64/debug-exceptions test
tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 3 +- .../selftests/kvm/aarch64/debug-exceptions.c | 250 ++++++++++++++++++ .../selftests/kvm/include/aarch64/processor.h | 83 +++++- .../testing/selftests/kvm/include/kvm_util.h | 23 +- .../selftests/kvm/include/x86_64/processor.h | 4 +- .../selftests/kvm/lib/aarch64/handlers.S | 126 +++++++++ .../selftests/kvm/lib/aarch64/processor.c | 97 +++++++ .../selftests/kvm/lib/x86_64/processor.c | 23 +- .../testing/selftests/kvm/x86_64/evmcs_test.c | 4 +- .../selftests/kvm/x86_64/kvm_pv_test.c | 2 +- .../selftests/kvm/x86_64/sync_regs_test.c | 7 +- .../selftests/kvm/x86_64/tsc_msrs_test.c | 9 - .../kvm/x86_64/userspace_msr_exit_test.c | 8 +- .../selftests/kvm/x86_64/xapic_ipi_test.c | 2 +- 15 files changed, 592 insertions(+), 50 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/debug-exceptions.c create mode 100644 tools/testing/selftests/kvm/lib/aarch64/handlers.S
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 1/6 KVM: selftests: Rename vm_handle_exception
Rename the vm_handle_exception function to a name that indicates more clearly that it installs something: vm_install_exception_handler.
--- tools/testing/selftests/kvm/include/x86_64/processor.h | 2 +- tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 ++-- tools/testing/selftests/kvm/x86_64/evmcs_test.c | 4 ++-- tools/testing/selftests/kvm/x86_64/kvm_pv_test.c | 2 +- .../selftests/kvm/x86_64/userspace_msr_exit_test.c | 8 ++++---- tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-)
tools/testing/selftests/kvm/include/x86_64/processor.h +1 -1
@@ -391,7 +391,7 @@ struct ex_regs {void vm_init_descriptor_tables (struct kvm_vm *vm);void vcpu_init_descriptor_tables (struct kvm_vm *vm,uint32_t vcpuid); -void vm_handle_exception (struct kvm_vm *vm,int vector, +void vm_install_exception_handler (struct kvm_vm *vm,int vector,void (*handler)(struct ex_regs *));/*
tools/testing/selftests/kvm/lib/x86_64/processor.c +2 -2
@@ -1244,8 +1244,8 @@ void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid) *(vm_vaddr_t *)addr_gva2hva (vm, (vm_vaddr_t)(&exception_handlers)) = vm->handlers; } -void vm_handle_exception (struct kvm_vm *vm,int vector, -void (*handler)(struct ex_regs *)) +void vm_install_exception_handler (struct kvm_vm *vm,int vector, +void (*handler)(struct ex_regs *)) {vm_vaddr_t *handlers = (vm_vaddr_t *)addr_gva2hva (vm, vm->handlers);
tools/testing/selftests/kvm/x86_64/evmcs_test.c +2 -2
@@ -154,8 +154,8 @@ int main(int argc, char *argv[])vm_init_descriptor_tables (vm);vcpu_init_descriptor_tables (vm,VCPU_ID ); -vm_handle_exception (vm,UD_VECTOR , guest_ud_handler); -vm_handle_exception (vm,NMI_VECTOR , guest_nmi_handler); +vm_install_exception_handler (vm,UD_VECTOR , guest_ud_handler); +vm_install_exception_handler (vm,NMI_VECTOR , guest_nmi_handler);pr_info ("Running L1 which uses EVMCS to run L2\n" );
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c +1 -1
@@ -227,7 +227,7 @@ int main(void)vm_init_descriptor_tables (vm);vcpu_init_descriptor_tables (vm,VCPU_ID ); -vm_handle_exception (vm,GP_VECTOR , guest_gp_handler); +vm_install_exception_handler (vm,GP_VECTOR , guest_gp_handler);enter_guest (vm);kvm_vm_free (vm);
tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +4 -4
@@ -574,7 +574,7 @@ static void test_msr_filter_allow(void) {vm_init_descriptor_tables (vm);vcpu_init_descriptor_tables (vm,VCPU_ID ); -vm_handle_exception (vm,GP_VECTOR , guest_gp_handler); +vm_install_exception_handler (vm,GP_VECTOR , guest_gp_handler);/* Process guest code userspace exits. */ run_guest_then_process_rdmsr (vm,MSR_IA32_XSS );
@@ -588,12 +588,12 @@ static void test_msr_filter_allow(void) {run_guest_then_process_wrmsr (vm,MSR_NON_EXISTENT );run_guest_then_process_rdmsr (vm,MSR_NON_EXISTENT ); -vm_handle_exception (vm,UD_VECTOR , guest_ud_handler); +vm_install_exception_handler (vm,UD_VECTOR , guest_ud_handler);run_guest (vm); -vm_handle_exception (vm,UD_VECTOR ,NULL ); +vm_install_exception_handler (vm,UD_VECTOR ,NULL );if (process_ucall (vm) !=UCALL_DONE ) { -vm_handle_exception (vm,GP_VECTOR , guest_fep_gp_handler); +vm_install_exception_handler (vm,GP_VECTOR , guest_fep_gp_handler);/* Process emulated rdmsr and wrmsr instructions. */ run_guest_then_process_rdmsr (vm,MSR_IA32_XSS );
tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +1 -1
@@ -462,7 +462,7 @@ int main(int argc, char *argv[])vm_init_descriptor_tables (vm);vcpu_init_descriptor_tables (vm,HALTER_VCPU_ID ); -vm_handle_exception (vm,IPI_VECTOR , guest_ipi_handler); +vm_install_exception_handler (vm,IPI_VECTOR , guest_ipi_handler);virt_pg_map (vm,APIC_DEFAULT_GPA ,APIC_DEFAULT_GPA ,0 );
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 2/6 KVM: selftests: Complete x86_64/sync_regs_test ucall
In reply to Ricardo KollerThe guest in sync_regs_test does raw ucalls by directly accessing the ucall IO port. It makes these ucalls without setting %rdi to a struct ucall, which is what a ucall uses to pass messages. The issue is that if the host did a get_ucall (the receiver side), it would try to access the struct ucall at %rdi=0 which would lead to an error ("No mapping for vm virtual address, gva: 0x0").
This issue is currently benign as there is no get_ucall in sync_regs_test; however, that will change in the next commit as it changes the unhandled exception reporting mechanism to use ucalls. In that case, every vcpu_run is followed by a get_ucall to check if the guest is trying to report an unhandled exception.
Fix this in advance by setting %rdi to a UCALL_NONE struct ucall for the sync_regs_test guest.
Tested with gcc-[8,9,10], and clang-[9,11].
--- tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/x86_64/sync_regs_test.c +6 -1
@@ -24,6 +24,10 @@#define UCALL_PIO_PORT ((uint16_t)0x1000) +struct ucall uc_none = { + .cmd =UCALL_NONE , +}; +/* * ucall is embedded here to protect against compiler reshuffling registers * before calling a function. In this test we only need to get KVM_EXIT_IO
@@ -34,7 +38,8 @@ void guest_code(void) asmvolatile ("1: in %[port], %%al\n" "add $0x1, %%rbx\n" "jmp 1b" - : : [port]"d" (UCALL_PIO_PORT ) :"rax" ,"rbx" ); + : : [port]"d" (UCALL_PIO_PORT ),"D" (&uc_none) + :"rax" ,"rbx" ); }static void compare_regs (struct kvm_regs *left,struct kvm_regs *right)
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 3/6 KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
In reply to Ricardo Kollerx86, 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)
--- .../testing/selftests/kvm/include/kvm_util.h | 1 + .../selftests/kvm/include/x86_64/processor.h | 2 -- .../selftests/kvm/lib/x86_64/processor.c | 19 ++++++++----------- 3 files changed, 9 insertions(+), 13 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +1 -0
@@ -349,6 +349,7 @@ enum {UCALL_SYNC ,UCALL_ABORT ,UCALL_DONE , + UCALL_UNHANDLED, };#define UCALL_MAX_ARGS 6
tools/testing/selftests/kvm/include/x86_64/processor.h +0 -2
@@ -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;
tools/testing/selftests/kvm/lib/x86_64/processor.c +8 -11
@@ -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,13 @@ void vm_install_exception_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); } }
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Sean Christopherson
reviewerRe: [PATCH v4 3/6] KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
Quoted 10 lines · Ricardo Koller
tools/testing/selftests/kvm/include/kvm_util.h +1
-0@@ -349,6 +349,7 @@ enum {UCALL_SYNC ,UCALL_ABORT ,UCALL_DONE , + UCALL_UNHANDLED, };
...
Quoted 7 lines
tools/testing/selftests/kvm/include/kvm_util.h +0
-3@@ -1254,16 +1254,13 @@ void vm_install_exception_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 ) {
tools/testing/selftests/kvm/include/kvm_util.h void vm_install_exception_handler(struct kvm_vm *vm, int vector, · line 1259
Quoted 10 lines
tools/testing/selftests/kvm/include/kvm_util.h +3
-7-/* 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 ) {
UCALL_UNHANDLED is a bit of an odd name. Without the surrounding context, I would have no idea that it's referring to an unhandled event, e.g. my gut reaction would be that it means the ucall itself was unhandled. Maybe UCALL_UNHANDLED_EVENT? It's rather long, but I don't think that will be problematic for any of the code.
Quoted 10 lines
tools/testing/selftests/kvm/include/kvm_util.h +4
-0+uint64_t vector = uc.args[0 ]; + +TEST_FAIL ("Unexpected vectored event in guest (vector:0x%lx)" , + vector); } }Signature · 1 line
2.32.0.272.g935e593368-goog
Re: [PATCH v4 3/6] KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
Quoted 27 lines · Sean Christopherson
Quoted 10 lines · Ricardo Koller
tools/testing/selftests/kvm/include/kvm_util.h +1
-0@@ -349,6 +349,7 @@ enum {UCALL_SYNC ,UCALL_ABORT ,UCALL_DONE , + UCALL_UNHANDLED, };...
Quoted 13 lines
tools/testing/selftests/kvm/include/kvm_util.h +0
-9@@ -1254,16 +1254,13 @@ void vm_install_exception_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)",
Quoted 8 lines
tools/testing/selftests/kvm/include/kvm_util.h void vm_install_exception_handler(struct kvm_vm *vm, int vector, · line 1259
Quoted 4 lines
tools/testing/selftests/kvm/include/kvm_util.h +3
-1- *data); +struct ucall uc; + +if (get_ucall (vm, vcpuid, &uc) ==UCALL_UNHANDLED ) {
UCALL_UNHANDLEDis a bit of an odd name. Without the surrounding context, I would have no idea that it's referring to an unhandled event, e.g. my gut reaction would be that it means the ucall itself was unhandled. MaybeUCALL_UNHANDLED_EVENT?
I see. I can send a new patch (this was commited as 75275d7fbe) with a new name. The only name I can think of that's more descriptive would be UCALL_UNHANDLED_EXCEPTION, but that's even longer.
Quoted 13 lines
It's rather long, but I don't think that will be problematic for any of the code.
Quoted 10 lines
tools/testing/selftests/kvm/include/kvm_util.h +4
-0+uint64_t vector = uc.args[0 ]; + +TEST_FAIL ("Unexpected vectored event in guest (vector:0x%lx)" , + vector); } }Signature · 1 line
2.32.0.272.g935e593368-goog
Sean Christopherson
reviewerRe: [PATCH v4 3/6] KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
Quoted 10 lines · Ricardo Koller
Quoted 8 lines · Sean Christopherson
tools/testing/selftests/kvm/lib/x86_64/processor.c void vm_install_exception_handler(struct kvm_vm *vm, int vector, · line 1259
Quoted 3 lines · Ricardo Koller
tools/testing/selftests/kvm/lib/x86_64/processor.c +3
-0+struct ucall uc; + +if (get_ucall (vm, vcpuid, &uc) ==UCALL_UNHANDLED ) {
UCALL_UNHANDLEDis a bit of an odd name. Without the surrounding context, I would have no idea that it's referring to an unhandled event, e.g. my gut reaction would be that it means the ucall itself was unhandled. MaybeUCALL_UNHANDLED_EVENT?
Quoted 2 lines
I see. I can send a new patch (this was commited as
75275d7fbe) with a new name.
Eh, no need to post another patch. If it can be fixed up in tree, great, if not, no big deal.
Quoted 2 lines
The only name I can think of that's more descriptive would be
UCALL_UNHANDLED_EXCEPTION, but that's even longer.
Unfortunately, EXCEPTION is incorrect as x86 will route unexpected IRQs through this as well.
PATCH v4 4/6 KVM: selftests: Move GUEST_ASSERT_EQ to utils header
In reply to Ricardo KollerMove GUEST_ASSERT_EQ to a common header, kvm_util.h, for other architectures and tests to use. Also modify __GUEST_ASSERT so it can be reused to implement GUEST_ASSERT_EQ.
--- .../testing/selftests/kvm/include/kvm_util.h | 22 ++++++++++--------- .../selftests/kvm/x86_64/tsc_msrs_test.c | 9 -------- 2 files changed, 12 insertions(+), 19 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +12 -10
@@ -368,26 +368,28 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc); ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4)#define GUEST_SYNC (stage) ucall(UCALL_SYNC, 2, "hello", stage)#define GUEST_DONE () ucall(UCALL_DONE, 0) -#define __GUEST_ASSERT(_condition, _nargs, _args...) do { \ - if (!(_condition)) \ - ucall(UCALL_ABORT, 2 + _nargs, \ - "Failed guest assert: " \ - #_condition, __LINE__, _args); \ +#define __GUEST_ASSERT(_condition, _condstr, _nargs, _args...) do { \ + if (!(_condition)) \ + ucall(UCALL_ABORT, 2 + _nargs, \ + "Failed guest assert: " \ + _condstr, __LINE__, _args); \ } while (0)#define GUEST_ASSERT (_condition) \ - __GUEST_ASSERT((_condition), 0, 0) + __GUEST_ASSERT(_condition, #_condition, 0, 0)#define GUEST_ASSERT_1 (_condition, arg1) \ - __GUEST_ASSERT((_condition), 1, (arg1)) + __GUEST_ASSERT(_condition, #_condition, 1, (arg1))#define GUEST_ASSERT_2 (_condition, arg1, arg2) \ - __GUEST_ASSERT((_condition), 2, (arg1), (arg2)) + __GUEST_ASSERT(_condition, #_condition, 2, (arg1), (arg2))#define GUEST_ASSERT_3 (_condition, arg1, arg2, arg3) \ - __GUEST_ASSERT((_condition), 3, (arg1), (arg2), (arg3)) + __GUEST_ASSERT(_condition, #_condition, 3, (arg1), (arg2), (arg3))#define GUEST_ASSERT_4 (_condition, arg1, arg2, arg3, arg4) \ - __GUEST_ASSERT((_condition), 4, (arg1), (arg2), (arg3), (arg4)) + __GUEST_ASSERT(_condition, #_condition, 4, (arg1), (arg2), (arg3), (arg4)) + +#define GUEST_ASSERT_EQ (a, b) __GUEST_ASSERT((a) == (b), #a " == " #b, 2, a, b)#endif /* SELFTEST_KVM_UTIL_H */
tools/testing/selftests/kvm/x86_64/tsc_msrs_test.c +0 -9
@@ -18,15 +18,6 @@#define rounded_rdmsr (x) ROUND(rdmsr(x))#define rounded_host_rdmsr (x) ROUND(vcpu_get_msr(vm, 0, x)) -#define GUEST_ASSERT_EQ (a, b) do { \ - __typeof(a) _a = (a); \ - __typeof(b) _b = (b); \ - if (_a != _b) \ - ucall(UCALL_ABORT, 4, \ - "Failed guest assert: " \ - #a " == " #b, __LINE__, _a, _b); \ - } while(0) -static void guest_code (void ) {u64 val =0 ;
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 5/6 KVM: selftests: Add exception handling support for aarch64
In reply to Ricardo KollerAdd the infrastructure needed to enable exception handling in aarch64 selftests. The exception handling defaults to an unhandled-exception handler which aborts the test, just like x86. These handlers can be overridden by calling vm_install_exception_handler(vector) or vm_install_sync_handler(vector, ec). The unhandled exception reporting from the guest is done using the ucall type introduced in a previous commit, UCALL_UNHANDLED.
The exception handling code is inspired on kvm-unit-tests.
--- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/include/aarch64/processor.h | 63 +++++++++ .../selftests/kvm/lib/aarch64/handlers.S | 126 ++++++++++++++++++ .../selftests/kvm/lib/aarch64/processor.c | 97 ++++++++++++++ 4 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/lib/aarch64/handlers.S
tools/testing/selftests/kvm/Makefile +1 -1
@@ -35,7 +35,7 @@ endif LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/rbtree.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S -LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c +LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
tools/testing/selftests/kvm/include/aarch64/processor.h +63 -0
79 lines not on this page · raw message
tools/testing/selftests/kvm/lib/aarch64/handlers.S new file +126 -0
126 lines not on this page · raw message
tools/testing/selftests/kvm/lib/aarch64/processor.c +97 -0
115 lines not on this page · raw message
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Zenghui Yu
reviewerRe: [PATCH v4 5/6] KVM: selftests: Add exception handling support for aarch64
[+Sean]
Quoted 18 lines · Ricardo Koller
Add the infrastructure needed to enable exception handling in aarch64 selftests. The exception handling defaults to an unhandled-exception handler which aborts the test, just like x86. These handlers can be overridden by calling
vm_install_exception_handler(vector)orvm_install_sync_handler(vector, ec). The unhandled exception reporting from the guest is done using the ucall type introduced in a previous commit,UCALL_UNHANDLED.The exception handling code is inspired on kvm-unit-tests.
Signed-off-by Ricardo Koller <[email protected]>--- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/include/aarch64/processor.h | 63 +++++++++ .../selftests/kvm/lib/aarch64/handlers.S | 126 ++++++++++++++++++ .../selftests/kvm/lib/aarch64/processor.c | 97 ++++++++++++++ 4 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/lib/aarch64/handlers.S
[...]
tools/testing/selftests/kvm/lib/aarch64/processor.c void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) · line 412
Quoted 4 lines
tools/testing/selftests/kvm/lib/aarch64/processor.c +4
-0+void vm_init_descriptor_tables (struct kvm_vm *vm) +{ + vm->handlers =vm_vaddr_alloc (vm,sizeof (struct handlers ), + vm->page_size,0 ,0 );
This raced with commit a75a895e6457 ("KVM: selftests: Unconditionally use memslot 0 for vaddr allocations") which dropped memslot parameters from vm_vaddr_alloc().
We can remove the related comments on top of vm_vaddr_alloc() as well.
Zenghui
Re: [PATCH v4 5/6] KVM: selftests: Add exception handling support for aarch64
Quoted 24 lines · Zenghui Yu
[+Sean]
Quoted 18 lines · Ricardo Koller
Add the infrastructure needed to enable exception handling in aarch64 selftests. The exception handling defaults to an unhandled-exception handler which aborts the test, just like x86. These handlers can be overridden by calling
vm_install_exception_handler(vector)orvm_install_sync_handler(vector, ec). The unhandled exception reporting from the guest is done using the ucall type introduced in a previous commit,UCALL_UNHANDLED.The exception handling code is inspired on kvm-unit-tests.
Signed-off-by Ricardo Koller <[email protected]>--- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/include/aarch64/processor.h | 63 +++++++++ .../selftests/kvm/lib/aarch64/handlers.S | 126 ++++++++++++++++++ .../selftests/kvm/lib/aarch64/processor.c | 97 ++++++++++++++ 4 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/lib/aarch64/handlers.S[...]
Quoted 8 lines
tools/testing/selftests/kvm/lib/aarch64/processor.c void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) · line 412
Quoted 4 lines
tools/testing/selftests/kvm/lib/aarch64/processor.c +4
-0+void vm_init_descriptor_tables (struct kvm_vm *vm) +{ + vm->handlers =vm_vaddr_alloc (vm,sizeof (struct handlers ), + vm->page_size,0 ,0 );This raced with commit
a75a895e6457("KVM: selftests: Unconditionally use memslot 0 for vaddr allocations") which dropped memslot parameters fromvm_vaddr_alloc().
Will send a fix to use vm_vaddr_alloc() without the memslot parameters.
Quoted 2 lines
We can remove the related comments on top of
vm_vaddr_alloc()as well.
Can do this as well, will send a separate patch removing this. Unless somebody was about to.
Quoted 2 lines
Zenghui
Thanks,
Ricardo
PATCH v4 6/6 KVM: selftests: Add aarch64/debug-exceptions test
In reply to Ricardo KollerCovers fundamental tests for debug exceptions. The guest installs and handle its debug exceptions itself, without KVM_SET_GUEST_DEBUG.
--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/debug-exceptions.c | 250 ++++++++++++++++++ .../selftests/kvm/include/aarch64/processor.h | 22 +- 4 files changed, 268 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/debug-exceptions.c
tools/testing/selftests/kvm/.gitignore +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +/aarch64/debug-exceptions /aarch64/get-reg-list /aarch64/get-reg-list-sve /aarch64/vgic_init
tools/testing/selftests/kvm/Makefile +1 -0
@@ -78,6 +78,7 @@ TEST_GEN_PROGS_x86_64 += memslot_perf_test TEST_GEN_PROGS_x86_64 += set_memory_region_test TEST_GEN_PROGS_x86_64 += steal_time +TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
tools/testing/selftests/kvm/aarch64/debug-exceptions.c new file +250 -0
250 lines not on this page · raw message
tools/testing/selftests/kvm/include/aarch64/processor.h +16 -6
@@ -14,12 +14,14 @@#define ARM64_CORE_REG (x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x)) -#define CPACR_EL1 3, 0, 1, 0, 2 -#define TCR_EL1 3, 0, 2, 0, 2 -#define MAIR_EL1 3, 0, 10, 2, 0 -#define TTBR0_EL1 3, 0, 2, 0, 0 -#define SCTLR_EL1 3, 0, 1, 0, 0 -#define VBAR_EL1 3, 0, 12, 0, 0 +#define CPACR_EL1 3, 0, 1, 0, 2 +#define TCR_EL1 3, 0, 2, 0, 2 +#define MAIR_EL1 3, 0, 10, 2, 0 +#define TTBR0_EL1 3, 0, 2, 0, 0 +#define SCTLR_EL1 3, 0, 1, 0, 0 +#define VBAR_EL1 3, 0, 12, 0, 0 + +#define ID_AA64DFR0_EL1 3, 0, 0, 5, 0/* * Default MAIR
@@ -98,6 +100,12 @@ enum {#define ESR_EC_SHIFT 26#define ESR_EC_MASK (ESR_EC_NUM - 1) +#define ESR_EC_SVC64 0x15 +#define ESR_EC_HW_BP_CURRENT 0x31 +#define ESR_EC_SSTEP_CURRENT 0x33 +#define ESR_EC_WP_CURRENT 0x35 +#define ESR_EC_BRK_INS 0x3c +void vm_init_descriptor_tables (struct kvm_vm *vm);void vcpu_init_descriptor_tables (struct kvm_vm *vm,uint32_t vcpuid);
@@ -119,4 +127,6 @@ void vm_install_sync_handler(struct kvm_vm *vm, val; \ }) +#define isb () asm volatile("isb" : : : "memory") +#endif /* SELFTEST_KVM_PROCESSOR_H */
Signature · 6 lines
2.32.0.272.g935e593368-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerQuoted 19 lines · Ricardo Koller
Hi,
These patches add a debug exception test in aarch64 KVM selftests while also adding basic exception handling support.
The structure of the exception handling is based on its x86 counterpart. Tests use the same calls to initialize exception handling and both architectures allow tests to override the handler for a particular vector, or (vector, ec) for synchronous exceptions in the arm64 case.
The debug test is similar to x86_64/debug_regs, except that the x86 one controls the debugging from outside the VM. This proposed arm64 test controls and handles debug exceptions from the inside.
Thanks,
Ricardov3 -> v4:
Quoted 8 lines
V3 was dropped because it was breaking x86 selftests builds (reported by the kernel test robot).
- renamevm_handle_exceptiontovm_install_sync_handlerinstead ofvm_install_vector_handlers. [Sean]
- use a single level of routing for exception handling. [Sean]
- fix issue in x86_64/sync_regs_test when switching to ucalls for unhandled
exceptions reporting.
This looks good to me. If I can get an Ack from any of the x86 maintainers, I'll queue the series.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 74 lines · Ricardo Koller
Hi,
These patches add a debug exception test in aarch64 KVM selftests while also adding basic exception handling support.
The structure of the exception handling is based on its x86 counterpart. Tests use the same calls to initialize exception handling and both architectures allow tests to override the handler for a particular vector, or (vector, ec) for synchronous exceptions in the arm64 case.
The debug test is similar to x86_64/debug_regs, except that the x86 one controls the debugging from outside the VM. This proposed arm64 test controls and handles debug exceptions from the inside.
Thanks,
Ricardov3 -> v4:
V3 was dropped because it was breaking x86 selftests builds (reported by the kernel test robot).
- renamevm_handle_exceptiontovm_install_sync_handlerinstead ofvm_install_vector_handlers. [Sean]
- use a single level of routing for exception handling. [Sean]
- fix issue in x86_64/sync_regs_test when switching to ucalls for unhandled exceptions reporting.v2 -> v3:
Addressed comments from Andrew and Marc (thanks again). Also, many thanks for the reviews and tests from Eric and Zenghui.
- add missing ISBs after writing into debug registers.
- not store/restore ofsp_el0on exceptions.
- add default handlers for Error and FIQ.
- change multipleTEST_ASSERT(false, ...)toTEST_FAIL.
- use Andrew's suggestion regarding__GUEST_ASSERTmodifications in order to easier implementGUEST_ASSERT_EQ(Thanks Andrew).v1 -> v2:
Addressed comments from Andrew and Marc (thank you very much):
- renamevm_handle_exceptionin all tests.
- introduceUCALL_UNHANDLEDin x86 first.
- moveGUEST_ASSERT_EQto common utils header.
- handle sync and other exceptions separately: use two tables (like kvm-unit-tests).
- add two separate functions for installing sync versus other exceptions
- changes inhandlers.S: use the same layout asuser_pt_regs, treat the EL1t vectors as invalid, refactor the vector table creation to not use manual numbering, add comments, remove LR from the stored registers.
- changes indebug-exceptions.c: remove unused headers, use the commonGUEST_ASSERT_EQ, usevcpu_runinstead of_vcpu_run.
- changes inprocessor.h:write_sysregwith support for xzr, replace EL1 with current in macro names, defineESR_EC_MASKas ESR_EC_NUM-1.Ricardo Koller (6):
KVM: selftests: Renamevm_handle_exception
KVM: selftests: Complete x86_64/sync_regs_test ucall
KVM: selftests: IntroduceUCALL_UNHANDLEDfor unhandled vector
reporting
KVM: selftests: MoveGUEST_ASSERT_EQto utils header
KVM: selftests: Add exception handling support for aarch64
KVM: selftests: Add aarch64/debug-exceptions testtools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 3 +- .../selftests/kvm/aarch64/debug-exceptions.c | 250 ++++++++++++++++++ .../selftests/kvm/include/aarch64/processor.h | 83 +++++- .../testing/selftests/kvm/include/kvm_util.h | 23 +- .../selftests/kvm/include/x86_64/processor.h | 4 +- .../selftests/kvm/lib/aarch64/handlers.S | 126 +++++++++ .../selftests/kvm/lib/aarch64/processor.c | 97 +++++++ .../selftests/kvm/lib/x86_64/processor.c | 23 +- .../testing/selftests/kvm/x86_64/evmcs_test.c | 4 +-
Quoted 12 lines
.../selftests/kvm/x86_64/kvm_pv_test.c | 2 +- .../selftests/kvm/x86_64/sync_regs_test.c | 7 +- .../selftests/kvm/x86_64/tsc_msrs_test.c | 9 - .../kvm/x86_64/userspace_msr_exit_test.c | 8 +- .../selftests/kvm/x86_64/xapic_ipi_test.c | 2 +- 15 files changed, 592 insertions(+), 50 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/debug-exceptions.c create mode 100644 tools/testing/selftests/kvm/lib/aarch64/handlers.SSignature · 1 line
2.32.0.272.g935e593368-goog
For the series
Thanks,
drew
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 9 lines · Ricardo Koller
These patches add a debug exception test in aarch64 KVM selftests while also adding basic exception handling support.
The structure of the exception handling is based on its x86 counterpart. Tests use the same calls to initialize exception handling and both architectures allow tests to override the handler for a particular vector, or (vector, ec) for synchronous exceptions in the arm64 case.
[...]
Applied to next, thanks!
[1/6] KVM: selftests: Rename vm_handle_exception
commit: b78f4a596692f6805e796a4c13f2d921b8a95166
[2/6] KVM: selftests: Complete x86_64/sync_regs_test ucall
commit: b7326c01122683b88e273a0cc826cd4c01234470
[3/6] KVM: selftests: Introduce UCALL_UNHANDLED for unhandled vector reporting
commit: 75275d7fbef47805b77e8af81a4d51e2d92db70f
[4/6] KVM: selftests: Move GUEST_ASSERT_EQ to utils header
commit: 67f709f52bf0b5c19f24d1234163123cbb6af545
[5/6] KVM: selftests: Add exception handling support for aarch64
commit: e3db7579ef355a0b2bfef4448b84d9ac882c8f2c
[6/6] KVM: selftests: Add aarch64/debug-exceptions test
commit: 4f05223acaeaabe0a1a188e25fab334735d85c5eCheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.