[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] xen/arm: ignore spurious interrupts from virtual timer


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • Date: Thu, 3 Dec 2026 23:25:29 +0000
  • Accept-language: en-US, uk-UA
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cPpmYS1hZvO/e+jOwDR72hXbZKxWKNMxtmhVuB+F45U=; b=bYY1yR8X/SawRqSQ2VghTD26O0feSvSq5kNBkgQj34Y+sOUInBZa1Z6ioNmWDxVpqumqZwUcZ0CtY0er+8funkHJXJliJOKD5PxLK5pKrwKt3w21/cixe5r9wrQfwz0OYVfrXisKmCu1qEq9fXjOA7z3c56rmmAIr/KF8cX4SUHXxwb6xVHXH/rRfU0n4pMmuvwFpvLE5JFvFxMIsT/3OmDshc+9RuDmscjNUmbmCPrN1oYomTr9KzK2HHwcdRtlKfeektBUitSvwCikYweegFweD1wx/1NSoRu4K244VPNRPzQoioAUt4FevaNvDz24xAbFVuVn7aXUPZOsGXaqCw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HchaqH5KFGPByuNzqhE2XqsBLxCHrmZcZWixx44lSMRmjMkRCujowMkJo1cO2VQCBRYdLj1GNzZ/bhGisiaaR3YOxVTUpWh68scaeBsRpVCDWBwpbJGl7caBLT9RfzodDtpEIX8LnVDzdi6sgG9C5qgjVfSNlCLsOukOBjfw+SGf6EBl1Qi5QRrUikswJUUAcaxLnM7kEhaFH/Lg7jPqK3j/N5F99+XpC5zW2jwQVX+Vymdig93okf2SDuSFoIM7O/0iYrBep9gxDnO9cRZMn6VJxJa2AVnlGpN3q7L1JcvZv/WXXa9xR/xHUUbzvIYHaRnsEoq8fDa24/9HVY9v5A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 03 Dec 2026 23:25:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdg32VNG8X8a0O80ublMNQ92xg0Q==
  • Thread-topic: [PATCH v2] xen/arm: ignore spurious interrupts from virtual timer

If the virtual timer IRQ fires but the timer is not pending (the ISTATUS
bit in CNTV_CTL_EL0 is clear), Xen masks the timer and injects the IRQ
into the guest. Linux unmasks the timer when it programs a new CVAL.
If ISTATUS is clear, its timer IRQ handler skips the clock event handler.
The timer can stay masked and the guest can miss the next timer IRQ.

This patch mirrors the Linux arm generic timer handler: if the interrupt
fires but the pending bit is not set, treat it as spurious and ignore it.

This issue is reproducible under heavy load on the R-Car X5H board
(Cortex-A720AE r0p0).

Add a performance counter for virtual timer IRQs ignored by this check.

Fixes: b765caf5101a ("xen/arm: support the ARM generic virtual timer")
Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
Changes in v2:
- Say "ISTATUS bit clear" in the commit message (Julien, Michal).
- Add the Fixes tag and a comment in vtimer_interrupt() (Michal).
- No functional change, so keep Volodymyr's Reviewed-by.
---
 xen/arch/arm/include/asm/perfc_defn.h |  7 ++++---
 xen/arch/arm/time.c                   | 16 +++++++++++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/include/asm/perfc_defn.h 
b/xen/arch/arm/include/asm/perfc_defn.h
index 8dfcac7e3b..50def279fa 100644
--- a/xen/arch/arm/include/asm/perfc_defn.h
+++ b/xen/arch/arm/include/asm/perfc_defn.h
@@ -70,9 +70,10 @@ PERFCOUNTER(ppis,                 "#PPIs")
 PERFCOUNTER(spis,                 "#SPIs")
 PERFCOUNTER(guest_irqs,           "#GUEST-IRQS")
 
-PERFCOUNTER(hyp_timer_irqs,   "Hypervisor timer interrupts")
-PERFCOUNTER(virt_timer_irqs,  "Virtual timer interrupts")
-PERFCOUNTER(maintenance_irqs, "Maintenance interrupts")
+PERFCOUNTER(hyp_timer_irqs,             "Hypervisor timer interrupts")
+PERFCOUNTER(virt_timer_irqs,            "Virtual timer interrupts")
+PERFCOUNTER(virt_timer_spurious_irqs,   "Virtual timer spurious interrupts")
+PERFCOUNTER(maintenance_irqs,           "Maintenance interrupts")
 
 PERFCOUNTER(atomics_guest,    "atomics: guest access")
 PERFCOUNTER(atomics_guest_paused,   "atomics: guest paused")
diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index 295afa685a..be52b24c67 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -262,6 +262,8 @@ static void htimer_interrupt(int irq, void *dev_id)
 
 static void vtimer_interrupt(int irq, void *dev_id)
 {
+    register_t ctl;
+
     /*
      * Edge-triggered interrupts can be used for the virtual timer. Even
      * if the timer output signal is masked in the context switch, the
@@ -275,9 +277,21 @@ static void vtimer_interrupt(int irq, void *dev_id)
     if ( unlikely(is_idle_vcpu(current)) )
         return;
 
+    ctl = READ_SYSREG(CNTV_CTL_EL0);
+
+    /*
+     * If ISTATUS is clear, do not mask the timer or inject the vIRQ.
+     * A guest that ignores the IRQ may leave the timer masked.
+     */
+    if ( unlikely(!(ctl & CNTx_CTL_PENDING)) )
+    {
+        perfc_incr(virt_timer_spurious_irqs);
+        return;
+    }
+
     perfc_incr(virt_timer_irqs);
 
-    current->arch.virt_timer.ctl = READ_SYSREG(CNTV_CTL_EL0);
+    current->arch.virt_timer.ctl = ctl;
     WRITE_SYSREG(current->arch.virt_timer.ctl | CNTx_CTL_MASK, CNTV_CTL_EL0);
     vgic_inject_irq(current->domain, current, current->arch.virt_timer.irq, 
true);
 }
-- 
2.53.0

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.