* [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen
@ 2026-12-06 11:00 David Yang
2026-12-06 11:00 ` [PATCH net v2 1/4] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: David Yang @ 2026-12-06 11:00 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.
v2:
- linearize skb if too many frags
- schedule NAPI once after reopening
v1: https://lore.kernel.org/r/20261126110310.344521-1-mmyangfl@gmail.com
David Yang (4):
net: hix5hd2_gmac: unmap input TX buffers, not returned ones
net: hix5hd2_gmac: linearize skb if too many frags
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 | 42 +++++++++++++++----
1 file changed, 34 insertions(+), 8 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 1/4] net: hix5hd2_gmac: unmap input TX buffers, not returned ones
2026-12-06 11:00 [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang
@ 2026-12-06 11:00 ` David Yang
2026-12-06 11:00 ` [PATCH net v2 2/4] net: hix5hd2_gmac: linearize skb if too many frags David Yang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: David Yang @ 2026-12-06 11:00 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 v2 2/4] net: hix5hd2_gmac: linearize skb if too many frags
2026-12-06 11:00 [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang
2026-12-06 11:00 ` [PATCH net v2 1/4] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang
@ 2026-12-06 11:00 ` David Yang
2026-12-06 11:00 ` [PATCH net v2 3/4] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang
2026-12-06 11:00 ` [PATCH net v2 4/4] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang
3 siblings, 0 replies; 5+ messages in thread
From: David Yang @ 2026-12-06 11:00 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
Hardware supports at most SG_MAX_SKB_FRAGS fragments. Ask the core to
linearize it if there are too many fragments.
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 | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
index 46386a0954a2..4aa5cb559d38 100644
--- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
@@ -907,12 +907,25 @@ static void hix5hd2_net_timeout(struct net_device *dev, unsigned int txqueue)
schedule_work(&priv->tx_timeout_task);
}
+static netdev_features_t
+hix5hd2_net_features_check(struct sk_buff *skb, struct net_device *dev,
+ netdev_features_t features)
+{
+#if (MAX_SKB_FRAGS > SG_MAX_SKB_FRAGS)
+ if (skb_shinfo(skb)->nr_frags > SG_MAX_SKB_FRAGS)
+ features &= ~NETIF_F_SG;
+#endif
+
+ return features;
+}
+
static const struct net_device_ops hix5hd2_netdev_ops = {
.ndo_open = hix5hd2_net_open,
.ndo_stop = hix5hd2_net_close,
.ndo_start_xmit = hix5hd2_net_xmit,
.ndo_tx_timeout = hix5hd2_net_timeout,
.ndo_set_mac_address = hix5hd2_net_set_mac_address,
+ .ndo_features_check = hix5hd2_net_features_check,
};
static const struct ethtool_ops hix5hd2_ethtools_ops = {
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net v2 3/4] net: hix5hd2_gmac: release TX SG buffers if using SG
2026-12-06 11:00 [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang
2026-12-06 11:00 ` [PATCH net v2 1/4] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang
2026-12-06 11:00 ` [PATCH net v2 2/4] net: hix5hd2_gmac: linearize skb if too many frags David Yang
@ 2026-12-06 11:00 ` David Yang
2026-12-06 11:00 ` [PATCH net v2 4/4] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang
3 siblings, 0 replies; 5+ messages in thread
From: David Yang @ 2026-12-06 11:00 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.
Fix it by mirroring hix5hd2_xmit_reclaim().
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 4aa5cb559d38..106356a1d264 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 v2 4/4] net: hix5hd2_gmac: keep TX/RX queues alive across a close
2026-12-06 11:00 [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang
` (2 preceding siblings ...)
2026-12-06 11:00 ` [PATCH net v2 3/4] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang
@ 2026-12-06 11:00 ` David Yang
3 siblings, 0 replies; 5+ messages in thread
From: David Yang @ 2026-12-06 11:00 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. hix5hd2_hw_init() wipes the pending interrupt status that would
have announced completions stranded behind the close, and the BQL state
now carries across the close as well, so schedule NAPI once after the
reopen.
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 | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
index 106356a1d264..850675fb3d13 100644
--- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
@@ -860,13 +860,17 @@ 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);
hix5hd2_port_enable(priv);
hix5hd2_irq_enable(priv);
+ /* Buffers retained across a close, but hix5hd2_hw_init() discarded any
+ * pending interrupt status; process any outstanding packets now.
+ */
+ napi_schedule(&priv->napi);
+
return 0;
}
@@ -878,7 +882,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 a close; release them with the rings on
+ * device removal.
+ */
if (dev->phydev) {
phy_stop(dev->phydev);
@@ -1003,6 +1009,8 @@ static void hix5hd2_destroy_hw_desc_queue(struct hix5hd2_priv *priv)
{
int i;
+ 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,
@@ -1281,10 +1289,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:
@@ -1311,9 +1319,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
end of thread, other threads:[~2026-12-06 11:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 11:00 [PATCH net v2 0/4] net: hix5hd2_gmac: fix memory corruption across interface reopen David Yang
2026-12-06 11:00 ` [PATCH net v2 1/4] net: hix5hd2_gmac: unmap input TX buffers, not returned ones David Yang
2026-12-06 11:00 ` [PATCH net v2 2/4] net: hix5hd2_gmac: linearize skb if too many frags David Yang
2026-12-06 11:00 ` [PATCH net v2 3/4] net: hix5hd2_gmac: release TX SG buffers if using SG David Yang
2026-12-06 11:00 ` [PATCH net v2 4/4] net: hix5hd2_gmac: keep TX/RX queues alive across a close David Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox