From nobody Wed Apr 8 07:25:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1775126883; cv=none; d=zohomail.com; s=zohoarc; b=AvFAmYk5tIsoA1WbSasgkgNSdpr5lNeVRzmvX2pXMVMqUgy2YCPqC/KlsC7QmTFHXiCwnx39cufOSkQEkgGE4IUZQy0kLWYvooPEHBc2mXk0hq9CN0qU4KreyzluGe9BaJrvfUzGZNUXZheKmKqaTYFLUfoeW4qTImfpsOMOf/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775126883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Q0cUh9DunvbioAZLIRhQfJTs0EihHFj+/wkrJJoLmJs=; b=i6mq4a7moDiClUO9iawIy/xzB02dsk74kV+wdLEkBpQR3ynGeeWb9/+Lz3/lHM6KhvN0tFKmhilQmp1D/qdwqX8SR2k5zxUXMpeDZxrf9lwj/Okp3k7+JTCoAOX4stE0u0btR7ENHqxBsjF0Pf4Dv640gKDadWxZaDtMhD9ng94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1775126883574105.47409252939372; Thu, 2 Apr 2026 03:48:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1271520.1559634 (Exim 4.92) (envelope-from ) id 1w8FaD-00045P-Di; Thu, 02 Apr 2026 10:47:29 +0000 Received: by outflank-mailman (output) from mailman id 1271520.1559634; Thu, 02 Apr 2026 10:47:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w8FaD-00044A-Ah; Thu, 02 Apr 2026 10:47:29 +0000 Received: by outflank-mailman (input) for mailman id 1271520; Thu, 02 Apr 2026 10:47:28 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w8FaC-0003yr-3q for xen-devel@lists.xenproject.org; Thu, 02 Apr 2026 10:47:28 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w8FaB-009q68-FZ for xen-devel@lists.xenproject.org; Thu, 02 Apr 2026 12:47:27 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ce493f-e002-0a2a0a5209dd-0a2a450a8a2e-0 for ; Thu, 02 Apr 2026 12:47:27 +0200 Received: from [209.85.218.46] (helo=mail-ej1-f46.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.0) (envelope-from ) id 69ce493f-ee98-0a2a450a0019-d155da2edc71-3 for ; Thu, 02 Apr 2026 12:47:27 +0200 Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-b9c280322e0so86796966b.0 for ; Thu, 02 Apr 2026 03:47:27 -0700 (PDT) Received: from EPUAKYIW02F7.. ([45.12.26.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3d028955sm76392366b.61.2026.04.02.03.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 03:47:25 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775126846; x=1775731646; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q0cUh9DunvbioAZLIRhQfJTs0EihHFj+/wkrJJoLmJs=; b=DgsaPB8gZzUseSYFpEQGPQeE1chIRot2lr90k5iTVS6HNsRvjL3FdDv9QcOPCABT/P A1uq2WUW68cKqRyyEpnDc/+DjEbG4e+8Ckbkvt60Xup+8z3aJXEx7pIhTO/PulvORb0M 9bEHd0M4vf8yhjWS/WAfyuhw8JOuZhfSSQfWxX+O8iYaJ63cucfQCkGwnaCorqVfJnro XKEz2jTeXX6KIgAYP8n/agVJpnNx8vREO4etwfGlzvoioHL5GeQ7LAeMqERcZ32dPl2M uiVN5oiWafmVmjIVEsmSZiJhZATbMvVdWF3+M8mT7eKayh9En1uGB2fN6AX/IyotDxQW 0MSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775126846; x=1775731646; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Q0cUh9DunvbioAZLIRhQfJTs0EihHFj+/wkrJJoLmJs=; b=gZytgkB6vKqyY+dzHO/Y3UaM+13tJKlw+dFJNCQWe4CbX+lN/K3foXvpeQ1v0NimgN lDJLqERFzNfYbYX1xuADkMxedSkSoUA7UPPwuX1DGXe6V66HgXcFYRW9mEAnJl+Uvaaj PPE/OJlEmmHDhyhxcJccJQP9EoBRJp68++qQNoOe4ukupiH/xj4i/L2jxANYSmKeYusA lCgqxqfZDv/06LKUjvuX3swEwaGydpc0/JCt3oklcU24MnPUy541RFtsv0garZQfqaIb ihujNOBI4UYDa4GQF13vsd/G1WD2fcCBn8yyr64zldZTxX/pt7f8CSp61j+dHP7rcWav /Jhw== X-Gm-Message-State: AOJu0YzSR2/+zYY8IW1ws+/2d3y6DFr9rR8PE/UJX+h7fjoOpPtDg5Ed 4iLjluHt81Mwyq+cwZq5jsWhoEzgHS/iZEqWNzP+W6eHjKchjm9t7P19EdhUZkwJ X-Gm-Gg: ATEYQzycnmdYyIMhm/MJPwYLF7L3O+oWUJka+LdoaEBitdbYA/okopmmhNwrx5lgvRS h9ZJ5iOE1dUSnTPBAd2IftxPwQfdbv+pPYlBXl5xFFMa6ov9FaqLK+I3WSyNQYSDSiW2bGRKWm2 k1VbNk04LOngCGVLpGG9DyXsU/kp+P9w7wxFZbbb6K7e85F1YcTZ/zhe74v5c4rgxzJsY6KXVxX l9095o1BJELbpFn7mhDC93VWriz3fQ9YY5wZ/s1WKcqMI4NNT9+oV1Nu7jorJltelUl0To31mTv 35VK/XDlqbANtbZrFFyLXP9aPpXObSfY+r0ivWzeWzebKZYL1UYRpRX9eVd8eL2ldawfO3y0b8d crrn4WGwjHF9VP3d8uyOZlNleA61UH4Ix+ESMSKd30VA1lj+gcS+ufhAEGc6ucwQwxXrWqhEg3X T34dyHGRmq96oUkzG0CDdUvPc/K+2wrEOt2hJj X-Received: by 2002:a17:907:724d:b0:b97:98b3:67ce with SMTP id a640c23a62f3a-b9c13b3ccc9mr480119866b.32.1775126845902; Thu, 02 Apr 2026 03:47:25 -0700 (PDT) From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Julien Grall Subject: [PATCH v8 01/13] xen/arm: Add suspend and resume timer helpers Date: Thu, 2 Apr 2026 13:45:02 +0300 Message-ID: <9b5e454f55d20d3e81771da53ae06fb511bd198e.1775125380.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1775126847-0F3490B1-23AF1613/0/0 X-purgate-type: clean X-purgate-size: 5007 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775126885773158500 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic Timer interrupts must be disabled while the system is suspended to prevent spurious wake-ups. Suspending timers in Xen consists of disabling the physical timer and the hypervisor timer on the current CPU. The virtual timer does not need explicit handling here, as it is already disabled on vCPU context switch and its state is restored per-vCPU on the next context restore. Resuming consists of raising TIMER_SOFTIRQ, which prompts the generic timer code to reprogram the hypervisor timer with the correct timeout. Xen does not use or expose the physical timer, so it remains disabled across suspend/resume. Introduce a new helper, disable_phys_hyp_timers(), to encapsulate disabling of the physical and hypervisor timers. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykola Kvach Acked-by: Julien Grall --- Changes in V7: - Dropped EL1/EL2 wording; use "physical timer" and "hypervisor timer" - Renamed helper to disable_phys_hyp_timers() to reflect its actual scope - Clarified virtual timer handling (disabled on vCPU switch-out, restored= on context restore) and added comments in suspend/resume paths - Added resume comment explaining which timers are restored by TIMER_SOFT= IRQ --- xen/arch/arm/include/asm/time.h | 5 ++++ xen/arch/arm/time.c | 44 ++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/include/asm/time.h b/xen/arch/arm/include/asm/tim= e.h index c194dbb9f5..9313b157ea 100644 --- a/xen/arch/arm/include/asm/time.h +++ b/xen/arch/arm/include/asm/time.h @@ -105,6 +105,11 @@ void preinit_xen_time(void); =20 void force_update_vcpu_system_time(struct vcpu *v); =20 +#ifdef CONFIG_SYSTEM_SUSPEND +void time_suspend(void); +void time_resume(void); +#endif /* CONFIG_SYSTEM_SUSPEND */ + #endif /* __ARM_TIME_H__ */ /* * Local variables: diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index a12912a106..f91dc64099 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -296,6 +296,14 @@ static void check_timer_irq_cfg(unsigned int irq, cons= t char *which) static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, irq_hyp); static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, irq_virt); =20 +/* Disable physical and hypervisor timers on the current CPU */ +static inline void disable_phys_hyp_timers(void) +{ + WRITE_SYSREG(0, CNTP_CTL_EL0); /* Physical timer disabled */ + WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */ + isb(); +} + /* Set up the timer interrupt on this CPU */ void init_timer_interrupt(void) { @@ -306,9 +314,7 @@ void init_timer_interrupt(void) WRITE_SYSREG64(0, CNTVOFF_EL2); /* No VM-specific offset */ /* Do not let the VMs program the physical timer, only read the physic= al counter */ WRITE_SYSREG(CNTHCTL_EL2_EL1PCTEN, CNTHCTL_EL2); - WRITE_SYSREG(0, CNTP_CTL_EL0); /* Physical timer disabled */ - WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */ - isb(); + disable_phys_hyp_timers(); =20 hyp_action->name =3D "hyptimer"; hyp_action->handler =3D htimer_interrupt; @@ -333,9 +339,7 @@ void init_timer_interrupt(void) */ static void deinit_timer_interrupt(void) { - WRITE_SYSREG(0, CNTP_CTL_EL0); /* Disable physical timer */ - WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Disable hypervisor's timer */ - isb(); + disable_phys_hyp_timers(); =20 release_irq(timer_irq[TIMER_HYP_PPI], NULL); release_irq(timer_irq[TIMER_VIRT_PPI], NULL); @@ -375,6 +379,34 @@ void domain_set_time_offset(struct domain *d, int64_t = time_offset_seconds) /* XXX update guest visible wallclock time */ } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +void time_suspend(void) +{ + /* CNTV already disabled by virt_timer_save() during vcpu context swit= ch. */ + disable_phys_hyp_timers(); +} + +void time_resume(void) +{ + /* + * Raising TIMER_SOFTIRQ triggers generic timer code to reprogram the + * hypervisor timer with the correct timeout (not known here). + * + * Xen doesn't use or expose the physical timer, so it remains disabled + * across suspend/resume. + * + * The virtual timer state is restored per-vCPU on the next context sw= itch. + * + * No further action is needed to restore timekeeping after power down, + * since the system counter is unaffected. See ARM DDI 0487 L.a, D12.1= .2 + * "The system counter must be implemented in an always-on power domai= n." + */ + raise_softirq(TIMER_SOFTIRQ); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ + static int cpu_time_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) --=20 2.43.0