Skip to content

Commit

Permalink
mlxsw: spectrum_matchall: Forbid to insert matchall rules in collisio…
Browse files Browse the repository at this point in the history
…n with flower rules

On ingress, the matchall rules doing mirroring and sampling are offloaded
into hardware blocks that are processed before any flower rules.
On egress, the matchall mirroring rules are offloaded into hardware
block that is processed after all flower rules.

Therefore check the priorities of inserted matchall rules against
existing flower rules and ensure the correct ordering.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
jpirko authored and kuba-moo committed May 9, 2020
1 parent aed6528 commit 18346b7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;

/* spectrum_matchall.c */
int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_flow_block *block,
struct tc_cls_matchall_offload *f);
void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
struct tc_cls_matchall_offload *f);
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ static int mlxsw_sp_flow_block_unbind(struct mlxsw_sp *mlxsw_sp,
static int mlxsw_sp_flow_block_mall_cb(struct mlxsw_sp_flow_block *flow_block,
struct tc_cls_matchall_offload *f)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_flow_block_mlxsw_sp(flow_block);

switch (f->command) {
case TC_CLSMATCHALL_REPLACE:
return mlxsw_sp_mall_replace(flow_block, f);
return mlxsw_sp_mall_replace(mlxsw_sp, flow_block, f);
case TC_CLSMATCHALL_DESTROY:
mlxsw_sp_mall_destroy(flow_block, f);
return 0;
Expand Down
37 changes: 36 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_matchall.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ static void mlxsw_sp_mall_prio_update(struct mlxsw_sp_flow_block *block)
}
}

int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_flow_block *block,
struct tc_cls_matchall_offload *f)
{
struct mlxsw_sp_flow_block_binding *binding;
struct mlxsw_sp_mall_entry *mall_entry;
__be16 protocol = f->common.protocol;
struct flow_action_entry *act;
unsigned int flower_min_prio;
unsigned int flower_max_prio;
bool flower_prio_valid;
int err;

if (!flow_offload_has_one_action(&f->rule->action)) {
Expand All @@ -216,6 +220,19 @@ int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
return -EOPNOTSUPP;
}

err = mlxsw_sp_flower_prio_get(mlxsw_sp, block, f->common.chain_index,
&flower_min_prio, &flower_max_prio);
if (err) {
if (err != -ENOENT) {
NL_SET_ERR_MSG(f->common.extack, "Failed to get flower priorities");
return err;
}
flower_prio_valid = false;
/* No flower filters are installed in specified chain. */
} else {
flower_prio_valid = true;
}

mall_entry = kzalloc(sizeof(*mall_entry), GFP_KERNEL);
if (!mall_entry)
return -ENOMEM;
Expand All @@ -226,6 +243,18 @@ int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
act = &f->rule->action.entries[0];

if (act->id == FLOW_ACTION_MIRRED && protocol == htons(ETH_P_ALL)) {
if (flower_prio_valid && mall_entry->ingress &&
mall_entry->priority >= flower_min_prio) {
NL_SET_ERR_MSG(f->common.extack, "Failed to add behind existing flower rules");
err = -EOPNOTSUPP;
goto errout;
}
if (flower_prio_valid && !mall_entry->ingress &&
mall_entry->priority <= flower_max_prio) {
NL_SET_ERR_MSG(f->common.extack, "Failed to add in front of existing flower rules");
err = -EOPNOTSUPP;
goto errout;
}
mall_entry->type = MLXSW_SP_MALL_ACTION_TYPE_MIRROR;
mall_entry->mirror.to_dev = act->dev;
} else if (act->id == FLOW_ACTION_SAMPLE &&
Expand All @@ -235,6 +264,12 @@ int mlxsw_sp_mall_replace(struct mlxsw_sp_flow_block *block,
err = -EOPNOTSUPP;
goto errout;
}
if (flower_prio_valid &&
mall_entry->priority >= flower_min_prio) {
NL_SET_ERR_MSG(f->common.extack, "Failed to add behind existing flower rules");
err = -EOPNOTSUPP;
goto errout;
}
if (act->sample.rate > MLXSW_REG_MPSC_RATE_MAX) {
NL_SET_ERR_MSG(f->common.extack, "Sample rate not supported");
err = -EOPNOTSUPP;
Expand Down

0 comments on commit 18346b7

Please sign in to comment.