net: sched: allow qdiscs to share filter block instances
Subsystems (5)
Jiri Pirko
maintainercover 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. If we don't pass any block number, a new one will be generated by kernel:
$ tc qdisc add dev ens7 ingress block 22
^^^^^^^^
$ tc qdisc add dev ens8 ingress block 22
^^^^^^^^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
Now we can add filter to any of qdiscs sharing the same block:
$ tc filter add dev ens7 ingress protocol ip pref 25 flower dst_ip 192.168.0.0/16 action drop
We will see the same output if we list filters for ens7 and ens8, including stats:
$ tc -s filter show dev ens7 ingress
filter protocol ip pref 25 flower chain 0
filter protocol ip pref 25 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 192.168.0.0/16
not_in_hw
action order 1: gact action drop
random type none pass val 0
index 1 ref 1 bind 1 installed 39 sec used 2 sec
Action statistics:
Sent 3108 bytes 37 pkt (dropped 37, overlimits 0 requeues 0)
backlog 0b 0p requeues 0$ tc -s filter show dev ens8 ingress
filter protocol ip pref 25 flower chain 0
filter protocol ip pref 25 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 192.168.0.0/16
not_in_hw
action order 1: gact action drop
random type none pass val 0
index 1 ref 1 bind 1 installed 40 sec used 3 sec
Action statistics:
Sent 3108 bytes 37 pkt (dropped 37, overlimits 0 requeues 0)
backlog 0b 0p requeues 0Jiri Pirko (5):
net: sched: introduce support for multiple filter chain pointers
registration
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: allow ingress and clsact qdiscs to share filter blocks
include/net/pkt_cls.h | 4 + include/net/sch_generic.h | 9 +- include/uapi/linux/pkt_sched.h | 11 ++ net/sched/cls_api.c | 327 +++++++++++++++++++++++++++++++++++------ net/sched/cls_bpf.c | 4 +- net/sched/cls_flow.c | 2 +- net/sched/cls_route.c | 2 +- net/sched/sch_ingress.c | 89 ++++++++++- 8 files changed, 397 insertions(+), 51 deletions(-)
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH 1/5 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.
--- include/net/pkt_cls.h | 3 + include/net/sch_generic.h | 5 +- net/sched/cls_api.c | 247 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 218 insertions(+), 37 deletions(-)
include/net/pkt_cls.h +3 -0
@@ -28,6 +28,8 @@ 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; +bool shareable; +u32 block_index; };struct tcf_block_cb ;
@@ -47,6 +49,7 @@ void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,static inline struct Qdisc *tcf_block_q (struct tcf_block *block) { +WARN_ON (block->refcnt !=1 );return block->q; }
include/net/sch_generic.h +3 -2
@@ -264,8 +264,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 */
@@ -274,6 +273,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 +212 -35
323 lines not on this page · raw message
Signature · 1 line
2.9.5
Jiri Pirko
maintainerPATCH 2/5 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
@@ -670,8 +670,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
Jiri Pirko
maintainerPATCH 3/5 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.
--- include/net/pkt_cls.h | 1 + include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ net/sched/cls_bpf.c | 4 +-- net/sched/cls_flow.c | 2 +- net/sched/cls_route.c | 2 +- 6 files changed, 75 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); int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
include/net/sch_generic.h +2 -0
@@ -278,6 +278,8 @@ struct tcf_block {struct net *net;struct Qdisc *q;struct list_head cb_list; +struct list_head owner_list; +bool keep_dst;struct work_struct work; };
net/sched/cls_api.c +68 -0
98 lines not on this page · raw message
net/sched/cls_bpf.c +2 -2
@@ -398,8 +398,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
@@ -520,7 +520,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
@@ -517,7 +517,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
Daniel Borkmann
maintainerRe: [patch net-next 3/5] net: sched: introduce block mechanism to handle netif_keep_dst calls
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Couple of classifiers call
netif_keep_dstdirectly onq->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 ofnetif_keep_dst.Signed-off-by Jiri Pirko <[email protected]>
[...]
net/sched/cls_api.c static struct tcf_chain *tcf_block_chain_zero(struct tcf_block *block) · line 441
Quoted 13 lines
net/sched/cls_api.c +13
-0+struct tcf_block_owner_item { +struct list_head list; +struct Qdisc *q; +enum tcf_block_binder_type binder_type; +}; + +static void +tcf_block_owner_netif_keep_dst (struct tcf_block *block, +struct Qdisc *q, +enum tcf_block_binder_type binder_type) +{ +if (block->keep_dst && + binder_type !=TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS )
Why we need to keep dst on TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS ? I presume this enum means sch_handle_egress() ? dst is dropped later ...
Quoted 9 lines
net/sched/cls_api.c +9
-0+netif_keep_dst (qdisc_dev (q)); +} + +void tcf_block_netif_keep_dst (struct tcf_block *block) +{ +struct tcf_block_owner_item *item; + + block->keep_dst = true; +list_for_each_entry (item, &block->owner_list, list)
Jiri Pirko
maintainerRe: [patch net-next 3/5] net: sched: introduce block mechanism to handle netif_keep_dst calls
Quoted 20 lines · Fri, Nov 03, 2017 at 09:15:54PM CET, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Couple of classifiers call
netif_keep_dstdirectly onq->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 ofnetif_keep_dst.Signed-off-by Jiri Pirko <[email protected]>[...]
Quoted 9 lines
net/sched/cls_api.c +9
-0+struct tcf_block_owner_item { +struct list_head list; +struct Qdisc *q; +enum tcf_block_binder_type binder_type; +}; + +static void +tcf_block_owner_netif_keep_dst(struct tcf_block *block, + struct Qdisc *q,
Quoted 8 lines
net/sched/cls_api.c static struct tcf_chain *tcf_block_chain_zero(struct tcf_block *block) · line 441
Quoted 4 lines
net/sched/cls_api.c +4
-0+ enum tcf_block_binder_type binder_type) +{ +if (block->keep_dst && + binder_type !=TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS )Why we need to keep dst on
TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS? I presume this enum meanssch_handle_egress()? dst is dropped later ...
This is because of the bpf check:
if (fp->dst_needed && !(tp->q->flags & TCQ_F_INGRESS))
netif_keep_dst(qdisc_dev(tp->q));I just maintain the same logic here.
Daniel Borkmann
maintainerRe: [patch net-next 3/5] net: sched: introduce block mechanism to handle netif_keep_dst calls
Quoted 30 lines · Jiri Pirko
Quoted 20 lines · Fri, Nov 03, 2017 at 09:15:54PM CET, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Couple of classifiers call
netif_keep_dstdirectly onq->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 ofnetif_keep_dst.Signed-off-by Jiri Pirko <[email protected]>[...]
Quoted 9 lines
net/sched/cls_api.c +9
-0+struct tcf_block_owner_item { +struct list_head list; +struct Qdisc *q; +enum tcf_block_binder_type binder_type; +}; + +static void +tcf_block_owner_netif_keep_dst(struct tcf_block *block, + struct Qdisc *q,Quoted 8 lines
net/sched/cls_api.c static struct tcf_chain *tcf_block_chain_zero(struct tcf_block *block) · line 441
Quoted 4 lines
net/sched/cls_api.c +4
-0+ enum tcf_block_binder_type binder_type) +{ +if (block->keep_dst && + binder_type !=TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS )Why we need to keep dst on
TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS? I presume this enum meanssch_handle_egress()? dst is dropped later ...
Quoted 5 lines
This is because of the bpf check:
if (fp->dst_needed && !(tp->q->flags & TCQ_F_INGRESS)) netif_keep_dst(qdisc_dev(tp->q));I just maintain the same logic here.
No, that's a wrong claim, really ...
clsact in general hooks into the same logic as ingress, so TC_H_CLSACT as major needs to reuse TC_H_INGRESS, and qdiscs set up as such set TCQ_F_INGRESS as flags. For clsact that means both your block binder types for clsact here (ingress/egress).
Please make sure that your other changes don't have similar assumption.
Jiri Pirko
maintainerRe: [patch net-next 3/5] net: sched: introduce block mechanism to handle netif_keep_dst calls
Quoted 35 lines · Sat, Nov 04, 2017 at 11:33:58AM CET, [email protected] wrote:
Quoted 34 lines · Jiri Pirko
Quoted 20 lines · Fri, Nov 03, 2017 at 09:15:54PM CET, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Couple of classifiers call
netif_keep_dstdirectly onq->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 ofnetif_keep_dst.Signed-off-by Jiri Pirko <[email protected]>[...]
Quoted 9 lines
net/sched/cls_api.c +9
-0+struct tcf_block_owner_item { +struct list_head list; +struct Qdisc *q; +enum tcf_block_binder_type binder_type; +}; + +static void +tcf_block_owner_netif_keep_dst(struct tcf_block *block, + struct Qdisc *q,Quoted 8 lines
net/sched/cls_api.c static struct tcf_chain *tcf_block_chain_zero(struct tcf_block *block) · line 441
Quoted 4 lines
net/sched/cls_api.c +4
-0+ enum tcf_block_binder_type binder_type) +{ +if (block->keep_dst && + binder_type !=TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS )Why we need to keep dst on
TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS? I presume this enum meanssch_handle_egress()? dst is dropped later ...This is because of the bpf check:
if (fp->dst_needed && !(tp->q->flags & TCQ_F_INGRESS)) netif_keep_dst(qdisc_dev(tp->q));
Quoted 8 lines
Quoted 1 line
I just maintain the same logic here.
No, that's a wrong claim, really ...
clsact in general hooks into the same logic as ingress, so
TC_H_CLSACTas major needs to reuseTC_H_INGRESS, and qdiscs set up as such setTCQ_F_INGRESSas flags. For clsact that means both your block binder types for clsact here (ingress/egress).
Ah, indeed, I missed this. I will rename TCQ_F_INGRESS to TCQ_F_CLSACT as a part of this patchset too.
Quoted 2 lines
Please make sure that your other changes don't have similar assumption.
They don't. Thanks for the review!
Daniel Borkmann
maintainerRe: [patch net-next 3/5] net: sched: introduce block mechanism to handle netif_keep_dst calls
On 11/04/2017 02:01 PM, Jiri Pirko wrote:
[...]
Quoted 2 lines
Ah, indeed, I missed this. I will rename
TCQ_F_INGRESStoTCQ_F_CLSACTas a part of this patchset too.
Sounds reasonable, thanks!
Jiri Pirko
maintainerPATCH 4/5 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
@@ -244,8 +244,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
@@ -123,8 +123,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;
@@ -158,8 +157,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);
@@ -1066,7 +1063,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 5/5 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.
--- include/uapi/linux/pkt_sched.h | 11 ++++++ net/sched/sch_ingress.c | 89 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_sched.h +11 -0
@@ -923,4 +923,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 +88 -1
142 lines not on this page · raw message
Signature · 1 line
2.9.5