Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Add splhigh() around the FPU code, we don't...



details:   https://anonhg.NetBSD.org/src/rev/800cacbb5cad
branches:  trunk
changeset: 833828:800cacbb5cad
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Jul 14 14:46:41 2018 +0000

description:
Add splhigh() around the FPU code, we don't want to be preempted in the
middle, this could corrupt the FPU state and trigger undefined behavior.

Intentionally use splhigh and not kpreempt_disable, to match the generic
x86 FPU code.

Compile-tested only (I don't have VIA).

Found by Maya almost a year ago.

diffstat:

 sys/arch/x86/x86/via_padlock.c |  17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diffs (47 lines):

diff -r 9b97f9f4757f -r 800cacbb5cad sys/arch/x86/x86/via_padlock.c
--- a/sys/arch/x86/x86/via_padlock.c    Sat Jul 14 14:34:32 2018 +0000
+++ b/sys/arch/x86/x86/via_padlock.c    Sat Jul 14 14:46:41 2018 +0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $     */
-/*     $NetBSD: via_padlock.c,v 1.25 2016/02/27 00:54:59 tls Exp $ */
+/*     $NetBSD: via_padlock.c,v 1.26 2018/07/14 14:46:41 maxv Exp $ */
 
 /*-
  * Copyright (c) 2003 Jason Wright
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.25 2016/02/27 00:54:59 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.26 2018/07/14 14:46:41 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -332,10 +332,13 @@
 via_padlock_cbc(void *cw, void *src, void *dst, void *key, int rep,
     void *iv)
 {
-       unsigned int creg0;
+       unsigned int cr0;
+       int s;
 
-       creg0 = rcr0();         /* Permit access to SIMD/FPU path */
-       lcr0(creg0 & ~(CR0_EM|CR0_TS));
+       s = splhigh();
+
+       cr0 = rcr0();           /* Permit access to SIMD/FPU path */
+       lcr0(cr0 & ~(CR0_EM|CR0_TS));
 
        /* Do the deed */
        __asm __volatile("pushfl; popfl");      /* force key reload */
@@ -343,7 +346,9 @@
                        : "a" (iv), "b" (key), "c" (rep), "d" (cw), "S" (src), "D" (dst)
                        : "memory", "cc");
 
-       lcr0(creg0);
+       lcr0(cr0);
+
+       splx(s);
 }
 
 int



Home | Main Index | Thread Index | Old Index