Skip to content

Commit 288d85e

Browse files
kliteynSaeed Mahameed
authored andcommitted
net/mlx5: DR, Fix potential race in dr_rule_create_rule_nic
Selecting builder should be protected by the lock to prevent the case where a new rule sets a builder in the nic_matcher while the previous rule is still using the nic_matcher. Fixing this issue and cleaning the error flow. Fixes: b9b81e1 ("net/mlx5: DR, For short chains of STEs, avoid allocating ste_arr dynamically") Signed-off-by: Yevgeny Kliteynik <[email protected]> Reviewed-by: Alex Vesker <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 1e66220 commit 288d85e

File tree

1 file changed

+15
-10
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/steering

1 file changed

+15
-10
lines changed

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,12 +1138,14 @@ dr_rule_create_rule_nic(struct mlx5dr_rule *rule,
11381138
rule->flow_source))
11391139
return 0;
11401140

1141+
mlx5dr_domain_nic_lock(nic_dmn);
1142+
11411143
ret = mlx5dr_matcher_select_builders(matcher,
11421144
nic_matcher,
11431145
dr_rule_get_ipv(&param->outer),
11441146
dr_rule_get_ipv(&param->inner));
11451147
if (ret)
1146-
return ret;
1148+
goto err_unlock;
11471149

11481150
hw_ste_arr_is_opt = nic_matcher->num_of_builders <= DR_RULE_MAX_STES_OPTIMIZED;
11491151
if (likely(hw_ste_arr_is_opt)) {
@@ -1152,12 +1154,12 @@ dr_rule_create_rule_nic(struct mlx5dr_rule *rule,
11521154
hw_ste_arr = kzalloc((nic_matcher->num_of_builders + DR_ACTION_MAX_STES) *
11531155
DR_STE_SIZE, GFP_KERNEL);
11541156

1155-
if (!hw_ste_arr)
1156-
return -ENOMEM;
1157+
if (!hw_ste_arr) {
1158+
ret = -ENOMEM;
1159+
goto err_unlock;
1160+
}
11571161
}
11581162

1159-
mlx5dr_domain_nic_lock(nic_dmn);
1160-
11611163
ret = mlx5dr_matcher_add_to_tbl_nic(dmn, nic_matcher);
11621164
if (ret)
11631165
goto free_hw_ste;
@@ -1223,7 +1225,10 @@ dr_rule_create_rule_nic(struct mlx5dr_rule *rule,
12231225

12241226
mlx5dr_domain_nic_unlock(nic_dmn);
12251227

1226-
goto out;
1228+
if (unlikely(!hw_ste_arr_is_opt))
1229+
kfree(hw_ste_arr);
1230+
1231+
return 0;
12271232

12281233
free_rule:
12291234
dr_rule_clean_rule_members(rule, nic_rule);
@@ -1238,12 +1243,12 @@ dr_rule_create_rule_nic(struct mlx5dr_rule *rule,
12381243
mlx5dr_matcher_remove_from_tbl_nic(dmn, nic_matcher);
12391244

12401245
free_hw_ste:
1241-
mlx5dr_domain_nic_unlock(nic_dmn);
1242-
1243-
out:
1244-
if (unlikely(!hw_ste_arr_is_opt))
1246+
if (!hw_ste_arr_is_opt)
12451247
kfree(hw_ste_arr);
12461248

1249+
err_unlock:
1250+
mlx5dr_domain_nic_unlock(nic_dmn);
1251+
12471252
return ret;
12481253
}
12491254

0 commit comments

Comments
 (0)