Author: kib
Date: Fri Nov 26 14:35:20 2010
New Revision: 215864
URL: http://svn.freebsd.org/changeset/base/215864

Log:
  MFaesni r215427:
  Only save FPU context when not executing in the context of the crypto
  thread.
  
  Tested by:    Mike Tancsa
  MFC after:    1 week

Modified:
  head/sys/crypto/via/padlock.c
  head/sys/crypto/via/padlock_cipher.c
  head/sys/crypto/via/padlock_hash.c

Modified: head/sys/crypto/via/padlock.c
==============================================================================
--- head/sys/crypto/via/padlock.c       Fri Nov 26 11:57:45 2010        
(r215863)
+++ head/sys/crypto/via/padlock.c       Fri Nov 26 14:35:20 2010        
(r215864)
@@ -170,7 +170,7 @@ padlock_newsession(device_t dev, uint32_
        struct padlock_session *ses = NULL;
        struct cryptoini *encini, *macini;
        struct thread *td;
-       int error;
+       int error, saved_ctx;
 
        if (sidp == NULL || cri == NULL)
                return (EINVAL);
@@ -238,10 +238,18 @@ padlock_newsession(device_t dev, uint32_
 
        if (macini != NULL) {
                td = curthread;
-               error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
+               if (!is_fpu_kern_thread(0)) {
+                       error = fpu_kern_enter(td, &ses->ses_fpu_ctx,
+                           FPU_KERN_NORMAL);
+                       saved_ctx = 1;
+               } else {
+                       error = 0;
+                       saved_ctx = 0;
+               }
                if (error == 0) {
                        error = padlock_hash_setup(ses, macini);
-                       fpu_kern_leave(td, &ses->ses_fpu_ctx);
+                       if (saved_ctx)
+                               fpu_kern_leave(td, &ses->ses_fpu_ctx);
                }
                if (error != 0) {
                        padlock_freesession_one(sc, ses, 0);

Modified: head/sys/crypto/via/padlock_cipher.c
==============================================================================
--- head/sys/crypto/via/padlock_cipher.c        Fri Nov 26 11:57:45 2010        
(r215863)
+++ head/sys/crypto/via/padlock_cipher.c        Fri Nov 26 14:35:20 2010        
(r215864)
@@ -205,7 +205,7 @@ padlock_cipher_process(struct padlock_se
        struct thread *td;
        u_char *buf, *abuf;
        uint32_t *key;
-       int allocated, error;
+       int allocated, error, saved_ctx;
 
        buf = padlock_cipher_alloc(enccrd, crp, &allocated);
        if (buf == NULL)
@@ -250,14 +250,21 @@ padlock_cipher_process(struct padlock_se
        }
 
        td = curthread;
-       error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
+       if (!is_fpu_kern_thread(0)) {
+               error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
+               saved_ctx = 1;
+       } else {
+               error = 0;
+               saved_ctx = 0;
+       }
        if (error != 0)
                goto out;
 
        padlock_cbc(abuf, abuf, enccrd->crd_len / AES_BLOCK_LEN, key, cw,
            ses->ses_iv);
 
-       fpu_kern_leave(td, &ses->ses_fpu_ctx);
+       if (saved_ctx)
+               fpu_kern_leave(td, &ses->ses_fpu_ctx);
 
        if (allocated) {
                crypto_copyback(crp->crp_flags, crp->crp_buf, enccrd->crd_skip,

Modified: head/sys/crypto/via/padlock_hash.c
==============================================================================
--- head/sys/crypto/via/padlock_hash.c  Fri Nov 26 11:57:45 2010        
(r215863)
+++ head/sys/crypto/via/padlock_hash.c  Fri Nov 26 14:35:20 2010        
(r215864)
@@ -366,17 +366,24 @@ padlock_hash_process(struct padlock_sess
     struct cryptop *crp)
 {
        struct thread *td;
-       int error;
+       int error, saved_ctx;
 
        td = curthread;
-       error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
+       if (!is_fpu_kern_thread(0)) {
+               error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
+               saved_ctx = 1;
+       } else {
+               error = 0;
+               saved_ctx = 0;
+       }
        if (error != 0)
                return (error);
        if ((maccrd->crd_flags & CRD_F_KEY_EXPLICIT) != 0)
                padlock_hash_key_setup(ses, maccrd->crd_key, maccrd->crd_klen);
 
        error = padlock_authcompute(ses, maccrd, crp->crp_buf, crp->crp_flags);
-       fpu_kern_leave(td, &ses->ses_fpu_ctx);
+       if (saved_ctx)
+               fpu_kern_leave(td, &ses->ses_fpu_ctx);
        return (error);
 }
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to