xen/arm: avoid overflow when setting vtimer in context switch
authorJiamei Xie <jiamei.xie@arm.com>
Wed, 6 Jul 2022 08:25:58 +0000 (16:25 +0800)
committerStefano Stabellini <stefano.stabellini@amd.com>
Wed, 3 Aug 2022 21:58:04 +0000 (14:58 -0700)
commit48e7440ec6eb6eb99011a549a649c44632f69edb
treee76c365be6dd2884a95b3cf5760aba85aabb821e
parent3050769a171a881b6225c98c750e1c5f92311081
xen/arm: avoid overflow when setting vtimer in context switch

virt_vtimer_save() will calculate the next deadline when the vCPU is
scheduled out. At the moment, Xen will use the following equation:

  virt_timer.cval + virt_time_base.offset - boot_count

The three values are 64-bit and one (cval) is controlled by domain. In
theory, it would be possible that the domain has started a long time
after the system boot. So virt_time_base.offset - boot_count may be a
large numbers.

This means a domain may inadvertently set a cval so the result would
overflow. Consequently, the deadline would be set very far in the
future. This could result to loss of timer interrupts or the vCPU
getting block "forever".

One way to solve the problem, would be to separately
   1) compute when the domain was created in ns
   2) convert cval to ns
   3) Add 1 and 2 together

The first part of the equation never change (the value is set/known at
domain creation). So take the opportunity to store it in domain structure.

Signed-off-by: Jiamei Xie <jiamei.xie@arm.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
(cherry picked from commit 6655eb81092a94e065fdcd0b47a1b1d69dc4e54c)
xen/arch/arm/vtimer.c
xen/include/asm-arm/domain.h