flow_offload hardware priority fixes
Subsystems (11)
Pablo Neira Ayuso
maintainerv4 cover flow_offload hardware priority fixes
Hi,
This patchset contains two updates for the flow_offload users:
1) Pass the major tc priority to drivers so they do not have to lshift it. This is a preparation patch for the fix coming in patch #2.
2) Set the hardware priority from the netfilter basechain priority, some drivers break when using the existing hardware priority number that is set to zero.
Please, apply.
Pablo Neira Ayuso (2):
net: sched: use major priority number as hardware priority
netfilter: nf_tables: map basechain priority to hardware priority
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- drivers/net/ethernet/mscc/ocelot_flower.c | 12 +++--------- drivers/net/ethernet/netronome/nfp/flower/qos_conf.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 2 +- include/net/netfilter/nf_tables_offload.h | 2 ++ include/net/pkt_cls.h | 2 +- net/netfilter/nf_tables_api.c | 4 ++++ net/netfilter/nf_tables_offload.c | 18 +++++++++++++++--- 9 files changed, 29 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v4 1/2 net: sched: use major priority number as hardware priority
tc transparently maps the software priority number to hardware. Update it to pass the major priority which is what most drivers expect. Update drivers too so they do not need to lshift the priority field of the flow_cls_common_offload object. The stmmac driver is an exception, since this code assumes the tc software priority is fine, therefore, lshift it just to be conservative.
---
v4: no changes.
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- drivers/net/ethernet/mscc/ocelot_flower.c | 12 +++--------- drivers/net/ethernet/netronome/nfp/flower/qos_conf.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 2 +- include/net/pkt_cls.h | 2 +- 6 files changed, 8 insertions(+), 14 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
@@ -3158,7 +3158,7 @@ mlx5e_flow_esw_attr_init(struct mlx5_esw_flow_attr *esw_attr, esw_attr->parse_attr = parse_attr; esw_attr->chain = f->common.chain_index; - esw_attr->prio =TC_H_MAJ (f->common.prio) >>16 ; + esw_attr->prio = f->common.prio; esw_attr->in_rep = in_rep; esw_attr->in_mdev = in_mdev;
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +1 -1
@@ -471,7 +471,7 @@ int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei)void mlxsw_sp_acl_rulei_priority (struct mlxsw_sp_acl_rule_info *rulei,unsigned int priority) { - rulei->priority = priority >>16 ; + rulei->priority = priority; } void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
drivers/net/ethernet/mscc/ocelot_flower.c +3 -9
@@ -13,12 +13,6 @@ struct ocelot_port_block {struct ocelot_port *port; }; -static u16 get_prio (u32 prio) -{ -/* prio starts from 0x1000 while the ids starts from 0 */ -return prio >>16 ; -} -static int ocelot_flower_parse_action (struct flow_cls_offload *f,struct ocelot_ace_rule *rule) {
@@ -168,7 +162,7 @@ static int ocelot_flower_parse(struct flow_cls_offload *f, } finished_key_parsing: - ocelot_rule->prio =get_prio (f->common.prio); + ocelot_rule->prio = f->common.prio; ocelot_rule->id = f->cookie;return ocelot_flower_parse_action (f, ocelot_rule); }
@@ -218,7 +212,7 @@ static int ocelot_flower_destroy(struct flow_cls_offload *f,struct ocelot_ace_rule rule;int ret; - rule.prio =get_prio (f->common.prio); + rule.prio = f->common.prio; rule.port = port_block->port; rule.id = f->cookie;
@@ -236,7 +230,7 @@ static int ocelot_flower_stats_update(struct flow_cls_offload *f,struct ocelot_ace_rule rule;int ret; - rule.prio =get_prio (f->common.prio); + rule.prio = f->common.prio; rule.port = port_block->port; rule.id = f->cookie; ret =ocelot_ace_rule_stats_update (&rule);
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +1 -1
@@ -93,7 +93,7 @@ nfp_flower_install_rate_limiter(struct nfp_app *app, struct net_device *netdev,return -EOPNOTSUPP ; } -if (flow->common.prio != (1 <<16 )) { +if (flow->common.prio !=1 ) {NL_SET_ERR_MSG_MOD (extack,"unsupported offload: qos rate limit offload requires highest priority" );return -EOPNOTSUPP ; }
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +1 -1
@@ -94,7 +94,7 @@ static int tc_fill_entry(struct stmmac_priv *priv,struct stmmac_tc_entry *entry, *frag =NULL ;struct tc_u32_sel *sel = cls->knode.sel;u32 off, data, mask, real_off, rem; -u32 prio = cls->common.prio; +u32 prio = cls->common.prio <<16 ;int ret;/* Only 1 match per entry */
include/net/pkt_cls.h +1 -1
@@ -646,7 +646,7 @@ tc_cls_common_offload_init(struct flow_cls_common_offload *cls_common, { cls_common->chain_index = tp->chain->index; cls_common->protocol = tp->protocol; - cls_common->prio = tp->prio; + cls_common->prio = tp->prio >>16 ;if (tc_skip_sw (flags) || flags &TCA_CLS_FLAGS_VERBOSE ) cls_common->extack = extack; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v4 2/2 netfilter: nf_tables: map basechain priority to hardware priority
In reply to Pablo Neira AyusoThis patch adds initial support for offloading basechains using the priority range from -32767 to 32767. This is restricting the netfilter priority range to 16-bit integer since this is what most drivers assume so far from tc.
The software to hardware priority mapping is not exposed to userspace. Hence, it should be possible to extend this range of supported priorities later on once drivers are updated to support for 32-bit integer priorities.
---
v4: no changes wrt. [PATCH net 2/2,v3] netfilter: nf_tables: map basechain
priority to hardware priority.
include/net/netfilter/nf_tables_offload.h | 2 ++ net/netfilter/nf_tables_api.c | 4 ++++ net/netfilter/nf_tables_offload.c | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-)
include/net/netfilter/nf_tables_offload.h +2 -0
@@ -73,4 +73,6 @@ int nft_flow_rule_offload_commit(struct net *net); (__reg)->key = __key; \memset (&(__reg)->mask,0xff , (__reg)->len); +u32 nft_chain_offload_priority (struct nft_base_chain *basechain); +#endif
net/netfilter/nf_tables_api.c +4 -0
@@ -1662,6 +1662,10 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, chain->flags |=NFT_BASE_CHAIN | flags; basechain->policy =NF_ACCEPT ; +if (chain->flags &NFT_CHAIN_HW_OFFLOAD && + !nft_chain_offload_priority (basechain)) +return -EOPNOTSUPP ; +flow_block_init (&basechain->flow_block); }else { chain =kzalloc (sizeof (*chain),GFP_KERNEL );
net/netfilter/nf_tables_offload.c +15 -3
@@ -103,10 +103,11 @@ void nft_offload_update_dependency(struct nft_offload_ctx *ctx, }static void nft_flow_offload_common_init (struct flow_cls_common_offload *common, -__be16 proto, -struct netlink_ext_ack *extack) +__be16 proto,int priority, +struct netlink_ext_ack *extack) { common->protocol = proto; + common->prio = priority; common->extack = extack; }
@@ -124,6 +125,15 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain,return 0 ; } +u32 nft_chain_offload_priority (struct nft_base_chain *basechain) +{ +if (basechain->ops.priority <SHRT_MIN || + basechain->ops.priority >SHRT_MAX ) +return 0 ; + +return basechain->ops.priority +abs (SHRT_MIN ); +} +static int nft_flow_offload_rule (struct nft_trans *trans,enum flow_cls_command command) {
@@ -142,7 +152,9 @@ static int nft_flow_offload_rule(struct nft_trans *trans,if (flow) proto = flow->proto; -nft_flow_offload_common_init (&cls_flow.common, proto, &extack); +nft_flow_offload_common_init (&cls_flow.common, proto, +nft_chain_offload_priority (basechain), + &extack); cls_flow.command = command; cls_flow.cookie = (unsigned long ) rule;if (flow)
Signature · 1 line
2.11.0
Quoted 11 lines · Pablo Neira Ayuso
Hi,
This patchset contains two updates for the
flow_offloadusers:1) Pass the major tc priority to drivers so they do not have to lshift it. This is a preparation patch for the fix coming in patch #2.
2) Set the hardware priority from the netfilter basechain priority, some drivers break when using the existing hardware priority number that is set to zero.
Seems reasonable, thanks.
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 6 Aug 2019 18:03:08 +0200
Quoted 9 lines
This patchset contains two updates for the
flow_offloadusers:1) Pass the major tc priority to drivers so they do not have to lshift it. This is a preparation patch for the fix coming in patch #2.
2) Set the hardware priority from the netfilter basechain priority, some drivers break when using the existing hardware priority number that is set to zero.
Series applied.
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Fri, 09 Aug 2019 12:37:41 -0700 (PDT)
Quoted 9 lines
From: Pablo Neira Ayuso <[email protected]>
Date: Tue, 6 Aug 2019 18:03:08 +0200Quoted 6 lines
This patchset contains two updates for the
flow_offloadusers:1) Pass the major tc priority to drivers so they do not have to lshift it. This is a preparation patch for the fix coming in patch #2.
Quoted 5 lines
Quoted 3 lines
2) Set the hardware priority from the netfilter basechain priority, some drivers break when using the existing hardware priority number that is set to zero.
Series applied.
Sorry, I had to revert:
[davem@localhost net]$ make -s -j14
In file included from ./include/linux/list.h:9,
from ./include/linux/module.h:9,
from net/netfilter/nf_tables_offload.c:3:net/netfilter/nf_tables_offload.c: In function ‘nft_chain_offload_priority’:./include/linux/kernel.h:269:23: warning: overflow in conversion from ‘short int’ to ‘signed char’ changes value from ‘-32768’ to ‘0’ [-Woverflow]
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
^
./include/linux/kernel.h:256:16: note: in expansion of macro ‘__abs_choose_expr’
#define abs(x) __abs_choose_expr(x, long long, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:257:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, long, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:258:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, int, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:259:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, short, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:260:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, char, \
^~~~~~~~~~~~~~~~~net/netfilter/nf_tables_offload.c:134:35: note: in expansion of macro ‘abs’
return basechain->ops.priority + abs(SHRT_MIN);
^~~
./include/linux/kernel.h:263:31: warning: overflow in conversion from ‘short int’ to ‘signed char’ changes value from ‘-32768’ to ‘0’ [-Woverflow]
(char)({ signed char __x = (x); __x<0?-__x:__x; }), \
^
./include/linux/kernel.h:269:54: note: in definition of macro ‘__abs_choose_expr’
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
^~~~~./include/linux/kernel.h:257:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, long, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:258:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, int, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:259:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, short, \
^~~~~~~~~~~~~~~~~./include/linux/kernel.h:260:3: note: in expansion of macro ‘__abs_choose_expr’
__abs_choose_expr(x, char, \
^~~~~~~~~~~~~~~~~net/netfilter/nf_tables_offload.c:134:35: note: in expansion of macro ‘abs’
return basechain->ops.priority + abs(SHRT_MIN);
^~~