Blame SOURCES/0248-netdrv-net-mlx5e-CT-Use-rhashtable-s-ct-entries-inst.patch

d8f823
From 38789d72ea1a8009cd52229695b56e6749a775db Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 19 May 2020 07:49:10 -0400
d8f823
Subject: [PATCH 248/312] [netdrv] net/mlx5e: CT: Use rhashtable's ct entries
d8f823
 instead of a separate list
d8f823
d8f823
Message-id: <20200519074934.6303-40-ahleihel@redhat.com>
d8f823
Patchwork-id: 310551
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1663246 39/63] net/mlx5e: CT: Use rhashtable's ct entries instead of a separate list
d8f823
Bugzilla: 1663246
d8f823
RH-Acked-by: Marcelo Leitner <mleitner@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
RH-Acked-by: John Linville <linville@redhat.com>
d8f823
RH-Acked-by: Ivan Vecera <ivecera@redhat.com>
d8f823
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1663246
d8f823
Upstream: v5.7-rc2
d8f823
d8f823
commit 9808dd0a2aeebcb72239a3b082159b0186d9ac3d
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Fri Mar 27 12:12:31 2020 +0300
d8f823
d8f823
    net/mlx5e: CT: Use rhashtable's ct entries instead of a separate list
d8f823
d8f823
    Fixes CT entries list corruption.
d8f823
d8f823
    After allowing parallel insertion/removals in upper nf flow table
d8f823
    layer, unprotected ct entries list can be corrupted by parallel add/del
d8f823
    on the same flow table.
d8f823
d8f823
    CT entries list is only used while freeing a ct zone flow table to
d8f823
    go over all the ct entries offloaded on that zone/table, and flush
d8f823
    the table.
d8f823
d8f823
    As rhashtable already provides an api to go over all the inserted entries,
d8f823
    fix the race by using the rhashtable iteration instead, and remove the list.
d8f823
d8f823
    Fixes: 7da182a998d6 ("netfilter: flowtable: Use work entry per offload command")
d8f823
    Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
d8f823
d8f823
Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
d8f823
---
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 19 +++++++------------
d8f823
 1 file changed, 7 insertions(+), 12 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
index cb43b53bc235..14b29d0d5092 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
@@ -67,11 +67,9 @@ struct mlx5_ct_ft {
d8f823
 	struct nf_flowtable *nf_ft;
d8f823
 	struct mlx5_tc_ct_priv *ct_priv;
d8f823
 	struct rhashtable ct_entries_ht;
d8f823
-	struct list_head ct_entries_list;
d8f823
 };
d8f823
 
d8f823
 struct mlx5_ct_entry {
d8f823
-	struct list_head list;
d8f823
 	u16 zone;
d8f823
 	struct rhash_head node;
d8f823
 	struct flow_rule *flow_rule;
d8f823
@@ -617,8 +615,6 @@ mlx5_tc_ct_block_flow_offload_add(struct mlx5_ct_ft *ft,
d8f823
 	if (err)
d8f823
 		goto err_insert;
d8f823
 
d8f823
-	list_add(&entry->list, &ft->ct_entries_list);
d8f823
-
d8f823
 	return 0;
d8f823
 
d8f823
 err_insert:
d8f823
@@ -646,7 +642,6 @@ mlx5_tc_ct_block_flow_offload_del(struct mlx5_ct_ft *ft,
d8f823
 	WARN_ON(rhashtable_remove_fast(&ft->ct_entries_ht,
d8f823
 				       &entry->node,
d8f823
 				       cts_ht_params));
d8f823
-	list_del(&entry->list);
d8f823
 	kfree(entry);
d8f823
 
d8f823
 	return 0;
d8f823
@@ -818,7 +813,6 @@ mlx5_tc_ct_add_ft_cb(struct mlx5_tc_ct_priv *ct_priv, u16 zone,
d8f823
 	ft->zone = zone;
d8f823
 	ft->nf_ft = nf_ft;
d8f823
 	ft->ct_priv = ct_priv;
d8f823
-	INIT_LIST_HEAD(&ft->ct_entries_list);
d8f823
 	refcount_set(&ft->refcount, 1);
d8f823
 
d8f823
 	err = rhashtable_init(&ft->ct_entries_ht, &cts_ht_params);
d8f823
@@ -847,12 +841,12 @@ mlx5_tc_ct_add_ft_cb(struct mlx5_tc_ct_priv *ct_priv, u16 zone,
d8f823
 }
d8f823
 
d8f823
 static void
d8f823
-mlx5_tc_ct_flush_ft(struct mlx5_tc_ct_priv *ct_priv, struct mlx5_ct_ft *ft)
d8f823
+mlx5_tc_ct_flush_ft_entry(void *ptr, void *arg)
d8f823
 {
d8f823
-	struct mlx5_ct_entry *entry;
d8f823
+	struct mlx5_tc_ct_priv *ct_priv = arg;
d8f823
+	struct mlx5_ct_entry *entry = ptr;
d8f823
 
d8f823
-	list_for_each_entry(entry, &ft->ct_entries_list, list)
d8f823
-		mlx5_tc_ct_entry_del_rules(ft->ct_priv, entry);
d8f823
+	mlx5_tc_ct_entry_del_rules(ct_priv, entry);
d8f823
 }
d8f823
 
d8f823
 static void
d8f823
@@ -863,9 +857,10 @@ mlx5_tc_ct_del_ft_cb(struct mlx5_tc_ct_priv *ct_priv, struct mlx5_ct_ft *ft)
d8f823
 
d8f823
 	nf_flow_table_offload_del_cb(ft->nf_ft,
d8f823
 				     mlx5_tc_ct_block_flow_offload, ft);
d8f823
-	mlx5_tc_ct_flush_ft(ct_priv, ft);
d8f823
 	rhashtable_remove_fast(&ct_priv->zone_ht, &ft->node, zone_params);
d8f823
-	rhashtable_destroy(&ft->ct_entries_ht);
d8f823
+	rhashtable_free_and_destroy(&ft->ct_entries_ht,
d8f823
+				    mlx5_tc_ct_flush_ft_entry,
d8f823
+				    ct_priv);
d8f823
 	kfree(ft);
d8f823
 }
d8f823
 
d8f823
-- 
d8f823
2.13.6
d8f823