Add arch_timer_edge_cases selftest
v6 cover Add arch_timer_edge_cases selftest
Add arch_timer_edge_cases selftest to test various corner cases of the ARM timers such as:
* timers above the max TVAL value
* timers in the past
* moving counters ahead and behind pending timers
* reprogramming timers
* timers fired multiple times
* masking/unmasking using the timer control mask
These are intentionally unusual scenarios to stress compliance with the arm architecture.
v6:
* Remove unused headers
* Declare const variables as static
* Clarify by using INT32_{MIN,MAX}
* Remove silly enum magic value
* Instead of commenting a function should be called with IRQs disabled, just disable them in function
* Remove unnecessary loop in test_reprogram_timers()
* Lift some invariant assignments out of loops
* Add some comments around better explaining wm() (irq_wait_method) functions
* Fix typos
v5:
https://lore.kernel.org/all/[email protected]/
v4:
https://lore.kernel.org/kvmarm/[email protected]/
v3:
https://lore.kernel.org/kvmarm/[email protected]/
v2:
https://lore.kernel.org/kvmarm/[email protected]/
v1:
https://lore.kernel.org/kvm/[email protected]/
Colton Lewis (2):
KVM: selftests: Ensure pending interrupts are handled in arch_timer
test
KVM: arm64: selftests: Add arch_timer_edge_cases selftest
tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/arch_timer_edge_cases.c | 1062 +++++++++++++++++ .../testing/selftests/kvm/aarch64/vgic_irq.c | 11 +- .../kvm/include/aarch64/arch_timer.h | 18 +- .../selftests/kvm/include/aarch64/processor.h | 3 + .../selftests/kvm/lib/aarch64/processor.c | 6 + 6 files changed, 1094 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/arch_timer_edge_cases.c
--
2.46.0.295.g3b9ea8a38a-goog
PATCH v6 1/2 KVM: selftests: Ensure pending interrupts are handled in arch_timer test
Break up the asm instructions poking daifclr and daifset to handle interrupts. R_RBZYL specifies pending interrupts will be handle after context synchronization events such as an ISB.
Introduce a function wrapper for the WFI instruction.
--- tools/testing/selftests/kvm/aarch64/vgic_irq.c | 11 +++++------ .../testing/selftests/kvm/include/aarch64/processor.h | 3 +++ tools/testing/selftests/kvm/lib/aarch64/processor.c | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/aarch64/vgic_irq.c +5 -6
@@ -269,13 +269,12 @@ static void guest_inject(struct test_args *args,KVM_INJECT_MULTI (cmd, first_intid, num);while (irq_handled < num) { - asmvolatile ("wfi\n" -"msr daifclr, #2\n" -/* handle IRQ */ -"msr daifset, #2\n" - : : :"memory" ); +wfi (); +local_irq_enable (); +isb ();/* handle IRQ */ +local_irq_disable (); } - asmvolatile ("msr daifclr, #2" : : :"memory" ); +local_irq_enable ();GUEST_ASSERT_EQ (irq_handled, num);for (i = first_intid; i < num + first_intid; i++)
tools/testing/selftests/kvm/include/aarch64/processor.h +3 -0
@@ -243,4 +243,7 @@ void smccc_smc(uint32_t function_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, struct arm_smccc_res *res); +/* Execute a Wait For Interrupt instruction. */ +void wfi (void ); +#endif /* SELFTEST_KVM_PROCESSOR_H */
tools/testing/selftests/kvm/lib/aarch64/processor.c +6 -0
@@ -639,3 +639,9 @@ void vm_vaddr_populate_bitmap(struct kvm_vm *vm)sparsebit_set_num (vm->vpages_valid,0 , (1ULL << vm->va_bits) >> vm->page_shift); } + +/* Helper to call wfi instruction. */ +void wfi (void ) +{ + asmvolatile ("wfi" ); +}
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog
PATCH v6 2/2 KVM: arm64: selftests: Add arch_timer_edge_cases selftest
In reply to Colton LewisAdd a new arch_timer_edge_cases selftests that validates:
* timers above the max TVAL value
* timers in the past
* moving counters ahead and behind pending timers
* reprograming timers
* timers fired multiple times
* masking/unmasking using the timer control mask
These are intentionally unusual scenarios to stress compliance with the arm architecture.
--- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/arch_timer_edge_cases.c | 1062 +++++++++++++++++ .../kvm/include/aarch64/arch_timer.h | 18 +- 3 files changed, 1080 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/aarch64/arch_timer_edge_cases.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -152,6 +152,7 @@ TEST_GEN_PROGS_x86_64 += pre_fault_memory_test TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test TEST_GEN_PROGS_aarch64 += aarch64/aarch32_id_regs +TEST_GEN_PROGS_aarch64 += aarch64/arch_timer_edge_cases TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/hypercalls TEST_GEN_PROGS_aarch64 += aarch64/page_fault_test
tools/testing/selftests/kvm/aarch64/arch_timer_edge_cases.c new file +1062 -0
1,062 lines not on this page · raw message
tools/testing/selftests/kvm/include/aarch64/arch_timer.h +17 -1
@@ -79,7 +79,7 @@ static inline uint64_t timer_get_cval(enum arch_timer timer)return 0 ; } -static inline void timer_set_tval (enum arch_timer timer,uint32_t tval) +static inline void timer_set_tval (enum arch_timer timer,int32_t tval) {switch (timer) {case VIRTUAL :
@@ -95,6 +95,22 @@ static inline void timer_set_tval(enum arch_timer timer, uint32_t tval)isb (); } +static inline int32_t timer_get_tval (enum arch_timer timer) +{ +isb (); +switch (timer) { +case VIRTUAL : +return read_sysreg (cntv_tval_el0); +case PHYSICAL : +return read_sysreg (cntp_tval_el0); +default : +GUEST_FAIL ("Could not get timer %d\n" , timer); + } + +/* We should not reach here */ +return 0 ; +} +static inline void timer_set_ctl (enum arch_timer timer,uint32_t ctl) {switch (timer) {
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog
Quoted 11 lines · Colton Lewis
Add
arch_timer_edge_casesselftest to test various corner cases of the ARM timers such as:* timers above the max TVAL value
* timers in the past
* moving counters ahead and behind pending timers
* reprogramming timers
* timers fired multiple times
* masking/unmasking using the timer control mask[...]
Applied to next, thanks!
[1/2] KVM: selftests: Ensure pending interrupts are handled in arch_timer test
commit: ca1a18368d764f9b29ab0c79b3ddd712f5511855
[2/2] KVM: arm64: selftests: Add arch_timer_edge_cases selftest
commit: 54306f564441f6bc99514af45552236f28b1768dCheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.