From nobody Wed Apr 8 01:19:28 2026 Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A648FB652 for ; Wed, 11 Mar 2026 02:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.204.34.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773197621; cv=none; b=vEe5MZZROb0bL8qVHqdlv0Mwlfy9cmK0ZrSbWrTboIbMK14dXUwSxzRHjIqdAXe6fQsicdevV7WmYUbWTVuOudktJt8fq1okL5OUZC1vXx0NOmbFyE8f9y6pG945ZiBqkOcxXrRgCSYKiSKcfvI+nxI7dVK99JYkOcy45sgVQNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773197621; c=relaxed/simple; bh=gy7SA+8vj/QLWMAenN3Vxk5AfAdTFQ8XwfDJ5fmJE3U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=L9Ovtye73JEJnhyT4oq2hp2wRDW3tf5OG6nJKfxONrV3NtGiClfJdiCDUHa/hWjo/L1lOLgdeVOj/cjc2xYq0Rm4Kl9Da3YyNEEOEHJ2GhypdRGuhIIM0I4NI0CLHlmJWfkuBOjXaD77rr8ZBRjbMaF4DUE++FCg8bU727WD3fI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=none smtp.mailfrom=linux.spacemit.com; arc=none smtp.client-ip=54.204.34.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.spacemit.com X-QQ-mid: zesmtpsz3t1773197520t47c586fc X-QQ-Originating-IP: sdF9k/qqbfx5xHwfrMQdZ7mOpjfe5m/MCdhh9M9/keE= Received: from = ( [120.237.158.181]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 11 Mar 2026 10:51:58 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3368258366227887137 X-QQ-CSender: troy.mitchell@linux.spacemit.com Sender: troy.mitchell@linux.spacemit.com From: Troy Mitchell Date: Wed, 11 Mar 2026 10:51:55 +0800 Subject: [PATCH RFC] riscv: disable local interrupts and stop other CPUs before restart Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-v7-0-rc1-rv-dis-int-before-restart-v1-1-bc46b4351cac@linux.dev> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x3NQQrCMBBG4auUWftDkraKbgUP4FZcJO1UZ5PKT AhC6d0NLr/NexsZq7DRpdtIuYrJmhv8oaPpHfOLIXMzBReOrvce9QQHnTy0YhaD5ILEy6oMZSt RC8bU8xjikAZ/phb6KC/y/U8edL9d6bnvP8hZ5w55AAAA X-Change-ID: 20260311-v7-0-rc1-rv-dis-int-before-restart-5b3e52a4b419 To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Troy Mitchell X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773197518; l=2848; i=troy.mitchell@linux.dev; s=20250710; h=from:subject:message-id; bh=gy7SA+8vj/QLWMAenN3Vxk5AfAdTFQ8XwfDJ5fmJE3U=; b=kHDZeMGQFMACmKsjUfZeMNJAuhwEWGczNZs3+BSngFXZ8rHoZKCrSzIgDCtM//OLMTYX0+vPn CRFG/dk8lBkAZGhb8SCUk8HR+oDpeJzHOV7O7hauAPASx9nkXIbqPNW X-Developer-Key: i=troy.mitchell@linux.dev; a=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EycxTfr4b/MRhipWxyG0ApmlySDlYW/16l4t5GIFQ8De TkzUlR+zyrxZQYaBO5TPuIaiApU4m8Key8V1vEuyA78Y0eHaQzy/FlUx5ceMnyMNR34la+T 0vJ2l25Bdm034zawaOyfthgpbA7H0v3K0JmX8+c1+m43stwcZXkHnvFcCTQM0waQHnO7RtI ybq7bOBP1ClD4GW6YkrgqmivyWRhT98CS9pkXVhuEG4eGYjc5fl84Th95LKnJ9y3XY3Ta0N a+vP X-QQ-XMRINFO: Mp0Kj//9VHAxzExpfF+O8yhSrljjwrznVg== X-QQ-RECHKSPAM: 0 Currently, the RISC-V implementation of machine_restart() directly calls do_kernel_restart() without disabling local interrupts or stopping other CPUs. This missing architectural setup causes fatal issues for systems that rely on external peripherals (e.g., I2C PMICs) to execute the system restart when CONFIG_PREEMPT_RCU is enabled. When a restart handler relies on the I2C subsystem, the I2C core checks i2c_in_atomic_xfer_mode() to decide whether to use the sleepable xfer or the polling atomic_xfer. This check evaluates to true if (!preemptible() || irqs_disabled()). During do_kernel_restart(), the restart handlers are invoked via atomic_notifier_call_chain(), which holds an RCU read lock. The behavior diverges based on the preemption model: 1. Under CONFIG_PREEMPT_VOLUNTARY or CONFIG_PREEMPT_NONE, rcu_read_lock() implicitly disables preemption. preemptible() evaluates to false, and the I2C core correctly routes to the atomic, polling transfer path. 2. Under CONFIG_PREEMPT_RCU, rcu_read_lock() does NOT disable preemption. Since machine_restart() left local interrupts enabled, irqs_disabled() is false, and preempt_count is 0. Consequently, preemptible() evaluates to true. As a result, the I2C core falsely assumes a sleepable context and routes the transfer to the standard master_xfer path. This inevitably triggers a schedule() call while holding the RCU read lock, resulting in a fatal splat: "Voluntary context switch within RCU read-side critical section!" and a system hang. Align RISC-V with other major architectures (e.g., ARM64) by adding local_irq_disable() and smp_send_stop() to machine_restart(). - local_irq_disable() guarantees a strict atomic context, forcing sub- systems like I2C to always fall back to polling mode. - smp_send_stop() ensures exclusive hardware access by quiescing other CPUs, preventing them from holding bus locks (e.g., I2C spinlocks) during the final restart phase. Signed-off-by: Troy Mitchell Reviewed-by: Aurelien Jarno Tested-by: Aurelien Jarno --- arch/riscv/kernel/reset.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c index 912288572226..7a5dcfdc3674 100644 --- a/arch/riscv/kernel/reset.c +++ b/arch/riscv/kernel/reset.c @@ -5,6 +5,7 @@ =20 #include #include +#include =20 static void default_power_off(void) { @@ -17,6 +18,10 @@ EXPORT_SYMBOL(pm_power_off); =20 void machine_restart(char *cmd) { + /* Disable interrupts first */ + local_irq_disable(); + smp_send_stop(); + do_kernel_restart(cmd); while (1); } --- base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f change-id: 20260311-v7-0-rc1-rv-dis-int-before-restart-5b3e52a4b419 Best regards, --=20 Troy Mitchell