Repository navigation
nvme: apple: keep the RTKit buffers of ANS across a firmware sleep - #3381
RyanTheTide merged 2 commits into
Conversation
For a suspend-to-RAM that goes through firmware, a controller without
the warm sleep sequence is put in IDLE, not shut down:
apple_nvme_suspend() saves the SART's entries, calls
apple_rtkit_idle() and then apple_rtkit_reinit(). The reinit frees
every buffer the firmware was given (syslog, crash log, ioreport,
oslog) with dma_free_coherent() and takes its range out of the SART.
On the wake the reset work calls apple_rtkit_reinit() once more,
writes the saved SART entries back, the freed ranges among them, and
starts ANS.
An idled ANS keeps its state. On T6000 (M1 Pro, J314s), after the
wake it sends HELLO, the kernel logs "RTKit: Initializing (protocol
version 12)", the endpoints are started, and the firmware then sends
syslog records without a buffer request or a SYSLOG_INIT before them:
RTKit: received syslog message but no syslog_msg_buffer
logged at each sleep and each wake. The firmware still writes the
records' text to the buffer it had before the sleep, which the page
allocator has handed to someone else by then, and which the SART
admits again. With an out-of-tree T6000 sleep sequence that freed and
re-admitted the buffers the same way, ANS's syslog text was found in
a process's page tables ("Bad page map"), followed by an oops.
Keep the buffers for as long as the firmware may use them. Add
apple_rtkit_reinit_retaining_buffers(), which resets a session's
handshake state as apple_rtkit_reinit() does and leaves the shared
buffers, their SART ranges and the syslog geometry alone, and use it
for the idle before the sleep and for the restart after it.
Both ways the firmware can come back are then served by the code
that is there:
- a firmware that resumes with its state never asks, keeps writing
to memory that is still its own, and its syslog records are read
and printed again;
- a firmware that starts from scratch asks again. A request of the
same size for an endpoint that has a buffer is answered with that
buffer by apple_rtkit_common_rx_get_buffer(), and a SYSLOG_INIT
replaces the geometry.
Nothing is allocated per sleep. The buffers are released as before
by apple_rtkit_free(), or by the apple_rtkit_reinit() of a
controller reset, which follows a shutdown the firmware
acknowledged.
The path is not specific to T6000: T8103 (M1) takes it as well. The
T8122 warm sequence does not reinitialize and is unchanged.
Fixes: 7dfc208 ("nvme-apple: idle ANS for a firmware sleep and start it cold after the wake")
Signed-off-by: Oliver Gregory <59419317+olivergreg@users.noreply.github.com>
0dc7f7a to
782fdd6
Compare
tools/asahi/rtkit-oslog-tests.py builds apple_rtkit_reset_session() and apple_rtkit_reinit() on their own. The previous commit moved the buffer frees and the mailbox start into two new static helpers, which the test does not take, so it stopped linking. Free the buffers inside apple_rtkit_reset_session() again, under !keep_buffers, and start the mailbox in apple_rtkit_reinit() and apple_rtkit_reinit_retaining_buffers() directly. No change in behaviour. Signed-off-by: Oliver Gregory <59419317+olivergreg@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH, then merge at b1ac1a3c
Blockers:
- Hosted CI at
b1ac1a3c: Pull-request CI workflows (apple-build,host-tests,kunit,pr-text) still need maintainer approval/run and a green pass atb1ac1a3c. - Target & cross-family lab hardware rows (noted under
**Not yet:**): Still awaits aT8103(J313) deep-sleep row (the SoC reaching the non-warmfw_sleeppath onmain) and a regression row on a second NVMe/RTKit family (T8122orM4, sincedrivers/soc/apple/rtkit.cis shared across all Macs andT8122refused warm sleep onmainalso entersif (fw_sleep)inapple_nvme_reset_work_impl()).
Checked:
- Audited all three touched files (
drivers/soc/apple/rtkit.c,include/linux/soc/apple/rtkit.h,drivers/nvme/host/apple.c) across both commits (782fdd6c,b1ac1a3c); zero code blockers found. - Verified
apple_rtkit_reset_session(rtk, keep_buffers)cleanly retains all eight shared buffers,syslog_msg_buffer,syslog_n_entries,syslog_msg_size, and{syslog,crashlog,oslog}_inheritedwhenkeep_buffers == true, while resetting endpoints, power states, and completions; verifiedapple_rtkit_common_rx_get_buffer()re-answers matching repeated requests (goto reply),apple_rtkit_syslog_rx_init()safely replacessyslog_msg_buffer, and ordinaryapple_rtkit_reinit()(keep_buffers = false) /apple_rtkit_free()release all retained buffers without leaks or double-frees. - Checked interaction with recently merged
#3445onmain(t8122_warm_refused/anv->shmem_deferindrivers/nvme/host/apple.c):anv->shmem_deferis still cleared tofalseon both normal completion andout:error exit, so retaining buffers insidertkonif (fw_sleep)is compatible withT8122refused warm sleep as well. - Verified PR text (
What/Tested/RiskTwo-way door/Not yet),Fixes: 7dfc208abc18, and the thoroughT6000(J314s) stand-in boot, deep-sleep, and refused-sleepO_DIRECTSHA-256 verification rows.
Evidence
drivers/soc/apple/rtkit.c:apple_rtkit_reinit()andapple_rtkit_cold_restart()passkeep_buffers = false;apple_rtkit_reinit_retaining_buffers()passeskeep_buffers = trueand detaches RX / flushesrtk->wqifapple_mbox_start()fails.drivers/nvme/host/apple.c: callsapple_rtkit_reinit_retaining_buffers()only in the!anv->hw->warm_sleepfirmware-sleep suspend path and whenfw_sleepis set inapple_nvme_reset_work_impl(); ordinary resets continue callingapple_rtkit_reinit().- Compatibility with
main(#3445): ont8122_warm_refused,anv->fw_sleep_restartis set alongsideanv->t8122_warm_refused, soapple_rtkit_reinit_retaining_buffers()keeps buffers insidertkwithout invokingshmem_destroywhileanv->shmem_deferis still cleared at exit.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
I tested |
There was a problem hiding this comment.
Verdict: MERGE at b1ac1a3c079c
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Audited all three touched files (drivers/soc/apple/rtkit.c, include/linux/soc/apple/rtkit.h, drivers/nvme/host/apple.c) across both commits (782fdd6c, b1ac1a3c); zero code blockers found.
- Verified
apple_rtkit_reset_session(rtk, keep_buffers)cleanly retains all eight shared buffers,syslog_msg_buffer,syslog_n_entries,syslog_msg_size, and{syslog,crashlog,oslog}_inheritedwhenkeep_buffers == true, while resetting endpoints, power states, and completions; verifiedapple_rtkit_common_rx_get_buffer()re-answers matching repeated requests (goto reply),apple_rtkit_syslog_rx_init()safely replacessyslog_msg_buffer, and ordinaryapple_rtkit_reinit()(keep_buffers = false) /apple_rtkit_free()release all retained buffers without leaks or double-frees. - Checked interaction with recently merged
#3445onmain(t8122_warm_refused/anv->shmem_deferindrivers/nvme/host/apple.c):anv->shmem_deferis still cleared tofalseon both normal completion andout:error exit, so retaining buffers insidertkonif (fw_sleep)is compatible withT8122refused warm sleep as well. - Verified PR text (
What/Tested/RiskTwo-way door/Not yet),Fixes: 7dfc208abc18, and the thoroughT6000(J314s) stand-in boot, deep-sleep, and refused-sleepO_DIRECTSHA-256 verification rows.
Follow-ups (not blocking): hosted CI approval; J313 deep-sleep row (2nd family not required)
|
Merging at |
What: Fixes #3379. Carries
Fixes: 7dfc208abc18(from PR #3172). On a firmware suspend-to-RAM,apple_nvme_suspend()idles a pre-M4 ANS without the warm sleep sequence and callsapple_rtkit_reinit(). That frees the shared RTKit buffers and removes their SART ranges while the idled firmware keeps its state. On wake, the saved SART entries are written back, re-admitting the freed ranges, and ANS keeps writing its syslog to freed memory. This addsapple_rtkit_reinit_retaining_buffers(), which resets the session's handshake state and leaves the shared buffers, their SART ranges, and the syslog geometry in place. ANS uses it for the idle before sleep and for the restart after wake. Ordinary controller resets still callapple_rtkit_reinit()and free the buffers as before. Nothing is allocated per sleep. The T8122 warm path does not reinitialise and is unchanged.Tested: MacBook Pro 14" M1 Pro (
T6000 / J314s), aura1.0.0b17-g26c1a85b(auramain). Headb1ac1a3cadds a host-test fix with no behaviour change. The same code, as carried in #3534, ran the third row and more than 150 deep sleeps. Three rows:782fdd6c;pcie_aspm=offfsync+O_DIRECTread-back,sha256comparedwatchdog did not stop!, also on the stock kernel). 0nvmeerrors orsyslog_msg_bufferlinesans2block and path; only T8103 reaches it on plainmain)T6000suspend-to-RAM series onmaincec0503a5a02;apple_sleep.deep=1 apple_sleep.untested_commit=1 pcie_aspm=offfsync+O_DIRECTread-back after each wakeANS: on after the sleep. 0syslog_msg_bufferlines (10 over 2 cycles without this commit), 0nvmeerrors, 0Bad page map, 0 SELinux denials. Other kernel errors and one failed desktop unit come from the out-of-tree series, none from NVMe or RTKit.enter; default cmdline +apple_sart.dyndbg=+p.suspendhad idled ANS (6 at.enter, 3 in a later device's suspend), 256 MiB write +fsync+O_DIRECTread-back after eachentries written back after a sleep that didn't happen, thenANS: on after the sleep. Noapple-sart ... wroteline after any of them, so ANS asked for no new buffers. Read-back matched every time. 0syslog_msg_bufferlines, 0nvmeerrorsRisk: Two-way door. A plain revert restores the previous behaviour, with no UAPI, device-tree, on-disk, or firmware state changes. On
main, T8103 (M1) is the only SoC that reaches the changed branch indrivers/nvme/host/apple.c; other pre-M4 SoCs usingapple_nvme_t8103_hwwill share it once they gain a sleep controller. T8122 (warm_sleep) and M4-and-later SoCs (needs_ioq_registers) do not run the changed lines.drivers/soc/apple/rtkit.cis shared by every Mac.apple_rtkit_reinit()keeps its signature and behaviour (keep_buffers = false),apple_rtkit_cold_restart()passesfalse, and only the two firmware-sleep call sites inapple.ccallapple_rtkit_reinit_retaining_buffers(). Ordinary controller resets, suspend-to-idle, shutdown, removal, and crash-kernel takeover still free buffers as before. On T8103 (not yet run on hardware), the ANS buffers stay allocated and in the SART across sleep, a firmware that asks again receives its existing buffers, and ANS syslog records are printed again rather than dropped. The failure mode to watch for on T8103 is ANS requesting a buffer of a different size after wake, whichapple_rtkit_common_rx_get_buffer()refuses with-EBUSYinstead of allocating a new buffer.Not yet: a T8103 (M1, J313) run and a row on another NVMe family (e.g.
T8122, M4), sincedrivers/soc/apple/rtkit.cis shared by every Mac. I don't have that hardware. Also not exercised: a second ANS firmware version and a KUnit case for the retaining reinit.Details
Evidence: On
main's non-warm firmware-sleep path, running on an M1 Pro (T6000, J314s) with a T6000 sleep series,RTKit: received syslog message but no syslog_msg_bufferappeared at every sleep and wake (10 times over 2 sleep cycles). No oops was captured onmain's path itself, though the code frees the buffers withdma_free_coherent()and re-admits their SART ranges on wake. On the same machine running an out-of-tree T6000 sleep sequence that freed and re-admitted the RTKit buffers the same way, repeated deep sleeps produced an oops withBUG: Bad page mapand page-table entries holding ASCII text from the ANS firmware's syslog.Code changes:
drivers/soc/apple/rtkit.c: the buffer frees stay inapple_rtkit_reset_session()under a newkeep_buffersargument.drivers/nvme/host/apple.c: callapple_rtkit_reinit_retaining_buffers()afterapple_rtkit_idle()in the non-warm firmware-sleep branch ofapple_nvme_suspend(), and inapple_nvme_reset_work_impl()whenfw_sleep(anv->fw_sleep_restart) is set.include/linux/soc/apple/rtkit.h: declareapple_rtkit_reinit_retaining_buffers().Post-wake behaviour and design notes:
apple_rtkit_syslog_rx_log()reads and prints its records again.apple_rtkit_common_rx_get_buffer()answers a matching request for an endpoint that already has a buffer with that buffer, andSYSLOG_INITreplaces the geometry inapple_rtkit_syslog_rx_init().apple_rtkit_warm_restart()was not reused because it setsrtk->warm_restart, keeps endpoint bitmaps, and does not restart endpoints, whereas this ANS wake performs a cold start with a full endpoint map.fw_sleep_restart.-EBUSYinapple_rtkit_coreanalytics_get_buffer(); ANS does not setAPPLE_RTKIT_NEEDS_COREANALYTICS.