Date: Sun, 16 Nov 2014 04:00:56 GMT From: John-Mark Gurney <jmg@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 1202863 for review Message-ID: <201411160400.sAG40uqU016826@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@1202863?ac=10 Change 1202863 by jmg@jmg_carbon2 on 2014/11/16 04:00:03 add a lock to protect aesni session state... This will need to be figured out how to handle this better for now.. but we can't share cpu context between sessions... I'm not really sure how the code on HEAD works w/o this without hitting the same issue... Sponsored by: FreeBSD Foundation Sponsored by: Netgate Affected files ... .. //depot/projects/opencrypto/sys/crypto/aesni/aesni.c#14 edit .. //depot/projects/opencrypto/sys/crypto/aesni/aesni.h#4 edit Differences ... ==== //depot/projects/opencrypto/sys/crypto/aesni/aesni.c#14 (text+ko) ==== @@ -39,6 +39,7 @@ #include <sys/kobj.h> #include <sys/libkern.h> #include <sys/lock.h> +#include <sys/mutex.h> #include <sys/module.h> #include <sys/malloc.h> #include <sys/rwlock.h> @@ -140,6 +141,7 @@ while ((ses = TAILQ_FIRST(&sc->sessions)) != NULL) { TAILQ_REMOVE(&sc->sessions, ses, next); fpu_kern_free_ctx(ses->fpu_ctx); + mtx_destroy(&ses->lck); free(ses, M_AESNI); } rw_wunlock(&sc->lock); @@ -213,6 +215,7 @@ rw_wunlock(&sc->lock); return (ENOMEM); } + mtx_init(&ses->lck, "aesni session", NULL, MTX_DEF); ses->id = sc->sid++; } else { TAILQ_REMOVE(&sc->sessions, ses, next); @@ -240,13 +243,16 @@ { struct fpu_kern_ctx *ctx; uint32_t sid; + struct mtx lck; sid = ses->id; + lck = ses->lck; TAILQ_REMOVE(&sc->sessions, ses, next); ctx = ses->fpu_ctx; - bzero(ses, sizeof(*ses)); + *ses = (struct aesni_session){}; ses->id = sid; ses->fpu_ctx = ctx; + ses->lck = lck; TAILQ_INSERT_HEAD(&sc->sessions, ses, next); } @@ -433,13 +439,17 @@ int error; td = curthread; + mtx_lock(&ses->lck); error = fpu_kern_enter(td, ses->fpu_ctx, FPU_KERN_NORMAL | FPU_KERN_KTHR); - if (error != 0) + if (error != 0) { + mtx_unlock(&ses->lck); return (error); + } error = aesni_cipher_setup_common(ses, encini->cri_key, encini->cri_klen); fpu_kern_leave(td, ses->fpu_ctx); + mtx_unlock(&ses->lck); return (error); } @@ -478,6 +488,7 @@ } td = curthread; + mtx_lock(&ses->lck); error = fpu_kern_enter(td, ses->fpu_ctx, FPU_KERN_NORMAL | FPU_KERN_KTHR); if (error != 0) @@ -585,6 +596,7 @@ out: fpu_kern_leave(td, ses->fpu_ctx); + mtx_unlock(&ses->lck); out1: if (allocated) { bzero(buf, enccrd->crd_len); ==== //depot/projects/opencrypto/sys/crypto/aesni/aesni.h#4 (text+ko) ==== @@ -66,6 +66,7 @@ uint32_t id; TAILQ_ENTRY(aesni_session) next; struct fpu_kern_ctx *fpu_ctx; + struct mtx lck; }; /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411160400.sAG40uqU016826>