net: sched: allow qdiscs to share filter block instances
Subsystems (7)
Jiri Pirko
maintainerv7 cover net: sched: allow qdiscs to share filter block instances
From: Jiri Pirko <[email protected]>
Currently the filters added to qdiscs are independent. So for example if you have 2 netdevices and you create ingress qdisc on both and you want to add identical filter rules both, you need to add them twice. This patchset makes this easier and mainly saves resources allowing to share all filters within a qdisc - I call it a "filter block". Also this helps to save resources when we do offload to hw for example to expensive TCAM.
So back to the example. First, we create 2 qdiscs. Both will share block number 22. "22" is just an identification:
$ tc qdisc add dev ens7 ingress block 22
^^^^^^^^
$ tc qdisc add dev ens8 ingress block 22
^^^^^^^^If we don't specify "block" command line option, no shared block would be created:
$ tc qdisc add dev ens9 ingress
Now if we list the qdiscs, we will see the block index in the output:
$ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1
To make is more visual, the situation looks like this:
ens7 ingress qdisc ens7 ingress qdisc
| |
| |
+----------> block 22 <----------+Unlimited number of qdiscs may share the same block.
Now we can add filter using the block index:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action drop
Note we cannot use the qdisc for filter manipulations of shared blocks:
$ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters.
We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22:
$ tc filter show block 22 filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
$ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
$ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
---v6->v7:
- patch 1:
- unsquashed shared block patch that was previously squashed by mistake
- fixed error path in block create - freeing chain 0
- patch 2:
- new patch - splitted from the previous one as it got accidentaly squashed in the rebasing process in the past
- converted to idr extended
- removed auto-generating of block indexes. Callers have to explicily tell that the block is shared by passing non-zero block index
- fixed error path in block get ext - freeing chain 0
- patch 7:
- changed extack message for block index handle as suggested by DaveA
- added extack message when block index does not exist
- the block ifindex magic is in define and change to 0xffffffff as suggested by Jamal
- patch 8:
- new patch implementing RTM_GETBLOCK in order to query if the block with some index exists
- patch 9:
- adjust to the core changes and check block index attributes for being 0
v5->v6:
- added patch 6 that introduces block handle
v4->v5:
- patch 5:
- add tracking of binding of devs that are unable to offload and check that before block cbs call.
v3->v4:
- patch 1:
- rebased on top of the current net-next
- added some extack strings
- patch 3:
- rebased on top of the current net-next
- patch 5:
- propagate netdev_ops->ndo_setup_tc error up to tcf_block_offload_bind caller
- patch 7:
- rebased on top of the current net-next
v2->v3:
- removed original patch 1, removing tp->q cls_bpf dependency. Fixed by Jakub in the meantime.
- patch 1:
- rebased on top of the current net-next
- patch 5:
- new patch
- patch 8:
- removed "p_" prefix from block index function args
- patch 10:
- add tc offload feature handling
Jiri Pirko (13):
net: sched: introduce support for multiple filter chain pointers
registration
net: sched: introduce shared filter blocks infrastructure
net: sched: avoid usage of tp->q in tcf_classify
net: sched: introduce block mechanism to handle netif_keep_dst calls
net: sched: remove classid and q fields from tcf_proto
net: sched: keep track of offloaded filters and check tc offload
feature
net: sched: use block index as a handle instead of qdisc when block is
shared
net: sched: add rt netlink message type for block get
net: sched: allow ingress and clsact qdiscs to share filter blocks
mlxsw: spectrum_acl: Reshuffle code around
mlxsw_sp_acl_ruleset_create/destroy
mlxsw: spectrum_acl: Don't store netdev and ingress for ruleset unbind
mlxsw: spectrum_acl: Implement TC block sharing
mlxsw: spectrum_acl: Pass mlxsw_sp_port down to ruleset bind/unbind
ops
drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 182 +++++- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 44 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 302 +++++++--- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 44 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 41 +- include/net/pkt_cls.h | 8 + include/net/sch_generic.h | 27 +- include/uapi/linux/pkt_sched.h | 11 + include/uapi/linux/rtnetlink.h | 12 + net/sched/cls_api.c | 655 ++++++++++++++++----- net/sched/cls_bpf.c | 9 +- net/sched/cls_flow.c | 2 +- net/sched/cls_flower.c | 3 +- net/sched/cls_matchall.c | 3 +- net/sched/cls_route.c | 2 +- net/sched/cls_u32.c | 13 +- net/sched/sch_ingress.c | 101 +++- security/selinux/nlmsgtab.c | 5 +- 18 files changed, 1155 insertions(+), 309 deletions(-)
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 1/13 net: sched: introduce support for multiple filter chain pointers registration
From: Jiri Pirko <[email protected]>
So far, there was possible only to register a single filter chain pointer to block->chain[0]. However, when the blocks will get shareable, we need to allow multiple filter chain pointers registration.
---v6->v7:
- unsquashed shared block patch that was previously squashed by mistake
- fixed error path in block create - freeing chain 0v3->v4:
- rebased on top of the current net-next
- added some extack stringsv2->v3:
- rebased on top of the current net-next
--- include/net/sch_generic.h | 3 +- net/sched/cls_api.c | 77 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 10 deletions(-)
include/net/sch_generic.h +1 -2
@@ -275,8 +275,7 @@ typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv);struct tcf_chain {struct tcf_proto __rcu *filter_chain; -tcf_chain_head_change_t *chain_head_change; -void *chain_head_change_priv; +struct list_head filter_chain_list;struct list_head list;struct tcf_block *block;u32 index;/* chain index */
net/sched/cls_api.c +69 -8
128 lines not on this page · raw message
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 2/13 net: sched: introduce shared filter blocks infrastructure
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Allow qdiscs to share filter blocks among them. Each qdisc type has to use block get/put extended modifications that enable sharing. Shared blocks are tracked within each net namespace and identified by u32 index. This index is passed from user during the qdisc creation. If user passes index that is not used by any other qdisc, new block is created. If user passes index that is already used, the existing block will be re-used.
---v6->v7:
- new patch - splitted from the previous one as it got accidentaly squashed in the rebasing process in the past
- converted to idr extended
- removed auto-generating of block indexes. Callers have to explicily tell that the block is shared by passing non-zero block index
- fixed error path in block get ext - freeing chain 0
--- include/net/pkt_cls.h | 7 ++ include/net/sch_generic.h | 2 + net/sched/cls_api.c | 163 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 148 insertions(+), 24 deletions(-)
include/net/pkt_cls.h +7 -0
@@ -29,6 +29,7 @@ struct tcf_block_ext_info {enum tcf_block_binder_type binder_type;tcf_chain_head_change_t *chain_head_change;void *chain_head_change_priv; +u32 block_index; };struct tcf_block_cb ;
@@ -48,8 +49,14 @@ void tcf_block_put(struct tcf_block *block);void tcf_block_put_ext (struct tcf_block *block,struct Qdisc *q,struct tcf_block_ext_info *ei); +static inline bool tcf_block_shared (struct tcf_block *block) +{ +return block->index; +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) { +WARN_ON (tcf_block_shared (block));return block->q; }
include/net/sch_generic.h +2 -0
@@ -284,6 +284,8 @@ struct tcf_chain {struct tcf_block {struct list_head chain_list; +u32 index;/* block index for shared blocks */ +unsigned int refcnt;struct net *net;struct Qdisc *q;struct list_head cb_list;
net/sched/cls_api.c +139 -24
225 lines not on this page · raw message
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 3/13 net: sched: avoid usage of tp->q in tcf_classify
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Use block index in the messages instead.
--- net/sched/cls_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/sched/cls_api.c +3 -2
@@ -672,8 +672,9 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,#ifdef CONFIG_NET_CLS_ACT reset:if (unlikely (limit++ >= max_reclassify_loop)) { -net_notice_ratelimited ("%s: reclassify loop, rule prio %u, protocol %02x\n" , - tp->q->ops->id, tp->prio &0xffff , +net_notice_ratelimited ("%u: reclassify loop, rule prio %u, protocol %02x\n" , + tp->chain->block->index, + tp->prio &0xffff ,ntohs (tp->protocol));return TC_ACT_SHOT ; }
Signature · 1 line
2.9.5
Re: [patch net-next v7 03/13] net: sched: avoid usage of tp->q in tcf_classify
Quoted 14 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Use block index in the messages instead.
Signed-off-by Jiri Pirko <[email protected]>--- net/sched/cls_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)net/sched/cls_api.c +0
-0
net/sched/cls_api.c int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, · line 675
Quoted 6 lines
net/sched/cls_api.c +1
-2@@ -672,8 +672,9 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,#ifdef CONFIG_NET_CLS_ACT reset:if (unlikely (limit++ >= max_reclassify_loop)) { - net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n", - tp->q->ops->id, tp->prio & 0xffff, + net_notice_ratelimited("%u: reclassify loop, rule prio %u, protocol %02x\n",
if you are dumping index instead of prio shouldn't the 'rule prio' above be adjusted?
Quoted 6 lines
net/sched/cls_api.c +2
-0+ tp->chain->block->index, + tp->prio &0xffff , ntohs(tp->protocol));return TC_ACT_SHOT ; }
Jiri Pirko
maintainerRe: [patch net-next v7 03/13] net: sched: avoid usage of tp->q in tcf_classify
Quoted 10 lines · Wed, Jan 10, 2018 at 05:17:28PM CET, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Use block index in the messages instead.
Signed-off-by Jiri Pirko <[email protected]>--- net/sched/cls_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 14 lines
net/sched/cls_api.c int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, · line 675
Quoted 11 lines
net/sched/cls_api.c +1
-2@@ -672,8 +672,9 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,#ifdef CONFIG_NET_CLS_ACT reset:if (unlikely (limit++ >= max_reclassify_loop)) { - net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n", - tp->q->ops->id, tp->prio & 0xffff, + net_notice_ratelimited("%u: reclassify loop, rule prio %u, protocol %02x\n",if you are dumping index instead of prio shouldn't the 'rule prio' above be adjusted?
I'm not! Why do you think so?
"%u:" is tp->chain->block->index
"prio %u" is tp->prio & 0xffff
"%02x" is ntohs(tp->protocol)
Quoted 9 lines
Quoted 8 lines
net/sched/cls_api.c +2
-0+ tp->chain->block->index, + tp->prio &0xffff , ntohs(tp->protocol));return TC_ACT_SHOT ; }
Re: [patch net-next v7 03/13] net: sched: avoid usage of tp->q in tcf_classify
Quoted 26 lines · Jiri Pirko
Quoted 10 lines · Wed, Jan 10, 2018 at 05:17:28PM CET, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Use block index in the messages instead.
Signed-off-by Jiri Pirko <[email protected]>--- net/sched/cls_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Quoted 14 lines
net/sched/cls_api.c int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, · line 675
Quoted 11 lines
net/sched/cls_api.c +1
-2@@ -672,8 +672,9 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,#ifdef CONFIG_NET_CLS_ACT reset:if (unlikely (limit++ >= max_reclassify_loop)) { - net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n", - tp->q->ops->id, tp->prio & 0xffff, + net_notice_ratelimited("%u: reclassify loop, rule prio %u, protocol %02x\n",if you are dumping index instead of prio shouldn't the 'rule prio' above be adjusted?
Quoted 6 lines
I'm not! Why do you think so?
"%u:" is
tp->chain->block->index
"prio %u" istp->prio&0xffff
"%02x" isntohs(tp->protocol)
Never mind. scanned that too quickly.
Jiri Pirko
maintainerPATCH v7 4/13 net: sched: introduce block mechanism to handle netif_keep_dst calls
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Couple of classifiers call netif_keep_dst directly on q->dev. That is not possible to do directly for shared blocke where multiple qdiscs are owning the block. So introduce a infrastructure to keep track of the block owners in list and use this list to implement block variant of netif_keep_dst.
---v3->v4:
- rebased on top of the current net-nextv1->v2:
- fix binder_type to check "egress" as well as pointed out by Daniel
--- include/net/pkt_cls.h | 1 + include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ net/sched/cls_bpf.c | 4 +-- net/sched/cls_flow.c | 2 +- net/sched/cls_route.c | 2 +- 6 files changed, 76 insertions(+), 4 deletions(-)
include/net/pkt_cls.h +1 -0
@@ -39,6 +39,7 @@ bool tcf_queue_work(struct work_struct *work);struct tcf_chain *tcf_chain_get (struct tcf_block *block,u32 chain_index,bool create);void tcf_chain_put (struct tcf_chain *chain); +void tcf_block_netif_keep_dst (struct tcf_block *block);int tcf_block_get (struct tcf_block **p_block,struct tcf_proto __rcu **p_filter_chain,struct Qdisc *q,struct netlink_ext_ack *extack);
include/net/sch_generic.h +2 -0
@@ -289,6 +289,8 @@ struct tcf_block {struct net *net;struct Qdisc *q;struct list_head cb_list; +struct list_head owner_list; +bool keep_dst; };static inline void qdisc_cb_private_validate (const struct sk_buff *skb,int sz)
net/sched/cls_api.c +69 -0
99 lines not on this page · raw message
net/sched/cls_bpf.c +2 -2
@@ -392,8 +392,8 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, prog->bpf_name = name; prog->filter = fp; -if (fp->dst_needed && !(tp->q->flags &TCQ_F_INGRESS )) -netif_keep_dst (qdisc_dev (tp->q)); +if (fp->dst_needed) +tcf_block_netif_keep_dst (tp->chain->block);return 0 ; }
net/sched/cls_flow.c +1 -1
@@ -526,7 +526,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,timer_setup (&fnew->perturb_timer, flow_perturbation,TIMER_DEFERRABLE ); -netif_keep_dst (qdisc_dev (tp->q)); +tcf_block_netif_keep_dst (tp->chain->block);if (tb[TCA_FLOW_KEYS ]) { fnew->keymask = keymask;
net/sched/cls_route.c +1 -1
@@ -527,7 +527,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,if (f->handle < f1->handle)break ; -netif_keep_dst (qdisc_dev (tp->q)); +tcf_block_netif_keep_dst (tp->chain->block);rcu_assign_pointer (f->next, f1);rcu_assign_pointer (*fp, f);
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 5/13 net: sched: remove classid and q fields from tcf_proto
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Both are no longer used, so remove them.
--- include/net/sch_generic.h | 2 -- net/sched/cls_api.c | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-)
include/net/sch_generic.h +0 -2
@@ -255,8 +255,6 @@ struct tcf_proto {/* All the rest */ u32 prio; -u32 classid; -struct Qdisc *q;void *data;const struct tcf_proto_ops *ops;struct tcf_chain *chain;
net/sched/cls_api.c +2 -5
@@ -122,8 +122,7 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp) }static struct tcf_proto *tcf_proto_create (const char *kind,u32 protocol, -u32 prio,u32 parent,struct Qdisc *q, -struct tcf_chain *chain) +u32 prio,struct tcf_chain *chain) {struct tcf_proto *tp;int err;
@@ -157,8 +156,6 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, tp->classify = tp->ops->classify; tp->protocol = protocol; tp->prio = prio; - tp->classid = parent; - tp->q = q; tp->chain = chain; err = tp->ops->init (tp);
@@ -1069,7 +1066,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, prio =tcf_auto_prio (tcf_chain_tp_prev (&chain_info)); tp =tcf_proto_create (nla_data (tca[TCA_KIND ]), - protocol, prio, parent, q, chain); + protocol, prio, chain);if (IS_ERR (tp)) { err =PTR_ERR (tp); goto errout;
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 6/13 net: sched: keep track of offloaded filters and check tc offload feature
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
During block bind, we need to check tc offload feature. If it is disabled yet still the block contains offloaded filters, forbid the bind. Also forbid to register callback for a block that already contains offloaded filters, as the play back is not supported now. For keeping track of offloaded filters there is a new counter introduced, alongside with couple of helpers called from cls_* code. These helpers set and clear TCA_CLS_FLAGS_IN_HW flag.
---v4->v5:
- add tracking of binding of devs that are unable to offload and check that before block cbs call.v3->v4:
- propagate netdev_ops->ndo_setup_tc error up to tcf_block_offload_bind callerv2->v3:
- new patch
--- include/net/sch_generic.h | 18 +++++++++++ net/sched/cls_api.c | 80 ++++++++++++++++++++++++++++++++++++++--------- net/sched/cls_bpf.c | 5 ++- net/sched/cls_flower.c | 3 +- net/sched/cls_matchall.c | 3 +- net/sched/cls_u32.c | 13 ++++---- 6 files changed, 99 insertions(+), 23 deletions(-)
include/net/sch_generic.h +18 -0
@@ -289,8 +289,26 @@ struct tcf_block {struct list_head cb_list;struct list_head owner_list;bool keep_dst; +unsigned int offloadcnt;/* Number of oddloaded filters */ +unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ }; +static inline void tcf_block_offload_inc (struct tcf_block *block,u32 *flags) +{ +if (*flags &TCA_CLS_FLAGS_IN_HW ) +return ; + *flags |=TCA_CLS_FLAGS_IN_HW ; + block->offloadcnt++; +} + +static inline void tcf_block_offload_dec (struct tcf_block *block,u32 *flags) +{ +if (!(*flags &TCA_CLS_FLAGS_IN_HW )) +return ; + *flags &= ~TCA_CLS_FLAGS_IN_HW ; + block->offloadcnt--; +} +static inline void qdisc_cb_private_validate (const struct sk_buff *skb,int sz) {struct qdisc_skb_cb *qcb;
net/sched/cls_api.c +66 -14
129 lines not on this page · raw message
net/sched/cls_bpf.c +4 -1
@@ -167,13 +167,16 @@ static int cls_bpf_offload_cmd(struct tcf_proto *tp, struct cls_bpf_prog *prog, cls_bpf.exts_integrated = obj->exts_integrated; cls_bpf.gen_flags = obj->gen_flags; +if (oldprog) +tcf_block_offload_dec (block, &oldprog->gen_flags); + err =tc_setup_cb_call (block,NULL ,TC_SETUP_CLSBPF , &cls_bpf, skip_sw);if (prog) {if (err <0 ) {cls_bpf_offload_cmd (tp, oldprog, prog);return err; }else if (err >0 ) { - prog->gen_flags |=TCA_CLS_FLAGS_IN_HW ; +tcf_block_offload_inc (block, &prog->gen_flags); } }
net/sched/cls_flower.c +2 -1
@@ -229,6 +229,7 @@ static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f)tc_setup_cb_call (block, &f->exts,TC_SETUP_CLSFLOWER , &cls_flower, false); +tcf_block_offload_dec (block, &f->flags); } static int fl_hw_replace_filter(struct tcf_proto *tp,
@@ -256,7 +257,7 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,fl_hw_destroy_filter (tp, f);return err; }else if (err >0 ) { - f->flags |=TCA_CLS_FLAGS_IN_HW ; +tcf_block_offload_inc (block, &f->flags); }if (skip_sw && !(f->flags &TCA_CLS_FLAGS_IN_HW ))
net/sched/cls_matchall.c +2 -1
@@ -81,6 +81,7 @@ static void mall_destroy_hw_filter(struct tcf_proto *tp, cls_mall.cookie = cookie;tc_setup_cb_call (block,NULL ,TC_SETUP_CLSMATCHALL , &cls_mall, false); +tcf_block_offload_dec (block, &head->flags); } static int mall_replace_hw_filter(struct tcf_proto *tp,
@@ -103,7 +104,7 @@ static int mall_replace_hw_filter(struct tcf_proto *tp,mall_destroy_hw_filter (tp, head, cookie);return err; }else if (err >0 ) { - head->flags |=TCA_CLS_FLAGS_IN_HW ; +tcf_block_offload_inc (block, &head->flags); }if (skip_sw && !(head->flags &TCA_CLS_FLAGS_IN_HW ))
net/sched/cls_u32.c +7 -6
@@ -529,16 +529,17 @@ static int u32_replace_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h,return 0 ; } -static void u32_remove_hw_knode (struct tcf_proto *tp,u32 handle) +static void u32_remove_hw_knode (struct tcf_proto *tp,struct tc_u_knode *n) {struct tcf_block *block = tp->chain->block;struct tc_cls_u32_offload cls_u32 = {};tc_cls_common_offload_init (&cls_u32.common, tp); cls_u32.command =TC_CLSU32_DELETE_KNODE ; - cls_u32.knode.handle = handle; + cls_u32.knode.handle = n->handle;tc_setup_cb_call (block,NULL ,TC_SETUP_CLSU32 , &cls_u32, false); +tcf_block_offload_dec (block, &n->flags); } static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
@@ -567,10 +568,10 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, err =tc_setup_cb_call (block,NULL ,TC_SETUP_CLSU32 , &cls_u32, skip_sw);if (err <0 ) { -u32_remove_hw_knode (tp, n->handle); +u32_remove_hw_knode (tp, n);return err; }else if (err >0 ) { - n->flags |=TCA_CLS_FLAGS_IN_HW ; +tcf_block_offload_inc (block, &n->flags); }if (skip_sw && !(n->flags &TCA_CLS_FLAGS_IN_HW ))
@@ -589,7 +590,7 @@ static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)RCU_INIT_POINTER (ht->ht[h],rtnl_dereference (n->next));tcf_unbind_filter (tp, &n->res); -u32_remove_hw_knode (tp, n->handle); +u32_remove_hw_knode (tp, n);idr_remove_ext (&ht->handle_idr, n->handle);if (tcf_exts_get_net (&n->exts))call_rcu (&n->rcu, u32_delete_key_freepf_rcu);
@@ -682,7 +683,7 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last) goto out;if (TC_U32_KEY (ht->handle)) { -u32_remove_hw_knode (tp, ht->handle); +u32_remove_hw_knode (tp, (struct tc_u_knode *)ht); ret =u32_delete_key (tp, (struct tc_u_knode *)ht); goto out; }
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 7/13 net: sched: use block index as a handle instead of qdisc when block is shared
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the tcm_ifindex 0 is invalid ifindex, reuse it to indicate that we work with block, instead of qdisc. So if tcm_ifindex is 0, tcm_parent is used to carry block_index.
If the block is set to be shared between at least 2 qdiscs, it is forbidden to use the qdisc handle to add/delete filters. In that case, userspace has to pass block_index.
Also, for dump of the filters, in case the block is shared in between at least 2 qdiscs, the each filter is dumped with tcm_ifindex 0 and tcm_parent set to block_index. That gives the user clear indication, that the filter belongs to a shared block and not only to one qdisc under which it is dumped.
---v6->v7:
- changed extack message for block index handle as suggested by DaveA
- added extack message when block index does not exist
- the block ifindex magic is in define and change to 0xffffffff as suggested by Jamalv5->v6:
- new patch
--- include/uapi/linux/rtnetlink.h | 6 ++ net/sched/cls_api.c | 202 ++++++++++++++++++++++++----------------- 2 files changed, 124 insertions(+), 84 deletions(-)
include/uapi/linux/rtnetlink.h +6 -0
@@ -541,9 +541,15 @@ struct tcmsg {int tcm_ifindex;__u32 tcm_handle;__u32 tcm_parent; +/* tcm_block_index is used instead of tcm_parent +* in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK +*/ +#define tcm_block_index tcm_parent__u32 tcm_info; }; +#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) +enum {TCA_UNSPEC ,TCA_KIND ,
net/sched/cls_api.c +118 -84
349 lines not on this page · raw message
Signature · 1 line
2.9.5
Re: [patch net-next v7 07/13] net: sched: use block index as a handle instead of qdisc when block is shared
Quoted 10 lines · Jiri Pirko
include/uapi/linux/rtnetlink.h +2
-0@@ -541,9 +541,15 @@ struct tcmsg {int tcm_ifindex;__u32 tcm_handle;__u32 tcm_parent; +/* tcm_block_index is used instead of tcm_parent +* in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK
include/uapi/linux/rtnetlink.h struct tcmsg { · line 555
Quoted 10 lines
include/uapi/linux/rtnetlink.h +4
-0+*/ +#define tcm_block_index tcm_parent__u32 tcm_info; }; +#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) +enum {TCA_UNSPEC ,TCA_KIND ,
This could be more clearly documented for anyone wanting to write an app against the API. Something like:
For shared blocks, tcm_ifindex is set to TCM_IFINDEX_MAGIC_BLOCK, and tcm_parent is aliased to tcm_block_index which is the block index.
Jiri Pirko
maintainerRe: [patch net-next v7 07/13] net: sched: use block index as a handle instead of qdisc when block is shared
Quoted 26 lines · Wed, Jan 10, 2018 at 07:12:44PM CET, [email protected] wrote:
Quoted 10 lines · Jiri Pirko
include/uapi/linux/rtnetlink.h +2
-0@@ -541,9 +541,15 @@ struct tcmsg {int tcm_ifindex;__u32 tcm_handle;__u32 tcm_parent; +/* tcm_block_index is used instead of tcm_parent +* in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK include/uapi/linux/rtnetlink.h struct tcmsg { · line 555
Quoted 10 lines
include/uapi/linux/rtnetlink.h +4
-0+*/ +#define tcm_block_index tcm_parent__u32 tcm_info; }; +#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) +enum {TCA_UNSPEC ,TCA_KIND ,This could be more clearly documented for anyone wanting to write an app against the API. Something like:
Quoted 2 lines
For shared blocks,
tcm_ifindexis set toTCM_IFINDEX_MAGIC_BLOCK, andtcm_parentis aliased totcm_block_indexwhich is the block index.
Okay, will add this comment here.
Jamal Hadi Salim
maintainerRe: [patch net-next v7 07/13] net: sched: use block index as a handle instead of qdisc when block is shared
In reply to Jiri PirkoQuoted 6 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As the
tcm_ifindex0 is invalid ifindex, reuse it to indicate that we work with block, instead of qdisc. So iftcm_ifindexis 0,tcm_parentis used to carryblock_index.
Commit log still refers to ifindex of 0 instead of TCM_IFINDEX_MAGIC_BLOCK
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 07/13] net: sched: use block index as a handle instead of qdisc when block is shared
Quoted 9 lines · Thu, Jan 11, 2018 at 02:25:36PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As the
tcm_ifindex0 is invalid ifindex, reuse it to indicate that we work with block, instead of qdisc. So iftcm_ifindexis 0,tcm_parentis used to carryblock_index.Commit log still refers to ifindex of 0 instead of
TCM_IFINDEX_MAGIC_BLOCK
Missed this. Will update, thanks!
Jiri Pirko
maintainerPATCH v7 8/13 net: sched: add rt netlink message type for block get
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add simple block get operation which primary purpose is to check the block existence by block index.
---v6->v7:
- new patch
--- include/uapi/linux/rtnetlink.h | 6 ++++ net/sched/cls_api.c | 64 ++++++++++++++++++++++++++++++++++++++++++ security/selinux/nlmsgtab.c | 5 +++- 3 files changed, 74 insertions(+), 1 deletion(-)
include/uapi/linux/rtnetlink.h +6 -0
@@ -150,6 +150,12 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT + RTM_NEWBLOCK = 100, +#define RTM_NEWBLOCK RTM_NEWBLOCK + RTM_DELBLOCK, +#define RTM_DELBLOCK RTM_DELBLOCK + RTM_GETBLOCK, +#define RTM_GETBLOCK RTM_GETBLOCK __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
net/sched/cls_api.c +64 -0
76 lines not on this page · raw message
security/selinux/nlmsgtab.c +4 -1
@@ -80,6 +80,9 @@ static const struct nlmsg_perm nlmsg_route_perms[] = { RTM_NEWSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWCACHEREPORT, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_NEWBLOCK, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_DELBLOCK, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_GETBLOCK, NETLINK_ROUTE_SOCKET__NLMSG_READ }, }; static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
@@ -159,7 +162,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)switch (sclass) {case SECCLASS_NETLINK_ROUTE_SOCKET :/* RTM_MAX always point to RTM_SETxxxx, ie RTM_NEWxxx + 3 */ -BUILD_BUG_ON (RTM_MAX != (RTM_NEWCACHEREPORT +3 )); +BUILD_BUG_ON (RTM_MAX != (RTM_NEWBLOCK +3 )); err =nlmsg_perm (nlmsg_type, perm, nlmsg_route_perms,sizeof (nlmsg_route_perms));break ;
Signature · 1 line
2.9.5
Re: [patch net-next v7 08/13] net: sched: add rt netlink message type for block get
Quoted 7 lines · Jiri Pirko
include/uapi/linux/rtnetlink.h +0
-0@@ -150,6 +150,12 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
include/uapi/linux/rtnetlink.h enum { · line 161
Quoted 10 lines
include/uapi/linux/rtnetlink.h +6
-0+ RTM_NEWBLOCK = 100, +#define RTM_NEWBLOCK RTM_NEWBLOCK + RTM_DELBLOCK, +#define RTM_DELBLOCK RTM_DELBLOCK + RTM_GETBLOCK, +#define RTM_GETBLOCK RTM_GETBLOCK __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
Seems like this is creating an inconsistency. RTM_GETBLOCK is used to dump the set of shared blocks, but RTM_NEWBLOCK / RTM_DELBLOCK are not used to create / delete one.
Jiri Pirko
maintainerRe: [patch net-next v7 08/13] net: sched: add rt netlink message type for block get
Quoted 9 lines · Wed, Jan 10, 2018 at 05:48:09PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
include/uapi/linux/rtnetlink.h +0
-0@@ -150,6 +150,12 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
Quoted 13 lines
include/uapi/linux/rtnetlink.h enum { · line 161
Quoted 9 lines
include/uapi/linux/rtnetlink.h +6
-0+ RTM_NEWBLOCK = 100, +#define RTM_NEWBLOCK RTM_NEWBLOCK + RTM_DELBLOCK, +#define RTM_DELBLOCK RTM_DELBLOCK + RTM_GETBLOCK, +#define RTM_GETBLOCK RTM_GETBLOCK __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };Seems like this is creating an inconsistency.
RTM_GETBLOCKis used to dump the set of shared blocks, butRTM_NEWBLOCK/RTM_DELBLOCKare not used to create / delete one.
Why is it a problem? RTM_NEWBLOCK is used as a reply for RTM_GETBLOCK. I plan to have block notifications as a follow-up, there the RTM_GETBLOCK and RTM_DELBLOCK will be used. The fact the user cannot create and delete block explicitly is no problem in my opinion. The block creation and deletion is done according to usage of qdiscs.
Jiri Pirko
maintainerRe: [patch net-next v7 08/13] net: sched: add rt netlink message type for block get
Quoted 24 lines · Thu, Jan 11, 2018 at 10:37:10AM CET, [email protected] wrote:
Quoted 9 lines · Wed, Jan 10, 2018 at 05:48:09PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
include/uapi/linux/rtnetlink.h +0
-0@@ -150,6 +150,12 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORTQuoted 13 lines
include/uapi/linux/rtnetlink.h enum { · line 161
Quoted 9 lines
include/uapi/linux/rtnetlink.h +6
-0+ RTM_NEWBLOCK = 100, +#define RTM_NEWBLOCK RTM_NEWBLOCK + RTM_DELBLOCK, +#define RTM_DELBLOCK RTM_DELBLOCK + RTM_GETBLOCK, +#define RTM_GETBLOCK RTM_GETBLOCK __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };Seems like this is creating an inconsistency.
RTM_GETBLOCKis used to dump the set of shared blocks, butRTM_NEWBLOCK/RTM_DELBLOCKare not used to create / delete one.
Quoted 2 lines
Why is it a problem?
RTM_NEWBLOCKis used as a reply forRTM_GETBLOCK. I plan to have block notifications as a follow-up, there theRTM_GETBLOCK
I mean RTM_NEWBLOCK and RTM_DELBLOCK of couse.
Quoted 3 lines
and
RTM_DELBLOCKwill be used. The fact the user cannot create and delete block explicitly is no problem in my opinion. The block creation and deletion is done according to usage of qdiscs.
Jamal Hadi Salim
maintainerRe: [patch net-next v7 08/13] net: sched: add rt netlink message type for block get
In reply to Jiri PirkoQuoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Add simple block get operation which primary purpose is to check the block existence by block index.
block_dump missing?
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 08/13] net: sched: add rt netlink message type for block get
Quoted 8 lines · Thu, Jan 11, 2018 at 02:27:11PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Add simple block get operation which primary purpose is to check the block existence by block index.
block_dumpmissing?
It is not needed for anything now. You see all the blocks when you list qdiscs. Yet, dump could be easily added if needed in the future.
Jiri Pirko
maintainerPATCH v7 9/13 net: sched: allow ingress and clsact qdiscs to share filter blocks
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
---v6->v7:
- adjust to the core changes and check block index attributes for being 0 v3->v4:
- rebased on top of the current net-nextv2->v3:
- removed "p_" prefix from block index function args
--- include/uapi/linux/pkt_sched.h | 11 +++++ net/sched/sch_ingress.c | 101 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_sched.h +11 -0
@@ -934,4 +934,15 @@ enum {#define TCA_CBS_MAX (__TCA_CBS_MAX - 1) +/* Ingress/clsact */ + +enum { +TCA_CLSACT_UNSPEC , +TCA_CLSACT_INGRESS_BLOCK , +TCA_CLSACT_EGRESS_BLOCK , + __TCA_CLSACT_MAX +}; + +#define TCA_CLSACT_MAX (__TCA_CLSACT_MAX - 1) +#endif
net/sched/sch_ingress.c +100 -1
148 lines not on this page · raw message
Signature · 1 line
2.9.5
Jamal Hadi Salim
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Will check again later after some coffee..
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 9 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Quoted 4 lines
Will check again later after some coffee..
cheers,
jamal
Jamal Hadi Salim
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 8 lines · Jiri Pirko
Quoted 7 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Quoted 7 lines
Quoted 2 lines
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 12 lines · Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 11 lines · Jiri Pirko
Quoted 9 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Quoted 7 lines
Quoted 4 lines
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?
Please see the iproute2 patches. Parsing of "block" command line option is done inside q_ingress.c
Jamal Hadi Salim
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 18 lines · Jiri Pirko
Quoted 17 lines · Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 15 lines · Jiri Pirko
Quoted 9 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Quoted 6 lines
Quoted 2 lines
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?Please see the iproute2 patches. Parsing of "block" command line option is done inside
q_ingress.c
I only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 22 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
Quoted 7 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Quoted 7 lines
Quoted 2 lines
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?
Quoted 7 lines
Quoted 3 lines
Please see the iproute2 patches. Parsing of "block" command line option is done inside
q_ingress.cI only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in net/sched/sch_ingress.c - there is where the parsing of block attr takes place.
Quoted 4 lines
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
I was thinking to take this direction originally. To have another generic attr called TCA_BLOCK or something that would be used when qdisc is created. For ingress, what would work. But for clsact, you need to be able to specify 2 block during qdisc creation - one for ingress, one for egress. That's when I realized this has to be per-qdisc-type attr.
Re: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 41 lines · Jiri Pirko
Quoted 22 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
Quoted 7 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Quoted 7 lines
Quoted 2 lines
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?Quoted 7 lines
Quoted 3 lines
Please see the iproute2 patches. Parsing of "block" command line option is done inside
q_ingress.cI only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in
net/sched/sch_ingress.c- there is where the parsing of block attr takes place.Quoted 4 lines
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
Quoted 5 lines
I was thinking to take this direction originally. To have another generic attr called
TCA_BLOCKor something that would be used when qdisc is created. For ingress, what would work. But for clsact, you need to be able to specify 2 block during qdisc creation - one for ingress, one for egress. That's when I realized this has to be per-qdisc-type attr.
yeah, see the problem...but.., would it help if we just introduce two generic attrs TCA_BLOCK_INGRESS and TCA_BLOCK_EGRESS instead of having to duplicate these attrs at every qdisc ?.
and add proper validation depending on qdisc type..
Jiri Pirko
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 49 lines · Thu, Jan 11, 2018 at 04:41:27PM CET, [email protected] wrote:
Quoted 41 lines · Jiri Pirko
Quoted 22 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
Quoted 7 lines · Thu, Jan 11, 2018 at 02:36:01PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Benefit from the previously introduced shared filter blocks infrastructure and allow ingress and clsact qdisc instances to share filter blocks. The block index is coming from userspace as qdisc option.
Quoted 7 lines
Quoted 2 lines
Didnt quiet follow why ingress is special and needs attributes to set the block but other qdiscs didnt.
Jamal, again, other qdiscs does not support block sharing. This patchset only adds support for sharing of block for ingress and clsact qdiscs. Later on, other qdiscs could also support block sharing.
Can you stop a config which says:
tc qdisc add dev ens9 root block 22 handle 1:0 prio ?Quoted 7 lines
Quoted 3 lines
Please see the iproute2 patches. Parsing of "block" command line option is done inside
q_ingress.cI only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in
net/sched/sch_ingress.c- there is where the parsing of block attr takes place.Quoted 4 lines
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
Quoted 5 lines
I was thinking to take this direction originally. To have another generic attr called
TCA_BLOCKor something that would be used when qdisc is created. For ingress, what would work. But for clsact, you need to be able to specify 2 block during qdisc creation - one for ingress, one for egress. That's when I realized this has to be per-qdisc-type attr.
Quoted 4 lines
yeah, see the problem...but.., would it help if we just introduce two generic attrs
TCA_BLOCK_INGRESSandTCA_BLOCK_EGRESSinstead of having to duplicate these attrs at every qdisc ?.
and add proper validation depending on qdisc type..
I guess it would make sense. I just did not want to introduce this limitation. But allright. Will do this.
Jamal Hadi Salim
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
In reply to Jiri PirkoQuoted 5 lines · Jiri Pirko
Quoted 4 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 8 lines
Quoted 3 lines
I only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in
net/sched/sch_ingress.c- there is where the parsing of block attr takes place.
reason i raised it is from looking at tc_ctl_tfilter(). If i specify ifindex != TCM_IFINDEX_MAGIC_BLOCK, parent = 0XFFFF.... and block = 22 that should work, no? i.e regardless of whether parent is INGRESS etc.
And so i was confused why you had attributes in sch_ingress.c
Quoted 6 lines
Quoted 5 lines
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
Quoted 6 lines
I was thinking to take this direction originally. To have another generic attr called
TCA_BLOCKor something that would be used when qdisc is created. For ingress, what would work. But for clsact, you need to be able to specify 2 block during qdisc creation - one for ingress, one for egress. That's when I realized this has to be per-qdisc-type attr.
ok for clsact - i can see that we dont have enough fields in the tcm message.
TCA_BLOCK sounds appealing - could be a speacial tlv with many block ids maybe? I really would like to use this for egress as well - and what i described earlier should work for me.
cheers,
jamal
Jiri Pirko
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 15 lines · Thu, Jan 11, 2018 at 04:44:32PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
Quoted 4 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
Quoted 8 lines
Quoted 3 lines
I only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in
net/sched/sch_ingress.c- there is where the parsing of block attr takes place.
Quoted 4 lines
reason i raised it is from looking at
tc_ctl_tfilter(). If i specify ifindex !=TCM_IFINDEX_MAGIC_BLOCK, parent =0XFFFF.... and block = 22 that should work, no? i.e regardless of whether parent is INGRESS etc.
No, the block needs to be created first by qdisc instance. Seems to me that you are mixing apples and oranges a bit.
Quoted 16 lines
And so i was confused why you had attributes in
sch_ingress.cQuoted 6 lines
Quoted 5 lines
Really - there is no reason for this API to be only via ingress qdisc attributes. You can add a check in cls api to reject any parent that is not either of the clsacts + ingress (depending on tc doesnt sound right).
Quoted 6 lines
I was thinking to take this direction originally. To have another generic attr called
TCA_BLOCKor something that would be used when qdisc is created. For ingress, what would work. But for clsact, you need to be able to specify 2 block during qdisc creation - one for ingress, one for egress. That's when I realized this has to be per-qdisc-type attr.
Quoted 2 lines
ok for clsact - i can see that we dont have enough fields in the tcm message.
That is not a problem. Again, don't mix filter manipulation with qdisc manipulation.
Quoted 4 lines
TCA_BLOCKsounds appealing - could be a speacial tlv with many block ids maybe? I really would like to use this for egress as well - and what i described earlier should work for me.
I don't get what you mean by "tlv with many block ids". What is it good for? :O
Quoted 3 lines
cheers,
jamal
Jamal Hadi Salim
maintainerRe: [patch net-next v7 09/13] net: sched: allow ingress and clsact qdiscs to share filter blocks
Quoted 16 lines · Jiri Pirko
Quoted 15 lines · Thu, Jan 11, 2018 at 04:44:32PM CET, [email protected] wrote:
Quoted 13 lines · Jiri Pirko
Quoted 7 lines · Thu, Jan 11, 2018 at 03:46:09PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Thu, Jan 11, 2018 at 03:37:08PM CET, [email protected] wrote:
I only looked at the kernel code. Good you can stop it at tc but the API does not stop it (unless you expect the rest of the world to only use tc).
Jamal, apparently, you did not looked at the kernel code either :) Look at the changes done in
net/sched/sch_ingress.c- there is where the parsing of block attr takes place.
Quoted 8 lines
Quoted 4 lines
reason i raised it is from looking at
tc_ctl_tfilter(). If i specify ifindex !=TCM_IFINDEX_MAGIC_BLOCK, parent =0XFFFF.... and block = 22 that should work, no? i.e regardless of whether parent is INGRESS etc.No, the block needs to be created first by qdisc instance. Seems to me that you are mixing apples and oranges a bit.
You are correct, the qdisc attachment must exist first ;->
Quoted 7 lines
Quoted 3 lines
TCA_BLOCKsounds appealing - could be a speacial tlv with many block ids maybe? I really would like to use this for egress as well - and what i described earlier should work for me.I don't get what you mean by "tlv with many block ids". What is it good for? :O
I meant A TLV with a bunch of 32 bit values, so you can have more than one block id in it. But what Roopa suggested is more explicit (and better).
cheers,
jamal
Jiri Pirko
maintainerPATCH v7 10/13 mlxsw: spectrum_acl: Reshuffle code around mlxsw_sp_acl_ruleset_create/destroy
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In order to prepare for follow-up changes, make the bind/unbind helpers very simple. That required move of ht insertion/removal and bind/unbind calls into mlxsw_sp_acl_ruleset_create/destroy.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 102 ++++++++++----------- 1 file changed, 46 insertions(+), 56 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +46 -56
@@ -118,8 +118,26 @@ struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp)return mlxsw_sp->acl->dummy_fid; } +static int mlxsw_sp_acl_ruleset_bind (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_ruleset *ruleset, +struct net_device *dev,bool ingress) +{ +const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; + +return ops->ruleset_bind (mlxsw_sp, ruleset->priv, dev, ingress); +} + +static void mlxsw_sp_acl_ruleset_unbind (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_ruleset *ruleset) +{ +const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; + + ops->ruleset_unbind (mlxsw_sp, ruleset->priv); +} +static struct mlxsw_sp_acl_ruleset * -mlxsw_sp_acl_ruleset_create (struct mlxsw_sp *mlxsw_sp, +mlxsw_sp_acl_ruleset_create (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, +bool ingress,u32 chain_index,const struct mlxsw_sp_acl_profile_ops *ops) {struct mlxsw_sp_acl *acl = mlxsw_sp->acl;
@@ -132,6 +150,9 @@ mlxsw_sp_acl_ruleset_create(struct mlxsw_sp *mlxsw_sp,if (!ruleset)return ERR_PTR (-ENOMEM ); ruleset->ref_count =1 ; + ruleset->ht_key.dev = dev; + ruleset->ht_key.ingress = ingress; + ruleset->ht_key.chain_index = chain_index; ruleset->ht_key.ops = ops; err =rhashtable_init (&ruleset->rule_ht, &mlxsw_sp_acl_rule_ht_params);
@@ -142,68 +163,49 @@ mlxsw_sp_acl_ruleset_create(struct mlxsw_sp *mlxsw_sp,if (err) goto err_ops_ruleset_add; -return ruleset; - -err_ops_ruleset_add: -rhashtable_destroy (&ruleset->rule_ht); -err_rhashtable_init: -kfree (ruleset); -return ERR_PTR (err); -} - -static void mlxsw_sp_acl_ruleset_destroy (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_ruleset *ruleset) -{ -const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; - - ops->ruleset_del (mlxsw_sp, ruleset->priv); -rhashtable_destroy (&ruleset->rule_ht); -kfree (ruleset); -} - -static int mlxsw_sp_acl_ruleset_bind (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_ruleset *ruleset, -struct net_device *dev,bool ingress, -u32 chain_index) -{ -const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; -struct mlxsw_sp_acl *acl = mlxsw_sp->acl; -int err; - - ruleset->ht_key.dev = dev; - ruleset->ht_key.ingress = ingress; - ruleset->ht_key.chain_index = chain_index; err =rhashtable_insert_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params);if (err) -return err; -if (!ruleset->ht_key.chain_index) { + goto err_ht_insert; + +if (!chain_index) {/* We only need ruleset with chain index 0, the implicit one, * to be directly bound to device. The rest of the rulesets * are bound by "Goto action set". */ - err = ops->ruleset_bind (mlxsw_sp, ruleset->priv, dev, ingress); + err =mlxsw_sp_acl_ruleset_bind (mlxsw_sp, ruleset, + dev, ingress);if (err) - goto err_ops_ruleset_bind; + goto err_ruleset_bind; } -return 0 ; -err_ops_ruleset_bind: +return ruleset; + +err_ruleset_bind:rhashtable_remove_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params); -return err; +err_ht_insert: + ops->ruleset_del (mlxsw_sp, ruleset->priv); +err_ops_ruleset_add: +rhashtable_destroy (&ruleset->rule_ht); +err_rhashtable_init: +kfree (ruleset); +return ERR_PTR (err); } -static void mlxsw_sp_acl_ruleset_unbind (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_ruleset *ruleset) +static void mlxsw_sp_acl_ruleset_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_ruleset *ruleset) {const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops;struct mlxsw_sp_acl *acl = mlxsw_sp->acl;if (!ruleset->ht_key.chain_index) - ops->ruleset_unbind (mlxsw_sp, ruleset->priv); +mlxsw_sp_acl_ruleset_unbind (mlxsw_sp, ruleset);rhashtable_remove_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params); + ops->ruleset_del (mlxsw_sp, ruleset->priv); +rhashtable_destroy (&ruleset->rule_ht); +kfree (ruleset); }static void mlxsw_sp_acl_ruleset_ref_inc (struct mlxsw_sp_acl_ruleset *ruleset)
@@ -216,7 +218,6 @@ static void mlxsw_sp_acl_ruleset_ref_dec(struct mlxsw_sp *mlxsw_sp, {if (--ruleset->ref_count)return ; -mlxsw_sp_acl_ruleset_unbind (mlxsw_sp, ruleset);mlxsw_sp_acl_ruleset_destroy (mlxsw_sp, ruleset); }
@@ -263,7 +264,6 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, struct net_device *dev,const struct mlxsw_sp_acl_profile_ops *ops;struct mlxsw_sp_acl *acl = mlxsw_sp->acl;struct mlxsw_sp_acl_ruleset *ruleset; -int err; ops = acl->ops->profile_ops (mlxsw_sp, profile);if (!ops)
@@ -275,18 +275,8 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, struct net_device *dev,mlxsw_sp_acl_ruleset_ref_inc (ruleset);return ruleset; } - ruleset =mlxsw_sp_acl_ruleset_create (mlxsw_sp, ops); -if (IS_ERR (ruleset)) -return ruleset; - err =mlxsw_sp_acl_ruleset_bind (mlxsw_sp, ruleset, dev, - ingress, chain_index); -if (err) - goto err_ruleset_bind; -return ruleset; - -err_ruleset_bind: -mlxsw_sp_acl_ruleset_destroy (mlxsw_sp, ruleset); -return ERR_PTR (err); +return mlxsw_sp_acl_ruleset_create (mlxsw_sp, dev, ingress, + chain_index, ops); } void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 11/13 mlxsw: spectrum_acl: Don't store netdev and ingress for ruleset unbind
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Instead, pass netdev and ingress flag to ruleset unbind op.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 3 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 9 ++++-- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 33 +++++++++++----------- 3 files changed, 24 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -1
@@ -477,7 +477,8 @@ struct mlxsw_sp_acl_profile_ops {void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv);int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv,struct net_device *dev,bool ingress); -void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv); +void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv, +struct net_device *dev,bool ingress);u16 (*ruleset_group_id)(void *ruleset_priv);size_t rule_priv_size; int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +6 -3
@@ -128,11 +128,12 @@ static int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp, }static void mlxsw_sp_acl_ruleset_unbind (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_ruleset *ruleset) +struct mlxsw_sp_acl_ruleset *ruleset, +struct net_device *dev,bool ingress) {const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; - ops->ruleset_unbind (mlxsw_sp, ruleset->priv); + ops->ruleset_unbind (mlxsw_sp, ruleset->priv, dev, ingress); } static struct mlxsw_sp_acl_ruleset *
@@ -200,7 +201,9 @@ static void mlxsw_sp_acl_ruleset_destroy(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl *acl = mlxsw_sp->acl;if (!ruleset->ht_key.chain_index) -mlxsw_sp_acl_ruleset_unbind (mlxsw_sp, ruleset); +mlxsw_sp_acl_ruleset_unbind (mlxsw_sp, ruleset, + ruleset->ht_key.dev, + ruleset->ht_key.ingress);rhashtable_remove_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params); ops->ruleset_del (mlxsw_sp, ruleset->priv);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +16 -17
@@ -154,10 +154,6 @@ struct mlxsw_sp_acl_tcam_group {struct list_head region_list;unsigned int region_count;struct rhashtable chunk_ht; -struct { -u16 local_port; -bool ingress; - } bound;struct mlxsw_sp_acl_tcam_group_ops *ops;const struct mlxsw_sp_acl_tcam_pattern *patterns;unsigned int patterns_count;
@@ -271,26 +267,28 @@ mlxsw_sp_acl_tcam_group_bind(struct mlxsw_sp *mlxsw_sp,return -EINVAL ; mlxsw_sp_port =netdev_priv (dev); - group->bound.local_port = mlxsw_sp_port->local_port; - group->bound.ingress = ingress; -mlxsw_reg_ppbt_pack (ppbt_pl, - group->bound.ingress ?MLXSW_REG_PXBT_E_IACL : -MLXSW_REG_PXBT_E_EACL , -MLXSW_REG_PXBT_OP_BIND , group->bound.local_port, +mlxsw_reg_ppbt_pack (ppbt_pl, ingress ?MLXSW_REG_PXBT_E_IACL : +MLXSW_REG_PXBT_E_EACL , +MLXSW_REG_PXBT_OP_BIND , mlxsw_sp_port->local_port, group->id);return mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (ppbt), ppbt_pl); }static void mlxsw_sp_acl_tcam_group_unbind (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_group *group) +struct mlxsw_sp_acl_tcam_group *group, +struct net_device *dev,bool ingress) { +struct mlxsw_sp_port *mlxsw_sp_port;char ppbt_pl[MLXSW_REG_PPBT_LEN ]; -mlxsw_reg_ppbt_pack (ppbt_pl, - group->bound.ingress ?MLXSW_REG_PXBT_E_IACL : -MLXSW_REG_PXBT_E_EACL , -MLXSW_REG_PXBT_OP_UNBIND , group->bound.local_port, +if (WARN_ON (!mlxsw_sp_port_dev_check (dev))) +return ; + + mlxsw_sp_port =netdev_priv (dev); +mlxsw_reg_ppbt_pack (ppbt_pl, ingress ?MLXSW_REG_PXBT_E_IACL : +MLXSW_REG_PXBT_E_EACL , +MLXSW_REG_PXBT_OP_UNBIND , mlxsw_sp_port->local_port, group->id);mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (ppbt), ppbt_pl); }
@@ -1066,11 +1064,12 @@ mlxsw_sp_acl_tcam_flower_ruleset_bind(struct mlxsw_sp *mlxsw_sp,static void mlxsw_sp_acl_tcam_flower_ruleset_unbind (struct mlxsw_sp *mlxsw_sp, -void *ruleset_priv) +void *ruleset_priv, +struct net_device *dev,bool ingress) {struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv; -mlxsw_sp_acl_tcam_group_unbind (mlxsw_sp, &ruleset->group); +mlxsw_sp_acl_tcam_group_unbind (mlxsw_sp, &ruleset->group, dev, ingress); } static u16
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 12/13 mlxsw: spectrum_acl: Implement TC block sharing
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Benefit from the prepared TC and in-driver ACL infrastructure and introduce block sharing offload. For that, a new struct "block" is introduced in spectrum_acl in order to hold a list of specific block-port bindings.
---v2->v3:
- add tc offload feature handlingv1->v2:
- new patch
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 182 +++++++++++++--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 37 +++- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 237 ++++++++++++++++++--- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 41 ++-- 4 files changed, 401 insertions(+), 96 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +152 -30
@@ -1747,72 +1747,186 @@ static int mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port, }static int -mlxsw_sp_setup_tc_cls_flower (struct mlxsw_sp_port *mlxsw_sp_port, -struct tc_cls_flower_offload *f, -bool ingress) +mlxsw_sp_setup_tc_cls_flower (struct mlxsw_sp_acl_block *acl_block, +struct tc_cls_flower_offload *f) { +struct mlxsw_sp *mlxsw_sp =mlxsw_sp_acl_block_mlxsw_sp (acl_block); +switch (f->command) {case TC_CLSFLOWER_REPLACE : -return mlxsw_sp_flower_replace (mlxsw_sp_port, ingress, f); +return mlxsw_sp_flower_replace (mlxsw_sp, acl_block, f);case TC_CLSFLOWER_DESTROY : -mlxsw_sp_flower_destroy (mlxsw_sp_port, ingress, f); +mlxsw_sp_flower_destroy (mlxsw_sp, acl_block, f);return 0 ;case TC_CLSFLOWER_STATS : -return mlxsw_sp_flower_stats (mlxsw_sp_port, ingress, f); +return mlxsw_sp_flower_stats (mlxsw_sp, acl_block, f);default :return -EOPNOTSUPP ; } } -static int mlxsw_sp_setup_tc_block_cb (enum tc_setup_type type,void *type_data, -void *cb_priv,bool ingress) +static int mlxsw_sp_setup_tc_block_cb_matchall (enum tc_setup_type type, +void *type_data, +void *cb_priv,bool ingress) {struct mlxsw_sp_port *mlxsw_sp_port = cb_priv; -if (!tc_can_offload (mlxsw_sp_port->dev)) -return -EOPNOTSUPP ; -switch (type) {case TC_SETUP_CLSMATCHALL : +if (!tc_can_offload (mlxsw_sp_port->dev)) +return -EOPNOTSUPP ; +return mlxsw_sp_setup_tc_cls_matchall (mlxsw_sp_port, type_data, ingress);case TC_SETUP_CLSFLOWER : -return mlxsw_sp_setup_tc_cls_flower (mlxsw_sp_port, type_data, - ingress); +return 0 ;default :return -EOPNOTSUPP ; } } -static int mlxsw_sp_setup_tc_block_cb_ig (enum tc_setup_type type, -void *type_data,void *cb_priv) +static int mlxsw_sp_setup_tc_block_cb_matchall_ig (enum tc_setup_type type, +void *type_data, +void *cb_priv) { -return mlxsw_sp_setup_tc_block_cb (type, type_data, cb_priv, true); +return mlxsw_sp_setup_tc_block_cb_matchall (type, type_data, + cb_priv, true); } -static int mlxsw_sp_setup_tc_block_cb_eg (enum tc_setup_type type, -void *type_data,void *cb_priv) +static int mlxsw_sp_setup_tc_block_cb_matchall_eg (enum tc_setup_type type, +void *type_data, +void *cb_priv) { -return mlxsw_sp_setup_tc_block_cb (type, type_data, cb_priv, false); +return mlxsw_sp_setup_tc_block_cb_matchall (type, type_data, + cb_priv, false); +} + +static int mlxsw_sp_setup_tc_block_cb_flower (enum tc_setup_type type, +void *type_data,void *cb_priv) +{ +struct mlxsw_sp_acl_block *acl_block = cb_priv; + +switch (type) { +case TC_SETUP_CLSMATCHALL : +return 0 ; +case TC_SETUP_CLSFLOWER : +if (mlxsw_sp_acl_block_disabled (acl_block)) +return -EOPNOTSUPP ; + +return mlxsw_sp_setup_tc_cls_flower (acl_block, type_data); +default : +return -EOPNOTSUPP ; + } +} + +static int +mlxsw_sp_setup_tc_block_flower_bind (struct mlxsw_sp_port *mlxsw_sp_port, +struct tcf_block *block,bool ingress) +{ +struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; +struct mlxsw_sp_acl_block *acl_block; +struct tcf_block_cb *block_cb; +int err; + + block_cb =tcf_block_cb_lookup (block, mlxsw_sp_setup_tc_block_cb_flower, + mlxsw_sp); +if (!block_cb) { + acl_block =mlxsw_sp_acl_block_create (mlxsw_sp, block->net); +if (!acl_block) +return -ENOMEM ; + block_cb =__tcf_block_cb_register (block, + mlxsw_sp_setup_tc_block_cb_flower, + mlxsw_sp, acl_block); +if (IS_ERR (block_cb)) { + err =PTR_ERR (block_cb); + goto err_cb_register; + } + }else { + acl_block =tcf_block_cb_priv (block_cb); + } +tcf_block_cb_incref (block_cb); + err =mlxsw_sp_acl_block_bind (mlxsw_sp, acl_block, + mlxsw_sp_port, ingress); +if (err) + goto err_block_bind; + +if (ingress) + mlxsw_sp_port->ing_acl_block = acl_block; +else + mlxsw_sp_port->eg_acl_block = acl_block; + +return 0 ; + +err_block_bind: +if (!tcf_block_cb_decref (block_cb)) { +__tcf_block_cb_unregister (block_cb); +err_cb_register: +mlxsw_sp_acl_block_destroy (acl_block); + } +return err; +} + +static void +mlxsw_sp_setup_tc_block_flower_unbind (struct mlxsw_sp_port *mlxsw_sp_port, +struct tcf_block *block,bool ingress) +{ +struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; +struct mlxsw_sp_acl_block *acl_block; +struct tcf_block_cb *block_cb; +int err; + + block_cb =tcf_block_cb_lookup (block, mlxsw_sp_setup_tc_block_cb_flower, + mlxsw_sp); +if (!block_cb) +return ; + +if (ingress) + mlxsw_sp_port->ing_acl_block =NULL ; +else + mlxsw_sp_port->eg_acl_block =NULL ; + + acl_block =tcf_block_cb_priv (block_cb); + err =mlxsw_sp_acl_block_unbind (mlxsw_sp, acl_block, + mlxsw_sp_port, ingress); +if (!err && !tcf_block_cb_decref (block_cb)) { +__tcf_block_cb_unregister (block_cb); +mlxsw_sp_acl_block_destroy (acl_block); + } }static int mlxsw_sp_setup_tc_block (struct mlxsw_sp_port *mlxsw_sp_port,struct tc_block_offload *f) {tc_setup_cb_t *cb; +bool ingress; +int err; -if (f->binder_type ==TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) - cb = mlxsw_sp_setup_tc_block_cb_ig; -else if (f->binder_type ==TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS ) - cb = mlxsw_sp_setup_tc_block_cb_eg; -else +if (f->binder_type ==TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) { + cb = mlxsw_sp_setup_tc_block_cb_matchall_ig; + ingress = true; + }else if (f->binder_type ==TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS ) { + cb = mlxsw_sp_setup_tc_block_cb_matchall_eg; + ingress = false; + }else {return -EOPNOTSUPP ; + }switch (f->command) {case TC_BLOCK_BIND : -return tcf_block_cb_register (f->block, cb, mlxsw_sp_port, - mlxsw_sp_port); + err =tcf_block_cb_register (f->block, cb, mlxsw_sp_port, + mlxsw_sp_port); +if (err) +return err; + err =mlxsw_sp_setup_tc_block_flower_bind (mlxsw_sp_port, + f->block, ingress); +if (err) { +tcf_block_cb_unregister (f->block, cb, mlxsw_sp_port); +return err; + } +return 0 ;case TC_BLOCK_UNBIND : +mlxsw_sp_setup_tc_block_flower_unbind (mlxsw_sp_port, + f->block, ingress);tcf_block_cb_unregister (f->block, cb, mlxsw_sp_port);return 0 ;default :
@@ -1840,10 +1954,18 @@ static int mlxsw_sp_feature_hw_tc(struct net_device *dev, bool enable) {struct mlxsw_sp_port *mlxsw_sp_port =netdev_priv (dev); -if (!enable && (mlxsw_sp_port->acl_rule_count || - !list_empty (&mlxsw_sp_port->mall_tc_list))) { -netdev_err (dev,"Active offloaded tc filters, can't turn hw_tc_offload off\n" ); -return -EINVAL ; +if (!enable) { +if (mlxsw_sp_acl_block_rule_count (mlxsw_sp_port->ing_acl_block) || +mlxsw_sp_acl_block_rule_count (mlxsw_sp_port->eg_acl_block) || + !list_empty (&mlxsw_sp_port->mall_tc_list)) { +netdev_err (dev,"Active offloaded tc filters, can't turn hw_tc_offload off\n" ); +return -EINVAL ; + } +mlxsw_sp_acl_block_disable_inc (mlxsw_sp_port->ing_acl_block); +mlxsw_sp_acl_block_disable_inc (mlxsw_sp_port->eg_acl_block); + }else { +mlxsw_sp_acl_block_disable_dec (mlxsw_sp_port->ing_acl_block); +mlxsw_sp_acl_block_disable_dec (mlxsw_sp_port->eg_acl_block); }return 0 ; }
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +29 -8
@@ -270,7 +270,8 @@ struct mlxsw_sp_port {struct mlxsw_sp_port_sample *sample;struct list_head vlans_list;struct mlxsw_sp_qdisc root_qdisc; -unsigned acl_rule_count; +struct mlxsw_sp_acl_block *ing_acl_block; +struct mlxsw_sp_acl_block *eg_acl_block; }; static inline bool
@@ -498,17 +499,34 @@ struct mlxsw_sp_acl_ops { enum mlxsw_sp_acl_profile profile); }; +struct mlxsw_sp_acl_block ;struct mlxsw_sp_acl_ruleset ;/* spectrum_acl.c */ struct mlxsw_afk *mlxsw_sp_acl_afk (struct mlxsw_sp_acl *acl); +struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp (struct mlxsw_sp_acl_block *block); +unsigned int mlxsw_sp_acl_block_rule_count (struct mlxsw_sp_acl_block *block); +void mlxsw_sp_acl_block_disable_inc (struct mlxsw_sp_acl_block *block); +void mlxsw_sp_acl_block_disable_dec (struct mlxsw_sp_acl_block *block); +bool mlxsw_sp_acl_block_disabled (struct mlxsw_sp_acl_block *block); +struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create (struct mlxsw_sp *mlxsw_sp, +struct net *net); +void mlxsw_sp_acl_block_destroy (struct mlxsw_sp_acl_block *block); +int mlxsw_sp_acl_block_bind (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block, +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress); +int mlxsw_sp_acl_block_unbind (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block, +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress);struct mlxsw_sp_acl_ruleset * -mlxsw_sp_acl_ruleset_lookup (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, -bool ingress,u32 chain_index, +mlxsw_sp_acl_ruleset_lookup (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block,u32 chain_index,enum mlxsw_sp_acl_profile profile);struct mlxsw_sp_acl_ruleset * -mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, -bool ingress,u32 chain_index, +mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block,u32 chain_index,enum mlxsw_sp_acl_profile profile);void mlxsw_sp_acl_ruleset_put (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_ruleset *ruleset);
@@ -575,11 +593,14 @@ void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);extern const struct mlxsw_sp_acl_ops mlxsw_sp_acl_tcam_ops;/* spectrum_flower.c */ -int mlxsw_sp_flower_replace (struct mlxsw_sp_port *mlxsw_sp_port,bool ingress, +int mlxsw_sp_flower_replace (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block,struct tc_cls_flower_offload *f); -void mlxsw_sp_flower_destroy (struct mlxsw_sp_port *mlxsw_sp_port,bool ingress, +void mlxsw_sp_flower_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block,struct tc_cls_flower_offload *f); -int mlxsw_sp_flower_stats (struct mlxsw_sp_port *mlxsw_sp_port,bool ingress, +int mlxsw_sp_flower_stats (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_block *block,struct tc_cls_flower_offload *f);/* spectrum_qdisc.c */
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +203 -34
338 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +17 -24
125 lines not on this page · raw message
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 13/13 mlxsw: spectrum_acl: Pass mlxsw_sp_port down to ruleset bind/unbind ops
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
No need to convert from mlxsw_sp_port to net_device and back again.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 6 +++-- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 4 ++-- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 27 +++++++++------------- 3 files changed, 17 insertions(+), 20 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +4 -2
@@ -477,9 +477,11 @@ struct mlxsw_sp_acl_profile_ops { void *priv, void *ruleset_priv);void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv);int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv, -struct net_device *dev,bool ingress); +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress);void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv, -struct net_device *dev,bool ingress); +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress);u16 (*ruleset_group_id)(void *ruleset_priv);size_t rule_priv_size; int (*rule_add)(struct mlxsw_sp *mlxsw_sp,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +2 -2
@@ -169,7 +169,7 @@ mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops;return ops->ruleset_bind (mlxsw_sp, ruleset->priv, - binding->mlxsw_sp_port->dev, binding->ingress); + binding->mlxsw_sp_port, binding->ingress); } static void
@@ -181,7 +181,7 @@ mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; ops->ruleset_unbind (mlxsw_sp, ruleset->priv, - binding->mlxsw_sp_port->dev, binding->ingress); + binding->mlxsw_sp_port, binding->ingress); }static bool mlxsw_sp_acl_ruleset_block_bound (struct mlxsw_sp_acl_block *block)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +11 -16
@@ -258,15 +258,11 @@ static void mlxsw_sp_acl_tcam_group_del(struct mlxsw_sp *mlxsw_sp,static int mlxsw_sp_acl_tcam_group_bind (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_group *group, -struct net_device *dev,bool ingress) +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress) { -struct mlxsw_sp_port *mlxsw_sp_port;char ppbt_pl[MLXSW_REG_PPBT_LEN ]; -if (!mlxsw_sp_port_dev_check (dev)) -return -EINVAL ; - - mlxsw_sp_port =netdev_priv (dev); mlxsw_reg_ppbt_pack(ppbt_pl, ingress ? MLXSW_REG_PXBT_E_IACL : MLXSW_REG_PXBT_E_EACL, MLXSW_REG_PXBT_OP_BIND, mlxsw_sp_port->local_port,
@@ -277,15 +273,11 @@ mlxsw_sp_acl_tcam_group_bind(struct mlxsw_sp *mlxsw_sp,static void mlxsw_sp_acl_tcam_group_unbind (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_group *group, -struct net_device *dev,bool ingress) +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress) { -struct mlxsw_sp_port *mlxsw_sp_port;char ppbt_pl[MLXSW_REG_PPBT_LEN ]; -if (WARN_ON (!mlxsw_sp_port_dev_check (dev))) -return ; - - mlxsw_sp_port =netdev_priv (dev); mlxsw_reg_ppbt_pack(ppbt_pl, ingress ? MLXSW_REG_PXBT_E_IACL : MLXSW_REG_PXBT_E_EACL, MLXSW_REG_PXBT_OP_UNBIND, mlxsw_sp_port->local_port,
@@ -1054,22 +1046,25 @@ mlxsw_sp_acl_tcam_flower_ruleset_del(struct mlxsw_sp *mlxsw_sp,static int mlxsw_sp_acl_tcam_flower_ruleset_bind (struct mlxsw_sp *mlxsw_sp,void *ruleset_priv, -struct net_device *dev,bool ingress) +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress) {struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;return mlxsw_sp_acl_tcam_group_bind (mlxsw_sp, &ruleset->group, - dev, ingress); + mlxsw_sp_port, ingress); }static void mlxsw_sp_acl_tcam_flower_ruleset_unbind (struct mlxsw_sp *mlxsw_sp,void *ruleset_priv, -struct net_device *dev,bool ingress) +struct mlxsw_sp_port *mlxsw_sp_port, +bool ingress) {struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv; -mlxsw_sp_acl_tcam_group_unbind (mlxsw_sp, &ruleset->group, dev, ingress); +mlxsw_sp_acl_tcam_group_unbind (mlxsw_sp, &ruleset->group, + mlxsw_sp_port, ingress); } static u16
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 1/3 include: update rtnetlink header according to kernel
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
--- include/uapi/linux/rtnetlink.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/uapi/linux/rtnetlink.h +12 -0
@@ -150,6 +150,12 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT + RTM_NEWBLOCK = 100, +#define RTM_NEWBLOCK RTM_NEWBLOCK + RTM_DELBLOCK, +#define RTM_DELBLOCK RTM_DELBLOCK + RTM_GETBLOCK, +#define RTM_GETBLOCK RTM_GETBLOCK __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
@@ -541,9 +547,15 @@ struct tcmsg {int tcm_ifindex;__u32 tcm_handle;__u32 tcm_parent; +/* tcm_block_index is used instead of tcm_parent +* in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK +*/ +#define tcm_block_index tcm_parent__u32 tcm_info; }; +#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) +enum {TCA_UNSPEC ,TCA_KIND ,
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 2/3 tc: introduce support for block-handle for filter operations
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
--- tc/tc_filter.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 17 deletions(-)
tc/tc_filter.c +110 -17
@@ -28,14 +28,17 @@static void usage (void ) {fprintf (stderr, -"Usage: tc filter [ add | del | change | replace | show ] dev STRING\n" -"Usage: tc filter get dev STRING parent CLASSID protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n" +"Usage: tc filter [ add | del | change | replace | show ] [ dev STRING ]\n" +" tc filter [ add | del | change | replace | show ] [ block BLOCK_INDEX ]\n" +" tc filter get dev STRING parent CLASSID protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n" +" tc filter get block BLOCK_INDEX protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n" " [ pref PRIO ] protocol PROTO [ chain CHAIN_INDEX ]\n" " [ estimator INTERVAL TIME_CONSTANT ]\n" " [ root | ingress | egress | parent CLASSID ]\n" " [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n" "\n" " tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ]\n" +" tc filter show [ block BLOCK_INDEX ]\n" "Where:\n" "FILTER_TYPE := { rsvp | u32 | bpf | fw | route | etc. }\n" "FILTERID := ... format depends on classifier, see there\n"
@@ -60,6 +63,7 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)int protocol_set =0 ;__u32 chain_index;int chain_index_set =0 ; +__u32 block_index =0 ;char *fhandle =NULL ;char d[IFNAMSIZ ] = {};char k[FILTER_NAMESZ ] = {};
@@ -73,7 +77,21 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)NEXT_ARG ();if (d[0 ])duparg ("dev" , *argv); +if (block_index) { +fprintf (stderr,"Error: \"dev\" cannot be used in the same time as \"block\"\n" ); +return -1 ; + }strncpy (d, *argv,sizeof (d)-1 ); + }else if (matches (*argv,"block" ) ==0 ) { +NEXT_ARG (); +if (block_index) +duparg ("block" , *argv); +if (d[0 ]) { +fprintf (stderr,"Error: \"block\" cannot be used in the same time as \"dev\"\n" ); +return -1 ; + } +if (get_u32 (&block_index, *argv,0 ) || !block_index) +invarg ("invalid block index value" , *argv); }else if (strcmp (*argv,"root" ) ==0 ) {if (req.t.tcm_parent) { fprintf(stderr,
@@ -168,6 +186,9 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)fprintf (stderr,"Cannot find device \"%s\"\n" , d);return 1 ; } + }else if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; }if (q) {
@@ -206,6 +227,7 @@ static __u32 filter_prio;static __u32 filter_protocol;static __u32 filter_chain_index;static int filter_chain_index_set; +static __u32 filter_block_index;__u16 f_proto;int print_filter (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg)
@@ -252,20 +274,27 @@ int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)print_bool (PRINT_ANY ,"added" ,"added " , true);print_string (PRINT_FP ,NULL ,"filter " ,NULL ); -if (!filter_ifindex || filter_ifindex != t->tcm_ifindex) -print_string (PRINT_ANY ,"dev" ,"dev %s " , -ll_index_to_name (t->tcm_ifindex)); - -if (!filter_parent || filter_parent != t->tcm_parent) { -if (t->tcm_parent ==TC_H_ROOT ) -print_bool (PRINT_ANY ,"root" ,"root " , true); -else if (t->tcm_parent ==TC_H_MAKE (TC_H_CLSACT ,TC_H_MIN_INGRESS )) -print_bool (PRINT_ANY ,"ingress" ,"ingress " , true); -else if (t->tcm_parent ==TC_H_MAKE (TC_H_CLSACT ,TC_H_MIN_EGRESS )) -print_bool (PRINT_ANY ,"egress" ,"egress " , true); -else { -print_tc_classid (abuf,sizeof (abuf), t->tcm_parent); -print_string (PRINT_ANY ,"parent" ,"parent %s " , abuf); +if (t->tcm_ifindex ==TCM_IFINDEX_MAGIC_BLOCK ) { +if (!filter_block_index || + filter_block_index != t->tcm_block_index) +print_uint (PRINT_ANY ,"block" ,"block %u " , + t->tcm_block_index); + }else { +if (!filter_ifindex || filter_ifindex != t->tcm_ifindex) +print_string (PRINT_ANY ,"dev" ,"dev %s " , +ll_index_to_name (t->tcm_ifindex)); + +if (!filter_parent || filter_parent != t->tcm_parent) { +if (t->tcm_parent ==TC_H_ROOT ) +print_bool (PRINT_ANY ,"root" ,"root " , true); +else if (t->tcm_parent ==TC_H_MAKE (TC_H_CLSACT ,TC_H_MIN_INGRESS )) +print_bool (PRINT_ANY ,"ingress" ,"ingress " , true); +else if (t->tcm_parent ==TC_H_MAKE (TC_H_CLSACT ,TC_H_MIN_EGRESS )) +print_bool (PRINT_ANY ,"egress" ,"egress " , true); +else { +print_tc_classid (abuf,sizeof (abuf), t->tcm_parent); +print_string (PRINT_ANY ,"parent" ,"parent %s " , abuf); + } } }
@@ -345,6 +374,7 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)int protocol_set =0 ;__u32 chain_index;int chain_index_set =0 ; +__u32 block_index =0 ;__u32 parent_handle =0 ;char *fhandle =NULL ;char d[IFNAMSIZ ] = {};
@@ -355,7 +385,21 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)NEXT_ARG ();if (d[0 ])duparg ("dev" , *argv); +if (block_index) { +fprintf (stderr,"Error: \"dev\" cannot be used in the same time as \"block\"\n" ); +return -1 ; + }strncpy (d, *argv,sizeof (d)-1 ); + }else if (matches (*argv,"block" ) ==0 ) { +NEXT_ARG (); +if (block_index) +duparg ("block" , *argv); +if (d[0 ]) { +fprintf (stderr,"Error: \"block\" cannot be used in the same time as \"dev\"\n" ); +return -1 ; + } +if (get_u32 (&block_index, *argv,0 ) || !block_index) +invarg ("invalid block index value" , *argv); }else if (strcmp (*argv,"root" ) ==0 ) {if (req.t.tcm_parent) { fprintf(stderr,
@@ -469,8 +513,12 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)return 1 ; } filter_ifindex = req.t.tcm_ifindex; + }else if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; }else { -fprintf (stderr,"Must specify netdevice \"dev\"\n" ); +fprintf (stderr,"Must specify netdevice \"dev\" or block index \"block\"\n" );return -1 ; }
@@ -504,6 +552,30 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)return 0 ; } +static bool block_index_exists (__u32 block_index) +{ +struct { +struct nlmsghdr n; +struct tcmsg t; + } req = { + .n.nlmsg_len =NLMSG_LENGTH (sizeof (struct tcmsg )), + .n.nlmsg_flags =NLM_F_REQUEST , + .n.nlmsg_type =RTM_GETBLOCK , + .t.tcm_parent =TC_H_UNSPEC , + .t.tcm_family =AF_UNSPEC , + }; +struct nlmsghdr *answer; + + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + +if (rtnl_talk (&rth, &req.n, &answer) <0 ) +return false; + +free (answer); +return true; +} +static int tc_filter_list (int argc,char **argv) {struct {
@@ -520,6 +592,7 @@ static int tc_filter_list(int argc, char **argv)__u32 prio =0 ;__u32 protocol =0 ;__u32 chain_index; +__u32 block_index =0 ;char *fhandle =NULL ;while (argc >0 ) {
@@ -527,7 +600,21 @@ static int tc_filter_list(int argc, char **argv)NEXT_ARG ();if (d[0 ])duparg ("dev" , *argv); +if (block_index) { +fprintf (stderr,"Error: \"dev\" cannot be used in the same time as \"block\"\n" ); +return -1 ; + }strncpy (d, *argv,sizeof (d)-1 ); + }else if (matches (*argv,"block" ) ==0 ) { +NEXT_ARG (); +if (block_index) +duparg ("block" , *argv); +if (d[0 ]) { +fprintf (stderr,"Error: \"block\" cannot be used in the same time as \"dev\"\n" ); +return -1 ; + } +if (get_u32 (&block_index, *argv,0 ) || !block_index) +invarg ("invalid block index value" , *argv); }else if (strcmp (*argv,"root" ) ==0 ) {if (req.t.tcm_parent) { fprintf(stderr,
@@ -616,6 +703,12 @@ static int tc_filter_list(int argc, char **argv)return 1 ; } filter_ifindex = req.t.tcm_ifindex; + }else if (block_index) { +if (!block_index_exists (block_index)) +return 1 ; + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; }if (filter_chain_index_set)
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH v7 3/3 tc: implement filter block sharing to ingress and clsact qdiscs
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
--- include/uapi/linux/pkt_sched.h | 11 +++++++++ tc/q_clsact.c | 52 ++++++++++++++++++++++++++++++++++++++---- tc/q_ingress.c | 30 +++++++++++++++++++++--- 3 files changed, 85 insertions(+), 8 deletions(-)
include/uapi/linux/pkt_sched.h +11 -0
@@ -934,4 +934,15 @@ enum {#define TCA_CBS_MAX (__TCA_CBS_MAX - 1) +/* Ingress/clsact */ + +enum { +TCA_CLSACT_UNSPEC , +TCA_CLSACT_INGRESS_BLOCK , +TCA_CLSACT_EGRESS_BLOCK , + __TCA_CLSACT_MAX +}; + +#define TCA_CLSACT_MAX (__TCA_CLSACT_MAX - 1) +#endif
tc/q_clsact.c +47 -5
70 lines not on this page · raw message
tc/q_ingress.c +27 -3
@@ -17,30 +17,54 @@static void explain (void ) { -fprintf (stderr,"Usage: ... ingress\n" ); +fprintf (stderr,"Usage: ... ingress [block BLOCK_INDEX]\n" ); }static int ingress_parse_opt (struct qdisc_util *qu,int argc,char **argv,struct nlmsghdr *n,const char *dev) { +struct rtattr *tail; +__u32 block_index =0 ; +while (argc >0 ) {if (strcmp (*argv,"handle" ) ==0 ) {NEXT_ARG (); - argc--; argv++; + }else if (strcmp (*argv,"block" ) ==0 ) { +NEXT_ARG (); +if (get_u32 (&block_index, *argv,0 ) || !block_index) +invarg ("invalid block index value" , *argv); }else {fprintf (stderr,"What is \"%s\"?\n" , *argv);explain ();return -1 ; } +NEXT_ARG_FWD (); } + tail =NLMSG_TAIL (n); +addattr_l (n,1024 ,TCA_OPTIONS ,NULL ,0 ); +if (block_index) +addattr32 (n,1024 ,TCA_CLSACT_INGRESS_BLOCK , block_index); + tail->rta_len = (void *)NLMSG_TAIL (n) - (void *) tail;return 0 ; }static int ingress_print_opt (struct qdisc_util *qu,FILE *f,struct rtattr *opt) { -fprintf (f,"---------------- " ); +struct rtattr *tb[TCA_CLSACT_MAX +1 ]; +__u32 block_index; + +if (!opt) +return 0 ; + +parse_rtattr_nested (tb,TCA_CLSACT_MAX , opt); + +if (tb[TCA_CLSACT_INGRESS_BLOCK ] && +RTA_PAYLOAD (tb[TCA_CLSACT_INGRESS_BLOCK ]) >=sizeof (__u32)) { + block_index =rta_getattr_u32 (tb[TCA_CLSACT_INGRESS_BLOCK ]); +print_uint (PRINT_ANY ,"block" ,"block %u " , block_index); + }return 0 ; }
Signature · 1 line
2.9.5
Jamal Hadi Salim
maintainerQuoted 61 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the filters added to qdiscs are independent. So for example if you have 2 netdevices and you create ingress qdisc on both and you want to add identical filter rules both, you need to add them twice. This patchset makes this easier and mainly saves resources allowing to share all filters within a qdisc - I call it a "filter block". Also this helps to save resources when we do offload to hw for example to expensive TCAM.
So back to the example. First, we create 2 qdiscs. Both will share block number 22. "22" is just an identification:
$ tc qdisc add dev ens7 ingress block 22 ^^^^^^^^ $ tc qdisc add dev ens8 ingress block 22 ^^^^^^^^If we don't specify "block" command line option, no shared block would be created:
$ tc qdisc add dev ens9 ingressNow if we list the qdiscs, we will see the block index in the output:
$ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1To make is more visual, the situation looks like this:
ens7 ingress qdisc ens7 ingress qdisc
| |
| |
+----------> block 22 <----------+Unlimited number of qdiscs may share the same block.
Now we can add filter using the block index:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action dropNote we cannot use the qdisc for filter manipulations of shared blocks:
$ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters.We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22:
$ tc filter show block 22 filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...$ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
Quoted 5 lines
$ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
Somewhere here mention the egress issue we talked about, something like:
----
At the moment on ingress and clsact_xxx are well supported by the block infrastructure. For this to work well with egress qdisc, all the ports/qdiscs sharing the block will have to be symmetric. e.g. if ens8 and ens9 root qdiscs shared a block at their (egress) root qdiscs, then those qdiscs would both need to have the same handle id. An example of a symettric shared block setup would like like:
tc qdisc add dev ens8 root block 22 handle 1:0 prio tc qdisc add dev ens9 root block 22 handle 1:0 prio
----
I am confident the above would work. You said you are thinking of getting this to always work (I cant think of a simple way to do it), but for the moment the above is fine.
Most people who want this would probably use clsact egress and not care about queues (so it may never be "fixed")
cheers,
jamal
Jiri Pirko
maintainerQuoted 62 lines · Thu, Jan 11, 2018 at 02:19:16PM CET, [email protected] wrote:
Quoted 61 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Currently the filters added to qdiscs are independent. So for example if you have 2 netdevices and you create ingress qdisc on both and you want to add identical filter rules both, you need to add them twice. This patchset makes this easier and mainly saves resources allowing to share all filters within a qdisc - I call it a "filter block". Also this helps to save resources when we do offload to hw for example to expensive TCAM.
So back to the example. First, we create 2 qdiscs. Both will share block number 22. "22" is just an identification:
$ tc qdisc add dev ens7 ingress block 22 ^^^^^^^^ $ tc qdisc add dev ens8 ingress block 22 ^^^^^^^^If we don't specify "block" command line option, no shared block would be created:
$ tc qdisc add dev ens9 ingressNow if we list the qdiscs, we will see the block index in the output:
$ tc qdisc qdisc ingress ffff: dev ens7 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens8 parent ffff:fff1 block 22 qdisc ingress ffff: dev ens9 parent ffff:fff1To make is more visual, the situation looks like this:
ens7 ingress qdisc ens7 ingress qdisc
| |
| |
+----------> block 22 <----------+Unlimited number of qdiscs may share the same block.
Now we can add filter using the block index:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 action dropNote we cannot use the qdisc for filter manipulations of shared blocks:
$ tc filter add dev ens8 ingress protocol ip pref 1 flower dst_ip 192.168.100.2 action drop Error: This filter block is shared. Please use the block index to manipulate the filters.We will see the same output if we list filters for ingress qdisc of ens7 and ens8, also for the block 22:
$ tc filter show block 22 filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...$ tc filter show dev ens7 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...
Quoted 8 lines
Quoted 5 lines
$ tc filter show dev ens8 ingress filter block 22 protocol ip pref 25 flower chain 0 filter block 22 protocol ip pref 25 flower chain 0 handle 0x1 ...Somewhere here mention the egress issue we talked about, something like:
I don't understand why to mention something that is not supported and future thinking and work needs to be done in order to support it. Let's leave that text for a cover letter of that patchset, could we?
Quoted 20 lines
----
At the moment on ingress andclsact_xxxare well supported by the block infrastructure. For this to work well with egress qdisc, all the ports/qdiscs sharing the block will have to be symmetric. e.g. if ens8 and ens9 root qdiscs shared a block at their (egress) root qdiscs, then those qdiscs would both need to have the same handle id. An example of a symettric shared block setup would like like:tc qdisc add dev ens8 root block 22 handle 1:0 prio tc qdisc add dev ens9 root block 22 handle 1:0 prio
----I am confident the above would work. You said you are thinking of getting this to always work (I cant think of a simple way to do it), but for the moment the above is fine.
Most people who want this would probably use clsact egress and not care about queues (so it may never be "fixed")cheers,
jamal