Skip to content

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

Open
axboe wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
axboe:centauri-attach-unlocked
Open

axboe wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
axboe:centauri-attach-unlocked

Conversation

@axboe

@axboe axboe commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

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.

The deadlock (stacks from a K116s, T6050, firmware 27.2):

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

Fix. Take a reference to the Beta function under the lock and call device_attach() after dropping it. 17 lines added, 6 removed, one file.

Reproduce. Two RTC deep sleeps back to back, the second started as soon as the first returns:

rtcwake -d rtc1 -m mem -s 40; rtcwake -d rtc1 -m mem -s 40

Without the fix the second rtcwake hangs every time (1 of 1 here, and it matches a lid-closed hang from the night before). Closing the lid a few seconds after a wake does the same.

Testing. K116s, 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.
  • 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.
  • centauri-recovery-tests.py, centauri-bt-arena-tests.py and centauri-wifi-pm-tests.py pass on this branch.

Not tested on a J714s or J716c; the three code paths are the same there.

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

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.

Fixes: 0a2d99d ("PCI: apple: T6050: look for a parked port's functions from a work")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
@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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants