tech-kern archive

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

Enable KMEM_GUARD without all the rest of DEBUG ?



On another thread discussing random kernel crashes (likely due to memory corruption) [1], it was suggested that KMEM_GUARD might be a useful tool for debugging...

By adding KMEM_GUARD itself to a kernel config file, I discovered that KMEM_GUARD cannot be enabled individually - it is currently required as part of a set of tools that are collectively enabled by 'options DEBUG'

/build/netbsd-test/src/sys/kern/subr_kmem.c: In function 'kmem_init': /build/netbsd-test/src/sys/kern/subr_kmem.c:344:20: error: 'kmem_guard' undeclared (first use in this function) /build/netbsd-test/src/sys/kern/subr_kmem.c:344:33: error: 'kmem_guard_depth' undeclared (first use in this function) /build/netbsd-test/src/sys/kern/subr_kmem.c:344:52: error: 'kmem_guard_size' undeclared (first use in this function)

The following patches allow building of a kernel with only KMEM_GUARD. The first patch makes the variable allocations depend on the KMEM_GUARD whether or not DEBUG was specified, and the second patch includes the necessary uvm_kmguard.c when either option is specified.


Index: subr_kmem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_kmem.c,v
retrieving revision 1.42
diff -u -p -r1.42 subr_kmem.c
--- sys/kern/subr_kmem.c 5 Feb 2012 03:40:08 -0000       1.42
+++ sys/kern/subr_kmem.c 8 Mar 2012 01:53:32 -0000
@@ -122,9 +122,6 @@ static pool_cache_t kmem_cache[KMEM_CACH
 static size_t kmem_cache_maxidx __read_mostly;

 #if defined(DEBUG)
-int kmem_guard_depth = 0;
-size_t kmem_guard_size;
-static struct uvm_kmguard kmem_guard;
 static void *kmem_freecheck;
 #define        KMEM_POISON
 #define        KMEM_REDZONE
@@ -132,6 +129,12 @@ static void *kmem_freecheck;
 #define        KMEM_GUARD
 #endif /* defined(DEBUG) */

+#if defined (KMEM_GUARD)
+int kmem_guard_depth = 0;
+size_t kmem_guard_size;
+static struct uvm_kmguard kmem_guard;
+#endif
+
 #if defined(KMEM_POISON)
 static int kmem_poison_ctor(void *, void *, int);
 static void kmem_poison_fill(void *, size_t);
Index: uvm/files.uvm
===================================================================
RCS file: /cvsroot/src/sys/uvm/files.uvm,v
retrieving revision 1.20
diff -u -p -r1.20 files.uvm
--- sys/uvm/files.uvm       17 May 2011 05:32:31 -0000      1.20
+++ sys/uvm/files.uvm       8 Mar 2012 02:18:55 -0000
@@ -25,7 +25,7 @@ file  uvm/uvm_glue.c
 file   uvm/uvm_init.c
 file   uvm/uvm_io.c
 file   uvm/uvm_km.c
-file   uvm/uvm_kmguard.c               debug
+file   uvm/uvm_kmguard.c               debug | kmem_guard
 file   uvm/uvm_loan.c
 file   uvm/uvm_map.c
 file   uvm/uvm_meter.c


Does anyone have any objections to committing these fixes?


[1] http://mail-index.netbsd.org/current-users/2012/03/07/msg019419.html


-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------


Home | Main Index | Thread Index | Old Index