--- zzzz-none-000/linux-4.4.271/kernel/module.c 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/kernel/module.c 2023-04-19 10:22:30.000000000 +0000 @@ -61,6 +61,14 @@ #include #include #include "module-internal.h" +#if defined(CONFIG_AVM_FASTIRQ) +#include +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ +#if defined(CONFIG_BUG_EXTRA_INFO) +#include +#endif/*--- #if defined(CONFIG_BUG_EXTRA_INFO) ---*/ + +#include #define CREATE_TRACE_POINTS #include @@ -275,6 +283,13 @@ #ifdef CONFIG_KGDB_KDB struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */ #endif /* CONFIG_KGDB_KDB */ +#ifdef CONFIG_CRASHLOG +struct list_head *crashlog_modules = &modules; +#endif +#ifdef CONFIG_QCA_MINIDUMP +struct list_head *minidump_modules = &modules; +EXPORT_SYMBOL(minidump_modules); +#endif static void module_assert_mutex(void) { @@ -782,6 +797,12 @@ MODINFO_ATTR(srcversion); static char last_unloaded_module[MODULE_NAME_LEN+1]; +#if defined(CONFIG_AVM_BOOTMEM) +static unsigned long last_unloaded_module_jiffies; +/*--- Berechnung bei ARCH_DMA_MINALIGN = 32 Byte korrekt, solange size <= 128 Byte ---*/ +#define MY_ALIGN_BIT (ffs(ARCH_DMA_MINALIGN) - 1) +#define SLAB_ORG_SIZE(size) (((((size-1) >> MY_ALIGN_BIT) + 1) << MY_ALIGN_BIT)) +#endif/*--- defined(CONFIG_AVM_BOOTMEM) ---*/ #ifdef CONFIG_MODULE_UNLOAD @@ -955,7 +976,7 @@ { struct module *mod; char name[MODULE_NAME_LEN]; - int ret, forced = 0; + int ret, forced = 0, status; if (!capable(CAP_SYS_MODULE) || modules_disabled) return -EPERM; @@ -1006,13 +1027,21 @@ /* Final destruction now no one is using it. */ if (mod->exit != NULL) mod->exit(); - blocking_notifier_call_chain(&module_notify_list, + status = blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING, mod); +#if defined(CONFIG_AVM_ENHANCED) + if(status == NOTIFY_BAD) { + return -EBUSY; + } +#endif/*--- #if defined(CONFIG_AVM_ENHANCED) ---*/ async_synchronize_full(); /* Store the name of the last unloaded module for diagnostic purposes */ strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); +#if defined(CONFIG_AVM_BOOTMEM) + last_unloaded_module_jiffies = jiffies; +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ free_module(mod); /* someone could wait for the module in add_unformed_module() */ wake_up_all(&module_wq); @@ -1263,6 +1292,7 @@ static const char vermagic[] = VERMAGIC_STRING; +#if defined (CONFIG_MODVERSIONS) || !defined (CONFIG_MODULE_STRIPPED) static int try_to_force_load(struct module *mod, const char *reason) { #ifdef CONFIG_MODULE_FORCE_LOAD @@ -1274,6 +1304,7 @@ return -ENOEXEC; #endif } +#endif #ifdef CONFIG_MODVERSIONS /* If the arch applies (non-zero) relocations to kernel kcrctab, unapply it. */ @@ -1468,6 +1499,11 @@ struct module_sect_attrs { struct attribute_group grp; unsigned int nsections; +#if defined(CONFIG_AVM_BOOTMEM) + unsigned char *names_ptr; + unsigned int names_size; + unsigned int slab_names_size; +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ struct module_sect_attr attrs[0]; }; @@ -1479,13 +1515,29 @@ return sprintf(buf, "0x%pK\n", (void *)sattr->address); } +#if defined(CONFIG_AVM_BOOTMEM) +static unsigned int global_modulesymbol_namesize; +static unsigned int global_modulesymbol_entries; +static unsigned int global_modulesymbol_slabsize; +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ + static void free_sect_attrs(struct module_sect_attrs *sect_attrs) { unsigned int section; - for (section = 0; section < sect_attrs->nsections; section++) - kfree(sect_attrs->attrs[section].name); - kfree(sect_attrs); +#if defined(CONFIG_AVM_BOOTMEM) + if(sect_attrs->names_ptr) { + global_modulesymbol_namesize -= sect_attrs->names_size; + global_modulesymbol_entries -= sect_attrs->nsections; + global_modulesymbol_slabsize -= sect_attrs->slab_names_size; + free_pages_exact(sect_attrs->names_ptr, sect_attrs->names_size); + } else +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ + { + for (section = 0; section < sect_attrs->nsections; section++) + kfree(sect_attrs->attrs[section].name); + kfree(sect_attrs); + } } static void add_sect_attrs(struct module *mod, const struct load_info *info) @@ -1495,10 +1547,25 @@ struct module_sect_attr *sattr; struct attribute **gattr; +#if defined(CONFIG_AVM_BOOTMEM) + unsigned int needed_size, sum_slab_names_size = 0, sum_names_size = 0, name_size; + unsigned char *names_ptr = NULL; + /* Count loaded sections and allocate structures */ + for (i = 0; i < info->hdr->e_shnum; i++) { + Elf_Shdr *sec = &info->sechdrs[i]; + if (sect_empty(sec)) + continue; + nloaded++; + name_size = strlen(info->secstrings + sec->sh_name) + 1; + sum_names_size += name_size; + sum_slab_names_size += SLAB_ORG_SIZE(name_size); + } +#else/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ /* Count loaded sections and allocate structures */ for (i = 0; i < info->hdr->e_shnum; i++) if (!sect_empty(&info->sechdrs[i])) nloaded++; +#endif/*--- #else ---*//*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ size[0] = ALIGN(sizeof(*sect_attrs) + nloaded * sizeof(sect_attrs->attrs[0]), sizeof(sect_attrs->grp.attrs[0])); @@ -1510,6 +1577,21 @@ /* Setup section attributes. */ sect_attrs->grp.name = "sections"; sect_attrs->grp.attrs = (void *)sect_attrs + size[0]; +#if defined(CONFIG_AVM_BOOTMEM) + needed_size = (sum_names_size + PAGE_SIZE - 1) & PAGE_MASK; + if(needed_size < sum_slab_names_size) { + names_ptr = alloc_pages_exact(needed_size, GFP_KERNEL | __GFP_ZERO); + if(names_ptr) { + sect_attrs->names_ptr = names_ptr; + sect_attrs->names_size = needed_size; + sect_attrs->slab_names_size = sum_slab_names_size; + global_modulesymbol_namesize += needed_size; + global_modulesymbol_entries += nloaded; + global_modulesymbol_slabsize += sum_slab_names_size; + /*--- printk(KERN_INFO"%s: symbols=%u size=%u(%u) saved-memory=%u byte\n", __func__, nloaded, needed_size, sum_names_size, sum_slab_names_size - needed_size); ---*/ + } + } +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ sect_attrs->nsections = 0; sattr = §_attrs->attrs[0]; @@ -2039,16 +2121,22 @@ /* This may be NULL, but that's OK */ unset_module_init_ro_nx(mod); module_arch_freeing_init(mod); - module_memfree(mod->module_init); + avm_module_mem_free(mod->module_init); kfree(mod->args); percpu_modfree(mod); /* Free lock-classes; relies on the preceding sync_rcu(). */ lockdep_free_key_range(mod->module_core, mod->core_size); +#if defined(CONFIG_BUG_EXTRA_INFO) + if(!IS_ERR_OR_NULL(release_bug_debug_table)){ + release_bug_debug_table(mod->name); + } +#endif/*--- #if defined(CONFIG_BUG_EXTRA_INFO) ---*/ + /* Finally, free the core (containing the module structure) */ unset_module_core_ro_nx(mod); - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_core); #ifdef CONFIG_MPU update_protections(current->mm); @@ -2602,6 +2690,11 @@ return vmalloc_exec(size); } +#if defined(CONFIG_AVM_ENHANCED) && defined(CONFIG_MIPS) +/*--- mbahr@avm.de: if we use KSEG0 it produce a kmemleak-warning: unknown object ???? ---*/ +#undef CONFIG_DEBUG_KMEMLEAK +#endif/*--- #if defined(CONFIG_AVM_ENHANCED) && defined(CONFIG_MIPS) ---*/ + #ifdef CONFIG_DEBUG_KMEMLEAK static void kmemleak_load_module(const struct module *mod, const struct load_info *info) @@ -2897,6 +2990,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) { +#ifndef CONFIG_MODULE_STRIPPED const char *modmagic = get_modinfo(info, "vermagic"); int err; @@ -2928,6 +3022,7 @@ pr_warn("%s: module is from the staging directory, the quality " "is unknown, you have been warned.\n", mod->name); } +#endif /* Set up license info based on the info section */ set_license(mod, get_modinfo(info, "license")); @@ -3027,7 +3122,7 @@ void *ptr; /* Do the allocs. */ - ptr = module_alloc(mod->core_size); + ptr = avm_module_mem_alloc(mod, mod->core_size, avm_module_mem_type_core); /* * The pointer to this block is stored in the module structure * which is inside the block. Just mark it as not being a @@ -3041,7 +3136,7 @@ mod->module_core = ptr; if (mod->init_size) { - ptr = module_alloc(mod->init_size); + ptr = avm_module_mem_alloc(mod, mod->init_size, avm_module_mem_type_init); /* * The pointer to this block is stored in the module structure * which is inside the block. This block doesn't need to be @@ -3050,7 +3145,7 @@ */ kmemleak_ignore(ptr); if (!ptr) { - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_core); return -ENOMEM; } memset(ptr, 0, mod->init_size); @@ -3201,8 +3296,8 @@ { percpu_modfree(mod); module_arch_freeing_init(mod); - module_memfree(mod->module_init); - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_init); + avm_module_mem_free(mod->module_core); } int __weak module_finalize(const Elf_Ehdr *hdr, @@ -3268,7 +3363,7 @@ static void do_free_init(struct rcu_head *head) { struct mod_initfree *m = container_of(head, struct mod_initfree, rcu); - module_memfree(m->module_init); + avm_module_mem_free(m->module_init); kfree(m); } @@ -3466,6 +3561,21 @@ mutex_unlock(&module_mutex); return err; } +#if defined(CONFIG_BUG_EXTRA_INFO) +/*--------------------------------------------------------------------------------*\ +\*--------------------------------------------------------------------------------*/ +static void __register_module_bugtable(struct module *mod, struct load_info *info) { + struct bug_debug_table_entry *bug_info; + unsigned int num_bug_info; + bug_info = section_objs(info, "__bug_debug_table", + sizeof(struct bug_debug_table_entry), &num_bug_info); + + /*--- printk(KERN_INFO"%s: %s: bug_info_start: %p num=%u\n", __func__, mod->name, bug_info, num_bug_info); ---*/ + if(num_bug_info && bug_info) { + register_bug_debug_table(mod->name, (unsigned long)bug_info, (unsigned long)&bug_info[num_bug_info]); + } +} +#endif/*--- #if defined(CONFIG_BUG_EXTRA_INFO) ---*/ static int unknown_module_param_cb(char *param, char *val, const char *modname, void *arg) @@ -3598,6 +3708,9 @@ if (err < 0) goto bug_cleanup; +#if defined(CONFIG_BUG_EXTRA_INFO) + __register_module_bugtable(mod, info); +#endif/*--- #if defined(CONFIG_BUG_EXTRA_INFO) ---*/ /* Get rid of temporary copy. */ free_copy(info); @@ -3977,6 +4090,11 @@ static void m_stop(struct seq_file *m, void *p) { +#if defined(CONFIG_AVM_BOOTMEM) && defined(CONFIG_KALLSYM) + if(strcmp(current->comm, "cat") == 0) { + seq_printf(m, "sum of module-symbols: %u (%u KiB) saved-memory %u KiB\n", global_modulesymbol_entries, global_modulesymbol_namesize / 1000, (global_modulesymbol_slabsize - global_modulesymbol_namesize) / 1000); + } +#endif/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ mutex_unlock(&module_mutex); } @@ -4046,6 +4164,10 @@ { const struct exception_table_entry *e = NULL; struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if (firq_is_avm_rte_restricted_mem_access()) + return e; +#endif preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { @@ -4096,6 +4218,10 @@ { struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if (firq_is_avm_rte_restricted_mem_access()) + return NULL; +#endif if (addr < module_addr_min || addr > module_addr_max) return NULL; @@ -4156,6 +4282,11 @@ struct module *mod; char buf[8]; +#if defined(CONFIG_AVM_FASTIRQ) + if (firq_is_avm_rte_restricted_mem_access()) + return; +#endif + printk(KERN_DEFAULT "Modules linked in:"); /* Most callers should already have preempt disabled, but make sure */ preempt_disable(); @@ -4165,9 +4296,17 @@ pr_cont(" %s%s", mod->name, module_flags(mod, buf)); } preempt_enable(); - if (last_unloaded_module[0]) - pr_cont(" [last unloaded: %s]", last_unloaded_module); - pr_cont("\n"); + if (last_unloaded_module[0]) { +#if defined(CONFIG_AVM_BOOTMEM) + + struct timespec sincetime; + jiffies_to_timespec(jiffies - last_unloaded_module_jiffies, &sincetime); + printk(" [last unloaded: %s before %lu.%03lu s]", last_unloaded_module, sincetime.tv_sec, sincetime.tv_nsec / (1000* 1000)); +#else/*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ + printk(" [last unloaded: %s]", last_unloaded_module); +#endif/*--- #else ---*//*--- #if defined(CONFIG_AVM_BOOTMEM) ---*/ + } + printk("\n"); } #ifdef CONFIG_MODVERSIONS