Skip to contentSkip to conversation

pull request (net-next): ipsec-next 2015-05-28

PATCH New Steffen Klassert 2 participants 9 messages May 28, 2015 – May 29, 2015

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

1) Remove xfrm_queue_purge as this is the same as skb_queue_purge.

2) Optimize policy and state walk.

3) Use a sane return code if afinfo registration fails.

4) Only check fori a acquire state if the state is not valid.

5) Remove a unnecessary NULL check before xfrm_pol_hold as it checks the input for NULL.

6) Return directly if the xfrm hold queue is empty, avoid to take a lock as it is nothing to do in this case.

7) Optimize the inexact policy search and allow for matching of policies with priority ~0U.

All from Li RongQing.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 04b7fe6a4a231871ef681bc95e08fe66992f7b1f:

Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide (2015-04-17 16:36:59 -0400)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master

for you to fetch changes up to 8faf491e642011f449d6405be52bedb70964aed6:

xfrm: optimise to search the inexact policy list (2015-05-18 10:31:56 +0200)

----------------------------------------------------------------
Li RongQing (7):
xfrm: remove the xfrm_queue_purge definition
xfrm: optimise the use of walk list header in xfrm_policy/state_walk
xfrm: fix the return code when xfrm_*_register_afinfo failed
xfrm: slightly optimise xfrm_input
xfrm: remove the unnecessary checking before call xfrm_pol_hold
xfrm: move the checking for old xfrm_policy hold_queue to beginning
xfrm: optimise to search the inexact policy list

 net/xfrm/xfrm_input.c  | 12 ++++++------
 net/xfrm/xfrm_policy.c | 42 ++++++++++++++++++++----------------------
 net/xfrm/xfrm_state.c  |  4 ++--
 3 files changed, 28 insertions(+), 30 deletions(-)
author maintainer
#1 lore raw

PATCH 1/7 xfrm: remove the xfrm_queue_purge definition

From: Li RongQing <[email protected]>

The task of xfrm_queue_purge is same as skb_queue_purge, so remove it

---
 net/xfrm/xfrm_policy.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
net/xfrm/xfrm_policy.c +2 -10
index 638af06..d8c35ad 100644
@@ -315,14 +315,6 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 }
 EXPORT_SYMBOL(xfrm_policy_destroy);
 
-static void xfrm_queue_purge(struct sk_buff_head *list)
-{
-	struct sk_buff *skb;
-
-	while ((skb = skb_dequeue(list)) != NULL)
-		kfree_skb(skb);
-}
-
 /* Rule must be locked. Release descentant resources, announce
  * entry dead. The rule must be unlinked from lists to the moment.
  */
@@ -335,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
 
 	if (del_timer(&policy->polq.hold_timer))
 		xfrm_pol_put(policy);
-	xfrm_queue_purge(&policy->polq.hold_queue);
+	skb_queue_purge(&policy->polq.hold_queue);
 
 	if (del_timer(&policy->timer))
 		xfrm_pol_put(policy);
@@ -1955,7 +1947,7 @@ out:
 
 purge_queue:
 	pq->timeout = 0;
-	xfrm_queue_purge(&pq->hold_queue);
+	skb_queue_purge(&pq->hold_queue);
 	xfrm_pol_put(pol);
 }
 
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

PATCH 2/7 xfrm: optimise the use of walk list header in xfrm_policy/state_walk

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

The walk from input is the list header, and marked as dead, and will be skipped in loop.

list_first_entry() can be used to return the true usable value from walk if walk is not empty

---
 net/xfrm/xfrm_policy.c | 4 +++-
 net/xfrm/xfrm_state.c  | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +3 -1
index d8c35ad..847053e 100644
@@ -1004,7 +1004,9 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
 	if (list_empty(&walk->walk.all))
 		x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all);
 	else
-		x = list_entry(&walk->walk.all, struct xfrm_policy_walk_entry, all);
+		x = list_first_entry(&walk->walk.all,
+				     struct xfrm_policy_walk_entry, all);
+
 	list_for_each_entry_from(x, &net->xfrm.policy_all, all) {
 		if (x->dead)
 			continue;
net/xfrm/xfrm_state.c +1 -1
index f5e39e3..df93183 100644
@@ -1626,7 +1626,7 @@ int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
 	if (list_empty(&walk->all))
 		x = list_first_entry(&net->xfrm.state_all, struct xfrm_state_walk, all);
 	else
-		x = list_entry(&walk->all, struct xfrm_state_walk, all);
+		x = list_first_entry(&walk->all, struct xfrm_state_walk, all);
 	list_for_each_entry_from(x, &net->xfrm.state_all, all) {
 		if (x->state == XFRM_STATE_DEAD)
 			continue;
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH 3/7 xfrm: fix the return code when xfrm_*_register_afinfo failed

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

If xfrm_*_register_afinfo failed since xfrm_*_afinfo[afinfo->family] had the value, return the -EEXIST, not -ENOBUFS

---
 net/xfrm/xfrm_input.c  | 2 +-
 net/xfrm/xfrm_policy.c | 2 +-
 net/xfrm/xfrm_state.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +1 -1
index 526c4fe..459796a 100644
@@ -29,7 +29,7 @@ int xfrm_input_register_afinfo(struct xfrm_input_afinfo *afinfo)
 		return -EAFNOSUPPORT;
 	spin_lock_bh(&xfrm_input_afinfo_lock);
 	if (unlikely(xfrm_input_afinfo[afinfo->family] != NULL))
-		err = -ENOBUFS;
+		err = -EEXIST;
 	else
 		rcu_assign_pointer(xfrm_input_afinfo[afinfo->family], afinfo);
 	spin_unlock_bh(&xfrm_input_afinfo_lock);
net/xfrm/xfrm_policy.c +1 -1
index 847053e..c4c47f3 100644
@@ -2808,7 +2808,7 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
 		return -EAFNOSUPPORT;
 	spin_lock(&xfrm_policy_afinfo_lock);
 	if (unlikely(xfrm_policy_afinfo[afinfo->family] != NULL))
-		err = -ENOBUFS;
+		err = -EEXIST;
 	else {
 		struct dst_ops *dst_ops = afinfo->dst_ops;
 		if (likely(dst_ops->kmem_cachep == NULL))
net/xfrm/xfrm_state.c +1 -1
index df93183..e47e498 100644
@@ -1908,7 +1908,7 @@ int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo)
 		return -EAFNOSUPPORT;
 	spin_lock_bh(&xfrm_state_afinfo_lock);
 	if (unlikely(xfrm_state_afinfo[afinfo->family] != NULL))
-		err = -ENOBUFS;
+		err = -EEXIST;
 	else
 		rcu_assign_pointer(xfrm_state_afinfo[afinfo->family], afinfo);
 	spin_unlock_bh(&xfrm_state_afinfo_lock);
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

PATCH 4/7 xfrm: slightly optimise xfrm_input

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

Check x->km.state with XFRM_STATE_ACQ only when state is not XFRM_STAT_VALID, not everytime

---
 net/xfrm/xfrm_input.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/xfrm/xfrm_input.c +5 -5
index 459796a..1858a45f 100644
@@ -239,13 +239,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 		skb->sp->xvec[skb->sp->len++] = x;
 
 		spin_lock(&x->lock);
-		if (unlikely(x->km.state == XFRM_STATE_ACQ)) {
-			XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);
-			goto drop_unlock;
-		}
 
 		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
-			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEINVALID);
+			if (x->km.state == XFRM_STATE_ACQ)
+				XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);
+			else
+				XFRM_INC_STATS(net,
+					       LINUX_MIB_XFRMINSTATEINVALID);
 			goto drop_unlock;
 		}
 
Signature · 1 line
1.9.1
author maintainer
#5 lore raw

PATCH 5/7 xfrm: remove the unnecessary checking before call xfrm_pol_hold

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

xfrm_pol_hold will check its input with NULL

---
 net/xfrm/xfrm_policy.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/xfrm/xfrm_policy.c +3 -4
index c4c47f3..435bc0d 100644
@@ -1127,8 +1127,8 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
 			break;
 		}
 	}
-	if (ret)
-		xfrm_pol_hold(ret);
+
+	xfrm_pol_hold(ret);
 fail:
 	read_unlock_bh(&net->xfrm.xfrm_policy_lock);
 
@@ -3211,8 +3211,7 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
 		}
 	}
 
-	if (ret)
-		xfrm_pol_hold(ret);
+	xfrm_pol_hold(ret);
 
 	read_unlock_bh(&net->xfrm.xfrm_policy_lock);
 
Signature · 1 line
1.9.1
author maintainer
#6 lore raw

PATCH 6/7 xfrm: move the checking for old xfrm_policy hold_queue to beginning

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

if hold_queue of old xfrm_policy is NULL, return directly, then not need to run other codes, especially take the spin lock

---
 net/xfrm/xfrm_policy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_policy.c +3 -3
index 435bc0d..3d264e5 100644
@@ -700,6 +700,9 @@ static void xfrm_policy_requeue(struct xfrm_policy *old,
 	struct xfrm_policy_queue *pq = &old->polq;
 	struct sk_buff_head list;
 
+	if (skb_queue_empty(&pq->hold_queue))
+		return;
+
 	__skb_queue_head_init(&list);
 
 	spin_lock_bh(&pq->hold_queue.lock);
@@ -708,9 +711,6 @@ static void xfrm_policy_requeue(struct xfrm_policy *old,
 		xfrm_pol_put(old);
 	spin_unlock_bh(&pq->hold_queue.lock);
 
-	if (skb_queue_empty(&list))
-		return;
-
 	pq = &new->polq;
 
 	spin_lock_bh(&pq->hold_queue.lock);
Signature · 1 line
1.9.1
author maintainer
#7 lore raw

PATCH 7/7 xfrm: optimise to search the inexact policy list

In reply to Steffen Klassert

From: Li RongQing <[email protected]>

The policies are organized into list by priority ascent of policy, so it is unnecessary to continue to loop the policy if the priority of current looped police is larger than or equal priority which is from the policy_bydst list.

This allows to match policy with ~0U priority in inexact list too.

---
 net/xfrm/xfrm_policy.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
net/xfrm/xfrm_policy.c +8 -3
index 3d264e5..18cead7 100644
@@ -1114,6 +1114,9 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
 	}
 	chain = &net->xfrm.policy_inexact[dir];
 	hlist_for_each_entry(pol, chain, bydst) {
+		if ((pol->priority >= priority) && ret)
+			break;
+
 		err = xfrm_policy_match(pol, fl, type, family, dir);
 		if (err) {
 			if (err == -ESRCH)
@@ -1122,7 +1125,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
 				ret = ERR_PTR(err);
 				goto fail;
 			}
-		} else if (pol->priority < priority) {
+		} else {
 			ret = pol;
 			break;
 		}
@@ -3203,9 +3206,11 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
 	}
 	chain = &net->xfrm.policy_inexact[dir];
 	hlist_for_each_entry(pol, chain, bydst) {
+		if ((pol->priority >= priority) && ret)
+			break;
+
 		if (xfrm_migrate_selector_match(sel, &pol->selector) &&
-		    pol->type == type &&
-		    pol->priority < priority) {
+		    pol->type == type) {
 			ret = pol;
 			break;
 		}
Signature · 1 line
1.9.1
maintainer
#8 lore raw
In reply to Steffen Klassert

From: Steffen Klassert <[email protected]>
Date: Thu, 28 May 2015 08:25:47 +0200

Quoted 14 lines

1) Remove xfrm_queue_purge as this is the same as skb_queue_purge.

2) Optimize policy and state walk.

3) Use a sane return code if afinfo registration fails.

4) Only check fori a acquire state if the state is not valid.

5) Remove a unnecessary NULL check before xfrm_pol_hold as it checks the input for NULL.

6) Return directly if the xfrm hold queue is empty, avoid to take a lock as it is nothing to do in this case.

Quoted 6 lines

7) Optimize the inexact policy search and allow for matching of policies with priority ~0U.

All from Li RongQing.

Please pull or let me know if there are problems.

Pulled, thanks Steffen.