net: sched: couple of adjustments/fixes
Subsystems (3)
Jiri Pirko
maintainercover net: sched: couple of adjustments/fixes
From: Jiri Pirko <[email protected]>
Jiri Pirko (2):
net: sched: change name of zombie chain to "held_by_acts_only"
net: sched: fix notifications for action-held chains
net/sched/cls_api.c | 84 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 36 deletions(-)
Signature · 1 line
2.14.4
Jiri Pirko
maintainerPATCH 1/2 net: sched: change name of zombie chain to "held_by_acts_only"
From: Jiri Pirko <[email protected]>
As mentioned by Cong and Jakub during the review process, it is a bit odd to sometimes (act flow) create a new chain which would be immediately a "zombie". So just rename it to "held_by_acts_only".
--- net/sched/cls_api.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
net/sched/cls_api.c +6 -8
@@ -272,11 +272,10 @@ static void tcf_chain_release_by_act(struct tcf_chain *chain) --chain->action_refcnt; } -static bool tcf_chain_is_zombie (struct tcf_chain *chain) +static bool tcf_chain_held_by_acts_only (struct tcf_chain *chain) {/* In case all the references are action references, this -* chain is a zombie and should not be listed in the chain -* dump list. +* chain should not be shown to the user. */ return chain->refcnt == chain->action_refcnt; }
@@ -1838,10 +1837,9 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n, chain =tcf_chain_lookup (block, chain_index);if (n->nlmsg_type ==RTM_NEWCHAIN ) {if (chain) { -if (tcf_chain_is_zombie (chain)) { +if (tcf_chain_held_by_acts_only (chain)) {/* The chain exists only because there is -* some action referencing it, meaning it -* is a zombie. +* some action referencing it. */ tcf_chain_hold (chain); }else {
@@ -1860,7 +1858,7 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n, } } }else { -if (!chain ||tcf_chain_is_zombie (chain)) { +if (!chain ||tcf_chain_held_by_acts_only (chain)) {NL_SET_ERR_MSG (extack,"Cannot find specified filter chain" );return -EINVAL ; }
@@ -1988,7 +1986,7 @@ static int tc_dump_chain(struct sk_buff *skb, struct netlink_callback *cb) index++;continue ; } -if (tcf_chain_is_zombie (chain)) +if (tcf_chain_held_by_acts_only (chain))continue ; err = tc_chain_fill_node(chain, net, skb, block, NETLINK_CB(cb->skb).portid,
Signature · 1 line
2.14.4
Re: [patch net-next 1/2] net: sched: change name of zombie chain to "held_by_acts_only"
Quoted 10 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As mentioned by Cong and Jakub during the review process, it is a bit odd to sometimes (act flow) create a new chain which would be immediately a "zombie". So just rename it to "
held_by_acts_only".Signed-off-by Jiri Pirko <[email protected]>Suggested-by Cong Wang <[email protected]>Suggested-by Jakub Kicinski <[email protected]>
Thanks for the update!
Jiri Pirko
maintainerPATCH 2/2 net: sched: fix notifications for action-held chains
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Chains that only have action references serve as placeholders. Until a non-action reference is created, user should not be aware of the chain. Also he should not receive any notifications about it. So send notifications for the new chain only in case the chain gets the first non-action reference. Symmetrically to that, when the last non-action reference is dropped, send the notification about deleted chain.
--- net/sched/cls_api.c | 70 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 28 deletions(-)
net/sched/cls_api.c +42 -28
@@ -262,16 +262,6 @@ static void tcf_chain_hold(struct tcf_chain *chain) ++chain->refcnt; } -static void tcf_chain_hold_by_act (struct tcf_chain *chain) -{ - ++chain->action_refcnt; -} - -static void tcf_chain_release_by_act (struct tcf_chain *chain) -{ - --chain->action_refcnt; -} -static bool tcf_chain_held_by_acts_only (struct tcf_chain *chain) {/* In case all the references are action references, this
@@ -295,52 +285,76 @@ static struct tcf_chain *tcf_chain_lookup(struct tcf_block *block,static int tc_chain_notify (struct tcf_chain *chain,struct sk_buff *oskb,u32 seq,u16 flags,int event,bool unicast); -struct tcf_chain *tcf_chain_get (struct tcf_block *block,u32 chain_index, -bool create) +struct tcf_chain *__tcf_chain_get (struct tcf_block *block,u32 chain_index, +bool create,bool by_act) {struct tcf_chain *chain =tcf_chain_lookup (block, chain_index);if (chain) {tcf_chain_hold (chain); -return chain; + }else { +if (!create) +return NULL ; + chain =tcf_chain_create (block, chain_index); +if (!chain) +return NULL ; } -if (!create) -return NULL ; - chain =tcf_chain_create (block, chain_index); -if (!chain) -return NULL ; -tc_chain_notify (chain,NULL ,0 ,NLM_F_CREATE |NLM_F_EXCL , -RTM_NEWCHAIN , false); +if (by_act) + ++chain->action_refcnt; + +/* Send notification only in case we got the first +* non-action reference. Until then, the chain acts only as +* a placeholder for actions pointing to it and user ought +* not know about them. +*/ +if (chain->refcnt - chain->action_refcnt ==1 && !by_act) +tc_chain_notify (chain,NULL ,0 ,NLM_F_CREATE |NLM_F_EXCL , +RTM_NEWCHAIN , false); +return chain; } + +struct tcf_chain *tcf_chain_get (struct tcf_block *block,u32 chain_index, +bool create) +{ +return __tcf_chain_get (block, chain_index, create, false); +}EXPORT_SYMBOL (tcf_chain_get);struct tcf_chain *tcf_chain_get_by_act (struct tcf_block *block,u32 chain_index) { -struct tcf_chain *chain =tcf_chain_get (block, chain_index, true); - -tcf_chain_hold_by_act (chain); -return chain; +return __tcf_chain_get (block, chain_index, true, true); }EXPORT_SYMBOL (tcf_chain_get_by_act);static void tc_chain_tmplt_del (struct tcf_chain *chain); -void tcf_chain_put (struct tcf_chain *chain) +void __tcf_chain_put (struct tcf_chain *chain,bool by_act) { -if (--chain->refcnt ==0 ) { +if (by_act) + chain->action_refcnt--; + chain->refcnt--; + +/* The last dropped non-action reference will trigger notification. */ +if (chain->refcnt - chain->action_refcnt ==0 && !by_act)tc_chain_notify (chain,NULL ,0 ,0 ,RTM_DELCHAIN , false); + +if (chain->refcnt ==0 ) {tc_chain_tmplt_del (chain);tcf_chain_destroy (chain); } } + +void tcf_chain_put (struct tcf_chain *chain) +{ +__tcf_chain_put (chain, false); +}EXPORT_SYMBOL (tcf_chain_put);void tcf_chain_put_by_act (struct tcf_chain *chain) { -tcf_chain_release_by_act (chain); -tcf_chain_put (chain); +__tcf_chain_put (chain, true); }EXPORT_SYMBOL (tcf_chain_put_by_act);
Signature · 1 line
2.14.4
Re: [patch net-next 2/2] net: sched: fix notifications for action-held chains
Quoted 11 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Chains that only have action references serve as placeholders. Until a non-action reference is created, user should not be aware of the chain. Also he should not receive any notifications about it. So send notifications for the new chain only in case the chain gets the first non-action reference. Symmetrically to that, when the last non-action reference is dropped, send the notification about deleted chain.
Quoted 2 lines
Reported-by Cong Wang <[email protected]>Signed-off-by Jiri Pirko <[email protected]>
I think __tcf_chain_{get,put}() can be static.
Other than that,
Thanks.
Jiri Pirko
maintainerRe: [patch net-next 2/2] net: sched: fix notifications for action-held chains
Quoted 12 lines · Wed, Aug 01, 2018 at 06:27:28AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Chains that only have action references serve as placeholders. Until a non-action reference is created, user should not be aware of the chain. Also he should not receive any notifications about it. So send notifications for the new chain only in case the chain gets the first non-action reference. Symmetrically to that, when the last non-action reference is dropped, send the notification about deleted chain.
Quoted 4 lines
Quoted 2 lines
Reported-by Cong Wang <[email protected]>Signed-off-by Jiri Pirko <[email protected]>I think __tcf_chain_{get,put}() can be static.
In fact, tcf_chain_get/put could be now static too. Will send v2. Thanks!
Quoted 6 lines
Other than that,
Acked-by Cong Wang <[email protected]>Thanks.