Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386/i386 Fix the secondary CPUs bug in i386. Same ...



details:   https://anonhg.NetBSD.org/src/rev/98ab5ee04da4
branches:  trunk
changeset: 815380:98ab5ee04da4
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat May 14 08:34:00 2016 +0000

description:
Fix the secondary CPUs bug in i386. Same as amd64.

diffstat:

 sys/arch/i386/i386/locore.S  |  37 ++++++++++++++++++++++++++++++++++---
 sys/arch/i386/i386/mptramp.S |  33 ++++++++++++++++++---------------
 2 files changed, 52 insertions(+), 18 deletions(-)

diffs (150 lines):

diff -r d61933b5d629 -r 98ab5ee04da4 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Sat May 14 08:19:42 2016 +0000
+++ b/sys/arch/i386/i386/locore.S       Sat May 14 08:34:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -168,6 +168,9 @@
 #endif /* XEN */
 #define        RELOC(x)        _RELOC(_C_LABEL(x))
 
+/* 32bit version of PG_NX */
+#define PG_NX32        0x80000000
+
 #ifndef PAE
 #define        PROC0_PDIR_OFF  0
 #else
@@ -234,6 +237,7 @@
  */
        .data
 
+       .globl  _C_LABEL(nox_flag)
        .globl  _C_LABEL(cputype)
        .globl  _C_LABEL(cpuid_level)
        .globl  _C_LABEL(esym)
@@ -279,6 +283,10 @@
        .long 0
 END(lapic_tpr)
 #endif
+
+       .type   _C_LABEL(nox_flag), @object
+LABEL(nox_flag)                .long   0       /* 32bit NOX flag, set if supported */
+END(nox_flag)
        .type   _C_LABEL(cputype), @object
 LABEL(cputype)         .long   0       /* are we 80486, Pentium, or.. */
 END(cputype)
@@ -550,6 +558,16 @@
         */
        movl    $_RELOC(tmpstk),%esp
 
+       /*
+        * Retrieve the NX/XD flag. We use the 32bit version of PG_NX.
+        */
+       movl    $0x80000001,%eax
+       cpuid
+       andl    $CPUID_NOX,%edx
+       jz      no_NOX
+       movl    $PG_NX32,RELOC(nox_flag)
+no_NOX:
+
 /*
  * There are two different layouts possible, depending on whether PAE is
  * enabled or not.
@@ -737,7 +755,20 @@
        movl    %eax,%cr3
 
        /*
-        * 2. Enable paging and the rest of it.
+        * 2. Set NOX in EFER, if available.
+        */
+       movl    RELOC(nox_flag),%ebx
+       cmpl    $0,%ebx
+       je      skip_NOX
+       movl    $MSR_EFER,%ecx
+       rdmsr
+       xorl    %eax,%eax
+       orl     $(EFER_NXE),%eax
+       wrmsr
+skip_NOX:
+
+       /*
+        * 3. Enable paging and the rest of it.
         */
        movl    %cr0,%eax
        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
diff -r d61933b5d629 -r 98ab5ee04da4 sys/arch/i386/i386/mptramp.S
--- a/sys/arch/i386/i386/mptramp.S      Sat May 14 08:19:42 2016 +0000
+++ b/sys/arch/i386/i386/mptramp.S      Sat May 14 08:34:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $        */
+/*     $NetBSD: mptramp.S,v 1.29 2016/05/14 08:34:00 maxv Exp $        */
 
 /*
  * Copyright (c) 2000, 2016 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.29 2016/05/14 08:34:00 maxv Exp $");
 
 #include "opt_mpbios.h"                /* for MPDEBUG */
 
@@ -177,11 +177,25 @@
        movl    %eax,%cr4
 #endif
 
+       /*
+        * Set NOX in EFER, if available.
+        */
+       movl    RELOC(nox_flag),%ebx
+       cmpl    $0,%ebx
+       je      no_NOX
+       movl    $MSR_EFER,%ecx
+       rdmsr
+       xorl    %eax,%eax
+       orl     $(EFER_NXE),%eax
+       wrmsr
+no_NOX:
+
+       /* Load %cr3. */
        movl    RELOC(mp_pdirpa),%ecx
        HALTT(0x5,%ecx)
+       movl    %ecx,%cr3               /* load PTD addr into MMU */
 
-       /* Load base of page directory and enable mapping. */
-       movl    %ecx,%cr3               /* load PTD addr into MMU */
+       /* Enable paging and the rest of it. */
        movl    %cr0,%eax
        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
        movl    %eax,%cr0
@@ -191,17 +205,6 @@
 #endif
        HALT(0x6)
 
-       /*
-        * If EFER_NXE is not enabled, fetching a page with a NX bit set
-        * will raise a #GP. Avoid that by setting the NXE feature now.
-        */
-       movl    _C_LABEL(cpu_feature)+2*4,%eax  /* cpu_feature[2] */
-       andl    $CPUID_NOX,%eax
-       jz      1f
-       movl    $MSR_EFER,%ecx
-       rdmsr
-       orl     $EFER_NXE,%eax  /* enable No-Execute feature */
-       wrmsr
 
 /*
  * ok, we are now running with paging enabled and sharing page tables



Home | Main Index | Thread Index | Old Index