Skip to content

wifi: apple: centauri: attach the Beta function outside the rescan lock and boot_lock - #2206

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
axboe:centauri-attach-unlocked
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
axboe:centauri-attach-unlocked

Conversation

@axboe

@axboe axboe commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A suspend that starts while the N1 is still coming up after a wake never finishes. The machine stays up with the suspend stuck, and no watchdog fires, because the sleep's WD2 is not armed yet. Seen on a K116s (T6050, M5 Pro), firmware 27.2: two RTC deep sleeps back to back do it every time, and a lid closed again a few seconds after a wake does too.

  • The suspend runs the PM notifiers. apple_pcie_t6050_pm_notify() calls flush_work() on the host's unpark work.
  • That work is in apple_pcie_t6050_cold_rescan(), waiting in pci_lock_rescan_remove().
  • centauri_t6050_start_ipc() holds the rescan lock while it attaches the Bluetooth function's driver. cen_probe() → hci_register_dev() → register_pm_notifier() waits to write the notifier chain the suspend is reading.

The boot worker's boot_lock has the same problem one step removed, and lockdep reports it at the first deep sleep: the attach ran under boot_lock, the PCIe host's PM notifier takes the rescan lock, and the rewake worker takes boot_lock in centauri_t6050_quiesce() with the rescan lock held.

&c->boot_lock --> (pm_chain_head).rwsem --> pci_rescan_remove_lock

Fixes: 0a2d99d ("PCI: apple: T6050: look for a parked port's functions from a work")

Change

centauri_t6050_start_ipc() takes a reference to the Beta function under the rescan lock and hands it back; the boot worker calls device_attach() after it has dropped both the rescan lock and boot_lock. One commit, three files, 28 lines added, 9 removed. Affects every machine with the N1 (T6050).

Testing

Tested: K116s (T6050, M5 Pro), firmware 27.2, with and without lock checking; rows below. Host tests 503/503 and centauri-t6050-probe.py at the head.

Risk: two-way · T6050 machines with the N1 (J714s, J716c, K116s).

The K116s does not sleep on main alone, so the rows are on a stack that contains this commit unchanged: main + #2187 + #2201 + #2309 + #2877 + #3065 + my other K116s commits. The command line is not the default (idle=nop among others).

Kernel Lock checking Result
stack with the first version of this commit (rescan lock only) on, with #3065 the boot_lock report above at the first deep sleep
stack with this commit on, with #3065 boot (Beta function bound to btcentauri_t6050) and 4 deep sleeps on one boot, 0 lockdep reports, debug_locks: 1 at the end, Wi-Fi back after each
stack with this commit off boot and deep sleep, resumed, Wi-Fi back
Rows for the first version (rescan lock only), integration/aurora 0abc2f3 plus my K116s series
  • 4 of 4 back-to-back 40 s deep sleeps resume on the same boot; Wi-Fi up and hci0 present after each. Without the fix the second rtcwake hangs every time.
  • With 15 s alarms the entry of a sleep that overlaps the N1's start is refused cleanly at the final check (-ETIME), as intended.
  • A suspend that overlaps the attach logs Beta driver attachment failed: -517; the deferred probe binds the function after the wake.

Still to run

  • J714s and J716c: not run here; the three code paths are the same there.

  • Lock checking only survives a T6050 deep sleep with T6050 sleep: two lock checking reports at the first deep sleep #3065.

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

  • No chip/board/firmware-version gate where a hardware property can decide

  • 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

@RyanTheTide

Copy link
Copy Markdown
Contributor

No blockers.

Checked drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c at the head: the Beta function is pinned with pci_dev_get() under the rescan lock and attached after pci_unlock_rescan_remove() (line 486), so the boot worker no longer holds the rescan lock while cen_probe() waits in register_pm_notifier(). The unlocked window is safe against teardown: centauri_t6050_quiesce() clears c->ready and then cancel_delayed_work_sync(&c->boot_work) waits for the attach, cen_probe() (drivers/bluetooth/btcentauri_t6050.c:951) defers once apple_centauri_control_ready() is false, and device_attach() itself refuses a device that device_del() already killed. Nothing in cen_probe() takes the rescan lock or F0's device lock, so the rewake teardown (which waits on the boot work under the rescan lock) cannot deadlock against it either. The return value is 0 on the attach path as before.

HW row: K116s on this branch with CONFIG_PROVE_LOCKING, 10 back-to-back rtcwake -d rtc1 -m mem -s 40 pairs: all resume, no lockdep splat, Wi-Fi and hci0 up after each; plus the regression summary for that boot (0 AVC denials, 0 failed units, 0 new kernel errors). A J714s or J716c run would cover the other boards with this radio.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Moving attachment out of the rescan lock is still needed. This head replays cleanly onto integration/aurora 5441428d9033, and the T6050 Centauri IPC object builds for arm64. The K116s suspend/resume row with lock checking remains open.

@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 pre-PR §1–§6 review at caa54bfba018 against integration/aurora tip 70a00e583b03: REQUEST_CHANGES.

Code, Concurrency & Supersession Audit

  • Not superseded: Even after commit b8fce260d6be (N1 keep-alive deep sleep), live drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c:453 still calls device_attach(&ipc->function[2]->dev) while holding pci_lock_rescan_remove(). The lock-order inversion with apple_pcie_t6050_pm_notify() -> flush_work(&pcie->t6050_unpark_work) -> apple_pcie_t6050_cold_rescan() -> pci_lock_rescan_remove() still exists on boot and on any fallback warm-reset sleep/recovery path.
  • §1–§3 (Concurrency / lifetimes / error paths): Clean.
    • centauri_t6050_start_ipc_locked() pins ipc->function[2] with pci_dev_get() before pci_unlock_rescan_remove(), and centauri_t6050_start_ipc() calls device_attach(&beta->dev) outside the rescan lock followed by pci_dev_put(beta).
    • Error paths preserve exact return values when beta == NULL (-ECANCELED, -EBUSY, -ENOMEM, etc.) and return 0 with the existing warning when device_attach() fails.
    • Teardown/removal races are safe: centauri_t6050_quiesce() clears c->ready (smp_store_release) and drains cancel_delayed_work_sync(&c->boot_work); cen_probe() (drivers/bluetooth/btcentauri_t6050.c:956) returns -EPROBE_DEFER when apple_centauri_control_ready() is false and takes neither the rescan lock nor F0's device_lock; centauri_t6050_prepare() serializes suspend behind c->boot_lock; and device_attach() safely skips a device_del()'d beta.
  • §4 (Attribution): Clean — human author/committer and human Signed-off-by: Jens Axboe <axboe@kernel.dk> only, zero AI commit trailers.
  • §6 (CI & naming): Live CI is green (host-tests run 44377640166).

Blockers

  1. §5 (Exact-head regression & lockdep evidence on current tip): The K116s suspend/resume test results were run on 0abc2f385e54 (prior to b8fce260d6be, which substantially changed centauri_pci.c/centauri_ipc.c/btcentauri_t6050.c deep sleep) and omit the required §5 regression summary. Please post an exact-head K116s test run (with CONFIG_PROVE_LOCKING exercising back-to-back suspend/resume including fallback/boot attach) plus the full regression pass (0 SELinux denials, 0 failed units, 0 new kernel errors).

Assisted-by: LLM (Gemini 4 Neon)

@axboe

axboe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

K116s row with lock checking, as far as it goes.

Kernel: integration/aurora 1b1304f + #2201 v9 + #2877 + my other K116s commits, with CONFIG_PROVE_LOCKING=y (7.3.0-m5pro-lockdep-g0775bf2adc57). It carries this PR's commit unchanged (same diff as caa54bf). Not this exact head standalone: the K116s does not sleep without #2201.

  • Boot, with the Beta function attached from the boot work: 0 lockdep reports.
  • First deep sleep (raw rtcwake -m mem, Wi-Fi associated, so the warm-reset path): no report from the Wi-Fi, Bluetooth or PCI side up to the point below.
  • That is where lockdep stops being useful on this machine. The first sleep trips two reports in integration's own sleep code, and lockdep turns itself off (debug_locks: 0):
    • BUG: workqueue leaked atomic, lock or RCU, with &dart->v27_lifecycle held from apple_dart_v27_claim() when the async suspend work returns.
    • RCU not watching for tracepoint at the mutex_trylock() in apple_spmi_fifo_trylock(), called from t6050_sleep_check_alarm() inside cpu_suspend().
  • So the resume side and every later sleep ran without lock checking. Five sleep entries on that boot, all resumed, Wi-Fi back, 0 failed units.

Neither report is this PR's. Until those two are sorted, a PROVE_LOCKING run on a T6050 covers the boot and the first suspend's entry, nothing after it. Without lock checking this commit has been in my daily kernel for five days.

@github-actions github-actions Bot added 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
…ck and boot_lock

centauri_t6050_start_ipc() holds the PCI rescan lock while it attaches
the Bluetooth function's driver, whose probe registers a PM notifier.
A suspend that starts while the N1 is still coming up after a wake
then never finishes:

- the suspend runs the PM notifiers; the PCIe host's flushes its
  unpark work,
- that work waits for the rescan lock in its cold rescan,
- the boot worker holds the lock and waits, in hci_register_dev(),
  to write the notifier chain the suspend is reading.

Nothing has armed the sleep's watchdog yet, so the machine stays up
with the suspend stuck. On a K116s, two RTC deep sleeps back to back
do it every time; a lid closed again a few seconds after a wake does
too.

Take a reference under the lock and attach after dropping it.

The boot worker's boot_lock has the same problem one step removed. The
attach ran under it, the PCIe host's PM notifier takes the rescan lock,
and the rewake worker takes boot_lock in centauri_t6050_quiesce() with
the rescan lock held. Lockdep reports it at the first deep sleep:

  &c->boot_lock --> (pm_chain_head).rwsem --> pci_rescan_remove_lock

So the boot worker attaches after it has dropped boot_lock as well.

Fixes: 0a2d99d ("PCI: apple: T6050: look for a parked port's functions from a work")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
@axboe axboe changed the title wifi: apple: centauri: attach the Beta function outside the rescan lock wifi: apple: centauri: attach the Beta function outside the rescan lock and boot_lock Nov 24, 2026
@axboe
axboe force-pushed the centauri-attach-unlocked branch from caa54bf to cbc00ab Compare November 24, 2026 13:04
@axboe
axboe requested review from a team as code owners November 24, 2026 13:04
@axboe
axboe requested review from LiamRay11 and malik-na November 24, 2026 13:04
@axboe

axboe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

v2 pushed (cbc00ab), rebased onto main 974efa5.

The lockdep row above stopped at the first sleep because of two reports in the sleep code. With those fixed (#3065) lockdep kept running and reported one more cycle, this one in this PR's area: the attach was still under the boot worker's boot_lock, and the rewake worker takes boot_lock with the rescan lock held. v2 moves the attach out from under boot_lock as well.

With v2 and #3065, CONFIG_PROVE_LOCKING=y: boot plus 4 deep sleeps on one boot, 0 lockdep reports, debug_locks: 1 at the end. The description has the rows and the new format.

@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-hw-row No hardware row at the PR head (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 cbc00abf: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at cbc00abf
Conflicts ok none
PR text ok Risk: two-way · T6050 machines with the N1 (J714s, J716c, K116s). - cbc00abf1689 T6050 / K116s (M5 Pro), firmware 27.2: booted on a stack that contains this change, there as the first version of the commit plus the boot_lock part on top (the surrounding code differs with #2877, so the commit is not byte-identical) (main 974efa5 + #2187 + #2201 v10 + #2309 + #2877 + the lock fixes + my other K116s commits, 7.3.0-m5pro-ge3fa7f0044df); 3 deep sleeps resumed on the same boot (raw rtcwake -m mem with Wi-Fi associated, logind suspend with an RTC alarm, raw rtcwake -m mem with Wi-Fi disconnected), panel and Wi-Fi back each time; 0 SELinux denials (not installed on this Debian), 0 failed units, 0 error-level kernel lines at boot, 0 new kernel errors at the wakes. The K116s does not sleep on main alone, so the rows are on a stack that contains this commit unchanged: main + #2187 + #2201 + #2309 + #2877 + #3065 + my other K116s commits. The command line is not the default (idle=nop among others).

Areas: none matched in CODEOWNERS
Merge: gh pr merge 2206 --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: MERGE at cbc00abf1689

Blockers: none

Checked: Full v2 diff (+28/-9, 3 files) against main (0a7dcb396537), rescan/boot_lock/refcount/teardown/suspend concurrency, and §1–§6 pre-PR checklist. Prior §5 blocker is resolved by the updated K116s CONFIG_PROVE_LOCKING=y and regression runs at cbc00abf1689, and moving device_attach() outside boot_lock fixes the lockdep cycle surfaced by lock checking.

Evidence
  • Locking & lifetimes (centauri_ipc.c:454,471-495, centauri_pci.c:458,477,500-501): centauri_t6050_start_ipc_locked() pins ipc->function[2] with pci_dev_get() under pci_lock_rescan_remove() after smp_store_release(&c->ready, true). centauri_t6050_boot_worker() initializes beta = NULL, transitions to CEN_BOOT_READY on success, drops both pci_rescan_remove_lock and c->boot_lock, and then calls centauri_t6050_attach_beta(c, beta) which always pairs pci_dev_put(beta). Teardown/removal races stay safe: centauri_t6050_quiesce() clears c->ready and drains cancel_delayed_work_sync(&c->boot_work), cen_probe() defers once apple_centauri_control_ready() is false, and dpm_prepare()'s device_block_probing() defers overlapping probes cleanly to dpm_complete(). (Minor non-blocking note: centauri_t6050_start_ipc() relies on caller-initialized *beta = NULL, which holds for its sole caller centauri_t6050_boot_worker().)
  • §1–§3 (No model gating / production-ready / safety): No chip/board/firmware gates, no cmdline/module params or hacks, DMA fencing and refcount pairing preserved.
  • §4 (Attribution & clean-room): Single commit cbc00abf1689, human author/committer and Signed-off-by: Jens Axboe <axboe@kernel.dk>, verified Fixes: 0a2d99d4ae30, clean PR title/body.
  • §5 (CI & HW evidence at head): host-tests (run 45399655802) and pr-text (run 45399657197) both green at cbc00abf1689. K116s (T6050, fw 27.2) tested at cbc00abf1689 both with CONFIG_PROVE_LOCKING=y (+ #3065: boot with Beta bound to btcentauri_t6050 + 4 deep sleeps, 0 lockdep reports, debug_locks: 1, Wi-Fi back each time) and without lockdep (3 deep sleeps across associated/logind/disconnected states, 0 SELinux denials, 0 failed units, 0 boot/wake kernel errors).
  • §6 (Naming): Clean across diff, commit, PR title, and PR body.

@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) ready-to-merge Meets the merge policy: merge it (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr merged commit 60d9996 into aurora-silicon:main Nov 24, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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