All of lore.kernel.org
 help / color / mirror / Atom feed
* pull request (net-next): ipsec-next 2017-04-11
@ 2017-04-11  5:53 Steffen Klassert
  2017-04-11  5:53 ` [PATCH 1/4] xfrm: remove unused struct xfrm_mgr::id Steffen Klassert
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Steffen Klassert @ 2017-04-11  5:53 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

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(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] xfrm: remove unused struct xfrm_mgr::id
  2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
@ 2017-04-11  5:53 ` Steffen Klassert
  2017-04-11  5:53 ` [PATCH 2/4] xfrm: use "unsigned int" in __xfrm6_pref_hash() Steffen Klassert
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Steffen Klassert @ 2017-04-11  5:53 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Alexey Dobriyan <adobriyan@gmail.com>

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/xfrm.h   | 1 -
 net/key/af_key.c     | 1 -
 net/xfrm/xfrm_user.c | 1 -
 3 files changed, 3 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 14d82bf..6e03a1a 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -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);
diff --git a/net/key/af_key.c b/net/key/af_key.c
index c6252ed..60cf2fb 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -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,
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 9705c27..8e696ea 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] xfrm: use "unsigned int" in __xfrm6_pref_hash()
  2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
  2017-04-11  5:53 ` [PATCH 1/4] xfrm: remove unused struct xfrm_mgr::id Steffen Klassert
@ 2017-04-11  5:53 ` Steffen Klassert
  2017-04-11  5:53 ` [PATCH 3/4] xfrm: use "unsigned int" in addr_match() Steffen Klassert
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Steffen Klassert @ 2017-04-11  5:53 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Alexey Dobriyan <adobriyan@gmail.com>

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

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_hash.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/xfrm/xfrm_hash.h b/net/xfrm/xfrm_hash.h
index 666c5ff..eaea9c4 100644
--- a/net/xfrm/xfrm_hash.h
+++ b/net/xfrm/xfrm_hash.h
@@ -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 */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] xfrm: use "unsigned int" in addr_match()
  2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
  2017-04-11  5:53 ` [PATCH 1/4] xfrm: remove unused struct xfrm_mgr::id Steffen Klassert
  2017-04-11  5:53 ` [PATCH 2/4] xfrm: use "unsigned int" in __xfrm6_pref_hash() Steffen Klassert
@ 2017-04-11  5:53 ` Steffen Klassert
  2017-04-11  5:53 ` [PATCH 4/4] xfrm: branchless addr4_match() on 64-bit Steffen Klassert
  2017-04-11 14:32 ` pull request (net-next): ipsec-next 2017-04-11 David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Steffen Klassert @ 2017-04-11  5:53 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Alexey Dobriyan <adobriyan@gmail.com>

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

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/xfrm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 6e03a1a..43b93d1 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -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 */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] xfrm: branchless addr4_match() on 64-bit
  2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
                   ` (2 preceding siblings ...)
  2017-04-11  5:53 ` [PATCH 3/4] xfrm: use "unsigned int" in addr_match() Steffen Klassert
@ 2017-04-11  5:53 ` Steffen Klassert
  2017-04-11 14:32 ` pull request (net-next): ipsec-next 2017-04-11 David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Steffen Klassert @ 2017-04-11  5:53 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Alexey Dobriyan <adobriyan@gmail.com>

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

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/xfrm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 43b93d1..9e3dc7b 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -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__
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: pull request (net-next): ipsec-next 2017-04-11
  2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
                   ` (3 preceding siblings ...)
  2017-04-11  5:53 ` [PATCH 4/4] xfrm: branchless addr4_match() on 64-bit Steffen Klassert
@ 2017-04-11 14:32 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-04-11 14:32 UTC (permalink / raw)
  To: steffen.klassert; +Cc: herbert, netdev

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Tue, 11 Apr 2017 07:53:48 +0200

> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-11 14:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-11  5:53 pull request (net-next): ipsec-next 2017-04-11 Steffen Klassert
2017-04-11  5:53 ` [PATCH 1/4] xfrm: remove unused struct xfrm_mgr::id Steffen Klassert
2017-04-11  5:53 ` [PATCH 2/4] xfrm: use "unsigned int" in __xfrm6_pref_hash() Steffen Klassert
2017-04-11  5:53 ` [PATCH 3/4] xfrm: use "unsigned int" in addr_match() Steffen Klassert
2017-04-11  5:53 ` [PATCH 4/4] xfrm: branchless addr4_match() on 64-bit Steffen Klassert
2017-04-11 14:32 ` pull request (net-next): ipsec-next 2017-04-11 David Miller

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.