tech-kern archive

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

ksyms_init considered too heavyweight for early bootstrap



I found out why a LOCKDEBUG sparc64 kernel crashes very early:

"Traditionally" we have called ksyms_init() very early in MD bootstrap(),
even before running pmap_bootstrap(). Nowadays ksyms_init() does a mutex_init(),
which is, at least with LOCKDEBUG, a very heavy weight operation - too much
for the still very restricted runtime environment at this stage - on sparc64
neither curcpu nor curlwp are valid, and we have not yet setup our trap
handlers.

Now I could solve this in a MD way (for example move the call to cpu_startup),
but I wonder if other archs run into the same problem (maybe with less drastic
failure mode) and the attached MI fix would be better?

Martin
Index: kern/init_main.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_main.c,v
retrieving revision 1.374
diff -u -p -r1.374 init_main.c
--- kern/init_main.c    14 Nov 2008 23:33:45 -0000      1.374
+++ kern/init_main.c    17 Nov 2008 10:19:50 -0000
@@ -111,6 +111,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,
 #include "opt_wapbl.h"
 
 #include "rnd.h"
+#include "ksyms.h"
 #include "sysmon_envsys.h"
 #include "sysmon_power.h"
 #include "sysmon_taskq.h"
@@ -340,6 +341,10 @@ main(void)
        /* Initialize lock caches. */
        mutex_obj_init();
 
+#if NKSYMS > 0
+       ksyms_init_finalize();
+#endif
+
        /* Initialize the extent manager. */
        extent_init();
 
Index: kern/kern_ksyms.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_ksyms.c,v
retrieving revision 1.46
diff -u -p -r1.46 kern_ksyms.c
--- kern/kern_ksyms.c   16 Nov 2008 16:15:58 -0000      1.46
+++ kern/kern_ksyms.c   17 Nov 2008 10:19:50 -0000
@@ -326,6 +326,12 @@ addsymtab(const char *name, void *symsta
        ksyms_initted = true;
 }
 
+void
+ksyms_init_finalize()
+{
+       mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
+}
+
 /*
  * Setup the kernel symbol table stuff.
  */
@@ -338,7 +344,6 @@ ksyms_init(int symsize, void *start, voi
        size_t strsize = 0;
        Elf_Ehdr *ehdr;
 
-       mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
 #ifdef SYMTAB_SPACE
        if (symsize <= 0 &&
            strncmp(db_symtab, SYMTAB_FILLER, sizeof(SYMTAB_FILLER))) {
Index: sys/ksyms.h
===================================================================
RCS file: /cvsroot/src/sys/sys/ksyms.h,v
retrieving revision 1.20
diff -u -p -r1.20 ksyms.h
--- sys/ksyms.h 16 Nov 2008 15:28:15 -0000      1.20
+++ sys/ksyms.h 17 Nov 2008 10:19:51 -0000
@@ -107,6 +107,7 @@ int ksyms_addsymtab(const char *, void *
 int ksyms_delsymtab(const char *);
 void ksyms_init(int, void *, void *);
 void ksyms_init_explicit(void *, void *, size_t, void *, size_t);
+void ksyms_init_finalize(void);
 int ksyms_sift(char *, char *, int);
 void ksyms_modload(const char *, void *, vsize_t, char *, vsize_t);
 void ksyms_modunload(const char *);


Home | Main Index | Thread Index | Old Index