Repository navigation
wifi: brcmfmac: msgbuf: send from pages that hold only transmit buffers - #3210
Conversation
A frame to send was mapped where the stack left it, in an skb head that shares its page with other kernel memory. The IOMMU maps the whole page, 16 KiB with 16K pages, so the device could read whatever else was in it. Copy each frame, after the Ethernet header that goes in the descriptor, into a buffer from a pool of pages that hold only transmit buffers and stay mapped to the device for reading. There is one buffer per transmit packet id, so as many frames can be in flight as before. One copy now replaces the map and unmap of every sent frame. A frame too long for a buffer, which the MTU does not allow, is dropped and counted. The receive pool code is now shared by both directions. The pools also track in host memory which buffers are posted, so a completion that names a buffer already returned cannot return it twice. Signed-off-by: Dj <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Update: the repeat runs show no post-sleep TX drop. The candidate's 188.8 Mb/s after sleep in the single run below was radio variance. Code tested: #3205 at How it was run: two more guarded one-shots on the default cmdline, the same day on the same Mac and the same 5 GHz access point (5785 MHz).
The order was AB (control boot, then candidate boot), not ABBA. Each boot ran:
Figures are Mb/s.
The 50 MB round right after wake: TX 249.6 (control) vs 245.6 (candidate), RX 194.0 vs 203.3. Each arm has one or two dips of 15–30 % in either direction; the candidate's lowest single round is before sleep. The candidate's medians are 3–7 % lower in three of the four columns, but there's only one boot per arm (AB, not ABBA) and single rounds swing far more than that, so I wouldn't read it as a regression. Post-sleep TX medians are equal. Health:
Both boots returned to the stock kernel, and the kits were removed from the Mac. Earlier run (single rounds): J773g (M4 Mac mini, BCM4388) at How it was run: two guarded one-shots on the default cmdline.
Test: BCM4388, Wi-Fi only, 5 GHz (5785 MHz) on the same access point for both boots. iperf3 isn't installed on the mini or the peer, so throughput comes from a minimal TCP sender/receiver run against a LAN peer: 200 MB each way, then one RTC s2idle sleep/wake, then 50 MB each way.
These are single over-the-air runs with no repeats, so the spread (±20 %) is radio variance: no direction is consistently lower on the candidate.
|
|
Verdict at Blockers: none. The host-test breakage it shared with #3205 is fixed by #3205's stub commit, which is merged into this branch (no force-push). Checked
Not blockers:
Evidence
|
|
J516s (MacBook Pro 16" M3 Pro, BCM4388/4, 16K pages, 27.2 stub) row for #3210 at |
A completion took a non-NULL pktid->skb as proof that a TX slot was ready. brcmf_msgbuf_alloc_tx_pktid() stores skb before pool and buf and the completion read them with plain loads, so on arm64 a completion that names a slot still being filled could see the new skb with the old pool or buffer, or the old fields with a claim already set. Give the slot three states. Claiming moves it FREE -> RESERVED; the allocators move it to READY with a release store after every field is written; completions acquire the state and read the fields only on READY. A completion for a RESERVED slot is stray and leaves the slot, its buffer and its skb to the TX worker. Teardown frees only the frames of READY slots. RX slots follow the same states. Add brcmf-msgbuf-pktid-tests.py: it runs the production claim, fill, completion and teardown code with a completion delivered in the middle of the fill, and five mutations of the ordering. Signed-off-by: Ryan Murray <[email protected]>
|
Pushed d532011 for the App's ready-state finding. A pktid slot now has three states. Claiming moves it FREE -> RESERVED. |
There was a problem hiding this comment.
Verdict: FIX, then re-review at d532011d
Blockers:
- Concurrent
brcmf_msgbuf_get_pktid()vs TX-ring-full rollback use-after-free / double-free ofskb(drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.cL647, L726–L755, L1181–L1201):brcmf_msgbuf_alloc_tx_pktid()publishesBRCMF_MSGBUF_PKTID_READYat L647 beforebrcmf_msgbuf_txflow()callsbrcmf_commonring_reserve_for_write(commonring)at L1196.- If
brcmf_commonring_reserve_for_write()returnsNULL(ring full), the TX worker rolls back viabrcmf_msgbuf_get_pktid(msgbuf->tx_pktids, pktid); brcmf_flowring_reinsert(flow, flowid, skb);(L1198–L1199), while the NAPI/DPC completion path (brcmf_msgbuf_process_txstatus(), L1371) can concurrently callbrcmf_msgbuf_get_pktid(msgbuf->tx_pktids, idx)for a stray/adversarial firmware completion naming that samepktid:- Race A (overlapping calls):
brcmf_msgbuf_get_pktid()checksatomic_read_acquire(&pktid->allocated) == BRCMF_MSGBUF_PKTID_READYwithout an atomic ownership claim (atomic_cmpxchg_acquireto an intermediate/claimed state). Both the completion thread and the TX rollback thread can observeREADYsimultaneously and consume the same slot; the completion thread freesskbviabrcmf_txfinalize()while the TX worker reinserts the sameskb(and a secondbrcmf_msgbuf_buf_put()can race against a freshly re-allocated buffer if the first thread already setFREE). - Race B (completion wins before rollback): Even without overlap, if a stray completion consumes the
READYslot between L647 and L1198,brcmf_msgbuf_process_txstatus()freesskb; then L1198 getsNULLfrombrcmf_msgbuf_get_pktid(), ignores theNULLreturn value, and callsbrcmf_flowring_reinsert(flow, flowid, skb)on the already-freedskb.
- Race A (overlapping calls):
- Fix: Either keep the TX slot in
BRCMF_MSGBUF_PKTID_RESERVEDuntilbrcmf_commonring_reserve_for_write()succeeds (releasing theRESERVEDslot directly on!ret_ptrso a stray completion can never touch an unposted TX slot), and/or makebrcmf_msgbuf_get_pktid()claimREADYatomically viaatomic_cmpxchg_acquireso at most one consumer can ever claim aREADYslot, and only callbrcmf_flowring_reinsert()if rollback actually reclaimed theskb. Extendtools/asahi/brcmf-msgbuf-pktid-tests.pyto cover a stray completion arriving during the!ret_ptrrollback window.
- Complete green hosted CI and post the fresh J316s or J413 iperf +
s2idlehardware row at the updated head.
Checked:
- Audited
69bfe623..d532011d(drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c,tools/asahi/brcmf-msgbuf-pktid-tests.py,tools/asahi/run-host-tests.py) and all callers ofalloc_tx_pktid,alloc_rx_pktid,get_pktid,get_rx_pktid, andrelease_array. - The
FREE -> RESERVED -> READY(atomic_set_release) /atomic_read_acquirepublication fixes the fill-window partial-field visibility bug on arm64 for both TX and RX allocators, and teardown (brcmf_msgbuf_release_array) cleanly frees onlyREADYslots. - DCO
Signed-off-by:present ond532011d; no Apple material or policy issues.
Evidence
msgbuf.cL647 setsBRCMF_MSGBUF_PKTID_READYinsidebrcmf_msgbuf_alloc_tx_pktid(), beforebrcmf_commonring_reserve_for_write()at L1196.msgbuf.cL1197–L1200 ignores the return value ofbrcmf_msgbuf_get_pktid()and unconditionally reinsertsskb.msgbuf.cL726 checksatomic_read_acquire(&pktid->allocated)without transitioning state atomically before readingskb/pool/bufand puttingbuf.
|
Merge-train review at |
…ring slot brcmf_msgbuf_get_pktid() only checked READY, so the TX worker's ring-full rollback and a completion naming the same packet id could both take the skb, and the slot was READY before brcmf_msgbuf_txflow() had a ring slot for it, so a stray completion in that window freed an skb the worker then reinserted. Keep the TX slot RESERVED until its message is in the ring and publish it there; on a full ring give the slot back directly, without going through the completion path. A completion now takes a READY slot with a cmpxchg to CLAIMED, TX and RX, so only one consumer ever gets its skb and buffer. The host test covers a stray completion before and inside the rollback, two interleaved completions for one id, and a threaded rollback/post stress, with two new mutations. Signed-off-by: Ryan Murray <[email protected]>
|
Pushed 69f3a4a on top of d532011 for the App's pktid points. The TX slot now stays RESERVED until brcmf_msgbuf_txflow() has its ring slot and is published there (after the last skb access); a full ring gives the slot back directly instead of going through brcmf_msgbuf_get_pktid(), so a stray completion in that window gets nothing and the worker keeps its skb. Completions (TX and RX) now claim a READY slot with atomic_cmpxchg_acquire(READY -> CLAIMED), so only one consumer ever takes the skb and buffer. |
There was a problem hiding this comment.
Verdict: HOLD at 69f3a4af — the d532011d TX-slot concurrency and rollback blockers are cleanly resolved; awaiting hosted CI completion and exact-head hardware rows (including a second Wi-Fi chip family).
Blockers:
- Wait for hosted CI checks at
69f3a4af(apple-build,host-tests,kunit,pr-text,readiness) to complete green. - Post the exact-head
69f3a4afhardware row on a second Wi-Fi chip family (e.g. J316s or J413: 60 s bidirectional iperf3 before and after s2idle, zeromsgbuf/pktid errors, neutral throughput) alongside J773g confirmation if re-run.
Checked:
- Verified commit
69f3a4afindrivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.cresolves both races flagged atd532011d:brcmf_msgbuf_alloc_tx_pktid()now leaves the TX slot inBRCMF_MSGBUF_PKTID_RESERVED; onbrcmf_commonring_reserve_for_write()failure inbrcmf_msgbuf_txflow(),brcmf_msgbuf_unclaim_tx_pktid()clearspktid->skb, returns the pool buffer, and releases the slotRESERVED -> FREE(atomic_set_release) directly so no stray completion can touchskbor the buffer.- On ring reservation success,
brcmf_msgbuf_post_tx_pktid()publishesRESERVED -> READY(atomic_set_release) after the lastskbread (skb->priority,skb->data,skb->len) andatomic_inc(&commonring->outstanding_tx)and strictly beforebrcmf_commonring_write_complete(). - Both
brcmf_msgbuf_get_rx_pktid()andbrcmf_msgbuf_get_pktid()atomically claimREADY -> CLAIMEDviaatomic_cmpxchg_acquire(), ensuring a single consumer extractsskb/pool/buf beforeCLAIMED -> FREE(atomic_set_release). brcmf_msgbuf_release_array()teardown remains consistent with the 4-state machine (FREE/RESERVED/READY/CLAIMED).
- Audited
tools/asahi/brcmf-msgbuf-pktid-tests.py: covers stray completions before and during ring-full rollback, concurrent duplicate TX and RX completions, threaded rollback/post stress with real atomics, and kills bothpublish-before-reserveandno-claimmutations (8/8pass reported,brcmfmacW=1clean).
Evidence
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c: audited L362–365, L629–686, L707–823, andbrcmf_msgbuf_txflow()L1220–1280 (brcmf_msgbuf_alloc_tx_pktid()is called exclusively frombrcmf_msgbuf_txflow()).tools/asahi/brcmf-msgbuf-pktid-tests.py: verified deterministic interleaving hooks (stray_at_reserve,second_completion), threadedstress(false)/stress(true), and mutation checks.- Reported local verification at
69f3a4af:run-host-tests8/8,brcmfmacW=1clean on arm64 LLVM.
|
69f3a4a J316s (M1 Pro, T6000, BCM4387) PASS: combined guarded one-shot |
Signed-off-by: Ryan Murray <[email protected]>
|
Row (J316s, M1 Pro, T6000) at exact head 69f3a4a in combined candidate 77b87daa (main de965eb + #3277 542bbdc + #3231 c955307 + #3210 69f3a4a), kernel 7.3.0-aurora-crj7+ (fleet edge config), kernel-only one-shot with the saved Stage 2 and the default command line -> PASS (TCP + s2idle, no pktid errors).
Evidence: traces/kernel/20261130-closeout-k114s-j316s-combo/m1pro/. Saved kernel 7.3.0-aurora-edge restored and verified. |
Signed-off-by: Ryan Murray <[email protected]>
|
I merged current |
There was a problem hiding this comment.
Verdict: HOLD at e8b43faa.
Checked: Compared the PR patch before and after the forward merge. The file set and added and removed lines match the reviewed revision. Hosted checks and a second Wi-Fi family before and after s2idle remain due; keep the TX completion and rollback coverage.
|
PASS — J773g (M4 mini, BCM4388) second Wi-Fi family row at
|
There was a problem hiding this comment.
Verdict: MERGE at e8b43faa
Blockers: none
Checked:
- Clean conflict-free forward merge
e8b43faaofmain(MERGEABLE, 3 files,+798/-124, PR patch byte-identical to reviewed69f3a4afwhere TX-slot concurrency and rollback blockers were resolved; 46/46 brcmf host tests with all mutations killed). - CI at
e8b43faa:Host tests(46340514381),pr-text(46340518151), andpr-readiness(46341028825) all passed. - Dual Broadcom Wi-Fi chip-family hardware proof (pre- and post-
s2idle):- J316s (M1 Pro, T6000): identical
69f3a4afpatch — 60 s TCP TX186.8/ RX114.5Mbit/s pre-sleep,s2idle1/1 (15 sPMU RTC wake), 30 s TX207.5/ RX117.2Mbit/s post-sleep, 0 brcmf msgbuf/pktid/err/warn lines, 0 WARN/BUG/Oops. - J773g (M4 mini, T8132, BCM4388/6): exact head
e8b43faa1cb9cf122cbe53be410cf963b781c568— 60 siperf3TX87.8/ RX118.0Mb/s pre-sleep,s2idle1/1 (rtc115 s wake), TX209.3/ RX194.8Mb/s post-sleep, 0 msgbuf/pktid errors.
- J316s (M1 Pro, T6000): identical
Evidence
- Both remaining blockers from the prior
HOLDate8b43faa(hosted CI completion and second Wi-Fi chip family pre/post-s2idleverification) are cleared byHost testspassing and the2026-11-30T20:53:33ZJ773g BCM4388 row.
|
code-owner ping <@422957901716652033>: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: brcmfmac mapped each frame to send where the stack left it, in an skb head that shares its page with other kernel memory. With 16K pages the IOMMU maps the whole 16 KiB page, so the device could read unrelated data next to the frame. Frames are now copied into buffers from a pool of pages that hold only transmit buffers and stay mapped read-only. This builds on #3205 (base is its branch; it moves to
mainonce #3205 merges).Tested: J773g (M4 mini) row PASS at
ac0d28980ac4: it ran3a7583863c72, and this head only merges #3205's host-test commit, so the driver code is unchanged (#3210 (comment)). The brcmf host tests pass at this head (46/46, all mutations killed), andmsgbuf.obuilds with W=1 on 16K pages.Risk: two-way · Macs with Broadcom PCIe Wi-Fi: M1, M2, M3, M4.
Not yet: The J516s (M3 Pro) row. M1 and M2 rows after merge. (The M4 mini's repeated runs, 4 before and 3 after sleep per arm, show no change after sleep: transmit medians 251.8 on main and 251.4 here.)
Details
dma_alloc_noncoherent()chunks withDMA_TO_DEVICE, zeroed and synced once. The device can read only these pages, and they hold only frames already handed to it. Memory is 256 pages on 16K pages.tx_errors. The MTU (at most 1500 bytes, no scatter-gather) never allows that today.dma_map_single()and adma_unmap_single()per send.brcmf_msgbuf_pool,brcmf_msgbuf_buf_get(),brcmf_msgbuf_buf_put(). The map-basedbrcmf_msgbuf_alloc_pktid()is gone.skb->datathe same way for transmit and has nothing that keeps the mapping to the frame.Evidence
./linux-build/build kernel linux-brcmf-fixes -- -j4 W=1 drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.owithCONFIG_ARM64_16K_PAGES=y,CONFIG_BRCMFMAC=m,CONFIG_BRCMFMAC_PCIE=y: no warnings.scripts/checkpatch.pl --strict: no errors or warnings; only "multiple blank lines" checks, which follow the file's existing two-line spacing between functions.764aec53fd69.