From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74406606A31C for ; Tue, 17 Nov 2026 05:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=o7fpwK+n; dkim=fail reason="signature verification failed" (2048-bit key) header.d=aurel32.net header.i=@aurel32.net header.a=rsa-sha256 header.s=202004.hall header.b=t4oNpCg/ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=I/SdlJEY3id4jMbhbJHkE868ROPJLrw48j7yY2Tujok=; b=o7fpwK+n5d7kgZb+USfe5sZsfF 6Gr0X4G13AMndGFtQxvIVYbM69oaVqoji9gwZG6f+bAL9aWKKyle1Z0njmqqi11Qo3oJMNx68KJ1v vftfZAD6LrC7RgsXy8vY0E+sTCO4QTgP1kSDnotVvIdvOM19bVI2NfLeKwkFnQbLr6SPJYa2OaETq 1yOiqzzk3YWuEu4qf2FRir5gIPcnExEWsF8Ar0XQZFCXFnpjuQvBpKJ4O6d7zWgZqyRKgAnah5sQJ VapTtEdAK6h8zCsIvbqAYufd3oGlqOA7Kxa/WalGhsnGitt4h5O9jvrrVd5iyTRsBYFqH2tP+z6wz PPfGpBJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTBph-00000004bwd-33uZ; Tue, 17 Nov 2026 05:34:17 +0000 Received: from hall.aurel32.net ([2001:bc8:30d7:100::1]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTBpe-00000004bw9-3Odw for linux-riscv@lists.infradead.org; Tue, 17 Nov 2026 05:34:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Content-Transfer-Encoding:From:Reply-To: Subject:Content-ID:Content-Description:X-Debbugs-Cc; bh=uv0Ajg/ZOj9nmloBlqc5KvujqzinojKoKdNon67mJq8=; b=t4oNpCg/JzIcewr8iMyCEB9uvi XGHUBmQTtxLRh//FgdVeDyVTrvME8RoKx9VfvZF+mAhD6XaxooBF5HYvQfPSxTHzECKUCnrprzbS4 diWHSaaPoU8mBzBUhKznCEIM1j5j2HPOvK+PfkEBn33c4JNmrVP070WSHpo72X3hFNa5dzkrOOC3h eq6uXsEXc+UIi0AuBn9QvpSmy4v0G80+EJoU1XSVwxkDqIAv9vYIxT9JhvTV6mNQl4ZYKylDXlyxH jdBKYTH4meTdq1WYPQTCMI8TDIc34WB9ctzotxxawmtORvDzVgAIZ09P5Y/wYkto6FVYNVAa73iT1 87qYJCkg==; Received: from authenticated user by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBpP-0000000Fa7M-0bSc; Tue, 17 Nov 2026 06:33:59 +0100 Date: Tue, 17 Nov 2026 06:33:58 +0100 From: Aurelien Jarno To: Anand Moon Cc: Sebastian Reichel , Troy Mitchell , Andi Shyti , Yixun Lan , "open list:I2C SUBSYSTEM HOST DRIVERS" , open list , "open list:SYSTEM RESET/SHUTDOWN DRIVERS" , "open list:RISC-V SPACEMIT SoC Support" , "open list:RISC-V SPACEMIT SoC Support" Subject: Re: [PATCH v1 2/2] power: reset: spacemit-p1: Use atomic I2C transfers for power-off and restart Message-ID: Mail-Followup-To: Anand Moon , Sebastian Reichel , Troy Mitchell , Andi Shyti , Yixun Lan , "open list:I2C SUBSYSTEM HOST DRIVERS" , open list , "open list:SYSTEM RESET/SHUTDOWN DRIVERS" , "open list:RISC-V SPACEMIT SoC Support" , "open list:RISC-V SPACEMIT SoC Support" References: <20261110061429.2036-1-linux.amoon@gmail.com> <20261110061429.2036-2-linux.amoon@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.4.1 (2026-07-04) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261116_213414_996010_B67FA594 X-CRM114-Status: GOOD ( 39.24 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-15.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Anand, On 2026-11-16 13:06, Anand Moon wrote: > Hi All, > > On Mon, 16 Nov 2026 at 11:33, Sebastian Reichel > wrote: > > > > Hi, > > > > On Tue, Nov 10, 2026 at 11:44:27AM +0530, Anand Moon wrote: > > > The SpacemiT P1 power-off and restart handlers use regmap_set_bits() > > > to access the PMIC. However, these handlers run in an atomic notifier > > > context (specifically within an rcu_read_lock() critical section), while > > > the I2C-backed regmap uses a sleepable mutex. > > > > > > This triggers a "WARNING: suspicious RCU usage" warning due to an illegal > > > context switch in the RCU read-side critical section during shutdown on the > > > Banana Pi BPI-F3: > > > > > > [ 563.803475] WARNING: suspicious RCU usage > > > [ 563.807813] 7.3.1-ARCH-RISC-V #1 Not tainted > > > [ 563.816614] ./include/linux/rcupdate.h:387 Illegal context switch in RCU read-side critical section! > > > ... > > > [ 563.841445] locks held by shutdown/1: 2, last CPU#0: > > > [ 563.846694] #0: ffffffff8404fb20 (system_transition_mutex){+.+.}-{4:4}, at: __do_sys_reboot+0x230/0x29e > > > [ 563.856806] #1: ffffffff84167860 (rcu_read_lock){....}-{1:3}, at: atomic_notifier_call_chain+0x4a/0x1c2 > > > > > > Replace the regmap operations with atomic I2C transfers to avoid sleeping > > > in an atomic context. Preserve unrelated register bits through > > > read-modify-write operations and check for atomic I2C support before > > > registering the handlers. > > > > > > Obtain the I2C client from the parent device and verify that the adapter > > > supports atomic transfers before registering the handlers. > > > > > > Tested on the Banana Pi BPI-F3 (SpacemiT K1). > > > > > > Assisted-by: LLM > > > Cc: Troy Mitchell > > > Cc: Aurelien Jarno > > > Fixes: 28124cc0fb8c ("driver: reset: spacemit-p1: add driver for poweroff/reboot") > > > Signed-off-by: Anand Moon > > > --- > > > > regmap runs i2c_transfer itself and thus also uses the atomic I2C > > transfers. The problem here is regmap itself. But instead of moving > > away from regmap, the atomic use case should be supported properly > > in regmap. > > > > On RISC-V platform, poweroff and reboot are already handled by OpenSBI > through the SBI System Reset (SRST) extension. Linux delegates these > operations to firmware using SBI_SRST_RESET_TYPE_SHUTDOWN for poweroff > and SBI_SRST_RESET_TYPE_COLD_REBOOT or SBI_SRST_RESET_TYPE_WARM_REBOOT > for reboot, depending on the supported reset type. > > Therefore, there is no need for an additional Linux PMIC poweroff/reboot handler > on this platform, as it duplicates functionality already provided by firmware. > > While supporting atomic operations in regmap may be useful more generally, > it is not necessary to address this platform's shutdown and reboot requirements. > > I tested this on the SpacemiT K1 Banana Pi BPI-F3 after removing this PMIC > poweroff/reboot driver. > > OpenSBI commit which handles this extension > > d9637d00bf47 ("lib: utils/reset: add SpacemiT P1 PMIC support") > b10e18ec854a ("lib: utils/i2c: add minimal SpacemiT I2C driver") > > Similarly, on the StarFive VisionFive 2, poweroff is handled by > OpenSBI through the > AXP15060 PMIC, so there is no need to register an additional poweroff > handler using > devm_register_power_off_handler(). > > OpenSBI commit which handles this extension > > 568ea49490d9 ("platform: starfive: add PMIC power ops in JH7110 > visionfive2 board") > > -----8<----------8<----------8<------ > diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c > index 50df66de24e06..069259f7d7c15 100644 > --- a/drivers/mfd/axp20x.c > +++ b/drivers/mfd/axp20x.c > @@ -1458,8 +1458,14 @@ int axp20x_device_probe(struct axp20x_dev *axp20x) > return ret; > } > > - if (axp20x->variant != AXP288_ID) > - devm_register_power_off_handler(axp20x->dev, > axp20x_power_off, axp20x); > + /* > + * The VisionFive 2 handles AXP15060 poweroff through OpenSBI. > + * Avoid accessing the I2C PMIC from the atomic poweroff path. > + */ > + if (axp20x->variant != AXP288_ID && !(axp20x->variant == AXP15060_ID && > + of_machine_is_compatible("starfive,jh7110"))) > + devm_register_power_off_handler(axp20x->dev, > + axp20x_power_off, axp20x); > > dev_info(axp20x->dev, "AXP20X driver loaded\n"); > > Please let me know if this works on your board? Yes, that works, but I don't think this is the correct solution to disable here. Also this won't scale for future boards which might use a different existing PMIC driver with poweroff support and that will also need to be patched. As pointed out by Troy in an earlier mail, the real problem is the priority at which the handler is registers, 192 for the reset and -256 for the poweroff one. I wonder if the SBI SRST extension should also register the poweroff one at 192. It seems it's about replacing the call to register_platform_power_off() by register_sys_off_handler(), which supports using a priority value. And maybe SYS_OFF_PRIO_FIRMWARE = 224 should be used there instead of 192. Regards Aurelien -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://aurel32.net _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv