DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Washington <joshwash@google.com>
To: Joshua Washington <joshwash@google.com>,
	Jeroen de Borst <jeroendb@google.com>,
	Rushil Gupta <rushilg@google.com>
Cc: dev@dpdk.org, "Jasper Tran O'Leary" <jtranoleary@google.com>,
	stable@dpdk.org
Subject: [PATCH 09/12] net/gve: properly handle RSS realloc failures
Date: Thu,  3 Dec 2026 15:26:32 -0800	[thread overview]
Message-ID: <20261203232637.1044501-10-joshwash@google.com> (raw)
In-Reply-To: <20261203232637.1044501-1-joshwash@google.com>

From: Jasper Tran O'Leary <jtranoleary@google.com>

Updating the cached private RSS configuration overwrites the key and
redirection table pointers directly with the reallocation result and
updates metadata sizes before allocations succeed. If reallocation fails
under memory pressure, the previous buffers are leaked and the cached
configuration retains NULL pointers alongside non-zero sizes, causing
subsequent RSS queries or updates to dereference NULL.

Move private RSS cache management out of gve_adminq_configure_rss() into
a wrapper in gve_ethdev.c so the base AdminQ helper only sends the
device command. Pre-allocate the replacement cache with
gve_init_rss_config() before issuing the AdminQ command, and transfer
ownership into priv->rss_config via gve_update_priv_rss_config() only
after the command succeeds, eliminating rte_realloc() and ensuring a
failed allocation never leaves the cache corrupted or out of sync with
the device. Also propagate gve_init_rss_config_from_priv() failure in
gve_dev_configure().

Fixes: d6ac6f456398 ("net/gve: add RSS helpers")
Cc: stable@dpdk.org

Signed-off-by: Jasper Tran O'Leary <jtranoleary@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
---
 drivers/net/gve/base/gve_adminq.c |  6 ++--
 drivers/net/gve/gve_ethdev.c      | 41 ++++++++++++++++++++++--
 drivers/net/gve/gve_rss.c         | 53 ++++++-------------------------
 drivers/net/gve/gve_rss.h         |  7 ++--
 4 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index 893763f3a3..d077c40b9a 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -8,7 +8,6 @@
 #include "../gve_ethdev.h"
 #include "gve_adminq.h"
 #include "gve_register.h"
-#include "gve_rss.h"
 
 #define GVE_MAX_ADMINQ_RELEASE_CHECK	500
 #define GVE_ADMINQ_SLEEP_LEN		20
@@ -1244,7 +1243,8 @@ int gve_adminq_configure_rss(struct gve_priv *priv,
 	int err = 0;
 	int i;
 
-	if (!rss_config->indir_size || !rss_config->key_size)
+	if (!rss_config || !rss_config->indir_size || !rss_config->key_size ||
+	    !rss_config->indir || !rss_config->key)
 		return -EINVAL;
 
 	indir = gve_alloc_dma_mem(&indirection_table_dma_mem,
@@ -1278,8 +1278,6 @@ int gve_adminq_configure_rss(struct gve_priv *priv,
 	};
 
 	err = gve_adminq_execute_cmd(priv, &cmd);
-	if (err == 0)
-		gve_update_priv_rss_config(priv, rss_config);
 
 out:
 	if (indir)
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index f27932aa89..dcb270d269 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -275,7 +275,10 @@ gve_dev_configure(struct rte_eth_dev *dev)
 		if (err == 0) {
 			struct gve_rss_config update_reta_config;
 
-			gve_init_rss_config_from_priv(priv, &update_reta_config);
+			err = gve_init_rss_config_from_priv(priv, &update_reta_config);
+			if (err != 0)
+				return err;
+
 			gve_generate_rss_reta(dev, &update_reta_config);
 
 			err = process_priv->ctrl_ops->configure_rss(priv, &update_reta_config);
@@ -1707,6 +1710,40 @@ gve_adminq_get_device_properties(struct gve_priv *priv)
 	return gve_adminq_describe_device(priv);
 }
 
+static int
+gve_configure_rss_adminq(struct gve_priv *priv,
+			 struct gve_rss_config *rss_config)
+{
+	struct gve_rss_config new_cache = {0};
+	int err;
+
+	if (priv == NULL || rss_config == NULL ||
+	    rss_config->key_size == 0 || rss_config->key == NULL ||
+	    rss_config->indir_size == 0 || rss_config->indir == NULL)
+		return -EINVAL;
+
+	err = gve_init_rss_config(&new_cache, rss_config->key_size,
+				  rss_config->indir_size);
+	if (err != 0)
+		return err;
+
+	err = gve_adminq_configure_rss(priv, rss_config);
+	if (err != 0) {
+		gve_free_rss_config(&new_cache);
+		return err;
+	}
+
+	new_cache.hash_types = rss_config->hash_types;
+	new_cache.alg = rss_config->alg;
+	memcpy(new_cache.key, rss_config->key,
+	       (size_t)rss_config->key_size * sizeof(*new_cache.key));
+	memcpy(new_cache.indir, rss_config->indir,
+	       (size_t)rss_config->indir_size * sizeof(*new_cache.indir));
+
+	gve_update_priv_rss_config(priv, &new_cache);
+	return 0;
+}
+
 static const struct gve_ctrl_ops gve_adminq_ops = {
 	.init_ctrl_plane = gve_adminq_alloc,
 	.free_ctrl_plane = gve_adminq_free,
@@ -1718,7 +1755,7 @@ static const struct gve_ctrl_ops gve_adminq_ops = {
 	.create_rx_queues = gve_adminq_create_rx_queues,
 	.destroy_rx_queues = gve_adminq_destroy_rx_queues,
 	.report_link_speed = gve_adminq_report_link_speed,
-	.configure_rss = gve_adminq_configure_rss,
+	.configure_rss = gve_configure_rss_adminq,
 	.add_flow_rule = gve_adminq_add_flow_rule,
 	.del_flow_rule = gve_adminq_del_flow_rule,
 	.reset_flow_rules = gve_adminq_reset_flow_rules,
diff --git a/drivers/net/gve/gve_rss.c b/drivers/net/gve/gve_rss.c
index 691ec6dab1..a6863aa7a5 100644
--- a/drivers/net/gve/gve_rss.c
+++ b/drivers/net/gve/gve_rss.c
@@ -75,53 +75,18 @@ gve_free_rss_config(struct gve_rss_config *gve_rss_conf)
 	memset(gve_rss_conf, 0, sizeof(*gve_rss_conf));
 }
 
-int
-gve_update_priv_rss_config(struct gve_priv *priv, struct gve_rss_config *config)
+void
+gve_update_priv_rss_config(struct gve_priv *priv,
+			   struct gve_rss_config *new_config)
 {
-	struct gve_rss_config *priv_config = &priv->rss_config;
-	int key_bytes, indir_bytes;
-
-	if (!config)
-		return -EINVAL;
-	if (config->key_size == 0 || !config->key)
-		return -EINVAL;
-	if (config->indir_size == 0 || !config->indir)
-		return -EINVAL;
-
-	priv_config->hash_types = config->hash_types;
-	priv_config->alg = config->alg;
-
-	priv_config->key_size = config->key_size;
-	key_bytes = priv_config->key_size * sizeof(*priv_config->key);
-	if (!priv_config->key)
-		priv_config->key = rte_zmalloc("priv rss key", key_bytes,
-			RTE_CACHE_LINE_SIZE);
-	else
-		priv_config->key = rte_realloc(priv_config->key, key_bytes,
-			RTE_CACHE_LINE_SIZE);
-	if (!priv_config->key)
-		return -ENOMEM;
-
-	priv_config->indir_size = config->indir_size;
-	indir_bytes = priv_config->indir_size * sizeof(*priv_config->indir);
-	if (!priv_config->indir)
-		priv_config->indir = rte_zmalloc("priv rss reta", indir_bytes,
-			RTE_CACHE_LINE_SIZE);
-	else
-		priv_config->indir = rte_realloc(priv_config->indir,
-			indir_bytes, RTE_CACHE_LINE_SIZE);
-
-	if (!priv_config->indir)
-		return -ENOMEM;
-
-	memcpy(priv_config->indir, config->indir,
-		config->indir_size * sizeof(*priv_config->indir));
-	memcpy(priv_config->key, config->key,
-		config->key_size * sizeof(*priv_config->key));
+	if (priv == NULL || new_config == NULL ||
+	    new_config == &priv->rss_config)
+		return;
 
+	gve_free_rss_config(&priv->rss_config);
+	priv->rss_config = *new_config;
+	memset(new_config, 0, sizeof(*new_config));
 	priv->rss_cache_dirty = false;
-
-	return 0;
 }
 
 int
diff --git a/drivers/net/gve/gve_rss.h b/drivers/net/gve/gve_rss.h
index 64ac0514b9..aef92d1f16 100644
--- a/drivers/net/gve/gve_rss.h
+++ b/drivers/net/gve/gve_rss.h
@@ -56,11 +56,12 @@ void
 gve_free_rss_config(struct gve_rss_config *gve_rss_conf);
 
 /**
- * Updates the rss_config stored in `priv` with the contents of `config`.
+ * Updates the rss_config stored in `priv` by taking ownership of the
+ * buffers in `new_config` and clearing `new_config`. This cannot fail.
  */
-int
+void
 gve_update_priv_rss_config(struct gve_priv *priv,
-			   struct gve_rss_config *config);
+			   struct gve_rss_config *new_config);
 
 /**
  * Updates the RSS key stored in `gve_rss_conf`. It is prioritized as follows:
-- 
2.56.1.915.g69d5ec7298-goog


  parent reply	other threads:[~2026-12-03 23:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 23:26 [PATCH 00/12] net/gve: stability fixes and DQO scattered Rx support Joshua Washington
2026-12-03 23:26 ` [PATCH 01/12] net/gve: disable queue start and stop Joshua Washington
2026-12-03 23:26 ` [PATCH 02/12] net/gve: free partially received GQI Rx packet Joshua Washington
2026-12-03 23:26 ` [PATCH 03/12] net/gve: fix integer underflow in GQI Rx path Joshua Washington
2026-12-03 23:26 ` [PATCH 04/12] net/gve: fix integer truncation in GQI QPL Tx path Joshua Washington
2026-12-03 23:26 ` [PATCH 05/12] net/gve: do not count unsent DQO Tx packets as oerrors Joshua Washington
2026-12-03 23:26 ` [PATCH 06/12] net/gve: disable unsupported TCP LRO offload Joshua Washington
2026-12-03 23:26 ` [PATCH 07/12] net/gve: drop multi-seg Rx packets if scatter is off Joshua Washington
2026-12-03 23:26 ` [PATCH 08/12] net/gve: reject non-power-of-2 ring sizes on DQO Joshua Washington
2026-12-03 23:26 ` Joshua Washington [this message]
2026-12-03 23:26 ` [PATCH 10/12] net/gve: reject unsupported flow attributes and item masks Joshua Washington
2026-12-03 23:26 ` [PATCH 11/12] net/gve: fix mbuf leak on GQI Rx queue start Joshua Washington
2026-12-03 23:26 ` [PATCH 12/12] net/gve: support scattered Rx for DQO Joshua Washington
2026-12-04 19:13 ` [PATCH 00/12] net/gve: stability fixes and DQO scattered Rx support Stephen Hemminger

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=20261203232637.1044501-10-joshwash@google.com \
    --to=joshwash@google.com \
    --cc=dev@dpdk.org \
    --cc=jeroendb@google.com \
    --cc=jtranoleary@google.com \
    --cc=rushilg@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