Skip to content

mfd: macsmc: count a port's dark wake on every board with a sleep policy - #2559

Open
axboe wants to merge 1 commit into
aurora-silicon:mainfrom
axboe:k116s-dark-wake-count
Open

axboe wants to merge 1 commit into
aurora-silicon:mainfrom
axboe:k116s-dark-wake-count

Conversation

@axboe

@axboe axboe commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

apple_smc_prepare_guard() waits for a command in flight only when dark_wakes is set (#2231, which replaced the mutex #2445 took at .prepare). apple_smc_dark_wake() returns for every board but the J714s before it counts a wake that apple_sleep_port_wake() already made dark, so on the other boards with a sleep policy (the J716c) dark_wakes stays 0.

There the guard at .suspend after a port's wake with the lid closed is a single trylock: if a command of the wake is still running, .suspend returns -EBUSY and the dark wake ends in a full one. That is the refusal the third commit of #2445 fixed.

Fixes: 18b4933 ("mfd: macsmc: J714s: keep the port and radio dark wakes to the J714s")

Change

One commit, 4 lines moved in apple_smc_dark_wake(): count a wake that is already dark first, then keep the J714s's own rule to the J714s. Nothing changes on the J714s. A board without a sleep policy (the J813) does not reach this function.

Testing

Tested: not run on hardware at this head. Found by reading the code after a rebase; I have not reproduced the refusal on main. Host tests pass in CI; checkpatch is clean.

Risk: two-way · T6050 machines with a sleep policy other than the J714s (J716c today; the K116s with #2201).

The K116s only reaches this code with #2201, which touches the same line, so my K116s runs are on an adapted form of this commit and are not a row at this head. With that form in my daily kernel, closed-lid charger plugs on the K116s (T6050, M5 Pro) go dark and re-enter the sleep cleanly.

Still to run

  • J716c: a closed-lid USB-C plug. Expected: woken for a port with the lid closed: dark wake, then PM: dark wake: suspending again with no -EBUSY from the SMC's .suspend, and the lid wakes it afterwards. I don't have a J716c.

  • Clean-room: no Apple code, strings, firmware, RE output or tuning values

  • No chip/board/firmware-version gate where a hardware property can decide (the J714s check is the one already in main)

  • Works on the default kernel command line; no hacks, delays or lab-only paths

  • Safety limits come from the machine, not from constants in code

  • Hardware safety rules followed for every test boot

  • Third-party commits unchanged; reporters and testers credited

  • Commits: human Signed-off-by only; no AI attribution in commits or PR text

  • Tested on the affected hardware; no regression (not at this head, see Testing)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The reorder looks right: it does what the second paragraph of 18b4933's message asked for, and outside the J714s dark_wakes is only read as a flag by apple_smc_prepare_guard() and cleared on the next full wake, so the missing cap there has no effect.

Two small things:

  • The commit message names the K116s, but apple_smc_prepare_guard() only runs with saved_enabled (macsmc.c:1520), which is set for the J714s, J716c and J813 (macsmc.c:649-657). On a K116s the re-entry never takes the trylock path, so the boards this changes are the J716c (and the J813, if it gets port dark wakes).
  • The comment above SMC_DARK_REENTRY_MS (macsmc.c:1491-1495) still says the wait is for "the re-entry right after a J714s dark wake"; it now applies to any counted dark wake.

A J716c run with a USB-C plug wake and the lid closed, showing the dark wake's re-entry: the SMC was busy for N ms line instead of the -EBUSY refusal, would confirm it.

Assisted-by: LLM (Claude:Opus 5.5)

@axboe
axboe force-pushed the k116s-dark-wake-count branch from cfeb58f to 4b663ff Compare November 21, 2026 13:41
@axboe

axboe commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Ryan, both taken at 4b663ff; the code is otherwise unchanged.

I have no J716c for the plug-wake run.

@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.

Pre-PR checklist review at 4b663fffcb1d (§1–§6). Commit attribution, clean-room, naming, and CI (host-tests) are clean, and reordering if (pm_dark_wake()) above the J714s wake_reasons check fixes the J716c path. Requesting changes because J813 is still not fixed by this patch (contrary to the title and commit message) and §5 hardware evidence is missing:

Blockers

  1. Real code bug — J813 (and any saved_enabled board without smc->sleep_policy) still leaves dark_wakes == 0 (drivers/mfd/macsmc.c:1079-1091 at PR head; 1118-1131 on integration/aurora):
    Both the PR title ("count a port's dark wake on every board") and commit message state that this fixes the other boards with the saved-context path: "the J716c, and the J813 if a port wakes it dark".
    However, apple_smc_sleep_wake() only calls apple_smc_dark_wake(smc) inside if (smc->sleep_policy):

    if (apple_smc_port_reasons_only(smc, smc->wake_record))
        apple_sleep_port_wake(apple_sleep_lid_closed_at_wake() > 0);
    if (smc->sleep_policy) {
        apple_smc_dark_wake(smc);
        return;
    }

    In drivers/soc/apple/sleep.c:9524, t8142_sleep_soc (J813) has .smc_policy == NULL (J813 uses apple_sleep_smc_defer_notice() / apple_smc_j813_saved_ops with smc->saved_enabled = true at macsmc.c:656-657). Therefore on J813:

    • apple_smc_dark_wake() is never reached at all;
    • smc->dark_wakes stays 0 after apple_sleep_port_wake() (and after apple_sleep_lid_closed_wake() or apple_sleep_debug_link_cut_wake());
    • on re-entry, apple_smc_prepare() -> apple_smc_sleep_prepare() -> apple_smc_prepare_guard() still runs with limit = 0 (single trylock).

    To actually count dark wakes on every board with the saved-context path, also increment smc->dark_wakes when pm_dark_wake() is set on the non-sleep_policy path of apple_smc_sleep_wake() (after apple_sleep_debug_link_cut_wake()), or drop J813 from the title/commit message if scoping this strictly to sleep_policy boards.

  2. Commit message wording on .prepare vs .suspend (drivers/mfd/macsmc.c:1559-1586):
    On J716c (apple_sleep_smc_policy() != NULL), apple_smc_prepare() takes mutex_lock(&smc->mutex) directly; the apple_smc_prepare_guard() trylock-vs-wait path runs at .suspend (apple_smc_suspend() -> apple_smc_sleep_prepare()). On J813 it runs at .prepare.

  3. §5 Evidence missing:
    No hardware run on any affected board (J716c or J813) and no §5 regression run (0 SELinux denials, 0 failed units, 0 new kernel errors). As @RyanTheTide noted, a J716c (and/or J813, once fixed there) closed-lid USB-C plug-wake run showing dark wake's re-entry: the SMC was busy for N ms (or clean re-entry without -EBUSY) plus a regression check is needed before merge.

Checklist summary (§1–§6)

  • §1 No model gating: Incomplete — still gated on smc->sleep_policy, missing J813 (saved_enabled without sleep_policy).
  • §2 Production-ready: Blocked by item 1.
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass — human author/committer and Signed-off-by, zero AI trailers.
  • §5 Evidence: Missing hardware verification and regression run.
  • §6 Naming: Pass.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, both points are taken at 4b663ff: the message names the J716c and J813, and the comment at macsmc.c:1492 says "a counted dark wake". The code is the same as before.

I checked the J813 point from the review above and it holds at this head. smc->dark_wakes is only incremented inside apple_smc_dark_wake() (macsmc.c:1027, 1043), and that is only called under if (smc->sleep_policy) (macsmc.c:1083). Only the T6050 sleep SoCs set .smc_policy (sleep-t6050.h:3763, 3892), so on the J813 (saved_enabled from macsmc.c:656) the guard at .prepare still gets limit = 0. Either count pm_dark_wake() on the path without a policy too (after apple_sleep_debug_link_cut_wake(), macsmc.c:1088), or limit the message to the J716c, where the guard runs at .suspend.

Assisted-by: LLM (Claude:Opus 5.5)

apple_smc_prepare_guard() waits for a command in flight only when
dark_wakes is set, and apple_smc_dark_wake() returns for every board but
the J714s before it counts a wake that apple_sleep_port_wake() already
made dark. On the other boards with a sleep policy (the J716c) the guard
at .suspend after a port's wake with the lid closed is then a single
trylock: if a command of the wake is still running, .suspend returns
-EBUSY and the dark wake ends in a full one.

Count the wake first, then keep the J714s's own rule to the J714s. The
comment on the wait no longer names the J714s.

A board without a sleep policy (the J813) does not get here and is not
changed.

Fixes: 18b4933 ("mfd: macsmc: J714s: keep the port and radio dark wakes to the J714s")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
@axboe axboe changed the title mfd: macsmc: count a port's dark wake on every board mfd: macsmc: count a port's dark wake on every board with a sleep policy Nov 22, 2026
@axboe
axboe force-pushed the k116s-dark-wake-count branch from 4b663ff to af97a52 Compare November 22, 2026 15:54
@axboe

axboe commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Ryan, DjDeveloperr, you are both right about the J813: it has no sleep policy, so it never reaches apple_smc_dark_wake() and this commit does nothing there. The message was wrong, not the scope. At af97a52 the code is unchanged and the message and title are limited to boards with a sleep policy (today that adds the J716c), with the J813 named as not changed. It also says .suspend now, which is where the guard runs with a policy.

I did not add counting on the path without a policy. That would change the J813's re-entry, and I have no J813 to run it on.

On the hardware row: I have no J716c either. The closest I have is the K116s with #2201 and this commit, which is not a J714s-table board and so takes the branch this commit moves: a closed-lid charger plug there was a dark wake (woken for a port with the lid closed: dark wake), the re-entry went through without -EBUSY and without the guard having to wait, and the lid woke it later. A J716c closed-lid plug wake needs a J716c owner.

@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.

Formal §1–§6 pre-PR re-review at verified live head af97a52c0a587e084aed2e715dfe716d3e444d43 (vs integration/aurora 70a00e583b03; not superseded; host-tests green).

Resolved from prior review (4b663fffcb1d)

  • Scope & commit message accuracy: Fixed — title, PR description, and commit message now accurately scope the change to boards with a sleep policy (adding J716c alongside J714s), explicitly noting that boards without a sleep policy (J813) do not reach apple_smc_dark_wake() and are unchanged.
  • .suspend vs .prepare wording: Fixed — accurately describes the guard running at .suspend on sleep-policy boards.
  • Code correctness: Reordering if (pm_dark_wake()) { smc->dark_wakes++; return; } ahead of if (smc->wake_reasons != apple_smc_j714s_wake_reasons) return; in apple_smc_dark_wake() is clean, preserves J714s behavior identically, lets apple_smc_prepare_guard() wait up to SMC_DARK_REENTRY_MS on J716c port dark-wake re-entry, and clears smc->dark_wakes on full wake in apple_smc_complete().

Checklist summary (§1–§6)

  • §1 No model gating: Pass (removes an unintended J714s-only gate on counting an already-dark port wake).
  • §2 Production-ready / §3 Safety / §6 Naming: Pass.
  • §4 Clean-room & attribution: Pass — human author/committer and Signed-off-by: only, clean Fixes: 18b493373c7c, zero AI commit trailers.
  • Live CI: Pass (host-tests green at af97a52c0a58).

Remaining blocker (§5)

  1. Missing hardware verification and regression run at af97a52c0a58: No test run has been posted on an affected in-tree board (J716c closed-lid USB-C plug dark wake + re-entry showing clean re-entry without -EBUSY), and no §5 regression line (0 SELinux denials, 0 failed units, 0 new kernel errors) has been posted for af97a52c0a58 (the K116s run used out-of-tree #2201 without regression counts). Once a J716c owner posts the closed-lid plug-wake + §5 regression row on af97a52c0a58, this is ready to approve.

@github-actions github-actions Bot added area:power Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@axboe

axboe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

I don't have a J716c, so that row isn't mine to give, and per the merge policy a row on a Mac the author doesn't have is requested, not a hold. The K116s only reaches this code with #2201, which touches the same line, so a K116s row would be on an adapted commit and not at this head. What I can say from the K116s with the adapted form in my daily kernel: closed-lid charger plugs go dark and re-enter cleanly, the last one this morning. The change itself is a reorder that leaves the J714s path as it was. If someone with a J716c wants to run the closed-lid plug, the description says what to look for.

@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at af97a52c: ready to merge

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at af97a52c
Conflicts ok none
PR text ok Risk: two-way · T6050 machines with a sleep policy other than the J714s (J716c today; the K116s with #2201). The K116s only reaches this code with #2201, which touches the same line, so my K116s runs are on an adapted form of this commit and are not a row at this head. With that form in my daily kernel, closed-lid charger plugs on the K116s (T6050, M5 Pro) go dark and re-enter the sleep cleanly.

Areas: area:power
Merge: gh pr merge 2559 --merge (Owners and Core through the bypass: add --admin).

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

@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.

Verdict: FINISH, then merge at af97a52c0a58: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: nobody in the lab has a J716c, so your K116s run (with #2201, which takes the branch this commit moves: closed-lid charger plug, dark wake, re-entry without -EBUSY) stands in for the code path. What's still needed is one J714s run at this head: a closed-lid port dark wake and its re-entry, showing nothing changed there. We'll get that row run on our J714s; you don't need to do anything.

Checked: no Apple material. This removes an unintended J714s-only gate: an already-dark wake is now counted first, and the J714s's own rule stays the same. dark_wakes is cleared on the next full wake, and a board without a sleep policy (J813) never reaches this function. The Fixes: tag is correct. CI green. This replaces my earlier reviews: the message is now accurate, and the code was right at both heads.

Evidence

Read af97a52c (drivers/mfd/macsmc.c, 4 lines moved) against apple_smc_prepare_guard(), apple_smc_sleep_wake() and apple_smc_complete(), and your K116s note from 11-22.

@DjDeveloperr
DjDeveloperr dismissed stale reviews from themself November 24, 2026 19:00

Superseded by the review at af97a52

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Hardware Row — M5 Pro (T6050 / J714s / G17S B1) at af97a52c0a587e084aed2e715dfe716d3e444d43

Result: PASS (J714s deep-sleep regression check)

  • Head: af97a52c0a587e084aed2e715dfe716d3e444d43 (af97a52c), built natively as 7.3.0-m5-pr2559 (drivers/mfd/macsmc.o verified compiled from af97a52c with the pm_dark_wake() count before the apple_smc_j714s_wake_reasons check).
  • Boot & configuration: Default command line with MTE ON (mte active in /proc/cpuinfo, no arm64.nomte) and SEP xART writes ENABLED (apple_sep loaded, writes ENABLED). mem_sleep is s2idle [deep], apple-sleep bound (deep sleep is the default: boot object resumes 0).
  • Deep sleep & dark-wake check (2 automated PMU RTC-alarm cycles, +35 s alarm each):
    • Pass 1: rc=0, 41 s RTC delta, boot object resumes 0 -> 1, wake status set: AP 76 NUB.SPMI0Sw3IRQ, macsmc 28c600000.smc: wake record: MBSE 0x106fe, MBSW 00 00 00 00 00 00 00 00.
    • Pass 2: rc=0, 41 s RTC delta, boot object resumes 1 -> 2, wake status set: AP 76 NUB.SPMI0Sw3IRQ, macsmc 28c600000.smc: wake record: MBSE 0x106fe, MBSW 00 00 00 00 00 00 00 00.
    • suspend_stats: success=2, fail=0.
    • Dark-wake & SMC guard behavior: 0 spontaneous wifibt/USB-C_plug dark wakes fired in these 2 cycles (a physical closed-lid cable plug cannot be driven remotely on this rig), 0 spurious dark-wake classifications, 0 -EBUSY sleep refusals, and 0 SMC policy/guard/quarantine errors.
  • Post-wake device & GPU health:
    • Headless Borealis Vulkan smoke (gpubench-vk --test compute.light, offscreen): all queue depths d1..d64 status: ok (d1 105.9 us/submit, d64 15.8 us/submit).
    • aurora-g17/capacity: crashed=0, online=1, firmware_linked_render_graphs kept=0 leaked=0, drained_render_pairs unsettled=0 failures=0 recovered=0 out_of_service=0.
    • Peripherals after wake: 24 USB devices enumerated, Wi-Fi reconnected (wlp1s0f0:connected).
    • dmesg: 0 GPU/DART faults, 0 SMC errors or -EBUSY refusals, 0 kernel oops/warnings.
    • systemctl --failed: 0 new failed units (pre-existing baseline tailscaled.service only).

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

Labels

area:power Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants