Skip to contentSkip to conversation

wifi: mt76: npu: fix RX packet reassembly across NAPI polls

PATCH In review Lorenzo Bianconi 2 participants 2 messages Nov 17 – Nov 19

Subsystems (2)
lore
Share & tools
lore

Lorenzo Bianconi

author maintainer
#0 lore raw

PATCH 1/1 wifi: mt76: npu: fix RX packet reassembly across NAPI polls

mt76_npu_dequeue() builds an skb from the descriptors that make up a single NPU RX packet. When a packet spans multiple descriptors and not all of them are ready yet, the function frees the partially built skb and returns NULL without advancing q->tail. The descriptors already consumed are then processed again on the next NAPI poll, even though their buffers have already been handed to the skb and recycled, leading to a use-after-free/double-free and possible memory corruption.

Rework RX processing to keep the partially built skb and the number of outstanding fragments across polls: store the skb in q->rx_head and the remaining fragment count in the new q->pending field. The new mt76_npu_rx_process_entry() consumes a whole packet, resuming a previously started one if needed, and advances q->tail for every consumed descriptor. Only fully received packets are passed up the stack.

Release any pending skb in mt76_npu_queue_cleanup() and add the missing DMA read barrier before accessing the descriptor length and info.

Fixes 7fb554b1b623 ("wifi: mt76: Introduce the NPU generic layer")
---
 drivers/net/wireless/mediatek/mt76/mt76.h |  1 +
 drivers/net/wireless/mediatek/mt76/npu.c  | 88 ++++++++++++++++++-------------
 2 files changed, 51 insertions(+), 38 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
index 9e851dea71d9..f52a0e2246be 100644
@@ -249,6 +249,7 @@ struct mt76_queue {
 	int ndesc;
 	int queued;
 	int buf_size;
+	int pending;
 	bool stopped;
 	bool blocked;
 
drivers/net/wireless/mediatek/mt76/npu.c +50 -38

129 lines not on this page · raw message

---
base-commit: 763b13f622e2758726e8e3ecaef819db8fa0430a
change-id: 20261117-mt76-npu-fixes-ed72cc316a6a

Best regards,

Signature · 1 line
Lorenzo Bianconi <[email protected]>
Tested-by on v1 1/1
#1 lore raw
Quoted 1 line · Lorenzo Bianconi

Thanks for posting. I ran the posted patch on mt76 467ae2e3 (W1700K, kernel 6.18.55) for another hour of iperf3. There are no oops, no page_pool warning, no refill or skb failure.

The missing rx slots from my mail of Nov 16 are still there (232 frames without LAST on their last slot, 7 unreadable tx-free events), but that is not caused by this patch. I will send the [BUG] report separately.

Thanks,
Florian