* [PATCH net-next 1/2] net: flow_offload: add tc police action parameters
2022-02-14 10:09 [PATCH net-next 0/2] flow_offload: add tc police parameters Jianbo Liu
@ 2022-02-14 10:09 ` Jianbo Liu
2022-02-14 10:09 ` [PATCH net-next 2/2] flow_offload: reject offload for all drivers with invalid police parameters Jianbo Liu
2022-02-14 13:41 ` [PATCH net-next 0/2] flow_offload: add tc " Ido Schimmel
2 siblings, 0 replies; 4+ messages in thread
From: Jianbo Liu @ 2022-02-14 10:09 UTC (permalink / raw)
To: netdev; +Cc: davem, jiri, idosch, ozsh, roid, Jianbo Liu
The current police offload action entry is missing exceed/notexceed
actions and parameters that can be configured by tc police action.
Add the missing parameters as a pre-step for offloading police actions
to hardware.
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Signed-off-by: Roi Dayan <roid@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
include/net/flow_offload.h | 13 ++++++++++
include/net/tc_act/tc_police.h | 30 ++++++++++++++++++++++
net/sched/act_police.c | 46 ++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+)
diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index 5b8c54eb7a6b..94cde6bbc8a5 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -148,6 +148,8 @@ enum flow_action_id {
FLOW_ACTION_MPLS_MANGLE,
FLOW_ACTION_GATE,
FLOW_ACTION_PPPOE_PUSH,
+ FLOW_ACTION_JUMP,
+ FLOW_ACTION_PIPE,
NUM_FLOW_ACTIONS,
};
@@ -235,9 +237,20 @@ struct flow_action_entry {
struct { /* FLOW_ACTION_POLICE */
u32 burst;
u64 rate_bytes_ps;
+ u64 peakrate_bytes_ps;
+ u32 avrate;
+ u16 overhead;
u64 burst_pkt;
u64 rate_pkt_ps;
u32 mtu;
+ struct {
+ enum flow_action_id act_id;
+ u32 index;
+ } exceed;
+ struct {
+ enum flow_action_id act_id;
+ u32 index;
+ } notexceed;
} police;
struct { /* FLOW_ACTION_CT */
int action;
diff --git a/include/net/tc_act/tc_police.h b/include/net/tc_act/tc_police.h
index 72649512dcdd..283bde711a42 100644
--- a/include/net/tc_act/tc_police.h
+++ b/include/net/tc_act/tc_police.h
@@ -159,4 +159,34 @@ static inline u32 tcf_police_tcfp_mtu(const struct tc_action *act)
return params->tcfp_mtu;
}
+static inline u64 tcf_police_peakrate_bytes_ps(const struct tc_action *act)
+{
+ struct tcf_police *police = to_police(act);
+ struct tcf_police_params *params;
+
+ params = rcu_dereference_protected(police->params,
+ lockdep_is_held(&police->tcf_lock));
+ return params->peak.rate_bytes_ps;
+}
+
+static inline u32 tcf_police_tcfp_ewma_rate(const struct tc_action *act)
+{
+ struct tcf_police *police = to_police(act);
+ struct tcf_police_params *params;
+
+ params = rcu_dereference_protected(police->params,
+ lockdep_is_held(&police->tcf_lock));
+ return params->tcfp_ewma_rate;
+}
+
+static inline u16 tcf_police_rate_overhead(const struct tc_action *act)
+{
+ struct tcf_police *police = to_police(act);
+ struct tcf_police_params *params;
+
+ params = rcu_dereference_protected(police->params,
+ lockdep_is_held(&police->tcf_lock));
+ return params->rate.overhead;
+}
+
#endif /* __NET_TC_POLICE_H */
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 0923aa2b8f8a..0457b6c9c4e7 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -405,20 +405,66 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index)
return tcf_idr_search(tn, a, index);
}
+static int tcf_police_act_to_flow_act(int tc_act, int *index)
+{
+ int act_id = -EOPNOTSUPP;
+
+ if (!TC_ACT_EXT_OPCODE(tc_act)) {
+ if (tc_act == TC_ACT_OK)
+ act_id = FLOW_ACTION_ACCEPT;
+ else if (tc_act == TC_ACT_SHOT)
+ act_id = FLOW_ACTION_DROP;
+ else if (tc_act == TC_ACT_PIPE)
+ act_id = FLOW_ACTION_PIPE;
+ } else if (TC_ACT_EXT_CMP(tc_act, TC_ACT_GOTO_CHAIN)) {
+ act_id = FLOW_ACTION_GOTO;
+ *index = tc_act & TC_ACT_EXT_VAL_MASK;
+ } else if (TC_ACT_EXT_CMP(tc_act, TC_ACT_JUMP)) {
+ act_id = FLOW_ACTION_JUMP;
+ *index = tc_act & TC_ACT_EXT_VAL_MASK;
+ }
+
+ return act_id;
+}
+
static int tcf_police_offload_act_setup(struct tc_action *act, void *entry_data,
u32 *index_inc, bool bind)
{
if (bind) {
struct flow_action_entry *entry = entry_data;
+ struct tcf_police *police = to_police(act);
+ struct tcf_police_params *p;
+ int act_id;
+
+ p = rcu_dereference_protected(police->params,
+ lockdep_is_held(&police->tcf_lock));
entry->id = FLOW_ACTION_POLICE;
entry->police.burst = tcf_police_burst(act);
entry->police.rate_bytes_ps =
tcf_police_rate_bytes_ps(act);
+ entry->police.peakrate_bytes_ps = tcf_police_peakrate_bytes_ps(act);
+ entry->police.avrate = tcf_police_tcfp_ewma_rate(act);
+ entry->police.overhead = tcf_police_rate_overhead(act);
entry->police.burst_pkt = tcf_police_burst_pkt(act);
entry->police.rate_pkt_ps =
tcf_police_rate_pkt_ps(act);
entry->police.mtu = tcf_police_tcfp_mtu(act);
+
+ act_id = tcf_police_act_to_flow_act(police->tcf_action,
+ &entry->police.exceed.index);
+ if (act_id < 0)
+ return act_id;
+
+ entry->police.exceed.act_id = act_id;
+
+ act_id = tcf_police_act_to_flow_act(p->tcfp_result,
+ &entry->police.notexceed.index);
+ if (act_id < 0)
+ return act_id;
+
+ entry->police.notexceed.act_id = act_id;
+
*index_inc = 1;
} else {
struct flow_offload_action *fl_action = entry_data;
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net-next 2/2] flow_offload: reject offload for all drivers with invalid police parameters
2022-02-14 10:09 [PATCH net-next 0/2] flow_offload: add tc police parameters Jianbo Liu
2022-02-14 10:09 ` [PATCH net-next 1/2] net: flow_offload: add tc police action parameters Jianbo Liu
@ 2022-02-14 10:09 ` Jianbo Liu
2022-02-14 13:41 ` [PATCH net-next 0/2] flow_offload: add tc " Ido Schimmel
2 siblings, 0 replies; 4+ messages in thread
From: Jianbo Liu @ 2022-02-14 10:09 UTC (permalink / raw)
To: netdev; +Cc: davem, jiri, idosch, ozsh, roid, Jianbo Liu
As more police parameters are passed to flow_offload, driver can check
them to make sure hardware handles packets in the way indicated by tc.
The conform-exceed control should be drop/pipe or drop/ok. As hardware
can't configure peakrate/avrate/overhead, offload should not be
supported if any of them is configured.
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
drivers/net/dsa/sja1105/sja1105_flower.c | 15 +++++++++
.../chelsio/cxgb4/cxgb4_tc_matchall.c | 31 +++++++++++++++++++
.../net/ethernet/freescale/enetc/enetc_qos.c | 17 ++++++++++
.../ethernet/marvell/octeontx2/nic/otx2_tc.c | 30 ++++++++++++++++++
.../net/ethernet/mellanox/mlx5/core/en_tc.c | 15 +++++++++
.../ethernet/mellanox/mlxsw/spectrum_flower.c | 15 +++++++++
drivers/net/ethernet/mscc/ocelot_flower.c | 16 ++++++++++
drivers/net/ethernet/mscc/ocelot_net.c | 15 +++++++++
.../ethernet/netronome/nfp/flower/qos_conf.c | 16 ++++++++++
9 files changed, 170 insertions(+)
diff --git a/drivers/net/dsa/sja1105/sja1105_flower.c b/drivers/net/dsa/sja1105/sja1105_flower.c
index 7dcdd784aea4..85f4e321a7a2 100644
--- a/drivers/net/dsa/sja1105/sja1105_flower.c
+++ b/drivers/net/dsa/sja1105/sja1105_flower.c
@@ -321,6 +321,21 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
flow_action_for_each(i, act, &rule->action) {
switch (act->id) {
case FLOW_ACTION_POLICE:
+ if ((act->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ act->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ act->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (act->police.peakrate_bytes_ps ||
+ act->police.avrate || act->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is 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");
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
index 28fd2de9e4cf..84a785e7a68f 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
@@ -48,6 +48,21 @@ static int cxgb4_matchall_egress_validate(struct net_device *dev,
flow_action_for_each(i, entry, actions) {
switch (entry->id) {
case FLOW_ACTION_POLICE:
+ if ((entry->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ entry->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ entry->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (entry->police.peakrate_bytes_ps ||
+ entry->police.avrate || entry->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (entry->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack,
"QoS offload not support packets per second");
@@ -150,6 +165,22 @@ static int cxgb4_matchall_alloc_tc(struct net_device *dev,
flow_action_for_each(i, entry, &cls->rule->action)
if (entry->id == FLOW_ACTION_POLICE)
break;
+
+ if ((entry->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ entry->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ entry->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (entry->police.peakrate_bytes_ps ||
+ entry->police.avrate || entry->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (entry->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack,
"QoS offload not support packets per second");
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_qos.c b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
index 3555c12edb45..183318e7255f 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_qos.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_qos.c
@@ -1230,6 +1230,23 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
/* Flow meter and max frame size */
if (entryp) {
+ if ((entryp->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ entryp->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ entryp->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ err = -EOPNOTSUPP;
+ goto free_sfi;
+ }
+
+ if (entryp->police.peakrate_bytes_ps ||
+ entryp->police.avrate || entryp->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ err = -EOPNOTSUPP;
+ goto free_sfi;
+ }
+
if (entryp->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
err = -EOPNOTSUPP;
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
index 626961a41089..15aa73cd0383 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
@@ -212,6 +212,21 @@ static int otx2_tc_egress_matchall_install(struct otx2_nic *nic,
entry = &cls->rule->action.entries[0];
switch (entry->id) {
case FLOW_ACTION_POLICE:
+ if ((entry->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ entry->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ entry->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (entry->police.peakrate_bytes_ps ||
+ entry->police.avrate || entry->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (entry->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
return -EOPNOTSUPP;
@@ -355,6 +370,21 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic,
return -EOPNOTSUPP;
}
+ if ((act->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ act->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ act->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (act->police.peakrate_bytes_ps ||
+ act->police.avrate || act->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (act->police.rate_bytes_ps > 0) {
rate = act->police.rate_bytes_ps * 8;
burst = act->police.burst;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 1287193a019b..829b09029cb0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -4197,6 +4197,21 @@ static int scan_tc_matchall_fdb_actions(struct mlx5e_priv *priv,
flow_action_for_each(i, act, flow_action) {
switch (act->id) {
case FLOW_ACTION_POLICE:
+ if ((act->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ act->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ act->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (act->police.peakrate_bytes_ps ||
+ act->police.avrate || act->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is 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;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index bb417db773b9..2de3eed6c637 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -191,6 +191,21 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
return -EOPNOTSUPP;
}
+ if ((act->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ act->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ act->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (act->police.peakrate_bytes_ps ||
+ act->police.avrate || act->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is 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;
diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c
index 949858891973..e8c0c32b9050 100644
--- a/drivers/net/ethernet/mscc/ocelot_flower.c
+++ b/drivers/net/ethernet/mscc/ocelot_flower.c
@@ -296,6 +296,22 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port,
"Last action must be GOTO");
return -EOPNOTSUPP;
}
+
+ if ((a->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ a->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ a->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (a->police.peakrate_bytes_ps ||
+ a->police.avrate || a->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (a->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack,
"QoS offload not support packets per second");
diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c
index e271b6225b72..afef105b0c3b 100644
--- a/drivers/net/ethernet/mscc/ocelot_net.c
+++ b/drivers/net/ethernet/mscc/ocelot_net.c
@@ -258,6 +258,21 @@ static int ocelot_setup_tc_cls_matchall(struct ocelot_port_private *priv,
return -EEXIST;
}
+ if ((action->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ action->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ action->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (action->police.peakrate_bytes_ps ||
+ action->police.avrate || action->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (action->police.rate_pkt_ps) {
NL_SET_ERR_MSG_MOD(extack,
"QoS offload not support packets per second");
diff --git a/drivers/net/ethernet/netronome/nfp/flower/qos_conf.c b/drivers/net/ethernet/netronome/nfp/flower/qos_conf.c
index 784c6dbf8bc4..09cfbda6a9ba 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/qos_conf.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/qos_conf.c
@@ -132,6 +132,22 @@ nfp_flower_install_rate_limiter(struct nfp_app *app, struct net_device *netdev,
"unsupported offload: qos rate limit offload requires police action");
return -EOPNOTSUPP;
}
+
+ if ((action->police.notexceed.act_id != FLOW_ACTION_ACCEPT &&
+ action->police.notexceed.act_id != FLOW_ACTION_PIPE) ||
+ action->police.exceed.act_id != FLOW_ACTION_DROP) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when conform-exceed is not drop/pipe or drop/ok");
+ return -EOPNOTSUPP;
+ }
+
+ if (action->police.peakrate_bytes_ps ||
+ action->police.avrate || action->police.overhead) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Police action is not supported when peakrate/avrate/overhead is configured");
+ return -EOPNOTSUPP;
+ }
+
if (action->police.rate_bytes_ps > 0) {
if (bps_num++) {
NL_SET_ERR_MSG_MOD(extack,
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread