bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamal Hadi Salim <jhs@mojatatu.com>
To: netdev@vger.kernel.org
Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com,
	namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com,
	Mahesh.Shirshyad@amd.com, tomasz.osinski@intel.com,
	jiri@resnulli.us, xiyou.wangcong@gmail.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	vladbu@nvidia.com, horms@kernel.org, khalidm@nvidia.com,
	toke@redhat.com, victor@mojatatu.com, pctammela@mojatatu.com,
	bpf@vger.kernel.org
Subject: [PATCH net-next v16  03/15] net/sched: act_api: Update tc_action_ops to account for P4 actions
Date: Wed, 10 Apr 2024 10:01:29 -0400	[thread overview]
Message-ID: <20240410140141.495384-4-jhs@mojatatu.com> (raw)
In-Reply-To: <20240410140141.495384-1-jhs@mojatatu.com>

The initialisation of P4TC action instances require access to a struct
p4tc_act (which appears in later patches) to help us to retrieve
information like the P4 action parameters etc. In order to retrieve
struct p4tc_act we need the pipeline name or id and the action name or id.
Also recall that P4TC action IDs are P4 and are net namespace specific and
not global like standard tc actions.
The init callback from tc_action_ops parameters had no way of
supplying us that information. To solve this issue, we decided to create a
new tc_action_ops callback (init_ops), that provies us with the
tc_action_ops  struct which then provides us with the pipeline and action
name. In addition we add a new refcount to struct tc_action_ops called
dyn_ref, which accounts for how many action instances we have of a specific
action.

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>
Reviewed-by: Vlad Buslov <vladbu@nvidia.com>
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 include/net/act_api.h |  6 ++++++
 net/sched/act_api.c   | 14 +++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/net/act_api.h b/include/net/act_api.h
index c839ff57c1a8..59f62c2a6ef2 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -120,6 +120,12 @@ struct tc_action_ops {
 			struct nlattr *est, struct tc_action **act,
 			struct tcf_proto *tp,
 			u32 flags, struct netlink_ext_ack *extack);
+	/* This should be merged with the original init action */
+	int     (*init_ops)(struct net *net, struct nlattr *nla,
+			    struct nlattr *est, struct tc_action **act,
+			   struct tcf_proto *tp,
+			   const struct tc_action_ops *ops, u32 flags,
+			   struct netlink_ext_ack *extack);
 	int     (*walk)(struct net *, struct sk_buff *,
 			struct netlink_callback *, int,
 			const struct tc_action_ops *,
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 87eb09121ca4..c094a57ab7df 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -1044,7 +1044,7 @@ int tcf_register_action(struct tc_action_ops *act,
 	struct tc_action_ops *a;
 	int ret;
 
-	if (!act->act || !act->dump || !act->init)
+	if (!act->act || !act->dump || (!act->init && !act->init_ops))
 		return -EINVAL;
 
 	/* We have to register pernet ops before making the action ops visible,
@@ -1517,8 +1517,16 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
 			}
 		}
 
-		err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, &a, tp,
-				userflags.value | flags, extack);
+		/* When we arrive here we guarantee that a_o->init or
+		 * a_o->init_ops exist.
+		 */
+		if (a_o->init)
+			err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, &a, tp,
+					userflags.value | flags, extack);
+		else
+			err = a_o->init_ops(net, tb[TCA_ACT_OPTIONS], est, &a,
+					    tp, a_o, userflags.value | flags,
+					    extack);
 	} else {
 		err = a_o->init(net, nla, est, &a, tp, userflags.value | flags,
 				extack);
-- 
2.34.1


  parent reply	other threads:[~2024-04-10 14:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 14:01 [PATCH net-next v16 00/15] Introducing P4TC (series 1) Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 01/15] net: sched: act_api: Introduce P4 actions list Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 02/15] net/sched: act_api: increase action kind string length Jamal Hadi Salim
2024-04-10 14:01 ` Jamal Hadi Salim [this message]
2024-04-10 14:01 ` [PATCH net-next v16 04/15] net/sched: act_api: add struct p4tc_action_ops as a parameter to lookup callback Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 05/15] net: sched: act_api: Add support for preallocated P4 action instances Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 06/15] p4tc: add P4 data types Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 07/15] p4tc: add template API Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 08/15] p4tc: add template pipeline create, get, update, delete Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 09/15] p4tc: add template action create, update, delete, get, flush and dump Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 10/15] p4tc: add runtime action support Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 11/15] p4tc: add template table create, update, delete, get, flush and dump Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 12/15] p4tc: add runtime table entry create and update Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 13/15] p4tc: add runtime table entry get, delete, flush and dump Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 14/15] p4tc: add set of P4TC table kfuncs Jamal Hadi Salim
2024-04-10 14:01 ` [PATCH net-next v16 15/15] p4tc: add P4 classifier Jamal Hadi Salim
2024-04-11 14:07 ` [PATCH net-next v16 00/15] Introducing P4TC (series 1) Paolo Abeni
2024-04-11 16:24   ` Jamal Hadi Salim
2024-04-19 12:08     ` Jamal Hadi Salim
2024-04-19 14:23       ` Alexei Starovoitov
2024-04-19 14:33         ` Jamal Hadi Salim
2024-04-19 14:37           ` Alexei Starovoitov
2024-04-19 14:45             ` Jamal Hadi Salim
2024-04-19 14:49               ` Alexei Starovoitov
2024-04-19 14:55                 ` Jamal Hadi Salim
2024-04-19 17:20       ` Paolo Abeni
2024-04-19 18:01         ` Jamal Hadi Salim
2024-04-26 17:12           ` Jamal Hadi Salim
2024-04-26 17:21             ` Paolo Abeni
2024-04-26 17:43               ` Alexei Starovoitov
2024-04-26 18:03                 ` Jamal Hadi Salim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410140141.495384-4-jhs@mojatatu.com \
    --to=jhs@mojatatu.com \
    --cc=Mahesh.Shirshyad@amd.com \
    --cc=anjali.singhai@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=deb.chatterjee@intel.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=khalidm@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mleitner@redhat.com \
    --cc=namrata.limaye@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pctammela@mojatatu.com \
    --cc=toke@redhat.com \
    --cc=tom@sipanda.io \
    --cc=tomasz.osinski@intel.com \
    --cc=victor@mojatatu.com \
    --cc=vladbu@nvidia.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).