Module Name: src
Committed By: snj
Date: Fri Apr 23 04:17:31 UTC 2010
Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: locore.S machdep.c mptramp.S
src/sys/arch/i386/i386 [netbsd-5-0]: machdep.c
src/sys/arch/i386/isa [netbsd-5-0]: npx.c
src/sys/arch/x86/include [netbsd-5-0]: cpu.h cpuvar.h
src/sys/arch/x86/x86 [netbsd-5-0]: cpu.c identcpu.c pmap.c
src/sys/arch/xen/x86 [netbsd-5-0]: cpu.c
Log Message:
Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
To generate a diff of this commit:
cvs rdiff -u -r1.47.8.2.2.1 -r1.47.8.2.2.2 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.102.4.10 -r1.102.4.10.2.1 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.9 -r1.9.14.1 src/sys/arch/amd64/amd64/mptramp.S
cvs rdiff -u -r1.644.4.10 -r1.644.4.10.2.1 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.129.10.5 -r1.129.10.5.2.1 src/sys/arch/i386/isa/npx.c
cvs rdiff -u -r1.9 -r1.9.8.1 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.27 -r1.27.14.1 src/sys/arch/x86/include/cpuvar.h
cvs rdiff -u -r1.57.4.3 -r1.57.4.3.2.1 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.10.4.2.2.1 -r1.10.4.2.2.2 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.74.4.1 -r1.74.4.1.2.1 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.28.4.1 -r1.28.4.1.2.1 src/sys/arch/xen/x86/cpu.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.47.8.2.2.1 src/sys/arch/amd64/amd64/locore.S:1.47.8.2.2.2
--- src/sys/arch/amd64/amd64/locore.S:1.47.8.2.2.1 Thu Apr 22 19:39:44 2010
+++ src/sys/arch/amd64/amd64/locore.S Fri Apr 23 04:17:29 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.47.8.2.2.1 2010/04/22 19:39:44 snj Exp $ */
+/* $NetBSD: locore.S,v 1.47.8.2.2.2 2010/04/23 04:17:29 snj Exp $ */
/*
* Copyright-o-rama!
@@ -235,7 +235,7 @@
#endif
.globl _C_LABEL(cpu_id),_C_LABEL(cpu_vendorname), _C_LABEL(cpu_brand_id)
- .globl _C_LABEL(cpuid_level),_C_LABEL(cpu_feature),_C_LABEL(cpu_feature2)
+ .globl _C_LABEL(cpuid_level)
.globl _C_LABEL(esym),_C_LABEL(eblob),_C_LABEL(boothowto)
.globl _C_LABEL(bootinfo),_C_LABEL(atdevbase)
.globl _C_LABEL(proc0paddr),_C_LABEL(PDPpaddr)
@@ -245,10 +245,6 @@
_C_LABEL(cpu): .long 0 # are we 386, 386sx, or 486,
# or Pentium, or..
_C_LABEL(cpu_id): .long 0 # saved from `cpuid' instruction
-_C_LABEL(cpu_feature): .long 0 # feature flags from 'cpuid'
- # instruction
-_C_LABEL(cpu_feature2): .long 0 # feature flags from 'cpuid'
- # instruction
_C_LABEL(cpuid_level): .long -1 # max. level accepted by 'cpuid'
# instruction
_C_LABEL(cpu_vendorname): .space 16 # vendor string returned by `cpuid'
@@ -300,7 +296,7 @@
gdt64_end:
farjmp64:
- .long longmode-KERNBASE
+ .long _RELOC(longmode)
.word GSEL(GCODE_SEL, SEL_KPL)
#endif /* !XEN */
@@ -423,18 +419,11 @@
movl $1,%eax
cpuid
movl %eax,RELOC(cpu_id)
- movl %edx,RELOC(cpu_feature)
- movl %ecx,RELOC(cpu_feature2)
/* Brand ID is bits 0-7 of %ebx */
andl $255,%ebx
movl %ebx,RELOC(cpu_brand_id)
- /* add AMD specific feature flags */
- movl $0x80000001,%eax
- cpuid
- orl %edx,RELOC(cpu_feature)
-
/*
* Finished with old stack; load new %esp now instead of later so we
* can trace this code without having to worry about the trace trap
Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.102.4.10 src/sys/arch/amd64/amd64/machdep.c:1.102.4.10.2.1
--- src/sys/arch/amd64/amd64/machdep.c:1.102.4.10 Sat Apr 4 17:39:09 2009
+++ src/sys/arch/amd64/amd64/machdep.c Fri Apr 23 04:17:29 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.102.4.10 2009/04/04 17:39:09 snj Exp $ */
+/* $NetBSD: machdep.c,v 1.102.4.10.2.1 2010/04/23 04:17:29 snj Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -112,7 +112,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.102.4.10 2009/04/04 17:39:09 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.102.4.10.2.1 2010/04/23 04:17:29 snj Exp $");
/* #define XENDEBUG_LOW */
@@ -1386,9 +1386,9 @@
__PRINTK(("init_x86_64(0x%lx)\n", first_avail));
first_bt_vaddr = (vaddr_t) (first_avail + KERNBASE + PAGE_SIZE * 2);
__PRINTK(("first_bt_vaddr 0x%lx\n", first_bt_vaddr));
- cpu_feature = cpu_info_primary.ci_feature_flags;
/* not on Xen... */
- cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR|CPUID_NOX);
+ cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR);
+ cpu_feature3 &= ~(CPUID_NOX);
#endif /* XEN */
cpu_init_msrs(&cpu_info_primary, true);
Index: src/sys/arch/amd64/amd64/mptramp.S
diff -u src/sys/arch/amd64/amd64/mptramp.S:1.9 src/sys/arch/amd64/amd64/mptramp.S:1.9.14.1
--- src/sys/arch/amd64/amd64/mptramp.S:1.9 Tue May 13 22:39:17 2008
+++ src/sys/arch/amd64/amd64/mptramp.S Fri Apr 23 04:17:29 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: mptramp.S,v 1.9 2008/05/13 22:39:17 ad Exp $ */
+/* $NetBSD: mptramp.S,v 1.9.14.1 2010/04/23 04:17:29 snj Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -223,7 +223,7 @@
testq %rdi, %rdi
jz 1b
- movl _C_LABEL(cpu_feature),%eax
+ movl _C_LABEL(cpu_feature3),%eax
andl $CPUID_NOX,%eax
jz 1f
movl $MSR_EFER,%ecx
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.644.4.10 src/sys/arch/i386/i386/machdep.c:1.644.4.10.2.1
--- src/sys/arch/i386/i386/machdep.c:1.644.4.10 Sat Apr 4 17:39:09 2009
+++ src/sys/arch/i386/i386/machdep.c Fri Apr 23 04:17:29 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.644.4.10 2009/04/04 17:39:09 snj Exp $ */
+/* $NetBSD: machdep.c,v 1.644.4.10.2.1 2010/04/23 04:17:29 snj Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.644.4.10 2009/04/04 17:39:09 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.644.4.10.2.1 2010/04/23 04:17:29 snj Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@@ -248,9 +248,6 @@
int physmem;
-unsigned int cpu_feature;
-unsigned int cpu_feature2;
-unsigned int cpu_feature_padlock;
int cpu_class;
int i386_fpu_present;
int i386_fpu_exception;
@@ -1433,8 +1430,6 @@
cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0];
#endif
cpu_probe(&cpu_info_primary);
- cpu_feature = cpu_info_primary.ci_feature_flags;
- cpu_feature2 = cpu_info_primary.ci_feature2_flags;
cpu_feature_padlock = cpu_info_primary.ci_padlock_flags;
proc0paddr = UAREA_TO_USER(proc0uarea);
@@ -1442,7 +1437,8 @@
#ifdef XEN
/* not on Xen... */
- cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR|CPUID_NOX);
+ cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR);
+ cpu_feature3 &= ~(CPUID_NOX);
lwp0.l_addr->u_pcb.pcb_cr3 = PDPpaddr - KERNBASE;
__PRINTK(("pcb_cr3 0x%lx cr3 0x%lx\n",
PDPpaddr - KERNBASE, xpmap_ptom(PDPpaddr - KERNBASE)));
Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.129.10.5 src/sys/arch/i386/isa/npx.c:1.129.10.5.2.1
--- src/sys/arch/i386/isa/npx.c:1.129.10.5 Thu Nov 27 03:37:02 2008
+++ src/sys/arch/i386/isa/npx.c Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: npx.c,v 1.129.10.5 2008/11/27 03:37:02 snj Exp $ */
+/* $NetBSD: npx.c,v 1.129.10.5.2.1 2010/04/23 04:17:30 snj Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.129.10.5 2008/11/27 03:37:02 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.129.10.5.2.1 2010/04/23 04:17:30 snj Exp $");
#if 0
#define IPRINTF(x) printf x
@@ -124,6 +124,7 @@
#include <uvm/uvm_extern.h>
#include <machine/cpufunc.h>
+#include <machine/cpuvar.h>
#include <machine/pcb.h>
#include <machine/trap.h>
#include <machine/specialreg.h>
Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.9 src/sys/arch/x86/include/cpu.h:1.9.8.1
--- src/sys/arch/x86/include/cpu.h:1.9 Sat Oct 25 19:13:40 2008
+++ src/sys/arch/x86/include/cpu.h Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.9 2008/10/25 19:13:40 mrg Exp $ */
+/* $NetBSD: cpu.h,v 1.9.8.1 2010/04/23 04:17:30 snj Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -304,9 +304,6 @@
extern int biosbasemem;
extern int biosextmem;
-extern unsigned int cpu_feature;
-extern unsigned int cpu_feature2;
-extern unsigned int cpu_feature_padlock;
extern int cpu;
extern int cpuid_level;
extern int cpu_class;
Index: src/sys/arch/x86/include/cpuvar.h
diff -u src/sys/arch/x86/include/cpuvar.h:1.27 src/sys/arch/x86/include/cpuvar.h:1.27.14.1
--- src/sys/arch/x86/include/cpuvar.h:1.27 Tue May 13 22:39:17 2008
+++ src/sys/arch/x86/include/cpuvar.h Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuvar.h,v 1.27 2008/05/13 22:39:17 ad Exp $ */
+/* $NetBSD: cpuvar.h,v 1.27.14.1 2010/04/23 04:17:30 snj Exp $ */
/*-
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -136,6 +136,11 @@
extern int cpu_vendor;
extern bool x86_mp_online;
+extern uint32_t cpu_feature;
+extern uint32_t cpu_feature2;
+extern uint32_t cpu_feature3;
+extern uint32_t cpu_feature4;
+extern uint32_t cpu_feature_padlock;
#endif
#endif /* !_X86_CPUVAR_H_ */
Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.57.4.3 src/sys/arch/x86/x86/cpu.c:1.57.4.3.2.1
--- src/sys/arch/x86/x86/cpu.c:1.57.4.3 Mon Feb 2 20:10:16 2009
+++ src/sys/arch/x86/x86/cpu.c Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.57.4.3 2009/02/02 20:10:16 snj Exp $ */
+/* $NetBSD: cpu.c,v 1.57.4.3.2.1 2010/04/23 04:17:30 snj Exp $ */
/*-
* Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.57.4.3 2009/02/02 20:10:16 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.57.4.3.2.1 2010/04/23 04:17:30 snj Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -167,6 +167,13 @@
uint32_t cpus_attached = 0;
uint32_t cpus_running = 0;
+/* CPUID feature flags */
+uint32_t cpu_feature; /* %edx */
+uint32_t cpu_feature2; /* %ecx */
+uint32_t cpu_feature3; /* extended features - %edx */
+uint32_t cpu_feature4; /* extended features - %ecx */
+uint32_t cpu_feature_padlock; /* VIA PadLock feature flags */
+
extern char x86_64_doubleflt_stack[];
bool x86_mp_online;
@@ -969,7 +976,7 @@
wrmsr(MSR_KERNELGSBASE, 0);
}
- if (cpu_feature & CPUID_NOX)
+ if (cpu_feature3 & CPUID_NOX)
wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NXE);
}
#endif /* __x86_64__ */
Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.10.4.2.2.1 src/sys/arch/x86/x86/identcpu.c:1.10.4.2.2.2
--- src/sys/arch/x86/x86/identcpu.c:1.10.4.2.2.1 Thu Apr 22 19:41:49 2010
+++ src/sys/arch/x86/x86/identcpu.c Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: identcpu.c,v 1.10.4.2.2.1 2010/04/22 19:41:49 snj Exp $ */
+/* $NetBSD: identcpu.c,v 1.10.4.2.2.2 2010/04/23 04:17:30 snj Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.10.4.2.2.1 2010/04/22 19:41:49 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.10.4.2.2.2 2010/04/23 04:17:30 snj Exp $");
#include "opt_enhanced_speedstep.h"
#include "opt_intel_odcm.h"
@@ -363,8 +363,8 @@
x86_cpuid(0x80000000, descs);
if (descs[0] >= 0x80000001) {
x86_cpuid(0x80000001, descs);
- ci->ci_feature3_flags |= descs[3]; /* %edx */
- ci->ci_feature4_flags = descs[2]; /* %ecx */
+ ci->ci_feature4_flags = descs[2]; /* %ecx */
+ ci->ci_feature3_flags = descs[3]; /* %edx */
}
cpu_probe_amd_cache(ci);
@@ -702,6 +702,8 @@
/* If first. */
cpu_feature = ci->ci_feature_flags;
cpu_feature2 = ci->ci_feature2_flags;
+ cpu_feature3 = ci->ci_feature3_flags;
+ cpu_feature4 = ci->ci_feature4_flags;
/* Early patch of text segment. */
#ifndef XEN
x86_patch(true);
@@ -710,6 +712,8 @@
/* If not first. */
cpu_feature &= ci->ci_feature_flags;
cpu_feature2 &= ci->ci_feature2_flags;
+ cpu_feature3 &= ci->ci_feature3_flags;
+ cpu_feature4 &= ci->ci_feature4_flags;
}
}
Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.74.4.1 src/sys/arch/x86/x86/pmap.c:1.74.4.1.2.1
--- src/sys/arch/x86/x86/pmap.c:1.74.4.1 Sat Apr 4 17:39:09 2009
+++ src/sys/arch/x86/x86/pmap.c Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.74.4.1 2009/04/04 17:39:09 snj Exp $ */
+/* $NetBSD: pmap.c,v 1.74.4.1.2.1 2010/04/23 04:17:30 snj Exp $ */
/*
* Copyright (c) 2007 Manuel Bouyer.
@@ -154,7 +154,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.74.4.1 2009/04/04 17:39:09 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.74.4.1.2.1 2010/04/23 04:17:30 snj Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -1074,7 +1074,7 @@
npte = ma | ((prot & VM_PROT_WRITE) ? PG_RW : PG_RO) |
PG_V | PG_k;
#ifndef XEN
- if ((cpu_feature & CPUID_NOX) && !(prot & VM_PROT_EXECUTE))
+ if ((cpu_feature3 & CPUID_NOX) && !(prot & VM_PROT_EXECUTE))
npte |= PG_NX;
#endif
opte = pmap_pte_testset (pte, npte); /* zap! */
@@ -1199,7 +1199,7 @@
#else
unsigned long p1i;
vaddr_t kva_end;
- pt_entry_t pg_nx = (cpu_feature & CPUID_NOX ? PG_NX : 0);
+ pt_entry_t pg_nx = (cpu_feature3 & CPUID_NOX ? PG_NX : 0);
#endif
/*
Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.28.4.1 src/sys/arch/xen/x86/cpu.c:1.28.4.1.2.1
--- src/sys/arch/xen/x86/cpu.c:1.28.4.1 Thu Nov 13 00:04:07 2008
+++ src/sys/arch/xen/x86/cpu.c Fri Apr 23 04:17:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.28.4.1 2008/11/13 00:04:07 snj Exp $ */
+/* $NetBSD: cpu.c,v 1.28.4.1.2.1 2010/04/23 04:17:30 snj Exp $ */
/* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp */
/*-
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.28.4.1 2008/11/13 00:04:07 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.28.4.1.2.1 2010/04/23 04:17:30 snj Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -173,6 +173,13 @@
uint32_t cpus_attached = 0;
uint32_t cpus_running = 0;
+/* CPUID feature flags */
+uint32_t cpu_feature; /* %edx */
+uint32_t cpu_feature2; /* %ecx */
+uint32_t cpu_feature3; /* extended features - %edx */
+uint32_t cpu_feature4; /* extended features - %ecx */
+uint32_t cpu_feature_padlock; /* VIA PadLock feature flags */
+
bool x86_mp_online;
paddr_t mp_trampoline_paddr = MP_TRAMPOLINE;
@@ -679,7 +686,6 @@
{
struct cpu_info *ci = (struct cpu_info *)v;
int s, i;
- uint32_t blacklist_features;
#ifdef __x86_64__
cpu_init_msrs(ci, true);
@@ -688,9 +694,8 @@
cpu_probe(ci);
/* not on Xen... */
- blacklist_features = ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR|CPUID_NOX); /* XXX add CPUID_SVM */
-
- cpu_feature &= blacklist_features;
+ cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR); /* XXX add CPUID_SVM */
+ cpu_feature3 &= ~CPUID_NOX;
KDASSERT((ci->ci_flags & CPUF_PRESENT) == 0);
atomic_or_32(&ci->ci_flags, CPUF_PRESENT);