Skip to contentSkip to conversation

x86/aesni: don't require alignment of data

PATCH In review Jakub Kicinski 3 participants 3 messages Dec 21, 2021 – Dec 31, 2021

Subsystems (5)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 x86/aesni: don't require alignment of data

x86 AES-NI routines can deal with unaligned data. Crypto context (key, iv etc.) have to be aligned but we take care of that separately by copying it onto the stack. We were feeding unaligned data into crypto routines up until commit 83c83e658863 ("crypto: aesni - refactor scatterlist processing") switched to use the full skcipher API which uses cra_alignmask to decide data alignment.

This fixes 21% performance regression in kTLS.

Tested by booting with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y (and running thru various kTLS packets).

Fixes 83c83e658863 ("crypto: aesni - refactor scatterlist processing")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 arch/x86/crypto/aesni-intel_glue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/crypto/aesni-intel_glue.c +2 -2
index e09f4672dd38..41901ba9d3a2 100644
@@ -1107,7 +1107,7 @@ static struct aead_alg aesni_aeads[] = { {
 		.cra_flags		= CRYPTO_ALG_INTERNAL,
 		.cra_blocksize		= 1,
 		.cra_ctxsize		= sizeof(struct aesni_rfc4106_gcm_ctx),
-		.cra_alignmask		= AESNI_ALIGN - 1,
+		.cra_alignmask		= 0,
 		.cra_module		= THIS_MODULE,
 	},
 }, {
@@ -1124,7 +1124,7 @@ static struct aead_alg aesni_aeads[] = { {
 		.cra_flags		= CRYPTO_ALG_INTERNAL,
 		.cra_blocksize		= 1,
 		.cra_ctxsize		= sizeof(struct generic_gcmaes_ctx),
-		.cra_alignmask		= AESNI_ALIGN - 1,
+		.cra_alignmask		= 0,
 		.cra_module		= THIS_MODULE,
 	},
 } };
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jakub Kicinski

x86 AES-NI routines can deal with unaligned data. Crypto context (key, iv etc.) have to be aligned but we take care of that separately by copying it onto the stack. We were feeding unaligned data into crypto routines up until commit 83c83e658863 ("crypto: aesni - refactor scatterlist processing") switched to use the full skcipher API which uses cra_alignmask to decide data alignment.

Quoted 8 lines

This fixes 21% performance regression in kTLS.

Tested by booting with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y (and running thru various kTLS packets).

Fixes 83c83e658863 ("crypto: aesni - refactor scatterlist processing")
Quoted 34 lines

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 arch/x86/crypto/aesni-intel_glue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/crypto/aesni-intel_glue.c +2 -3
index e09f4672dd38..41901ba9d3a2 100644
@@ -1107,7 +1107,7 @@ static struct aead_alg aesni_aeads[] = { {
                .cra_flags              = CRYPTO_ALG_INTERNAL,
                .cra_blocksize          = 1,
                .cra_ctxsize            = sizeof(struct aesni_rfc4106_gcm_ctx),
-               .cra_alignmask          = AESNI_ALIGN - 1,
+               .cra_alignmask          = 0,
                .cra_module             = THIS_MODULE,
        },
 }, {
@@ -1124,7 +1124,7 @@ static struct aead_alg aesni_aeads[] = { {
                .cra_flags              = CRYPTO_ALG_INTERNAL,
                .cra_blocksize          = 1,
                .cra_ctxsize            = sizeof(struct generic_gcmaes_ctx),
-               .cra_alignmask          = AESNI_ALIGN - 1,
+               .cra_alignmask          = 0,
                .cra_module             = THIS_MODULE,
        },
 } };
--

2.31.1

maintainer
#2 lore raw
In reply to Jakub Kicinski
Quoted 15 lines · Jakub Kicinski

x86 AES-NI routines can deal with unaligned data. Crypto context (key, iv etc.) have to be aligned but we take care of that separately by copying it onto the stack. We were feeding unaligned data into crypto routines up until commit 83c83e658863 ("crypto: aesni - refactor scatterlist processing") switched to use the full skcipher API which uses cra_alignmask to decide data alignment.

This fixes 21% performance regression in kTLS.

Tested by booting with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y (and running thru various kTLS packets).

Fixes 83c83e658863 ("crypto: aesni - refactor scatterlist processing")
Quoted 8 lines

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 arch/x86/crypto/aesni-intel_glue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt