Skip to content

Commit f5c2ff1

Browse files
Maor GottliebSaeed Mahameed
authored andcommitted
net/mlx5: Allocate FTE object without lock
Allocation of new FTE is a massive operation, part of it could be done without taking the flow group write lock. Split the FTE allocation to two functions of actions which need to be under lock and action which don't have. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent bd71b08 commit f5c2ff1

File tree

1 file changed

+46
-46
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+46
-46
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,33 @@ static void del_sw_flow_group(struct fs_node *node)
546546
WARN_ON(err);
547547
}
548548

549-
static struct fs_fte *alloc_fte(struct mlx5_flow_act *flow_act,
550-
u32 *match_value,
551-
unsigned int index)
549+
static int insert_fte(struct mlx5_flow_group *fg, struct fs_fte *fte)
550+
{
551+
int index;
552+
int ret;
553+
554+
index = ida_simple_get(&fg->fte_allocator, 0, fg->max_ftes, GFP_KERNEL);
555+
if (index < 0)
556+
return index;
557+
558+
fte->index = index + fg->start_index;
559+
ret = rhashtable_insert_fast(&fg->ftes_hash,
560+
&fte->hash,
561+
rhash_fte);
562+
if (ret)
563+
goto err_ida_remove;
564+
565+
tree_add_node(&fte->node, &fg->node);
566+
list_add_tail(&fte->node.list, &fg->node.children);
567+
return 0;
568+
569+
err_ida_remove:
570+
ida_simple_remove(&fg->fte_allocator, index);
571+
return ret;
572+
}
573+
574+
static struct fs_fte *alloc_fte(u32 *match_value,
575+
struct mlx5_flow_act *flow_act)
552576
{
553577
struct fs_fte *fte;
554578

@@ -559,51 +583,13 @@ static struct fs_fte *alloc_fte(struct mlx5_flow_act *flow_act,
559583
memcpy(fte->val, match_value, sizeof(fte->val));
560584
fte->node.type = FS_TYPE_FLOW_ENTRY;
561585
fte->flow_tag = flow_act->flow_tag;
562-
fte->index = index;
563586
fte->action = flow_act->action;
564587
fte->encap_id = flow_act->encap_id;
565588
fte->modify_id = flow_act->modify_id;
566589

567-
return fte;
568-
}
569-
570-
static struct fs_fte *alloc_insert_fte(struct mlx5_flow_group *fg,
571-
u32 *match_value,
572-
struct mlx5_flow_act *flow_act)
573-
{
574-
struct fs_fte *fte;
575-
int index;
576-
int ret;
577-
578-
index = ida_simple_get(&fg->fte_allocator, 0,
579-
fg->max_ftes,
580-
GFP_KERNEL);
581-
if (index < 0)
582-
return ERR_PTR(index);
583-
584-
fte = alloc_fte(flow_act, match_value, index + fg->start_index);
585-
if (IS_ERR(fte)) {
586-
ret = PTR_ERR(fte);
587-
goto err_ida_remove;
588-
}
589-
590-
ret = rhashtable_insert_fast(&fg->ftes_hash,
591-
&fte->hash,
592-
rhash_fte);
593-
if (ret)
594-
goto err_free;
595-
596590
tree_init_node(&fte->node, del_hw_fte, del_sw_fte);
597-
tree_add_node(&fte->node, &fg->node);
598-
list_add_tail(&fte->node.list, &fg->node.children);
599591

600592
return fte;
601-
602-
err_free:
603-
kfree(fte);
604-
err_ida_remove:
605-
ida_simple_remove(&fg->fte_allocator, index);
606-
return ERR_PTR(ret);
607593
}
608594

609595
static void dealloc_flow_group(struct mlx5_flow_group *fg)
@@ -1589,6 +1575,11 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15891575
bool take_write = false;
15901576
struct fs_fte *fte;
15911577
u64 version;
1578+
int err;
1579+
1580+
fte = alloc_fte(spec->match_value, flow_act);
1581+
if (IS_ERR(fte))
1582+
return ERR_PTR(-ENOMEM);
15921583

15931584
list_for_each_entry(iter, match_head, list) {
15941585
nested_down_read_ref_node(&iter->g->node, FS_LOCK_PARENT);
@@ -1620,6 +1611,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16201611
flow_act, dest, dest_num, fte_tmp);
16211612
up_write_ref_node(&fte_tmp->node);
16221613
tree_put_node(&fte_tmp->node);
1614+
kfree(fte);
16231615
return rule;
16241616
}
16251617

@@ -1655,13 +1647,14 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16551647

16561648
if (!g->node.active)
16571649
continue;
1658-
fte = alloc_insert_fte(g, spec->match_value, flow_act);
1659-
if (IS_ERR(fte)) {
1660-
if (PTR_ERR(fte) == -ENOSPC)
1650+
err = insert_fte(g, fte);
1651+
if (err) {
1652+
if (err == -ENOSPC)
16611653
continue;
16621654
list_for_each_entry(iter, match_head, list)
16631655
up_write_ref_node(&iter->g->node);
1664-
return (void *)fte;
1656+
kfree(fte);
1657+
return ERR_PTR(err);
16651658
}
16661659

16671660
nested_down_write_ref_node(&fte->node, FS_LOCK_CHILD);
@@ -1677,6 +1670,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16771670
out:
16781671
list_for_each_entry(iter, match_head, list)
16791672
up_write_ref_node(&iter->g->node);
1673+
kfree(fte);
16801674
return rule;
16811675
}
16821676

@@ -1746,12 +1740,18 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
17461740
if (err)
17471741
goto err_release_fg;
17481742

1749-
fte = alloc_insert_fte(g, spec->match_value, flow_act);
1743+
fte = alloc_fte(spec->match_value, flow_act);
17501744
if (IS_ERR(fte)) {
17511745
err = PTR_ERR(fte);
17521746
goto err_release_fg;
17531747
}
17541748

1749+
err = insert_fte(g, fte);
1750+
if (err) {
1751+
kfree(fte);
1752+
goto err_release_fg;
1753+
}
1754+
17551755
nested_down_write_ref_node(&fte->node, FS_LOCK_CHILD);
17561756
up_write_ref_node(&g->node);
17571757
rule = add_rule_fg(g, spec->match_value, flow_act, dest,

0 commit comments

Comments
 (0)