From nobody Sun Sep 28 17:12:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1757584755; cv=none; d=zohomail.com; s=zohoarc; b=eGtsrr/12kFODCQ4nDpX4Cs0kZ4Fba3JxxdtFcD1XNYDbvvKWoFJhaqXfx/F2VYLPDdzsK+pmp/rdg//NFwtocTSq19hrws1UNRE65IrbE5LwVVDi1ceSvzrOvgF4bQ6dM0CTaL8Pie9Ou0y3zC03Syg0m1WwlZ8Wjs92OQceEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757584755; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CgPzvRW3PYzQdn11ycTE+/tC0brKHXf/hxY7dZiqdA0=; b=HBnGSkdoNpoI5/7G9bb2Kmmuu5dhSVe7T2cABC+eEiDQTeG+Xguk4IXd4pLgp3IifCccJF/vLkjJjhBjsHdrlv/WZNHQ8zx1GE9NpX22a+2AePBjykMipwruJ7ZIpG0ZKcC9ABr0X3prtwQjU3uRmcCzIhEaGuSejuU6FqbGyFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175758475584057.24581425987196; Thu, 11 Sep 2025 02:59:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwe32-0001ha-6O; Thu, 11 Sep 2025 05:57:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwe2y-0001fZ-8I; Thu, 11 Sep 2025 05:56:56 -0400 Received: from [115.124.30.113] (helo=out30-113.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwe2l-0005Oz-4Q; Thu, 11 Sep 2025 05:56:54 -0400 Received: from ea134-sw06.eng.xrvm.cn(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0Wnlj.Kl_1757584578 cluster:ay36) by smtp.aliyun-inc.com; Thu, 11 Sep 2025 17:56:18 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1757584579; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=CgPzvRW3PYzQdn11ycTE+/tC0brKHXf/hxY7dZiqdA0=; b=XGBEyuwff66vK3txMViFTYpzQguPI0OHyxy8eslHSbATRiM9flvdU15v47mtkxzFEQtiKrQJForWVh3BqkH6Jf4TdgLk7o8shK/ceTgwmO1TSns21GANtq8G0Rfe5AHQlBaHb34Ui6gDOHXJxgAofBqO7Ntosud5YrHxeauldS4= From: TANG Tiancheng Date: Thu, 11 Sep 2025 17:56:15 +0800 Subject: [PATCH v3 3/4] hw/intc: Save timers array in RISC-V mtimer VMState MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250911-timers-v3-3-60508f640050@linux.alibaba.com> References: <20250911-timers-v3-0-60508f640050@linux.alibaba.com> In-Reply-To: <20250911-timers-v3-0-60508f640050@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-riscv@nongnu.org, Peter Xu , Fabiano Rosas , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1757584576; l=2900; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=YkJJfhz9vbR/O68Q0eP/tZoK/MlSnuQnZJEPg8ettsM=; b=zX8pSu4q98Mxg1Cx/NhE9Xy5ssHS2EgrSBbWvAsguzNZFRtKURz6cnysq8xsiUApmSzJ6uz61 7zPl1UxfB97B8WZir890h1DqTa5eTfph8AnTXz6r8UviLLHhiV3oAXx X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.113 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=115.124.30.113; envelope-from=lyndra@linux.alibaba.com; helo=out30-113.freemail.mail.aliyun.com X-Spam_score_int: -86 X-Spam_score: -8.7 X-Spam_bar: -------- X-Spam_report: (-8.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1757584758441116600 The current 'timecmp' field in vmstate_riscv_mtimer is insufficient to keep timers functional after migration. If an mtimer's entry in 'mtimer->timers' is active at the time the snapshot is taken, it means riscv_aclint_mtimer_write_timecmp() has written to 'mtimecmp' and scheduled a timer into QEMU's main loop 'timer_list'. During snapshot save, these active timers must also be migrated; otherwise, after snapshot load there is no mechanism to restore 'mtimer->timers' back into the 'timer_list', and any pending timer events would be lost. QEMU's migration framework commonly uses VMSTATE_TIMER_xxx macros to save and restore 'QEMUTimer' variables. However, 'timers' is a pointer array with variable length, and vmstate.h did not previously provide a helper macro for such type. This commit adds a new macro, 'VMSTATE_TIMER_PTR_VARRAY', to handle saving and restoring a variable-length array of 'QEMUTimer *'. We then use this macro to migrate the 'mtimer->timers' array, ensuring that timer events remain scheduled correctly after snapshot load. Reviewed-by: LIU Zhiwei Signed-off-by: TANG Tiancheng Reviewed-by: Alistair Francis --- hw/intc/riscv_aclint.c | 6 ++++-- include/hw/intc/riscv_aclint.h | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c index 318a9c8248432a8cd4c3f3fa990739917ecf7ca1..9f4c36e965e2aa379d75c0a9f65= 6177f0dd82a45 100644 --- a/hw/intc/riscv_aclint.c +++ b/hw/intc/riscv_aclint.c @@ -323,13 +323,15 @@ static void riscv_aclint_mtimer_reset_enter(Object *o= bj, ResetType type) =20 static const VMStateDescription vmstate_riscv_mtimer =3D { .name =3D "riscv_mtimer", - .version_id =3D 2, - .minimum_version_id =3D 2, + .version_id =3D 3, + .minimum_version_id =3D 3, .fields =3D (const VMStateField[]) { VMSTATE_UINT64(time_delta, RISCVAclintMTimerState), VMSTATE_VARRAY_UINT32(timecmp, RISCVAclintMTimerState, num_harts, 0, vmstate_info_uint64, uint64_t), + VMSTATE_TIMER_PTR_VARRAY(timers, RISCVAclintMTimerState, + num_harts), VMSTATE_END_OF_LIST() } }; diff --git a/include/hw/intc/riscv_aclint.h b/include/hw/intc/riscv_aclint.h index 693415eb6defe4454e5731a681e025f3bac3ad2e..4b7406eec005a06b7c040d8483a= 8790866a39297 100644 --- a/include/hw/intc/riscv_aclint.h +++ b/include/hw/intc/riscv_aclint.h @@ -80,4 +80,8 @@ enum { RISCV_ACLINT_SWI_SIZE =3D 0x4000 }; =20 +#define VMSTATE_TIMER_PTR_VARRAY(_f, _s, _f_n) \ +VMSTATE_VARRAY_OF_POINTER_UINT32(_f, _s, _f_n, 0, vmstate_info_timer, \ + QEMUTimer *) + #endif --=20 2.43.0