Skip to contentSkip to conversation

gve: clear flow rule cache state when freeing its buffers

PATCH In review Zhao Li 2 participants 2 messages Nov 18

Subsystems (3)
lore
Share & tools
lore

Zhao Li

author
#0 lore raw

PATCH 1/1 gve: clear flow rule cache state when freeing its buffers

Freeing the flow-rule cache clears its pointers but retains the cached counts and synchronization flag. A successful rule-reset command invalidates the cache, but a failed reset does not. Recovery can then allocate zeroed buffers while retaining a nonzero count and synced flag, causing a later flow-rule query to return zeroed rules as if they were a synchronized cache.

Clear the complete cache state after freeing its buffers so reallocation always starts unsynchronized with zero cached entries.

Found by code review. Compile-tested with W=1.

AI assistance was used.

Fixes 57718b60df9b ("gve: Add flow steering adminq commands")

---
No new W=1, sparse or smatch warnings.

 drivers/net/ethernet/google/gve/gve_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/google/gve/gve_main.c +1 -2
index 35cf0f06a0f2..747f5229d7ef 100644
@@ -189,9 +189,8 @@ static void gve_free_flow_rule_caches(struct gve_priv *priv)
 	struct gve_flow_rules_cache *flow_rules_cache = &priv->flow_rules_cache;
 
 	kvfree(flow_rules_cache->rule_ids_cache);
-	flow_rules_cache->rule_ids_cache = NULL;
 	kvfree(flow_rules_cache->rules_cache);
-	flow_rules_cache->rules_cache = NULL;
+	memset(flow_rules_cache, 0, sizeof(*flow_rules_cache));
 }
 
 static int gve_alloc_rss_config_cache(struct gve_priv *priv)

base-commit: a2239d5dbbda3a61b6323df8836f605921a29f7f

Signature · 1 line
2.56.1
#1 lore raw
Quoted 5 lines · Zhao Li

Freeing the flow-rule cache clears its pointers but retains the cached counts and synchronization flag. A successful rule-reset command invalidates the cache, but a failed reset does not. Recovery can then allocate zeroed buffers while retaining a nonzero count and synced flag,

Yes, this is possible when gve_adminq_reset_flow_rules() fails in the gve_reset() path however....

Quoted 2 lines

causing a later flow-rule query to return zeroed rules as if they were a synchronized cache.

The user visible case is narrower and will only show up on an ethtool -n <dev> rule 0 with a stale value. Because gve_get_flow_rule_entry() will end up re-querying for every other location.

Also, the more holistic fix is up in gve_adminq_configure_flow_rule():

(quoted diff) +0 -0

b/drivers/net/ethernet/google/gve/gve_adminq.c
index 8b215fca9c1b..ee9d5bc20e7e 100644

drivers/net/ethernet/google/gve/gve_adminq.c +1 -2
@@ -1399,8 +1399,7 @@ gve_adminq_configure_flow_rule(struct gve_priv *priv,
                        sizeof(struct gve_adminq_configure_flow_rule),
                        flow_rule_cmd);
 
-       if (!err)
-               priv->flow_rules_cache.rules_cache_synced = false;
+       priv->flow_rules_cache.rules_cache_synced = false;
 
        return err;
 }

When a new flow rule configuration is _attempted_ as opposed to just successful, we can treat the cache as out of sync because the command could have failed for any reason and the device state is unknown. This covers both the reset path and a failed add/del command.

I'd suggest a v2 with this diff instead of the memset describing the problem a bit more in detail in the commit message. Feel free to use:

pw-bot: cr

Quoted 37 lines

Clear the complete cache state after freeing its buffers so reallocation always starts unsynchronized with zero cached entries.

Found by code review. Compile-tested with W=1.

AI assistance was used.

Fixes 57718b60df9b ("gve: Add flow steering adminq commands")

---
No new W=1, sparse or smatch warnings.

 drivers/net/ethernet/google/gve/gve_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/google/gve/gve_main.c +1 -2
index 35cf0f06a0f2..747f5229d7ef 100644
@@ -189,9 +189,8 @@ static void gve_free_flow_rule_caches(struct gve_priv *priv)
        struct gve_flow_rules_cache *flow_rules_cache = &priv->flow_rules_cache;
 
        kvfree(flow_rules_cache->rule_ids_cache);
-       flow_rules_cache->rule_ids_cache = NULL;
        kvfree(flow_rules_cache->rules_cache);
-       flow_rules_cache->rules_cache = NULL;
+       memset(flow_rules_cache, 0, sizeof(*flow_rules_cache));
 }
 
 static int gve_alloc_rss_config_cache(struct gve_priv *priv)

base-commit: a2239d5dbbda3a61b6323df8836f605921a29f7f --
2.56.1