netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: Vlad Buslov <vladbu@mellanox.com>
Cc: jiri@resnulli.us, netdev@vger.kernel.org, jhs@mojatatu.com,
	xiyou.wangcong@gmail.com, davem@davemloft.net, ast@kernel.org,
	daniel@iogearbox.net, kliteyn@mellanox.com
Subject: Re: [PATCH v3 07/11] net: sched: implement reference counted action release
Date: Mon, 28 May 2018 18:38:36 -0300	[thread overview]
Message-ID: <20180528213836.GM3787@localhost.localdomain> (raw)
In-Reply-To: <1527455849-22327-8-git-send-email-vladbu@mellanox.com>

On Mon, May 28, 2018 at 12:17:25AM +0300, Vlad Buslov wrote:
> Implement helper delete function that uses new action ops 'delete', instead
> of destroying action directly. This is required so act API could delete
> actions by index, without holding any references to action that is being
> deleted.
> 
> Implement function __tcf_action_put() that releases reference to action and
> frees it, if necessary. Refactor action deletion code to use new put
> function and not to rely on rtnl lock. Remove rtnl lock assertions that are
> no longer needed.
> 
> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>

Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>

> ---
> Changes from V1 to V2:
> - Removed redundant actions ops lookup during delete.
> - Assume all actions have delete implemented and don't check for it
>   explicitly.
> - Rearrange variable definitions in tcf_action_delete.
> 
>  net/sched/act_api.c | 84 +++++++++++++++++++++++++++++++++++++++--------------
>  net/sched/cls_api.c |  1 -
>  2 files changed, 62 insertions(+), 23 deletions(-)
> 
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index 0f31f09946ab..a023873db713 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -90,21 +90,39 @@ static void free_tcf(struct tc_action *p)
>  	kfree(p);
>  }
>  
> -static void tcf_idr_remove(struct tcf_idrinfo *idrinfo, struct tc_action *p)
> +static void tcf_action_cleanup(struct tc_action *p)
>  {
> -	spin_lock(&idrinfo->lock);
> -	idr_remove(&idrinfo->action_idr, p->tcfa_index);
> -	spin_unlock(&idrinfo->lock);
> +	if (p->ops->cleanup)
> +		p->ops->cleanup(p);
> +
>  	gen_kill_estimator(&p->tcfa_rate_est);
>  	free_tcf(p);
>  }
>  
> +static int __tcf_action_put(struct tc_action *p, bool bind)
> +{
> +	struct tcf_idrinfo *idrinfo = p->idrinfo;
> +
> +	if (refcount_dec_and_lock(&p->tcfa_refcnt, &idrinfo->lock)) {
> +		if (bind)
> +			atomic_dec(&p->tcfa_bindcnt);
> +		idr_remove(&idrinfo->action_idr, p->tcfa_index);
> +		spin_unlock(&idrinfo->lock);
> +
> +		tcf_action_cleanup(p);
> +		return 1;
> +	}
> +
> +	if (bind)
> +		atomic_dec(&p->tcfa_bindcnt);
> +
> +	return 0;
> +}
> +
>  int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
>  {
>  	int ret = 0;
>  
> -	ASSERT_RTNL();
> -
>  	/* Release with strict==1 and bind==0 is only called through act API
>  	 * interface (classifiers always bind). Only case when action with
>  	 * positive reference count and zero bind count can exist is when it was
> @@ -118,18 +136,11 @@ int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
>  	 * are acceptable.
>  	 */
>  	if (p) {
> -		if (bind)
> -			atomic_dec(&p->tcfa_bindcnt);
> -		else if (strict && atomic_read(&p->tcfa_bindcnt) > 0)
> +		if (!bind && strict && atomic_read(&p->tcfa_bindcnt) > 0)
>  			return -EPERM;
>  
> -		if (atomic_read(&p->tcfa_bindcnt) <= 0 &&
> -		    refcount_dec_and_test(&p->tcfa_refcnt)) {
> -			if (p->ops->cleanup)
> -				p->ops->cleanup(p);
> -			tcf_idr_remove(p->idrinfo, p);
> +		if (__tcf_action_put(p, bind))
>  			ret = ACT_P_DELETED;
> -		}
>  	}
>  
>  	return ret;
> @@ -340,11 +351,7 @@ int tcf_idr_delete_index(struct tc_action_net *tn, u32 index)
>  						p->tcfa_index));
>  			spin_unlock(&idrinfo->lock);
>  
> -			if (p->ops->cleanup)
> -				p->ops->cleanup(p);
> -
> -			gen_kill_estimator(&p->tcfa_rate_est);
> -			free_tcf(p);
> +			tcf_action_cleanup(p);
>  			module_put(owner);
>  			return 0;
>  		}
> @@ -615,6 +622,11 @@ int tcf_action_destroy(struct list_head *actions, int bind)
>  	return ret;
>  }
>  
> +static int tcf_action_put(struct tc_action *p)
> +{
> +	return __tcf_action_put(p, false);
> +}
> +
>  int
>  tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
>  {
> @@ -1092,6 +1104,35 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
>  	return err;
>  }
>  
> +static int tcf_action_delete(struct net *net, struct list_head *actions,
> +			     struct netlink_ext_ack *extack)
> +{
> +	struct tc_action *a, *tmp;
> +	u32 act_index;
> +	int ret;
> +
> +	list_for_each_entry_safe(a, tmp, actions, list) {
> +		const struct tc_action_ops *ops = a->ops;
> +
> +		/* Actions can be deleted concurrently so we must save their
> +		 * type and id to search again after reference is released.
> +		 */
> +		act_index = a->tcfa_index;
> +
> +		list_del(&a->list);
> +		if (tcf_action_put(a)) {
> +			/* last reference, action was deleted concurrently */
> +			module_put(ops->owner);
> +		} else  {
> +			/* now do the delete */
> +			ret = ops->delete(net, act_index);
> +			if (ret < 0)
> +				return ret;
> +		}
> +	}
> +	return 0;
> +}
> +
>  static int
>  tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
>  	       u32 portid, size_t attr_size, struct netlink_ext_ack *extack)
> @@ -1112,7 +1153,7 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
>  	}
>  
>  	/* now do the delete */
> -	ret = tcf_action_destroy(actions, 0);
> +	ret = tcf_action_delete(net, actions, extack);
>  	if (ret < 0) {
>  		NL_SET_ERR_MSG(extack, "Failed to delete TC action");
>  		kfree_skb(skb);
> @@ -1164,7 +1205,6 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
>  	if (event == RTM_GETACTION)
>  		ret = tcf_get_notify(net, portid, n, &actions, event, extack);
>  	else { /* delete */
> -		cleanup_a(&actions, 1); /* lookup took reference */
>  		ret = tcf_del_notify(net, n, &actions, portid, attr_size, extack);
>  		if (ret)
>  			goto err;
> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
> index efbf01ce14c2..dd37d0ae3fce 100644
> --- a/net/sched/cls_api.c
> +++ b/net/sched/cls_api.c
> @@ -1417,7 +1417,6 @@ void tcf_exts_destroy(struct tcf_exts *exts)
>  #ifdef CONFIG_NET_CLS_ACT
>  	LIST_HEAD(actions);
>  
> -	ASSERT_RTNL();
>  	tcf_exts_to_list(exts, &actions);
>  	tcf_action_destroy(&actions, TCA_ACT_UNBIND);
>  	kfree(exts->actions);
> -- 
> 2.7.5
> 

  parent reply	other threads:[~2018-05-28 21:38 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-27 16:41 [PATCH v2 00/11] Modify action API for implementing lockless actions Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 01/11] net: sched: use rcu for action cookie update Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 02/11] net: sched: change type of reference and bind counters Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 03/11] net: sched: implement unlocked action init API Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 04/11] net: sched: always take reference to action Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 05/11] net: sched: implement action API that deletes action by index Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 06/11] net: sched: add 'delete' function to action ops Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 07/11] net: sched: implement reference counted action release Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 08/11] net: sched: don't release reference on action overwrite Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 09/11] net: sched: use reference counting action init Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 10/11] net: sched: atomically check-allocate action Vlad Buslov
2018-05-27 16:41 ` [PATCH v2 11/11] net: sched: change action API to use array of pointers to actions Vlad Buslov
2018-05-27 17:57 ` [PATCH v2 00/11] Modify action API for implementing lockless actions Jiri Pirko
2018-05-27 21:17   ` [PATCH v3 " Vlad Buslov
2018-05-27 21:17     ` [PATCH v3 01/11] net: sched: use rcu for action cookie update Vlad Buslov
2018-05-28 21:37       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 02/11] net: sched: change type of reference and bind counters Vlad Buslov
2018-05-28 21:37       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 03/11] net: sched: implement unlocked action init API Vlad Buslov
2018-05-28 14:17       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 04/11] net: sched: always take reference to action Vlad Buslov
2018-05-28 14:19       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 05/11] net: sched: implement action API that deletes action by index Vlad Buslov
2018-05-28 14:21       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 06/11] net: sched: add 'delete' function to action ops Vlad Buslov
2018-05-28 14:21       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 07/11] net: sched: implement reference counted action release Vlad Buslov
2018-05-28 14:30       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner [this message]
2018-05-27 21:17     ` [PATCH v3 08/11] net: sched: don't release reference on action overwrite Vlad Buslov
2018-05-28 14:27       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 09/11] net: sched: use reference counting action init Vlad Buslov
2018-05-28 15:08       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 10/11] net: sched: atomically check-allocate action Vlad Buslov
2018-05-28 15:24       ` Jiri Pirko
2018-05-28 21:38       ` Marcelo Ricardo Leitner
2018-05-27 21:17     ` [PATCH v3 11/11] net: sched: change action API to use array of pointers to actions Vlad Buslov
2018-05-28 21:31       ` Marcelo Ricardo Leitner
2018-05-29 10:25         ` Vlad Buslov
2018-05-30 20:37       ` Jiri Pirko
2018-05-29  4:26     ` [PATCH v3 00/11] Modify action API for implementing lockless actions Cong Wang
2018-05-29 10:20       ` Vlad Buslov

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=20180528213836.GM3787@localhost.localdomain \
    --to=marcelo.leitner@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kliteyn@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=vladbu@mellanox.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).