linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops
@ 2022-09-02 11:24 Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Zhengchao Shao
                   ` (21 more replies)
  0 siblings, 22 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

The implementation logic of the walk/lookup hook function in each action
module is the same. Therefore, the two functions can be reconstructed.
When registering tc_action_ops of each action module, the corresponding
net_id is saved to tc_action_ops. In this way, the net_id of the
corresponding module can be directly obtained in act_api without executing
the specific walk and lookup hook functions. Generic functions can be
added to replace the walk and lookup hook functions of each action module.
Then, modify each action module in alphabetical order. Last, remove the
adaptation code of the patchset.

Zhengchao Shao (22):
  net: sched: act_api: implement generic walker and search for tc action
  net: sched: act_bpf: get rid of tcf_bpf_walker and tcf_bpf_search
  net: sched: act_connmark: get rid of tcf_connmark_walker and
    tcf_connmark_search
  net: sched: act_csum: get rid of tcf_csum_walker and tcf_csum_search
  net: sched: act_ct: get rid of tcf_ct_walker and tcf_ct_search
  net: sched: act_ctinfo: get rid of tcf_ctinfo_walker and
    tcf_ctinfo_search
  net: sched: act_gact: get rid of tcf_gact_walker and tcf_gact_search
  net: sched: act_gate: get rid of tcf_gate_walker and tcf_gate_search
  net: sched: act_ife: get rid of tcf_ife_walker and tcf_ife_search
  net: sched: act_ipt: get rid of tcf_ipt_walker/tcf_xt_walker and
    tcf_ipt_search/tcf_xt_search
  net: sched: act_mirred: get rid of tcf_mirred_walker and
    tcf_mirred_search
  net: sched: act_mpls: get rid of tcf_mpls_walker and tcf_mpls_search
  net: sched: act_nat: get rid of tcf_nat_walker and tcf_nat_search
  net: sched: act_pedit: get rid of tcf_pedit_walker and
    tcf_pedit_search
  net: sched: act_police: get rid of tcf_police_walker and
    tcf_police_search
  net: sched: act_sample: get rid of tcf_sample_walker and
    tcf_sample_search
  net: sched: act_simple: get rid of tcf_simp_walker and tcf_simp_search
  net: sched: act_skbedit: get rid of tcf_skbedit_walker and
    tcf_skbedit_search
  net: sched: act_skbmod: get rid of tcf_skbmod_walker and
    tcf_skbmod_search
  net: sched: act_tunnel_key: get rid of tunnel_key_walker and
    tunnel_key_search
  net: sched: act_vlan: get rid of tcf_vlan_walker and tcf_vlan_search
  net: sched: act: remove redundant code in act_api

 include/net/act_api.h      | 11 +----------
 net/sched/act_api.c        | 40 +++++++++++++++++++++++++++-----------
 net/sched/act_bpf.c        | 20 +------------------
 net/sched/act_connmark.c   | 20 +------------------
 net/sched/act_csum.c       | 20 +------------------
 net/sched/act_ct.c         | 20 +------------------
 net/sched/act_ctinfo.c     | 20 +------------------
 net/sched/act_gact.c       | 20 +------------------
 net/sched/act_gate.c       | 19 +-----------------
 net/sched/act_ife.c        | 20 +------------------
 net/sched/act_ipt.c        | 40 ++------------------------------------
 net/sched/act_mirred.c     | 20 +------------------
 net/sched/act_mpls.c       | 20 +------------------
 net/sched/act_nat.c        | 20 +------------------
 net/sched/act_pedit.c      | 20 +------------------
 net/sched/act_police.c     | 20 +------------------
 net/sched/act_sample.c     | 20 +------------------
 net/sched/act_simple.c     | 20 +------------------
 net/sched/act_skbedit.c    | 20 +------------------
 net/sched/act_skbmod.c     | 20 +------------------
 net/sched/act_tunnel_key.c | 20 +------------------
 net/sched/act_vlan.c       | 20 +------------------
 22 files changed, 51 insertions(+), 419 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 13:53   ` Jamal Hadi Salim
  2022-09-02 11:24 ` [PATCH net-next 02/22] net: sched: act_bpf: get rid of tcf_bpf_walker and tcf_bpf_search Zhengchao Shao
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Being able to get tc_action_net by using net_id stored in tc_action_ops
and execute the generic walk/search function, add __tcf_generic_walker()
and __tcf_idr_search() helpers.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 include/net/act_api.h |  1 +
 net/sched/act_api.c   | 48 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/include/net/act_api.h b/include/net/act_api.h
index 9cf6870b526e..a79d6e58519e 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -113,6 +113,7 @@ struct tc_action_ops {
 	enum tca_id  id; /* identifier should match kind */
 	size_t	size;
 	struct module		*owner;
+	unsigned int		*net_id;
 	int     (*act)(struct sk_buff *, const struct tc_action *,
 		       struct tcf_result *); /* called under RCU BH lock*/
 	int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 817065aa2833..7063d2004199 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -676,6 +676,25 @@ int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
 }
 EXPORT_SYMBOL(tcf_idr_search);
 
+static int __tcf_generic_walker(struct net *net, struct sk_buff *skb,
+				struct netlink_callback *cb, int type,
+				const struct tc_action_ops *ops,
+				struct netlink_ext_ack *extack)
+{
+	struct tc_action_net *tn = net_generic(net, *ops->net_id);
+
+	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
+}
+
+static int __tcf_idr_search(struct net *net,
+			    const struct tc_action_ops *ops,
+			    struct tc_action **a, u32 index)
+{
+	struct tc_action_net *tn = net_generic(net, *ops->net_id);
+
+	return tcf_idr_search(tn, a, index);
+}
+
 static int tcf_idr_delete_index(struct tcf_idrinfo *idrinfo, u32 index)
 {
 	struct tc_action *p;
@@ -926,7 +945,8 @@ int tcf_register_action(struct tc_action_ops *act,
 	struct tc_action_ops *a;
 	int ret;
 
-	if (!act->act || !act->dump || !act->init || !act->walk || !act->lookup)
+	if (!act->act || !act->dump || !act->init ||
+	    (!act->net_id && (!act->walk || !act->lookup)))
 		return -EINVAL;
 
 	/* We have to register pernet ops before making the action ops visible,
@@ -1638,9 +1658,16 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
 		goto err_out;
 	}
 	err = -ENOENT;
-	if (ops->lookup(net, &a, index) == 0) {
-		NL_SET_ERR_MSG(extack, "TC action with specified index not found");
-		goto err_mod;
+	if (ops->lookup) {
+		if (ops->lookup(net, &a, index) == 0) {
+			NL_SET_ERR_MSG(extack, "TC action with specified index not found");
+			goto err_mod;
+		}
+	} else {
+		if (__tcf_idr_search(net, ops, &a, index) == 0) {
+			NL_SET_ERR_MSG(extack, "TC action with specified index not found");
+			goto err_mod;
+		}
 	}
 
 	module_put(ops->owner);
@@ -1703,7 +1730,12 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
 		goto out_module_put;
 	}
 
-	err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
+	if (ops->walk) {
+		err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
+	} else {
+		err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
+	}
+
 	if (err <= 0) {
 		nla_nest_cancel(skb, nest);
 		goto out_module_put;
@@ -2121,7 +2153,11 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
 	if (nest == NULL)
 		goto out_module_put;
 
-	ret = a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL);
+	if (a_o->walk)
+		ret = a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL);
+	else
+		ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
+
 	if (ret < 0)
 		goto out_module_put;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 02/22] net: sched: act_bpf: get rid of tcf_bpf_walker and tcf_bpf_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 03/22] net: sched: act_connmark: get rid of tcf_connmark_walker and tcf_connmark_search Zhengchao Shao
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
bpf_net_id when registering act_bpf_ops. And then remove the walk
and lookup hook functions in act_bpf.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_bpf.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index fea2d78b9ddc..d7fc5c4157d6 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -390,33 +390,15 @@ static void tcf_bpf_cleanup(struct tc_action *act)
 	tcf_bpf_cfg_cleanup(&tmp);
 }
 
-static int tcf_bpf_walker(struct net *net, struct sk_buff *skb,
-			  struct netlink_callback *cb, int type,
-			  const struct tc_action_ops *ops,
-			  struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, bpf_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, bpf_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_bpf_ops __read_mostly = {
 	.kind		=	"bpf",
 	.id		=	TCA_ID_BPF,
+	.net_id		=	&bpf_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_bpf_act,
 	.dump		=	tcf_bpf_dump,
 	.cleanup	=	tcf_bpf_cleanup,
 	.init		=	tcf_bpf_init,
-	.walk		=	tcf_bpf_walker,
-	.lookup		=	tcf_bpf_search,
 	.size		=	sizeof(struct tcf_bpf),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 03/22] net: sched: act_connmark: get rid of tcf_connmark_walker and tcf_connmark_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 02/22] net: sched: act_bpf: get rid of tcf_bpf_walker and tcf_bpf_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 04/22] net: sched: act_csum: get rid of tcf_csum_walker and tcf_csum_search Zhengchao Shao
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
connmark_net_id when registering act_connmark_ops. And then remove
the walk and lookup hook functions in act_connmark.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_connmark.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 09e2aafc8943..e7cc0aba9c4f 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -200,32 +200,14 @@ static inline int tcf_connmark_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_connmark_walker(struct net *net, struct sk_buff *skb,
-			       struct netlink_callback *cb, int type,
-			       const struct tc_action_ops *ops,
-			       struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, connmark_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, connmark_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_connmark_ops = {
 	.kind		=	"connmark",
 	.id		=	TCA_ID_CONNMARK,
+	.net_id		=	&connmark_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_connmark_act,
 	.dump		=	tcf_connmark_dump,
 	.init		=	tcf_connmark_init,
-	.walk		=	tcf_connmark_walker,
-	.lookup		=	tcf_connmark_search,
 	.size		=	sizeof(struct tcf_connmark_info),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 04/22] net: sched: act_csum: get rid of tcf_csum_walker and tcf_csum_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (2 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 03/22] net: sched: act_connmark: get rid of tcf_connmark_walker and tcf_connmark_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 05/22] net: sched: act_ct: get rid of tcf_ct_walker and tcf_ct_search Zhengchao Shao
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
csum_net_id when registering act_csum_ops. And then remove the walk
and lookup hook functions in act_csum.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_csum.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 22847ee009ef..095132b0f96a 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -673,23 +673,6 @@ static void tcf_csum_cleanup(struct tc_action *a)
 		kfree_rcu(params, rcu);
 }
 
-static int tcf_csum_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, csum_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, csum_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static size_t tcf_csum_get_fill_size(const struct tc_action *act)
 {
 	return nla_total_size(sizeof(struct tc_csum));
@@ -717,13 +700,12 @@ static int tcf_csum_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_csum_ops = {
 	.kind		= "csum",
 	.id		= TCA_ID_CSUM,
+	.net_id		= &csum_net_id,
 	.owner		= THIS_MODULE,
 	.act		= tcf_csum_act,
 	.dump		= tcf_csum_dump,
 	.init		= tcf_csum_init,
 	.cleanup	= tcf_csum_cleanup,
-	.walk		= tcf_csum_walker,
-	.lookup		= tcf_csum_search,
 	.get_fill_size  = tcf_csum_get_fill_size,
 	.offload_act_setup = tcf_csum_offload_act_setup,
 	.size		= sizeof(struct tcf_csum),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 05/22] net: sched: act_ct: get rid of tcf_ct_walker and tcf_ct_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (3 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 04/22] net: sched: act_csum: get rid of tcf_csum_walker and tcf_csum_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 06/22] net: sched: act_ctinfo: get rid of tcf_ctinfo_walker and tcf_ctinfo_search Zhengchao Shao
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
ct_net_id when registering act_ct_ops. And then remove the walk and
lookup hook functions in act_ct.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_ct.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index d55afb8d14be..436517272c9d 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -1558,23 +1558,6 @@ static inline int tcf_ct_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_ct_walker(struct net *net, struct sk_buff *skb,
-			 struct netlink_callback *cb, int type,
-			 const struct tc_action_ops *ops,
-			 struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, ct_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_ct_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, ct_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static void tcf_stats_update(struct tc_action *a, u64 bytes, u64 packets,
 			     u64 drops, u64 lastuse, bool hw)
 {
@@ -1608,13 +1591,12 @@ static int tcf_ct_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_ct_ops = {
 	.kind		=	"ct",
 	.id		=	TCA_ID_CT,
+	.net_id		=	&ct_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_ct_act,
 	.dump		=	tcf_ct_dump,
 	.init		=	tcf_ct_init,
 	.cleanup	=	tcf_ct_cleanup,
-	.walk		=	tcf_ct_walker,
-	.lookup		=	tcf_ct_search,
 	.stats_update	=	tcf_stats_update,
 	.offload_act_setup =	tcf_ct_offload_act_setup,
 	.size		=	sizeof(struct tcf_ct),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 06/22] net: sched: act_ctinfo: get rid of tcf_ctinfo_walker and tcf_ctinfo_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (4 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 05/22] net: sched: act_ct: get rid of tcf_ct_walker and tcf_ct_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 07/22] net: sched: act_gact: get rid of tcf_gact_walker and tcf_gact_search Zhengchao Shao
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
ctinfo_net_id when registering act_ctinfo_ops. And then remove the
walk and lookup hook functions in act_ctinfo.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_ctinfo.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_ctinfo.c b/net/sched/act_ctinfo.c
index 0281e45987a4..b79c5a5177aa 100644
--- a/net/sched/act_ctinfo.c
+++ b/net/sched/act_ctinfo.c
@@ -342,23 +342,6 @@ static int tcf_ctinfo_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_ctinfo_walker(struct net *net, struct sk_buff *skb,
-			     struct netlink_callback *cb, int type,
-			     const struct tc_action_ops *ops,
-			     struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_ctinfo_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static void tcf_ctinfo_cleanup(struct tc_action *a)
 {
 	struct tcf_ctinfo *ci = to_ctinfo(a);
@@ -372,13 +355,12 @@ static void tcf_ctinfo_cleanup(struct tc_action *a)
 static struct tc_action_ops act_ctinfo_ops = {
 	.kind	= "ctinfo",
 	.id	= TCA_ID_CTINFO,
+	.net_id	= &ctinfo_net_id,
 	.owner	= THIS_MODULE,
 	.act	= tcf_ctinfo_act,
 	.dump	= tcf_ctinfo_dump,
 	.init	= tcf_ctinfo_init,
 	.cleanup= tcf_ctinfo_cleanup,
-	.walk	= tcf_ctinfo_walker,
-	.lookup	= tcf_ctinfo_search,
 	.size	= sizeof(struct tcf_ctinfo),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 07/22] net: sched: act_gact: get rid of tcf_gact_walker and tcf_gact_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (5 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 06/22] net: sched: act_ctinfo: get rid of tcf_ctinfo_walker and tcf_ctinfo_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 08/22] net: sched: act_gate: get rid of tcf_gate_walker and tcf_gate_search Zhengchao Shao
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
gact_net_id when registering act_gact_ops. And then remove the walk
and lookup hook functions in act_gact.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_gact.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index ac29d1065232..80c276d2793d 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -222,23 +222,6 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_gact_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, gact_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, gact_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static size_t tcf_gact_get_fill_size(const struct tc_action *act)
 {
 	size_t sz = nla_total_size(sizeof(struct tc_gact)); /* TCA_GACT_PARMS */
@@ -303,13 +286,12 @@ static int tcf_gact_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_gact_ops = {
 	.kind		=	"gact",
 	.id		=	TCA_ID_GACT,
+	.net_id		=	&gact_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_gact_act,
 	.stats_update	=	tcf_gact_stats_update,
 	.dump		=	tcf_gact_dump,
 	.init		=	tcf_gact_init,
-	.walk		=	tcf_gact_walker,
-	.lookup		=	tcf_gact_search,
 	.get_fill_size	=	tcf_gact_get_fill_size,
 	.offload_act_setup =	tcf_gact_offload_act_setup,
 	.size		=	sizeof(struct tcf_gact),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 08/22] net: sched: act_gate: get rid of tcf_gate_walker and tcf_gate_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (6 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 07/22] net: sched: act_gact: get rid of tcf_gact_walker and tcf_gact_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 09/22] net: sched: act_ife: get rid of tcf_ife_walker and tcf_ife_search Zhengchao Shao
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
gate_net_id when registering act_gate_ops. And then remove the walk
and lookup hook functions in act_gate.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_gate.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index fd5155274733..e347e3b42a14 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -565,15 +565,6 @@ static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_gate_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, gate_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
 
 static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u64 packets,
 				  u64 drops, u64 lastuse, bool hw)
@@ -585,13 +576,6 @@ static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u64 packets,
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
-static int tcf_gate_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, gate_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static size_t tcf_gate_get_fill_size(const struct tc_action *act)
 {
 	return nla_total_size(sizeof(struct tc_gate));
@@ -649,15 +633,14 @@ static int tcf_gate_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_gate_ops = {
 	.kind		=	"gate",
 	.id		=	TCA_ID_GATE,
+	.net_id		=	&gate_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_gate_act,
 	.dump		=	tcf_gate_dump,
 	.init		=	tcf_gate_init,
 	.cleanup	=	tcf_gate_cleanup,
-	.walk		=	tcf_gate_walker,
 	.stats_update	=	tcf_gate_stats_update,
 	.get_fill_size	=	tcf_gate_get_fill_size,
-	.lookup		=	tcf_gate_search,
 	.offload_act_setup =	tcf_gate_offload_act_setup,
 	.size		=	sizeof(struct tcf_gate),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 09/22] net: sched: act_ife: get rid of tcf_ife_walker and tcf_ife_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (7 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 08/22] net: sched: act_gate: get rid of tcf_gate_walker and tcf_gate_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 10/22] net: sched: act_ipt: get rid of tcf_ipt_walker/tcf_xt_walker and tcf_ipt_search/tcf_xt_search Zhengchao Shao
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
ife_net_id when registering act_ife_ops. And then remove the walk
and lookup hook functions in act_ife.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_ife.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 41ba55e60b1b..d473618877e0 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -878,33 +878,15 @@ static int tcf_ife_act(struct sk_buff *skb, const struct tc_action *a,
 	return tcf_ife_decode(skb, a, res);
 }
 
-static int tcf_ife_walker(struct net *net, struct sk_buff *skb,
-			  struct netlink_callback *cb, int type,
-			  const struct tc_action_ops *ops,
-			  struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, ife_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, ife_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_ife_ops = {
 	.kind = "ife",
 	.id = TCA_ID_IFE,
+	.net_id = &ife_net_id,
 	.owner = THIS_MODULE,
 	.act = tcf_ife_act,
 	.dump = tcf_ife_dump,
 	.cleanup = tcf_ife_cleanup,
 	.init = tcf_ife_init,
-	.walk = tcf_ife_walker,
-	.lookup = tcf_ife_search,
 	.size =	sizeof(struct tcf_ife_info),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 10/22] net: sched: act_ipt: get rid of tcf_ipt_walker/tcf_xt_walker and tcf_ipt_search/tcf_xt_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (8 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 09/22] net: sched: act_ife: get rid of tcf_ife_walker and tcf_ife_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 11/22] net: sched: act_mirred: get rid of tcf_mirred_walker and tcf_mirred_search Zhengchao Shao
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
ipt_net_id/xt_net_id when registering act_ipt_ops/act_xt_ops. And
then remove the walk and lookup hook functions in act_ipt.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_ipt.c | 40 ++--------------------------------------
 1 file changed, 2 insertions(+), 38 deletions(-)

diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 2f3d507c24a1..abacfb134caf 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -316,33 +316,15 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind,
 	return -1;
 }
 
-static int tcf_ipt_walker(struct net *net, struct sk_buff *skb,
-			  struct netlink_callback *cb, int type,
-			  const struct tc_action_ops *ops,
-			  struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, ipt_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, ipt_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_ipt_ops = {
 	.kind		=	"ipt",
 	.id		=	TCA_ID_IPT,
+	.net_id		=	&ipt_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_ipt_act,
 	.dump		=	tcf_ipt_dump,
 	.cleanup	=	tcf_ipt_release,
 	.init		=	tcf_ipt_init,
-	.walk		=	tcf_ipt_walker,
-	.lookup		=	tcf_ipt_search,
 	.size		=	sizeof(struct tcf_ipt),
 };
 
@@ -365,33 +347,15 @@ static struct pernet_operations ipt_net_ops = {
 	.size = sizeof(struct tc_action_net),
 };
 
-static int tcf_xt_walker(struct net *net, struct sk_buff *skb,
-			 struct netlink_callback *cb, int type,
-			 const struct tc_action_ops *ops,
-			 struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, xt_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, xt_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_xt_ops = {
 	.kind		=	"xt",
 	.id		=	TCA_ID_XT,
+	.net_id		=	&xt_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_ipt_act,
 	.dump		=	tcf_ipt_dump,
 	.cleanup	=	tcf_ipt_release,
 	.init		=	tcf_xt_init,
-	.walk		=	tcf_xt_walker,
-	.lookup		=	tcf_xt_search,
 	.size		=	sizeof(struct tcf_ipt),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 11/22] net: sched: act_mirred: get rid of tcf_mirred_walker and tcf_mirred_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (9 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 10/22] net: sched: act_ipt: get rid of tcf_ipt_walker/tcf_xt_walker and tcf_ipt_search/tcf_xt_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 12/22] net: sched: act_mpls: get rid of tcf_mpls_walker and tcf_mpls_search Zhengchao Shao
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
mirred_net_id when registering act_mirred_ops. And then remove the
walk and lookup hook functions in act_mirred.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_mirred.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index a1d70cf86843..4b266a6cbb3f 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -373,23 +373,6 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind,
 	return -1;
 }
 
-static int tcf_mirred_walker(struct net *net, struct sk_buff *skb,
-			     struct netlink_callback *cb, int type,
-			     const struct tc_action_ops *ops,
-			     struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, mirred_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_mirred_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, mirred_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static int mirred_device_event(struct notifier_block *unused,
 			       unsigned long event, void *ptr)
 {
@@ -504,14 +487,13 @@ static int tcf_mirred_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_mirred_ops = {
 	.kind		=	"mirred",
 	.id		=	TCA_ID_MIRRED,
+	.net_id		=	&mirred_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_mirred_act,
 	.stats_update	=	tcf_stats_update,
 	.dump		=	tcf_mirred_dump,
 	.cleanup	=	tcf_mirred_release,
 	.init		=	tcf_mirred_init,
-	.walk		=	tcf_mirred_walker,
-	.lookup		=	tcf_mirred_search,
 	.get_fill_size	=	tcf_mirred_get_fill_size,
 	.offload_act_setup =	tcf_mirred_offload_act_setup,
 	.size		=	sizeof(struct tcf_mirred),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 12/22] net: sched: act_mpls: get rid of tcf_mpls_walker and tcf_mpls_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (10 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 11/22] net: sched: act_mirred: get rid of tcf_mirred_walker and tcf_mirred_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 13/22] net: sched: act_nat: get rid of tcf_nat_walker and tcf_nat_search Zhengchao Shao
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
mpls_net_id when registering act_mpls_ops. And then remove the walk
and lookup hook functions in act_mpls.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_mpls.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
index adabeccb63e1..32c5b9586025 100644
--- a/net/sched/act_mpls.c
+++ b/net/sched/act_mpls.c
@@ -367,23 +367,6 @@ static int tcf_mpls_dump(struct sk_buff *skb, struct tc_action *a,
 	return -EMSGSIZE;
 }
 
-static int tcf_mpls_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, mpls_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_mpls_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, mpls_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static int tcf_mpls_offload_act_setup(struct tc_action *act, void *entry_data,
 				      u32 *index_inc, bool bind,
 				      struct netlink_ext_ack *extack)
@@ -446,13 +429,12 @@ static int tcf_mpls_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_mpls_ops = {
 	.kind		=	"mpls",
 	.id		=	TCA_ID_MPLS,
+	.net_id		=	&mpls_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_mpls_act,
 	.dump		=	tcf_mpls_dump,
 	.init		=	tcf_mpls_init,
 	.cleanup	=	tcf_mpls_cleanup,
-	.walk		=	tcf_mpls_walker,
-	.lookup		=	tcf_mpls_search,
 	.offload_act_setup =	tcf_mpls_offload_act_setup,
 	.size		=	sizeof(struct tcf_mpls),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 13/22] net: sched: act_nat: get rid of tcf_nat_walker and tcf_nat_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (11 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 12/22] net: sched: act_mpls: get rid of tcf_mpls_walker and tcf_mpls_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 14/22] net: sched: act_pedit: get rid of tcf_pedit_walker and tcf_pedit_search Zhengchao Shao
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
nat_net_id when registering act_nat_ops. And then remove the walk
and lookup hook functions in act_nat.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_nat.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 2a39b3729e84..c95601bc738c 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -289,32 +289,14 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_nat_walker(struct net *net, struct sk_buff *skb,
-			  struct netlink_callback *cb, int type,
-			  const struct tc_action_ops *ops,
-			  struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, nat_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, nat_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_nat_ops = {
 	.kind		=	"nat",
 	.id		=	TCA_ID_NAT,
+	.net_id		=	&nat_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_nat_act,
 	.dump		=	tcf_nat_dump,
 	.init		=	tcf_nat_init,
-	.walk		=	tcf_nat_walker,
-	.lookup		=	tcf_nat_search,
 	.size		=	sizeof(struct tcf_nat),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 14/22] net: sched: act_pedit: get rid of tcf_pedit_walker and tcf_pedit_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (12 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 13/22] net: sched: act_nat: get rid of tcf_nat_walker and tcf_nat_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 15/22] net: sched: act_police: get rid of tcf_police_walker and tcf_police_search Zhengchao Shao
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
pedit_net_id when registering act_pedit_ops. And then remove the walk
and lookup hook functions in act_pedit.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_pedit.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 823ee643371c..15d1b206e73b 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -492,23 +492,6 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_pedit_walker(struct net *net, struct sk_buff *skb,
-			    struct netlink_callback *cb, int type,
-			    const struct tc_action_ops *ops,
-			    struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, pedit_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, pedit_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,
 				       u32 *index_inc, bool bind,
 				       struct netlink_ext_ack *extack)
@@ -547,14 +530,13 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_pedit_ops = {
 	.kind		=	"pedit",
 	.id		=	TCA_ID_PEDIT,
+	.net_id		=	&pedit_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_pedit_act,
 	.stats_update	=	tcf_pedit_stats_update,
 	.dump		=	tcf_pedit_dump,
 	.cleanup	=	tcf_pedit_cleanup,
 	.init		=	tcf_pedit_init,
-	.walk		=	tcf_pedit_walker,
-	.lookup		=	tcf_pedit_search,
 	.offload_act_setup =	tcf_pedit_offload_act_setup,
 	.size		=	sizeof(struct tcf_pedit),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 15/22] net: sched: act_police: get rid of tcf_police_walker and tcf_police_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (13 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 14/22] net: sched: act_pedit: get rid of tcf_pedit_walker and tcf_pedit_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 16/22] net: sched: act_sample: get rid of tcf_sample_walker and tcf_sample_search Zhengchao Shao
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
police_net_id when registering act_police_ops. And then remove the
walk and lookup hook functions in act_police.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_police.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index b759628a47c2..a9dd89210bd4 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -25,16 +25,6 @@
 static unsigned int police_net_id;
 static struct tc_action_ops act_police_ops;
 
-static int tcf_police_walker(struct net *net, struct sk_buff *skb,
-				 struct netlink_callback *cb, int type,
-				 const struct tc_action_ops *ops,
-				 struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, police_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
 static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = {
 	[TCA_POLICE_RATE]	= { .len = TC_RTAB_SIZE },
 	[TCA_POLICE_PEAKRATE]	= { .len = TC_RTAB_SIZE },
@@ -412,13 +402,6 @@ static int tcf_police_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_police_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, police_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static int tcf_police_act_to_flow_act(int tc_act, u32 *extval,
 				      struct netlink_ext_ack *extack)
 {
@@ -508,13 +491,12 @@ MODULE_LICENSE("GPL");
 static struct tc_action_ops act_police_ops = {
 	.kind		=	"police",
 	.id		=	TCA_ID_POLICE,
+	.net_id		=	&police_net_id,
 	.owner		=	THIS_MODULE,
 	.stats_update	=	tcf_police_stats_update,
 	.act		=	tcf_police_act,
 	.dump		=	tcf_police_dump,
 	.init		=	tcf_police_init,
-	.walk		=	tcf_police_walker,
-	.lookup		=	tcf_police_search,
 	.cleanup	=	tcf_police_cleanup,
 	.offload_act_setup =	tcf_police_offload_act_setup,
 	.size		=	sizeof(struct tcf_police),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 16/22] net: sched: act_sample: get rid of tcf_sample_walker and tcf_sample_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (14 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 15/22] net: sched: act_police: get rid of tcf_police_walker and tcf_police_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 17/22] net: sched: act_simple: get rid of tcf_simp_walker and tcf_simp_search Zhengchao Shao
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
sample_net_id when registering act_sample_ops. And then remove the
walk and lookup hook functions in act_sample.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_sample.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
index 2f7f5e44d28c..f545f38acbdc 100644
--- a/net/sched/act_sample.c
+++ b/net/sched/act_sample.c
@@ -241,23 +241,6 @@ static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_sample_walker(struct net *net, struct sk_buff *skb,
-			     struct netlink_callback *cb, int type,
-			     const struct tc_action_ops *ops,
-			     struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, sample_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, sample_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static void tcf_psample_group_put(void *priv)
 {
 	struct psample_group *group = priv;
@@ -315,14 +298,13 @@ static int tcf_sample_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_sample_ops = {
 	.kind	  = "sample",
 	.id	  = TCA_ID_SAMPLE,
+	.net_id	  = &sample_net_id,
 	.owner	  = THIS_MODULE,
 	.act	  = tcf_sample_act,
 	.stats_update = tcf_sample_stats_update,
 	.dump	  = tcf_sample_dump,
 	.init	  = tcf_sample_init,
 	.cleanup  = tcf_sample_cleanup,
-	.walk	  = tcf_sample_walker,
-	.lookup	  = tcf_sample_search,
 	.get_psample_group = tcf_sample_get_group,
 	.offload_act_setup    = tcf_sample_offload_act_setup,
 	.size	  = sizeof(struct tcf_sample),
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 17/22] net: sched: act_simple: get rid of tcf_simp_walker and tcf_simp_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (15 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 16/22] net: sched: act_sample: get rid of tcf_sample_walker and tcf_sample_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 18/22] net: sched: act_skbedit: get rid of tcf_skbedit_walker and tcf_skbedit_search Zhengchao Shao
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
simp_net_id when registering act_simp_ops. And then remove the walk
and lookup hook functions in act_simple.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_simple.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 8c1d60bde93e..0091e6cd707b 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -198,33 +198,15 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_simp_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, simp_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, simp_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_simp_ops = {
 	.kind		=	"simple",
 	.id		=	TCA_ID_SIMP,
+	.net_id		=	&simp_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_simp_act,
 	.dump		=	tcf_simp_dump,
 	.cleanup	=	tcf_simp_release,
 	.init		=	tcf_simp_init,
-	.walk		=	tcf_simp_walker,
-	.lookup		=	tcf_simp_search,
 	.size		=	sizeof(struct tcf_defact),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 18/22] net: sched: act_skbedit: get rid of tcf_skbedit_walker and tcf_skbedit_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (16 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 17/22] net: sched: act_simple: get rid of tcf_simp_walker and tcf_simp_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 19/22] net: sched: act_skbmod: get rid of tcf_skbmod_walker and tcf_skbmod_search Zhengchao Shao
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
skbedit_net_id when registering act_skbedit_ops. And then remove the
walk and lookup hook functions in act_skbedit.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_skbedit.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index e3bd11dfe1ca..8dfbfab0b5de 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -347,23 +347,6 @@ static void tcf_skbedit_cleanup(struct tc_action *a)
 		kfree_rcu(params, rcu);
 }
 
-static int tcf_skbedit_walker(struct net *net, struct sk_buff *skb,
-			      struct netlink_callback *cb, int type,
-			      const struct tc_action_ops *ops,
-			      struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, skbedit_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static size_t tcf_skbedit_get_fill_size(const struct tc_action *act)
 {
 	return nla_total_size(sizeof(struct tc_skbedit))
@@ -422,15 +405,14 @@ static int tcf_skbedit_offload_act_setup(struct tc_action *act, void *entry_data
 static struct tc_action_ops act_skbedit_ops = {
 	.kind		=	"skbedit",
 	.id		=	TCA_ID_SKBEDIT,
+	.net_id		=	&skbedit_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_skbedit_act,
 	.stats_update	=	tcf_skbedit_stats_update,
 	.dump		=	tcf_skbedit_dump,
 	.init		=	tcf_skbedit_init,
 	.cleanup	=	tcf_skbedit_cleanup,
-	.walk		=	tcf_skbedit_walker,
 	.get_fill_size	=	tcf_skbedit_get_fill_size,
-	.lookup		=	tcf_skbedit_search,
 	.offload_act_setup =	tcf_skbedit_offload_act_setup,
 	.size		=	sizeof(struct tcf_skbedit),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 19/22] net: sched: act_skbmod: get rid of tcf_skbmod_walker and tcf_skbmod_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (17 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 18/22] net: sched: act_skbedit: get rid of tcf_skbedit_walker and tcf_skbedit_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 20/22] net: sched: act_tunnel_key: get rid of tunnel_key_walker and tunnel_key_search Zhengchao Shao
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
skbmod_net_id when registering act_skbmod_ops. And then remove the
walk and lookup hook functions in act_skbmod.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_skbmod.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index 2083612d8780..ae52e5f175ed 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -276,33 +276,15 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_skbmod_walker(struct net *net, struct sk_buff *skb,
-			     struct netlink_callback *cb, int type,
-			     const struct tc_action_ops *ops,
-			     struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, skbmod_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tcf_skbmod_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, skbmod_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static struct tc_action_ops act_skbmod_ops = {
 	.kind		=	"skbmod",
 	.id		=	TCA_ACT_SKBMOD,
+	.net_id		=	&skbmod_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_skbmod_act,
 	.dump		=	tcf_skbmod_dump,
 	.init		=	tcf_skbmod_init,
 	.cleanup	=	tcf_skbmod_cleanup,
-	.walk		=	tcf_skbmod_walker,
-	.lookup		=	tcf_skbmod_search,
 	.size		=	sizeof(struct tcf_skbmod),
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 20/22] net: sched: act_tunnel_key: get rid of tunnel_key_walker and tunnel_key_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (18 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 19/22] net: sched: act_skbmod: get rid of tcf_skbmod_walker and tcf_skbmod_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 21/22] net: sched: act_vlan: get rid of tcf_vlan_walker and tcf_vlan_search Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api Zhengchao Shao
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
tunnel_key_net_id when registering act_tunnel_key_ops. And then
remove the walk and lookup hook functions in act_tunnel_key.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_tunnel_key.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 856dc23cef8c..47bc251c82ec 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -770,23 +770,6 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tunnel_key_walker(struct net *net, struct sk_buff *skb,
-			     struct netlink_callback *cb, int type,
-			     const struct tc_action_ops *ops,
-			     struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
-static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static void tcf_tunnel_encap_put_tunnel(void *priv)
 {
 	struct ip_tunnel_info *tunnel = priv;
@@ -845,13 +828,12 @@ static int tcf_tunnel_key_offload_act_setup(struct tc_action *act,
 static struct tc_action_ops act_tunnel_key_ops = {
 	.kind		=	"tunnel_key",
 	.id		=	TCA_ID_TUNNEL_KEY,
+	.net_id		=	&tunnel_key_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tunnel_key_act,
 	.dump		=	tunnel_key_dump,
 	.init		=	tunnel_key_init,
 	.cleanup	=	tunnel_key_release,
-	.walk		=	tunnel_key_walker,
-	.lookup		=	tunnel_key_search,
 	.offload_act_setup =	tcf_tunnel_key_offload_act_setup,
 	.size		=	sizeof(struct tcf_tunnel_key),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 21/22] net: sched: act_vlan: get rid of tcf_vlan_walker and tcf_vlan_search
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (19 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 20/22] net: sched: act_tunnel_key: get rid of tunnel_key_walker and tunnel_key_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 11:24 ` [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api Zhengchao Shao
  21 siblings, 0 replies; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Use __tcf_generic_walker() and __tcf_idr_search() helpers by saving
vlan_net_id when registering act_vlan_ops. And then remove the walk
and lookup hook functions in act_vlan.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/sched/act_vlan.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 68b5e772386a..54543a5fac38 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -333,16 +333,6 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
 	return -1;
 }
 
-static int tcf_vlan_walker(struct net *net, struct sk_buff *skb,
-			   struct netlink_callback *cb, int type,
-			   const struct tc_action_ops *ops,
-			   struct netlink_ext_ack *extack)
-{
-	struct tc_action_net *tn = net_generic(net, vlan_net_id);
-
-	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
-}
-
 static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u64 packets,
 				  u64 drops, u64 lastuse, bool hw)
 {
@@ -353,13 +343,6 @@ static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u64 packets,
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
-static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index)
-{
-	struct tc_action_net *tn = net_generic(net, vlan_net_id);
-
-	return tcf_idr_search(tn, a, index);
-}
-
 static size_t tcf_vlan_get_fill_size(const struct tc_action *act)
 {
 	return nla_total_size(sizeof(struct tc_vlan))
@@ -433,15 +416,14 @@ static int tcf_vlan_offload_act_setup(struct tc_action *act, void *entry_data,
 static struct tc_action_ops act_vlan_ops = {
 	.kind		=	"vlan",
 	.id		=	TCA_ID_VLAN,
+	.net_id		=	&vlan_net_id,
 	.owner		=	THIS_MODULE,
 	.act		=	tcf_vlan_act,
 	.dump		=	tcf_vlan_dump,
 	.init		=	tcf_vlan_init,
 	.cleanup	=	tcf_vlan_cleanup,
-	.walk		=	tcf_vlan_walker,
 	.stats_update	=	tcf_vlan_stats_update,
 	.get_fill_size	=	tcf_vlan_get_fill_size,
-	.lookup		=	tcf_vlan_search,
 	.offload_act_setup =	tcf_vlan_offload_act_setup,
 	.size		=	sizeof(struct tcf_vlan),
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api
  2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
                   ` (20 preceding siblings ...)
  2022-09-02 11:24 ` [PATCH net-next 21/22] net: sched: act_vlan: get rid of tcf_vlan_walker and tcf_vlan_search Zhengchao Shao
@ 2022-09-02 11:24 ` Zhengchao Shao
  2022-09-02 14:03   ` Jamal Hadi Salim
  21 siblings, 1 reply; 26+ messages in thread
From: Zhengchao Shao @ 2022-09-02 11:24 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni, jhs,
	xiyou.wangcong, jiri, martin.lau
  Cc: daniel, john.fastabend, ast, andrii, song, yhs, kpsingh, sdf,
	haoluo, jolsa, weiyongjun1, yuehaibing, shaozhengchao

Based on previous patches of this patchset, the walk and lookup hooks in
the tc_action_ops structure are no longer used, and redundant code logic
branches should be removed. tcf_generic_walker() and tcf_idr_search() are
also used only in the act_api.c, change them to static.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 include/net/act_api.h | 10 ----------
 net/sched/act_api.c   | 42 ++++++++++++------------------------------
 2 files changed, 12 insertions(+), 40 deletions(-)

diff --git a/include/net/act_api.h b/include/net/act_api.h
index a79d6e58519e..ebd84ef06b5b 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -118,15 +118,10 @@ struct tc_action_ops {
 		       struct tcf_result *); /* called under RCU BH lock*/
 	int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
 	void	(*cleanup)(struct tc_action *);
-	int     (*lookup)(struct net *net, struct tc_action **a, u32 index);
 	int     (*init)(struct net *net, struct nlattr *nla,
 			struct nlattr *est, struct tc_action **act,
 			struct tcf_proto *tp,
 			u32 flags, struct netlink_ext_ack *extack);
-	int     (*walk)(struct net *, struct sk_buff *,
-			struct netlink_callback *, int,
-			const struct tc_action_ops *,
-			struct netlink_ext_ack *);
 	void	(*stats_update)(struct tc_action *, u64, u64, u64, u64, bool);
 	size_t  (*get_fill_size)(const struct tc_action *act);
 	struct net_device *(*get_dev)(const struct tc_action *a,
@@ -178,11 +173,6 @@ static inline void tc_action_net_exit(struct list_head *net_list,
 	rtnl_unlock();
 }
 
-int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
-		       struct netlink_callback *cb, int type,
-		       const struct tc_action_ops *ops,
-		       struct netlink_ext_ack *extack);
-int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
 int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
 		   struct tc_action **a, const struct tc_action_ops *ops,
 		   int bind, bool cpustats, u32 flags);
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 7063d2004199..2d26aec25e3a 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -636,10 +636,10 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
 	return ret;
 }
 
-int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
-		       struct netlink_callback *cb, int type,
-		       const struct tc_action_ops *ops,
-		       struct netlink_ext_ack *extack)
+static int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
+			      struct netlink_callback *cb, int type,
+			      const struct tc_action_ops *ops,
+			      struct netlink_ext_ack *extack)
 {
 	struct tcf_idrinfo *idrinfo = tn->idrinfo;
 
@@ -653,9 +653,8 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
 		return -EINVAL;
 	}
 }
-EXPORT_SYMBOL(tcf_generic_walker);
 
-int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
+static int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
 {
 	struct tcf_idrinfo *idrinfo = tn->idrinfo;
 	struct tc_action *p;
@@ -674,7 +673,6 @@ int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
 	}
 	return false;
 }
-EXPORT_SYMBOL(tcf_idr_search);
 
 static int __tcf_generic_walker(struct net *net, struct sk_buff *skb,
 				struct netlink_callback *cb, int type,
@@ -945,8 +943,7 @@ int tcf_register_action(struct tc_action_ops *act,
 	struct tc_action_ops *a;
 	int ret;
 
-	if (!act->act || !act->dump || !act->init ||
-	    (!act->net_id && (!act->walk || !act->lookup)))
+	if (!act->act || !act->dump || !act->init || !act->net_id)
 		return -EINVAL;
 
 	/* We have to register pernet ops before making the action ops visible,
@@ -1658,16 +1655,10 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
 		goto err_out;
 	}
 	err = -ENOENT;
-	if (ops->lookup) {
-		if (ops->lookup(net, &a, index) == 0) {
-			NL_SET_ERR_MSG(extack, "TC action with specified index not found");
-			goto err_mod;
-		}
-	} else {
-		if (__tcf_idr_search(net, ops, &a, index) == 0) {
-			NL_SET_ERR_MSG(extack, "TC action with specified index not found");
-			goto err_mod;
-		}
+
+	if (__tcf_idr_search(net, ops, &a, index) == 0) {
+		NL_SET_ERR_MSG(extack, "TC action with specified index not found");
+		goto err_mod;
 	}
 
 	module_put(ops->owner);
@@ -1730,12 +1721,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
 		goto out_module_put;
 	}
 
-	if (ops->walk) {
-		err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
-	} else {
-		err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
-	}
-
+	err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
 	if (err <= 0) {
 		nla_nest_cancel(skb, nest);
 		goto out_module_put;
@@ -2153,11 +2139,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
 	if (nest == NULL)
 		goto out_module_put;
 
-	if (a_o->walk)
-		ret = a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL);
-	else
-		ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
-
+	ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
 	if (ret < 0)
 		goto out_module_put;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action
  2022-09-02 11:24 ` [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Zhengchao Shao
@ 2022-09-02 13:53   ` Jamal Hadi Salim
  0 siblings, 0 replies; 26+ messages in thread
From: Jamal Hadi Salim @ 2022-09-02 13:53 UTC (permalink / raw)
  To: Zhengchao Shao
  Cc: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni,
	xiyou.wangcong, jiri, martin.lau, daniel, john.fastabend, ast,
	andrii, song, yhs, kpsingh, sdf, haoluo, jolsa, weiyongjun1,
	yuehaibing

On Fri, Sep 2, 2022 at 7:22 AM Zhengchao Shao <shaozhengchao@huawei.com> wrote:
>
> Being able to get tc_action_net by using net_id stored in tc_action_ops
> and execute the generic walk/search function, add __tcf_generic_walker()
> and __tcf_idr_search() helpers.
>

These are nice cleanups.
Can you please run all tdc tests for all changes you are making to
the tc subsystem? Maybe do a kindness and add more tests.

Just small  opinions below. Otherwise you can add my ACK.

> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  include/net/act_api.h |  1 +
>  net/sched/act_api.c   | 48 +++++++++++++++++++++++++++++++++++++------
>  2 files changed, 43 insertions(+), 6 deletions(-)
>
> diff --git a/include/net/act_api.h b/include/net/act_api.h
> index 9cf6870b526e..a79d6e58519e 100644
\

> @@ -926,7 +945,8 @@ int tcf_register_action(struct tc_action_ops *act,
>         struct tc_action_ops *a;
>         int ret;
>
> -       if (!act->act || !act->dump || !act->init || !act->walk || !act->lookup)
> +       if (!act->act || !act->dump || !act->init ||
> +           (!act->net_id && (!act->walk || !act->lookup)))

I can understand net_id, but why && (!act->walk || !act->lookup) ?
Assumedly they are now optional, no?


> +       if (ops->walk) {
> +               err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
> +       } else {
> +               err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
> +       }

Bikeshed mod: those braces.

cheers,
jamal

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api
  2022-09-02 11:24 ` [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api Zhengchao Shao
@ 2022-09-02 14:03   ` Jamal Hadi Salim
  2022-09-06 12:20     ` shaozhengchao
  0 siblings, 1 reply; 26+ messages in thread
From: Jamal Hadi Salim @ 2022-09-02 14:03 UTC (permalink / raw)
  To: Zhengchao Shao
  Cc: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni,
	xiyou.wangcong, jiri, martin.lau, daniel, john.fastabend, ast,
	andrii, song, yhs, kpsingh, sdf, haoluo, jolsa, weiyongjun1,
	yuehaibing

On Fri, Sep 2, 2022 at 7:22 AM Zhengchao Shao <shaozhengchao@huawei.com> wrote:
>
> Based on previous patches of this patchset, the walk and lookup hooks in
> the tc_action_ops structure are no longer used, and redundant code logic
> branches should be removed. tcf_generic_walker() and tcf_idr_search() are
> also used only in the act_api.c, change them to static.
>

All the rest look good.
It is possible to have extra computation for a lookup/walk depending on the
action complexity. That was the point of those APIs; however, we could argue
that if a user shows up with those demands then we'll add them then.
If you want to remove the callbacks, why not do them in the first patch?

cheers,
jamal

> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  include/net/act_api.h | 10 ----------
>  net/sched/act_api.c   | 42 ++++++++++++------------------------------
>  2 files changed, 12 insertions(+), 40 deletions(-)
>
> diff --git a/include/net/act_api.h b/include/net/act_api.h
> index a79d6e58519e..ebd84ef06b5b 100644
> --- a/include/net/act_api.h
> +++ b/include/net/act_api.h
> @@ -118,15 +118,10 @@ struct tc_action_ops {
>                        struct tcf_result *); /* called under RCU BH lock*/
>         int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
>         void    (*cleanup)(struct tc_action *);
> -       int     (*lookup)(struct net *net, struct tc_action **a, u32 index);
>         int     (*init)(struct net *net, struct nlattr *nla,
>                         struct nlattr *est, struct tc_action **act,
>                         struct tcf_proto *tp,
>                         u32 flags, struct netlink_ext_ack *extack);
> -       int     (*walk)(struct net *, struct sk_buff *,
> -                       struct netlink_callback *, int,
> -                       const struct tc_action_ops *,
> -                       struct netlink_ext_ack *);
>         void    (*stats_update)(struct tc_action *, u64, u64, u64, u64, bool);
>         size_t  (*get_fill_size)(const struct tc_action *act);
>         struct net_device *(*get_dev)(const struct tc_action *a,
> @@ -178,11 +173,6 @@ static inline void tc_action_net_exit(struct list_head *net_list,
>         rtnl_unlock();
>  }
>
> -int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
> -                      struct netlink_callback *cb, int type,
> -                      const struct tc_action_ops *ops,
> -                      struct netlink_ext_ack *extack);
> -int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
>  int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
>                    struct tc_action **a, const struct tc_action_ops *ops,
>                    int bind, bool cpustats, u32 flags);
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index 7063d2004199..2d26aec25e3a 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -636,10 +636,10 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
>         return ret;
>  }
>
> -int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
> -                      struct netlink_callback *cb, int type,
> -                      const struct tc_action_ops *ops,
> -                      struct netlink_ext_ack *extack)
> +static int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
> +                             struct netlink_callback *cb, int type,
> +                             const struct tc_action_ops *ops,
> +                             struct netlink_ext_ack *extack)
>  {
>         struct tcf_idrinfo *idrinfo = tn->idrinfo;
>
> @@ -653,9 +653,8 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
>                 return -EINVAL;
>         }
>  }
> -EXPORT_SYMBOL(tcf_generic_walker);
>
> -int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
> +static int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
>  {
>         struct tcf_idrinfo *idrinfo = tn->idrinfo;
>         struct tc_action *p;
> @@ -674,7 +673,6 @@ int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
>         }
>         return false;
>  }
> -EXPORT_SYMBOL(tcf_idr_search);
>
>  static int __tcf_generic_walker(struct net *net, struct sk_buff *skb,
>                                 struct netlink_callback *cb, int type,
> @@ -945,8 +943,7 @@ int tcf_register_action(struct tc_action_ops *act,
>         struct tc_action_ops *a;
>         int ret;
>
> -       if (!act->act || !act->dump || !act->init ||
> -           (!act->net_id && (!act->walk || !act->lookup)))
> +       if (!act->act || !act->dump || !act->init || !act->net_id)
>                 return -EINVAL;
>
>         /* We have to register pernet ops before making the action ops visible,
> @@ -1658,16 +1655,10 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
>                 goto err_out;
>         }
>         err = -ENOENT;
> -       if (ops->lookup) {
> -               if (ops->lookup(net, &a, index) == 0) {
> -                       NL_SET_ERR_MSG(extack, "TC action with specified index not found");
> -                       goto err_mod;
> -               }
> -       } else {
> -               if (__tcf_idr_search(net, ops, &a, index) == 0) {
> -                       NL_SET_ERR_MSG(extack, "TC action with specified index not found");
> -                       goto err_mod;
> -               }
> +
> +       if (__tcf_idr_search(net, ops, &a, index) == 0) {
> +               NL_SET_ERR_MSG(extack, "TC action with specified index not found");
> +               goto err_mod;
>         }
>
>         module_put(ops->owner);
> @@ -1730,12 +1721,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
>                 goto out_module_put;
>         }
>
> -       if (ops->walk) {
> -               err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
> -       } else {
> -               err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
> -       }
> -
> +       err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
>         if (err <= 0) {
>                 nla_nest_cancel(skb, nest);
>                 goto out_module_put;
> @@ -2153,11 +2139,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
>         if (nest == NULL)
>                 goto out_module_put;
>
> -       if (a_o->walk)
> -               ret = a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL);
> -       else
> -               ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
> -
> +       ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
>         if (ret < 0)
>                 goto out_module_put;
>
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api
  2022-09-02 14:03   ` Jamal Hadi Salim
@ 2022-09-06 12:20     ` shaozhengchao
  0 siblings, 0 replies; 26+ messages in thread
From: shaozhengchao @ 2022-09-06 12:20 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni,
	xiyou.wangcong, jiri, martin.lau, daniel, john.fastabend, ast,
	andrii, song, yhs, kpsingh, sdf, haoluo, jolsa, weiyongjun1,
	yuehaibing



On 2022/9/2 22:03, Jamal Hadi Salim wrote:
> On Fri, Sep 2, 2022 at 7:22 AM Zhengchao Shao <shaozhengchao@huawei.com> wrote:
>>
>> Based on previous patches of this patchset, the walk and lookup hooks in
>> the tc_action_ops structure are no longer used, and redundant code logic
>> branches should be removed. tcf_generic_walker() and tcf_idr_search() are
>> also used only in the act_api.c, change them to static.
>>
> 
> All the rest look good.
> It is possible to have extra computation for a lookup/walk depending on the
> action complexity. That was the point of those APIs; however, we could argue
> that if a user shows up with those demands then we'll add them then.
> If you want to remove the callbacks, why not do them in the first patch?
> 
> cheers,
> jamal
> 

Hi jamal:
	Thank you for your reply. I have test patchset v2 with TDC action 
module, and they are all passed. Next, I will add some selftest in other 
patchset.
	I will reserve the walk and lookup interfaces and delete them only when 
they are no longer used.
	
Zhengchao Shao
>> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>> ---
>>   include/net/act_api.h | 10 ----------
>>   net/sched/act_api.c   | 42 ++++++++++++------------------------------
>>   2 files changed, 12 insertions(+), 40 deletions(-)
>>
>> diff --git a/include/net/act_api.h b/include/net/act_api.h
>> index a79d6e58519e..ebd84ef06b5b 100644
>> --- a/include/net/act_api.h
>> +++ b/include/net/act_api.h
>> @@ -118,15 +118,10 @@ struct tc_action_ops {
>>                         struct tcf_result *); /* called under RCU BH lock*/
>>          int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
>>          void    (*cleanup)(struct tc_action *);
>> -       int     (*lookup)(struct net *net, struct tc_action **a, u32 index);
>>          int     (*init)(struct net *net, struct nlattr *nla,
>>                          struct nlattr *est, struct tc_action **act,
>>                          struct tcf_proto *tp,
>>                          u32 flags, struct netlink_ext_ack *extack);
>> -       int     (*walk)(struct net *, struct sk_buff *,
>> -                       struct netlink_callback *, int,
>> -                       const struct tc_action_ops *,
>> -                       struct netlink_ext_ack *);
>>          void    (*stats_update)(struct tc_action *, u64, u64, u64, u64, bool);
>>          size_t  (*get_fill_size)(const struct tc_action *act);
>>          struct net_device *(*get_dev)(const struct tc_action *a,
>> @@ -178,11 +173,6 @@ static inline void tc_action_net_exit(struct list_head *net_list,
>>          rtnl_unlock();
>>   }
>>
>> -int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
>> -                      struct netlink_callback *cb, int type,
>> -                      const struct tc_action_ops *ops,
>> -                      struct netlink_ext_ack *extack);
>> -int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
>>   int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
>>                     struct tc_action **a, const struct tc_action_ops *ops,
>>                     int bind, bool cpustats, u32 flags);
>> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
>> index 7063d2004199..2d26aec25e3a 100644
>> --- a/net/sched/act_api.c
>> +++ b/net/sched/act_api.c
>> @@ -636,10 +636,10 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
>>          return ret;
>>   }
>>
>> -int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
>> -                      struct netlink_callback *cb, int type,
>> -                      const struct tc_action_ops *ops,
>> -                      struct netlink_ext_ack *extack)
>> +static int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
>> +                             struct netlink_callback *cb, int type,
>> +                             const struct tc_action_ops *ops,
>> +                             struct netlink_ext_ack *extack)
>>   {
>>          struct tcf_idrinfo *idrinfo = tn->idrinfo;
>>
>> @@ -653,9 +653,8 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
>>                  return -EINVAL;
>>          }
>>   }
>> -EXPORT_SYMBOL(tcf_generic_walker);
>>
>> -int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
>> +static int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
>>   {
>>          struct tcf_idrinfo *idrinfo = tn->idrinfo;
>>          struct tc_action *p;
>> @@ -674,7 +673,6 @@ int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
>>          }
>>          return false;
>>   }
>> -EXPORT_SYMBOL(tcf_idr_search);
>>
>>   static int __tcf_generic_walker(struct net *net, struct sk_buff *skb,
>>                                  struct netlink_callback *cb, int type,
>> @@ -945,8 +943,7 @@ int tcf_register_action(struct tc_action_ops *act,
>>          struct tc_action_ops *a;
>>          int ret;
>>
>> -       if (!act->act || !act->dump || !act->init ||
>> -           (!act->net_id && (!act->walk || !act->lookup)))
>> +       if (!act->act || !act->dump || !act->init || !act->net_id)
>>                  return -EINVAL;
>>
>>          /* We have to register pernet ops before making the action ops visible,
>> @@ -1658,16 +1655,10 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
>>                  goto err_out;
>>          }
>>          err = -ENOENT;
>> -       if (ops->lookup) {
>> -               if (ops->lookup(net, &a, index) == 0) {
>> -                       NL_SET_ERR_MSG(extack, "TC action with specified index not found");
>> -                       goto err_mod;
>> -               }
>> -       } else {
>> -               if (__tcf_idr_search(net, ops, &a, index) == 0) {
>> -                       NL_SET_ERR_MSG(extack, "TC action with specified index not found");
>> -                       goto err_mod;
>> -               }
>> +
>> +       if (__tcf_idr_search(net, ops, &a, index) == 0) {
>> +               NL_SET_ERR_MSG(extack, "TC action with specified index not found");
>> +               goto err_mod;
>>          }
>>
>>          module_put(ops->owner);
>> @@ -1730,12 +1721,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
>>                  goto out_module_put;
>>          }
>>
>> -       if (ops->walk) {
>> -               err = ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack);
>> -       } else {
>> -               err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
>> -       }
>> -
>> +       err = __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack);
>>          if (err <= 0) {
>>                  nla_nest_cancel(skb, nest);
>>                  goto out_module_put;
>> @@ -2153,11 +2139,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
>>          if (nest == NULL)
>>                  goto out_module_put;
>>
>> -       if (a_o->walk)
>> -               ret = a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL);
>> -       else
>> -               ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
>> -
>> +       ret = __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL);
>>          if (ret < 0)
>>                  goto out_module_put;
>>
>> --
>> 2.17.1
>>
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2022-09-06 12:25 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02 11:24 [PATCH net-next 00/22] refactor the walk and lookup hook functions in tc_action_ops Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Zhengchao Shao
2022-09-02 13:53   ` Jamal Hadi Salim
2022-09-02 11:24 ` [PATCH net-next 02/22] net: sched: act_bpf: get rid of tcf_bpf_walker and tcf_bpf_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 03/22] net: sched: act_connmark: get rid of tcf_connmark_walker and tcf_connmark_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 04/22] net: sched: act_csum: get rid of tcf_csum_walker and tcf_csum_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 05/22] net: sched: act_ct: get rid of tcf_ct_walker and tcf_ct_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 06/22] net: sched: act_ctinfo: get rid of tcf_ctinfo_walker and tcf_ctinfo_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 07/22] net: sched: act_gact: get rid of tcf_gact_walker and tcf_gact_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 08/22] net: sched: act_gate: get rid of tcf_gate_walker and tcf_gate_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 09/22] net: sched: act_ife: get rid of tcf_ife_walker and tcf_ife_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 10/22] net: sched: act_ipt: get rid of tcf_ipt_walker/tcf_xt_walker and tcf_ipt_search/tcf_xt_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 11/22] net: sched: act_mirred: get rid of tcf_mirred_walker and tcf_mirred_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 12/22] net: sched: act_mpls: get rid of tcf_mpls_walker and tcf_mpls_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 13/22] net: sched: act_nat: get rid of tcf_nat_walker and tcf_nat_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 14/22] net: sched: act_pedit: get rid of tcf_pedit_walker and tcf_pedit_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 15/22] net: sched: act_police: get rid of tcf_police_walker and tcf_police_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 16/22] net: sched: act_sample: get rid of tcf_sample_walker and tcf_sample_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 17/22] net: sched: act_simple: get rid of tcf_simp_walker and tcf_simp_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 18/22] net: sched: act_skbedit: get rid of tcf_skbedit_walker and tcf_skbedit_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 19/22] net: sched: act_skbmod: get rid of tcf_skbmod_walker and tcf_skbmod_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 20/22] net: sched: act_tunnel_key: get rid of tunnel_key_walker and tunnel_key_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 21/22] net: sched: act_vlan: get rid of tcf_vlan_walker and tcf_vlan_search Zhengchao Shao
2022-09-02 11:24 ` [PATCH net-next 22/22] net: sched: act: remove redundant code in act_api Zhengchao Shao
2022-09-02 14:03   ` Jamal Hadi Salim
2022-09-06 12:20     ` shaozhengchao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).