From: Aurelien Jarno <aurelien@aurel32.net>
To: Anand Moon <linux.amoon@gmail.com>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>,
Troy Mitchell <troy.mitchell@linux.spacemit.com>,
Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@kernel.org>,
"open list:I2C SUBSYSTEM HOST DRIVERS"
<linux-i2c@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:SYSTEM RESET/SHUTDOWN DRIVERS"
<linux-pm@vger.kernel.org>,
"open list:RISC-V SPACEMIT SoC Support"
<linux-riscv@lists.infradead.org>,
"open list:RISC-V SPACEMIT SoC Support"
<spacemit@lists.linux.dev>
Subject: Re: [PATCH v1 2/2] power: reset: spacemit-p1: Use atomic I2C transfers for power-off and restart
Date: Tue, 17 Nov 2026 23:26:22 +0100 [thread overview]
Message-ID: <avzUjsZzhky4krEV@aurel32.net> (raw)
In-Reply-To: <CANAwSgSXP1bZVVrX71jfgi1iR9AY4TpM0pk07ke+oeLvcX1fEQ@mail.gmail.com>
Hi Anand,
On 2026-11-17 18:04, Anand Moon wrote:
> Hi Aurelien,
>
> On Tue, 17 Nov 2026 at 11:04, Aurelien Jarno <aurelien@aurel32.net> wrote:
> >
> > Hi Anand,
> >
> > On 2026-11-16 13:06, Anand Moon wrote:
> > > Hi All,
> > >
> > > On Mon, 16 Nov 2026 at 11:33, Sebastian Reichel
> > > <sebastian.reichel@collabora.com> 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 <troy.mitchell@linux.spacemit.com>
> > > > > Cc: Aurelien Jarno <aurelien@aurel32.net>
> > > > > Fixes: 28124cc0fb8c ("driver: reset: spacemit-p1: add driver for poweroff/reboot")
> > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> > > > > ---
> > > >
> > > > 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.
> >
> No changes needed over here, reboot and power-off priority will
> work fine.
> > 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.
> >
> Thanks for your input; with the changes below.
> It works fine on Spacemit k1 and Starfive Vision 2 for reboot and power-off.
>
> arch/riscv/kernel/sbi.c | 51 +++++++++++++++++++++++++++++++----------
> 1 file changed, 39 insertions(+), 12 deletions(-)
Thanks for this patch. It sounds good overall, and it's always good to
switch to the newest API.
I have been able to test it successfully on VisionFive 2 and Banana-Pi
F3. Please find a few comments below.
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index af1ccea222f1..32a3d2df9032 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -512,23 +512,55 @@ static void sbi_srst_reset(unsigned long type,
> unsigned long reason)
> __func__, type, reason);
> }
>
> -static int sbi_srst_reboot(struct notifier_block *this,
> - unsigned long mode, void *cmd)
> +static int sbi_srst_reboot(struct sys_off_data *data)
> {
> - sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
> + sbi_srst_reset((reboot_mode == REBOOT_WARM ||
> + reboot_mode == REBOOT_SOFT) ?
> SBI_SRST_RESET_TYPE_WARM_REBOOT :
> SBI_SRST_RESET_TYPE_COLD_REBOOT,
> SBI_SRST_RESET_REASON_NONE);
> +
> return NOTIFY_DONE;
> }
>
> -static struct notifier_block sbi_srst_reboot_nb;
> -
> -static void sbi_srst_power_off(void)
> +static int sbi_srst_power_off(struct sys_off_data *data)
> {
> sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN,
> SBI_SRST_RESET_REASON_NONE);
> +
> + return NOTIFY_DONE;
> +}
> +
> +static bool srst_power_off;
> +static bool sbi_srst_available;
Not sure we want global variables for this, as they are not used anymore
once the initialisation is done.
> +
> +static int __init sbi_srst_sys_off_init(void)
> +{
> + struct sys_off_handler *handler;
> +
> + if (!sbi_srst_available)
> + return 0;
> +
> + handler = register_sys_off_handler(SYS_OFF_MODE_RESTART,
> + SYS_OFF_PRIO_HIGH,
I think you should use SYS_OFF_PRIO_FIRMWARE for both entry. It
corresponds to the reboot provider.
> + sbi_srst_reboot, NULL);
> + if (IS_ERR(handler))
> + pr_warn("Failed to register SBI SRST restart handler: %ld\n",
> + PTR_ERR(handler));
> +
> + handler = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
> + SYS_OFF_PRIO_FIRMWARE,
> + sbi_srst_power_off, NULL);
> + if (IS_ERR(handler)) {
> + pr_warn("Failed to register SBI SRST poweroff handler: %ld\n",
> + PTR_ERR(handler));
> + } else {
> + srst_power_off = true;
> + }
> +
> + return 0;
> }
> +device_initcall(sbi_srst_sys_off_init);
Any reason to use a device_initcall as opposed to just calling the
fuunction from the sbi_init function below? If so, please provide the
reason in the commit message when submitting the final patch.
> /**
> * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
> @@ -643,7 +675,6 @@ int sbi_debug_console_read(char *bytes, unsigned
> int num_bytes)
>
> void __init sbi_init(void)
> {
> - bool srst_power_off = false;
> int ret;
>
> ret = sbi_get_spec_version();
> @@ -677,11 +708,7 @@ void __init sbi_init(void)
> if (sbi_spec_version >= sbi_mk_version(0, 3) &&
> sbi_probe_extension(SBI_EXT_SRST)) {
> pr_info("SBI SRST extension detected\n");
> - register_platform_power_off(sbi_srst_power_off);
> - srst_power_off = true;
> - sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
> - sbi_srst_reboot_nb.priority = 192;
> - register_restart_handler(&sbi_srst_reboot_nb);
> + sbi_srst_available = true;
> }
> if (sbi_spec_version >= sbi_mk_version(2, 0) &&
> sbi_probe_extension(SBI_EXT_DBCN) > 0) {
Regards
Aurelien
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
next prev parent reply other threads:[~2026-11-17 22:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 6:14 [PATCH v1 1/2] i2c: spacemit: Avoid sleeping during bus reset in atomic context Anand Moon
2026-11-10 6:14 ` [PATCH v1 2/2] power: reset: spacemit-p1: Use atomic I2C transfers for power-off and restart Anand Moon
2026-11-10 21:25 ` Aurelien Jarno
2026-11-11 1:16 ` Troy Mitchell
2026-11-11 9:29 ` Aurelien Jarno
2026-11-11 11:05 ` Anand Moon
2026-11-16 0:30 ` Sebastian Reichel
2026-11-16 7:36 ` Anand Moon
2026-11-17 5:33 ` Aurelien Jarno
2026-11-17 12:34 ` Anand Moon
2026-11-17 22:26 ` Aurelien Jarno [this message]
2026-11-10 6:41 ` [PATCH v1 1/2] i2c: spacemit: Avoid sleeping during bus reset in atomic context Troy Mitchell
2026-11-10 6:49 ` Troy Mitchell
2026-11-10 7:04 ` Anand Moon
2026-11-10 20:49 ` Aurelien Jarno
2026-11-10 21:15 ` Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avzUjsZzhky4krEV@aurel32.net \
--to=aurelien@aurel32.net \
--cc=andi.shyti@kernel.org \
--cc=dlan@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux.amoon@gmail.com \
--cc=sebastian.reichel@collabora.com \
--cc=spacemit@lists.linux.dev \
--cc=troy.mitchell@linux.spacemit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox