Skip to content

wifi: brcmfmac: msgbuf: receive into pages that hold only receive buffers - #3205

Merged
RyanTheTide merged 3 commits into
mainfrom
fix/brcmfmac-rx-own-pages
Nov 28, 2026
Merged

RyanTheTide merged 3 commits into
mainfrom
fix/brcmfmac-rx-own-pages

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: brcmfmac posts 2 KiB receive skbs carved from page fragments, and with 16K pages the IOMMU maps the whole 16 KiB page, so the device can also write the skb's shared info and the other skbs in that page. Receive buffers now come from two pools of pages that hold only receive buffers and stay mapped; each completed buffer is copied into a new skb of the reported length. A second commit drops received frames shorter than an Ethernet header, or longer than their buffer, before eth_type_trans() sees them.

Tested: J773g (M4 mini) row PASS at a0ab00a770c0: it ran 764aec53fd69, and this head only adds a host-test commit, so the driver code is unchanged (#3205 (comment)). The brcmf host tests pass at this head (46/46, all mutations killed), and msgbuf.o builds 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
  • Why: brcmu_pkt_buf_get_skb() uses dev_alloc_skb(), which for these sizes takes the head from page_frag_alloc(): several skb heads share one page, each with its skb_shared_info right after its data. dma_map_single() maps the page-aligned range around the buffer, and the IOMMU's page is the kernel's page, so the device can reach the whole page.
  • Pools: data buffers are min(max_rxbufpost, NR_RX_PKTIDS) × 2048 bytes; control buffers (ioctl responses and events) are 8 + 8 × 8192 bytes. Each pool is allocated in page-sized dma_alloc_noncoherent() chunks, zeroed and synced for the device once, with the same receive direction as before (bidirectional on BCM4378, BCM4387 and BCM4388). The free list is host memory.
  • Completion: the used range is synced for the CPU, copied into an skb of the reported length, and the buffer goes back to its pool. A data offset past the end of the buffer drops it; before, the pull was skipped and the data from offset 0 was delivered.
  • The rx-complete and event handlers refill after the copy, so the pools need no spare buffer.
  • An ioctl response is copied out when it completes. One that arrives after its request timed out is dropped at the next request, instead of holding a buffer for good.
  • Cost: one copy of the received bytes per packet replaces a dma_map_single() and a dma_unmap_single() per packet. Memory is about what the posted skbs used: 32 pages for 255 data buffers plus 8 for control on 16K pages.
  • Upstream brcmfmac maps skb->data the same way and has nothing that keeps receive mappings inside the buffer.
  • Short frames: a data or event completion shorter than ETH_HLEN reached eth_type_trans(), which pulls ETH_HLEN and wraps skb->len; a monitor frame that short makes brcmf_netif_mon_rx() trim past its start. Those, and frames longer than their buffer, are now dropped and counted in rx_errors and rx_length_errors, with a rate-limited warning. The shortest monitor frame (10-byte header plus the 4-byte trailer) is exactly ETH_HLEN.
  • Transmit is unchanged here; it gets the same treatment in a follow-up PR.
Evidence
  • ./linux-build/build kernel linux-pciewifi-fixes -- -j3 W=1 drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.o with CONFIG_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.
  • Base: 40e5e29cc915.

…fers

A 2 KiB receive skb comes from a page fragment, and the IOMMU maps the
whole page it sits in: 16 KiB with 16K pages. Besides the 2 KiB it was
given, the device can then write that skb's shared info, the other skbs
in the page, and skbs already handed to the stack while a buffer from
the same page is still posted.

Post receive buffers from two pools of pages that hold nothing but
receive buffers and stay mapped while the rings exist: 2 KiB data
buffers and 8 KiB control buffers. A completed buffer is copied into a
new skb of the reported length and goes back to its pool, so an skb is
never mapped for receive. This also drops the map and unmap of every
received packet.

An ioctl response is now copied out when it completes rather than when
its waiter wakes, so a response that arrives after its request timed
out returns its buffer instead of holding it.

Signed-off-by: Dj <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 07:49
… header

A data or event completion whose reported length is below ETH_HLEN
reaches eth_type_trans(), which pulls ETH_HLEN bytes and wraps skb->len.
A monitor frame that short makes brcmf_netif_mon_rx() trim past its
start. A reported length beyond the receive buffer has already been cut
by the copy and no longer matches the frame.

Drop both, count them in rx_errors and rx_length_errors of the interface,
and warn, rate-limited.

Signed-off-by: Dj <[email protected]>
@github-actions github-actions Bot added area:wireless Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (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 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at a0ab00a7: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text, pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at a0ab00a7
Conflicts ok none
PR text ok Risk: two-way · Macs with Broadcom PCIe Wi-Fi: M1, M2, M3, M4.

Areas: area:gpu, area:wireless

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

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 764aec53fd69 and #3210 at 3a7583863c72. The current heads, a0ab00a770c0 (#3205) and ac0d28980ac4 (#3210), change only tools/asahi/brcmf-assoc-tests.py and brcmf-recovery-tests.py, so the kernel code is the same.

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:

  • 4 rounds of 200 MB each way;
  • one RTC s2idle sleep/wake, then 50 MB each way;
  • 3 more rounds of 200 MB each way.

Figures are Mb/s.

mini TX before sleep mini TX after sleep (3 × 200 MB) mini RX before sleep mini RX after sleep
control 257.4, 249.3, 240.2, 239.4 (median 244.8) 214.9, 259.3, 251.8 (251.8) 263.0, 229.8, 261.7, 237.0 (249.4) 277.3, 257.8, 259.6 (259.6)
candidate 217.1, 248.2, 240.4, 164.1 (median 228.8) 253.9, 202.1, 251.4 (251.4) 228.0, 239.6, 229.4, 242.6 (234.5) 244.3, 224.0, 248.8 (244.3)

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:

  • wld0 rx errors, length errors, crc and missed: +0 on every round on both boots.
  • 0 "No PKTID available", "Failed to alloc SKB" and "too long to send" lines.
  • "using bidirectional receive DMA" on both.
  • s2idle: suspend success +1, same boot, reassociated, 0 failed units.
  • 0 DART/IOMMU faults and 0 PCIe error lines.

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 764aec53fd69: PASS. This head ran unchanged inside #3210's head 3a7583863c72, one build for both PRs.

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.

mini TX (iperf3 -c direction) mini RX
control, 200 MB 212.6 Mb/s 233.0 Mb/s
candidate, 200 MB 263.4 Mb/s 225.6 Mb/s
control, 50 MB after sleep 257.4 Mb/s 250.0 Mb/s
candidate, 50 MB after sleep 188.8 Mb/s 232.5 Mb/s

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.

@DjDeveloperr

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Verdict at a0ab00a770c0: ready (code). CI host-tests on this head was still pending when I checked, so I ran the brcmf subset locally. The J773g row above passed; the J516s row is still owed.

Blockers: none. My first-pass blocker (red host-tests) is fixed. brcmf-assoc-tests.py and brcmf-recovery-tests.py now model struct brcmf_msgbuf with ioctl_resp, give the association stub an xchg(), and hand the response over from the stubbed send at the reported length, as the completion does now. msgbuf.c is unchanged from 764aec53fd69.

Checked

  • The pools (brcmf_msgbuf_rxpool_init(), msgbuf.c:497) come from page-sized dma_alloc_noncoherent() chunks. Those are zeroed, mapped once with the same receive direction as before, and synced for the device before first use. So a 16K IOMMU page around a posted buffer holds only other receive buffers, not skb heads or skb_shared_info.
  • brcmf_msgbuf_get_rx_pktid() (615): an offset past the buffer is dropped, and the length is clamped to buf_size - offset, so the sync and the copy stay inside the buffer and nothing underflows. The buffer goes back to its pool before allocated clears. Data and ctrl buffers are posted from the same completion context that returns them, so the free list doesn't race with the posting path.
  • Refills now happen after the copy in all three completion paths (rx, event, ioctl), so pools sized at min(max_rxbufpost, NR_RX_PKTIDS) and max_ioctlrespbuf + max_eventbuf never run short.
  • ioctl responses: the copy to the caller is now min(len, skb->len). Before, it was min(len, ret_len) from an 8 KiB skb, which over-read when the firmware claimed more than 8 KiB. A response that arrives after its request timed out gives its buffer back at once.
  • brcmf_msgbuf_rx_len_ok() (1535) drops frames shorter than ETH_HLEN (for both eth_type_trans() and the monitor trim), and frames whose reported length was cut. It counts them in rx_errors/rx_length_errors.
  • The attach failure path and detach free the pools idempotently. A pool that was never set up has NULL arrays.
  • No runtime switches and no SoC or board gates. The sizes are the existing BRCMF_MSGBUF_MAX_* and ring limits.

Not blockers:

  • The chunk size is PAGE_ALIGN(buf_size) (507), which assumes that the IOMMU page is the CPU page. That holds on the 16K kernels we ship. On a 4K-page kernel over a 16K DART, a chunk would share its IOMMU page with 12K of other memory. Sizing chunks from the IOMMU granule (dma_get_merge_boundary(dev) + 1 when it's non-zero) would make this hold everywhere.
  • The comment at 805 says that a late response "is not this one". That's true only when the late response lands before the next request starts. One that lands while the next request waits is still taken as its answer, because trans_id isn't compared. This isn't new.
Evidence
  • tools/asahi/run-host-tests.py --only brcmf at a0ab00a770c0: 46/46 passed, mutations included (skb-capacity, header-length, short-ie, cmplt-header, and the recovery mutations).
  • make W=1 drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.o (asahi profile, 16K pages, LLVM=1, arm64) at 764aec53fd69, the same msgbuf.c: builds, no warnings. checkpatch.pl --strict: 0 errors and 0 warnings; the checks are blank-line spacing, which the file already uses.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 26, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (MacBook Pro 16" M3 Pro, BCM4388/4, 16K pages, 27.2 stub) row for #3210 at 3a7583863c72, which carries #3205's 764aec53fd69: PASS. The candidate was main 9a9862253576 + #3180, #3195, #3196, #3021, #3210 (no file overlap), booted one-shot twice. The control was main alone: 9a9862253576 and b12781353833, whose brcmfmac is identical. iperf3 ran over Wi-Fi to a host on the same network, 210 MB per run. Receive (into the J516s): 240, 239, 246 and 240 Mb/s with the PRs, against 240, 209, 216 and 241 on main. Transmit: 186, 186, 168 and 186 Mb/s, against 239, 168, 210 and 140 on main. Wi-Fi varies a lot, and the transmit runs sit inside main's spread. With the PRs, using bidirectional receive DMA is logged (it is on main too), rx_errors and rx_length_errors on wld0 stayed at 0, and there were no "too long to send", "No PKTID available" or "Failed to alloc SKB" lines and 0 DART/IOMMU faults. 0 failed units, and no new kernel error lines beyond dwc3-apple's s2idle refusal (also on main) and the MTP HID "no listeners" line the baseline logs. The sleep step was skipped because s2idle is refused at prepare on the J516s.

…etion

brcmf_msgbuf_query_dcmd_len() now takes its response skb from
msgbuf->ioctl_resp with xchg() instead of looking up a packet id. The
association and recovery controls compile it against their own
struct brcmf_msgbuf, which still had ioctl_resp_pktid, and the
association controls had no xchg().

Give both stubs the ioctl_resp field, and have the stubbed send hand over
its response there, holding the reported length, as the completion now
does. Drop the brcmf_msgbuf_get_pktid() stubs, which nothing calls.

Signed-off-by: DjDeveloperr <[email protected]>
@github-actions github-actions Bot added the area:gpu Area from CODEOWNERS (bot) label Nov 26, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Independent J316s (M1 Pro, BCM4387) row on #3210's head ac0d2898, which carries this PR's commits: PASS. Receive and send throughput match the base and the installed module, sha256 matched on every 256 MiB transfer both ways, before and after s2idle. Details and one pre-existing removal-after-sleep hang (it happens with the base and the installed module too, so it isn't this PR): #3210 (comment)

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at a0ab00a7 (once cancelled CI checks are rerun green)

Blockers: none (code, host tests, and three-generation hardware rows are ready; rerun the 4 cancelled CI checks before merge).

Checked:

  • drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c: verified brcmf_msgbuf_rxpool allocates dedicated PAGE_ALIGN(buf_size) noncoherent DMA chunks so 16K IOMMU mappings never expose sk_buff or unrelated kernel memory; verified dma_sync_single_for_device on init/repost and dma_sync_single_for_cpu before copying into fresh skbs; verified offset > size bounds checks, min(len, pool->buf_size - offset) clamping, and brcmf_msgbuf_rx_len_ok() dropping frames < ETH_HLEN or truncated (skb->len != len) before eth_type_trans() / brcmf_netif_mon_rx().
  • Verified ioctl_resp uses xchg(&msgbuf->ioctl_resp, ...) so timed-out ioctl responses cannot leak buffers or race completions.
  • Verified host tests (brcmf-assoc-tests.py, brcmf-recovery-tests.py, 46/46 passing) and hardware rows across J773g (M4), J516s (M3 Pro, BCM4388), and J316s (M1 Pro, BCM4387, 256 MiB sha256 verified both directions pre/post s2idle).
Evidence
  • Diff reviewed at a0ab00a7 (all 3 files, 671 lines).
  • CI at review time: 3 passed, 0 failed, 4 cancelled.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at a0ab00a7 (App approval noted; rows: 4 cancelled; J773g + J516s + J316s PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train: everything else is ready (App approval, J773g + J516s + J316s rows, Dj pinged). The only red check is pr-text: see the pr-text job. Edit the PR body and the check re-runs; then it merges.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule at a0ab00a7. (1) The review App approved at this head. (2) Hosted CI is green except a stale pr-text result from before the last body edit (the rerun is stuck in the runner backlog); the canonical pr-text.sh passes locally on the current body. (3/4) Rows: J773g + J516s + J316s. (5) No blocking review at this head. (6) Dj was pinged more than 1 h ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 2a173ca into main Nov 28, 2026
4 of 15 checks passed
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) area:wireless Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants