Skip to content

Commit

Permalink
Merge branch 'mlx5-Support-tc-police-jump-conform-exceed-attribute'
Browse files Browse the repository at this point in the history
Saeed Mahameed says:

====================
Support tc police jump conform-exceed attribute

The tc police action conform-exceed option defines how to handle
packets which exceed or conform to the configured bandwidth limit.
One of the possible conform-exceed values is jump, which skips over
a specified number of actions.
This series adds support for conform-exceed jump action.

The series adds platform support for branching actions by providing
true/false flow attributes to the branching action.
This is necessary for supporting police jump, as each branch may
execute a different action list.

The first five patches are preparation patches:
- Patches 1 and 2 add support for actions with no destinations (e.g. drop)
- Patch 3 refactor the code for subsequent function reuse
- Patch 4 defines an abstract way for identifying terminating actions
- Patch 5 updates action list validations logic considering branching actions

The following three patches introduce an interface for abstracting branching
actions:
- Patch 6 introduces an abstract api for defining branching actions
- Patch 7 generically instantiates the branching flow attributes using
  the abstract API

Patch 8 adds the platform support for jump actions, by executing the following
sequence:
  a. Store the jumping flow attr
  b. Identify the jump target action while iterating the actions list.
  c. Instantiate a new flow attribute after the jump target action.
     This is the flow attribute that the branching action should jump to.
  d. Set the target post action id on:
    d.1. The jumping attribute, thus realizing the jump functionality.
    d.2. The attribute preceding the target jump attr, if not terminating.

The next patches apply the platform's branching attributes to the police
action:
- Patch 9 is a refactor patch
- Patch 10 initializes the post meter table with the red/green flow attributes,
           as were initialized by the platform
- Patch 11 enables the offload of meter actions using jump conform-exceed
           value.
====================

Link: https://lore.kernel.org/all/20221203221337.29267-1-saeed@kernel.org/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Dec 8, 2022
2 parents bde55dd + 3603f26 commit ddda632
Show file tree
Hide file tree
Showing 17 changed files with 495 additions and 174 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ tc_act_parse_accept(struct mlx5e_tc_act_parse_state *parse_state,
struct mlx5e_tc_act mlx5e_tc_act_accept = {
.can_offload = tc_act_can_offload_accept,
.parse_action = tc_act_parse_accept,
.is_terminating_action = true,
};
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static struct mlx5e_tc_act *tc_acts_fdb[NUM_FLOW_ACTIONS] = {
[FLOW_ACTION_DROP] = &mlx5e_tc_act_drop,
[FLOW_ACTION_TRAP] = &mlx5e_tc_act_trap,
[FLOW_ACTION_GOTO] = &mlx5e_tc_act_goto,
[FLOW_ACTION_REDIRECT] = &mlx5e_tc_act_mirred,
[FLOW_ACTION_REDIRECT] = &mlx5e_tc_act_redirect,
[FLOW_ACTION_MIRRED] = &mlx5e_tc_act_mirred,
[FLOW_ACTION_REDIRECT_INGRESS] = &mlx5e_tc_act_redirect_ingress,
[FLOW_ACTION_VLAN_PUSH] = &mlx5e_tc_act_vlan,
Expand Down
12 changes: 12 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct mlx5e_tc_act_parse_state {
struct mlx5_tc_ct_priv *ct_priv;
};

struct mlx5e_tc_act_branch_ctrl {
enum flow_action_id act_id;
u32 extval;
};

struct mlx5e_tc_act {
bool (*can_offload)(struct mlx5e_tc_act_parse_state *parse_state,
const struct flow_action_entry *act,
Expand Down Expand Up @@ -60,6 +65,12 @@ struct mlx5e_tc_act {

int (*stats_action)(struct mlx5e_priv *priv,
struct flow_offload_action *fl_act);

bool (*get_branch_ctrl)(const struct flow_action_entry *act,
struct mlx5e_tc_act_branch_ctrl *cond_true,
struct mlx5e_tc_act_branch_ctrl *cond_false);

bool is_terminating_action;
};

struct mlx5e_tc_flow_action {
Expand All @@ -81,6 +92,7 @@ extern struct mlx5e_tc_act mlx5e_tc_act_vlan_mangle;
extern struct mlx5e_tc_act mlx5e_tc_act_mpls_push;
extern struct mlx5e_tc_act mlx5e_tc_act_mpls_pop;
extern struct mlx5e_tc_act mlx5e_tc_act_mirred;
extern struct mlx5e_tc_act mlx5e_tc_act_redirect;
extern struct mlx5e_tc_act mlx5e_tc_act_mirred_nic;
extern struct mlx5e_tc_act mlx5e_tc_act_ct;
extern struct mlx5e_tc_act mlx5e_tc_act_sample;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ tc_act_parse_drop(struct mlx5e_tc_act_parse_state *parse_state,
struct mlx5e_tc_act mlx5e_tc_act_drop = {
.can_offload = tc_act_can_offload_drop,
.parse_action = tc_act_parse_drop,
.is_terminating_action = true,
};
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/goto.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ struct mlx5e_tc_act mlx5e_tc_act_goto = {
.can_offload = tc_act_can_offload_goto,
.parse_action = tc_act_parse_goto,
.post_parse = tc_act_post_parse_goto,
.is_terminating_action = true,
};
7 changes: 7 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,11 @@ tc_act_parse_mirred(struct mlx5e_tc_act_parse_state *parse_state,
struct mlx5e_tc_act mlx5e_tc_act_mirred = {
.can_offload = tc_act_can_offload_mirred,
.parse_action = tc_act_parse_mirred,
.is_terminating_action = false,
};

struct mlx5e_tc_act mlx5e_tc_act_redirect = {
.can_offload = tc_act_can_offload_mirred,
.parse_action = tc_act_parse_mirred,
.is_terminating_action = true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ tc_act_parse_mirred_nic(struct mlx5e_tc_act_parse_state *parse_state,
struct mlx5e_tc_act mlx5e_tc_act_mirred_nic = {
.can_offload = tc_act_can_offload_mirred_nic,
.parse_action = tc_act_parse_mirred_nic,
.is_terminating_action = true,
};
66 changes: 57 additions & 9 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,54 @@
#include "act.h"
#include "en/tc_priv.h"

static bool police_act_validate_control(enum flow_action_id act_id,
struct netlink_ext_ack *extack)
{
if (act_id != FLOW_ACTION_PIPE &&
act_id != FLOW_ACTION_ACCEPT &&
act_id != FLOW_ACTION_JUMP &&
act_id != FLOW_ACTION_DROP) {
NL_SET_ERR_MSG_MOD(extack,
"Offload not supported when conform-exceed action is not pipe, ok, jump or drop");
return false;
}

return true;
}

static int police_act_validate(const struct flow_action_entry *act,
struct netlink_ext_ack *extack)
{
if (!police_act_validate_control(act->police.exceed.act_id, extack) ||
!police_act_validate_control(act->police.notexceed.act_id, extack))
return -EOPNOTSUPP;

if (act->police.peakrate_bytes_ps ||
act->police.avrate || act->police.overhead) {
NL_SET_ERR_MSG_MOD(extack,
"Offload not supported when peakrate/avrate/overhead is configured");
return -EOPNOTSUPP;
}

if (act->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack,
"QoS offload not support packets per second");
return -EOPNOTSUPP;
}

return 0;
}

static bool
tc_act_can_offload_police(struct mlx5e_tc_act_parse_state *parse_state,
const struct flow_action_entry *act,
int act_index,
struct mlx5_flow_attr *attr)
{
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
NL_SET_ERR_MSG_MOD(parse_state->extack,
"Offload not supported when conform action is not pipe or ok");
return false;
}
if (mlx5e_policer_validate(parse_state->flow_action, act,
parse_state->extack))
int err;

err = police_act_validate(act, parse_state->extack);
if (err)
return false;

return !!mlx5e_get_flow_meters(parse_state->flow->priv->mdev);
Expand Down Expand Up @@ -79,7 +113,7 @@ tc_act_police_offload(struct mlx5e_priv *priv,
struct mlx5e_flow_meter_handle *meter;
int err = 0;

err = mlx5e_policer_validate(&fl_act->action, act, fl_act->extack);
err = police_act_validate(act, fl_act->extack);
if (err)
return err;

Expand Down Expand Up @@ -147,11 +181,25 @@ tc_act_police_stats(struct mlx5e_priv *priv,
return 0;
}

static bool
tc_act_police_get_branch_ctrl(const struct flow_action_entry *act,
struct mlx5e_tc_act_branch_ctrl *cond_true,
struct mlx5e_tc_act_branch_ctrl *cond_false)
{
cond_true->act_id = act->police.notexceed.act_id;
cond_true->extval = act->police.notexceed.extval;

cond_false->act_id = act->police.exceed.act_id;
cond_false->extval = act->police.exceed.extval;
return true;
}

struct mlx5e_tc_act mlx5e_tc_act_police = {
.can_offload = tc_act_can_offload_police,
.parse_action = tc_act_parse_police,
.is_multi_table_act = tc_act_is_multi_table_act_police,
.offload_action = tc_act_police_offload,
.destroy_action = tc_act_police_destroy,
.stats_action = tc_act_police_stats,
.get_branch_ctrl = tc_act_police_get_branch_ctrl,
};
24 changes: 12 additions & 12 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ __mlx5e_flow_meter_alloc(struct mlx5e_flow_meters *flow_meters)
counter = mlx5_fc_create(mdev, true);
if (IS_ERR(counter)) {
err = PTR_ERR(counter);
goto err_red_counter;
goto err_drop_counter;
}
meter->red_counter = counter;
meter->drop_counter = counter;

counter = mlx5_fc_create(mdev, true);
if (IS_ERR(counter)) {
err = PTR_ERR(counter);
goto err_green_counter;
goto err_act_counter;
}
meter->green_counter = counter;
meter->act_counter = counter;

meters_obj = list_first_entry_or_null(&flow_meters->partial_list,
struct mlx5e_flow_meter_aso_obj,
Expand Down Expand Up @@ -313,10 +313,10 @@ __mlx5e_flow_meter_alloc(struct mlx5e_flow_meters *flow_meters)
err_mem:
mlx5e_flow_meter_destroy_aso_obj(mdev, id);
err_create:
mlx5_fc_destroy(mdev, meter->green_counter);
err_green_counter:
mlx5_fc_destroy(mdev, meter->red_counter);
err_red_counter:
mlx5_fc_destroy(mdev, meter->act_counter);
err_act_counter:
mlx5_fc_destroy(mdev, meter->drop_counter);
err_drop_counter:
kfree(meter);
return ERR_PTR(err);
}
Expand All @@ -329,8 +329,8 @@ __mlx5e_flow_meter_free(struct mlx5e_flow_meter_handle *meter)
struct mlx5e_flow_meter_aso_obj *meters_obj;
int n, pos;

mlx5_fc_destroy(mdev, meter->green_counter);
mlx5_fc_destroy(mdev, meter->red_counter);
mlx5_fc_destroy(mdev, meter->act_counter);
mlx5_fc_destroy(mdev, meter->drop_counter);

meters_obj = meter->meters_obj;
pos = (meter->obj_id - meters_obj->base_id) * 2 + meter->idx;
Expand Down Expand Up @@ -575,8 +575,8 @@ mlx5e_tc_meter_get_stats(struct mlx5e_flow_meter_handle *meter,
u64 bytes1, packets1, lastuse1;
u64 bytes2, packets2, lastuse2;

mlx5_fc_query_cached(meter->green_counter, &bytes1, &packets1, &lastuse1);
mlx5_fc_query_cached(meter->red_counter, &bytes2, &packets2, &lastuse2);
mlx5_fc_query_cached(meter->act_counter, &bytes1, &packets1, &lastuse1);
mlx5_fc_query_cached(meter->drop_counter, &bytes2, &packets2, &lastuse2);

*bytes = bytes1 + bytes2;
*packets = packets1 + packets2;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct mlx5e_flow_meter_handle {
struct hlist_node hlist;
struct mlx5e_flow_meter_params params;

struct mlx5_fc *green_counter;
struct mlx5_fc *red_counter;
struct mlx5_fc *act_counter;
struct mlx5_fc *drop_counter;
};

struct mlx5e_meter_attr {
Expand Down
Loading

0 comments on commit ddda632

Please sign in to comment.