Skip to content

Commit 70840b6

Browse files
Paul BlakeySaeed Mahameed
authored andcommitted
net/mlx5: CT: Change idr to xarray to protect parallel tuple id allocation
After allowing parallel tuple insertion, we get the following trace: [ 5505.142249] ------------[ cut here ]------------ [ 5505.148155] WARNING: CPU: 21 PID: 13313 at lib/radix-tree.c:581 delete_node+0x16c/0x180 [ 5505.295553] CPU: 21 PID: 13313 Comm: kworker/u50:22 Tainted: G OE 5.6.0+ #78 [ 5505.304824] Hardware name: Supermicro Super Server/X10DRT-P, BIOS 2.0b 03/30/2017 [ 5505.313740] Workqueue: nf_flow_table_offload flow_offload_work_handler [nf_flow_table] [ 5505.323257] RIP: 0010:delete_node+0x16c/0x180 [ 5505.349862] RSP: 0018:ffffb19184eb7b30 EFLAGS: 00010282 [ 5505.356785] RAX: 0000000000000000 RBX: ffff904ac95b86d8 RCX: ffff904b6f938838 [ 5505.365190] RDX: 0000000000000000 RSI: ffff904ac954b908 RDI: ffff904ac954b920 [ 5505.373628] RBP: ffff904b4ac13060 R08: 0000000000000001 R09: 0000000000000000 [ 5505.382155] R10: 0000000000000000 R11: 0000000000000040 R12: 0000000000000000 [ 5505.390527] R13: ffffb19184eb7bfc R14: ffff904b6bef5800 R15: ffff90482c1203c0 [ 5505.399246] FS: 0000000000000000(0000) GS:ffff904c2fc80000(0000) knlGS:0000000000000000 [ 5505.408621] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 5505.415739] CR2: 00007f5d27006010 CR3: 0000000058c10006 CR4: 00000000001626e0 [ 5505.424547] Call Trace: [ 5505.428429] idr_alloc_u32+0x7b/0xc0 [ 5505.433803] mlx5_tc_ct_entry_add_rule+0xbf/0x950 [mlx5_core] [ 5505.441354] ? mlx5_fc_create+0x23c/0x370 [mlx5_core] [ 5505.448225] mlx5_tc_ct_block_flow_offload+0x874/0x10b0 [mlx5_core] [ 5505.456278] ? mlx5_tc_ct_block_flow_offload+0x63d/0x10b0 [mlx5_core] [ 5505.464532] nf_flow_offload_tuple.isra.21+0xc5/0x140 [nf_flow_table] [ 5505.472286] ? __kmalloc+0x217/0x2f0 [ 5505.477093] ? flow_rule_alloc+0x1c/0x30 [ 5505.482117] flow_offload_work_handler+0x1d0/0x290 [nf_flow_table] [ 5505.489674] ? process_one_work+0x17c/0x580 [ 5505.494922] process_one_work+0x202/0x580 [ 5505.500082] ? process_one_work+0x17c/0x580 [ 5505.505696] worker_thread+0x4c/0x3f0 [ 5505.510458] kthread+0x103/0x140 [ 5505.514989] ? process_one_work+0x580/0x580 [ 5505.520616] ? kthread_bind+0x10/0x10 [ 5505.525837] ret_from_fork+0x3a/0x50 [ 5505.570841] ---[ end trace 07995de9c56d6831 ]--- This happens from parallel deletes/adds to idr, as idr isn't protected. Fix that by using xarray as the tuple_ids allocator instead of idr. Fixes: 7da182a ("netfilter: flowtable: Use work entry per offload command") Reviewed-by: Roi Dayan <[email protected]> Signed-off-by: Paul Blakey <[email protected]> Reviewed-by: Oz Shlomo <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent a019b36 commit 70840b6

File tree

1 file changed

+12
-11
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/en

1 file changed

+12
-11
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net/flow_offload.h>
1313
#include <net/netfilter/nf_flow_table.h>
1414
#include <linux/workqueue.h>
15+
#include <linux/xarray.h>
1516

1617
#include "esw/chains.h"
1718
#include "en/tc_ct.h"
@@ -35,7 +36,7 @@ struct mlx5_tc_ct_priv {
3536
struct mlx5_eswitch *esw;
3637
const struct net_device *netdev;
3738
struct idr fte_ids;
38-
struct idr tuple_ids;
39+
struct xarray tuple_ids;
3940
struct rhashtable zone_ht;
4041
struct mlx5_flow_table *ct;
4142
struct mlx5_flow_table *ct_nat;
@@ -238,7 +239,7 @@ mlx5_tc_ct_entry_del_rule(struct mlx5_tc_ct_priv *ct_priv,
238239

239240
mlx5_eswitch_del_offloaded_rule(esw, zone_rule->rule, attr);
240241
mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
241-
idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
242+
xa_erase(&ct_priv->tuple_ids, zone_rule->tupleid);
242243
}
243244

244245
static void
@@ -483,7 +484,7 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
483484
struct mlx5_esw_flow_attr *attr = &zone_rule->attr;
484485
struct mlx5_eswitch *esw = ct_priv->esw;
485486
struct mlx5_flow_spec *spec = NULL;
486-
u32 tupleid = 1;
487+
u32 tupleid;
487488
int err;
488489

489490
zone_rule->nat = nat;
@@ -493,12 +494,12 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
493494
return -ENOMEM;
494495

495496
/* Get tuple unique id */
496-
err = idr_alloc_u32(&ct_priv->tuple_ids, zone_rule, &tupleid,
497-
TUPLE_ID_MAX, GFP_KERNEL);
497+
err = xa_alloc(&ct_priv->tuple_ids, &tupleid, zone_rule,
498+
XA_LIMIT(1, TUPLE_ID_MAX), GFP_KERNEL);
498499
if (err) {
499500
netdev_warn(ct_priv->netdev,
500501
"Failed to allocate tuple id, err: %d\n", err);
501-
goto err_idr_alloc;
502+
goto err_xa_alloc;
502503
}
503504
zone_rule->tupleid = tupleid;
504505

@@ -539,8 +540,8 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
539540
err_rule:
540541
mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
541542
err_mod_hdr:
542-
idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
543-
err_idr_alloc:
543+
xa_erase(&ct_priv->tuple_ids, zone_rule->tupleid);
544+
err_xa_alloc:
544545
kfree(spec);
545546
return err;
546547
}
@@ -1299,7 +1300,7 @@ mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv)
12991300
}
13001301

13011302
idr_init(&ct_priv->fte_ids);
1302-
idr_init(&ct_priv->tuple_ids);
1303+
xa_init_flags(&ct_priv->tuple_ids, XA_FLAGS_ALLOC1);
13031304
mutex_init(&ct_priv->control_lock);
13041305
rhashtable_init(&ct_priv->zone_ht, &zone_params);
13051306

@@ -1334,7 +1335,7 @@ mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv)
13341335

13351336
rhashtable_destroy(&ct_priv->zone_ht);
13361337
mutex_destroy(&ct_priv->control_lock);
1337-
idr_destroy(&ct_priv->tuple_ids);
1338+
xa_destroy(&ct_priv->tuple_ids);
13381339
idr_destroy(&ct_priv->fte_ids);
13391340
kfree(ct_priv);
13401341

@@ -1352,7 +1353,7 @@ mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
13521353
if (!ct_priv || !tupleid)
13531354
return true;
13541355

1355-
zone_rule = idr_find(&ct_priv->tuple_ids, tupleid);
1356+
zone_rule = xa_load(&ct_priv->tuple_ids, tupleid);
13561357
if (!zone_rule)
13571358
return false;
13581359

0 commit comments

Comments
 (0)