Skip to contentSkip to conversation

net: sched: don't dump chains only held by actions

PATCH In review Jiri Pirko 3 participants 8 messages Jul 27, 2018 – Jul 31, 2018

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

PATCH 1/1 net: sched: don't dump chains only held by actions

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

---
rfc->v1:
- fixed get/del paths to also ignore zombie chains

---
 include/net/pkt_cls.h     |  3 ++
 include/net/sch_generic.h |  1 +
 net/sched/act_api.c       |  4 +--
 net/sched/cls_api.c       | 70 +++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 64 insertions(+), 14 deletions(-)
include/net/pkt_cls.h +3 -0
index a3101582f642..6d02f31abba8 100644
@@ -39,7 +39,10 @@ bool tcf_queue_work(struct rcu_work *rwork, work_func_t func);
 #ifdef CONFIG_NET_CLS
 struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
 				bool create);
+struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block,
+				       u32 chain_index);
 void tcf_chain_put(struct tcf_chain *chain);
+void tcf_chain_put_by_act(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,
include/net/sch_generic.h +1 -0
index 085c509c8674..c5432362dc26 100644
@@ -314,6 +314,7 @@ struct tcf_chain {
 	struct tcf_block *block;
 	u32 index; /* chain index */
 	unsigned int refcnt;
+	unsigned int action_refcnt;
 	bool explicitly_created;
 	const struct tcf_proto_ops *tmplt_ops;
 	void *tmplt_priv;
net/sched/act_api.c +2 -2
index 148a89ab789b..b43df1e25c6d 100644
@@ -36,7 +36,7 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
 
 	if (!tp)
 		return -EINVAL;
-	a->goto_chain = tcf_chain_get(tp->chain->block, chain_index, true);
+	a->goto_chain = tcf_chain_get_by_act(tp->chain->block, chain_index);
 	if (!a->goto_chain)
 		return -ENOMEM;
 	return 0;
@@ -44,7 +44,7 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
 
 static void tcf_action_goto_chain_fini(struct tc_action *a)
 {
-	tcf_chain_put(a->goto_chain);
+	tcf_chain_put_by_act(a->goto_chain);
 }
 
 static void tcf_action_goto_chain_exec(const struct tc_action *a,
net/sched/cls_api.c +58 -12

102 lines not on this page · raw message

Signature · 1 line
2.14.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Looks reasonable to me.

#2 lore raw
Quoted 12 lines · Cong Wang
Quoted 10 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Quoted 5 lines
Quoted 1 line

Looks reasonable to me.

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

author maintainer
#3 lore raw
Quoted 17 lines · Sat, Jul 28, 2018 at 07:39:36PM CEST, [email protected] wrote:
Quoted 16 lines · Cong Wang
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Looks reasonable to me.

Quoted 8 lines
Quoted 1 line

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

No. action always increases both refcnt and action_refcnt

#4 lore raw
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Sat, Jul 28, 2018 at 07:39:36PM CEST, [email protected] wrote:
Quoted 17 lines · Cong Wang
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Looks reasonable to me.

Quoted 8 lines
Quoted 6 lines

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

No. action always increases both refcnt and action_refcnt

Hmm, then the name zombie is confusing, with your definition all chains implicitly created by actions are zombies, unless touched by user explicitly. Please find a better name.

Also, tcf_chain_get_by_act() could send out RTM_NEWCHAIN too, which is confusing too as it is still a "zombie".

author maintainer
#5 lore raw
Quoted 29 lines · Mon, Jul 30, 2018 at 08:19:56PM CEST, [email protected] wrote:
Quoted 28 lines · Jiri Pirko
Quoted 25 lines · Sat, Jul 28, 2018 at 07:39:36PM CEST, [email protected] wrote:
Quoted 12 lines · Cong Wang
Quoted 10 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Quoted 5 lines
Quoted 1 line

Looks reasonable to me.

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

Quoted 5 lines
Quoted 1 line

No. action always increases both refcnt and action_refcnt

Hmm, then the name zombie is confusing, with your definition all chains implicitly created by actions are zombies, unless touched by user explicitly. Please find a better name.

Okay. Perhaps chain_inactive?

Quoted 3 lines

Also, tcf_chain_get_by_act() could send out RTM_NEWCHAIN too, which is confusing too as it is still a "zombie".

Will check.

#6 lore raw
Quoted 30 lines · Jiri Pirko
Quoted 29 lines · Mon, Jul 30, 2018 at 08:19:56PM CEST, [email protected] wrote:
Quoted 28 lines · Jiri Pirko
Quoted 25 lines · Sat, Jul 28, 2018 at 07:39:36PM CEST, [email protected] wrote:
Quoted 12 lines · Cong Wang
Quoted 10 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Quoted 5 lines
Quoted 1 line

Looks reasonable to me.

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

No. action always increases both refcnt and action_refcnt

Hmm, then the name zombie is confusing, with your definition all chains implicitly created by actions are zombies, unless touched by user explicitly. Please find a better name.

Okay. Perhaps chain_inactive?

FWIW to me active brings to mind that it's handling traffic. Brining in my suggestions from an off-list discussion:

tcf_chain_act_refs_only() or tcf_chain_pure_act_target()

or maybe tcf_chain_has_no_filters() ?

author maintainer
#7 lore raw
Quoted 37 lines · Tue, Jul 31, 2018 at 10:01:46AM CEST, [email protected] wrote:
Quoted 36 lines · Jiri Pirko
Quoted 34 lines · Mon, Jul 30, 2018 at 08:19:56PM CEST, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Sat, Jul 28, 2018 at 07:39:36PM CEST, [email protected] wrote:
Quoted 17 lines · Cong Wang
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

In case a chain is empty and not explicitly created by a user, such chain should not exist. The only exception is if there is an action "goto chain" pointing to it. In that case, don't show the chain in the dump. Track the chain references held by actions and use them to find out if a chain should or should not be shown in chain dump.

Looks reasonable to me.

Quoted 8 lines
Quoted 6 lines

Hold on...

If you increase the refcnt for a zombie chain on NEWCHAIN path, then it would become a non-zombie, this makes sense. However, if the action_refcnt gets increased again when another action uses it, it become a zombie again because refcnt==action_refcnt??

No. action always increases both refcnt and action_refcnt

Hmm, then the name zombie is confusing, with your definition all chains implicitly created by actions are zombies, unless touched by user explicitly. Please find a better name.

Quoted 6 lines
Quoted 1 line

Okay. Perhaps chain_inactive?

FWIW to me active brings to mind that it's handling traffic. Brining in my suggestions from an off-list discussion:

tcf_chain_act_refs_only() or tcf_chain_pure_act_target()

:/

Quoted 2 lines

or maybe tcf_chain_has_no_filters() ?

That is not accurate, as explicitly created chain does not have any filters too.

I think this is good:
tcf_chain_held_by_acts_only()