Repository navigation
mfd: macsmc: Initialise the completions before the RTKit - #2935
Conversation
apple_smc_probe() initialised init_done and cmd_done only after the RTKit was initialised, woken and the SMC endpoint started. The receive callback is live from the RTKit's initialisation on, and it completes init_done for the first message on the SMC endpoint, so a message that arrives before the probe got that far completes a completion that is still all zeroes. Initialise both completions together with the mutex, the spinlock and the boot stage the receive callback checks, before the RTKit is initialised, in a helper, apple_smc_init_state(). Add a KUnit case that takes the first message with only that state set up. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Signed-off-by: Ryan Murray <[email protected]>
|
Review at c7e6527.
Rows owed at this head (none posted): a boot with SMC sensors and fans up on J616s and on one saved_enabled board (J714s or J813), as the body already lists. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at c7e6527a587ff12701034ea85ce639d37d49fad7.
Checklist Summary
- §1 No model gating: Pass (pre-existing
saved_enabledlogic untouched). - §2 Production-ready: Pass.
- §3 Safety: Blocker — RTKit callback state initialization is still incomplete (see below).
- §4 Clean-room & attribution: Pass — human author/committer (
Ryan Murray <[email protected]>) and humanSigned-off-by:, zero AI trailers in commit. - §5 Evidence: Pending — KUnit
macsmc_early_message_testpasses (swait internal asserts cleanly removed), but hardware rows (fleet82 boots +saved_enabledboard J714s/J813) are still owed. - §6 Naming: Pass.
- CI (at review time):
host-testsgreen.
Blocking Finding
-
Incomplete RTKit callback state initialization (
drivers/mfd/macsmc.c:642-649vs715and582):
apple_smc_init_state()states "The state the RTKit callbacks use. A message can arrive as soon as the RTKit is initialised, so this is set up before that." It movesmutex,lock,init_done,cmd_done, andboot_stagebeforedevm_apple_rtkit_init*(), but leavesBLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);atmacsmc.c:715— after RTKit init,apple_rtkit_wake(),apple_rtkit_start_ep(),SMC_MSG_INITIALIZE, andwait_for_completion_timeout(&smc->init_done).Once the first SMC message sets
smc->boot_stage = APPLE_SMC_INITIALIZEDand callscomplete(&smc->init_done), any asynchronousSMC_MSG_NOTIFICATIONarriving before probe executes line 715 returnsfalsefromapple_smc_rtkit_recv_early()(macsmc.c:539-541), queues the RTKit worker, and runsapple_smc_rtkit_recv()->blocking_notifier_call_chain(&smc->event_handlers, ...)(macsmc.c:582) on an uninitialized (all-zero)struct blocking_notifier_head(rw_semaphore), risking an oops/wait-list corruption or lockdep splat.Please move
BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);intoapple_smc_init_state()(and optionally exercise anSMC_MSG_NOTIFICATIONthroughapple_smc_rtkit_recv()inmacsmc_early_message_test).
Verdict
REQUEST_CHANGES — close the remaining event_handlers init-order window in apple_smc_init_state(), and attach the owed §5 hardware rows.
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at c7e6527a587f. The current initialization helper still leaves the notification chain for later in probe, while endpoint setup can already deliver asynchronous notifications. Initialize the notifier head with the other callback state and add a test that exercises the first notification before child devices are registered. Check the normal SMC sensor enumeration on J473 and J413.
The receive worker can dispatch a notification once the SMC sends its initial reply. Initialize the notifier chain with the rest of the callback state so it is ready before either RTKit path installs the callbacks. Signed-off-by: Ryan Murray <[email protected]>
|
The follow-up at |
RyanTheTide
left a comment
There was a problem hiding this comment.
Re-review at 38d93aa. The added commit moves the blocking notifier head into the same initialization helper as the receive-side completions and stage. Both saved-session and ordinary RTKit initialization now occur after every field touched by an immediate event is initialized. The old post-endpoint init is removed, so it cannot discard an early notification chain. The early-reply test covers the boot transition. Keep the exact-head live SMC probe rows and the CI result distinct from the software check.
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at verified live head 38d93aa124a9b9dbb3e01c8269f2c08e40053c75 (CI 1/1 green: Host tests / host-tests).
Prior Finding Verification & Technical Audit
- Uninitialized
event_handlersnotifier head (Prior Blocker 1) — FIXED:38d93aa124a9movesBLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers)intoapple_smc_init_state()(macsmc.c:642-650), removing the late initialization afterwait_for_completion_timeout(&smc->init_done). - Full RTKit callback pre-init audit: Verified every field touched by
apple_smc_rtkit_crashed(),apple_smc_rtkit_shmem_setup(),apple_smc_rtkit_recv_early(), andapple_smc_rtkit_recv()(mutex,lock,init_done,cmd_done,event_handlers,boot_stage,dev,saved_enabled,sram,sram_base, and zero-initializedatomic_*/saved_*/msg_id) is initialized prior to bothdevm_apple_rtkit_init_m5_saved()anddevm_apple_rtkit_init()(macsmc.c:681-684). - Resume/reset & error unwind:
macsmckeeps the SMC running across sleep (cmd_doneis re-initialized per command viareinit_completion()undersmc->mutex;init_doneis probe-only). Probe failures afterapple_rtkit_wake()cleanly quiesce RTKit viadevm_add_action_or_reset(dev, apple_smc_rtkit_shutdown, smc). - KUnit: Author reports exact-head
macsmc-parserarm64 QEMU pass (17/17) at38d93aa124a9, includingmacsmc_early_message_test.
Checklist Summary
- §1 No model gating: Pass (pre-existing
saved_enabledlogic untouched). - §2 Production-ready: Pass.
- §3 Safety: Pass (0 code blockers).
- §4 Clean-room & attribution: Pass (both commits
c7e6527a,38d93aa1carry human author/committerRyan Murray <[email protected]>and humanSigned-off-by:only, zero AI trailers in commits; PR body disclosure present). - §5 Evidence: Blocked — see below.
- §6 Naming: Pass.
Remaining Blocker
- §5 — Owed physical hardware boot rows: Zero hardware rows have been posted yet. As noted in
## Still to runand your comment at38d93aa124a9, physical boots covering both standard RTKit Macs (e.g. M1 Pro / M2 Air / M2 mini / M4 Pro) and asaved_enabledboard (J714s or J813) with SMC sensor/notification verification and the full §5 regression triad (SELinux Enforcing, 0 AVC denials, 0 failed units, 0 new kernel errors) remain open.
Non-blocking Note
- Optionally consider also delivering an
SMC_MSG_NOTIFICATIONthroughapple_smc_rtkit_recv()inmacsmc_early_message_testto directly exercise the initializedevent_handlerschain.
Verdict
REQUEST_CHANGES — code is clean and the prior init-order blocker is resolved; ready to approve once the owed §5 hardware boot rows and regression triad are posted.
|
J316s (M1 Pro, standard RTKit) booted the kernel built at The stock and trial kernels each bound the SMC and its six child drivers and returned 142 numeric hwmon readings, including both fan tachometers. The trial resumed from one 12-second PMU-RTC s2idle on the same boot. SELinux stayed Enforcing with 0 AVCs, 0 failed units and 0 new kernel error signatures. The two DWC3 prepare errors match the stock RTC control. The production kernel was restored and the trial entry and modules were removed. The RTKit notification trace saw zero callbacks during the observation window and RTC cycle. A live notification event and a physical boot on a saved-transport board such as J714s or J813 remain open. Assisted-by: LLM (Codex) |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 38d93aa124a9: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: the J316s row covers standard RTKit (the SMC and its six children bound, 142 hwmon readings). Needed: one saved_enabled board at this head (the J714s, or a J813) with the SMC sensors and notifications working. The M5 lead can run it on the J714s.
Checked: no Apple material, no gates: the completions are set up before the RTKit starts. CI green.
Superseded by the review at 38d93aa
Keep the probe state initialized before either RTKit transport starts. Retain the wake-reason and WKTP changes alongside the early-message and WKTP KUnit cases. Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at c9aa492328: the code is ready; it needs only rows at this head.
Blockers: none in the code. Missing rows, as your Not yet says. The change since 38d93aa1 is only the forward merge.
- Saved transport: startup on a J714s or J813 at this head, with sensor reads and an event notification. I'm asking the M5 lead for the J714s.
- Standard transport: a refresh of your J316s row at this head.
Checked: the mutex, spinlock, both completions, the notifier head and boot_stage are all set before devm_apple_rtkit_init(), so an early message finds valid state. Nothing is initialised twice later in probe, and the new KUnit case covers the early INITIALIZE reply. No Apple material, no gates, no new parameters.
|
J714s (MacBook Pro 14" M5 Pro, T6050) row at
|
What: Initialise the Apple SMC completions, synchronization state and notification chain before either RTKit transport can call the driver. A message can arrive during probe.
Tested: ARM64 QEMU
macsmc-parserat source identical toc9aa492328dcpassed 21/21, including the early-message case and the four main-branch WKTP cases. The previous38d93aa124a9J316s standard transport boot bound all six children, returned 142 readings and passed a short s2idle. See the exact receipts below.Risk: two-way door · any Mac using the Apple SMC, including Macs with the saved RTKit transport.
Not yet: Current-head saved-transport startup on J714s or J813, including normal sensor reads and event notifications. Current-head standard transport refresh on J316s or the closest shared Mac.
Evidence
The normal forward merge retains
main's wake-reason and WKTP changes and the original early-initialisation behavior. The QEMU test source and committed source differ only in.github/CODEOWNERS. The staged diff passed strict checkpatch with zero findings. The old standard-transport row is documented in this PR's comments and is the baseline for the refresh.