Parallel IPsec
Subsystems (5)
Steffen Klassert
maintainercover Parallel IPsec
This patchset adds the 'pcrypt' parallel crypto template. With this template it is possible to process the crypto requests of a transform in parallel without getting request reorder. This is in particular interesting for IPsec.
I posted a first network based version to the netdev list some time ago. The discussion can be found here:
http://lwn.net/Articles/309029/
The parallel crypto template is based on a generic parallelization/serialization method. This method uses the remote softirq invocation infrastructure for parallelization and serialization. With this method data objects can be processed in parallel, starting at some given point.
After doing some expensive operations in parallel, it is possible to serialize again. The parallelized data objects return after serialization in the order as they were before the parallelization. In the case of IPsec, this makes it possible to run the expensive parts in parallel without getting packet reordering.
I did forwarding tests with two quad core machines (Intel Core 2 Quad Q6600) and an EXFO FTB-400 packet blazer.
Unfortunately the thoughput tests are not that meaningful as long as we don't use the new reentrant ahash/shash interface, because the lock in authenc_hash serializes the requests. As soon as this work stabilize I'll start to convert authenc to ahash if nobody else did it in between.
The results of the troughput tests are as follows:
cryptodev-2.6
Packetsize: 1420 byte
Encryption: aes192-sha1
bidirectional throughput: 2 x 132 Mbit/s
unidirectional throughput: 260 Mbit/s
cryptodev-2.6 + pcrypt (authenc) parallelization:
Packetsize: 1420 byte
Encryption: aes192-sha1
bidirectional throughput: 2 x 320 Mbit/s
unidirectional throughput: 493 Mbit/s
To reduce the hold time of the lock in authenc_hash I did the same tests again with aes192-digest_null:
cryptodev-2.6
Packetsize: 1420 byte
Encryption: aes192-digest_null
bidirectional throughput: 2 x 243 Mbit/s
unidirectional throughput: 480 Mbit/s
cryptodev-2.6 + pcrypt (authenc) parallelization:
Packetsize: 1420 byte
Encryption: aes192-digest_null
bidirectional throughput: 2 x 592 Mbit/s
unidirectional throughput: 936 Mbit/s
Steffen
Steffen Klassert
maintainerRFC PATCH 1/4 padata: generic interface for parallel processing
This patch introduces an interface to process data objects in parallel. On request it is possible to serialize again. The parallelized objects return after serialization in the same order as they were before the parallelization.
--- include/linux/interrupt.h | 3 +- include/linux/padata.h | 116 +++++++++++ kernel/Makefile | 2 +- kernel/padata.c | 490 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 609 insertions(+), 2 deletions(-) create mode 100644 include/linux/padata.h create mode 100644 kernel/padata.c
include/linux/interrupt.h +2 -1
@@ -253,7 +253,8 @@ enumTASKLET_SOFTIRQ ,SCHED_SOFTIRQ ,HRTIMER_SOFTIRQ , -RCU_SOFTIRQ ,/* Preferable RCU should always be the last softirq */ +PADATA_SOFTIRQ , +RCU_SOFTIRQ ,/* Preferable RCU should always be the last softirq */ NR_SOFTIRQS };
include/linux/padata.h new file +116 -0
116 lines not on this page · raw message
kernel/Makefile +1 -1
@@ -40,7 +40,7 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o -obj-$(CONFIG_USE_GENERIC_SMP_HELPERS) += smp.o +obj-$(CONFIG_USE_GENERIC_SMP_HELPERS) += smp.o padata.o ifneq ($(CONFIG_SMP),y) obj-y += up.o endif
kernel/padata.c new file +490 -0
490 lines not on this page · raw message
Signature · 1 line
1.5.4.2
Steffen Klassert
maintainerRFC PATCH 2/4 cpu_chainiv: add percpu IV chain genarator
In reply to Steffen KlassertIf the crypro requests of a crypto transformation are processed in parallel, the usual chain IV generator would serialize the crypto requests again. The percpu IV chain genarator allocates the IV as percpu data and generates percpu IV chains, so a crypro request does not need to wait for the completition of the IV generation from a previous request that runs on a different cpu.
--- crypto/Makefile | 1 + crypto/cpu_chainiv.c | 327 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 crypto/cpu_chainiv.c
crypto/Makefile +1 -0
@@ -19,6 +19,7 @@ crypto_blkcipher-objs := ablkcipher.o crypto_blkcipher-objs += blkcipher.o obj-$(CONFIG_CRYPTO_BLKCIPHER2) += crypto_blkcipher.o obj-$(CONFIG_CRYPTO_BLKCIPHER2) += chainiv.o +obj-$(CONFIG_CRYPTO_BLKCIPHER2) += cpu_chainiv.o obj-$(CONFIG_CRYPTO_BLKCIPHER2) += eseqiv.o obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
crypto/cpu_chainiv.c new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
1.5.4.2
Herbert Xu
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 8 lines · Steffen Klassert
If the crypro requests of a crypto transformation are processed in parallel, the usual chain IV generator would serialize the crypto requests again. The percpu IV chain genarator allocates the IV as percpu data and generates percpu IV chains, so a crypro request does not need to wait for the completition of the IV generation from a previous request that runs on a different cpu.
Signed-off-by Steffen Klassert <[email protected]>
I actually thought about this one when I first wrote chainiv, I chose to avoid this because it has some security consequences. In particular, an attacker would now be able to infer whether two packets belong to two differnt flows from the fact that they came from two different IV streams.
In any case, I don't think this is central to your work, right?
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtSteffen Klassert
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 10 lines · Herbert Xu
Quoted 8 lines · Steffen Klassert
If the crypro requests of a crypto transformation are processed in parallel, the usual chain IV generator would serialize the crypto requests again. The percpu IV chain genarator allocates the IV as percpu data and generates percpu IV chains, so a crypro request does not need to wait for the completition of the IV generation from a previous request that runs on a different cpu.
Signed-off-by Steffen Klassert <[email protected]>
Quoted 8 lines
I actually thought about this one when I first wrote chainiv, I chose to avoid this because it has some security consequences. In particular, an attacker would now be able to infer whether two packets belong to two differnt flows from the fact that they came from two different IV streams.
In any case, I don't think this is central to your work, right?
Well, to do efficient parallel processing we need a percpu IV chain genarator. pcrypt sends the crypto requests round robin to the cpus independent of the flow they are belong to, so the flows and the IV streams are mixing. As long as we use the percpu IV chain genarator just for parallel algorithms we don't have this security issues.
Herbert Xu
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 6 lines · Steffen Klassert
Well, to do efficient parallel processing we need a percpu IV chain genarator. pcrypt sends the crypto requests round robin to the cpus independent of the flow they are belong to, so the flows and the IV streams are mixing. As long as we use the percpu IV chain genarator just for parallel algorithms we don't have this security issues.
How about using eseqiv? It's designed for exactly this situation where you want parallel async processing. Its overhead is just one extra encryption block.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtSteffen Klassert
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 5 lines · Herbert Xu
How about using eseqiv? It's designed for exactly this situation where you want parallel async processing. Its overhead is just one extra encryption block.
Yes, that's an option too. I'll give it a try.
Thanks!
Steffen Klassert
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
In reply to Herbert XuQuoted 5 lines · Herbert Xu
How about using eseqiv? It's designed for exactly this situation where you want parallel async processing. Its overhead is just one extra encryption block.
Actually I'm instantiate a crypto_nivaead_type algorithm and choose for cpu_chainiv as the IV generator for that algorithm. If I want to do the same with eseqiv it would require to add aead support to eseqiv. Is this what you are thinking about, or is there a way to instantiate a crypto_aead_type algorithm and notify the ablkcipher to choose for eseqiv as it's default IV genarator?
Steffen
Herbert Xu
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 7 lines · Steffen Klassert
Actually I'm instantiate a
crypto_nivaead_typealgorithm and choose forcpu_chainivas the IV generator for that algorithm. If I want to do the same with eseqiv it would require to add aead support to eseqiv. Is this what you are thinking about, or is there a way to instantiate acrypto_aead_typealgorithm and notify the ablkcipher to choose for eseqiv as it's default IV genarator?
You can allocate eseqiv(alg), e.g., eseqiv(cbc(aes)).
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtSteffen Klassert
maintainerRe: [RFC] [PATCH 2/4] cpu_chainiv: add percpu IV chain genarator
Quoted 3 lines · Herbert Xu
You can allocate eseqiv(alg), e.g., eseqiv(cbc(aes)).
Ok, that's possible. I missed this possibility, probaply because nobody is actually doing it this way. Thanks!
Unfortunately eseqiv does not work out of the box if we do synchronous encryption.
If crypto_ablkcipher_encrypt() returns synchronous, eseqiv_complete2() is called even if req->giv is already the pointer to the generated IV. The generated IV is overwritten with some random data in this case.
I fixed this by calling eseqiv_complete2() just in the case when an asynchronous algorithm would call eseqiv_complete() as the complete function. I'll send the patch with an extra mail.
Now pcrypt runs fine together with eseqiv and the throughput results are very similar to the ones with cpu_chainiv.
Steffen
Steffen Klassert
maintainerRFC PATCH 3/4 pcrypt: Add pcrypt crypto parallelization engine
In reply to Steffen KlassertThis patch adds a parallel crypto template that takes a crypto algorithm and converts it to process the crypto transforms in parallel. For the moment only aead is supported.
--- crypto/Kconfig | 13 ++ crypto/Makefile | 2 + crypto/pcrypt.c | 417 +++++++++++++++++++++++++++++++++++++++++++++ crypto/pcrypt_core.c | 125 ++++++++++++++ include/crypto/pcrypt.h | 85 +++++++++ include/linux/crypto.h | 2 + include/linux/interrupt.h | 2 + 7 files changed, 646 insertions(+), 0 deletions(-) create mode 100644 crypto/pcrypt.c create mode 100644 crypto/pcrypt_core.c create mode 100644 include/crypto/pcrypt.h
crypto/Kconfig +13 -0
@@ -112,6 +112,19 @@ config CRYPTO_NULL help These are 'Null' algorithms, used by IPsec, which do nothing. +config CRYPTO_PCRYPT_CORE + bool + select CRYPTO_AEAD + +config CRYPTO_PCRYPT + tristate "Parallel crypto engine (EXPERIMENTAL)" + depends on USE_GENERIC_SMP_HELPERS && EXPERIMENTAL + select CRYPTO_MANAGER + select CRYPTO_PCRYPT_CORE + help + This converts an arbitrary crypto algorithm into a parallel + algorithm that is executed in a softirq. + config CRYPTO_WORKQUEUE tristate
crypto/Makefile +2 -0
@@ -57,6 +57,8 @@ obj-$(CONFIG_CRYPTO_XTS) += xts.o obj-$(CONFIG_CRYPTO_CTR) += ctr.o obj-$(CONFIG_CRYPTO_GCM) += gcm.o obj-$(CONFIG_CRYPTO_CCM) += ccm.o +obj-$(CONFIG_CRYPTO_PCRYPT_CORE) += pcrypt_core.o +obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o obj-$(CONFIG_CRYPTO_DES) += des_generic.o obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
crypto/pcrypt.c new file +417 -0
417 lines not on this page · raw message
crypto/pcrypt_core.c new file +125 -0
125 lines not on this page · raw message
include/crypto/pcrypt.h new file +85 -0
85 lines not on this page · raw message
include/linux/crypto.h +2 -0
@@ -71,6 +71,8 @@#define CRYPTO_ALG_TESTED 0x00000400 +#define CRYPTO_ALG_PCRYPT 0x00000800 +/* * Transform masks and values (for crt_flags). */
include/linux/interrupt.h +2 -0
@@ -253,6 +253,8 @@ enumTASKLET_SOFTIRQ ,SCHED_SOFTIRQ ,HRTIMER_SOFTIRQ , +AEAD_ENC_SOFTIRQ , +AEAD_DEC_SOFTIRQ ,PADATA_SOFTIRQ , RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
Signature · 1 line
1.5.4.2
Steffen Klassert
maintainerRFC PATCH 4/4 esp: add the pcrypt hooks to esp
In reply to Steffen KlassertAdd the pcrypt hooks to esp to be able to use pcrypt-ed IPsec.
--- net/ipv4/esp4.c | 5 +++-- net/ipv6/esp6.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/esp4.c +3 -2
@@ -1,5 +1,6 @@#include <crypto/aead.h> #include <crypto/authenc.h> +#include <crypto/pcrypt.h> #include <linux/err.h> #include <linux/module.h> #include <net/ip.h>
@@ -447,7 +448,7 @@ static int esp_init_aead(struct xfrm_state *x)struct crypto_aead *aead;int err; - aead =crypto_alloc_aead (x->aead->alg_name,0 ,0 ); + aead =crypto_alloc_aead_tfm (x->aead->alg_name,0 ,0 ); err =PTR_ERR (aead);if (IS_ERR (aead)) goto error;
@@ -489,7 +490,7 @@ static int esp_init_authenc(struct xfrm_state *x) x->ealg->alg_name) >= CRYPTO_MAX_ALG_NAME) goto error; - aead =crypto_alloc_aead (authenc_name,0 ,0 ); + aead =crypto_alloc_aead_tfm (authenc_name,0 ,0 ); err =PTR_ERR (aead);if (IS_ERR (aead)) goto error;
net/ipv6/esp6.c +3 -2
@@ -26,6 +26,7 @@#include <crypto/aead.h> #include <crypto/authenc.h> +#include <crypto/pcrypt.h> #include <linux/err.h> #include <linux/module.h> #include <net/ip.h>
@@ -390,7 +391,7 @@ static int esp_init_aead(struct xfrm_state *x)struct crypto_aead *aead;int err; - aead =crypto_alloc_aead (x->aead->alg_name,0 ,0 ); + aead =crypto_alloc_aead_tfm (x->aead->alg_name,0 ,0 ); err =PTR_ERR (aead);if (IS_ERR (aead)) goto error;
@@ -432,7 +433,7 @@ static int esp_init_authenc(struct xfrm_state *x) x->ealg->alg_name) >= CRYPTO_MAX_ALG_NAME) goto error; - aead =crypto_alloc_aead (authenc_name,0 ,0 ); + aead =crypto_alloc_aead_tfm (authenc_name,0 ,0 ); err =PTR_ERR (aead);if (IS_ERR (aead)) goto error;
Signature · 1 line
1.5.4.2
Herbert Xu
maintainerRe: [RFC] [PATCH 4/4] esp: add the pcrypt hooks to esp
net/ipv4/esp4.c static int esp_init_aead(struct xfrm_state *x) · line 451
Quoted 7 lines · Steffen Klassert
net/ipv4/esp4.c +1
-1@@ -447,7 +448,7 @@ static int esp_init_aead(struct xfrm_state *x)struct crypto_aead *aead;int err; - aead =crypto_alloc_aead (x->aead->alg_name,0 ,0 ); + aead =crypto_alloc_aead_tfm (x->aead->alg_name,0 ,0 );
I'd like this to be configurable. After all, there's not much point in doing this if your crypto is done through PCI.
The easiest way is to let the user specify pcrypt through the algorithm name. In fact, as long as pcrypt has a higher priority than the default software algorithms, the user simply has to instantiate it in order for it to be the default for all uses of that algorithm.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtSteffen Klassert
maintainerRe: [RFC] [PATCH 4/4] esp: add the pcrypt hooks to esp
Quoted 6 lines · Herbert Xu
Quoted 5 lines · Steffen Klassert
net/ipv4/esp4.c +0
-0@@ -447,7 +448,7 @@ static int esp_init_aead(struct xfrm_state *x)struct crypto_aead *aead;int err;
Quoted 6 lines
Review static int esp_init_aead(struct xfrm_state *x) · line 451
Quoted 2 lines
(quoted diff) +1
-1- aead = crypto_alloc_aead(x->aead->alg_name, 0, 0); + aead = crypto_alloc_aead_tfm(x->aead->alg_name, 0, 0);I'd like this to be configurable. After all, there's not much point in doing this if your crypto is done through PCI.
Indeed, it should be configurable. I was not sure what's the best way to make it configurable, so I decided to just make it the default to be able to use it in this first version.
Quoted 6 lines
The easiest way is to let the user specify pcrypt through the algorithm name. In fact, as long as pcrypt has a higher priority than the default software algorithms, the user simply has to instantiate it in order for it to be the default for all uses of that algorithm.
For IPsec I thought about something like 'pcrypt(authenc(...,...))' to be able to process each crypto request with just one parallelization/serialization call. Perhaps I'm missing something, but actually I don't see how to choose for this from userspace through the name without adding an entry for each possible combination of hmac and blkcipher algorithm to the xfrm_aead_list. I'd appreciate any hint here. My idea to make it configurable was to do it similar to the async algorithms by
aead = crypto_alloc_aead_tfm(x->aead->alg_name, flags, CRYPTO_ALG_PCRYPT);
if CRYPTO_ALG_PCRYPT is set in flags, the crypto manager tries to choose a parallel algorithm, if it is not set parallel algorithms will be ignored. ~