Skip to content

nvme: apple: give every ANS the longer RTKit handshake timeout - #2475

Merged
RyanTheTide merged 4 commits into
mainfrom
sweep/redundant-gates-nvme
Nov 28, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
sweep/redundant-gates-nvme

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

nvme-apple raised the RTKit handshake timeout to 10 s only for apple,t6050-nvme-ans2 (drivers/nvme/host/apple.c:2743, 0630fab), because iBoot-handed ANS firmware can take about 3 s to answer. That is firmware behaviour, not a T6050 property. A new SoC would fail with "ANS did not boot" until someone added its compatible. Separately, apple_nvme_m5_sleep() checked the T6050 compatible next to match data that already implies it.

Change

  • Every ANS gets the 10 s handshake timeout. The wait ends as soon as the reply arrives, so a responsive ANS is not slowed down. Only a dead ANS is reported later.
  • The post-sleep "ANS on" loop retried 15 times, a budget written for a 1 s timeout. It is now bounded at 15 s since the run bit, so a dead ANS is still given up on after about 15 to 20 s, not 150 s.
  • The redundant compatible check in apple-m5-sleep.h:196 is dropped. This does not change behaviour.

Testing

Built with the lane release config (arm64, LLVM=1): drivers/nvme/host/apple.o with W=1, no new warnings.

  • Hardware (one-shot test kernel 7.3.0-aurora-swl1 or -swl2 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):

    • T8112 J413 (swl2, kernel-only): boot + 3 s2idle cycles rc=0, 0 kernel errors, 0 DART errors, Wi-Fi up, 0 brcmfmac DMA / NVMe timeout lines, 0 AVC.
  • Hardware (one-shot test kernel 7.3.0-aurora-swl1 or -swl2 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):

    • T6000 J316s (swl2, kernel-only): boot + 3 s2idle cycles rc=0, 0 kernel errors, 0 DART errors, Wi-Fi up, 0 brcmfmac DMA / NVMe timeout lines, 0 AVC.

Still to run

  • Neo, J616s, M1 Pro, M2: boot clean, root on NVMe, dmesg | grep -iE 'ANS|nvme' shows no timeout. Hardware rows: pending.
  • Neo: one s2idle/deep sleep cycle (rtcwake against rtc0). Expect "ANS: on N ms after the run bit" with N well under 1000. Hardware row: pending.
Credit and reach

Rolando Trevino found and fixed the slow handshake on T6050. The change reaches T8103/T8112/T600x/T602x/T603x/T604x/T8122/T8132/T8140/T8142/T6050 ANS. On all of them, success returns at the first reply, so the change only matters when the ANS fails.

nvme-apple raised the RTKit handshake timeout to 10 s only for the
apple,t6050-nvme-ans2 ANS, because its iBoot-handed firmware can take
about 3 s to answer the power-state and endpoint-map handshake. That is
firmware behaviour, not a T6050 property: any ANS firmware handed over
by iBoot can be slow, and a newer SoC would fail to boot with "ANS did
not boot" before anyone added its compatible.

The wait ends as soon as the reply arrives, so a fast ANS is not slowed
down; only a dead ANS is reported later. Set the timeout for every ANS.

The post-sleep "ANS on" loop retried apple_rtkit_boot() 15 times, a
budget written for the 1 s timeout. Bound it by time since the run bit
(15 s) instead, so a longer timeout does not stretch the wait for a dead
ANS to 150 s.

Fixes: 0630fab ("soc: apple: rtkit: wait up to 10 s for a handshake reply")
Suggested-by: Rolando Trevino <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
apple_nvme_m5_sleep() required the T6050 sleep policy from the match
data and then also apple,t6050-nvme-ans2. The policy is only in
apple_nvme_t6050_hw, which only that compatible matches. Drop the second
check. No behaviour change.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 20, 2026 00:25
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s row (MacBook Pro 16" M4 Pro, T6040). One-shot test kernel: integration 2c35f50 + this PR's two commits, fleet75 config. The loaded nvme-apple build-id matches that build.

  • Boot clean with root on NVMe (nvme0n1p6). No ANS or NVMe timeout lines at boot or after resume.
  • 2/2 s2idle cycles (rtcwake on the apple-pmu-rtc, rc=0). NVMe works after resume: a 1 GiB O_DIRECT read runs at 1.4 GB/s (production fleet75 on the same boot path: 1.5 GB/s).
  • Gate: 0 failed units, 0 AVC denials, 0 DART errors. The only kernel error lines are the dwc3-apple genpd_prepare returns -11 lines production also prints on each suspend.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Rows on the J413, J316s and J616s are clean. Still needed: a Neo J700 row (NVMe root boots clean, and one sleep cycle shows "ANS: on N ms after the run bit" well under 1000 ms, since the post-sleep retry loop changed), and a review.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review at c967739. The ANS allocation change extends the same handshake to every controller. Normal replies still end the wait immediately. The sleep restart change compares elapsed time only between apple_rtkit_boot() attempts, so the last attempt can run past the stated 15 s budget. Please pass the remaining budget to the blocking attempt or describe the actual upper bound and prove that it fits the resume watchdog. Include missing-reply and slow-reply host cases and the J413/J473 NVMe resume row.

@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 checklist review at c9677392918b298ab3fd4efd8788d3ff86cf840f:

  • §1 No model gating: Pass — removes two of_device_is_compatible(..., "apple,t6050-nvme-ans2") gates (drivers/nvme/host/apple.c:2776 and drivers/nvme/host/apple-m5-sleep.h:196). Commit 2 is verified equivalent since only apple_nvme_t6050_hw sets m5_sleep = &apple_nvme_t6050_sleep_policy.
  • §3 Safety, §4 Clean-room & attribution, §6 Naming: Pass. Both commits have human author/committer and human Signed-off-by: only (zero AI commit trailers); PR body has Assisted-by:; host-tests CI passes.

Blockers

  1. §2 / Correctness — apple_nvme_sleep_wait_on() overshoots the stated 15 s budget (drivers/nvme/host/apple.c:3004-3065):

    • apple_nvme_sleep_wait_on() only checks ktime_ms_delta(ktime_get(), anv->sleep_run_time) < APPLE_NVME_SLEEP_ON_MS (15 s) between apple_rtkit_boot() attempts.
    • Because apple_rtkit_boot() now uses APPLE_NVME_HANDSHAKE_TIMEOUT_MS (10 s) on every ANS at each blocking handshake step (epmap_completion, iop_pwr_ack_completion, apple_rtkit_set_ap_power_state), a dead ANS always runs at least two full 10 s iterations (~20 s), and an ANS that partially progresses and fails near 14.9 s triggers another full 10–30 s apple_rtkit_boot() call — overshooting the documented 15 s cap to 20–35+ s.
    • Please pass/clamp the remaining time budget into the wait (or add a deadline-bounded RTKit boot helper) so the 15 s limit is actually enforced, or explicitly document and prove the real worst-case upper bound against the resume path/watchdog.
  2. §5 Evidence — modified post-sleep retry path (apple_nvme_sleep_wait_on()) has no hardware run:

    • apple_nvme_sleep_wait_on() is only entered on controllers with sleep_traced = true (T8132, T8140 Neo/J700, T8142). None of the tested Macs (J413 T8112, J316s T6000, J616s T6040) exercise that path, and commit 2 (apple_nvme_m5_sleep()) is T6050-only with no T6050 row.
    • Please add at least a hardware sleep-resume row on a sleep_traced Mac (e.g., Neo J700 / T8132) confirming "ANS: on N ms after the run bit" with 0 kernel errors, 0 AVC denials, and 0 failed units (as noted in "Still to run").

@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (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
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 958951f6: not ready yet

Check Detail
CI at head ok 26 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok comment at 958951f6
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:platform

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 c9677392918b

Blockers:

  1. drivers/nvme/host/apple.c:3022-3065, apple_nvme_sleep_wait_on(): the 15 s APPLE_NVME_SLEEP_ON_MS budget is only checked between apple_rtkit_boot() attempts, and each attempt can now wait the 10 s handshake timeout at every step on every ANS. A dead ANS therefore takes at least two full attempts (about 20 s), and one that fails near 14.9 s starts another full attempt, so the wake can hang for 20–35 s against the stated 15 s. Fix: pass the remaining budget into the boot (a deadline-bounded RTKit boot helper), or stop when the remaining time is shorter than one handshake.

Checked: no Apple material. This removes a chip gate: every ANS gets the longer RTKit handshake timeout. The J413 and other combined-kernel boots (3 s2idle cycles, 0 NVMe timeout lines) show no regression. CI green. This replaces my earlier review.

Evidence

Read c9677392 (apple.c, apple-m5-sleep.h).

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 19:46

Superseded by the review at c967739

Review follow-up. apple_nvme_sleep_wait_on() checked its 15 s budget
only between apple_rtkit_boot() attempts, and with the longer handshake
timeout on every ANS each attempt can wait 10 s at every handshake step.
A dead ANS took at least two full attempts, and one that failed near
the end of the budget started another, so a wake could hang for 20-35 s.

Add apple_rtkit_boot_by(), which runs apple_rtkit_boot() with no
handshake wait past a deadline, and give each attempt the time left in
the budget, at least 1 s so a late attempt still gets a chance. The
whole wait now ends within about 16 s. Other RTKit users are unchanged:
without a deadline each wait still takes the handshake timeout.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 27, 2026 06:54
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Fixed at 958951f (fix commit 38531c4 plus a merge of main, normal push).

Blocker 1 (15 s budget overrun): a new apple_rtkit_boot_by(rtk, deadline) runs apple_rtkit_boot() with no handshake wait past deadline. Both wait helpers take min(handshake timeout, time left); with no time left they only try the completion once. apple_nvme_sleep_wait_on() gives each attempt the time left in the 15 s budget, with at least 1 s so an attempt that starts late still gets a chance. The whole wait now ends within about 16 s, against the 20–35 s before. Other RTKit users are unchanged (no deadline set means the full handshake timeout per wait).
Testing: builds in the fleet-config kernel 7.3.0-aurora-fixa2 (this PR's files byte-identical to its head). checkpatch is clean.
Still to run: s2idle rows at this head on our Macs (ANS wake, 0 "not on" lines, disk I/O after wake). The dead-ANS timing case can't be produced on demand on hardware, so the bound rests on the code above.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Row at 958951f6e26a (this PR's files byte-identical in the combined test kernel 7.3.0-aurora-fixa2): M1 Pro (J316s, T6000/G13S): PASS, M2 Air (J413, T8112/G14G): PASS.

ANS comes back from s2idle on T6000 and T8112 with 0 "not on" lines. The deadline bound itself only matters for a dead ANS, which can't be produced on demand.

Detail

Both rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK api.smoke 8/8 pass. J413 also: glmark2 off-screen (FBO) score 7672, 2 audio sinks. On the M1 Pro, glmark2-wayland never starts rendering: its internal panel is dead and there is no Wayland output, the same on fleet89 (traced), so no GL FBO number there. Silent, no playback. Logs: traces/kernel/20261127-fixa2-rows/ (store).
Kernel kit: kits/test/20261127-fixa2 = main 0a4f97d + forward-merged heads of #2919 #2886 #2302 #2475 #2393 #2384 #2895.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Row at 958951f6e26a (byte-identical in 7.3.0-aurora-fixa2): Neo (J700, T8140/G17P): PASS.

Third family: ANS comes back from s2idle on T8140 too, with 0 "not on" lines.

Detail

Neo (J700, T8140/G17P), fixa2 booted once as a non-default BLS entry, then back to fleet89, verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). SELinux Enforcing, 0 failed units, 0 AVC, 0 oops, 0 err-level kernel lines; Wi-Fi up; G17P Vulkan device; dEQP-VK api.smoke 8/8 and draw.renderpass.simple_draw 4/4; watchdog armed (57 s left of 60); s2idle on rtc0 rc=0 with a 64 MiB direct NVMe read after the wake. Two lines are the same on fleet89 (baseline traced): the boot-time "G17: crash logs from the firmware data segment" note, and Wi-Fi needing ~9 s after the wake before ping answers. Logs: traces/kernel/20261127-fixa2-rows/neo/ (store).

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

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 958951f6

Blockers: none (27/27 CI green and 3-family exact-head rows PASS; ready to merge).

Checked:

  • drivers/nvme/host/apple.c, apple-m5-sleep.h, drivers/soc/apple/rtkit*: commit 38531c49 resolves the prior dead-ANS timeout-budget blocker cleanly by computing remaining budget APPLE_NVME_SLEEP_ON_MS - elapsed (clamped by APPLE_NVME_SLEEP_TRY_MIN_MS) and bounding each retry with apple_rtkit_boot_by(anv->rtk, jiffies + msecs_to_jiffies(left)).
  • Removes two of_device_is_compatible(..., "apple,t6050-nvme-ans2") gates so every ANS shares the longer RTKit handshake timeout and m5_sleep match-data path.
  • Hardware rows & CI: 27/27 CI checks green (SUCCESS), MERGEABLE on main, and exact-head s2idle rows PASS across three families (J316s M1 Pro, J413 M2 Air, J700 Neo, 0 "not on" errors).
  • Checked for Apple material, tool attribution, private serials, and gating: clean; human Signed-off-by present.
Evidence
  • Head: 958951f6e26a (base: main, mergeable: MERGEABLE, +66/-16 across 5 files).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 958951f6. The review App approved this head (NEON-PR-REVIEW2's adversarial pass) and hosted CI is green. Rows: 3-family. Your earlier change request is on an older head, and the App verified the blockers are addressed here. Unless you object or restate a blocker, this merges in 1 h under the 6-point rule.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merging under the 6-point rule (Ryan 09:29, permanent), at 958951f6. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: 3-family. (5) There's no blocking review. (6) Dj was pinged here 61 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 608749a into main Nov 28, 2026
28 checks passed
@RyanTheTide
RyanTheTide deleted the sweep/redundant-gates-nvme branch November 28, 2026 12:56
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) 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants