Skip to content

Commit 59d589f

Browse files
Maor GottliebGoKu-Gear6
authored andcommitted
net/mlx5: Export building of matched flow groups list
Refactor the code and export the build of the matched flow groups list to separate function. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Orabug: 28571062 (cherry picked from commit 46719d7) cherry-pick-repo=kernel/git/torvalds/linux.git Conflicts: drivers/net/ethernet/mellanox/mlx5/core/fs_core.c Conflict was caused by missing code semantics changes made in core/fs_core.c back in v4.15 (b92af5a). However, those changes in the commit (b92af5a) will be overwritten later by patch #5 (net/mlx5: Support multiple updates of steering rules in parallel) in this series. Signed-off-by: Erez Alfasi <[email protected]> Signed-off-by: Aron Silverton <[email protected]> Signed-off-by: Qing Huang <[email protected]> Reviewed-by: Aron Silverton <[email protected]>
1 parent 66dc6fe commit 59d589f

File tree

1 file changed

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

1 file changed

+65
-35
lines changed

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

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,47 +1443,89 @@ static bool dest_is_valid(struct mlx5_flow_destination *dest,
14431443
return true;
14441444
}
14451445

1446-
static struct mlx5_flow_handle *
1447-
try_add_to_existing_fg(struct mlx5_flow_table *ft,
1448-
struct mlx5_flow_spec *spec,
1449-
struct mlx5_flow_act *flow_act,
1450-
struct mlx5_flow_destination *dest,
1451-
int dest_num)
1452-
{
1446+
struct match_list {
1447+
struct list_head list;
14531448
struct mlx5_flow_group *g;
1454-
struct mlx5_flow_handle *rule = ERR_PTR(-ENOENT);
1449+
};
1450+
1451+
struct match_list_head {
1452+
struct list_head list;
1453+
struct match_list first;
1454+
};
1455+
1456+
static void free_match_list(struct match_list_head *head)
1457+
{
1458+
if (!list_empty(&head->list)) {
1459+
struct match_list *iter, *match_tmp;
1460+
1461+
list_del(&head->first.list);
1462+
list_for_each_entry_safe(iter, match_tmp, &head->list,
1463+
list) {
1464+
list_del(&iter->list);
1465+
kfree(iter);
1466+
}
1467+
}
1468+
}
1469+
1470+
static int build_match_list(struct match_list_head *match_head,
1471+
struct mlx5_flow_table *ft,
1472+
struct mlx5_flow_spec *spec)
1473+
{
14551474
struct rhlist_head *tmp, *list;
1456-
struct match_list {
1457-
struct list_head list;
1458-
struct mlx5_flow_group *g;
1459-
} match_list, *iter;
1460-
LIST_HEAD(match_head);
1475+
struct mlx5_flow_group *g;
1476+
int err = 0;
14611477

14621478
rcu_read_lock();
1479+
INIT_LIST_HEAD(&match_head->list);
14631480
/* Collect all fgs which has a matching match_criteria */
14641481
list = rhltable_lookup(&ft->fgs_hash, spec, rhash_fg);
1482+
/* RCU is atomic, we can't execute FW commands here */
14651483
rhl_for_each_entry_rcu(g, tmp, list, hash) {
14661484
struct match_list *curr_match;
14671485

1468-
if (likely(list_empty(&match_head))) {
1469-
match_list.g = g;
1470-
list_add_tail(&match_list.list, &match_head);
1486+
if (likely(list_empty(&match_head->list))) {
1487+
match_head->first.g = g;
1488+
list_add_tail(&match_head->first.list,
1489+
&match_head->list);
14711490
continue;
14721491
}
1492+
14731493
curr_match = kmalloc(sizeof(*curr_match), GFP_ATOMIC);
14741494

14751495
if (!curr_match) {
1476-
rcu_read_unlock();
1477-
rule = ERR_PTR(-ENOMEM);
1478-
goto free_list;
1496+
free_match_list(match_head);
1497+
err = -ENOMEM;
1498+
goto out;
14791499
}
14801500
curr_match->g = g;
1481-
list_add_tail(&curr_match->list, &match_head);
1501+
list_add_tail(&curr_match->list, &match_head->list);
14821502
}
1503+
out:
14831504
rcu_read_unlock();
1505+
return err;
1506+
}
1507+
1508+
static struct mlx5_flow_handle *
1509+
try_add_to_existing_fg(struct mlx5_flow_table *ft,
1510+
struct mlx5_flow_spec *spec,
1511+
struct mlx5_flow_act *flow_act,
1512+
struct mlx5_flow_destination *dest,
1513+
int dest_num)
1514+
{
1515+
struct mlx5_flow_group *g;
1516+
struct mlx5_flow_handle *rule;
1517+
struct match_list_head match_head;
1518+
struct match_list *iter;
1519+
int err;
1520+
1521+
/* Collect all fgs which has a matching match_criteria */
1522+
err = build_match_list(&match_head, ft, spec);
1523+
if (err)
1524+
return ERR_PTR(err);
1525+
14841526

14851527
/* Try to find a fg that already contains a matching fte */
1486-
list_for_each_entry(iter, &match_head, list) {
1528+
list_for_each_entry(iter, &match_head.list, list) {
14871529
struct fs_fte *fte;
14881530

14891531
g = iter->g;
@@ -1502,7 +1544,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15021544
/* No group with matching fte found. Try to add a new fte to any
15031545
* matching fg.
15041546
*/
1505-
list_for_each_entry(iter, &match_head, list) {
1547+
list_for_each_entry(iter, &match_head.list, list) {
15061548
g = iter->g;
15071549

15081550
nested_lock_ref_node(&g->node, FS_MUTEX_PARENT);
@@ -1516,19 +1558,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15161558
}
15171559

15181560
free_list:
1519-
if (!list_empty(&match_head)) {
1520-
struct match_list *match_tmp;
1521-
1522-
/* The most common case is having one FG. Since we want to
1523-
* optimize this case, we save the first on the stack.
1524-
* Therefore, no need to free it.
1525-
*/
1526-
list_del(&list_first_entry(&match_head, typeof(*iter), list)->list);
1527-
list_for_each_entry_safe(iter, match_tmp, &match_head, list) {
1528-
list_del(&iter->list);
1529-
kfree(iter);
1530-
}
1531-
}
1561+
free_match_list(&match_head);
15321562

15331563
return rule;
15341564
}

0 commit comments

Comments
 (0)