Module Name: src
Committed By: jym
Date: Tue May 4 23:27:14 UTC 2010
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c trap.c
src/sys/arch/i386/include: pte.h
src/sys/arch/x86/include: specialreg.h
src/sys/arch/x86/x86: pmap.c
src/sys/arch/xen/x86: cpu.c
Log Message:
Enable the NX bit feature for Xen i386pae and amd64 kernels.
Tested with Xen 3.1 and Xen 3.3, dom0 and domU, by bouyer@ and j...@.
Ok bou...@.
To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.686 -r1.687 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.256 -r1.257 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/include/pte.h
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.43 -r1.44 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/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.144 src/sys/arch/amd64/amd64/machdep.c:1.145
--- src/sys/arch/amd64/amd64/machdep.c:1.144 Sun Apr 18 23:47:50 2010
+++ src/sys/arch/amd64/amd64/machdep.c Tue May 4 23:27:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.144 2010/04/18 23:47:50 jym Exp $ */
+/* $NetBSD: machdep.c,v 1.145 2010/05/04 23:27:13 jym Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.144 2010/04/18 23:47:50 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.145 2010/05/04 23:27:13 jym Exp $");
/* #define XENDEBUG_LOW */
@@ -1253,7 +1253,6 @@
#endif /* XEN */
cpu_feature[0] &= ~CPUID_FEAT_BLACKLIST;
- cpu_feature[2] &= ~CPUID_EXT_FEAT_BLACKLIST;
cpu_init_msrs(&cpu_info_primary, true);
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.686 src/sys/arch/i386/i386/machdep.c:1.687
--- src/sys/arch/i386/i386/machdep.c:1.686 Fri Apr 23 16:07:33 2010
+++ src/sys/arch/i386/i386/machdep.c Tue May 4 23:27:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.686 2010/04/23 16:07:33 joerg Exp $ */
+/* $NetBSD: machdep.c,v 1.687 2010/05/04 23:27:13 jym 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.686 2010/04/23 16:07:33 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.687 2010/05/04 23:27:13 jym Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@@ -1299,7 +1299,6 @@
pcb = lwp_getpcb(&lwp0);
cpu_feature[0] &= ~CPUID_FEAT_BLACKLIST;
- cpu_feature[2] &= ~CPUID_EXT_FEAT_BLACKLIST;
cpu_init_msrs(&cpu_info_primary, true);
Index: src/sys/arch/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.256 src/sys/arch/i386/i386/trap.c:1.257
--- src/sys/arch/i386/i386/trap.c:1.256 Fri Apr 23 19:18:09 2010
+++ src/sys/arch/i386/i386/trap.c Tue May 4 23:27:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.256 2010/04/23 19:18:09 rmind Exp $ */
+/* $NetBSD: trap.c,v 1.257 2010/05/04 23:27:13 jym Exp $ */
/*-
* Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.256 2010/04/23 19:18:09 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.257 2010/05/04 23:27:13 jym Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -671,6 +671,8 @@
map = &vm->vm_map;
if (frame->tf_err & PGEX_W)
ftype = VM_PROT_WRITE;
+ else if (frame->tf_err & PGEX_X)
+ ftype = VM_PROT_EXECUTE;
else
ftype = VM_PROT_READ;
Index: src/sys/arch/i386/include/pte.h
diff -u src/sys/arch/i386/include/pte.h:1.22 src/sys/arch/i386/include/pte.h:1.23
--- src/sys/arch/i386/include/pte.h:1.22 Tue Apr 6 20:43:57 2010
+++ src/sys/arch/i386/include/pte.h Tue May 4 23:27:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: pte.h,v 1.22 2010/04/06 20:43:57 jld Exp $ */
+/* $NetBSD: pte.h,v 1.23 2010/05/04 23:27:14 jym Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -274,5 +274,6 @@
#define PGEX_P 0x01 /* protection violation (vs. no mapping) */
#define PGEX_W 0x02 /* exception during a write cycle */
#define PGEX_U 0x04 /* exception while in user mode (upl) */
+#define PGEX_X 0x10 /* exception during instruction fetch */
#endif /* _I386_PTE_H_ */
Index: src/sys/arch/x86/include/specialreg.h
diff -u src/sys/arch/x86/include/specialreg.h:1.40 src/sys/arch/x86/include/specialreg.h:1.41
--- src/sys/arch/x86/include/specialreg.h:1.40 Sun Apr 18 23:47:51 2010
+++ src/sys/arch/x86/include/specialreg.h Tue May 4 23:27:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: specialreg.h,v 1.40 2010/04/18 23:47:51 jym Exp $ */
+/* $NetBSD: specialreg.h,v 1.41 2010/05/04 23:27:14 jym Exp $ */
/*-
* Copyright (c) 1991 The Regents of the University of California.
@@ -262,10 +262,8 @@
#ifdef XEN
/* Not on Xen */
#define CPUID_FEAT_BLACKLIST (CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR)
-#define CPUID_EXT_FEAT_BLACKLIST (CPUID_NOX)
#else
#define CPUID_FEAT_BLACKLIST 0
-#define CPUID_EXT_FEAT_BLACKLIST 0
#endif /* XEN */
/*
Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.107 src/sys/arch/x86/x86/pmap.c:1.108
--- src/sys/arch/x86/x86/pmap.c:1.107 Sun Apr 18 23:47:51 2010
+++ src/sys/arch/x86/x86/pmap.c Tue May 4 23:27:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.107 2010/04/18 23:47:51 jym Exp $ */
+/* $NetBSD: pmap.c,v 1.108 2010/05/04 23:27:14 jym Exp $ */
/*
* Copyright (c) 2007 Manuel Bouyer.
@@ -149,7 +149,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.107 2010/04/18 23:47:51 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.108 2010/05/04 23:27:14 jym Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -1146,10 +1146,9 @@
if (flags & PMAP_NOCACHE)
npte |= PG_N;
-#ifndef XEN
if ((cpu_feature[2] & CPUID_NOX) && !(prot & VM_PROT_EXECUTE))
npte |= PG_NX;
-#endif
+
opte = pmap_pte_testset (pte, npte); /* zap! */
if (pmap_valid_entry(opte)) {
@@ -1268,14 +1267,13 @@
struct pcb *pcb;
int i;
vaddr_t kva;
-#ifdef XEN
- pt_entry_t pg_nx = 0;
-#else
+#ifndef XEN
unsigned long p1i;
vaddr_t kva_end;
- pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0);
#endif
+ pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0);
+
/*
* set up our local static global vars that keep track of the
* usage of KVM before kernel_map is set up
Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.43 src/sys/arch/xen/x86/cpu.c:1.44
--- src/sys/arch/xen/x86/cpu.c:1.43 Sun Apr 18 23:47:52 2010
+++ src/sys/arch/xen/x86/cpu.c Tue May 4 23:27:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.43 2010/04/18 23:47:52 jym Exp $ */
+/* $NetBSD: cpu.c,v 1.44 2010/05/04 23:27:14 jym 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.43 2010/04/18 23:47:52 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.44 2010/05/04 23:27:14 jym Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -1005,6 +1005,9 @@
HYPERVISOR_set_segment_base (SEGBASE_GS_USER, 0);
}
#endif /* __x86_64__ */
+
+ if (cpu_feature[2] & CPUID_NOX)
+ wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NXE);
}
void