summaryrefslogtreecommitdiffstats
path: root/sys/dev/random/nehemiah.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-06-05 16:00:53 +0000
committerkib <kib@FreeBSD.org>2010-06-05 16:00:53 +0000
commit6a41cd83d70cdd49e05e3507e1bff813ffbcdced (patch)
tree645d17d30352ada99870f57e7ca5b1fe43ad629c /sys/dev/random/nehemiah.c
parent2d77212fe48ecc0a97a3c56ca4cb8dc37493a066 (diff)
downloadFreeBSD-src-6a41cd83d70cdd49e05e3507e1bff813ffbcdced.zip
FreeBSD-src-6a41cd83d70cdd49e05e3507e1bff813ffbcdced.tar.gz
Use the fpu_kern_enter() interface to properly separate usermode FPU
context from in-kernel execution of padlock instructions and to handle spurious FPUDNA exceptions that sometime are raised when doing padlock calculations. Globally mark crypto(9) kthread as using FPU. Reviewed by: pjd Hardware provided by: Sentex Communications Tested by: pho PR: amd64/135014 MFC after: 1 month
Diffstat (limited to 'sys/dev/random/nehemiah.c')
-rw-r--r--sys/dev/random/nehemiah.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/sys/dev/random/nehemiah.c b/sys/dev/random/nehemiah.c
index e34cdfa..f91e228 100644
--- a/sys/dev/random/nehemiah.c
+++ b/sys/dev/random/nehemiah.c
@@ -35,6 +35,8 @@ __FBSDID("$FreeBSD$");
#include <sys/selinfo.h>
#include <sys/systm.h>
+#include <machine/pcb.h>
+
#include <dev/random/randomdev.h>
#define RANDOM_BLOCK_SIZE 256
@@ -82,6 +84,8 @@ static uint8_t out[RANDOM_BLOCK_SIZE+7] __aligned(16);
static union VIA_ACE_CW acw __aligned(16);
+static struct fpu_kern_ctx fpu_ctx_save;
+
static struct mtx random_nehemiah_mtx;
/* ARGSUSED */
@@ -142,11 +146,16 @@ random_nehemiah_deinit(void)
static int
random_nehemiah_read(void *buf, int c)
{
- int i;
+ int i, error;
size_t count, ret;
uint8_t *p;
mtx_lock(&random_nehemiah_mtx);
+ error = fpu_kern_enter(curthread, &fpu_ctx_save, FPU_KERN_NORMAL);
+ if (error != 0) {
+ mtx_unlock(&random_nehemiah_mtx);
+ return (0);
+ }
/* Get a random AES key */
count = 0;
@@ -187,6 +196,7 @@ random_nehemiah_read(void *buf, int c)
c = MIN(RANDOM_BLOCK_SIZE, c);
memcpy(buf, out, (size_t)c);
+ fpu_kern_leave(curthread, &fpu_ctx_save);
mtx_unlock(&random_nehemiah_mtx);
return (c);
}
OpenPOWER on IntegriCloud