Blame SOURCES/0249-netdrv-net-mlx5-CT-Change-idr-to-xarray-to-protect-p.patch

d8f823
From e3cb19855b89bc59087b8a0a26e60fd85a5b1ba9 Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 19 May 2020 07:49:11 -0400
d8f823
Subject: [PATCH 249/312] [netdrv] net/mlx5: CT: Change idr to xarray to
d8f823
 protect parallel tuple id allocation
d8f823
d8f823
Message-id: <20200519074934.6303-41-ahleihel@redhat.com>
d8f823
Patchwork-id: 310542
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1663246 40/63] net/mlx5: CT: Change idr to xarray to protect parallel tuple id allocation
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-rc3
d8f823
d8f823
commit 70840b66da4d3b9a8962905d9111a53ee628beb3
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Mon Apr 6 15:47:52 2020 +0300
d8f823
d8f823
    net/mlx5: CT: Change idr to xarray to protect parallel tuple id allocation
d8f823
d8f823
    After allowing parallel tuple insertion, we get the following trace:
d8f823
d8f823
    [ 5505.142249] ------------[ cut here ]------------
d8f823
    [ 5505.148155] WARNING: CPU: 21 PID: 13313 at lib/radix-tree.c:581 delete_node+0x16c/0x180
d8f823
    [ 5505.295553] CPU: 21 PID: 13313 Comm: kworker/u50:22 Tainted: G           OE     5.6.0+ #78
d8f823
    [ 5505.304824] Hardware name: Supermicro Super Server/X10DRT-P, BIOS 2.0b 03/30/2017
d8f823
    [ 5505.313740] Workqueue: nf_flow_table_offload flow_offload_work_handler [nf_flow_table]
d8f823
    [ 5505.323257] RIP: 0010:delete_node+0x16c/0x180
d8f823
    [ 5505.349862] RSP: 0018:ffffb19184eb7b30 EFLAGS: 00010282
d8f823
    [ 5505.356785] RAX: 0000000000000000 RBX: ffff904ac95b86d8 RCX: ffff904b6f938838
d8f823
    [ 5505.365190] RDX: 0000000000000000 RSI: ffff904ac954b908 RDI: ffff904ac954b920
d8f823
    [ 5505.373628] RBP: ffff904b4ac13060 R08: 0000000000000001 R09: 0000000000000000
d8f823
    [ 5505.382155] R10: 0000000000000000 R11: 0000000000000040 R12: 0000000000000000
d8f823
    [ 5505.390527] R13: ffffb19184eb7bfc R14: ffff904b6bef5800 R15: ffff90482c1203c0
d8f823
    [ 5505.399246] FS:  0000000000000000(0000) GS:ffff904c2fc80000(0000) knlGS:0000000000000000
d8f823
    [ 5505.408621] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
d8f823
    [ 5505.415739] CR2: 00007f5d27006010 CR3: 0000000058c10006 CR4: 00000000001626e0
d8f823
    [ 5505.424547] Call Trace:
d8f823
    [ 5505.428429]  idr_alloc_u32+0x7b/0xc0
d8f823
    [ 5505.433803]  mlx5_tc_ct_entry_add_rule+0xbf/0x950 [mlx5_core]
d8f823
    [ 5505.441354]  ? mlx5_fc_create+0x23c/0x370 [mlx5_core]
d8f823
    [ 5505.448225]  mlx5_tc_ct_block_flow_offload+0x874/0x10b0 [mlx5_core]
d8f823
    [ 5505.456278]  ? mlx5_tc_ct_block_flow_offload+0x63d/0x10b0 [mlx5_core]
d8f823
    [ 5505.464532]  nf_flow_offload_tuple.isra.21+0xc5/0x140 [nf_flow_table]
d8f823
    [ 5505.472286]  ? __kmalloc+0x217/0x2f0
d8f823
    [ 5505.477093]  ? flow_rule_alloc+0x1c/0x30
d8f823
    [ 5505.482117]  flow_offload_work_handler+0x1d0/0x290 [nf_flow_table]
d8f823
    [ 5505.489674]  ? process_one_work+0x17c/0x580
d8f823
    [ 5505.494922]  process_one_work+0x202/0x580
d8f823
    [ 5505.500082]  ? process_one_work+0x17c/0x580
d8f823
    [ 5505.505696]  worker_thread+0x4c/0x3f0
d8f823
    [ 5505.510458]  kthread+0x103/0x140
d8f823
    [ 5505.514989]  ? process_one_work+0x580/0x580
d8f823
    [ 5505.520616]  ? kthread_bind+0x10/0x10
d8f823
    [ 5505.525837]  ret_from_fork+0x3a/0x50
d8f823
    [ 5505.570841] ---[ end trace 07995de9c56d6831 ]---
d8f823
d8f823
    This happens from parallel deletes/adds to idr, as idr isn't protected.
d8f823
    Fix that by using xarray as the tuple_ids allocator instead of idr.
d8f823
d8f823
    Fixes: 7da182a998d6 ("netfilter: flowtable: Use work entry per offload command")
d8f823
    Reviewed-by: Roi Dayan <roid@mellanox.com>
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Reviewed-by: Oz Shlomo <ozsh@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 | 23 +++++++++++-----------
d8f823
 1 file changed, 12 insertions(+), 11 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 14b29d0d5092..46eba4d60db1 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
@@ -12,6 +12,7 @@
d8f823
 #include <net/flow_offload.h>
d8f823
 #include <net/netfilter/nf_flow_table.h>
d8f823
 #include <linux/workqueue.h>
d8f823
+#include <linux/xarray.h>
d8f823
 
d8f823
 #include "en/tc_ct.h"
d8f823
 #include "en.h"
d8f823
@@ -35,7 +36,7 @@ struct mlx5_tc_ct_priv {
d8f823
 	struct mlx5_eswitch *esw;
d8f823
 	const struct net_device *netdev;
d8f823
 	struct idr fte_ids;
d8f823
-	struct idr tuple_ids;
d8f823
+	struct xarray tuple_ids;
d8f823
 	struct rhashtable zone_ht;
d8f823
 	struct mlx5_flow_table *ct;
d8f823
 	struct mlx5_flow_table *ct_nat;
d8f823
@@ -238,7 +239,7 @@ mlx5_tc_ct_entry_del_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 
d8f823
 	mlx5_eswitch_del_offloaded_rule(esw, zone_rule->rule, attr);
d8f823
 	mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
d8f823
-	idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
+	xa_erase(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
 }
d8f823
 
d8f823
 static void
d8f823
@@ -483,7 +484,7 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 	struct mlx5_esw_flow_attr *attr = &zone_rule->attr;
d8f823
 	struct mlx5_eswitch *esw = ct_priv->esw;
d8f823
 	struct mlx5_flow_spec *spec = NULL;
d8f823
-	u32 tupleid = 1;
d8f823
+	u32 tupleid;
d8f823
 	int err;
d8f823
 
d8f823
 	zone_rule->nat = nat;
d8f823
@@ -493,12 +494,12 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 		return -ENOMEM;
d8f823
 
d8f823
 	/* Get tuple unique id */
d8f823
-	err = idr_alloc_u32(&ct_priv->tuple_ids, zone_rule, &tupleid,
d8f823
-			    TUPLE_ID_MAX, GFP_KERNEL);
d8f823
+	err = xa_alloc(&ct_priv->tuple_ids, &tupleid, zone_rule,
d8f823
+		       XA_LIMIT(1, TUPLE_ID_MAX), GFP_KERNEL);
d8f823
 	if (err) {
d8f823
 		netdev_warn(ct_priv->netdev,
d8f823
 			    "Failed to allocate tuple id, err: %d\n", err);
d8f823
-		goto err_idr_alloc;
d8f823
+		goto err_xa_alloc;
d8f823
 	}
d8f823
 	zone_rule->tupleid = tupleid;
d8f823
 
d8f823
@@ -539,8 +540,8 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 err_rule:
d8f823
 	mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
d8f823
 err_mod_hdr:
d8f823
-	idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
-err_idr_alloc:
d8f823
+	xa_erase(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
+err_xa_alloc:
d8f823
 	kfree(spec);
d8f823
 	return err;
d8f823
 }
d8f823
@@ -1299,7 +1300,7 @@ mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv)
d8f823
 	}
d8f823
 
d8f823
 	idr_init(&ct_priv->fte_ids);
d8f823
-	idr_init(&ct_priv->tuple_ids);
d8f823
+	xa_init_flags(&ct_priv->tuple_ids, XA_FLAGS_ALLOC1);
d8f823
 	mutex_init(&ct_priv->control_lock);
d8f823
 	rhashtable_init(&ct_priv->zone_ht, &zone_params);
d8f823
 
d8f823
@@ -1334,7 +1335,7 @@ mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv)
d8f823
 
d8f823
 	rhashtable_destroy(&ct_priv->zone_ht);
d8f823
 	mutex_destroy(&ct_priv->control_lock);
d8f823
-	idr_destroy(&ct_priv->tuple_ids);
d8f823
+	xa_destroy(&ct_priv->tuple_ids);
d8f823
 	idr_destroy(&ct_priv->fte_ids);
d8f823
 	kfree(ct_priv);
d8f823
 
d8f823
@@ -1352,7 +1353,7 @@ mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
d8f823
 	if (!ct_priv || !tupleid)
d8f823
 		return true;
d8f823
 
d8f823
-	zone_rule = idr_find(&ct_priv->tuple_ids, tupleid);
d8f823
+	zone_rule = xa_load(&ct_priv->tuple_ids, tupleid);
d8f823
 	if (!zone_rule)
d8f823
 		return false;
d8f823
 
d8f823
-- 
d8f823
2.13.6
d8f823