All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlad Buslov <vladbu@nvidia.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: <netdev@vger.kernel.org>, <kernel@mojatatu.com>,
	<deb.chatterjee@intel.com>, <anjali.singhai@intel.com>,
	<namrata.limaye@intel.com>, <khalidm@nvidia.com>,
	<tom@sipanda.io>, <pratyush@sipanda.io>, <jiri@resnulli.us>,
	<xiyou.wangcong@gmail.com>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<simon.horman@corigine.com>
Subject: Re: [PATCH net-next RFC 01/20] net/sched: act_api: change act_base into an IDR
Date: Wed, 25 Jan 2023 18:48:57 +0200	[thread overview]
Message-ID: <87k01ad01q.fsf@nvidia.com> (raw)
In-Reply-To: <20230124170510.316970-1-jhs@mojatatu.com>


On Tue 24 Jan 2023 at 12:04, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> 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;

Hi Jamal,

Since TCA_ID_DYN is exposed to userspace and this code expects to use
the whole range of [TCA_ID_DYN, TCA_ID_MAX] for dynamic actions any new
action added after that will have two choices:

- Insert future TCA_ID_*NEW_ACTION* before TCA_ID_DYN in the enum tca_id
in order for this code to continue to work (probably breaking userspace
code compiled for previous kernels).

- Modify this code to allocate dynamic action id from empty range
following new action enum value, which is not ideal.

Maybe consider defining TCA_ID_DYN=128 in order to leave some space for
new actions to be added before it without affecting the userspace?

> +
> +		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;


  parent reply	other threads:[~2023-01-25 16:58 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Vlad Buslov [this message]
2023-01-26 12:37   ` [PATCH net-next RFC 01/20] net/sched: act_api: change act_base into an IDR 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=87k01ad01q.fsf@nvidia.com \
    --to=vladbu@nvidia.com \
    --cc=anjali.singhai@intel.com \
    --cc=davem@davemloft.net \
    --cc=deb.chatterjee@intel.com \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kernel@mojatatu.com \
    --cc=khalidm@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=namrata.limaye@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pratyush@sipanda.io \
    --cc=simon.horman@corigine.com \
    --cc=tom@sipanda.io \
    --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 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.