Skip to content

Commit

Permalink
net/mlx5: DR, Add check for unsupported fields in match param
Browse files Browse the repository at this point in the history
When a matcher is being built, we "consume" (clear) mask fields one by one,
and to verify that we do support all the required fields we check if the
whole mask was consumed, else the matching request includes unsupported
fields.

Signed-off-by: Muhammad Sammar <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
Reviewed-by: Yevgeny Kliteynik <[email protected]>
  • Loading branch information
Muhammad Sammar authored and Saeed Mahameed committed Oct 29, 2021
1 parent 504e157 commit 941f197
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 133 deletions.
28 changes: 25 additions & 3 deletions drivers/net/ethernet/mellanox/mlx5/core/steering/dr_matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,10 @@ static int dr_matcher_init_fdb(struct mlx5dr_matcher *matcher)
static int dr_matcher_init(struct mlx5dr_matcher *matcher,
struct mlx5dr_match_parameters *mask)
{
struct mlx5dr_match_parameters consumed_mask;
struct mlx5dr_table *tbl = matcher->tbl;
struct mlx5dr_domain *dmn = tbl->dmn;
int ret;
int i, ret;

if (matcher->match_criteria >= DR_MATCHER_CRITERIA_MAX) {
mlx5dr_err(dmn, "Invalid match criteria attribute\n");
Expand All @@ -889,8 +890,16 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
mlx5dr_err(dmn, "Invalid match size attribute\n");
return -EINVAL;
}

consumed_mask.match_buf = kzalloc(mask->match_sz, GFP_KERNEL);
if (!consumed_mask.match_buf)
return -ENOMEM;

consumed_mask.match_sz = mask->match_sz;
memcpy(consumed_mask.match_buf, mask->match_buf, mask->match_sz);
mlx5dr_ste_copy_param(matcher->match_criteria,
&matcher->mask, mask);
&matcher->mask, &consumed_mask,
true);
}

switch (dmn->type) {
Expand All @@ -909,9 +918,22 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
break;
default:
WARN_ON(true);
return -EINVAL;
ret = -EINVAL;
goto free_consumed_mask;
}

/* Check that all mask data was consumed */
for (i = 0; i < consumed_mask.match_sz; i++) {
if (consumed_mask.match_buf[i]) {
mlx5dr_dbg(dmn, "Match param mask contains unsupported parameters\n");
ret = -EOPNOTSUPP;
goto free_consumed_mask;
}
}

ret = 0;
free_consumed_mask:
kfree(consumed_mask.match_buf);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ static bool dr_rule_verify(struct mlx5dr_matcher *matcher,
return false;
}

mlx5dr_ste_copy_param(matcher->match_criteria, param, value);
mlx5dr_ste_copy_param(matcher->match_criteria, param, value, false);

if (match_criteria & DR_MATCHER_CRITERIA_OUTER) {
s_idx = offsetof(struct mlx5dr_match_param, outer);
Expand Down
Loading

0 comments on commit 941f197

Please sign in to comment.