Skip to contentSkip to conversation

mfd: rk8xx: Register poweroff handler in atomic phase

PATCH Applied Eric Anderson 3 participants 5 messages Sep 8 – Sep 22 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: rk8xx: Register poweroff handler in atomic phase

This fixes a regression from v6.1 to v6.6 where Google Veyron devices (rk3288) would not power off after being shut down.

Prior to commit 4fec8a5a85c4 ("mfd: rk808: Convert to device managed resources"), pm_power_off was called by legacy_pm_power_off() which itself was registered using SYS_OFF_MODE_POWER_OFF. But in that commit the registration of rk808_power_off() moved to SYS_OFF_MODE_POWER_OFF_PREPARE. At the very least, the code should be consistent between SYS_OFF_MODE_POWER_OFF and SYS_OFF_MODE_RESTART; both should be *_PREPARE or both not.

It appears interrupt delivery is already shut down (but not disabled) when SYS_OFF_MODE_POWER_OFF_PREPARE is triggered, so regmap_update_bits() in rk808_power_off() does not complete successfully. Registering rk808_power_off() as SYS_OFF_MODE_POWER_OFF runs with interrupts disabled which causes polling I/O to be used instead, and the device to power down.

Fixes 4fec8a5a85c4 ("mfd: rk808: Convert to device managed resources")
Assisted-by Gemini:gemini-3.5-flash
---
 drivers/mfd/rk8xx-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/rk8xx-core.c +1 -1
index 3dcf6abfda74..21182df45d1b 100644
@@ -875,7 +875,7 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
 	if (device_property_read_bool(dev, "system-power-controller") ||
 	    device_property_read_bool(dev, "rockchip,system-power-controller")) {
 		ret = devm_register_sys_off_handler(dev,
-				    SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH,
+				    SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
 				    &rk808_power_off, rk808);
 		if (ret)
 			return dev_err_probe(dev, ret,

---
base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff
change-id: 20260908-veyron-shutdown-09b3faffb5f9

Best regards,

Signature · 1 line
Eric Anderson <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The patch moves the power-off handler to SYS_OFF_MODE_POWER_OFF, which executes in an atomic context (local interrupts disabled and secondary CPUs halted). The handler calls regmap_update_bits(), which unconditionally attempts to acquire a sleepable regmap mutex, leading to a system deadlock if the mutex is held by a stopped CPU.

Pre-existing issues:
- [High] The restart handler rk808_restart() identically calls regmap_update_bits() from an atomic context, presenting a pre-existing deadlock risk during system reboot. --

commit 9ca348a7dffb994afa6516d011f6fbab7c173e09
Author: Eric Anderson <[email protected]>

mfd: rk8xx: Register poweroff handler in atomic phase

This commit fixes a poweroff regression on Google Veyron devices by moving the power-off handler registration from SYS_OFF_MODE_POWER_OFF_PREPARE to SYS_OFF_MODE_POWER_OFF. This change causes the handler to execute with local interrupts disabled to enable polling I/O for device power down.

drivers/mfd/rk8xx-core.c int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap · line 879

Quoted 11 lines
drivers/mfd/rk8xx-core.c +1 -1
index 3dcf6abfda74f..21182df45d1b6 100644
@@ -875,7 +875,7 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
 	if (device_property_read_bool(dev, "system-power-controller") ||
 	    device_property_read_bool(dev, "rockchip,system-power-controller")) {
 		ret = devm_register_sys_off_handler(dev,
-				    SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH,
+				    SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
 				    &rk808_power_off, rk808);

[Severity: High]
Does this change introduce a deadlock risk during system shutdown?

Moving the power-off handler to SYS_OFF_MODE_POWER_OFF means it executes in an atomic context where local interrupts are disabled and secondary CPUs are halted via smp_send_stop().

However, the handler calls regmap_update_bits():

drivers/mfd/rk8xx-core.c:rk808_power_off() {
	...
	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
	...
}

regmap_update_bits() attempts to acquire a sleepable regmap mutex. If a secondary CPU was stopped while holding this mutex during a background regmap operation, the primary CPU will block indefinitely with interrupts disabled, preventing the system from shutting down.

[Severity: High]
This is a pre-existing issue, but does rk808_restart() have the same deadlock risk during system reboot?

The restart handler is similarly registered using SYS_OFF_MODE_RESTART, which also executes in an atomic context with secondary CPUs halted.

Like the power-off handler, it issues a regmap_update_bits() call:

drivers/mfd/rk8xx-core.c:rk808_restart() {
	...
	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
	...
}

This poses the same structural deadlock risk if another CPU was stopped while holding the sleepable regmap mutex.

Quoted 3 lines
drivers/mfd/rk8xx-core.c +0 -0
 		if (ret)
 			return dev_err_probe(dev, ret,

"failed to register poweroff handler\n");

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
Quoted 4 lines · On Tue, 08 Sep 2026, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The patch moves the power-off handler to SYS_OFF_MODE_POWER_OFF, which executes in an atomic context (local interrupts disabled and secondary CPUs halted). The handler calls regmap_update_bits(), which unconditionally attempts to acquire a sleepable regmap mutex, leading to a system deadlock if the mutex is held by a stopped CPU.

Please review, explain or fix the Sashiko review(s).

If this is a set, this request includes the other patches too.

Quoted 70 lines

Pre-existing issues:
- [High] The restart handler rk808_restart() identically calls regmap_update_bits() from an atomic context, presenting a pre-existing deadlock risk during system reboot. --

commit 9ca348a7dffb994afa6516d011f6fbab7c173e09
Author: Eric Anderson <[email protected]>

mfd: rk8xx: Register poweroff handler in atomic phase

This commit fixes a poweroff regression on Google Veyron devices by moving the power-off handler registration from SYS_OFF_MODE_POWER_OFF_PREPARE to SYS_OFF_MODE_POWER_OFF. This change causes the handler to execute with local interrupts disabled to enable polling I/O for device power down.

drivers/mfd/rk8xx-core.c int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap · line 879

Quoted 11 lines
drivers/mfd/rk8xx-core.c +1 -1
index 3dcf6abfda74f..21182df45d1b6 100644
@@ -875,7 +875,7 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
 	if (device_property_read_bool(dev, "system-power-controller") ||
 	    device_property_read_bool(dev, "rockchip,system-power-controller")) {
 		ret = devm_register_sys_off_handler(dev,
-				    SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH,
+				    SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
 				    &rk808_power_off, rk808);

[Severity: High]
Does this change introduce a deadlock risk during system shutdown?

Moving the power-off handler to SYS_OFF_MODE_POWER_OFF means it executes in an atomic context where local interrupts are disabled and secondary CPUs are halted via smp_send_stop().

However, the handler calls regmap_update_bits():

drivers/mfd/rk8xx-core.c:rk808_power_off() {
	...
	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
	...
}

regmap_update_bits() attempts to acquire a sleepable regmap mutex. If a secondary CPU was stopped while holding this mutex during a background regmap operation, the primary CPU will block indefinitely with interrupts disabled, preventing the system from shutting down.

[Severity: High]
This is a pre-existing issue, but does rk808_restart() have the same deadlock risk during system reboot?

The restart handler is similarly registered using SYS_OFF_MODE_RESTART, which also executes in an atomic context with secondary CPUs halted.

Like the power-off handler, it issues a regmap_update_bits() call:

drivers/mfd/rk8xx-core.c:rk808_restart() {
	...
	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
	...
}

This poses the same structural deadlock risk if another CPU was stopped while holding the sleepable regmap mutex.

Quoted 3 lines
drivers/mfd/rk8xx-core.c +0 -0
 		if (ret)
 			return dev_err_probe(dev, ret,

"failed to register poweroff handler\n");

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Signature · 1 line
Lee Jones
#3 lore raw
Quoted 5 lines · Lee Jones
Quoted 2 lines · On Tue, 08 Sep 2026, [email protected] wrote:

New issues:
- [High] The patch moves the power-off handler to SYS_OFF_MODE_POWER_OFF, which executes in an atomic context (local interrupts disabled and secondary CPUs halted). The handler calls regmap_update_bits(), which unconditionally attempts to acquire a sleepable regmap mutex, leading to a system deadlock if the mutex is held by a stopped CPU.

Please review, explain or fix the Sashiko review(s).

From my perspctive, my change is a limited revert for a regression, and the findings were prexisting (before the regression, and still today with reset). Also, my change is fixing a guaranteed hang, so even if this could cause a deadlock with non-zero probability, that is still an improvement over the current code.

Looking into the actual report, without me knowing anything about anything, it is either not an issue or a widespread problem. as3722_pm_power_off, atc2603c_do_poweroff/atc2609a_do_poweroff, syscon_poweroff, max77620_pm_power_off look to have the same pattern (best as I can tell). The counter examples are rk808_power_off and odroid_go_ultra_poweroff_prepare which register as _PREPARE, with odroid_go_ultra also having an explicit comment about the lock.

This is happening in the final acts of shutting down, so it seems the system should be pretty quiet at this point. If there's a better approach, I could look into it, but someone would need to provide a hint as my ability to provide this patch was "make it work like it used to." Alternatively, the patch could be viewed as a regression report.

maintainer Applied
#4 lore raw

Re: (subset) [PATCH] mfd: rk8xx: Register poweroff handler in atomic phase

In reply to Eric Anderson
Quoted 11 lines · Eric Anderson

This fixes a regression from v6.1 to v6.6 where Google Veyron devices (rk3288) would not power off after being shut down.

Prior to commit 4fec8a5a85c4 ("mfd: rk808: Convert to device managed resources"), pm_power_off was called by legacy_pm_power_off() which itself was registered using SYS_OFF_MODE_POWER_OFF. But in that commit the registration of rk808_power_off() moved to SYS_OFF_MODE_POWER_OFF_PREPARE. At the very least, the code should be consistent between SYS_OFF_MODE_POWER_OFF and SYS_OFF_MODE_RESTART; both should be *_PREPARE or both not.

Quoted 1 line

[...]

Applied, thanks!

[1/1] mfd: rk8xx: Register poweroff handler in atomic phase

      commit: a9c8cbec9f5d209efb3d8811f7d46d7af39504d1

--
Lee Jones [李琼斯]