Skip to content

Commit d97b4b1

Browse files
Jianbo Liudavem330
authored andcommitted
flow_offload: reject offload for all drivers with invalid police parameters
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. Besides, for drop/ok, the police should be the last action. As hardware can't configure peakrate/avrate/overhead, offload should not be supported if any of them is configured. Signed-off-by: Jianbo Liu <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b8cd583 commit d97b4b1

File tree

12 files changed

+369
-38
lines changed

12 files changed

+369
-38
lines changed

drivers/net/dsa/sja1105/sja1105_flower.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,46 @@ static int sja1105_flower_parse_key(struct sja1105_private *priv,
300300
return -EOPNOTSUPP;
301301
}
302302

303+
static int sja1105_policer_validate(const struct flow_action *action,
304+
const struct flow_action_entry *act,
305+
struct netlink_ext_ack *extack)
306+
{
307+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
308+
NL_SET_ERR_MSG_MOD(extack,
309+
"Offload not supported when exceed action is not drop");
310+
return -EOPNOTSUPP;
311+
}
312+
313+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
314+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
315+
NL_SET_ERR_MSG_MOD(extack,
316+
"Offload not supported when conform action is not pipe or ok");
317+
return -EOPNOTSUPP;
318+
}
319+
320+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
321+
!flow_action_is_last_entry(action, act)) {
322+
NL_SET_ERR_MSG_MOD(extack,
323+
"Offload not supported when conform action is ok, but action is not last");
324+
return -EOPNOTSUPP;
325+
}
326+
327+
if (act->police.peakrate_bytes_ps ||
328+
act->police.avrate || act->police.overhead) {
329+
NL_SET_ERR_MSG_MOD(extack,
330+
"Offload not supported when peakrate/avrate/overhead is configured");
331+
return -EOPNOTSUPP;
332+
}
333+
334+
if (act->police.rate_pkt_ps) {
335+
NL_SET_ERR_MSG_MOD(extack,
336+
"QoS offload not support packets per second");
337+
return -EOPNOTSUPP;
338+
}
339+
340+
return 0;
341+
}
342+
303343
int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
304344
struct flow_cls_offload *cls, bool ingress)
305345
{
@@ -321,12 +361,9 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
321361
flow_action_for_each(i, act, &rule->action) {
322362
switch (act->id) {
323363
case FLOW_ACTION_POLICE:
324-
if (act->police.rate_pkt_ps) {
325-
NL_SET_ERR_MSG_MOD(extack,
326-
"QoS offload not support packets per second");
327-
rc = -EOPNOTSUPP;
364+
rc = sja1105_policer_validate(&rule->action, act, extack);
365+
if (rc)
328366
goto out;
329-
}
330367

331368
rc = sja1105_flower_policer(priv, port, extack, cookie,
332369
&key,

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@
88
#include "cxgb4_filter.h"
99
#include "cxgb4_tc_flower.h"
1010

11+
static int cxgb4_policer_validate(const struct flow_action *action,
12+
const struct flow_action_entry *act,
13+
struct netlink_ext_ack *extack)
14+
{
15+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
16+
NL_SET_ERR_MSG_MOD(extack,
17+
"Offload not supported when exceed action is not drop");
18+
return -EOPNOTSUPP;
19+
}
20+
21+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
22+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
23+
NL_SET_ERR_MSG_MOD(extack,
24+
"Offload not supported when conform action is not pipe or ok");
25+
return -EOPNOTSUPP;
26+
}
27+
28+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
29+
!flow_action_is_last_entry(action, act)) {
30+
NL_SET_ERR_MSG_MOD(extack,
31+
"Offload not supported when conform action is ok, but action is not last");
32+
return -EOPNOTSUPP;
33+
}
34+
35+
if (act->police.peakrate_bytes_ps ||
36+
act->police.avrate || act->police.overhead) {
37+
NL_SET_ERR_MSG_MOD(extack,
38+
"Offload not supported when peakrate/avrate/overhead is configured");
39+
return -EOPNOTSUPP;
40+
}
41+
42+
if (act->police.rate_pkt_ps) {
43+
NL_SET_ERR_MSG_MOD(extack,
44+
"QoS offload not support packets per second");
45+
return -EOPNOTSUPP;
46+
}
47+
48+
return 0;
49+
}
50+
1151
static int cxgb4_matchall_egress_validate(struct net_device *dev,
1252
struct tc_cls_matchall_offload *cls)
1353
{
@@ -48,11 +88,10 @@ static int cxgb4_matchall_egress_validate(struct net_device *dev,
4888
flow_action_for_each(i, entry, actions) {
4989
switch (entry->id) {
5090
case FLOW_ACTION_POLICE:
51-
if (entry->police.rate_pkt_ps) {
52-
NL_SET_ERR_MSG_MOD(extack,
53-
"QoS offload not support packets per second");
54-
return -EOPNOTSUPP;
55-
}
91+
ret = cxgb4_policer_validate(actions, entry, extack);
92+
if (ret)
93+
return ret;
94+
5695
/* Convert bytes per second to bits per second */
5796
if (entry->police.rate_bytes_ps * 8 > max_link_rate) {
5897
NL_SET_ERR_MSG_MOD(extack,
@@ -150,11 +189,11 @@ static int cxgb4_matchall_alloc_tc(struct net_device *dev,
150189
flow_action_for_each(i, entry, &cls->rule->action)
151190
if (entry->id == FLOW_ACTION_POLICE)
152191
break;
153-
if (entry->police.rate_pkt_ps) {
154-
NL_SET_ERR_MSG_MOD(extack,
155-
"QoS offload not support packets per second");
156-
return -EOPNOTSUPP;
157-
}
192+
193+
ret = cxgb4_policer_validate(&cls->rule->action, entry, extack);
194+
if (ret)
195+
return ret;
196+
158197
/* Convert from bytes per second to Kbps */
159198
p.u.params.maxrate = div_u64(entry->police.rate_bytes_ps * 8, 1000);
160199
p.u.params.channel = pi->tx_chan;

drivers/net/ethernet/freescale/enetc/enetc_qos.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,46 @@ static struct actions_fwd *enetc_check_flow_actions(u64 acts,
10211021
return NULL;
10221022
}
10231023

1024+
static int enetc_psfp_policer_validate(const struct flow_action *action,
1025+
const struct flow_action_entry *act,
1026+
struct netlink_ext_ack *extack)
1027+
{
1028+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
1029+
NL_SET_ERR_MSG_MOD(extack,
1030+
"Offload not supported when exceed action is not drop");
1031+
return -EOPNOTSUPP;
1032+
}
1033+
1034+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
1035+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
1036+
NL_SET_ERR_MSG_MOD(extack,
1037+
"Offload not supported when conform action is not pipe or ok");
1038+
return -EOPNOTSUPP;
1039+
}
1040+
1041+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
1042+
!flow_action_is_last_entry(action, act)) {
1043+
NL_SET_ERR_MSG_MOD(extack,
1044+
"Offload not supported when conform action is ok, but action is not last");
1045+
return -EOPNOTSUPP;
1046+
}
1047+
1048+
if (act->police.peakrate_bytes_ps ||
1049+
act->police.avrate || act->police.overhead) {
1050+
NL_SET_ERR_MSG_MOD(extack,
1051+
"Offload not supported when peakrate/avrate/overhead is configured");
1052+
return -EOPNOTSUPP;
1053+
}
1054+
1055+
if (act->police.rate_pkt_ps) {
1056+
NL_SET_ERR_MSG_MOD(extack,
1057+
"QoS offload not support packets per second");
1058+
return -EOPNOTSUPP;
1059+
}
1060+
1061+
return 0;
1062+
}
1063+
10241064
static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
10251065
struct flow_cls_offload *f)
10261066
{
@@ -1177,11 +1217,10 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
11771217

11781218
/* Flow meter and max frame size */
11791219
if (entryp) {
1180-
if (entryp->police.rate_pkt_ps) {
1181-
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
1182-
err = -EOPNOTSUPP;
1220+
err = enetc_psfp_policer_validate(&rule->action, entryp, extack);
1221+
if (err)
11831222
goto free_sfi;
1184-
}
1223+
11851224
if (entryp->police.burst) {
11861225
fmi = kzalloc(sizeof(*fmi), GFP_KERNEL);
11871226
if (!fmi) {

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,40 @@ static int otx2_tc_validate_flow(struct otx2_nic *nic,
190190
return 0;
191191
}
192192

193+
static int otx2_policer_validate(const struct flow_action *action,
194+
const struct flow_action_entry *act,
195+
struct netlink_ext_ack *extack)
196+
{
197+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
198+
NL_SET_ERR_MSG_MOD(extack,
199+
"Offload not supported when exceed action is not drop");
200+
return -EOPNOTSUPP;
201+
}
202+
203+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
204+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
205+
NL_SET_ERR_MSG_MOD(extack,
206+
"Offload not supported when conform action is not pipe or ok");
207+
return -EOPNOTSUPP;
208+
}
209+
210+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
211+
!flow_action_is_last_entry(action, act)) {
212+
NL_SET_ERR_MSG_MOD(extack,
213+
"Offload not supported when conform action is ok, but action is not last");
214+
return -EOPNOTSUPP;
215+
}
216+
217+
if (act->police.peakrate_bytes_ps ||
218+
act->police.avrate || act->police.overhead) {
219+
NL_SET_ERR_MSG_MOD(extack,
220+
"Offload not supported when peakrate/avrate/overhead is configured");
221+
return -EOPNOTSUPP;
222+
}
223+
224+
return 0;
225+
}
226+
193227
static int otx2_tc_egress_matchall_install(struct otx2_nic *nic,
194228
struct tc_cls_matchall_offload *cls)
195229
{
@@ -212,6 +246,10 @@ static int otx2_tc_egress_matchall_install(struct otx2_nic *nic,
212246
entry = &cls->rule->action.entries[0];
213247
switch (entry->id) {
214248
case FLOW_ACTION_POLICE:
249+
err = otx2_policer_validate(&cls->rule->action, entry, extack);
250+
if (err)
251+
return err;
252+
215253
if (entry->police.rate_pkt_ps) {
216254
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
217255
return -EOPNOTSUPP;
@@ -315,6 +353,7 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic,
315353
u8 nr_police = 0;
316354
bool pps = false;
317355
u64 rate;
356+
int err;
318357
int i;
319358

320359
if (!flow_action_has_entries(flow_action)) {
@@ -355,6 +394,10 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic,
355394
return -EOPNOTSUPP;
356395
}
357396

397+
err = otx2_policer_validate(flow_action, act, extack);
398+
if (err)
399+
return err;
400+
358401
if (act->police.rate_bytes_ps > 0) {
359402
rate = act->police.rate_bytes_ps * 8;
360403
burst = act->police.burst;

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,6 +4482,46 @@ static int apply_police_params(struct mlx5e_priv *priv, u64 rate,
44824482
return err;
44834483
}
44844484

4485+
static int mlx5e_policer_validate(const struct flow_action *action,
4486+
const struct flow_action_entry *act,
4487+
struct netlink_ext_ack *extack)
4488+
{
4489+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
4490+
NL_SET_ERR_MSG_MOD(extack,
4491+
"Offload not supported when exceed action is not drop");
4492+
return -EOPNOTSUPP;
4493+
}
4494+
4495+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
4496+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
4497+
NL_SET_ERR_MSG_MOD(extack,
4498+
"Offload not supported when conform action is not pipe or ok");
4499+
return -EOPNOTSUPP;
4500+
}
4501+
4502+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
4503+
!flow_action_is_last_entry(action, act)) {
4504+
NL_SET_ERR_MSG_MOD(extack,
4505+
"Offload not supported when conform action is ok, but action is not last");
4506+
return -EOPNOTSUPP;
4507+
}
4508+
4509+
if (act->police.peakrate_bytes_ps ||
4510+
act->police.avrate || act->police.overhead) {
4511+
NL_SET_ERR_MSG_MOD(extack,
4512+
"Offload not supported when peakrate/avrate/overhead is configured");
4513+
return -EOPNOTSUPP;
4514+
}
4515+
4516+
if (act->police.rate_pkt_ps) {
4517+
NL_SET_ERR_MSG_MOD(extack,
4518+
"QoS offload not support packets per second");
4519+
return -EOPNOTSUPP;
4520+
}
4521+
4522+
return 0;
4523+
}
4524+
44854525
static int scan_tc_matchall_fdb_actions(struct mlx5e_priv *priv,
44864526
struct flow_action *flow_action,
44874527
struct netlink_ext_ack *extack)
@@ -4509,10 +4549,10 @@ static int scan_tc_matchall_fdb_actions(struct mlx5e_priv *priv,
45094549
flow_action_for_each(i, act, flow_action) {
45104550
switch (act->id) {
45114551
case FLOW_ACTION_POLICE:
4512-
if (act->police.rate_pkt_ps) {
4513-
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
4514-
return -EOPNOTSUPP;
4515-
}
4552+
err = mlx5e_policer_validate(flow_action, act, extack);
4553+
if (err)
4554+
return err;
4555+
45164556
err = apply_police_params(priv, act->police.rate_bytes_ps, extack);
45174557
if (err)
45184558
return err;

drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,46 @@
1515
#include "spectrum.h"
1616
#include "core_acl_flex_keys.h"
1717

18+
static int mlxsw_sp_policer_validate(const struct flow_action *action,
19+
const struct flow_action_entry *act,
20+
struct netlink_ext_ack *extack)
21+
{
22+
if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
23+
NL_SET_ERR_MSG_MOD(extack,
24+
"Offload not supported when exceed action is not drop");
25+
return -EOPNOTSUPP;
26+
}
27+
28+
if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
29+
act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
30+
NL_SET_ERR_MSG_MOD(extack,
31+
"Offload not supported when conform action is not pipe or ok");
32+
return -EOPNOTSUPP;
33+
}
34+
35+
if (act->police.notexceed.act_id == FLOW_ACTION_ACCEPT &&
36+
!flow_action_is_last_entry(action, act)) {
37+
NL_SET_ERR_MSG_MOD(extack,
38+
"Offload not supported when conform action is ok, but action is not last");
39+
return -EOPNOTSUPP;
40+
}
41+
42+
if (act->police.peakrate_bytes_ps ||
43+
act->police.avrate || act->police.overhead) {
44+
NL_SET_ERR_MSG_MOD(extack,
45+
"Offload not supported when peakrate/avrate/overhead is configured");
46+
return -EOPNOTSUPP;
47+
}
48+
49+
if (act->police.rate_pkt_ps) {
50+
NL_SET_ERR_MSG_MOD(extack,
51+
"QoS offload not support packets per second");
52+
return -EOPNOTSUPP;
53+
}
54+
55+
return 0;
56+
}
57+
1858
static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
1959
struct mlxsw_sp_flow_block *block,
2060
struct mlxsw_sp_acl_rule_info *rulei,
@@ -191,10 +231,9 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
191231
return -EOPNOTSUPP;
192232
}
193233

194-
if (act->police.rate_pkt_ps) {
195-
NL_SET_ERR_MSG_MOD(extack, "QoS offload not support packets per second");
196-
return -EOPNOTSUPP;
197-
}
234+
err = mlxsw_sp_policer_validate(flow_action, act, extack);
235+
if (err)
236+
return err;
198237

199238
/* The kernel might adjust the requested burst size so
200239
* that it is not exactly a power of two. Re-adjust it

0 commit comments

Comments
 (0)