From nobody Mon Feb 9 21:19:33 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDE343A1E99 for ; Sun, 4 Jan 2026 14:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767535221; cv=none; b=Ep24xm4F5lZ92G2Y1qnE+vdv/WFH/GEhYf2c7hbudWM4xToVaqPA3pi3W3Ga6tzMUJA6QiVvQWR3Johehfeod/1mkXXV885zjMKVAmrqJZmkW8SO0XqTTaWojy7bDUQgHi2fQMpkIIeOP6ZLGIrhCwyE2iSn5CMuJrV3dZ/GkPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767535221; c=relaxed/simple; bh=smLKmAbNA+Lg2DxKtUMzNvxFdylFJ6K1oRlbE5gn/dA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MyIdqgLP4YyQy9iSq6p1QnzxDW2yWfGnkpOD7fXo+GgPNrFNCR3EPDFe3a26QlUw/8lWRusURQNcJFC6iGTxcZfofDK+y+whVcmvb3ouBgBPLkSXad8bIG5gJjedoH95iMqQG3kRa/Hzx0yq0ua2gGRne6PrcIwL3Tvu3CPCKkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hwd2jAOx; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hwd2jAOx" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2a07fac8aa1so143827205ad.1 for ; Sun, 04 Jan 2026 06:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767535219; x=1768140019; darn=vger.kernel.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=qqmQmaFNmFjEy7S54wIHblwNMJ9e6UGwg3T65EY/Hjg=; b=hwd2jAOxW2xI41oyKa1XRrSNjRbA/Y/Vlo5XdM9e0RSYwP3h4R8K50TU1sbNfDOKnu +D+exPSq0RT0Eq2Bn8MOOjvD2icR1kOOaIMQe5b3VgbzJbHyF6WLzJtY1Sj7kSFh3/gl qnf9KdkaX6TqTGCv15TUTS1Zf2U5VQgs5zPMMV6ThS0Ut+JXWHoXSrOGqmu2QC0Vdjdy uHQKned6gexHGgF311kyycSgqSdpRrxlGadAXL5lK6ZOcXefa2Mq2iSdZHYS7Wno17GU CRXVY+4+WeyQnbfAtXzn4ndTxbBL/b/z/3Qt1Aa2HUtjvFXjjo50/H5IMfSphw9F5kNa NYYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767535219; x=1768140019; 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=qqmQmaFNmFjEy7S54wIHblwNMJ9e6UGwg3T65EY/Hjg=; b=JOb3m6OJamvBLv4pmPw3QrB8c65UXj52biFo6xKqfOmsGno9rkc2+Y8GTRTokplEaI yA3A0IzoP5L/3f6ooVMRyUbZNGOO2pYVCCm++c90ZC/W0bLVZTym1xOD4WNJisMXiX1+ hQEWXEFuzwoBZm9rGrPJKX8Y4pLz4U3CuYh1DHm0qRx7ZrkNP1Dr4mI0xsZnRNArCzEw RvWhLmB43EVmeP5KxXKPMhVMte8+rwZorP0JAH9OIG/yo5ka4Q+bqOO0MtHSAHMHNm/V cQOooh299O2tkbTc3Pf1pSsGKL8r1afUW5Lrw71iv8st4nJ2uq2sKQeUu+9IigI5OW3r Cdaw== X-Forwarded-Encrypted: i=1; AJvYcCWv/pNZvOG+A0tYIwAWiNs07xtQEMa2bRxy6JaPDp4N4fwDyfAWDxIUt4t/1xKUp3iK2zwtpbEYTyAs7D8=@vger.kernel.org X-Gm-Message-State: AOJu0YzBWYzl8JyfDtRclfOvceGt7m2lzj9EDHj2I4DFqG857bl129KP jBn1Om9YHG7N/mcl6QGY9np3bR8VIcLUS3PsksNCMlL+EbSxbrEkwz9E X-Gm-Gg: AY/fxX7mWKKqezd68aooKLxWIAUrneM/nqLsIAWgrdMgcbcywcyxlxzNPloNcuxY+F8 NBqpmQPOwGkvCuJTVLR3VPIpFw4eRPCttDBQ1fth1KqDUJqc+aLSoulbtG/uqz+HPygAwp/Vt4+ 2Wz1ZY1zTfaETm/9hwvGnVy7BmllAUbOx4KHbqJAgAXfucGrrOgjiXMdQd+SBWgiSWInjFi08z6 ZCmuyFh9LkutTncA0UtV2un99wgUjpKClxXxqdJQnUbxfOABUBmZ/0wH/SMt4jON4PmalNutkBp v+pbB8xUnEbaKQ2QQRojCgoQoUScOYeB1FzXQdudvB6cfsoKbdJyVstwa9ojofFxMQQIEro1f2V GkauaZA8DmdR6V7FKPspJ2M/DlmusJ3dqTjX/IdT2ouO/rbC77fiRC028sQb9TisHzcBltkN1pe ruXTL3OPyqn+RPQYvx1u5Xdm2llw8sKGCZHwSQTG6S+TZhlO4EVPmgci3TtF++PyUk X-Google-Smtp-Source: AGHT+IFF0zPQhAdEGQIhG511RClUe4pVQFBGTYZnIh7qDrj28ymiDIGxnpivMIor8szJu6tv6fbZ2A== X-Received: by 2002:a17:902:f546:b0:2a0:c84f:412c with SMTP id d9443c01a7336-2a2f2a3be72mr478366475ad.57.1767535219101; Sun, 04 Jan 2026 06:00:19 -0800 (PST) Received: from localhost.localdomain (g163-131-201-140.scn-net.ne.jp. [163.131.201.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d4cb25sm432327535ad.56.2026.01.04.06.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 06:00:18 -0800 (PST) From: Naohiko Shimizu To: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: alex@ghiti.fr, anup@brainfault.org, atish.patra@linux.dev, daniel.lezcano@linaro.org, tglx@linutronix.de, nick.hu@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Naohiko Shimizu Subject: [PATCH v3 3/3] riscv: suspend: Fix stimecmp update hazard on RV32 Date: Sun, 4 Jan 2026 22:59:38 +0900 Message-Id: <20260104135938.524-4-naohiko.shimizu@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260104135938.524-1-naohiko.shimizu@gmail.com> References: <20260104135938.524-1-naohiko.shimizu@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On RV32, updating the 64-bit stimecmp (or vstimecmp) CSR requires two separate 32-bit writes. A race condition exists if the timer triggers during these two writes. The RISC-V Privileged Specification (e.g., Section 3.2.1 for mtimecmp) recommends a specific 3-step sequence to avoid spurious interrupts when updating 64-bit comparison registers on 32-bit systems: 1. Set the low-order bits (stimecmp) to all ones (ULONG_MAX). 2. Set the high-order bits (stimecmph) to the desired value. 3. Set the low-order bits (stimecmp) to the desired value. Current implementation writes the LSB first without ensuring a future value, which may lead to a transient state where the 64-bit comparison is incorrectly evaluated as "expired" by the hardware. This results in spurious timer interrupts. This patch adopts the spec-recommended 3-step sequence to ensure the intermediate 64-bit state is never smaller than the current time. Fixes: ffef54ad4110 ("riscv: Add stimecmp save and restore") Signed-off-by: Naohiko Shimizu Reviewed-by: Anup Patel --- arch/riscv/kernel/suspend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index 24b3f57d467f..aff93090c4ef 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -51,10 +51,11 @@ void suspend_restore_csrs(struct suspend_context *conte= xt) =20 #ifdef CONFIG_MMU if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { - csr_write(CSR_STIMECMP, context->stimecmp); #if __riscv_xlen < 64 + csr_write(CSR_STIMECMP, ULONG_MAX); csr_write(CSR_STIMECMPH, context->stimecmph); #endif + csr_write(CSR_STIMECMP, context->stimecmp); } =20 csr_write(CSR_SATP, context->satp); --=20 2.39.5