* [PATCH net 0/3] net: hix5hd2_gmac: fix memory corruption across interface reopen
@ 2026-11-26 11:03 David Yang
2026-11-26 11:03 ` [PATCH net 1/3] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Yang @ 2026-11-26 11:03 UTC (permalink / raw)
To: netdev
Cc: David Yang, Jian Shen, Jijie Shao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Zhangfei Gao,
Dongpo Li
Found and verified on a Hi3716cv200 board, where received frames came up
as slab garbage after reopening interface.
The SG path problem is discovered and fixed by LLM but not hardware
verified - TX SG feature is only available on hisi-gmac-v2 while
Hi3716cv200 has v1.
David Yang (3):
net: hix5hd2_gmac: unmap input TX buffers, not returned ones
net: hix5hd2_gmac: release TX SG buffers if using SG
net: hix5hd2_gmac: keep TX/RX queues alive across a close
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 25 +++++++++++++------
1 file changed, 17 insertions(+), 8 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net 1/3] net: hix5hd2_gmac: unmap input TX buffers, not returned ones 2026-11-26 11:03 [PATCH net 0/3] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang @ 2026-11-26 11:03 ` David Yang 2026-11-26 11:03 ` [PATCH net 2/3] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang 2026-11-26 11:03 ` [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang 2 siblings, 0 replies; 5+ messages in thread From: David Yang @ 2026-11-26 11:03 UTC (permalink / raw) To: netdev Cc: David Yang, Jian Shen, Jijie Shao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Zhangfei Gao, Dongpo Li hix5hd2_free_dma_desc_rings() released DMA addresses from tx_rq, the "return queue", which could reference memory already consumed and freed in an earlier round, or not yet reference buffers unconsumed from the input queue, resulting in memory corruption or a mapping leak. Read the addresses from the input queue, tx_bq, instead. Fixes: 57c5bc9ad7d7 ("net: hisilicon: add hix5hd2 mac driver") Signed-off-by: David Yang <mmyangfl@gmail.com> --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index 12a5657653f8..46386a0954a2 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -816,7 +816,7 @@ static void hix5hd2_free_dma_desc_rings(struct hix5hd2_priv *priv) if (skb == NULL) continue; - desc = priv->tx_rq.desc + i; + desc = priv->tx_bq.desc + i; addr = le32_to_cpu(desc->buff_addr); dma_unmap_single(priv->dev, addr, skb->len, DMA_TO_DEVICE); dev_kfree_skb_any(skb); -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/3] net: hix5hd2_gmac: release TX SG buffers if using SG 2026-11-26 11:03 [PATCH net 0/3] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang 2026-11-26 11:03 ` [PATCH net 1/3] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang @ 2026-11-26 11:03 ` David Yang 2026-11-26 11:03 ` [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang 2 siblings, 0 replies; 5+ messages in thread From: David Yang @ 2026-11-26 11:03 UTC (permalink / raw) To: netdev Cc: David Yang, Jian Shen, Jijie Shao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Zhangfei Gao, Dongpo Li The commit in question added scatter-gather feature for TX queues, but left the release path in hix5hd2_free_dma_desc_rings() untouched. Give the release the same branch the reclaim has. Fixes: e5222b1c3f21 ("net: hix5hd2_gmac: add tx scatter-gather feature") Signed-off-by: David Yang <mmyangfl@gmail.com> --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index 46386a0954a2..0d4701d1e173 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -816,9 +816,14 @@ static void hix5hd2_free_dma_desc_rings(struct hix5hd2_priv *priv) if (skb == NULL) continue; - desc = priv->tx_bq.desc + i; - addr = le32_to_cpu(desc->buff_addr); - dma_unmap_single(priv->dev, addr, skb->len, DMA_TO_DEVICE); + if (skb_shinfo(skb)->nr_frags) { + hix5hd2_clean_sg_desc(priv, skb, i); + } else { + desc = priv->tx_bq.desc + i; + addr = le32_to_cpu(desc->buff_addr); + dma_unmap_single(priv->dev, addr, skb->len, + DMA_TO_DEVICE); + } dev_kfree_skb_any(skb); priv->tx_skb[i] = NULL; } -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close 2026-11-26 11:03 [PATCH net 0/3] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang 2026-11-26 11:03 ` [PATCH net 1/3] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang 2026-11-26 11:03 ` [PATCH net 2/3] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang @ 2026-11-26 11:03 ` David Yang 2026-11-27 11:51 ` netdev-bot+sashiko 2 siblings, 1 reply; 5+ messages in thread From: David Yang @ 2026-11-26 11:03 UTC (permalink / raw) To: netdev Cc: David Yang, Jian Shen, Jijie Shao, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Zhangfei Gao, Dongpo Li hix5hd2_net_close() frees the buffers while the block still holds prefetched descriptors. On Hi3716cv200 the descriptors consumed at the next open carried the previous session's stamps and the received frames came up as slab garbage, indicating possible memory corruption. Do not release the buffers at close; keep them until the device goes away. The sibling hisi_femac had the same defect, and was fixed by commit d54b21d82430 ("net: hisilicon: hisi_femac: Stop the receiver before releasing the RX ring"), which resets the port before freeing its ring. This one, however, has no equivalent: the interface reset leaves the prefetched descriptors in place, and the reset that clears the queue state also resets the switch-fabric port the MAC feeds, so neither can serve to quiesce the block before a free. With buffers retained across a close, completions of pre-close sends reach BQL only after the reopen, so drop netdev_reset_queue() from the open; resetting there would report completions of bytes it never counted. The release reads the scatter-gather descriptors as well as the hardware ones, so the hardware queues are destroyed before the SG queue. Fixes: 57c5bc9ad7d7 ("net: hisilicon: add hix5hd2 mac driver") Signed-off-by: David Yang <mmyangfl@gmail.com> --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index 0d4701d1e173..0df31a2ec3ad 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -860,7 +860,6 @@ static int hix5hd2_net_open(struct net_device *dev) hix5hd2_hw_init(priv); hix5hd2_rx_refill(priv); - netdev_reset_queue(dev); netif_start_queue(dev); napi_enable(&priv->napi); @@ -878,7 +877,9 @@ static int hix5hd2_net_close(struct net_device *dev) hix5hd2_irq_disable(priv); napi_disable(&priv->napi); netif_stop_queue(dev); - hix5hd2_free_dma_desc_rings(priv); + /* the buffers stay owned across the close; both rings are released + * with the queues when the device goes away + */ if (dev->phydev) { phy_stop(dev->phydev); @@ -990,6 +991,9 @@ static void hix5hd2_destroy_hw_desc_queue(struct hix5hd2_priv *priv) { int i; + /* the buffers survive a close: release them with the rings */ + hix5hd2_free_dma_desc_rings(priv); + for (i = 0; i < QUEUE_NUMS; i++) { if (priv->pool[i].desc) { dma_free_coherent(priv->dev, priv->pool[i].size, @@ -1268,10 +1272,10 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) return ret; out_destroy_queue: - if (HAS_CAP_TSO(priv->hw_cap)) - hix5hd2_destroy_sg_desc_queue(priv); netif_napi_del(&priv->napi); hix5hd2_destroy_hw_desc_queue(priv); + if (HAS_CAP_TSO(priv->hw_cap)) + hix5hd2_destroy_sg_desc_queue(priv); out_phy_node: of_node_put(priv->phy_node); err_mdiobus: @@ -1298,9 +1302,9 @@ static void hix5hd2_dev_remove(struct platform_device *pdev) mdiobus_unregister(priv->bus); mdiobus_free(priv->bus); + hix5hd2_destroy_hw_desc_queue(priv); if (HAS_CAP_TSO(priv->hw_cap)) hix5hd2_destroy_sg_desc_queue(priv); - hix5hd2_destroy_hw_desc_queue(priv); of_node_put(priv->phy_node); free_netdev(ndev); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close 2026-11-26 11:03 ` [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang @ 2026-11-27 11:51 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-11-27 11:51 UTC (permalink / raw) To: mmyangfl Cc: netdev, shenjian15, shaojijie, andrew+netdev, davem, edumazet, kuba, pabeni, zhangfei.gao, lidongpo Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 2 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The fix is incomplete. - [High] net: hix5hd2_gmac: TX/RX queue stall on reopen in hix5hd2_net_open() - [Medium] hix5hd2_net_close() no longer frees tx_skb[] or rx_skb[]. -- net: hix5hd2_gmac: keep TX/RX queues alive across a close This patch stops hix5hd2_net_close() from freeing the TX/RX buffers. The release moves into hix5hd2_destroy_hw_desc_queue(), so buffers are only freed when the device goes away. It also drops netdev_reset_queue() from hix5hd2_net_open() and destroys the hardware queues before the SG queue in the probe error path and in hix5hd2_dev_remove(). > diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c > index 0d4701d1e1731..0df31a2ec3ad8 100644 > --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c > +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c [ ... ] > @@ -878,7 +877,9 @@ static int hix5hd2_net_close(struct net_device *dev) > hix5hd2_irq_disable(priv); > napi_disable(&priv->napi); > netif_stop_queue(dev); > - hix5hd2_free_dma_desc_rings(priv); > + /* the buffers stay owned across the close; both rings are released > + * with the queues when the device goes away > + */ [Severity: High] Now that the rings and BQL state carry across a close, can the interface come back up with TX and RX stuck? hix5hd2_net_close() only disables the port, the interrupts and NAPI. It does not call hix5hd2_xmit_reclaim() and does not drain RX_BQ. Any descriptors that completed into TX_RQ or RX_BQ after the last poll therefore stay there, and their skbs stay in tx_skb[] and rx_skb[]. On the next open, hix5hd2_hw_init() does: writel_relaxed(~0, priv->base + RAW_PMU_INT); That discards the pending TX_RQ_IN_INT and RX_BQ_IN_INT bits, and their timeout variants, for those completions. hix5hd2_net_open() then neither reclaims nor schedules NAPI; it only enables the interrupts. hix5hd2_poll() is only reached from hix5hd2_interrupt(), so nothing looks at TX_RQ or RX_BQ until the hardware raises a fresh interrupt. On the TX side, suppose netdev_sent_queue() hit the BQL limit before the close. Then __QUEUE_STATE_STACK_XOFF is still set. netif_start_queue() only clears __QUEUE_STATE_DRV_XOFF. With netdev_reset_queue() gone, the only thing that clears STACK_XOFF is netdev_completed_queue() in hix5hd2_xmit_reclaim(). The same happens if the ring was full. Every hix5hd2_net_xmit() call finds priv->tx_skb[pos] occupied and stops the queue again. If all of those frames had already moved to TX_RQ, nothing is left in TX_BQ to raise a new completion, so the queue would stay stopped. On the RX side, suppose RX_FQ had been fully consumed into RX_BQ. Every rx_skb[] slot is then populated, so hix5hd2_rx_refill() breaks on the first one. The hardware has no free buffers to receive into and no reason to raise another RX interrupt. Recovery is affected too. dev_watchdog() would call hix5hd2_net_timeout(), but hix5hd2_tx_timeout_task() only does dev_close() followed by dev_open(). That now repeats the same sequence without reclaiming anything or resetting BQL. Before this patch, the cycle at least freed tx_skb[] and reset the BQL state. Does the hardware re-raise the TX_RQ/RX_BQ timeout interrupts for entries already sitting in those queues after RAW_PMU_INT is cleared? If not, should hix5hd2_net_open() process the leftover completions itself? One option would be a napi_schedule() once after napi_enable() and hix5hd2_irq_enable(), so that the BQL accounting and the rings are reconciled on reopen. [Severity: Medium] With the free removed from here, what releases TX skbs that were queued before "ip link set down" and not yet reclaimed, if the interface stays down? They now seem to stay in tx_skb[] until one of two things happens. Either a later open lets the hardware complete them and hix5hd2_xmit_reclaim() runs, or the device is removed and hix5hd2_destroy_hw_desc_queue() frees them. While they are held, each skb keeps its sk_wmem_alloc charge, so a closed socket cannot finish __sk_destruct(). The socket's netns reference is also kept, so a netns whose sockets sent through this device just before the down cannot be torn down. MSG_ZEROCOPY skbs would keep their user pages pinned, and their completion notifications would never arrive. Close only clears PORT_EN and DESC_WR_RD_ENA. Would hix5hd2_port_enable() on the next open then transmit the frames queued before the down? That could happen long after a MAC address or configuration change made while the interface was down. The same applies to RX buffers already completed into RX_BQ before the close. hix5hd2_rx() would deliver them to the stack after the reopen. The commit message says the buffers are kept "until the device goes away" and describes the BQL effect, but it does not mention these side effects. Could they be described and weighed against the alternatives? [ ... ] > @@ -990,6 +991,9 @@ static void hix5hd2_destroy_hw_desc_queue(struct hix5hd2_priv *priv) > { > int i; > > + /* the buffers survive a close: release them with the rings */ > + hix5hd2_free_dma_desc_rings(priv); > + > for (i = 0; i < QUEUE_NUMS; i++) { > if (priv->pool[i].desc) { > dma_free_coherent(priv->dev, priv->pool[i].size, [Severity: High] Doesn't this still free the RX/TX buffers and rings while the block holds prefetched descriptors, only now on remove instead of on close? The remove path looks like this: hix5hd2_dev_remove() unregister_netdev() hix5hd2_net_close() /* port disable, irq off, clocks off */ hix5hd2_destroy_hw_desc_queue() hix5hd2_free_dma_desc_rings() /* unmap and free rx_skb[]/tx_skb[] */ dma_free_coherent() /* all four rings */ hix5hd2_net_close() writes no queue pointer register. The commit message also says neither available reset can quiesce the block. So the queue state inside the MAC appears to survive this free. On a re-probe (sysfs unbind/bind or rmmod/insmod), the only thing that could clear that state is hix5hd2_mac_core_reset(): static inline void hix5hd2_mac_core_reset(struct hix5hd2_priv *priv) { if (!priv->mac_core_rst) return; ... } The gmac0/gmac1 nodes in arch/arm/boot/dts/hisilicon/hisi-x5hd2.dtsi have no resets property. devm_reset_control_get(dev, "mac_core") therefore fails and mac_core_rst is NULL on the SoC this patch targets. The next open then runs three steps: - hix5hd2_hw_init() rewrites only the depth and start addresses. - hix5hd2_rx_refill() fills CIRC_SPACE() slots computed from the stale RX_FQ_WR_ADDR and RX_FQ_RD_ADDR values. - hix5hd2_port_enable() restarts descriptor processing. Under the hardware model in the commit message, would the block then use the previous binding's prefetched descriptors and DMA into RX buffers that were freed at remove? The rest of the hardware FQ entries would sit in a freshly zeroed ring with buff_addr 0. After that, completions would land on slots where the newly allocated, zeroed rx_skb[]/tx_skb[] entries are NULL: hix5hd2_rx() { ... skb = priv->rx_skb[pos]; if (unlikely(!skb)) { netdev_err(dev, "inconsistent rx_skb\n"); break; } ... } hix5hd2_xmit_reclaim() does the same for tx_skb[]. Both loops break without advancing RX_BQ_RD_ADDR or TX_RQ_RD_ADDR. Can RX and TX stall permanently at this point? After this patch the TX timeout close/open no longer touches the rings, so it does not look like it can recover. Is a quiesce or a reset at probe needed before this free, so the fix also covers the remove and re-probe path? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126110310.344521-1-mmyangfl%40gmail.com ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 11:51 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-26 11:03 [PATCH net 0/3] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang 2026-11-26 11:03 ` [PATCH net 1/3] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang 2026-11-26 11:03 ` [PATCH net 2/3] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang 2026-11-26 11:03 ` [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang 2026-11-27 11:51 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox