Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys This patch fixes the NX regression issue observed on amd...
details: https://anonhg.NetBSD.org/src/rev/10c92590d203
branches: trunk
changeset: 754072:10c92590d203
user: jym <jym%NetBSD.org@localhost>
date: Sun Apr 18 23:47:50 2010 +0000
description:
This patch fixes 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).
- replace cpu_feature and ci_feature_flags variables by cpu_feature and
ci_feat_val arrays. This makes it cleaner and brings kernel code closer
to the design of cpuctl(8). A warning will be raised for each CPU that
does not expose the same features as the Boot Processor (BP).
- the blacklist of CPU features is now a macro defined in the
specialreg.h header, instead of hardcoding it inside MD initialization
code; fix comments.
- replace checks against CPUID_TSC with the cpu_hascounter() function.
- clean up the code in init_x86_64(), as cpu_feature variables are set
inside cpu_probe().
- use cpu_init_msrs() for i386. It will be eventually used later for NX
feature under i386 PAE kernels.
- remove code that checks for CPUID_NOX in amd64 mptramp.S, this is already
performed by cpu_hatch() through cpu_init_msrs().
- remove cpu_signature and feature_flags members from struct mpbios_proc
(they were never used).
This patch was tested with i386 MONOLITHIC, XEN3PAE_DOM0 and XEN3_DOM0 under
a native i386 host, and amd64 GENERIC, XEN3_DOM0 via QEMU virtual machines.
XXX Should kernel rev be bumped?
XXX A similar patch should be pulled-up for NetBSD-5, hopefully tomorrow.
diffstat:
sys/arch/amd64/amd64/locore.S | 17 +----
sys/arch/amd64/amd64/machdep.c | 18 +++--
sys/arch/amd64/amd64/mptramp.S | 10 +---
sys/arch/amd64/amd64/procfs_machdep.c | 6 +-
sys/arch/i386/i386/genassym.cf | 3 +-
sys/arch/i386/i386/machdep.c | 18 ++---
sys/arch/i386/i386/procfs_machdep.c | 6 +-
sys/arch/i386/isa/npx.c | 7 +-
sys/arch/x86/include/cpu.h | 18 +++---
sys/arch/x86/include/cpuvar.h | 4 +-
sys/arch/x86/include/mpbiosreg.h | 4 +-
sys/arch/x86/include/specialreg.h | 18 ++++-
sys/arch/x86/x86/cpu.c | 36 +++++++----
sys/arch/x86/x86/cpu_topology.c | 11 ++-
sys/arch/x86/x86/identcpu.c | 75 +++++++++++++++----------
sys/arch/x86/x86/mpbios.c | 6 +-
sys/arch/x86/x86/patch.c | 10 +-
sys/arch/x86/x86/pmap.c | 16 ++--
sys/arch/x86/x86/tsc.c | 8 +-
sys/arch/x86/x86/via_padlock.c | 14 ++--
sys/arch/x86/x86/x86_machdep.c | 6 +-
sys/arch/xen/x86/cpu.c | 36 ++++++-----
sys/compat/linux32/arch/amd64/linux32_exec.h | 4 +-
sys/compat/linux32/common/linux32_exec_elf32.c | 5 +-
24 files changed, 185 insertions(+), 171 deletions(-)
diffs (truncated from 1234 to 300 lines):
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/amd64/amd64/locore.S Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.56 2010/04/18 15:24:54 jym Exp $ */
+/* $NetBSD: locore.S,v 1.57 2010/04/18 23:47:50 jym Exp $ */
/*
* Copyright-o-rama!
@@ -231,7 +231,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(PDPpaddr)
@@ -241,10 +241,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'
@@ -295,7 +291,7 @@
gdt64_end:
farjmp64:
- .long longmode-KERNBASE
+ .long _RELOC(longmode)
.word GSEL(GCODE_SEL, SEL_KPL)
#endif /* !XEN */
@@ -418,18 +414,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
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/amd64/amd64/machdep.c Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.143 2010/03/01 01:35:11 jym Exp $ */
+/* $NetBSD: machdep.c,v 1.144 2010/04/18 23:47:50 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.143 2010/03/01 01:35:11 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.144 2010/04/18 23:47:50 jym Exp $");
/* #define XENDEBUG_LOW */
@@ -1241,21 +1241,24 @@
#if !defined(REALEXTMEM) && !defined(REALBASEMEM)
struct btinfo_memmap *bim;
#endif
+#endif /* !XEN */
+
cpu_probe(&cpu_info_primary);
-#else /* XEN */
- cpu_probe(&cpu_info_primary);
+
+#ifdef XEN
KASSERT(HYPERVISOR_shared_info != NULL);
cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0];
__PRINTK(("init_x86_64(0x%lx)\n", first_avail));
- cpu_feature = cpu_info_primary.ci_feature_flags;
- /* not on Xen... */
- cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR|CPUID_NOX);
#endif /* XEN */
+ cpu_feature[0] &= ~CPUID_FEAT_BLACKLIST;
+ cpu_feature[2] &= ~CPUID_EXT_FEAT_BLACKLIST;
+
cpu_init_msrs(&cpu_info_primary, true);
pcb = lwp_getpcb(&lwp0);
+
#ifdef XEN
pcb->pcb_cr3 = xen_start_info.pt_base - KERNBASE;
__PRINTK(("pcb_cr3 0x%lx\n", xen_start_info.pt_base - KERNBASE));
@@ -1348,6 +1351,7 @@
pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
pmap_update(pmap_kernel());
memset((void *)idt_vaddr, 0, PAGE_SIZE);
+
#ifndef XEN
pmap_changeprot_local(idt_vaddr, VM_PROT_READ);
#endif
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/amd64/amd64/mptramp.S
--- a/sys/arch/amd64/amd64/mptramp.S Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/amd64/amd64/mptramp.S Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mptramp.S,v 1.10 2009/11/27 03:23:04 rmind Exp $ */
+/* $NetBSD: mptramp.S,v 1.11 2010/04/18 23:47:50 jym Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -223,15 +223,7 @@
testq %rdi, %rdi
jz 1b
- movl _C_LABEL(cpu_feature),%eax
- andl $CPUID_NOX,%eax
- jz 1f
- movl $MSR_EFER,%ecx
- rdmsr
- orl $EFER_NXE,%eax
- wrmsr
1:
-
movq CPU_INFO_IDLELWP(%rdi),%rsi
movq L_PCB(%rsi),%rsi
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/amd64/amd64/procfs_machdep.c
--- a/sys/arch/amd64/amd64/procfs_machdep.c Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/amd64/amd64/procfs_machdep.c Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_machdep.c,v 1.14 2010/01/18 22:31:14 rmind Exp $ */
+/* $NetBSD: procfs_machdep.c,v 1.15 2010/04/18 23:47:50 jym Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.14 2010/01/18 22:31:14 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.15 2010/04/18 23:47:50 jym Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -151,7 +151,7 @@
p = featurebuf;
left = sizeof(featurebuf);
for (i = 0; i < 32; i++) {
- if ((ci->ci_feature_flags & (1 << i)) && x86_features[i]) {
+ if ((ci->ci_feat_val[0] & (1 << i)) && x86_features[i]) {
l = snprintf(p, left, "%s ", x86_features[i]);
left -= l;
p += l;
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/i386/i386/genassym.cf
--- a/sys/arch/i386/i386/genassym.cf Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/i386/i386/genassym.cf Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.85 2010/02/22 23:52:17 jym Exp $
+# $NetBSD: genassym.cf,v 1.86 2010/04/18 23:47:50 jym Exp $
#
# Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -313,7 +313,6 @@
define CPU_INFO_VENDOR offsetof(struct cpu_info, ci_vendor[0])
define CPU_INFO_SIGNATURE offsetof(struct cpu_info, ci_signature)
-define CPU_INFO_FEATURES offsetof(struct cpu_info, ci_feature_flags)
define CPU_TLOG_OFFSET offsetof(struct cpu_info, ci_tlog_offset)
define CPU_TLOG_BASE offsetof(struct cpu_info, ci_tlog_base)
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/i386/i386/machdep.c Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.684 2010/03/01 01:35:11 jym Exp $ */
+/* $NetBSD: machdep.c,v 1.685 2010/04/18 23:47:51 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.684 2010/03/01 01:35:11 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.685 2010/04/18 23:47:51 jym Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@@ -244,10 +244,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;
@@ -1298,16 +1294,16 @@
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;
uvm_lwp_setuarea(&lwp0, lwp0uarea);
pcb = lwp_getpcb(&lwp0);
+ cpu_feature[0] &= ~CPUID_FEAT_BLACKLIST;
+ cpu_feature[2] &= ~CPUID_EXT_FEAT_BLACKLIST;
+
+ cpu_init_msrs(&cpu_info_primary, true);
+
#ifdef XEN
- /* not on Xen... */
- cpu_feature &= ~(CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR|CPUID_NOX);
pcb->pcb_cr3 = PDPpaddr - KERNBASE;
__PRINTK(("pcb_cr3 0x%lx cr3 0x%lx\n",
PDPpaddr - KERNBASE, xpmap_ptom(PDPpaddr - KERNBASE)));
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/i386/i386/procfs_machdep.c
--- a/sys/arch/i386/i386/procfs_machdep.c Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/i386/i386/procfs_machdep.c Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_machdep.c,v 1.33 2010/01/18 22:31:14 rmind Exp $ */
+/* $NetBSD: procfs_machdep.c,v 1.34 2010/04/18 23:47:51 jym Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.33 2010/01/18 22:31:14 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.34 2010/04/18 23:47:51 jym Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -114,7 +114,7 @@
p = featurebuf;
left = sizeof(featurebuf);
for (i = 0; i < 32; i++) {
- if ((ci->ci_feature_flags & (1 << i)) && x86_features[i]) {
+ if ((ci->ci_feat_val[0] & (1 << i)) && x86_features[i]) {
l = snprintf(p, left, "%s ", x86_features[i]);
left -= l;
p += l;
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/i386/isa/npx.c
--- a/sys/arch/i386/isa/npx.c Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/i386/isa/npx.c Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npx.c,v 1.135 2009/11/21 03:11:01 rmind Exp $ */
+/* $NetBSD: npx.c,v 1.136 2010/04/18 23:47:51 jym Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.135 2009/11/21 03:11:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.136 2010/04/18 23:47:51 jym Exp $");
#if 0
#define IPRINTF(x) printf x
@@ -123,6 +123,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>
@@ -215,7 +216,7 @@
int status;
unsigned irqmask;
- if (cpu_feature & CPUID_FPU) {
+ if (cpu_feature[0] & CPUID_FPU) {
i386_fpu_exception = 1;
return NPX_CPUID;
}
diff -r 3bf7b4b6628a -r 10c92590d203 sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h Sun Apr 18 21:17:47 2010 +0000
+++ b/sys/arch/x86/include/cpu.h Sun Apr 18 23:47:50 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.20 2010/01/18 16:40:17 rmind Exp $ */
Home |
Main Index |
Thread Index |
Old Index