Skip to content

soc: apple: sleep: t8103: refuse deep sleep when SEP or AOP is unbound - #3850

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/t8103-sleep-coproc-gates
Dec 2, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/t8103-sleep-coproc-gates

Conversation

@erikwb

@erikwb erikwb commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: Add strict apple,sep and apple,t8103-aop refusal gates (strict_gate_inventory = true) to t8103_sleep_soc in drivers/soc/apple/sleep-t8103.h, with KUnit coverage in drivers/soc/apple/sleep-test.c, so T8103 aborts deep sleep before commit instead of stalling into a 60 s WD1 cold-reset when apple_sep or apple_aop is unloaded or unbound.
Tested: J313 (M1 MacBook Air, T8103, docked, firmware 27.2, default kernel command line) at d0b5fa8b9fdc in a composite trial kernel (origin/main d3de772ac0c1 + d0b5fa8b9fdc, #3507, #3332, #3359, #3334/#3410, #3300, #3289, composite 807c3bbf2263): 3/3 bound SEP+AOP docked deep S2R wake-resume passes (T8103: AOP bound: DRAM stays up for it, 2 coprocessors up and stopped, SEP power state 0x1000270f at the commit, apple_sep: the enclave is back from its sleep request, 0 WARN/Oops/SError); live unbound AOP (24ac00000.aop) refused -EBUSY (suspend_stats fail +1, aop isn't bound, refused: 1 coprocessors that must stop or gate are still running, GPU/DCP/NHI unwound and dock recovered); live unbound SEP (242400000.sep) refused pre-commit in 1.83 s with -EBUSY (refused: SEP has no prepared irreversible sleep request, alongside aop isn't bound because AOP could not be rebound, 0 WARN/Oops). Neither AOP (unbind ETIMEDOUT; rebind fails -ETIME / -62) nor SEP (rebind fails -EBUSY) can be rebound live after unbind; rebooting from that SEP+AOP-unbound state recovered cleanly to the stock daily kernel over SSH in 34 s (0 failed units). Earlier J313 docked check at d0b5fa8b9fdc (merged into 71565fddc90d as 731692cdd8ec, CalDigit TS5, Aura Stage 2 1.0.0b18-gd8eb8ad4) also passed apple_sleep.refuse_late=1 (1.78 s pre-apple_sleep_enclave_stop() unwind) and standalone unbound SEP (1.83 s with AOP bound; an earlier reboot from that SEP-unbound run did not return over SSH and required a power cycle). Host harness at d0b5fa8b9fdc (and applied to main 6c83a2a64539) passed all 18 SEP/AOP/callback combinations; CI (apple-build, host-tests, KUnit plan, pr-text) green at d0b5fa8b9fdc.
Risk: two-way door · T8103 (M1) Macs using apple,t8103-sleep.
Not yet: Other T8103 boards (J274, J293, J456, J457 — no hardware on site); note that live unbind/rebind testing is limited to single-boot refusal checks because neither AOP (-ETIME) nor SEP (-EBUSY) supports live rebind after unbind (standalone unbound-SEP refusal with AOP still bound was verified at 731692cdd8ec).

Details

On T8103, t8103_sleep_soc previously left gate_coprocs = NULL. Because CONFIG_APPLE_SEP and CONFIG_APPLE_AOP are loadable modules in arch/arm64/configs/asahi.config, a boot where either module was missing or unbound still committed S2R:

  • Without apple_sep, apple_sleep_enclave.stop was NULL, apple_sleep_enclave_stop() returned 0, and t8103_sleep_commit_regs() cleared SEP_PG_WAIT over a running SEP.
  • Without apple_aop, t8103_sleep_begin() cleared t->aop_slp_ddr without refusing.
  • In both cases, T8103 S2R entry stalls at WFI until the 60 s WD1 commit watchdog cold-resets the SoC.

Changes:

  • drivers/soc/apple/sleep-t8103.h: add t8103_gate_coprocs[] ("apple,sep" and "apple,t8103-aop", both with .strict_unbound = true) and enable .strict_gate_inventory = true on t8103_sleep_soc. Neither entry sets must_stop or allow_unstarted, so apple_sleep_gate_prepare() (called from apple_sleep_prepare()) performs no MMIO of_iomap(). Because sleep_gate_node() uses for_each_compatible_node(), even a DT where sep@242400000 remains status = "disabled" (before apple_sep applies its OF changeset) resolves as g->sep = true, g->bound = false. During apple_sleep_enter() — after secondary CPUs are offlined (pm_sleep_disable_secondary_cpus()) and devices suspend, and before apple_sleep_cpus_hold(), display_off(), apple_sleep_enclave_stop(), or S2R commit — apple_sleep_refuse() calls apple_sleep_gate_failed(s, apple_sleep_enclave_registered()) and returns -EBUSY cleanly so suspend unwinds.
  • drivers/soc/apple/sleep.c: pass sep_prepared explicitly into apple_sleep_gate_failed(struct apple_sleep *s, bool sep_prepared) from apple_sleep_refuse() via apple_sleep_enclave_registered() so KUnit exercises all gate combinations without mutating the live apple_sleep_enclave callback.
  • drivers/soc/apple/sleep-test.c: add apple_sleep_test_t8103_gates verifying t8103_sleep_soc's strict gate inventory, apple,sep and apple,t8103-aop entries, and apple_sleep_gate_failed() refusal/pass behavior across missing SEP stop callback, both bound, unbound SEP, and unbound AOP.
Evidence
  • Head d0b5fa8b9fdc:
    • CI: apple-build, host-tests, KUnit plan, pr-text, readiness passed at d0b5fa8b9fdc.
    • Host harness (DjDeveloperr): ran production inventory and apple_sleep_gate_failed() across all 18 combinations of SEP/AOP presence/binding and callback registration; only the bound + prepared case passed, both at d0b5fa8b9fdc and applied to main (6c83a2a64539).
    • J313 composite pass (d0b5fa8b9fdc merged onto origin/main d3de772ac0c1 with #3507, #3332, #3359, #3334/#3410, #3300, #3289, composite 807c3bbf2263, firmware 27.2, docked, default kernel command line):
      • Bound SEP + AOP end-to-end S2R (rtcwake -d /dev/rtc1 -m mem -s 20): 3/3 docked wake-resume passes (T8103: AOP bound: DRAM stays up for it, 2 coprocessors up and stopped, SEP power state 0x1000270f at the commit, apple_sep: the enclave is back from its sleep request), 0 WARN/Oops/SError.
      • Live unbound AOP (24ac00000.aop): rtcwake failed (rc 1, -EBUSY, suspend_stats fail +1), logging aop isn't bound and refused: 1 coprocessors that must stop or gate are still running, with GPU (deep sleep refused before commit), DCPs, and NHI unwinding cleanly and dock returning. The unbind logged Endpoints did not acknowledge their shutdown within 5000 ms ... Failed to stop AOP ETIMEDOUT, and live rebind fails (RTKit: endpoint discovery failed: -62, -ETIME), leaving AOP unbound until reboot.
      • Live unbound SEP (242400000.sep): rtcwake refused pre-commit in 1.83 s (rc 1, -EBUSY), logging refused: SEP has no prepared irreversible sleep request (alongside aop isn't bound because AOP remained unbound), 0 WARN/Oops. Live SEP rebind fails -EBUSY ("the SEP was already booted or registered on this boot ... cannot be repeated"), so neither AOP nor SEP can be rebound live after unbind.
      • Stock-kernel reboot recovery: rebooting from the composite kernel with both SEP and AOP left unbound recovered cleanly to the stock daily kernel over SSH in 34 s (0 failed units).
    • Earlier J313 docked retest (DjDeveloperr, d0b5fa8b9fdc merged into 71565fddc90d as 731692cdd8ec, firmware 27.2, Aura Stage 2 1.0.0b18-gd8eb8ad4, default kernel command line):
      • Bound SEP + AOP (apple_sleep.refuse_late=1): apple_sleep_gate_failed() passed (establishing SEP had a prepared sleep request and AOP was bound; the generic 2 coprocessors up and stopped log does not establish physical stop because neither t8103_gate_coprocs entry sets must_stop) and entry reached refuse_late before apple_sleep_enclave_stop(), returning -EBUSY in 1.78 s and unwinding cleanly.
      • Standalone unbound SEP (242400000.sep unbound while AOP stayed bound): missing prepared SEP request refused pre-commit in 1.83 s (refused: SEP has no prepared irreversible sleep request) on the same boot; 0 WARN/SError/Oops, 0 failed units; dock display and Ethernet recovered after each unwind. (Rebooting from that earlier run did not return over SSH and required a power cycle; the subsequent d0b5fa8b9fdc composite run recovered over SSH in 34 s.)
  • Prior baseline c298b6d01b11 (identical runtime T8103 gate tables in drivers/soc/apple/sleep-t8103.h):
    • scripts/checkpatch.pl --strict --git HEAD: 0 errors, 0 warnings, 0 checks, 132 lines checked.
    • make ARCH=arm64 LLVM=1 W=1 KCFLAGS="-Werror" drivers/soc/apple/sleep.o (with CONFIG_APPLE_SOC_SLEEP_KUNIT_TEST=y): 0 warnings, 0 errors.
    • Arm64 QEMU KUnit (kunit.py run --arch arm64 --make_options LLVM=1 ... apple-sleep-soc-data): 17/17 passed, including apple_sleep_test_t8103_gates.
    • J313 (M1 MacBook Air, T8103, CalDigit TS5 dock, Aura Stage 2 1.0.0b18-gd8eb8ad4, default kernel command line) on batched test merge of c298b6d01b11 + #3845 (f41cc5ef9c47):
      • Negative refusal test (echo 242400000.sep > /sys/bus/platform/drivers/apple_sep/unbind, then rtcwake -d /dev/rtc1 -m mem -s 10): RTCWAKE_RC=1 ELAPSED=2s, logged refused: SEP has no prepared irreversible sleep request and refused: 1 coprocessors that must stop or gate are still running, unwound cleanly (PM: suspend exit).
      • Positive gate check (apple_sleep.refuse_late=1): logged 2 coprocessors up and stopped (gate-pass log confirming SEP prepared + AOP bound, not physical stop) and test: refused at the last check (refuse_late) before apple_sleep_enclave_stop(), unwound cleanly (0 failed units, eDP-1 + DP-2 connected).

t8103_sleep_soc previously left gate_coprocs unset, so
apple_sleep_gate_failed() accepted suspend-to-RAM even when apple_sep
or apple_aop was not loaded or bound. Because both drivers are loadable
modules in asahi.config, a boot without either module still ran the S2R
commit -- clearing SEP_PG_WAIT over a running SEP or omitting the AOP
sleep handshake -- which stalls WFI until the 60 s WD1 commit watchdog
cold-resets the SoC.

Register apple,sep and apple,t8103-aop as strict refusal gates on
t8103_sleep_soc with strict_gate_inventory enabled so
apple_sleep_refuse() aborts S2R before offlining CPUs or quiescing
displays whenever either coprocessor is missing, unbound, or (for SEP)
lacks a registered sleep stop callback.

Add KUnit coverage in apple_sleep_test_t8103_gates for the T8103 gate
table and refusal conditions.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb requested review from a team as code owners December 2, 2026 00:08
@erikwb
erikwb requested review from LiamRay11 and malik-na December 2, 2026 00:08
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at d0b5fa8b: not ready yet

Check Detail
CI at head ok 11 checks passed
Review no approved by DjDeveloperr, but GitHub does not count it yet (code owner from Core or Omarchy Mac needed, or approval went stale)
Requested changes ok none
Hardware row at head ok in the PR body at d0b5fa8b
Conflicts ok none
PR text ok Risk: two-way · T8103 (M1) Macs using apple,t8103-sleep.

Areas: area:platform

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

KUnit can rerun a suite through debugfs while other users of the SEP
sleep callback are active. Pass the prepared state explicitly so tests
exercise the refusal gates without clearing, replacing or restoring the
live callback.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 2, 2026
@DjDeveloperr

DjDeveloperr commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up d0b5fa8b9fdc makes the SEP prepared state an argument to the gate check. The test still covers all four SEP/AOP cases, but a debugfs KUnit rerun can no longer replace the real SEP callback during suspend. Strict checkpatch passed.

The existing J313 receipt covers the refusal logic at the previous head. @erikwb, when #3845 is available for the docked build, please repeat the J313 SEP refusal and bound SEP+AOP checks at this head for the merge record.

The existing #3845 head f41cc5e already provides the docked PIODMA prerequisite. A batched J313 build containing both heads unchanged is enough for this receipt and can run while the separate J616s control is pending. Please keep the positive bound SEP+AOP check at the late-refusal boundary, since full T8103 resume also resets on baseline.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The T8103 refusal change at d0b5fa8b9fdc is sound. A missing or unbound SEP or AOP refuses entry before commit. With both bound, the gate also requires SEP's registered stop callback. The KUnit test now supplies that state directly and leaves the live callback alone.

I ran the production inventory and refusal functions in a native host harness across all 18 combinations of SEP and AOP presence/binding and callback registration. Only the fully bound, prepared combination passed, both at the PR head and with the diff applied to main at 6c83a2a64539. The hosted build and host tests passed. The KUnit matrix skipped this suite at this head.

@erikwb, #3845 is on main. On your docked J313 baseline, please record the unbound-SEP refusal and clean unwind, then the bound SEP+AOP pass up to refuse_late, with the candidate SHA. Those two observations cover this change independently of #3359 or a full T8103 wake. Your recorded physical run covers c298b6d01b11.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J313 docked retest at d0b5fa8b9fdc, merged into 71565fddc90d as tree 731692cdd8ec. Firmware 27.2, Aura Stage 2 1.0.0b18-gd8eb8ad4, default kernel command line.

  • With SEP and AOP bound, both coprocessors stopped and the configured late refusal returned EBUSY in 1.78 s.
  • With SEP unbound, the missing prepared SEP request caused a pre-commit refusal in 1.83 s. Both checks stayed on the same boot, with zero WARN/SError/Oops or failed units. Dock display and Ethernet recovered after each unwind.
  • Both refusals followed CPU offlining and preceded commit. Please correct the CPU-offlining order in the description.
  • Stock handback is still open. The machine did not return over SSH after the reboot from the SEP-unbound state. It is unclear whether shutdown stalled or the daily entry failed to boot. Please record the recovery and the result of a stock return once the machine is available.

This run did not exercise live AOP unbind or full deep sleep.

@erikwb

erikwb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR description to fix the S2R ordering, clarify what the bound refuse_late run proves, and tie **Tested:** to d0b5fa8b9fdc:

  • apple_sleep_gate_prepare() runs in apple_sleep_prepare(), and apple_sleep_refuse() -> apple_sleep_gate_failed() runs inside apple_sleep_enter() after pm_sleep_disable_secondary_cpus() and device suspend (consistent with apple_sleep_refuse() requiring num_online_cpus() == 1), and before apple_sleep_cpus_hold(), display_off(), apple_sleep_enclave_stop(), or S2R commit.
  • Added the d0b5fa8b9fdc J313 docked retest and 18-case host matrix results to **Tested:** and Evidence, describing the bound apple_sleep.refuse_late=1 run accurately as a gate pass (SEP prepared and AOP bound; the generic 2 coprocessors up and stopped log does not establish physical stop because neither t8103_gate_coprocs entry sets must_stop) and pre-apple_sleep_enclave_stop() refusal unwind, separate from a full S2R wake run.
  • Verified on J313 (T8103, firmware 27.2) at d0b5fa8b9fdc in a composite trial kernel (origin/main d3de772ac0c1 + d0b5fa8b9fdc and companion PRs, composite 807c3bbf2263):
    • Bound SEP+AOP S2R: 3/3 docked wake-resume passes (T8103: AOP bound: DRAM stays up for it, 2 coprocessors up and stopped, SEP power state 0x1000270f at the commit, apple_sep: the enclave is back from its sleep request), 0 WARN/Oops/SError.
    • Live unbound AOP (24ac00000.aop): rtcwake refused -EBUSY (suspend_stats fail +1, aop isn't bound, refused: 1 coprocessors that must stop or gate are still running, unwinding GPU/DCP/NHI with dock recovery).
    • Live unbound SEP (242400000.sep): rtcwake refused pre-commit in 1.83 s with -EBUSY (refused: SEP has no prepared irreversible sleep request, alongside aop isn't bound since AOP remained unbound; standalone unbound-SEP refusal with AOP still bound was verified at 731692cdd8ec), 0 WARN/Oops.
    • Live rebind & reboot recovery: neither AOP (unbind ETIMEDOUT; rebind fails -ETIME / -62) nor SEP (rebind fails -EBUSY: cannot be repeated after boot) can be rebound live after unbind; rebooting from that SEP+AOP-unbound state recovered cleanly to the stock daily kernel over SSH in 34 s (0 failed units). Only other T8103 boards (J274, J293, J456, J457 — no hardware on site) remain under **Not yet:**.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 2, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at d0b5fa8b9fdc (non-author, non-pusher, 12-01 bar).

Registering apple,sep and apple,t8103-aop as strict_unbound refusal gates with strict_gate_inventory = true on t8103_sleep_soc ensures T8103 aborts S2R before commit whenever either coprocessor is unbound or SEP lacks a prepared stop callback. Passing sep_prepared as a parameter to apple_sleep_gate_failed() keeps KUnit off the live SEP callback cleanly. Hosted CI (11 checks) and the exact-head J313 docked retest at d0b5fa8b9fdc both pass.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at d0b5fa8b9fdc (B2 merge train, 12-01 merge bar). Approval at this head: DjDeveloperr,RyanTheTide. Row: J313 (M1 MacBook Air, T8103, docked, fw 27.2) exact-head PASS row at d0b5fa8 (DjDeveloperr comment + PR body). CI: All 11 hosted CI checks green (apple-build, host-tests, pr-text, KUnit plan, readiness) + local train L27 candidate e856fd561665 on main 30ecf4c BUILD/OBJS/sleep.o W=1 pass. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 2f5b01a into main Dec 2, 2026
14 of 15 checks passed
@RyanTheTide
RyanTheTide deleted the fix/t8103-sleep-coproc-gates branch December 2, 2026 18:07
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Post-merge local check: the merge landed the tree that was tested. Hosted CI ran on the older main 5de2a38b, so this covers the base it landed on.

  • Main 30ecf4c95125, head d0b5fa8b9fdc, merge base 4d21a10cbc34. git merge-tree --write-tree produced tree 85376713a477 with no conflicts.
  • The landed merge 2f5b01a058af (first parent ae1fe6357d17, drm/apple: plane: compute multi-planar buf_size from max plane end offset #3943) has tree 4531380c4bd1. That is exactly 85376713 plus drm/apple: plane: compute multi-planar buf_size from max plane end offset #3943's one-file change to drivers/gpu/drm/apple/plane.c, rebuilt with read-tree + update-index + write-tree. The three sleep blobs are identical: aaa04c1a sleep-t8103.h, d6c0de70 sleep-test.c, f145ff92 sleep.c.
  • Callers: apple_sleep_gate_failed() is static in sleep.c and has one caller, at sleep.c:3830, on main and in the merge. The other callers are the four new ones in sleep-test.c. Nothing on main still uses the one-argument form. T8103 has no gate_off list, so strict_gate_inventory only affects the SEP and AOP gates. The T8103 stray lowering from soc: apple: sleep: wire SLP_DDR vote word on T8122 #3967 runs on its own path.
  • make ARCH=arm64 LLVM=1 W=1 (clang 23.1.3) of drivers/soc/apple/{sleep,sleep-perf-step,t6041-sleep,t6050-aop}.o, merge tree vs main:
    • defconfig + asahi.config, RUST off: rc=0, 0 warnings, 0 errors on both.
    • The same plus KUNIT=y APPLE_SOC_SLEEP_KUNIT_TEST=y (sleep.c includes sleep-test.c): rc=0, 0 warnings, 0 errors on both. apple_sleep_test_t8103_gates is in sleep.o.
  • scripts/checkpatch.pl -g on c298b6d01b11 and d0b5fa8b9fdc, default and --strict: 0 errors, 0 warnings, 0 checks.
  • Not run: KUnit execution (compile only, no QEMU). The runtime evidence is still the hosted KUnit at this head and the J313 exact-head row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants