patches for DPDK stable branches
 help / color / mirror / Atom feed
From: "Jasper Tran O'Leary" <jtranoleary@google.com>
To: jtranoleary@google.com
Cc: stable@dpdk.org, Joshua Washington <joshwash@google.com>
Subject: [PATCH] net/gve: free device resources in gve_dev_close
Date: Fri, 18 Jul 2025 18:22:16 +0000	[thread overview]
Message-ID: <20250718182216.466040-1-jtranoleary@google.com> (raw)

Previously, upon a device close, the driver would only stop its queues,
whereas a device remove would cause the driver to free its resources.
However, expected behavior in DPDK is to have a device close free all of
its resources because ports are not reused.

This patch adds all device teardown functionality within the device
close function. It also flattens and refactors steps related to freeing
device resources such that gve_dev_close reads more linearly.

Fixes: 457967cd2b2d ("net/gve: support device initialization")
Cc: stable@dpdk.org

Signed-off-by: Jasper Tran O'Leary <jtranoleary@google.com>
Acked-by: Joshua Washington <joshwash@google.com>
---
 drivers/net/gve/base/gve_adminq.c |   2 -
 drivers/net/gve/gve_ethdev.c      | 139 +++++++++++++++++++++--------------------
 2 files changed, 72 insertions(+), 69 deletions(-)

diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index 4b250a9..15a05da 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -276,8 +276,6 @@ void gve_adminq_release(struct gve_priv *priv)
 			msleep(GVE_ADMINQ_SLEEP_LEN);
 		}
 	}
-	gve_clear_device_rings_ok(priv);
-	gve_clear_device_resources_ok(priv);
 	gve_clear_admin_queue_ok(priv);
 }

diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index ef1c543..56e1a47 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -383,6 +383,8 @@ gve_start_queues(struct rte_eth_dev *dev)
 		}
 	}

+	gve_set_device_rings_ok(priv);
+
 	return 0;

 err_rx:
@@ -395,6 +397,8 @@ err_tx:
 		gve_stop_tx_queues(dev);
 	else
 		gve_stop_tx_queues_dqo(dev);
+
+	gve_clear_device_rings_ok(priv);
 	return ret;
 }

@@ -440,8 +444,11 @@ static int
 gve_dev_stop(struct rte_eth_dev *dev)
 {
 	struct gve_priv *priv = dev->data->dev_private;
+
+	dev->data->dev_started = 0;
 	dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;

+	gve_clear_device_rings_ok(priv);
 	if (gve_is_gqi(priv)) {
 		gve_stop_tx_queues(dev);
 		gve_stop_rx_queues(dev);
@@ -450,27 +457,18 @@ gve_dev_stop(struct rte_eth_dev *dev)
 		gve_stop_rx_queues_dqo(dev);
 	}

-	dev->data->dev_started = 0;
-
 	if (gve_is_gqi(dev->data->dev_private))
 		gve_free_stats_report(dev);

 	return 0;
 }

-static int
-gve_dev_close(struct rte_eth_dev *dev)
+static void
+gve_free_queues(struct rte_eth_dev *dev)
 {
 	struct gve_priv *priv = dev->data->dev_private;
-	int err = 0;
 	uint16_t i;

-	if (dev->data->dev_started) {
-		err = gve_dev_stop(dev);
-		if (err != 0)
-			PMD_DRV_LOG(ERR, "Failed to stop dev.");
-	}
-
 	if (gve_is_gqi(priv)) {
 		for (i = 0; i < dev->data->nb_tx_queues; i++)
 			gve_tx_queue_release(dev, i);
@@ -484,8 +482,67 @@ gve_dev_close(struct rte_eth_dev *dev)
 		for (i = 0; i < dev->data->nb_rx_queues; i++)
 			gve_rx_queue_release_dqo(dev, i);
 	}
+}
+
+static void
+gve_free_counter_array(struct gve_priv *priv)
+{
+	rte_memzone_free(priv->cnt_array_mz);
+	priv->cnt_array = NULL;
+}
+
+static void
+gve_free_irq_db(struct gve_priv *priv)
+{
+	rte_memzone_free(priv->irq_dbs_mz);
+	priv->irq_dbs = NULL;
+}
+
+static void
+gve_free_ptype_lut_dqo(struct gve_priv *priv)
+{
+	if (!gve_is_gqi(priv)) {
+		rte_free(priv->ptype_lut_dqo);
+		priv->ptype_lut_dqo = NULL;
+	}
+}

-	rte_free(priv->adminq);
+static void
+gve_teardown_device_resources(struct gve_priv *priv)
+{
+	int err;
+
+	/* Tell device its resources are being freed */
+	if (gve_get_device_resources_ok(priv)) {
+		err = gve_adminq_deconfigure_device_resources(priv);
+		if (err)
+			PMD_DRV_LOG(ERR, "Could not deconfigure device resources: err=%d", err);
+	}
+
+	gve_free_ptype_lut_dqo(priv);
+	gve_free_counter_array(priv);
+	gve_free_irq_db(priv);
+	gve_clear_device_resources_ok(priv);
+}
+
+static int
+gve_dev_close(struct rte_eth_dev *dev)
+{
+	struct gve_priv *priv = dev->data->dev_private;
+	int err = 0;
+
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	if (dev->data->dev_started) {
+		err = gve_dev_stop(dev);
+		if (err != 0)
+			PMD_DRV_LOG(ERR, "Failed to stop dev.");
+	}
+
+	gve_free_queues(dev);
+	gve_teardown_device_resources(priv);
+	gve_adminq_free(priv);

 	dev->data->mac_addrs = NULL;

@@ -1056,41 +1113,6 @@ static const struct eth_dev_ops gve_eth_dev_ops_dqo = {
 	.reta_query           = gve_rss_reta_query,
 };

-static void
-gve_free_counter_array(struct gve_priv *priv)
-{
-	rte_memzone_free(priv->cnt_array_mz);
-	priv->cnt_array = NULL;
-}
-
-static void
-gve_free_irq_db(struct gve_priv *priv)
-{
-	rte_memzone_free(priv->irq_dbs_mz);
-	priv->irq_dbs = NULL;
-}
-
-static void
-gve_teardown_device_resources(struct gve_priv *priv)
-{
-	int err;
-
-	/* Tell device its resources are being freed */
-	if (gve_get_device_resources_ok(priv)) {
-		err = gve_adminq_deconfigure_device_resources(priv);
-		if (err)
-			PMD_DRV_LOG(ERR, "Could not deconfigure device resources: err=%d", err);
-	}
-
-	if (!gve_is_gqi(priv)) {
-		rte_free(priv->ptype_lut_dqo);
-		priv->ptype_lut_dqo = NULL;
-	}
-	gve_free_counter_array(priv);
-	gve_free_irq_db(priv);
-	gve_clear_device_resources_ok(priv);
-}
-
 static int
 pci_dev_msix_vec_count(struct rte_pci_device *pdev)
 {
@@ -1160,6 +1182,8 @@ gve_setup_device_resources(struct gve_priv *priv)
 		}
 	}

+	gve_set_device_resources_ok(priv);
+
 	return 0;
 free_ptype_lut:
 	rte_free(priv->ptype_lut_dqo);
@@ -1252,13 +1276,6 @@ free_adminq:
 	return err;
 }

-static void
-gve_teardown_priv_resources(struct gve_priv *priv)
-{
-	gve_teardown_device_resources(priv);
-	gve_adminq_free(priv);
-}
-
 static int
 gve_dev_init(struct rte_eth_dev *eth_dev)
 {
@@ -1328,18 +1345,6 @@ gve_dev_init(struct rte_eth_dev *eth_dev)
 	return 0;
 }

-static int
-gve_dev_uninit(struct rte_eth_dev *eth_dev)
-{
-	struct gve_priv *priv = eth_dev->data->dev_private;
-
-	gve_teardown_priv_resources(priv);
-
-	eth_dev->data->mac_addrs = NULL;
-
-	return 0;
-}
-
 static int
 gve_pci_probe(__rte_unused struct rte_pci_driver *pci_drv,
 	      struct rte_pci_device *pci_dev)
@@ -1350,7 +1355,7 @@ gve_pci_probe(__rte_unused struct rte_pci_driver *pci_drv,
 static int
 gve_pci_remove(struct rte_pci_device *pci_dev)
 {
-	return rte_eth_dev_pci_generic_remove(pci_dev, gve_dev_uninit);
+	return rte_eth_dev_pci_generic_remove(pci_dev, gve_dev_close);
 }

 static const struct rte_pci_id pci_id_gve_map[] = {
--
2.50.0.727.gbf7dc18ff4-goog


             reply	other threads:[~2025-07-18 18:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-18 18:22 Jasper Tran O'Leary [this message]
2025-07-18 18:27 Jasper Tran O'Leary

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=20250718182216.466040-1-jtranoleary@google.com \
    --to=jtranoleary@google.com \
    --cc=joshwash@google.com \
    --cc=stable@dpdk.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;
as well as URLs for NNTP newsgroup(s).