Module Name: src Committed By: kamil Date: Tue Dec 13 10:54:27 UTC 2016
Modified Files: src/sys/arch/i386/conf: files.i386 src/sys/arch/i386/i386: trap.c src/sys/arch/x86/include: cpufunc.h src/sys/arch/x86/x86: pmap.c src/sys/arch/xen/conf: files.compat files.xen src/sys/arch/xen/x86: xen_pmap.c Removed Files: src/sys/arch/i386/i386: db_dbgreg.S Log Message: Torn down KSTACK_CHECK_DR0, i386-only feature to detect stack overflow This feature was intended to detect stack overflow with CPU Debug Registers (x86). It was never ported to other ports, neither amd64 and should be adapted for SMP... Currently there might be better ways to detect stack overflows like page mapping protection. Since the number of Debug Registers is restricted (4 on x86), torn it down completely. This interface introduced helper functions for Debug Registers, they will be replaced with the new <x86/dbregs.h> interface. KSTACK_CHECK_DR0 was disabled by default and won't affect ordinary users. Sponsored by <The NetBSD Foundation> To generate a diff of this commit: cvs rdiff -u -r1.374 -r1.375 src/sys/arch/i386/conf/files.i386 cvs rdiff -u -r1.7 -r0 src/sys/arch/i386/i386/db_dbgreg.S cvs rdiff -u -r1.280 -r1.281 src/sys/arch/i386/i386/trap.c cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/include/cpufunc.h cvs rdiff -u -r1.230 -r1.231 src/sys/arch/x86/x86/pmap.c cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/conf/files.compat cvs rdiff -u -r1.141 -r1.142 src/sys/arch/xen/conf/files.xen cvs rdiff -u -r1.23 -r1.24 src/sys/arch/xen/x86/xen_pmap.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/i386/conf/files.i386 diff -u src/sys/arch/i386/conf/files.i386:1.374 src/sys/arch/i386/conf/files.i386:1.375 --- src/sys/arch/i386/conf/files.i386:1.374 Wed Feb 12 23:24:09 2014 +++ src/sys/arch/i386/conf/files.i386 Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -# $NetBSD: files.i386,v 1.374 2014/02/12 23:24:09 dsl Exp $ +# $NetBSD: files.i386,v 1.375 2016/12/13 10:54:27 kamil Exp $ # # new style config file for i386 architecture # @@ -41,9 +41,6 @@ defflag opt_pcibios.h PCIBIOS PCIBIOSVER PCIBIOS_INTR_GUESS PCIINTR_DEBUG defparam opt_pcibios.h PCIBIOS_IRQS_HINT -# kernel stack debug -defflag opt_kstack_dr0.h KSTACK_CHECK_DR0 - # splraise()/spllower() debug defflag opt_spldebug.h SPLDEBUG @@ -63,7 +60,6 @@ file arch/i386/i386/aout_machdep.c exec_ file arch/i386/i386/busfunc.S file arch/i386/i386/cpufunc.S file arch/i386/i386/cpu_in_cksum.S (inet | inet6) & cpu_in_cksum -file arch/i386/i386/db_dbgreg.S ddb | kstack_check_dr0 file arch/i386/i386/db_disasm.c ddb file arch/i386/i386/db_interface.c ddb file arch/i386/i386/db_machdep.c ddb Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.280 src/sys/arch/i386/i386/trap.c:1.281 --- src/sys/arch/i386/i386/trap.c:1.280 Sun Sep 25 12:53:24 2016 +++ src/sys/arch/i386/i386/trap.c Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.280 2016/09/25 12:53:24 maxv Exp $ */ +/* $NetBSD: trap.c,v 1.281 2016/12/13 10:54:27 kamil Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,14 +68,13 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.280 2016/09/25 12:53:24 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.281 2016/12/13 10:54:27 kamil Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" #include "opt_lockdebug.h" #include "opt_multiprocessor.h" #include "opt_vm86.h" -#include "opt_kstack_dr0.h" #include "opt_xen.h" #include "opt_dtrace.h" @@ -233,24 +232,6 @@ trap_print(const struct trapframe *frame l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l)); } -static void -check_dr0(void) -{ -#ifdef KSTACK_CHECK_DR0 - u_int mask, dr6 = rdr6(); - - mask = 1 << 0; /* dr0 */ - if (dr6 & mask) { - panic("trap on DR0: maybe kernel stack overflow\n"); -#if 0 - dr6 &= ~mask; - ldr6(dr6); - return; -#endif - } -#endif -} - /* * trap(frame): exception, fault, and trap interface to BSD kernel. * @@ -323,9 +304,7 @@ trap(struct trapframe *frame) default: we_re_toast: - if (type == T_TRCTRAP) - check_dr0(); - else + if (type != T_TRCTRAP) trap_print(frame, l); if (kdb_trap(type, 0, frame)) Index: src/sys/arch/x86/include/cpufunc.h diff -u src/sys/arch/x86/include/cpufunc.h:1.21 src/sys/arch/x86/include/cpufunc.h:1.22 --- src/sys/arch/x86/include/cpufunc.h:1.21 Tue Dec 13 10:21:33 2016 +++ src/sys/arch/x86/include/cpufunc.h Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.h,v 1.21 2016/12/13 10:21:33 kamil Exp $ */ +/* $NetBSD: cpufunc.h,v 1.22 2016/12/13 10:54:27 kamil Exp $ */ /*- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. @@ -68,7 +68,6 @@ void lcr8(vaddr_t); vaddr_t rcr8(void); void tlbflush(void); void tlbflushg(void); -void dr0(void *, uint32_t, uint32_t, uint32_t); register_t rdr0(void); void ldr0(register_t); register_t rdr1(void); Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.230 src/sys/arch/x86/x86/pmap.c:1.231 --- src/sys/arch/x86/x86/pmap.c:1.230 Sun Dec 11 08:31:53 2016 +++ src/sys/arch/x86/x86/pmap.c Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $ */ +/* $NetBSD: pmap.c,v 1.231 2016/12/13 10:54:27 kamil Exp $ */ /*- * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc. @@ -171,15 +171,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.231 2016/12/13 10:54:27 kamil Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" #include "opt_multiprocessor.h" #include "opt_xen.h" -#if !defined(__x86_64__) -#include "opt_kstack_dr0.h" -#endif /* !defined(__x86_64__) */ #include <sys/param.h> #include <sys/systm.h> @@ -2627,15 +2624,6 @@ pmap_activate(struct lwp *l) if (l == ci->ci_curlwp) { KASSERT(ci->ci_want_pmapload == 0); KASSERT(ci->ci_tlbstate != TLBSTATE_VALID); -#ifdef KSTACK_CHECK_DR0 - /* - * setup breakpoint on the top of stack - */ - if (l == &lwp0) - dr0(0, 0, 0, 0); - else - dr0(KSTACK_LOWEST_ADDR(l), 1, 3, 1); -#endif /* * no need to switch to kernel vmspace because Index: src/sys/arch/xen/conf/files.compat diff -u src/sys/arch/xen/conf/files.compat:1.24 src/sys/arch/xen/conf/files.compat:1.25 --- src/sys/arch/xen/conf/files.compat:1.24 Wed Oct 3 18:58:32 2012 +++ src/sys/arch/xen/conf/files.compat Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -# $NetBSD: files.compat,v 1.24 2012/10/03 18:58:32 dsl Exp $ +# $NetBSD: files.compat,v 1.25 2016/12/13 10:54:27 kamil Exp $ # NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp # options for MP configuration through the MP spec @@ -43,9 +43,6 @@ defflag opt_compat_oldboot.h XXXCOMPAT_ # Large page size defflag opt_largepages.h XXXLARGEPAGES -# kernel stack debug -defflag opt_kstack_dr0.h XXXKSTACK_CHECK_DR0 - #Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation) defflag opt_intel_odcm.h XXXINTEL_ONDEMAND_CLOCKMOD Index: src/sys/arch/xen/conf/files.xen diff -u src/sys/arch/xen/conf/files.xen:1.141 src/sys/arch/xen/conf/files.xen:1.142 --- src/sys/arch/xen/conf/files.xen:1.141 Fri May 20 03:41:20 2016 +++ src/sys/arch/xen/conf/files.xen Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -# $NetBSD: files.xen,v 1.141 2016/05/20 03:41:20 jnemeth Exp $ +# $NetBSD: files.xen,v 1.142 2016/12/13 10:54:27 kamil Exp $ # NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp # NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp @@ -39,7 +39,6 @@ file arch/i386/i386/aout_machdep.c exec_ file arch/i386/i386/busfunc.S file arch/i386/i386/cpufunc.S file arch/i386/i386/cpu_in_cksum.S (inet | inet6) & cpu_in_cksum -file arch/i386/i386/db_dbgreg.S ddb | kstack_check_dr0 file arch/i386/i386/db_disasm.c ddb file arch/i386/i386/db_interface.c ddb file arch/i386/i386/db_machdep.c ddb Index: src/sys/arch/xen/x86/xen_pmap.c diff -u src/sys/arch/xen/x86/xen_pmap.c:1.23 src/sys/arch/xen/x86/xen_pmap.c:1.24 --- src/sys/arch/xen/x86/xen_pmap.c:1.23 Mon Nov 21 04:10:05 2016 +++ src/sys/arch/xen/x86/xen_pmap.c Tue Dec 13 10:54:27 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_pmap.c,v 1.23 2016/11/21 04:10:05 ozaki-r Exp $ */ +/* $NetBSD: xen_pmap.c,v 1.24 2016/12/13 10:54:27 kamil Exp $ */ /* * Copyright (c) 2007 Manuel Bouyer. @@ -102,15 +102,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.23 2016/11/21 04:10:05 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.24 2016/12/13 10:54:27 kamil Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" #include "opt_multiprocessor.h" #include "opt_xen.h" -#if !defined(__x86_64__) -#include "opt_kstack_dr0.h" -#endif /* !defined(__x86_64__) */ #include <sys/param.h> #include <sys/systm.h>