Skip to contentSkip to conversation

crypto: Remove CRYPTO_TFM_REQ_MAY_SLEEP flag in AES-NI accelerated ecb/cbc mode

PATCH In review Huang Ying 2 participants 3 messages Jun 15, 2009 – Jun 19, 2009

Subsystems (2)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

PATCH 2/3 crypto: Remove CRYPTO_TFM_REQ_MAY_SLEEP flag in AES-NI accelerated ecb/cbc mode

Because AES-NI instructions will touch XMM state, corresponding code must be enclosed within kernel_fpu_begin/end, which used preempt_disable/enable. So sleep should be prevented between kernel_fpu_begin/end.

---
 arch/x86/crypto/aesni-intel_glue.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/x86/crypto/aesni-intel_glue.c +4 -0
@@ -198,6 +198,7 @@ static int ecb_encrypt(struct blkcipher_
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt(desc, &walk);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	kernel_fpu_begin();
 	while ((nbytes = walk.nbytes)) {
@@ -221,6 +222,7 @@ static int ecb_decrypt(struct blkcipher_
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt(desc, &walk);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	kernel_fpu_begin();
 	while ((nbytes = walk.nbytes)) {
@@ -266,6 +268,7 @@ static int cbc_encrypt(struct blkcipher_
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt(desc, &walk);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	kernel_fpu_begin();
 	while ((nbytes = walk.nbytes)) {
@@ -289,6 +292,7 @@ static int cbc_decrypt(struct blkcipher_
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt(desc, &walk);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	kernel_fpu_begin();
 	while ((nbytes = walk.nbytes)) {
maintainer
#1 lore raw
Quoted 6 lines · Huang Ying

Because AES-NI instructions will touch XMM state, corresponding code must be enclosed within kernel_fpu_begin/end, which used preempt_disable/enable. So sleep should be prevented between kernel_fpu_begin/end.

I'll apply this for now. But it would be much better to allow sleeping in this case.

Couldn't we simply move the kernel_fpu_begin/end inside the loop? It shouldn't be too expensive when it runs the 2nd time since it doesn't have to save anything, right?

Cheer,

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.txt
author
#2 lore raw
Quoted 6 lines · Herbert Xu
Quoted 5 lines · Huang Ying

Because AES-NI instructions will touch XMM state, corresponding code must be enclosed within kernel_fpu_begin/end, which used preempt_disable/enable. So sleep should be prevented between kernel_fpu_begin/end.

Quoted 8 lines
Quoted 1 line

I'll apply this for now. But it would be much better to allow sleeping in this case.

Couldn't we simply move the kernel_fpu_begin/end inside the loop? It shouldn't be too expensive when it runs the 2nd time since it doesn't have to save anything, right?

I will test the performance difference.

Best Regards,
Huang Ying