Skip to contentSkip to conversation

pull request (net-next): ipsec-next 2017-04-11

PATCH New Steffen Klassert 2 participants 6 messages Apr 11, 2017

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

1) Remove unused field from struct xfrm_mgr.

2) Code size optimizations for the xfrm prefix hash and address match.

3) Branch optimization for addr4_match.

All patches from Alexey Dobriyan.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit add641e7dee31b36aee83412c29e39dd1f5e0c9c:

sched: act_csum: don't mangle TCP and UDP GSO packets (2017-03-23 17:40:33 -0700)

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 6c786bcb29dd684533ec165057f437d5bb34a4b2:

xfrm: branchless addr4_match() on 64-bit (2017-03-27 07:04:14 +0200)

----------------------------------------------------------------
Alexey Dobriyan (4):
xfrm: remove unused struct xfrm_mgr::id
xfrm: use "unsigned int" in __xfrm6_pref_hash()
xfrm: use "unsigned int" in addr_match()
xfrm: branchless addr4_match() on 64-bit

 include/net/xfrm.h   | 11 +++++------
 net/key/af_key.c     |  1 -
 net/xfrm/xfrm_hash.h |  4 ++--
 net/xfrm/xfrm_user.c |  1 -
 4 files changed, 7 insertions(+), 10 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 xfrm: remove unused struct xfrm_mgr::id

From: Alexey Dobriyan <[email protected]>

---
 include/net/xfrm.h   | 1 -
 net/key/af_key.c     | 1 -
 net/xfrm/xfrm_user.c | 1 -
 3 files changed, 3 deletions(-)
include/net/xfrm.h +0 -1
index 14d82bf..6e03a1a 100644
@@ -586,7 +586,6 @@ struct xfrm_migrate {
 
 struct xfrm_mgr {
 	struct list_head	list;
-	char			*id;
 	int			(*notify)(struct xfrm_state *x, const struct km_event *c);
 	int			(*acquire)(struct xfrm_state *x, struct xfrm_tmpl *, struct xfrm_policy *xp);
 	struct xfrm_policy	*(*compile_policy)(struct sock *sk, int opt, u8 *data, int len, int *dir);
net/key/af_key.c +0 -1
index c6252ed..60cf2fb 100644
@@ -3792,7 +3792,6 @@ static inline void pfkey_exit_proc(struct net *net)
 
 static struct xfrm_mgr pfkeyv2_mgr =
 {
-	.id		= "pfkeyv2",
 	.notify		= pfkey_send_notify,
 	.acquire	= pfkey_send_acquire,
 	.compile_policy	= pfkey_compile_policy,
net/xfrm/xfrm_user.c +0 -1
index 9705c27..8e696ea 100644
@@ -3101,7 +3101,6 @@ static bool xfrm_is_alive(const struct km_event *c)
 }
 
 static struct xfrm_mgr netlink_mgr = {
-	.id		= "netlink",
 	.notify		= xfrm_send_state_notify,
 	.acquire	= xfrm_send_acquire,
 	.compile_policy	= xfrm_compile_policy,
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH 2/4 xfrm: use "unsigned int" in __xfrm6_pref_hash()

In reply to Steffen Klassert

From: Alexey Dobriyan <[email protected]>

x86_64 is zero-extending arch so "unsigned int" is preferred over "int" for address calculations.

Space savings:

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-58 (-58)
function old new delta
xfrm_hash_resize 2752 2743 -9
policy_hash_bysel 985 973 -12
policy_hash_direct 1036 999 -37

---
 net/xfrm/xfrm_hash.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_hash.h +2 -2
index 666c5ff..eaea9c4 100644
@@ -54,8 +54,8 @@ static inline unsigned int __xfrm4_dpref_spref_hash(const xfrm_address_t *daddr,
 static inline unsigned int __xfrm6_pref_hash(const xfrm_address_t *addr,
 					     __u8 prefixlen)
 {
-	int pdw;
-	int pbi;
+	unsigned int pdw;
+	unsigned int pbi;
 	u32 initval = 0;
 
 	pdw = prefixlen >> 5;     /* num of whole u32 in prefix */
Signature · 1 line
2.7.4
author maintainer
#3 lore raw

PATCH 3/4 xfrm: use "unsigned int" in addr_match()

In reply to Steffen Klassert

From: Alexey Dobriyan <[email protected]>

x86_64 is zero-extending arch so "unsigned int" is preferred over "int" for address calculations and extending to size_t.

Space savings:

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-24 (-24)
function old new delta
xfrm_state_walk 708 696 -12
xfrm_selector_match 918 906 -12

---
 include/net/xfrm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/net/xfrm.h +3 -3
index 6e03a1a..43b93d1 100644
@@ -816,12 +816,12 @@ static inline void xfrm_state_hold(struct xfrm_state *x)
 }
 
 static inline bool addr_match(const void *token1, const void *token2,
-			      int prefixlen)
+			      unsigned int prefixlen)
 {
 	const __be32 *a1 = token1;
 	const __be32 *a2 = token2;
-	int pdw;
-	int pbi;
+	unsigned int pdw;
+	unsigned int pbi;
 
 	pdw = prefixlen >> 5;	  /* num of whole u32 in prefix */
 	pbi = prefixlen &  0x1f;  /* num of bits in incomplete u32 in prefix */
Signature · 1 line
2.7.4
author maintainer
#4 lore raw

PATCH 4/4 xfrm: branchless addr4_match() on 64-bit

In reply to Steffen Klassert

From: Alexey Dobriyan <[email protected]>

Current addr4_match() code has special test for /0 prefixes because of standard required undefined behaviour. However, it is possible to omit it on 64-bit because shifting can be done within a 64-bit register and then truncated to the expected value (which is 0 mask).

Implicit truncation by htonl() fits nicely into R32-within-R64 model on x86-64.

Space savings: none (coincidence)
Branch savings: 1

Before:

	movzx  eax,BYTE PTR [rdi+0x2a]		# ->prefixlen_d
	test   al,al
	jne    xfrm_selector_match + 0x23f
		...
	movzx  eax,BYTE PTR [rbx+0x2b]		# ->prefixlen_s
	test   al,al
	je     xfrm_selector_match + 0x1c7

After (no branches):

	mov    r8d,0x20
	mov    rdx,0xffffffffffffffff
	mov    esi,DWORD PTR [rsi+0x2c]
	mov    ecx,r8d
	sub    cl,BYTE PTR [rdi+0x2a]
	xor    esi,DWORD PTR [rbx]
	mov    rdi,rdx
	xor    eax,eax
	shl    rdi,cl
	bswap  edi
---
 include/net/xfrm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/xfrm.h +2 -2
index 43b93d1..9e3dc7b 100644
@@ -845,9 +845,9 @@ static inline bool addr_match(const void *token1, const void *token2,
 static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)
 {
 	/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
-	if (prefixlen == 0)
+	if (sizeof(long) == 4 && prefixlen == 0)
 		return true;
-	return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
+	return !((a1 ^ a2) & htonl(~0UL << (32 - prefixlen)));
 }
 
 static __inline__
Signature · 1 line
2.7.4
maintainer
#5 lore raw
In reply to Steffen Klassert

From: Steffen Klassert <[email protected]>
Date: Tue, 11 Apr 2017 07:53:48 +0200

Quoted 10 lines

1) Remove unused field from struct xfrm_mgr.

2) Code size optimizations for the xfrm prefix hash and address match.

3) Branch optimization for addr4_match.

All patches from Alexey Dobriyan.

Please pull or let me know if there are problems.

Pulled, thanks Steffen.