net: airoha: Clean up RX queues in airoha_dev_stop
Subsystems (4)
PATCH 1/1 net: airoha: Clean up RX queues in airoha_dev_stop
When the last port is stopped, airoha_dev_stop() clears TX queues but neglects to clean up RX queues. This can lead to:
- RX ring buffer descriptors remaining valid after device close
- Potential DMA synchronization issues on device reopen
- Risk of use-after-free if pages are freed while DMA is still active
Add cleanup loop for RX queues to mirror the TX queue cleanup, ensuring symmetric resource management.
--- drivers/net/ethernet/airoha/airoha_eth.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/airoha/airoha_eth.c +7 -0
@@ -1771,6 +1771,13 @@ static int airoha_dev_stop(struct net_device *dev)airoha_qdma_cleanup_tx_queue (&qdma->q_tx[i]); } + +for (i =0 ; i <ARRAY_SIZE (qdma->q_rx); i++) { +if (!qdma->q_rx[i].ndesc) +continue ; + +airoha_qdma_cleanup_rx_queue (&qdma->q_rx[i]); + } }return 0 ;
Signature · 1 line
2.51.0
Simon Horman
reviewerQuoted 11 lines · Wayen Yan
When the last port is stopped,
airoha_dev_stop()clears TX queues but neglects to clean up RX queues. This can lead to:
- RX ring buffer descriptors remaining valid after device close
- Potential DMA synchronization issues on device reopen
- Risk of use-after-free if pages are freed while DMA is still activeAdd cleanup loop for RX queues to mirror the TX queue cleanup, ensuring symmetric resource management.
Fixes 20bf7d07c956 ("net: airoha: add QDMA support for Airoha EN7581 Ethernet")Signed-off-by Wayen Yan <[email protected]>
Hi Wayen Yan,
There is AI-generated review of this patch-set available on both
https://sashiko.dev and https://netdev-ai.bots.linux.dev/sashiko/
I asked AI to summarise these concerns, it came up with the following. I would appreciate it if you could look over this feedback.
1. NAPI Synchronization:
While the TX path is managed by the netdev layer during stop, the RX path relies on the NAPI subsystem. Since NAPI remains active during airoha_dev_stop(), the new cleanup loop could race with the poller (airoha_qdma_rx_process). It would be safer to call napi_disable() before draining the queues to ensure exclusive access to the descriptors.
2. RX Queue Refill:
Unlike TX, the RX hardware requires descriptors to be pre-allocated and posted by the driver to receive data. Because this patch empties the rings, airoha_dev_open() needs a corresponding update to refill them (e.g., via airoha_qdma_fill_rx_queue()). Without this, the interface will encounter an empty ring on restart, leading to an RX stall.
3. SKB Accumulation:
The cleanup should also account for the q->skb pointer used for fragmented packets. If a partial packet is sitting in the queue when the interface is stopped, freeing it and resetting the pointer to NULL will prevent a memory leak and ensure the next session starts with a clean state.