Netdev List
 help / color / mirror / Atom feed
From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>,
	Jian Shen <shenjian15@huawei.com>,
	Jijie Shao <shaojijie@huawei.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Zhangfei Gao <zhangfei.gao@linaro.org>,
	Dongpo Li <lidongpo@hisilicon.com>
Subject: [PATCH net 3/3] net: hix5hd2_gmac: keep TX/RX queues alive across a close
Date: Thu, 26 Nov 2026 19:03:05 +0800	[thread overview]
Message-ID: <20261126110310.344521-4-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261126110310.344521-1-mmyangfl@gmail.com>

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


      parent reply	other threads:[~2026-11-26 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126110310.344521-4-mmyangfl@gmail.com \
    --to=mmyangfl@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lidongpo@hisilicon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shaojijie@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=zhangfei.gao@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox