From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 867611F09A3 for ; Sat, 3 Jan 2026 09:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767433569; cv=none; b=JbmgOdZvot3wKXrF6Mqcig1u77b9Rry6Z1L23LhdEjOdDpnqYH7QfC3ahIPVu0ERYveLU/mpDY0tIZ5dm61iiXXDNwQL0fTFm6q736lhjkh0LH7kJCoDvbPHje2AwAooDYIrb0egEBaayjuBGazLmT6AXrBuQkQ0ynlcsIbLMz4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767433569; c=relaxed/simple; bh=efwmUAMzmS/UvUUv5mWngiAZpwOYPN2n8W0XJebLrtw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=E0RexfgaWPJ8ji7pper6ProYE5ms4MUNbzpJF00UgdccyhbzY8h3sg+JBkhWkBiCgaKd3YQXSOQijtTfLx9/YTuC7oA/hjOseJQcIevvjXcAXgCo6B7TftubTf6dPicwjYp+ISpls3qd0rF7l71ShP0/WP0h/5++s4FZctEiSKI= 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=gRUOXpep; arc=none smtp.client-ip=209.85.214.175 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="gRUOXpep" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2a09757004cso161265815ad.3 for ; Sat, 03 Jan 2026 01:46:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767433568; x=1768038368; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JD0n/Fm55UFJQkbcsKqmkl3SnWwAZypi4Xu05/Efcno=; b=gRUOXpeprNWIdHsPrwTPycXZbhvZkIbq0atNY92FRzihdp2c2n549eK5oGSvPjHUVO ZWVpEZ7K/K8AG/FpB2Wi17H+lbAVGzdpbk0x4sjSI2BPiJ95UrEoF+MI/THJbQIxSkL0 ZgHspwYOmvbd+CkmGCUrt/bqRuGa/FdNUOsDbWLxmItOVYWmjCkCCJCLPgpAz4VMo986 xBT1bi2Dfi6PPEjqGiE9H3jRbW8Dn5Rjp2JYgQo9AdE83/DuMfPBty9+gDjHwwB+IMN5 nZClo1UB9WcBcEECYCclJ6tdDPKbPlwUFWQ1qMuGbjGFnEvo3InkonOZeUyZOhs66yfE 3lVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767433568; x=1768038368; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JD0n/Fm55UFJQkbcsKqmkl3SnWwAZypi4Xu05/Efcno=; b=wt4RV/zNiYQiOGW29X1j4S4WWOWaelcCJKWh7uAtHfUTN1AvaYNtJJezyDFb7MybLh AahDrqPx8/+lHlJpJR+F0Hs2msBvClb4sG/CEIrHUVTdSt/F1M83TWqHcuzAxqDnkZqh 9JlGqRdGL5viw7KDds0IGybIeHGr5ZVGJvnWxV0A7k0ktjjOT/z0VABILqcwHLnbMPRc /ZT+sz/eq7HYbebzLiuCuGZhiEwYaBM8Ud1tKw5GNdt5fj3bgfyBjAzecNoS2Qm/uNt8 QLThWNMytwCniNohGoxc43k++4feM4FFEtnX9I5VbCQ2TERB/k9eTRkv6HpN6XyH007r 2Tag== X-Forwarded-Encrypted: i=1; AJvYcCXQE3LvhDccMFtWOG9PqyyN/GpzPxkiiDn9kzQu0BJj11MGpMoF0rx219WwzYSLOSt/Qy6pS8xsoZBsIUo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0aQ9y0GJVaEKvE85BYcS1vPh3P1fP87whLuXYeeIqEyH+jjTZ 2UpieosAMD/KgvokM0s88OSUj2IfCaffgO3KIJ9g9/ec+Q7hvm1PNeLY X-Gm-Gg: AY/fxX571ub17yGFEsVS3XHBpmxcB87iCYaqw2uYr5tlNBdfikdsd9W/LTOgp7OsVKL mfxKsw7HvRRHGzuln6Ps6dWlLdDrES/EPLcQu4PVcAJwl27Gzca5SOapCeu7Sth1En4yn1L7NCD Xq2GPXUWGEJDp2ETa4SdCFyPHYKZIBxAarvy/g0Mh1nnyOgmEdv0rY4Nw9ESnoidCIepX4mXNGt sipYEnILQpDmQgRNxHfWrxCproL6XIaaLuaXDUnRT5fa16RoLQHFEPXxCM9Nbbrw1Hqpsuzr2YX 4wuQ8B3OcQGiQjPJYep7rUn+Ut23gbyIel+WR9s6H622HS92IRnT/PweFYc62JJZr4M3rDFyfvU cSSw78YVjfafoK93CZwiwBoQ1kHUU6N5p0d0XKegO7JJ4qF3hNLaS+I1fMr/0hHyZV7zHcnP6sm uibxux44HrpexyuTldiYioLYwCx54tg9nInjauN+4NctR3DgtfXuWNATb04xIXtl6l X-Google-Smtp-Source: AGHT+IFNLzKaiu1Bm8BObCDrR25tQvlAZc+Fjmboe3LwUIgq+AoeE4YcWvhwHDPuA8YxLt19m+hacA== X-Received: by 2002:a17:903:244f:b0:2a1:3ade:c351 with SMTP id d9443c01a7336-2a2f222bd48mr502840155ad.2.1767433567709; Sat, 03 Jan 2026 01:46:07 -0800 (PST) Received: from localhost.localdomain (123-48-16-240.area55c.commufa.jp. [123.48.16.240]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d4cbdasm403124315ad.65.2026.01.03.01.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jan 2026 01:46:07 -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 0/3] riscv: Fix potential spurious timer interrupts on RV32 Date: Sat, 3 Jan 2026 18:44:58 +0900 Message-Id: <20260103094501.5625-1-naohiko.shimizu@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch series addresses a potential race condition when updating 64-bit timer comparison registers (stimecmp/vstimecmp) on RV32 systems. According to the RISC-V Privileged Specification (specifically section 3.2.1 for mtimecmp, which applies logically to stimcmp as well), updating a 64-bit comparison register via two 32-bit writes can cause a spurious interrupt if the intermediate state is evaluated by the hardware. Currently, the Linux kernel (including v6.12) often writes the LSB first or does not use the recommended 3-step sequence (setting LSB to 0xFFFFFFFF first) on RV32. This can lead to a transient state where Time >= Compare is incorrectly true, triggering a "ghost" pending interrupt. Changes: 1. Fix suspend_restore_csrs to use the 3-step sequence for stimecmp. 2. Fix KVM vcpu timer updates to prevent vstimecmp hazards. 3. Fix riscv_clock_next_event in the clocksource driver. Although this hazard is difficult to observe in QEMU due to its instruction-boundary interrupt polling, it is a critical correctness issue for physical RV32 hardware implementations with asynchronous comparators. Signed-off-by: Naohiko Shimizu Naohiko Shimizu (3): riscv: clocksource: Fix stimecmp update hazard on RV32 riscv: kvm: Fix vstimecmp update hazard on RV32 riscv: suspend: Fix stimecmp update hazard on RV32 arch/riscv/kernel/suspend.c | 3 ++- arch/riscv/kvm/vcpu_timer.c | 6 ++++-- drivers/clocksource/timer-riscv.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) -- 2.39.5