MFaesni r215427:

Only save FPU context when not executing in the context of the crypto
thread.

Tested by:	Mike Tancsa
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2010-11-26 14:35:20 +00:00
parent d7e6be6924
commit 3e07b6217f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215864
3 changed files with 31 additions and 9 deletions

View File

@ -170,7 +170,7 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
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_t *sidp, struct cryptoini *cri)
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);

View File

@ -205,7 +205,7 @@ padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
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_session *ses, struct cryptodesc *enccrd,
}
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,

View File

@ -366,17 +366,24 @@ padlock_hash_process(struct padlock_session *ses, struct cryptodesc *maccrd,
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);
}