Skip to content

wifi/Bluetooth: apple: centauri: fix scan lock stalls, abort sync, and BT ring drain - #3120

Merged
DjDeveloperr merged 3 commits into
mainfrom
fix/centauri-scan-reliability
Nov 25, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
fix/centauri-scan-reliability

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Risk: two-way · Apple N1 / Centauri Wi-Fi and Bluetooth (T6050, T8142, T8152)

What:
Fixes live-reproduced Wi-Fi scan flakiness and a Bluetooth ring-drain stall window across Apple Centauri / N1 drivers:

  1. Release wifi->lock during scan polling & skip firmware link queries mid-scan (drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c, drivers/net/wireless/apple/centauri/centauri_wifi.c):
    • scan_profile27() (T6050) and scan_worker() (shared T8142/T8152) previously held wifi->lock across the entire multi-second scan while sleeping in usleep_range(1000, 2000). Any concurrent cfg80211 query (wifi_get_station() / iw link / NetworkManager signal polling) took wiphy->mtx and blocked on wifi->lock for seconds, stalling nl80211 scan aborts and rapid re-triggers (-EBUSY).
    • Release wifi->lock around usleep_range(1000, 2000) and re-check teardown/transport state (stopping, command_failed, host_sleep_sent / transport_paused, BAR status) after re-acquiring the lock before calling drain(), before starting each chunk, on scan_stop_chunk() entry, and after wait loops exit at deadline.
    • In T6050 fill_station(), skip synchronous firmware query_link_status() while wifi->scan_request is active, returning the cached signal and live netdev counters immediately.
  2. Synchronize scan-stop completion & clear stale disconnect latches before join (t6050/centauri_wifi.c, centauri_wifi.c):
    • Add scan_stop_chunk() (and scan_wait_stop() in shared centauri_wifi.c) so command 65537 scan stops on abort and timeout wait up to 1000 ms for the firmware's 0x80000005 completion event (treating firmware status 342 as already stopped), including when scan_abort arrives after a stop was already sent (stopped == true), and propagate stop errors/timeouts instead of continuing to the next chunk.
    • In connect_worker() on both drivers, drain and clear connect_event/disconnect_event after host_setup_commands() immediately before issuing join command 131072 so a stale pre-join disconnect event cannot abort a new association with -ENOTCONN.
  3. Reschedule Bluetooth io_work when ring work remains (drivers/bluetooth/btcentauri_t6050.c):
    • cen_io_work() previously took a single cen_tail() snapshot per ring with a fixed CEN_RX_SLOTS budget and returned without re-checking whether new RX descriptors arrived or TX slots freed up.
    • Add cen_rx_pending() and cen_tx_ready() checks before exiting cen_io_work(), rescheduling io_work whenever open RX rings (aux, LE ring 10, HCI event ring 7) have unread descriptors or non-empty TX queues have free slots.
  4. Host tests (tools/asahi/centauri-scan-tests.py, registered in tools/asahi/run-host-tests.py):
    • Compiles production functions from T6050 Wi-Fi (scan_transport_stopped, scan_stop_chunk, scan_profile27, fill_station), shared Wi-Fi (scan_transport_stopped, scan_wait_stop, scan_stop_chunk, scan_worker), and T6050 Bluetooth (cen_rx_pending, cen_tx_ready, cen_io_work) and exercises lock release, station queries mid-scan, guarded stop entry / timeout exit, chunk error propagation, post-stop abort wait, and BT RX/TX rescheduling, plus 9 negative controls.

Tested:

  • Host unit tests on 1620c5f2a3fbea582596d94fd3a0480f7a6cecb9: python3 tools/asahi/run-host-tests.py --only centauri — 18/18 passed (including 9/9 negative controls in centauri-scan-tests.py).
  • Style check: scripts/checkpatch.pl --strict --git origin/main..HEAD — 0 errors, 0 checks (0 warnings on 1620c5f2a3fb).
  • Hardware verified on Apple M5 Pro (J714s, commit 1620c5f2a3fbea582596d94fd3a0480f7a6cecb9, kernel 7.3.0-m5-censcan2 with MTE on, SEP active, default cmdline; baseline 7.3.0-m5-cdirect15; verified running module SHA256s match module-manifest.txt):
Check (wlp1s0f0 / hci0) Before (7.3.0-m5-cdirect15) After (7.3.0-m5-censcan2, 1620c5f2a3fb)
iw link during active scan (5×) 2,758 ms stall 1–2 ms (5/5 passed, max 2 ms, live -49 dBm)
scan abort + immediate re-trigger (5×, 0.1–3.0 s) 2,166 ms abort stall, next trigger -EBUSY (-16) 1–2 ms abort (max 2 ms), 5/5 immediate scan flush passed (0 -EBUSY, 17–18 BSSes)
Back-to-back Wi-Fi scans 20/20 (18–20 BSSes) 10/10 (19–20 BSSes, 4,731–5,336 ms, 0 errors)
Bluetooth scans (LE + interleaved) 10/10 (33–36 unique) 6/6 (3× LE: 38 unique; 3× interleaved: 37–39 unique)
Concurrent Wi-Fi + BT scans (3×) — 3/3 passed (6/6 Wi-Fi 17–19 BSSes + 3/3 BT 38 unique)
Post-sleep (RTC0 +26 s, WoWLAN any) Wi-Fi + BT — Stayed connected (Welcome 89), post-wake Wi-Fi scan flush rc=0 (14 BSSes) + BT btmgmt find -l rc=0 (38 unique)
High-rate 5 s raw BLE scan (Filter_Duplicates=0) + HCI pings 94.0 ext_adv/s, 42/42 CC 109.0 ext_adv/s (545 in 5 s), 24/24 HCI Command Completes
Centauri / Bluetooth kernel errors (dmesg) — 0
  • GPU liveness on 7.3.0-m5-censcan2 (1620c5f2a3fb): vulkaninfo + gpubench-vk compute.light passed before (108.99 us) and after (108.64 us), 0 faults.
  • Restored J714s ESP byte-identically to 7.3.0-m5-cdirect15, verified GPU alive, cleaned temporary build/module artifacts, and released hw.

…stop

scan_profile27() on T6050 and scan_worker() on T8142/T8152 held wifi->lock
across the multi-second scan polling loop. Any concurrent cfg80211 station
query (such as NetworkManager or iw link polling while holding wiphy->mtx)
blocked on wifi->lock for the entire scan, stalling nl80211 operations
including scan abort and causing -EBUSY failures on rapid rescan or
connect. In addition, scan abort/timeout paths returned without waiting for
the firmware's 0x80000005 stop completion event, allowing stale completions
to terminate a subsequent scan early, and connect_worker() could latch a
stale disconnect event drained during host_setup_commands().

Release wifi->lock around the polling sleep in both drivers' scan loops
while re-checking stopping, command_failed, sleep/pause flags and Alpha
stage before touching the transport. Skip synchronous firmware link-status
queries in T6050 fill_station() while a scan is active so station queries
return cached signal and live counters without contending with off-channel
dwells. Synchronize command 65537 scan stops with a bounded wait for
0x80000005 (treating status 342 as already stopped), and drain and clear
stale connect/disconnect event flags right before sending the join command
in connect_worker().

Signed-off-by: Diljit Singh <[email protected]>
Unlike the polling btcentauri transport, btcentauri_t6050 relies on MSIs
and TX submission kicks to run cen_io_work(). cen_io_work() snapshotted
each RX ring tail once and drained at most CEN_RX_SLOTS entries without
checking whether more descriptors had arrived during drain or whether a
non-empty TX queue could now publish into a freed TX ring slot. Under
advertising bursts or coalesced interrupts, unread events or queued frames
could sit in the rings until an unrelated wakeup.

Re-check all open RX ring tails and pending TX queues with available ring
space before leaving cen_io_work(), rescheduling io_work when work remains.
Add host unit tests and negative controls in
tools/asahi/centauri-scan-tests.py covering both Wi-Fi scan lock/stop
synchronization and Bluetooth ring drain rescheduling.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 03:41
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 1620c5f2: ready to merge

Check Detail
CI at head ok 3 checks passed
Review ok review verdict MERGE at 1620c5f2; no GitHub approval yet, so approve it or merge through the bypass (--admin)
Requested changes ok none
Hardware row at head ok comment at 1620c5f2
Conflicts ok none
PR text ok Risk: two-way · Apple N1 / Centauri Wi-Fi and Bluetooth (T6050, T8142, T8152)

Areas: area:gpu
Merge: gh pr merge 3120 --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.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

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 e0d3171c5b11

Blockers:

  1. drivers/net/wireless/apple/centauri/centauri_wifi.c:916-921,1022-1033 and drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c:1143-1149,1269-1278: On the final iteration of the wait loop, when jiffies >= deadline right after mutex_unlock(&wifi->lock); usleep_range(1000, 2000); mutex_lock(&wifi->lock);, the loop exits without re-checking stopping, transport_paused, command_failed, host_sleep_sent, or readl(wifi->a.bar + 8) != 2 (and without one final drain(wifi)), then immediately calls scan_stop_chunk(wifi, done). scan_stop_chunk() calls command(wifi, 65537, NULL, 0) directly, and neither command_control() (centauri_wifi.c:737-766) nor command_reply() (t6050/centauri_wifi.c:764-810) checks READ_ONCE(wifi->stopping) or readl(wifi->a.bar + 8) != 2 before publishing a TX descriptor, advancing command_head, writing index_write, and ringing writel(1, wifi->a.bar + 0x1004) (in t6050/centauri_wifi.c:812-814, command_reply() then faults the transport after already ringing the doorbell). Fix: guard the entry of scan_stop_chunk() in both drivers with the same stopping/transport_paused/command_failed/host_sleep_sent/readl(wifi->a.bar + 8) != 2 check before calling command(wifi, 65537, NULL, 0), and re-check state (and drain once) after the timeout loop exits before issuing the stop/warning.
  2. drivers/net/wireless/apple/centauri/centauri_wifi.c:958,1031-1033: scan_worker() discards the return value of scan_stop_chunk(wifi, done) on chunk timeout, leaving ret == 0. If scan_stop_chunk() returned -EIO (because stopping, transport_paused, or bar + 8 != 2 triggered during its unlocked wait) or -ETIMEDOUT, the outer for (chunk = 0; chunk < chunks && !ret; chunk++) loop proceeds directly to the next chunk and calls command(wifi, 65551, scan, scan_size) without checking stopping, transport_paused, or scan_abort. Fix: capture ret = scan_stop_chunk(wifi, done) (or propagate non-zero errors/timeouts) and check stopping/transport_paused/scan_abort before starting each chunk.
  3. drivers/net/wireless/apple/centauri/centauri_wifi.c:993-998,1007-1020: If the chunk already sent command(65537) at line 1012 (stopped = true, extending deadline by 1000 ms to wait for 0x80000005), and wifi->scan_abort becomes true before 0x80000005 arrives, if (!stopped) skips waiting for the in-flight stop completion and breaks immediately with -ECANCELED, leaving 0x80000005 unconsumed for the next scan. Fix: factor out the post-stop wait for wifi->scans_done != done so the abort path still waits for the already-issued stop's 0x80000005 completion (stopping early if stopping/transport_paused/bar + 8 != 2).
  4. PR readiness metadata: the J714s hardware evidence row currently cites 7.3.0-m5-censcan without the exact head commit SHA (e0d3171c), which is why pr-readiness is failing.

Checked: full source audit of drivers/net/wireless/apple/centauri/centauri_wifi.c, drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c, drivers/bluetooth/btcentauri_t6050.c, and tools/testing/selftests/drivers/net/apple/centauri-scan-tests.py; checked lock-drop concurrency windows, teardown/suspend races, ring drain safety, and zero board/model gating.

Evidence
  • drivers/bluetooth/btcentauri_t6050.c (cen_rx_pending(), cen_tx_ready(), cen_io_work()) audited clean: cen_aux_start() opens required rings 2 & 8 whenever bt->running is set, cen_io_work() checks !bt->running || transport_paused under bt->lock, and cancel_work_sync() tears down cleanly on close/suspend/remove.
  • In both Wi-Fi drivers, the do { ... mutex_unlock(); usleep_range(); mutex_lock(); } while (time_before(jiffies, deadline)); pattern creates a post-sleep exit path with no state check before scan_stop_chunk() rings BAR + 0x1004 via command(65537).
  • In centauri_wifi.c:1031-1033, ignoring scan_stop_chunk()'s return value allows scan_worker() to enter the next chunk after -EIO or -ETIMEDOUT.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 25, 2026
… wait

Address post-sleep unlock window races across both the T6050 and shared
Centauri Wi-Fi scan loops:

- Guard scan_stop_chunk() entry in both drivers with the transport state
  check before issuing command 65537, and re-check transport state plus
  one final drain() after the scan/stop wait loops exit at deadline.
- In shared centauri_wifi.c scan_worker(), propagate scan_stop_chunk()
  errors/timeouts to ret and check transport/abort state before starting
  each subsequent chunk.
- Factor out scan_wait_stop() in shared centauri_wifi.c so an abort
  arriving after command 65537 was already sent still waits for the
  in-flight 0x80000005 completion unless the transport stops.
- Extend tools/asahi/centauri-scan-tests.py to cover all three races
  against both drivers' production functions and add negative controls.

Signed-off-by: Diljit Singh <[email protected]>

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: MERGE.

Blockers: none.

Checked: Re-reviewed commit 1620c5f2a3fb across drivers/net/wireless/apple/centauri/centauri_wifi.c, drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c, drivers/bluetooth/btcentauri_t6050.c, and tools/asahi/centauri-scan-tests.py, verified all four prior blockers are resolved, executed tools/asahi/centauri-scan-tests.py --negative-controls at this exact head, and confirmed all 3/3 CI checks (host-tests, readiness, pr-text) are green.

Evidence
  • All prior blockers resolved at 1620c5f2a3fb:
    • scan_transport_stopped() now guards scan_stop_chunk() entry before command(65537) in both drivers, and both wait loops re-check transport state plus run a final drain(wifi) after exiting at deadline.
    • centauri_wifi.c scan_worker() checks scan_transport_stopped() and scan_abort before each chunk, propagates ret = stopped ? -ETIMEDOUT : scan_stop_chunk(wifi, done), and computes info.aborted from !!ret || scan_abort || stopping.
    • centauri_wifi.c abort handling now calls scan_wait_stop(wifi, done) when stopped == true so an in-flight 65537 stop still consumes its 0x80000005 completion (exiting early with -EIO if transport stops).
    • PR readiness metadata updated cleanly (readiness / readiness and pr-text / pr-text both green).
  • Local host-test & negative-control run (tools/asahi/centauri-scan-tests.py --negative-controls at 1620c5f2a3fb):
    • wifi-production: PASS, shared-wifi-production: PASS, bt-production: PASS.
    • All 9/9 negative controls (scan-holds-lock-in-sleep, station-queries-fw-during-scan, timeout-skips-stop-wait, abort-ignores-342, t6050-stop-skips-entry-guard, shared-timeout-drops-stop-ret, shared-abort-skips-inflight-stop-wait, bt-drops-rx-reschedule, bt-drops-tx-reschedule) correctly rejected.
  • CI at head 1620c5f2a3fb: 3/3 green (host-tests, readiness / readiness, pr-text / pr-text).

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@satchlj Addressed all 4 review items in follow-up commit 1620c5f2a3fbea582596d94fd3a0480f7a6cecb9:

  1. Guarded scan_stop_chunk() entry and timeout exit (both drivers): Added scan_transport_stopped() entry checks in scan_stop_chunk() before issuing command 65537, and re-checked transport state plus one final drain(wifi) after the scan/stop wait loops exit at deadline in both drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c and drivers/net/wireless/apple/centauri/centauri_wifi.c.
  2. Propagated stop errors & guarded chunk starts (centauri_wifi.c): Captured ret = stopped ? -ETIMEDOUT : scan_stop_chunk(wifi, done) on chunk timeout and checked scan_transport_stopped(wifi) / scan_abort before starting each chunk in scan_worker().
  3. Waited for in-flight stop on late abort (centauri_wifi.c): Factored out scan_wait_stop() so an abort arriving after command(65537) was already issued (stopped == true) still waits for the in-flight 0x80000005 completion (exiting early with -EIO if the transport stops).
  4. Tests & exact-head J714s verification: Extended tools/asahi/centauri-scan-tests.py to compile and test shared centauri_wifi.c alongside T6050 Wi-Fi/BT for all three races (run-host-tests.py --only centauri: 18/18 passed, 9/9 negative controls; checkpatch.pl --strict: 0 errors/0 warnings on 1620c5f2a3fb), re-verified live on J714s (7.3.0-m5-censcan2 at 1620c5f2a3fb: iw link mid-scan 1–2 ms, scan abort 1–2 ms + 5/5 scan flush, 10/10 Wi-Fi, 6/6 BT, 3/3 concurrent Wi-Fi+BT, RTC0 +26 s post-sleep Wi-Fi+BT, 109.0 ext_adv/s + 24/24 CC, 0 Centauri/BT kernel errors), and updated the PR **Tested:** section with the exact head SHA.

@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-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@DjDeveloperr
DjDeveloperr merged commit 4d8a19b into main Nov 25, 2026
5 of 6 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/centauri-scan-reliability branch November 25, 2026 05:10
m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 25, 2026
Resolve the scan_worker conflict with aurora-silicon#3120's scan stop guards: a
stopped transport asks for recovery only when the driver isn't
stopping or paused and Alpha isn't at its run stage.

Signed-off-by: Nick <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) 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.

2 participants