Module Name: src Committed By: martin Date: Thu Mar 3 14:46:07 UTC 2016
Modified Files: src/sys/kern [netbsd-7-0]: kern_ksyms.c kern_module.c Log Message: Pull up following revision(s) (requested by pgoyette in ticket #1108): sys/kern/kern_module.c: revision 1.107-1.110 sys/kern/kern_ksyms.c: revision 1.82 Add some additional status messages for kern.module.verbose=TRUE Remove extraneous ')' from previous. KNF In module_do_load(), consolidate checking for a pre-existing module, and return a single error value EEXIST. When making a recursive call (to load required modules), treat a pre-existing module as success. Without this change, when a module was loaded by specific request (as opposed to being loaded as a requirement of some other module), we would always load the module from the file-system, and then after making various sanity/compatability checks we would destroy the new copy if there was a pre-existing copy. Fixes PR kern/40764 XXX Note that if the module exists, we bypass all of the various XXX "compatability" checks, including whether or not the existing XXX module is of any particular class! (In the previous code, we XXX checked to see if the newly-loaded copy had the correct class, XXX but not the pre-existing copy, which could have been loaded XXX from a different path/filename.) To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.72.4.1 src/sys/kern/kern_ksyms.c cvs rdiff -u -r1.97.2.1 -r1.97.2.1.2.1 src/sys/kern/kern_module.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/kern/kern_ksyms.c diff -u src/sys/kern/kern_ksyms.c:1.72 src/sys/kern/kern_ksyms.c:1.72.4.1 --- src/sys/kern/kern_ksyms.c:1.72 Fri Jul 25 08:10:40 2014 +++ src/sys/kern/kern_ksyms.c Thu Mar 3 14:46:07 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ksyms.c,v 1.72 2014/07/25 08:10:40 dholland Exp $ */ +/* $NetBSD: kern_ksyms.c,v 1.72.4.1 2016/03/03 14:46:07 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.72 2014/07/25 08:10:40 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.72.4.1 2016/03/03 14:46:07 martin Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -324,7 +324,7 @@ addsymtab(const char *name, void *symsta nglob = 0; for (i = n = 0; i < nsyms; i++) { - /* This breaks CTF mapping, so don't do it when + /* This breaks CTF mapping, so don't do it when * DTrace is enabled */ #ifndef KDTRACE_HOOKS @@ -389,7 +389,7 @@ addsymtab(const char *name, void *symsta panic("addsymtab"); #ifdef KDTRACE_HOOKS - /* + /* * Build the mapping from original symbol id to new symbol table. * Deleted symbols will have a zero map, indices will be one based * instead of zero based. @@ -481,7 +481,7 @@ ksyms_addsyms_elf(int symsize, void *sta shdr[ehdr->e_shstrndx].sh_offset; for (i = 1; i < ehdr->e_shnum; i++) { #ifdef DEBUG - printf("ksyms: checking %s\n", &shstr[shdr[i].sh_name]); + printf("ksyms: checking %s\n", &shstr[shdr[i].sh_name]); #endif if (shdr[i].sh_type != SHT_PROGBITS) continue; @@ -499,7 +499,7 @@ ksyms_addsyms_elf(int symsize, void *sta } #ifdef DEBUG } else { - printf("ksyms: e_shstrndx == 0\n"); + printf("ksyms: e_shstrndx == 0\n"); #endif } #endif @@ -527,9 +527,8 @@ ksyms_addsyms_elf(int symsize, void *sta */ void ksyms_addsyms_explicit(void *ehdr, void *symstart, size_t symsize, - void *strstart, size_t strsize) + void *strstart, size_t strsize) { - if (!ksyms_verify(symstart, strstart)) return; @@ -549,7 +548,7 @@ ksyms_addsyms_explicit(void *ehdr, void */ int ksyms_getval_unlocked(const char *mod, const char *sym, unsigned long *val, - int type) + int type) { struct ksyms_symtab *st; Elf_Sym *es; @@ -717,7 +716,7 @@ ksyms_getname(const char **mod, const ch */ void ksyms_modload(const char *name, void *symstart, vsize_t symsize, - char *strstart, vsize_t strsize) + char *strstart, vsize_t strsize) { struct ksyms_symtab *st; @@ -827,20 +826,20 @@ ksyms_sift(char *mod, char *sym, int mod static void ksyms_sizes_calc(void) { - struct ksyms_symtab *st; + struct ksyms_symtab *st; int i, delta; - ksyms_symsz = ksyms_strsz = 0; - TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) { + ksyms_symsz = ksyms_strsz = 0; + TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) { delta = ksyms_strsz - st->sd_usroffset; if (delta != 0) { for (i = 0; i < st->sd_symsize/sizeof(Elf_Sym); i++) st->sd_symstart[i].st_name += delta; st->sd_usroffset = ksyms_strsz; } - ksyms_symsz += st->sd_symsize; - ksyms_strsz += st->sd_strsize; - } + ksyms_symsz += st->sd_symsize; + ksyms_strsz += st->sd_strsize; + } } static void @@ -922,7 +921,6 @@ ksyms_hdr_init(void *hdraddr) static int ksymsopen(dev_t dev, int oflags, int devtype, struct lwp *l) { - if (minor(dev) != 0 || !ksyms_loaded) return ENXIO; @@ -951,7 +949,7 @@ ksymsclose(dev_t dev, int oflags, int de struct ksyms_symtab *st, *next; bool resize; - /* Discard refernces to symbol tables. */ + /* Discard references to symbol tables. */ mutex_enter(&ksyms_lock); ksyms_isopen = false; resize = false; @@ -1047,7 +1045,6 @@ ksymsread(dev_t dev, struct uio *uio, in static int ksymswrite(dev_t dev, struct uio *uio, int ioflag) { - return EROFS; } Index: src/sys/kern/kern_module.c diff -u src/sys/kern/kern_module.c:1.97.2.1 src/sys/kern/kern_module.c:1.97.2.1.2.1 --- src/sys/kern/kern_module.c:1.97.2.1 Fri May 15 03:44:19 2015 +++ src/sys/kern/kern_module.c Thu Mar 3 14:46:07 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.97.2.1 2015/05/15 03:44:19 snj Exp $ */ +/* $NetBSD: kern_module.c,v 1.97.2.1.2.1 2016/03/03 14:46:07 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.97.2.1 2015/05/15 03:44:19 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.97.2.1.2.1 2016/03/03 14:46:07 martin Exp $"); #define _MODULE_INTERNAL @@ -937,19 +937,19 @@ module_do_load(const char *name, bool is TAILQ_INSERT_TAIL(pending, mod, mod_chain); } else { /* - * If a requisite module, check to see if it is - * already present. + * Check to see if module is already present. */ - if (isdep) { - mod = module_lookup(name); - if (mod != NULL) { - if (modp != NULL) { - *modp = mod; - } - depth--; - return 0; + mod = module_lookup(name); + if (mod != NULL) { + if (modp != NULL) { + *modp = mod; } - } + module_print("%s module `%s' already loaded", + isdep ? "dependent" : "requested", name); + depth--; + return EEXIST; + } + mod = module_newmodule(MODULE_SOURCE_FILESYS); if (mod == NULL) { module_error("out of memory for `%s'", name); @@ -1028,19 +1028,6 @@ module_do_load(const char *name, bool is } /* - * Check to see if the module is already loaded. If so, we may - * have been recursively called to handle a dependency, so be sure - * to set modp. - */ - if ((mod2 = module_lookup(mi->mi_name)) != NULL) { - if (modp != NULL) - *modp = mod2; - module_print("module `%s' already loaded", mi->mi_name); - error = EEXIST; - goto fail; - } - - /* * Block circular dependencies. */ TAILQ_FOREACH(mod2, pending, mod_chain) { @@ -1048,10 +1035,10 @@ module_do_load(const char *name, bool is continue; } if (strcmp(mod2->mod_info->mi_name, mi->mi_name) == 0) { - error = EDEADLK; + error = EDEADLK; module_error("circular dependency detected for `%s'", mi->mi_name); - goto fail; + goto fail; } } @@ -1091,7 +1078,7 @@ module_do_load(const char *name, bool is } error = module_do_load(buf, true, flags, NULL, &mod2, MODULE_CLASS_ANY, true); - if (error != 0) { + if (error != 0 && error != EEXIST) { module_error("recursive load failed for `%s' " "(`%s' required), error %d", mi->mi_name, buf, error); @@ -1153,6 +1140,7 @@ module_do_load(const char *name, bool is module_thread_kick(); } depth--; + module_print("module `%s' loaded successfully", mi->mi_name); return 0; fail: @@ -1183,13 +1171,16 @@ module_do_unload(const char *name, bool KASSERT(kernconfig_is_held()); KASSERT(name != NULL); + module_print("unload requested for '%s' (%s)", name, + load_requires_force?"TRUE":"FALSE"); mod = module_lookup(name); if (mod == NULL) { module_error("module `%s' not found", name); return ENOENT; } if (mod->mod_refcnt != 0) { - module_print("module `%s' busy", name); + module_print("module `%s' busy (%d refs)", name, + mod->mod_refcnt); return EBUSY; } @@ -1198,6 +1189,8 @@ module_do_unload(const char *name, bool */ if (mod->mod_source == MODULE_SOURCE_KERNEL && mod->mod_info->mi_class == MODULE_CLASS_SECMODEL) { + module_print("cannot unload built-in secmodel module `%s'", + name); return EPERM; } @@ -1369,7 +1362,10 @@ module_thread(void *cookie) error = (*mi->mi_modcmd)(MODULE_CMD_AUTOUNLOAD, NULL); if (error == 0 || error == ENOTTY) { (void)module_do_unload(mi->mi_name, false); - } + } else + module_print("module `%s' declined to be " + "auto-unloaded error=%d", mi->mi_name, + error); } kernconfig_unlock();