linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: nv: Set ISTATUS for emulated timers, If timer expired
@ 2024-12-09  5:32 Ganapatrao Kulkarni
  2024-12-09  9:54 ` Marc Zyngier
  2024-12-09 19:36 ` kernel test robot
  0 siblings, 2 replies; 32+ messages in thread
From: Ganapatrao Kulkarni @ 2024-12-09  5:32 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, linux-kernel
  Cc: maz, oliver.upton, christoffer.dall, suzuki.poulose, will,
	catalin.marinas, coltonlewis, joey.gouly, yuzenghui, darren,
	gankulkarni, vishnu

During automated testing of Nested Virtualization using avocado-vt,
it has been observed that during some boot test iterations,
the Guest-Hypervisor boot was getting crashed with a
synchronous exception while it is still booting EDK2.

The test is launching Multiple instances of Guest-Hypervisor boot
and while booting, QEMU monitor issued the command "info register"
at regular intervals to take a register dump. To execute this
command, QEMU stops the run and does the register read of various
registers. While resuming the run, the function kvm_arm_timer_write()
writes back the saved CNTV_CTL_EL0 register with ISTATUS cleared always
and resulting in the loss of pending interrupt for emulated timers.

In hardware based timers, ISTATUS is a RO/WI bit and gets set by the
h/w, if the condition is still met. However, in Nested-Virtualization
case, the Guest-Hypervisor's EDK2 is using an emulated virtual timer
and losing ISTATUS state and the interrupt forever.

Adding fix in kvm_arm_timer_write to set ISTATUS for emulated
timers, if the timer expired already.

Fixes: 81dc9504a700 ("KVM: arm64: nv: timers: Support hyp timer emulation")
Co-developed-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Signed-off-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
---
 arch/arm64/kvm/arch_timer.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index 1215df590418..aca58113d790 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -1199,7 +1199,16 @@ static void kvm_arm_timer_write(struct kvm_vcpu *vcpu,
 		break;
 
 	case TIMER_REG_CTL:
-		timer_set_ctl(timer, val & ~ARCH_TIMER_CTRL_IT_STAT);
+		struct timer_map map;
+
+		val &= ~ARCH_TIMER_CTRL_IT_STAT;
+		get_timer_map(vcpu, &map);
+		/* Set ISTATUS bit for emulated timers, if timer expired. */
+		if (timer == map.emul_vtimer || timer == map.emul_ptimer) {
+			if (!kvm_timer_compute_delta(timer))
+				val |= ARCH_TIMER_CTRL_IT_STAT;
+		}
+		timer_set_ctl(timer, val);
 		break;
 
 	case TIMER_REG_CVAL:
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2025-02-20  6:12 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09  5:32 [PATCH] KVM: arm64: nv: Set ISTATUS for emulated timers, If timer expired Ganapatrao Kulkarni
2024-12-09  9:54 ` Marc Zyngier
2024-12-09 12:25   ` Ganapatrao Kulkarni
2024-12-09 13:20     ` Marc Zyngier
2024-12-09 15:23       ` Marc Zyngier
2024-12-09 15:39       ` Ganapatrao Kulkarni
2024-12-09 15:52         ` Marc Zyngier
2024-12-09 16:46         ` Eric Auger
2024-12-09 17:30           ` Marc Zyngier
2024-12-09 17:34             ` Eric Auger
2024-12-19  9:30               ` Ganapatrao Kulkarni
2024-12-19 12:23                 ` Marc Zyngier
2025-01-14 13:12                 ` Eric Auger
2025-01-14 14:38                   ` Marc Zyngier
2025-01-14 14:57                     ` Eric Auger
2025-01-14 15:52                       ` Marc Zyngier
2025-01-16 17:52                         ` Eric Auger
2025-01-16 18:25                           ` Marc Zyngier
2025-02-07 17:45                           ` Marc Zyngier
2025-02-07 18:09                             ` Oliver Upton
2025-02-07 18:38                               ` Marc Zyngier
2025-02-07 19:08                                 ` Oliver Upton
2025-02-10 18:26                                 ` Eric Auger
2025-02-11 19:20                                   ` Marc Zyngier
2025-02-15 17:50                                   ` Marc Zyngier
2025-02-18  7:33                                     ` Ganapatrao Kulkarni
2025-02-18 16:33                                       ` Marc Zyngier
2025-02-18 21:24                                       ` Marc Zyngier
2025-02-20  6:10                                         ` Ganapatrao Kulkarni
2025-02-10 13:18                             ` Eric Auger
2024-12-10 12:48       ` Ganapatrao Kulkarni
2024-12-09 19:36 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).