Program an unmasked timer whose cval sits within long_wait_ms of the
counter's wrap while the guest's counter is at wait_ms, and expect no
interrupt. The guest's counter can't reach it, but a host that applies
the timer's offset by adding it to cval wraps the sum into the past and
fires at once. The one existing case with a cval past the wrap, in the
sanity checks, runs with the timer masked and can't see that.

Signed-off-by: Fuad Tabba <[email protected]>
---
 .../kvm/arm64/arch_timer_edge_cases.c         | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c 
b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
index d9c9377a63256..69986a7f0d37d 100644
--- a/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
+++ b/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
@@ -787,6 +787,30 @@ static void test_timers_in_the_past(enum arch_timer timer)
        }
 }
 
+/*
+ * With the counter at wait_ms, a tval of -(wait_ms + long_wait_ms) puts cval
+ * within long_wait_ms of the counter's wrap: a deadline further away than the
+ * counter can reach. Unmasked, so an early ISTATUS shows up as an IRQ.
+ */
+static void test_timers_past_counter_wrap(enum arch_timer timer)
+{
+       s32 tval = -(s32)msec_to_cycles(test_args.wait_ms + 
test_args.long_wait_ms);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(sleep_method); i++) {
+               sleep_method_t sm = sleep_method[i];
+
+               local_irq_disable();
+               set_counter(timer, msec_to_cycles(test_args.wait_ms));
+               set_tval_irq(timer, tval, CTL_ENABLE);
+               sm(timer, msecs_to_usecs(test_args.wait_ms) + 
TIMEOUT_NO_IRQ_US);
+               local_irq_enable();
+               isb();
+               assert_irqs_handled(0);
+               timer_set_ctl(timer, CTL_IMASK);
+       }
+}
+
 static void test_long_timer_delays(enum arch_timer timer)
 {
        s32 tval = (s32)msec_to_cycles(test_args.long_wait_ms);
@@ -806,6 +830,7 @@ static void guest_run_iteration(enum arch_timer timer)
        test_basic_functionality(timer);
        test_timers_sanity_checks(timer);
 
+       test_timers_past_counter_wrap(timer);
        test_timers_above_tval_max(timer);
        test_timers_in_the_past(timer);
 
-- 
2.39.5


Reply via email to