[PATCH 09/12] net/gve: properly handle RSS realloc failures

Joshua Washington joshwash at google.com
Fri Dec 4 00:26:32 CET 2026


From: Jasper Tran O'Leary <jtranoleary at 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 at dpdk.org

Signed-off-by: Jasper Tran O'Leary <jtranoleary at google.com>
Signed-off-by: Joshua Washington <joshwash at 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



More information about the stable mailing list