* pull request (net-next): ipsec-next 2018-05-07
@ 2018-05-07 9:01 Steffen Klassert
2018-05-07 9:01 ` [PATCH 1/5] selftests: add xfrm state-policy-monitor to rtnetlink.sh Steffen Klassert
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
1) Add selftests for the xfrm commands.
From Shannon Nelson.
2) Enable hardware checksum offload for ESP encapsulated
UDP packets if the hardware supports this.
From Jacek Kalwas.
3) Remove VLA usage in __xfrm6_sort. From Kees Cook.
4) Fix a typo in the comment of vti6_ioctl.
From Sun Lianwen.
5) Use a dedicated slab cache for struct xfrm_state,
this reduces the memory usage of this struct
by 25 percent. From Mathias Krause.
Please note that this pull request has a merge conflict
between commit:
bec1f6f69736 ("udp: generate gso with UDP_SEGMENT")
from the net-next tree and commit:
cd027a5433d6 ("udp: enable UDP checksum offload for ESP")
from the ipsec-next tree.
The conflict can be solved as done in linux-next.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit ef53e9e14714de2ce26eaae0244c07c426064d69:
net: Remove unused tcp_set_state tracepoint (2018-04-16 19:02:15 -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 565f0fa902b64020d5d147ff1708567e9e0b6e49:
xfrm: use a dedicated slab cache for struct xfrm_state (2018-05-04 10:14:00 +0200)
----------------------------------------------------------------
Jacek Kalwas (1):
udp: enable UDP checksum offload for ESP
Kees Cook (1):
xfrm: remove VLA usage in __xfrm6_sort()
Mathias Krause (1):
xfrm: use a dedicated slab cache for struct xfrm_state
Shannon Nelson (1):
selftests: add xfrm state-policy-monitor to rtnetlink.sh
Sun Lianwen (1):
change the comment of vti6_ioctl
net/ipv4/ip_output.c | 2 +-
net/ipv6/ip6_vti.c | 2 +-
net/ipv6/xfrm6_state.c | 6 +-
net/xfrm/xfrm_state.c | 9 ++-
tools/testing/selftests/net/rtnetlink.sh | 103 +++++++++++++++++++++++++++++++
5 files changed, 114 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] selftests: add xfrm state-policy-monitor to rtnetlink.sh
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
@ 2018-05-07 9:01 ` Steffen Klassert
2018-05-07 9:01 ` [PATCH 2/5] udp: enable UDP checksum offload for ESP Steffen Klassert
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
From: Shannon Nelson <shannon.nelson@oracle.com>
Add a simple set of tests for the IPsec xfrm commands.
Signed-off-by: Shannon Nelson <shannon.nelson@oracle.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
tools/testing/selftests/net/rtnetlink.sh | 103 +++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh
index e6f485235435..760faef2e12e 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -502,6 +502,108 @@ kci_test_macsec()
echo "PASS: macsec"
}
+#-------------------------------------------------------------------
+# Example commands
+# ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
+# spi 0x07 mode transport reqid 0x07 replay-window 32 \
+# aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
+# sel src 14.0.0.52/24 dst 14.0.0.70/24
+# ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
+# tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
+# spi 0x07 mode transport reqid 0x07
+#
+# Subcommands not tested
+# ip x s update
+# ip x s allocspi
+# ip x s deleteall
+# ip x p update
+# ip x p deleteall
+# ip x p set
+#-------------------------------------------------------------------
+kci_test_ipsec()
+{
+ srcip="14.0.0.52"
+ dstip="14.0.0.70"
+ algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
+
+ # flush to be sure there's nothing configured
+ ip x s flush ; ip x p flush
+ check_err $?
+
+ # start the monitor in the background
+ tmpfile=`mktemp ipsectestXXX`
+ ip x m > $tmpfile &
+ mpid=$!
+ sleep 0.2
+
+ ipsecid="proto esp src $srcip dst $dstip spi 0x07"
+ ip x s add $ipsecid \
+ mode transport reqid 0x07 replay-window 32 \
+ $algo sel src $srcip/24 dst $dstip/24
+ check_err $?
+
+ lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
+ test $lines -eq 2
+ check_err $?
+
+ ip x s count | grep -q "SAD count 1"
+ check_err $?
+
+ lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
+ test $lines -eq 2
+ check_err $?
+
+ ip x s delete $ipsecid
+ check_err $?
+
+ lines=`ip x s list | wc -l`
+ test $lines -eq 0
+ check_err $?
+
+ ipsecsel="dir out src $srcip/24 dst $dstip/24"
+ ip x p add $ipsecsel \
+ tmpl proto esp src $srcip dst $dstip \
+ spi 0x07 mode transport reqid 0x07
+ check_err $?
+
+ lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
+ test $lines -eq 2
+ check_err $?
+
+ ip x p count | grep -q "SPD IN 0 OUT 1 FWD 0"
+ check_err $?
+
+ lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
+ test $lines -eq 2
+ check_err $?
+
+ ip x p delete $ipsecsel
+ check_err $?
+
+ lines=`ip x p list | wc -l`
+ test $lines -eq 0
+ check_err $?
+
+ # check the monitor results
+ kill $mpid
+ lines=`wc -l $tmpfile | cut "-d " -f1`
+ test $lines -eq 20
+ check_err $?
+ rm -rf $tmpfile
+
+ # clean up any leftovers
+ ip x s flush
+ check_err $?
+ ip x p flush
+ check_err $?
+
+ if [ $ret -ne 0 ]; then
+ echo "FAIL: ipsec"
+ return 1
+ fi
+ echo "PASS: ipsec"
+}
+
kci_test_gretap()
{
testns="testns"
@@ -755,6 +857,7 @@ kci_test_rtnl()
kci_test_vrf
kci_test_encap
kci_test_macsec
+ kci_test_ipsec
kci_del_dummy
}
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] udp: enable UDP checksum offload for ESP
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
2018-05-07 9:01 ` [PATCH 1/5] selftests: add xfrm state-policy-monitor to rtnetlink.sh Steffen Klassert
@ 2018-05-07 9:01 ` Steffen Klassert
2018-05-07 9:01 ` [PATCH 3/5] xfrm: remove VLA usage in __xfrm6_sort() Steffen Klassert
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
From: Jacek Kalwas <jacek.kalwas@intel.com>
In case NIC has support for ESP TX CSUM offload skb->ip_summed is not
set to CHECKSUM_PARTIAL which results in checksum calculated by SW.
Fix enables ESP TX CSUM for UDP by extending condition with check for
NETIF_F_HW_ESP_TX_CSUM.
Signed-off-by: Jacek Kalwas <jacek.kalwas@intel.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/ipv4/ip_output.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4c11b810a447..a2dfb5a9ba76 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -907,7 +907,7 @@ static int __ip_append_data(struct sock *sk,
length + fragheaderlen <= mtu &&
rt->dst.dev->features & (NETIF_F_HW_CSUM | NETIF_F_IP_CSUM) &&
!(flags & MSG_MORE) &&
- !exthdrlen)
+ (!exthdrlen || (rt->dst.dev->features & NETIF_F_HW_ESP_TX_CSUM)))
csummode = CHECKSUM_PARTIAL;
cork->length += length;
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] xfrm: remove VLA usage in __xfrm6_sort()
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
2018-05-07 9:01 ` [PATCH 1/5] selftests: add xfrm state-policy-monitor to rtnetlink.sh Steffen Klassert
2018-05-07 9:01 ` [PATCH 2/5] udp: enable UDP checksum offload for ESP Steffen Klassert
@ 2018-05-07 9:01 ` Steffen Klassert
2018-05-07 9:01 ` [PATCH 4/5] change the comment of vti6_ioctl Steffen Klassert
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
From: Kees Cook <keescook@chromium.org>
In the quest to remove all stack VLA usage removed from the kernel[1],
just use XFRM_MAX_DEPTH as already done for the "class" array. In one
case, it'll do this loop up to 5, the other caller up to 6.
[1] https://lkml.org/lkml/2018/3/7/621
Co-developed-by: Andreas Christoforou <andreaschristofo@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/ipv6/xfrm6_state.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c
index 16f434791763..5bdca3d5d6b7 100644
--- a/net/ipv6/xfrm6_state.c
+++ b/net/ipv6/xfrm6_state.c
@@ -60,11 +60,9 @@ xfrm6_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl,
static int
__xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass)
{
- int i;
+ int count[XFRM_MAX_DEPTH] = { };
int class[XFRM_MAX_DEPTH];
- int count[maxclass];
-
- memset(count, 0, sizeof(count));
+ int i;
for (i = 0; i < n; i++) {
int c;
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] change the comment of vti6_ioctl
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
` (2 preceding siblings ...)
2018-05-07 9:01 ` [PATCH 3/5] xfrm: remove VLA usage in __xfrm6_sort() Steffen Klassert
@ 2018-05-07 9:01 ` Steffen Klassert
2018-05-07 9:01 ` [PATCH 5/5] xfrm: use a dedicated slab cache for struct xfrm_state Steffen Klassert
2018-05-08 3:57 ` pull request (net-next): ipsec-next 2018-05-07 David Miller
5 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
From: Sun Lianwen <sunlw.fnst@cn.fujitsu.com>
The comment of vti6_ioctl() is wrong. which use vti6_tnl_ioctl
instead of vti6_ioctl.
Signed-off-by: Sun Lianwen <sunlw.fnst@cn.fujitsu.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/ipv6/ip6_vti.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index c214ffec02f0..deadc4c3703b 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -743,7 +743,7 @@ vti6_parm_to_user(struct ip6_tnl_parm2 *u, const struct __ip6_tnl_parm *p)
}
/**
- * vti6_tnl_ioctl - configure vti6 tunnels from userspace
+ * vti6_ioctl - configure vti6 tunnels from userspace
* @dev: virtual device associated with tunnel
* @ifr: parameters passed from userspace
* @cmd: command to be performed
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] xfrm: use a dedicated slab cache for struct xfrm_state
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
` (3 preceding siblings ...)
2018-05-07 9:01 ` [PATCH 4/5] change the comment of vti6_ioctl Steffen Klassert
@ 2018-05-07 9:01 ` Steffen Klassert
2018-05-08 3:57 ` pull request (net-next): ipsec-next 2018-05-07 David Miller
5 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2018-05-07 9:01 UTC (permalink / raw)
To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev
From: Mathias Krause <minipli@googlemail.com>
struct xfrm_state is rather large (768 bytes here) and therefore wastes
quite a lot of memory as it falls into the kmalloc-1024 slab cache,
leaving 256 bytes of unused memory per XFRM state object -- a net waste
of 25%.
Using a dedicated slab cache for struct xfrm_state reduces the level of
internal fragmentation to a minimum.
On my configuration SLUB chooses to create a slab cache covering 4
pages holding 21 objects, resulting in an average memory waste of ~13
bytes per object -- a net waste of only 1.6%.
In my tests this led to memory savings of roughly 2.3MB for 10k XFRM
states.
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/xfrm/xfrm_state.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f9d2f2233f09..f595797a20ce 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -42,6 +42,7 @@ static void xfrm_state_gc_task(struct work_struct *work);
static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
static __read_mostly seqcount_t xfrm_state_hash_generation = SEQCNT_ZERO(xfrm_state_hash_generation);
+static struct kmem_cache *xfrm_state_cache __ro_after_init;
static DECLARE_WORK(xfrm_state_gc_work, xfrm_state_gc_task);
static HLIST_HEAD(xfrm_state_gc_list);
@@ -451,7 +452,7 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
}
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
- kfree(x);
+ kmem_cache_free(xfrm_state_cache, x);
}
static void xfrm_state_gc_task(struct work_struct *work)
@@ -563,7 +564,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
{
struct xfrm_state *x;
- x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
+ x = kmem_cache_alloc(xfrm_state_cache, GFP_ATOMIC | __GFP_ZERO);
if (x) {
write_pnet(&x->xs_net, net);
@@ -2307,6 +2308,10 @@ int __net_init xfrm_state_init(struct net *net)
{
unsigned int sz;
+ if (net_eq(net, &init_net))
+ xfrm_state_cache = KMEM_CACHE(xfrm_state,
+ SLAB_HWCACHE_ALIGN | SLAB_PANIC);
+
INIT_LIST_HEAD(&net->xfrm.state_all);
sz = sizeof(struct hlist_head) * 8;
--
2.14.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: pull request (net-next): ipsec-next 2018-05-07
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
` (4 preceding siblings ...)
2018-05-07 9:01 ` [PATCH 5/5] xfrm: use a dedicated slab cache for struct xfrm_state Steffen Klassert
@ 2018-05-08 3:57 ` David Miller
5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2018-05-08 3:57 UTC (permalink / raw)
To: steffen.klassert; +Cc: herbert, netdev
From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Mon, 7 May 2018 11:01:11 +0200
> 1) Add selftests for the xfrm commands.
> From Shannon Nelson.
>
> 2) Enable hardware checksum offload for ESP encapsulated
> UDP packets if the hardware supports this.
> From Jacek Kalwas.
>
> 3) Remove VLA usage in __xfrm6_sort. From Kees Cook.
>
> 4) Fix a typo in the comment of vti6_ioctl.
> From Sun Lianwen.
>
> 5) Use a dedicated slab cache for struct xfrm_state,
> this reduces the memory usage of this struct
> by 25 percent. From Mathias Krause.
...
> git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master
Pulled, thanks Steffen.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-05-08 3:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-07 9:01 pull request (net-next): ipsec-next 2018-05-07 Steffen Klassert
2018-05-07 9:01 ` [PATCH 1/5] selftests: add xfrm state-policy-monitor to rtnetlink.sh Steffen Klassert
2018-05-07 9:01 ` [PATCH 2/5] udp: enable UDP checksum offload for ESP Steffen Klassert
2018-05-07 9:01 ` [PATCH 3/5] xfrm: remove VLA usage in __xfrm6_sort() Steffen Klassert
2018-05-07 9:01 ` [PATCH 4/5] change the comment of vti6_ioctl Steffen Klassert
2018-05-07 9:01 ` [PATCH 5/5] xfrm: use a dedicated slab cache for struct xfrm_state Steffen Klassert
2018-05-08 3:57 ` pull request (net-next): ipsec-next 2018-05-07 David Miller
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).