All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next RFC 01/20] net/sched: act_api: change act_base into an IDR
@ 2023-01-24 17:04 Jamal Hadi Salim
  2023-01-24 17:04 ` [PATCH net-next RFC 02/20] net/sched: act_api: increase action kind string length Jamal Hadi Salim
                   ` (19 more replies)
  0 siblings, 20 replies; 42+ messages in thread
From: Jamal Hadi Salim @ 2023-01-24 17:04 UTC (permalink / raw)
  To: netdev
  Cc: kernel, deb.chatterjee, anjali.singhai, namrata.limaye, khalidm,
	tom, pratyush, jiri, xiyou.wangcong, davem, edumazet, kuba,
	pabeni, vladbu, simon.horman

Convert act_base from a list to an IDR.

With the introduction of P4TC action templates, we introduce the concept of
dynamically creating actions on the fly. Dynamic action IDs are not statically
defined (as was the case previously) and are therefore harder to manage within
existing linked list approach. We convert to IDR because it has built in ID
management which we would have to re-invent with linked lists.

Co-developed-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Co-developed-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 include/uapi/linux/pkt_cls.h |  1 +
 net/sched/act_api.c          | 39 +++++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 648a82f32..4d716841c 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -139,6 +139,7 @@ enum tca_id {
 	TCA_ID_MPLS,
 	TCA_ID_CT,
 	TCA_ID_GATE,
+	TCA_ID_DYN,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index cd09ef49d..811dddc3b 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -890,7 +890,7 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
 }
 EXPORT_SYMBOL(tcf_idrinfo_destroy);
 
-static LIST_HEAD(act_base);
+static DEFINE_IDR(act_base);
 static DEFINE_RWLOCK(act_mod_lock);
 /* since act ops id is stored in pernet subsystem list,
  * then there is no way to walk through only all the action
@@ -949,7 +949,6 @@ static void tcf_pernet_del_id_list(unsigned int id)
 int tcf_register_action(struct tc_action_ops *act,
 			struct pernet_operations *ops)
 {
-	struct tc_action_ops *a;
 	int ret;
 
 	if (!act->act || !act->dump || !act->init)
@@ -970,13 +969,24 @@ int tcf_register_action(struct tc_action_ops *act,
 	}
 
 	write_lock(&act_mod_lock);
-	list_for_each_entry(a, &act_base, head) {
-		if (act->id == a->id || (strcmp(act->kind, a->kind) == 0)) {
+	if (act->id) {
+		if (idr_find(&act_base, act->id)) {
 			ret = -EEXIST;
 			goto err_out;
 		}
+		ret = idr_alloc_u32(&act_base, act, &act->id, act->id,
+				    GFP_ATOMIC);
+		if (ret < 0)
+			goto err_out;
+	} else {
+		/* Only dynamic actions will require ID generation */
+		act->id = TCA_ID_DYN;
+
+		ret = idr_alloc_u32(&act_base, act, &act->id, TCA_ID_MAX,
+				    GFP_ATOMIC);
+		if (ret < 0)
+			goto err_out;
 	}
-	list_add_tail(&act->head, &act_base);
 	write_unlock(&act_mod_lock);
 
 	return 0;
@@ -994,17 +1004,12 @@ EXPORT_SYMBOL(tcf_register_action);
 int tcf_unregister_action(struct tc_action_ops *act,
 			  struct pernet_operations *ops)
 {
-	struct tc_action_ops *a;
-	int err = -ENOENT;
+	int err = 0;
 
 	write_lock(&act_mod_lock);
-	list_for_each_entry(a, &act_base, head) {
-		if (a == act) {
-			list_del(&act->head);
-			err = 0;
-			break;
-		}
-	}
+	if (!idr_remove(&act_base, act->id))
+		err = -EINVAL;
+
 	write_unlock(&act_mod_lock);
 	if (!err) {
 		unregister_pernet_subsys(ops);
@@ -1019,10 +1024,11 @@ EXPORT_SYMBOL(tcf_unregister_action);
 static struct tc_action_ops *tc_lookup_action_n(char *kind)
 {
 	struct tc_action_ops *a, *res = NULL;
+	unsigned long tmp, id;
 
 	if (kind) {
 		read_lock(&act_mod_lock);
-		list_for_each_entry(a, &act_base, head) {
+		idr_for_each_entry_ul(&act_base, a, tmp, id) {
 			if (strcmp(kind, a->kind) == 0) {
 				if (try_module_get(a->owner))
 					res = a;
@@ -1038,10 +1044,11 @@ static struct tc_action_ops *tc_lookup_action_n(char *kind)
 static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
 {
 	struct tc_action_ops *a, *res = NULL;
+	unsigned long tmp, id;
 
 	if (kind) {
 		read_lock(&act_mod_lock);
-		list_for_each_entry(a, &act_base, head) {
+		idr_for_each_entry_ul(&act_base, a, tmp, id) {
 			if (nla_strcmp(kind, a->kind) == 0) {
 				if (try_module_get(a->owner))
 					res = a;
-- 
2.34.1


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

end of thread, other threads:[~2023-06-05 14:46 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 17:04 [PATCH net-next RFC 01/20] net/sched: act_api: change act_base into an IDR Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 02/20] net/sched: act_api: increase action kind string length Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 03/20] net/sched: act_api: increase TCA_ID_MAX Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 04/20] net/sched: act_api: add init_ops to struct tc_action_op Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 05/20] net/sched: act_api: introduce tc_lookup_action_byid() Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 06/20] net/sched: act_api: export generic tc action searcher Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 07/20] net/sched: act_api: create and export __tcf_register_action Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 08/20] net/sched: act_api: add struct p4tc_action_ops as a parameter to lookup callback Jamal Hadi Salim
2023-01-24 17:04 ` [PATCH net-next RFC 09/20] net: introduce rcu_replace_pointer_rtnl Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 10/20] net/kparser: add kParser Jamal Hadi Salim
2023-01-24 19:26   ` kernel test robot
2023-01-24 21:19   ` kernel test robot
2023-01-25  2:48   ` kernel test robot
2023-01-24 17:05 ` [PATCH net-next RFC 11/20] p4tc: add P4 data types Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 12/20] p4tc: add pipeline create, get, update, delete Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 13/20] p4tc: add metadata create, update, delete, get, flush and dump Jamal Hadi Salim
2023-01-24 20:27   ` kernel test robot
2023-06-05 10:22   ` Simon Horman
2023-06-05 14:45     ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 14/20] p4tc: add header field create, get, delete, " Jamal Hadi Salim
2023-01-24 21:29   ` kernel test robot
2023-01-25 21:39   ` Vlad Buslov
2023-01-26 14:54     ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 15/20] p4tc: add action template create, update, delete, get, " Jamal Hadi Salim
2023-01-25 21:10   ` Vlad Buslov
2023-01-26 15:28     ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 16/20] p4tc: add table " Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 17/20] p4tc: add table entry create, update, get, delete, " Jamal Hadi Salim
2023-01-25 21:20   ` Vlad Buslov
2023-01-26 15:45     ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 18/20] p4tc: add register create, update, delete, get, " Jamal Hadi Salim
2023-01-25 21:44   ` Vlad Buslov
2023-01-26 15:49     ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 19/20] p4tc: add dynamic action commands Jamal Hadi Salim
2023-01-24 22:00   ` kernel test robot
2023-01-25 21:29   ` Vlad Buslov
2023-01-26 12:52     ` Jamal Hadi Salim
2023-01-26 17:04       ` Vlad Buslov
2023-01-26 19:01         ` Jamal Hadi Salim
2023-01-24 17:05 ` [PATCH net-next RFC 20/20] p4tc: add P4 classifier Jamal Hadi Salim
2023-01-25 16:48 ` [PATCH net-next RFC 01/20] net/sched: act_api: change act_base into an IDR Vlad Buslov
2023-01-26 12:37   ` Jamal Hadi Salim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.