From 55facfacd40df9bd8979759566a16983f8337b95 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:11:39 +1100 Subject: [PATCH] pmdomain: apple: no PS reset recovery during system sleep A power-on that stops with bit 11 latched is retried after a PS reset pulse while the domain is gated (commit a10defefab5d). The genpd noirq resume runs that power-on with the domain's DARTs and engine still in their noirq phase, and on the T8140 the recovery there hangs the machine. In a suspend loop on the J700 (12 systemd and 12 direct pm_test=platform suspends per boot, from a fresh boot), kernels with the recovery hung on 3 of 3 boots. The hw watchdog brought each one back, and no "cleared by a PS reset" line ever reached the disk. Kernels without it (fleet36, and the same tree with the recovery reverted) hung on none of 6 boots. Two of those boots latched ANE_SYS, quarantined the ANE and kept going. The freezer and devices test levels, which never power a domain off, hung on none of 6 boots with the recovery in place. This is the J700 "hang on suspend entry" seen in fleet43 suites and on aneres2. Skip the recovery while the domain is in a system sleep transition (from its suspend_late to its resume_early). The power-on then fails as before #1255. genpd ignores the error in that phase and keeps the domain requested on, and the ANE quarantines at PM_POST_SUSPEND as it did before. Runtime power-ons, including apple_pmgr_ps_cycle(), keep the recovery. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/pmdomain/apple/pmgr-pwrstate-test.c | 17 +++++++++++++++-- drivers/pmdomain/apple/pmgr-pwrstate.c | 13 +++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate-test.c b/drivers/pmdomain/apple/pmgr-pwrstate-test.c index b3a8cd1f5715c..67698ccfc74aa 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate-test.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate-test.c @@ -296,7 +296,11 @@ static void pmgr_ps_power_on_latch_cleared_test(struct kunit *test) KUNIT_EXPECT_EQ(test, r->auto_writes, 1U); } -/* The same in the noirq phase of a system sleep, where genpd ignores errors. */ +/* + * Not in the noirq phase of a system sleep (no PS reset there: it hangs the + * T8140). The power-on fails, which genpd ignores in that phase, and the + * domain stays requested on. + */ static void pmgr_ps_power_on_latch_sleep_test(struct kunit *test) { struct pmgr_ps_test_reg *r; @@ -305,9 +309,18 @@ static void pmgr_ps_power_on_latch_sleep_test(struct kunit *test) ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, true, &r); ps->system_sleep = true; r->latched = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->reset_writes, 0U); + KUNIT_EXPECT_FALSE(test, r->val & APPLE_PMGR_PS_RESET); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_CLKGATE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); + + /* The same domain after the sleep: the recovery runs again. */ + ps->system_sleep = false; KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), 0); + KUNIT_EXPECT_EQ(test, r->reset_writes, 1U); KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_ACTIVE); - KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); } /* A latch the reset does not clear still fails, and the domain is requested off. */ diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 0c825a64b42bd..688842390a6a2 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -94,14 +94,23 @@ static int apple_pmgr_ps_wait_parent(struct apple_pmgr_ps *ps, u32 *cur) * their state there anyway), then request @reg, the on state, again. * Domains whose bit 11 means a parent that is not up yet (wait_parent) and * those with their own state contract are left alone. + * + * Never during a system sleep transition: there the power-on comes from the + * genpd noirq resume, with the DARTs and the engine of the domain still in + * their noirq phase. On the T8140 a recovery at that point hangs the machine: + * in a suspend loop on the J700, kernels with it hung on 3 of 3 boots and came + * back only through the watchdog, while kernels without it hung on none of 6, + * two of which latched ANE_SYS and carried on with the ANE quarantined. The + * power-on then fails as it did before, and genpd, which ignores errors in + * that phase, keeps the domain requested on. */ static int apple_pmgr_ps_clear_latch(struct apple_pmgr_ps *ps, u32 reg, u32 *cur) { u32 off = (reg & ~APPLE_PMGR_PS_TARGET) | APPLE_PMGR_PS_PWRGATE; int ret; - if (ps->wait_parent || ps->strict_state || ps->externally_clocked || - !(*cur & APPLE_PMGR_BUSY) || + if (ps->system_sleep || ps->wait_parent || ps->strict_state || + ps->externally_clocked || !(*cur & APPLE_PMGR_BUSY) || FIELD_GET(APPLE_PMGR_PS_ACTUAL, *cur) == APPLE_PMGR_PS_ACTIVE) return -ETIMEDOUT;