Skip to content

wifi: cfg80211: send the held-back scan message of a stale request - #2110

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
LiamRay11:j804/cfg80211-stale-scan
Dec 1, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
LiamRay11:j804/cfg80211-stale-scan

Conversation

@LiamRay11

@LiamRay11 LiamRay11 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A generic cfg80211 fix. If a netdev goes down while its driver is still scanning, every later scan and connect on that wiphy fails with -EBUSY until the driver is reloaded.

The bug

  • On NETDEV_DOWN, cfg80211 completes the scan with ___cfg80211_scan_done(rdev, false). That parks the result message in rdev->scan_msg and, because the driver still owns the request, only marks the request stale.
  • When the driver later calls cfg80211_scan_done(), the stale path frees the request and returns without queueing scan_done_wk. That work is the only place that sends and clears rdev->scan_msg.
  • The message stays forever, and nl80211_trigger_scan(), cfg80211_conn_scan() and the internal scans return -EBUSY while it is set.

The fix

Queue scan_done_wk from the stale path too, so the parked message is sent. A run queued this way may find that the message is already gone and a newer scan is running, so the work function now returns when there is no message to send and the current request has not been completed by the driver.

Testing

On hardware: MacBook Pro 14-inch (M6, J804), 2026-11-16, tested by LiamRay11.

  • What ran: kernel 7.3.0 built from integration/aurora bf423bf0e with all nine J804 linux PRs merged (t8152-mailboxes, dart-gen3, dt-board, centauri, g18-fast-retire, cfg80211-stale-scan, smc, cs42l84-jack, and an NVMe PR that is not sent yet), plus retest-only device-tree changes that are not part of these PRs: SSD nodes (ANS mailbox, SART, NVMe), PCIe port 0 with the N1 Wi-Fi, the USB0 gadget console, and a read-only NVRAM partition. Those nodes were needed to reach the root filesystem and SSH.
  • Booted through aura on the installed root filesystem. A systemctl reboot from this kernel (watchdog restart) returned to the installed system.

Results for this PR (smoke test only):

  • After a pm_test=devices suspend cycle, Wi-Fi stayed connected, a rescan listed 39 networks, and there were 0 CTRL-EVENT-SCAN-FAILED / -16 messages.
  • pm_test=devices does not take the interface down during a running scan, so it does not reproduce the lid-sleep race this fixes. That kernel did not carry the Centauri scan-abort changes either.

Earlier, with the Centauri driver on an older base (integration/aurora f5fa539): NetworkManager takes the interface down for a lid-close sleep while a wpa_supplicant scan runs. Without the fix, every scan after the wake failed with CTRL-EVENT-SCAN-FAILED ret=-16 until reboot. With the fix, Wi-Fi reconnected within 2 s after each of two lid sleeps. That run also had the Centauri scan-abort and interface-down handling, which is not upstream and not in this PR.

Checks on this base: net/wireless/scan.o builds with W=1 without warnings.

integration/aurora has since moved to 677be395b; this branch still merges into it without conflicts.

Notes for reviewers

  • NETDEV_DOWN also warns when a driver has not finished its scan, so the trigger here is partly a driver that does not abort its scan on ndo_stop. The cfg80211 state is still wrong afterwards: one late cfg80211_scan_done() should not wedge the wiphy.
  • This is core wireless code. It may belong on linux-wireless as well as, or instead of, this fork.

When a netdev goes down while its driver is still scanning,
NETDEV_DOWN completes the scan for cfg80211 with
___cfg80211_scan_done(rdev, false). That parks the result message in
rdev->scan_msg, to be sent once the driver is done, and, because the
driver still owns the request, only marks the request stale. When the
driver later calls cfg80211_scan_done(), the stale path frees the
request and returns without queueing scan_done_wk, the only place that
sends and clears rdev->scan_msg. The message then stays forever, and
nl80211_trigger_scan(), cfg80211_conn_scan() and the internal scans
all fail with -EBUSY while it is set: no scan or connect works on that
wiphy until the driver is reloaded.

Queue scan_done_wk from the stale path as well, so the parked message
is sent. Since a run queued this way may find that the message has
already gone out and a newer scan is in progress, make the work
function return when there is no message to send and the current
request has not yet been completed by the driver.

Seen on a MacBook Pro (M6, J804) with the Centauri driver, on an earlier
base (integration/aurora f5fa539): NetworkManager takes the interface
down for a lid-close sleep while a wpa_supplicant scan runs, and after
the wake every scan failed with "CTRL-EVENT-SCAN-FAILED ret=-16" until
reboot. With this change (and scan abort and interface-down handling in
that driver), Wi-Fi reconnected within 2 s after each of two lid sleeps,
with no failed scan.

Signed-off-by: LiamRay11 <[email protected]>

@sithglan sithglan 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.

Test report, 2026-11-17: Apple Mac mini M6 (J873g/T8152, board 0x24). PR revision tested: 517dd2f1d5602720d72b0b6d7eca3ce6d9a58012.

Host validation used the combined #2105–2108/#2110–2112 series (54742c617db4 on 677be395b9d2) with Clang 22. All changed driver objects built with W=1 and no new warnings; two pre-existing DART unused-helper warnings were unchanged.

net/wireless/scan.o built with Clang 22 and W=1 with no new warnings. This patch was also applied to the separate M6 hardware-test kernel; Wi-Fi scans completed successfully, returning 10 and 19 BSS entries in the two smoke runs.

The scan-versus-NETDEV_DOWN / held-back stale-request race was not deliberately triggered. This is build and ordinary scanning smoke coverage, not a reproduction of the race or proof that every ordering is fixed.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

The fix is right as far as I can see. Since dab68a7 ("wifi: cfg80211: don't free driver-owned scan requests"), NETDEV_DOWN parks the message in rdev->scan_msg (net/wireless/core.c:1786-1791, scan.c:1197-1198), and the stale path in cfg80211_scan_done() was the only completion left that did not queue scan_done_wk. That left scan_msg set for good, and nl80211.c:11300 and scan.c:3608/4091 return -EBUSY while it is set. The new early return in __cfg80211_scan_done() (scan.c:1214) cannot skip a normal completion, because the non-stale path sets notified before it queues the work (scan.c:1263-1264). It only skips a stale-path run that finds the message already sent and a newer request still with the driver. rdev is taken before the kfree(intreq), so there is no use after free at scan.c:1236-1243.

  1. Commit 517dd2f carries Co-Authored-By: Claude Opus 5.5 <[email protected]>. Drop it; the commit should have the human Signed-off-by only. For linux-wireless the sign-off also needs a real name rather than the GitHub handle. End the PR body with Assisted-by: LLM (<Vendor>:<Model>) instead of the "Generated with Claude Code" line.
  2. Nit: dab68a7 is upstream, so this regression is upstream too. A Fixes: dab68a74e90b ("wifi: cfg80211: don't free driver-owned scan requests") tag would let it go to linux-wireless and stable as a fix.

HW row: J804 with the Centauri driver on current integration/aurora plus this commit only (no driver scan-abort changes), default command line: take the interface down while a scan runs (e.g. iw dev wlan0 scan trigger; ip link set wlan0 down; ip link set wlan0 up, 20 iterations, then 5 lid-close sleeps under NetworkManager). Every later iw scan and the reconnect succeed, with 0 CTRL-EVENT-SCAN-FAILED ret=-16, 0 AVC denials, 0 failed units and 0 new kernel errors. Repeat the same loop without the commit to show the -EBUSY wedge.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train adversarial review (MERGETRAIN-LINUX2) at 517dd2f: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2110 wifi: cfg80211: send the held-back scan message of a stale request @517dd2f1

VERDICT: NO BLOCKERS

Code checks out:

  • NETDEV_DOWN (core.c:1786-1791) and p2p stop (core.c:271-274) call ___cfg80211_scan_done(rdev, false). That parks the message in rdev->scan_msg (scan.c:1197-1198) and, for a driver-owned request, only marks it stale (scan.c:1124-1125).
  • The stale branch of cfg80211_scan_done() (scan.c:1231-1245) now queues scan_done_wk. That work is the only place that sends and clears scan_msg (scan.c:1143-1147).
  • wiphy_work_queue is safe in the atomic context cfg80211_scan_done() may be called from.
  • The new early return in __cfg80211_scan_done() (scan.c:1214) cannot swallow a normal completion: the non-stale path sets notified before it queues (scan.c:1263-1264).
  • When both int_scan_req and scan_req go stale, the second queued run finds scan_msg NULL and scan_req NULL and returns at scan.c:1150. The 6 GHz split's second-part request is not yet notified, so a stray stale-path run leaves it alone.
  • rdev is taken before kfree(intreq).

Nits:

  • 517dd2f carries Co-Authored-By: Claude Opus 5.5 (already pushed). The sign-off is a handle, not a real name, as linux-wireless requires.
  • It should have Fixes: dab68a74e90b ("wifi: cfg80211: don't free driver-owned scan requests"). The bug is upstream, so this should also go to linux-wireless and stable.

Missing rows:

  • The race has never been reproduced on this base without the out-of-tree Centauri scan-abort changes. Needed: Ryan's row on J804 (scan trigger, then link down/up, 20 iterations plus 5 lid sleeps under NetworkManager, 0 ret=-16), and the same loop without the commit to show the wedge.
  • This is core cfg80211, used by brcmfmac on every M1-M4 Mac and MT7932 on Neo. Needed: one no-regression scan and ip link down mid-scan row on a brcmfmac Mac (M1 Pro or J616s) and on Neo.

@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 §1–§6 pre-PR review at verified live head 517dd2f1d5602720d72b0b6d7eca3ce6d9a58012 (base integration/aurora 70a00e583b03; not superseded; MERGEABLE/clean; live CI Host tests run 43992647221: PASS).

Technical Assessment (§1–§3, §6 Sound)

  • Correctness & concurrency (net/wireless/scan.c, +19/-1): Verified against live net/wireless/scan.c and net/wireless/core.c. NETDEV_DOWN (core.c:1786-1792) and P2P stop (core.c:271-276) call ___cfg80211_scan_done(rdev, false), parking the completion skb in rdev->scan_msg and marking a driver-owned request stale = true. Queueing wiphy_work_queue(&rdev->wiphy, &rdev->scan_done_wk) on the intreq->stale path in cfg80211_scan_done() closes the permanent -EBUSY/-EAGAIN wedge in nl80211_trigger_scan(), cfg80211_conn_scan(), and cfg80211_wext_siwscan():
    • rdev is captured from request->wiphy prior to kfree(intreq) (no UAF).
    • wiphy_work_queue() is atomic-context safe and runs __cfg80211_scan_done() under rdev->wiphy.mtx, guaranteeing serialization after NETDEV_DOWN stores rdev->scan_msg = msg.
    • The guard if (!rdev->scan_msg && req && !req->notified) return; in __cfg80211_scan_done() prevents a stray stale-path work run from prematurely completing a newly started scan (including part 2 of a WIPHY_FLAG_SPLIT_SCAN_6GHZ split scan) while never dropping a normal completion (which sets intreq->notified = true before queueing scan_done_wk).
  • §1 / §2 / §3 / §6: Generic cfg80211 fix, no model gating, default-cmdline safe, naming clean.

Blockers Before APPROVE

  1. §4 Attribution — AI commit trailer present (hard rule):
    • Commit 517dd2f1d560 carries Co-Authored-By: Claude Opus 5.5 <[email protected]>. Per §4, commits must carry human author/committer and human Signed-off-by: only, with zero AI commit trailers. Drop the Co-Authored-By: trailer from the commit, and replace the PR body's Generated with [Claude Code] footer with a plain Assisted-by: line.
  2. §5 Exact-head hardware reproduction & regression triad missing:
    • Neither the J804 pm_test=devices run nor the J873g smoke test actually triggered the NETDEV_DOWN-during-active-scan race on this head (the older f5fa539 run also carried out-of-tree Centauri scan-abort patches), and neither includes the §5 regression health triad (0 SELinux denials [or N/A], 0 failed units, 0 new kernel errors).
    • Because this changes core net/wireless/scan.c (shared by brcmfmac, mt7932, and centauri), please post an exact-head run on default cmdline (without out-of-tree scan-abort workarounds) reproducing ip link set <iface> down mid-scan -> link up -> subsequent scan/connect succeeding with 0 -EBUSY/CTRL-EVENT-SCAN-FAILED ret=-16 wedge, along with the §5 regression triad (0 SELinux denials, 0 failed units, 0 new kernel errors), and confirm or request a no-regression check on a brcmfmac / mt7932 Mac per §1.
  3. §6 CI coverage after re-push:
    • .github/workflows/mt7932-kunit.yml (which triggers on net/wireless/**) landed on integration/aurora after 517dd2f1d560; once re-pushed with the §4 fix, both Host tests and MT7932 KUnit must finish green.

Non-Blocking Note

  • Since upstream commit dab68a74e90b ("wifi: cfg80211: don't free driver-owned scan requests") introduced this behavior, adding a Fixes: tag (and using a real name in Signed-off-by:) will make upstreaming to linux-wireless/stable clean.

@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

@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: FINISH, then merge at 517dd2f1d560

Blockers:

  1. Commit 517dd2f1 carries a Co-Authored-By: trailer that names an AI tool. We keep tool attribution out of commits. The commands below drop that line only; your Signed-off-by stays. The row stays valid after that push, because the code doesn't change.
git fetch origin
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter "grep -viE '^(assisted-by:|(co-authored-by|signed-off-by):.*(claude|copilot|codex|gemini|cursor|openai|anthropic)|[^a-z]*generated with)' | git stripspace" origin/main..HEAD
git push --force-with-lease

Checked: no Apple material, no gates, generic cfg80211 fix. The stale path in cfg80211_scan_done() now queues scan_done_wk, and the new early return in __cfg80211_scan_done() can't skip a normal completion, because that path sets notified before it queues the work. Rows at this head on J873g (sithglan) and J804. CI green. This replaces my earlier review: the extra race-reproduction run and the regression checklist it asked for aren't needed to merge, and I removed the tool footer from the PR body myself.

Evidence

Read the diff against net/wireless/scan.c and core.c (NETDEV_DOWN and p2p stop park the message; the stale path was the only completion that never sent it). A run on a brcmfmac Mac is a check after the merge. Nit: a Fixes: dab68a74e90b tag would help upstreaming.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 18:51

Superseded by the review at 517dd2f

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 6c02e964: ready to merge

Check Detail
CI at head ok 3 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 6c02e964
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS
Merge: gh pr merge 2110 --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: approve at 6c02e964c9b0. The one blocker from my earlier review is fixed, so I'm dismissing it.

Fixed: the tool-attribution trailer. 6c02e964c9b0 is the same change with the Co-Authored-By: line removed and your Signed-off-by kept.

Code unchanged: it has the same parent (bf423bf0e42c) and the same tree (273cd4060218) as the reviewed 517dd2f1. So the J873g and J804 rows and my earlier read of cfg80211_scan_done()/__cfg80211_scan_done() still apply.

Checked: CI is green at this head (host tests, KUnit, pr-text, readiness), and the PR body carries no attribution.

Not blocking: a Fixes: dab68a74e90b tag would still help upstreaming.

Merging is left to the PR Merge Lane.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 26, 2026 23:39

Superseded by the review at 6c02e96

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, A18 Pro): forced scan abort with this fix

What was tested: this PR's diff (head 6c02e964) applied to main dbfbced7, built warm as cfg80211.ko (installed sha256 614b92a6) on the J700 kernel 7.3.0-neo-fence-kclean (Image sha256 a2c0a040). The head itself is about 4,000 commits behind main, so this is the change on current main, not the exact head. One-shot trial boot f2dd6de2; stock Fedora -41 restored and verified afterwards. Wi-Fi is mt7932-fullmac (wld0), which is also the Neo's only network link.

Before the abort: wld0 connected; two root scans returned 7 and 9 BSS. Boot error lines: 11, with 0 Wi-Fi and 0 PCIe (the stock boot has 12, 0 Wi-Fi, 0 PCIe).

The trigger, as in the PR: run from a detached root unit:

  1. iw dev wld0 scan trigger
  2. 0.3 s later, ip link set wld0 down while the scan runs
  3. ip link set wld0 up 3 s later

Results

  • NetworkManager reconnected within 1 s.
  • Three rescans in the next ~6 s returned -EBUSY (-16), while the reconnect and its own scan were still running.
  • A rescan about 20 s later succeeded with 12 BSS, and Wi-Fi stayed connected. The wiphy did not stay wedged, which is the bug this PR fixes.
  • 0 kernel lines, 0 errors and 0 PCIe lines after the trigger; 0 WARN, 0 AVC, 0 failed units.

Not covered: a stock-kernel run of the same trigger. If the bug reproduces there, it would cut the Neo's only network link until reboot. So this row shows that the fixed kernel recovers; it does not show that stock wedges.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 6c02e964c9b0 (B2 merge train, 12-01 merge bar). Approval at this head: DjDeveloperr. Row: J700 comment at 6c02e96. CI: linux train L1 = main 595e754 + #3503 #3499 #3240 #3208 #3696 #731 #2634 #2110 #3325 #3441 #3650 (candidate ef98b31c): Apple driver compile (defconfig + asahi.config, LLVM=1, Rust) pass, Apple DTBs W=1 pass, planned KUnit clpc/dcp-fabric/dcp-topology/dcp-display/pmgr-pwrstate/mt7932/asahi all pass; host-tests green (or path-skipped) at this head. The rest of the hosted run is queued behind the ~19 h backlog. Revert: git revert -m 1 <merge commit>.

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

Labels

needs-template PR body lacks Tested or 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.

4 participants