module: avoid userspace pressure on unwanted allocations
Subsystems (2)
Luis Chamberlain
maintainercover module: avoid userspace pressure on unwanted allocations
A long time ago we had some issues with userspace doing stupid stuff. Well, it turns out even the kernel and do stupid stuff too, as we're learning with the ACPI modules aliaes and that hammering tons of loads.
So add a bit of code which gets us a bit more in the defensive about these situations.
To experiment, this also adds in-kernel alias support to see if this helps with some larger systems.
This is all based on some old code which tried to add defensive mechanisms the last of which was here and I had dropped the ball:
https://lore.kernel.org/all/[email protected]/
I've only compile tested this for now. Will need to stress to test with kmod tests 0008 and 0009 to see if there's any differences. I'll have to re-test and re-gnuplot stuff there. But early feedback is appreciated, hence the RFC.
David Hildenbrand had reported a while ago issues with userspace doing insane things with allocations bringing a system down to its knees. This is part of the motivation for this series.
I repeat, I only have compiled tested this so far.
A few Suggested-by there linger since Linus had suggested a few of these ideas a long time ago and we just never picked them up.
Luis Chamberlain (12):
module: use goto errors on check_modinfo() and layout_and_allocate()
module: move get_modinfo() helpers all above
module: rename next_string() to module_next_tag_pair()
module: add a for_each_modinfo_entry()
module: add debugging alias parsing support
module: move early sanity checks into a helper
module: move check_modinfo() early to early_mod_check()
module: move finished_loading()
module: extract patient module check into helper
module: avoid allocation if module is already present and ready
module: use list_add_tail_rcu() when adding module
module: use aliases to find module on find_module_all()
include/linux/module.h | 4 + kernel/module/Kconfig | 19 +++ kernel/module/Makefile | 1 + kernel/module/aliases.c | 109 +++++++++++++ kernel/module/internal.h | 25 +++ kernel/module/main.c | 324 +++++++++++++++++++++++---------------- 6 files changed, 346 insertions(+), 136 deletions(-) create mode 100644 kernel/module/aliases.c
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 3/12 module: rename next_string() to module_next_tag_pair()
This makes it clearer what it is doing. While at it, make it available to other code other than main.c. This will be used in the subsequent patch and make the changes easier to read.
--- kernel/module/internal.h | 2 ++ kernel/module/main.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-)
kernel/module/internal.h +2 -0
@@ -96,6 +96,8 @@ long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,char *module_flags (struct module *mod,char *buf,bool show_state);size_t module_flags_taint (unsigned long taints,char *buf); +char *module_next_tag_pair (char *string,unsigned long *secsize); +static inline void module_assert_mutex_or_preempt (void ) {#ifdef CONFIG_LOCKDEP
kernel/module/main.c +3 -3
@@ -1017,7 +1017,7 @@ int try_to_force_load(struct module *mod, const char *reason) }/* Parse tag=value strings from .modinfo section */ -static char *next_string (char *string,unsigned long *secsize) +char *module_next_tag_pair (char *string,unsigned long *secsize) {/* Skip non-zero chars */ while (string[0 ]) {
@@ -1051,10 +1051,10 @@ static char *get_next_modinfo(const struct load_info *info, const char *tag,if (prev) { size -= prev - modinfo; - modinfo =next_string (prev, &size); + modinfo =module_next_tag_pair (prev, &size); } -for (p = modinfo; p; p =next_string (p, &size)) { +for (p = modinfo; p; p =module_next_tag_pair (p, &size)) {if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' )return p + taglen +1 ; }
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 7/12 module: move check_modinfo() early to early_mod_check()
In reply to Luis ChamberlainThis moves check_modinfo() to early_mod_check(). This doesn't make any functional changes either, as check_modinfo() was the first call on layout_and_allocate(), so we're just moving it back one routine and at the end.
This let's us keep separate the checkers from the allocater.
--- kernel/module/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/module/main.c +5 -5
@@ -2284,10 +2284,6 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)unsigned int ndx;int err; - err =check_modinfo (info->mod, info, flags); -if (err) -return ERR_PTR (err); -/* Allow arches to frob section contents and sizes. */ err =module_frob_arch_sections (info->hdr, info->sechdrs, info->secstrings, info->mod);
@@ -2702,7 +2698,11 @@ static int early_mod_check(struct load_info *info, int flags)/* Check module struct version now, before we try to use module. */ if (!check_modstruct_version (info, info->mod)) -return ENOEXEC ; +return -ENOEXEC ; + + err =check_modinfo (info->mod, info, flags); +if (err) +return err;return 0 ; }
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 1/12 module: use goto errors on check_modinfo() and layout_and_allocate()
In reply to Luis ChamberlainAlthough both routines don't have much complex errors paths we will expand on these routine in the future, setting up error lables now for both will make subsequent changes easier to review. This changes has no functional changes.
--- kernel/module/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
kernel/module/main.c +8 -4
@@ -1998,7 +1998,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) err =check_modinfo_livepatch (mod, info);if (err) -return err; + goto err_out;/* Set up license info based on the info section */ set_license (mod,get_modinfo (info,"license" ));
@@ -2011,6 +2011,8 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) }return 0 ; +err_out: +return err; }static int find_module_sections (struct module *mod,struct load_info *info)
@@ -2288,12 +2290,12 @@ static struct module *layout_and_allocate(struct load_info *info, int flags) err =module_frob_arch_sections (info->hdr, info->sechdrs, info->secstrings, info->mod);if (err <0 ) -return ERR_PTR (err); + goto err_out; err =module_enforce_rwx_sections (info->hdr, info->sechdrs, info->secstrings, info->mod);if (err <0 ) -return ERR_PTR (err); + goto err_out;/* We will do a special allocation for per-cpu sections later. */ info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long )SHF_ALLOC ;
@@ -2327,12 +2329,14 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)/* Allocate and move to the final place */ err =move_module (info->mod, info);if (err) -return ERR_PTR (err); + goto err_out;/* Module has been copied to its final place now: return it. */ mod = (void *)info->sechdrs[info->index.mod].sh_addr;kmemleak_load_module (mod, info);return mod; +err_out: +return ERR_PTR (err); }/* mod is no longer valid after this! */
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 2/12 module: move get_modinfo() helpers all above
In reply to Luis ChamberlainInstead of forward declaring routines for get_modinfo() just move everything up. This makes no functional changes.
--- kernel/module/main.c | 100 +++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 52 deletions(-)
kernel/module/main.c +48 -52
@@ -1016,9 +1016,55 @@ int try_to_force_load(struct module *mod, const char *reason)#endif } -static char *get_modinfo (const struct load_info *info,const char *tag); +/* Parse tag=value strings from .modinfo section */ +static char *next_string (char *string,unsigned long *secsize) +{ +/* Skip non-zero chars */ +while (string[0 ]) { + string++; +if ((*secsize)-- <=1 ) +return NULL ; + } + +/* Skip any zero padding. */ +while (!string[0 ]) { + string++; +if ((*secsize)-- <=1 ) +return NULL ; + } +return string; +} +static char *get_next_modinfo (const struct load_info *info,const char *tag, -char *prev); +char *prev) +{ +char *p; +unsigned int taglen =strlen (tag); +Elf_Shdr *infosec = &info->sechdrs[info->index.info]; +unsigned long size = infosec->sh_size; + +/* +* get_modinfo() calls made before rewrite_section_headers() +* must use sh_offset, as sh_addr isn't set! +*/ +char *modinfo = (char *)info->hdr + infosec->sh_offset; + +if (prev) { + size -= prev - modinfo; + modinfo =next_string (prev, &size); + } + +for (p = modinfo; p; p =next_string (p, &size)) { +if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' ) +return p + taglen +1 ; + } +return NULL ; +} + +static char *get_modinfo (const struct load_info *info,const char *tag) +{ +return get_next_modinfo (info, tag,NULL ); +} static int verify_namespace_is_imported(const struct load_info *info, const struct kernel_symbol *sym,
@@ -1544,56 +1590,6 @@ static void set_license(struct module *mod, const char *license) } } -/* Parse tag=value strings from .modinfo section */ -static char *next_string (char *string,unsigned long *secsize) -{ -/* Skip non-zero chars */ -while (string[0 ]) { - string++; -if ((*secsize)-- <=1 ) -return NULL ; - } - -/* Skip any zero padding. */ -while (!string[0 ]) { - string++; -if ((*secsize)-- <=1 ) -return NULL ; - } -return string; -} - -static char *get_next_modinfo (const struct load_info *info,const char *tag, -char *prev) -{ -char *p; -unsigned int taglen =strlen (tag); -Elf_Shdr *infosec = &info->sechdrs[info->index.info]; -unsigned long size = infosec->sh_size; - -/* -* get_modinfo() calls made before rewrite_section_headers() -* must use sh_offset, as sh_addr isn't set! -*/ -char *modinfo = (char *)info->hdr + infosec->sh_offset; - -if (prev) { - size -= prev - modinfo; - modinfo =next_string (prev, &size); - } - -for (p = modinfo; p; p =next_string (p, &size)) { -if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' ) -return p + taglen +1 ; - } -return NULL ; -} - -static char *get_modinfo (const struct load_info *info,const char *tag) -{ -return get_next_modinfo (info, tag,NULL ); -} -static void setup_modinfo (struct module *mod,struct load_info *info) {struct module_attribute *attr;
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 8/12 module: move finished_loading()
In reply to Luis ChamberlainThis has no functional change, just moves a routine earlier as we'll make use of it next.
--- kernel/module/main.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
kernel/module/main.c +21 -21
@@ -2370,27 +2370,6 @@ static int post_relocation(struct module *mod, const struct load_info *info)return module_finalize (info->hdr, info->sechdrs, mod); } -/* Is this module of this name done loading? No locks held. */ -static bool finished_loading (const char *name) -{ -struct module *mod; -bool ret; - -/* -* The module_mutex should not be a heavily contended lock; -* if we get the occasional sleep here, we'll go an extra iteration -* in the wait_event_interruptible(), which is harmless. -*/ -sched_annotate_sleep (); -mutex_lock (&module_mutex); - mod =find_module_all (name,strlen (name), true); - ret = !mod || mod->state ==MODULE_STATE_LIVE - || mod->state ==MODULE_STATE_GOING ; -mutex_unlock (&module_mutex); - -return ret; -} -/* Call module constructors. */ static void do_mod_ctors (struct module *mod) {
@@ -2554,6 +2533,27 @@ static int may_init_module(void)return 0 ; } +/* Is this module of this name done loading? No locks held. */ +static bool finished_loading (const char *name) +{ +struct module *mod; +bool ret; + +/* +* The module_mutex should not be a heavily contended lock; +* if we get the occasional sleep here, we'll go an extra iteration +* in the wait_event_interruptible(), which is harmless. +*/ +sched_annotate_sleep (); +mutex_lock (&module_mutex); + mod =find_module_all (name,strlen (name), true); + ret = !mod || mod->state ==MODULE_STATE_LIVE + || mod->state ==MODULE_STATE_GOING ; +mutex_unlock (&module_mutex); + +return ret; +} +/* * We try to place it in the list now to make sure it's unique before * we dedicate too many resources. In particular, temporary percpu
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 9/12 module: extract patient module check into helper
In reply to Luis ChamberlainThe patient module check inside add_unformed_module() is large enough as we need it. It is a bit hard to read too, so just move it to a helper and do the inverse checks first to help shift the code and make it easier to read. The new helper then is module_patient_check_exists().
--- kernel/module/main.c | 71 +++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 31 deletions(-)
kernel/module/main.c +40 -31
@@ -2554,6 +2554,43 @@ static bool finished_loading(const char *name)return ret; } +/* Must be called with module_mutex held */ +static int module_patient_check_exists (const char *name) +{ +struct module *old; +int err =0 ; + + old =find_module_all (name,strlen (name), true); +if (old ==NULL ) +return 0 ; + +if (old->state ==MODULE_STATE_COMING + || old->state ==MODULE_STATE_UNFORMED ) { +/* Wait in case it fails to load. */ +mutex_unlock (&module_mutex); + err =wait_event_interruptible (module_wq, +finished_loading (name)); +if (err) +return err; + +/* The module might have gone in the meantime. */ +mutex_lock (&module_mutex); + old =find_module_all (name,strlen (name), true); + } + +/* +* We are here only when the same module was being loaded. Do +* not try to load it again right now. It prevents long delays +* caused by serialized module load failures. It might happen +* when more devices of the same type trigger load of +* a particular module. +*/ +if (old && old->state ==MODULE_STATE_LIVE ) +return -EEXIST ; +else +return -EBUSY ; +} +/* * We try to place it in the list now to make sure it's unique before * we dedicate too many resources. In particular, temporary percpu
@@ -2562,41 +2599,14 @@ static bool finished_loading(const char *name)static int add_unformed_module (struct module *mod) {int err; -struct module *old; mod->state =MODULE_STATE_UNFORMED ;mutex_lock (&module_mutex); - old =find_module_all (mod->name,strlen (mod->name), true); -if (old !=NULL ) { -if (old->state ==MODULE_STATE_COMING - || old->state ==MODULE_STATE_UNFORMED ) { -/* Wait in case it fails to load. */ -mutex_unlock (&module_mutex); - err =wait_event_interruptible (module_wq, -finished_loading (mod->name)); -if (err) - goto out_unlocked; - -/* The module might have gone in the meantime. */ -mutex_lock (&module_mutex); - old =find_module_all (mod->name,strlen (mod->name), - true); - } - -/* -* We are here only when the same module was being loaded. Do -* not try to load it again right now. It prevents long delays -* caused by serialized module load failures. It might happen -* when more devices of the same type trigger load of -* a particular module. -*/ -if (old && old->state ==MODULE_STATE_LIVE ) - err = -EEXIST ; -else - err = -EBUSY ; + err =module_patient_check_exists (mod->name); +if (err) goto out; - } +mod_update_bounds (mod);list_add_rcu (&mod->list, &modules);mod_tree_insert (mod);
@@ -2604,7 +2614,6 @@ static int add_unformed_module(struct module *mod) out:mutex_unlock (&module_mutex); -out_unlocked:return err; }
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 4/12 module: add a for_each_modinfo_entry()
In reply to Luis ChamberlainAdd a for_each_modinfo_entry() to make it easier to read and use. This produces no functional changes but makes this code easiert to read as we are used to with loops in the kernel and trims more lines of code.
--- kernel/module/internal.h | 3 +++ kernel/module/main.c | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/module/internal.h +3 -0
@@ -98,6 +98,9 @@ size_t module_flags_taint(unsigned long taints, char *buf);char *module_next_tag_pair (char *string,unsigned long *secsize); +#define for_each_modinfo_entry (entry, info, name) \ + for (entry = get_modinfo(info, name); entry; entry = get_next_modinfo(info, name, entry)) +static inline void module_assert_mutex_or_preempt (void ) {#ifdef CONFIG_LOCKDEP
kernel/module/main.c +1 -4
@@ -1075,12 +1075,9 @@ static int verify_namespace_is_imported(const struct load_info *info, namespace =kernel_symbol_namespace (sym);if (namespace && namespace[0 ]) { - imported_namespace =get_modinfo (info,"import_ns" ); -while (imported_namespace) { +for_each_modinfo_entry (imported_namespace, info,"import_ns" ) {if (strcmp (namespace, imported_namespace) ==0 )return 0 ; - imported_namespace =get_next_modinfo ( - info,"import_ns" , imported_namespace); }#ifdef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS pr_warn(
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 10/12 module: avoid allocation if module is already present and ready
In reply to Luis Chamberlainload_module() will allocate a struct module before even checking if the module is already loaded. This can create unecessary memory pressure since we can easily just check if the module is already present early with the copy of the module information from userspace after we've validated it a bit.
This can only be an issue if a system is getting hammered with userspace loading modules. Note that there are two ways to load modules, one is auto-loading in-kernel and that pings back to userspace to just call modprobe. Then userspace itself *is* supposed to check if a module is present before loading it. But we're observing situations where tons of the same module are in effect being loaded. In that situation we can end up allocating memory for module requests which after allocating memory will fail to load.
To avoid memory pressure for such stupid cases put a stop gap for them.
--- kernel/module/main.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/module/main.c +4 -0
@@ -2713,6 +2713,10 @@ static int early_mod_check(struct load_info *info, int flags)if (err)return err; + err =module_patient_check_exists (info->mod->name); +if (err) +return err; +return 0 ; }
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 6/12 module: move early sanity checks into a helper
In reply to Luis ChamberlainMove early sanity checkers for the module into a helper. This let's us make it clear when we are working with the local copy of the module prior to allocation.
This produces no functional changes, it just makes subsequent changes easier to read.
--- kernel/module/main.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-)
kernel/module/main.c +26 -17
@@ -2682,6 +2682,31 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname,return 0 ; } +/* Module within temporary copy, this doesn't do any allocation */ +static int early_mod_check (struct load_info *info,int flags) +{ +int err; + +/* +* Now that we know we have the correct module name, check +* if it's blacklisted. +*/ +if (blacklisted (info->name)) { +pr_err ("Module %s is blacklisted\n" , info->name); +return -EPERM ; + } + + err =rewrite_section_headers (info, flags); +if (err) +return err; + +/* Check module struct version now, before we try to use module. */ +if (!check_modstruct_version (info, info->mod)) +return ENOEXEC ; + +return 0 ; +} +/* * Allocate and load the module: note that size of section 0 is always * zero, and we rely on this for optional sections.
@@ -2725,26 +2750,10 @@ static int load_module(struct load_info *info, const char __user *uargs,if (err) goto free_copy; -/* -* Now that we know we have the correct module name, check -* if it's blacklisted. -*/ -if (blacklisted (info->name)) { - err = -EPERM ; -pr_err ("Module %s is blacklisted\n" , info->name); - goto free_copy; - } - - err =rewrite_section_headers (info, flags); + err =early_mod_check (info, flags);if (err) goto free_copy; -/* Check module struct version now, before we try to use module. */ -if (!check_modstruct_version (info, info->mod)) { - err = -ENOEXEC ; - goto free_copy; - } -/* Figure out module layout, and allocate all the memory. */ mod =layout_and_allocate (info, flags);if (IS_ERR (mod)) {
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 12/12 module: use aliases to find module on find_module_all()
In reply to Luis ChamberlainModules can have a series of aliases, but we don't currently use them to check if a module is already loaded. Part of this is because load_module() will stick to checking for already loaded modules using the actual module name, not an alias. Its however desriable to also check for aliases on find_module_all() for existing callers and future callers. The curent gain to using aliases on find_module_all() will simply be to be able to support unloading modules using the alias using the delete_module() syscall.
You can debug this with dynamic debug:
GRUB_CMDLINE_LINUX_DEFAULT="dyndbg=\"func module_process_aliases +p; func module_name_match +p; \" "
--- kernel/module/aliases.c | 17 +++++++++++++++++ kernel/module/internal.h | 5 +++++ kernel/module/main.c | 24 +++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-)
kernel/module/aliases.c +17 -0
@@ -90,3 +90,20 @@ int module_process_aliases(struct module *mod, struct load_info *info)return -ENOMEM ; } + +bool module_name_match_aliases (struct module *mod,const char *name,size_t len) +{ +unsigned int i; +const char *alias; + +for (i=0 ; i < mod->num_aliases; i++) { + alias = mod->aliases[i]; +if (strlen (alias) == len && !memcmp (alias, name, len)) { +pr_debug ("module %s alias matched: alias[%u] = %s\n" , + mod->name, i, alias); +return true; + } + } + +return false; +}
kernel/module/internal.h +5 -0
@@ -306,6 +306,7 @@ static inline int same_magic(const char *amagic, const char *bmagic, bool has_cr#ifdef CONFIG_MODULE_KERNEL_ALIAS void free_mod_aliases (struct module *mod);int module_process_aliases (struct module *mod,struct load_info *info); +bool module_name_match_aliases (struct module *mod,const char *name,size_t len);#else static void free_mod_aliases (struct module *mod) {
@@ -314,4 +315,8 @@ static int module_process_aliases(struct module *mod, struct load_info *info) {return 0 ; } +static bool module_name_match_aliases (struct module *mod,const char *name,size_t len) +{ +return false; +}#endif /* CONFIG_MODULE_KERNEL_ALIAS */
kernel/module/main.c +23 -1
@@ -338,6 +338,28 @@ bool find_symbol(struct find_symbol_arg *fsa)return false; } +static bool module_name_match (struct module *mod,const char *name,size_t len) +{ +unsigned int i; +const char *alias; + +if (strlen (mod->name) == len && !memcmp (mod->name, name, len)) +return true; + +return module_name_match_aliases (mod, name, len); + +for (i=0 ; i < mod->num_aliases; i++) { + alias = mod->aliases[i]; +if (strlen (alias) == len && !memcmp (alias, name, len)) { +pr_debug ("module %s alias matched: alias[%u] = %s\n" , + mod->name, i, alias); +return true; + } + } + +return false; +} +/* * Search for module by name: must hold module_mutex (or preempt disabled * for read-only access).
@@ -353,7 +375,7 @@ struct module *find_module_all(const char *name, size_t len, lockdep_is_held(&module_mutex)) {if (!even_unformed && mod->state ==MODULE_STATE_UNFORMED )continue ; -if (strlen (mod->name) == len && !memcmp (mod->name, name, len)) +if (module_name_match (mod, name, len))return mod; }return NULL ;
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 5/12 module: add debugging alias parsing support
In reply to Luis ChamberlainWe don't have in-kernel alias parsing support as aliases are all dealt with in userspace. There has simply been no need to have support for processing them in kernel. We have done this under the assumption that userspace just Does The Right Thing (TM) about aliases and loading modules and that there is no real gain of processing aliases in-kernel.
Obviously userspace can be buggy though, and it can lie to us. We currently have no easy way to determine this. Parsing aliases is an example debugging facility we can use to help with these sorts of problems.
But there are some possible optimizations that may also be possible and enabling support let's folks experiment with these posibilities.
We disable this by default but folks can also enable this to experiment with features which may use aliases in-kernel. Folks should not enable this on production kernels. It'll bloat your loaded kernel modules a tiny bit by the size of the aliases that exist for them once loaded.
You can debug aliase by adding to your dynamic debug:
GRUB_CMDLINE_LINUX_DEFAULT="dyndbg=\"func module_process_aliases +p;\" "
Upon boot for example here a few entries:
module ext4 num_aliases: 5
alias[0] = fs-ext4
alias[1] = ext3
alias[2] = fs-ext3
alias[3] = ext2
alias[4] = fs-ext2
module xfs num_aliases: 1
alias[0] = fs-xfs
module floppy num_aliases: 3
alias[0] = block-major-2-*
alias[1] = acpi*:PNP0700:*
alias[2] = pnp:dPNP0700*
module ata_piix num_aliases: 89
alias[0] = pci:v00008086d00008C81sv*sd*bc*sc*i*
alias[1] = pci:v00008086d00008C80sv*sd*bc*sc*i*
alias[2] = pci:v00008086d00008C89sv*sd*bc*sc*i*
alias[3] = pci:v00008086d00008C88sv*sd*bc*sc*i*
... etc ...
--- include/linux/module.h | 4 ++ kernel/module/Kconfig | 19 +++++++++ kernel/module/Makefile | 1 + kernel/module/aliases.c | 92 ++++++++++++++++++++++++++++++++++++++++ kernel/module/internal.h | 15 +++++++ kernel/module/main.c | 17 ++++++-- 6 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 kernel/module/aliases.c
include/linux/module.h +4 -0
@@ -420,6 +420,10 @@ struct module {const char *srcversion;struct kobject *holders_dir; +#ifdef CONFIG_MODULE_KERNEL_ALIAS +unsigned int num_aliases; +const char **aliases; +#endif /* Exported symbols */ const struct kernel_symbol *syms;const s32 *crcs;
kernel/module/Kconfig +19 -0
@@ -22,6 +22,25 @@ menuconfig MODULES if MODULES +config MODULE_DEBUG + bool "Enable debugging information for modules" + default n + help + Enables debugging of the module infrastructure. Say no unless you + are debugging the module framework. Don't enable this on production. + This is only for experimentation and debugging. + +config MODULE_KERNEL_ALIAS + bool "Enable in-kernel alias processing for modules" + default n + depends on MODULE_DEBUG + help + The kernel has historically not processed aliases in-kernel since + we expect userspace can do all the proper work for us. Enable this + if you want to experiment processing aliases in-kernel. This will + bloat your kernel modules's memory by the number of aliases each + module has once loaded into the kernel. + config MODULE_FORCE_LOAD bool "Forced module loading" default n
kernel/module/Makefile +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_SYSFS) += sysfs.o obj-$(CONFIG_KGDB_KDB) += kdb.o obj-$(CONFIG_MODVERSIONS) += version.o obj-$(CONFIG_MODULE_UNLOAD_TAINT_TRACKING) += tracking.o +obj-$(CONFIG_MODULE_KERNEL_ALIAS) += aliases.o
kernel/module/aliases.c new file +92 -0
92 lines not on this page · raw message
kernel/module/internal.h +15 -0
@@ -96,6 +96,8 @@ long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,char *module_flags (struct module *mod,char *buf,bool show_state);size_t module_flags_taint (unsigned long taints,char *buf); +char *get_modinfo (const struct load_info *info,const char *tag); +char *get_next_modinfo (const struct load_info *info,const char *tag,char *prev);char *module_next_tag_pair (char *string,unsigned long *secsize);#define for_each_modinfo_entry (entry, info, name) \
@@ -300,3 +302,16 @@ static inline int same_magic(const char *amagic, const char *bmagic, bool has_cr return strcmp(amagic, bmagic) == 0; }#endif /* CONFIG_MODVERSIONS */ + +#ifdef CONFIG_MODULE_KERNEL_ALIAS +void free_mod_aliases (struct module *mod); +int module_process_aliases (struct module *mod,struct load_info *info); +#else +static void free_mod_aliases (struct module *mod) +{ +} +static int module_process_aliases (struct module *mod,struct load_info *info) +{ +return 0 ; +} +#endif /* CONFIG_MODULE_KERNEL_ALIAS */
kernel/module/main.c +14 -3
@@ -2,6 +2,7 @@/* * Copyright (C) 2002 Richard Henderson * Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. +* Copyright (C) 2023 Luis Chamberlain <[email protected]> */ #define INCLUDE_VERMAGIC
@@ -1035,8 +1036,7 @@ char *module_next_tag_pair(char *string, unsigned long *secsize)return string; } -static char *get_next_modinfo (const struct load_info *info,const char *tag, -char *prev) +char *get_next_modinfo (const struct load_info *info,const char *tag,char *prev) {char *p;unsigned int taglen =strlen (tag);
@@ -1061,7 +1061,7 @@ static char *get_next_modinfo(const struct load_info *info, const char *tag,return NULL ; } -static char *get_modinfo (const struct load_info *info,const char *tag) +char *get_modinfo (const struct load_info *info,const char *tag) {return get_next_modinfo (info, tag,NULL ); }
@@ -1289,6 +1289,7 @@ static void free_module(struct module *mod)module_arch_freeing_init (mod);kfree (mod->args);percpu_modfree (mod); +free_mod_aliases (mod);free_mod_mem (mod); }
@@ -1989,6 +1990,12 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) "is unknown, you have been warned.\n", mod->name); } +if (get_modinfo (info,"alias" )) { + err =module_process_aliases (mod, info); +if (err) + goto err_out_skip_alloc; + } + err =check_modinfo_livepatch (mod, info);if (err) goto err_out;
@@ -2005,6 +2012,8 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)return 0 ; err_out: +free_mod_aliases (mod); +err_out_skip_alloc:return err; }
@@ -2329,6 +2338,7 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)kmemleak_load_module (mod, info);return mod; err_out: +free_mod_aliases (mod);return ERR_PTR (err); }
@@ -2890,6 +2900,7 @@ static int load_module(struct load_info *info, const char __user *uargs,synchronize_rcu ();mutex_unlock (&module_mutex); free_module: +free_mod_aliases (mod);/* Free lock-classes; relies on the preceding sync_rcu() */ for_class_mod_mem_type(type, core_data) { lockdep_free_key_range(mod->mem[type].base,
Signature · 1 line
2.39.1
Luis Chamberlain
maintainerRFC 11/12 module: use list_add_tail_rcu() when adding module
In reply to Luis ChamberlainPut a new module at the end of the list intead of making new modules at the top of the list. find_module_all() start the hunt using the first entry on the list, if we assume that the modules which are first loaded are the most frequently looked for modules this should provide a tiny optimization.
This is theoretical, and could use more actual data by analzying the impact of this patch on boot time a slew of systems using systemd-analyze.
--- kernel/module/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/module/main.c +1 -1
@@ -2608,7 +2608,7 @@ static int add_unformed_module(struct module *mod) goto out;mod_update_bounds (mod); -list_add_rcu (&mod->list, &modules); +list_add_tail_rcu (&mod->list, &modules);mod_tree_insert (mod); err =0 ;
Signature · 1 line
2.39.1
kernel test robot
build botRe: [RFC 12/12] module: use aliases to find module on find_module_all()
In reply to Luis Chamberlain[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Luis,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on mcgrof/modules-next]
[also build test ERROR on linus/master v6.3-rc1 next-20230310] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Luis-Chamberlain/module-use-goto-errors-on-check_modinfo-and-layout_and_allocate/20230311-131905 base: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next patch link: https://lore.kernel.org/r/20230311051712.4095040-13-mcgrof%40kernel.org patch subject: [RFC 12/12] module: use aliases to find module on find_module_all() config: parisc-randconfig-r002-20230310 (https://download.01.org/0day-ci/archive/20230311/[email protected]/config) compiler: hppa-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/d92029475386e6bbbea10a2f56a87d37e61a2b38
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Luis-Chamberlain/module-use-goto-errors-on-check_modinfo-and-layout_and_allocate/20230311-131905 git checkout d92029475386e6bbbea10a2f56a87d37e61a2b38
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc SHELL=/bin/bash kernel/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
kernel/module/main.c: In function 'module_name_match':
>> kernel/module/main.c:351:26: error: 'struct module' has no member named 'num_aliases'
351 | for (i=0; i < mod->num_aliases; i++) {
| ^~
>> kernel/module/main.c:352:28: error: 'struct module' has no member named 'aliases'
352 | alias = mod->aliases[i];
| ^~vim +351 kernel/module/main.c
340
341 static bool module_name_match(struct module *mod, const char *name, size_t len)
342 {
343 unsigned int i;
344 const char *alias;
345
346 if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
347 return true;
348
349 return module_name_match_aliases(mod, name, len);
350
> 351 for (i=0; i < mod->num_aliases; i++) {
> 352 alias = mod->aliases[i]; 353 if (strlen(alias) == len && !memcmp(alias, name, len)) {
354 pr_debug("module %s alias matched: alias[%u] = %s\n",
355 mod->name, i, alias);
356 return true;
357 }
358 }
359
360 return false;
361 }
362
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [RFC 12/12] module: use aliases to find module on find_module_all()
In reply to Luis Chamberlain[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Luis,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on mcgrof/modules-next]
[also build test ERROR on linus/master v6.3-rc1 next-20230310] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Luis-Chamberlain/module-use-goto-errors-on-check_modinfo-and-layout_and_allocate/20230311-131905 base: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next patch link: https://lore.kernel.org/r/20230311051712.4095040-13-mcgrof%40kernel.org patch subject: [RFC 12/12] module: use aliases to find module on find_module_all() config: x86_64-randconfig-a001 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/d92029475386e6bbbea10a2f56a87d37e61a2b38
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Luis-Chamberlain/module-use-goto-errors-on-check_modinfo-and-layout_and_allocate/20230311-131905 git checkout d92029475386e6bbbea10a2f56a87d37e61a2b38
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash kernel/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> kernel/module/main.c:351:21: error: no member named 'num_aliases' in 'struct module'
for (i=0; i < mod->num_aliases; i++) {
~~~ ^
>> kernel/module/main.c:352:16: error: no member named 'aliases' in 'struct module'
alias = mod->aliases[i];
~~~ ^2 errors generated.
vim +351 kernel/module/main.c
340
341 static bool module_name_match(struct module *mod, const char *name, size_t len)
342 {
343 unsigned int i;
344 const char *alias;
345
346 if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
347 return true;
348
349 return module_name_match_aliases(mod, name, len);
350
> 351 for (i=0; i < mod->num_aliases; i++) {
> 352 alias = mod->aliases[i]; 353 if (strlen(alias) == len && !memcmp(alias, name, len)) {
354 pr_debug("module %s alias matched: alias[%u] = %s\n",
355 mod->name, i, alias);
356 return true;
357 }
358 }
359
360 return false;
361 }
362
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Quoted 15 lines · Luis Chamberlain
A long time ago we had some issues with userspace doing stupid stuff. Well, it turns out even the kernel and do stupid stuff too, as we're learning with the ACPI modules aliaes and that hammering tons of loads.
So add a bit of code which gets us a bit more in the defensive about these situations.
To experiment, this also adds in-kernel alias support to see if this helps with some larger systems.
This is all based on some old code which tried to add defensive mechanisms the last of which was here and I had dropped the ball:
Quoted 8 lines
I've only compile tested this for now. Will need to stress to test with kmod tests 0008 and 0009 to see if there's any differences. I'll have to re-test and re-gnuplot stuff there. But early feedback is appreciated, hence the RFC.
David Hildenbrand had reported a while ago issues with userspace doing insane things with allocations bringing a system down to its knees. This is part of the motivation for this series.
I'll try to grab a system where I can reproduce the issue and give your patches a churn.
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Petr Pavlu
maintainerRe: [RFC 12/12] module: use aliases to find module on find_module_all()
In reply to Luis ChamberlainQuoted 8 lines · Luis Chamberlain
Modules can have a series of aliases, but we don't currently use them to check if a module is already loaded. Part of this is because
load_module()will stick to checking for already loaded modules using the actual module name, not an alias. Its however desriable to also check for aliases onfind_module_all()for existing callers and future callers. The curent gain to using aliases onfind_module_all()will simply be to be able to support unloading modules using the alias using thedelete_module()syscall.
Different modules can have same aliases. Running
'sort modules.alias | cut -d' ' -f2 | uniq -dc' shows a list of them. When a modprobe load of such an alias is requested, my reading is that this new find_module_all() logic (if enabled) causes that only the first matched module is inserted and others get recognized as duplicates, which doesn't look right to me.
In general, I'm not sure that I understand motivation to keep track of these aliases in the kernel. Do you have links to previous discussions that I could perhaps read?
Thanks,
Petr
Luis Chamberlain
maintainerQuoted 21 lines · David Hildenbrand
Quoted 20 lines · Luis Chamberlain
A long time ago we had some issues with userspace doing stupid stuff. Well, it turns out even the kernel and do stupid stuff too, as we're learning with the ACPI modules aliaes and that hammering tons of loads.
So add a bit of code which gets us a bit more in the defensive about these situations.
To experiment, this also adds in-kernel alias support to see if this helps with some larger systems.
This is all based on some old code which tried to add defensive mechanisms the last of which was here and I had dropped the ball:
https://lore.kernel.org/all/[email protected]/
I've only compile tested this for now. Will need to stress to test with kmod tests 0008 and 0009 to see if there's any differences. I'll have to re-test and re-gnuplot stuff there. But early feedback is appreciated, hence the RFC.
Quoted 7 lines
Quoted 3 lines
David Hildenbrand had reported a while ago issues with userspace doing insane things with allocations bringing a system down to its knees. This is part of the motivation for this series.
I'll try to grab a system where I can reproduce the issue and give your patches a churn.
Great, then please wait for v2 RFC as the first patch was missing an obvious mutex grab / release, I already have some memory pressure data that shows gains. Hope to post soon.
Luis
Luis Chamberlain
maintainerRe: [RFC 12/12] module: use aliases to find module on find_module_all()
In reply to Petr PavluQuoted 10 lines · Petr Pavlu
Quoted 8 lines · Luis Chamberlain
Modules can have a series of aliases, but we don't currently use them to check if a module is already loaded. Part of this is because
load_module()will stick to checking for already loaded modules using the actual module name, not an alias. Its however desriable to also check for aliases onfind_module_all()for existing callers and future callers. The curent gain to using aliases onfind_module_all()will simply be to be able to support unloading modules using the alias using thedelete_module()syscall.
Quoted 2 lines
Different modules can have same aliases. Running
'sort modules.alias | cut -d' ' -f2 | uniq -dc' shows a list of them.
Ah then nevermind then thanks! I'll be sure to document this moving forwward!
Quoted 8 lines
When a modprobe load of such an alias is requested, my reading is that this new
find_module_all()logic (if enabled) causes that only the first matched module is inserted and others get recognized as duplicates, which doesn't look right to me.In general, I'm not sure that I understand motivation to keep track of these aliases in the kernel. Do you have links to previous discussions that I could perhaps read?
The idea was an old one and if it could help, but the above makes the idea useless, and so the only value for these aliases in-kernel could be for debugging, that's all.
Removing this will also simplify this patch series anyway.
Luis
Quoted 27 lines · Luis Chamberlain
Quoted 26 lines · David Hildenbrand
Quoted 23 lines · Luis Chamberlain
A long time ago we had some issues with userspace doing stupid stuff. Well, it turns out even the kernel and do stupid stuff too, as we're learning with the ACPI modules aliaes and that hammering tons of loads.
So add a bit of code which gets us a bit more in the defensive about these situations.
To experiment, this also adds in-kernel alias support to see if this helps with some larger systems.
This is all based on some old code which tried to add defensive mechanisms the last of which was here and I had dropped the ball:
https://lore.kernel.org/all/[email protected]/
I've only compile tested this for now. Will need to stress to test with kmod tests 0008 and 0009 to see if there's any differences. I'll have to re-test and re-gnuplot stuff there. But early feedback is appreciated, hence the RFC.
David Hildenbrand had reported a while ago issues with userspace doing insane things with allocations bringing a system down to its knees. This is part of the motivation for this series.
Quoted 6 lines
Quoted 2 lines
I'll try to grab a system where I can reproduce the issue and give your patches a churn.
Great, then please wait for v2 RFC as the first patch was missing an obvious mutex grab / release, I already have some memory pressure data that shows gains. Hope to post soon.
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 35 lines · David Hildenbrand
Quoted 27 lines · Luis Chamberlain
Quoted 26 lines · David Hildenbrand
Quoted 23 lines · Luis Chamberlain
A long time ago we had some issues with userspace doing stupid stuff. Well, it turns out even the kernel and do stupid stuff too, as we're learning with the ACPI modules aliaes and that hammering tons of loads.
So add a bit of code which gets us a bit more in the defensive about these situations.
To experiment, this also adds in-kernel alias support to see if this helps with some larger systems.
This is all based on some old code which tried to add defensive mechanisms the last of which was here and I had dropped the ball:
https://lore.kernel.org/all/[email protected]/
I've only compile tested this for now. Will need to stress to test with kmod tests 0008 and 0009 to see if there's any differences. I'll have to re-test and re-gnuplot stuff there. But early feedback is appreciated, hence the RFC.
David Hildenbrand had reported a while ago issues with userspace doing insane things with allocations bringing a system down to its knees. This is part of the motivation for this series.
Quoted 6 lines
Quoted 2 lines
I'll try to grab a system where I can reproduce the issue and give your patches a churn.
Great, then please wait for v2 RFC as the first patch was missing an obvious mutex grab / release, I already have some memory pressure data that shows gains. Hope to post soon.
Quoted 6 lines
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
I'm seeing about ~86 MiB saving on the upper bound on memory usage while hammering on kmod test 0008, and this is on a small system.
Probably won't help *that* much but am curious... if it helps somewhat.
Luis
Luis Chamberlain
maintainerQuoted 8 lines · Luis Chamberlain
Quoted 6 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
Quoted 8 lines
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
I'm seeing about ~86 MiB saving on the upper bound on memory usage while hammering on kmod test 0008, and this is on a small system.
Probably won't help *that* much but am curious... if it helps somewhat.
How much cpu count BTW?
Luis
Luis Chamberlain
maintainerQuoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
The last patch really would have no justification yet at all unless it does help your case.
Luis
Quoted 11 lines · Luis Chamberlain
Quoted 10 lines · Luis Chamberlain
Quoted 6 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
Quoted 8 lines
Quoted 6 lines
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
I'm seeing about ~86 MiB saving on the upper bound on memory usage while hammering on kmod test 0008, and this is on a small system.
Probably won't help *that* much but am curious... if it helps somewhat.
How much cpu count BTW?
220 physical ones and 440 virtual ones.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 12 lines · Luis Chamberlain
Quoted 11 lines · Luis Chamberlain
Quoted 10 lines · Luis Chamberlain
Quoted 6 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
Quoted 8 lines
Quoted 1 line
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Okay, I have a system where I can reproduce.
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 28 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Quoted 7 lines
Okay, I have a system where I can reproduce.
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Yes please give that a run.
Please collect systemd-analyze given lack of any other tool to evaluate any deltas. Can't think of anything else to gather other than seeing if it booted.
If that boots works then try removing the last patch "module: add a sanity check prior to allowing kernel module auto-loading" to see if that last patch helped or was just noise. As it stands I'm not convinced yet if it did help, if it *does* help we probably need to rethink some finit_module() allocations things.
If you *still* can't boot the system, well, we should re-think finit_module() allocation path a bit more too.
Luis
Quoted 31 lines · Luis Chamberlain
Quoted 30 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Okay, I have a system where I can reproduce.
Quoted 7 lines
Quoted 5 lines
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Yes please give that a run.
Reproduced with v6.3.0-rc1 (on 1st try)
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Quoted 4 lines
Please collect systemd-analyze given lack of any other tool to evaluate any deltas. Can't think of anything else to gather other than seeing if it booted.
Issue is that some services (kdump, tuned) seem to take sometimes ages on that system to start for some reason, and systemd-analyze refuses to do something reasonable while the system is still booting up.
I'll see if I can come up with some data.
Quoted 6 lines
If that boots works then try removing the last patch "module: add a sanity check prior to allowing kernel module auto-loading" to see if that last patch helped or was just noise. As it stands I'm not convinced yet if it did help, if it *does* help we probably need to rethink some
finit_module()allocations things.
Okay, will try without the last patch tomorrow.
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 34 lines · David Hildenbrand
Quoted 33 lines · Luis Chamberlain
Quoted 32 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Okay, I have a system where I can reproduce.
Should I give
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Yes please give that a run.
Reproduced with v6.3.0-rc1 (on 1st try)
By reproduced, you mean it fails to boot?
Quoted 1 line
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
Quoted 6 lines
Quoted 3 lines
Please collect systemd-analyze given lack of any other tool to evaluate any deltas. Can't think of anything else to gather other than seeing if it booted.
Issue is that some services (kdump, tuned) seem to take sometimes ages on that system to start for some reason,
How about disabling that?
Quoted 2 lines
and systemd-analyze refuses to do
something reasonable while the system is still booting up.
I see.
Quoted 1 line
I'll see if I can come up with some data.
Thanks!
Quoted 7 lines
Quoted 5 lines
If that boots works then try removing the last patch "module: add a sanity check prior to allowing kernel module auto-loading" to see if that last patch helped or was just noise. As it stands I'm not convinced yet if it did help, if it *does* help we probably need to rethink some
finit_module()allocations things.Okay, will try without the last patch tomorrow.
Thanks!!
Luis
Luis Chamberlain
maintainerQuoted 5 lines · Luis Chamberlain
Quoted 1 line · David Hildenbrand
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
Now that we know that tree works, I'm curious also now if you can confirm just re-ordering the patches still works (it should)
And although it's *probably* just noise, but I'm very curious how much, if any difference there is if you just revert "module: use list_add_tail_rcu() when adding module".
The data on that commit log is pretty small as I have a low end system, and I'm not yet done beating the hell out of a system with stress-ng, but getting some data froma pretty large system would be great. Specially if this series seems to prove fixing boot on them.
Luis
Quoted 37 lines · Luis Chamberlain
Quoted 36 lines · David Hildenbrand
Quoted 35 lines · Luis Chamberlain
Quoted 34 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Okay, I have a system where I can reproduce.
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
from yesterday a churn?
Yes please give that a run.
Reproduced with v6.3.0-rc1 (on 1st try)
By reproduced, you mean it fails to boot?
It boots but we get vmap allocation warnings, because the ~440 CPUs manage to completely exhaust the module vmap area due to KASAN.
Quoted 4 lines
Quoted 2 lines
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
It boots and I don't get the vmap allocation warnings.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Please collect systemd-analyze given lack of any other tool to evaluate any deltas. Can't think of anything else to gather other than seeing if it booted.
Issue is that some services (kdump, tuned) seem to take sometimes ages on that system to start for some reason,
How about disabling that?
It seems to be random services. On my debug kernel with KASAN everything is just super slow. I'll try to measure on a !debug kernel.
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 40 lines · David Hildenbrand
Quoted 39 lines · Luis Chamberlain
Quoted 38 lines · David Hildenbrand
Quoted 37 lines · Luis Chamberlain
Quoted 35 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Okay, I have a system where I can reproduce.
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Yes please give that a run.
Reproduced with v6.3.0-rc1 (on 1st try)
By reproduced, you mean it fails to boot?
It boots but we get vmap allocation warnings, because the ~440 CPUs manage to completely exhaust the module vmap area due to KASAN.
Thanks, can you post a trace?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
It boots and I don't get the vmap allocation warnings.
Wonderful!
Now to zero if all commits are required, and measure small value-add for each of them. That is the hard part and thanks for any time you can help dedicate towards that.
There's really only 3 functional changes we need to measure:
In the 20230319-module-alloc-opts-adjust branch they are left towards the end, in history, the top being the most recent commit:
600f1f769d06 module: add a sanity check prior to allowing kernel module auto-loading 680f2c1fff2d module: use list_add_tail_rcu() when adding module 6023a6c7d98c module: avoid allocation if module is already present and ready
My guess is the majority of the fix comes from the last commit, so commit 6023a6c7d98c ("module: avoid allocation if module is already present and ready").
The rcu one probably doesn't help much but I think it makes sense while we're at it.
The last one is the one I'm less convinced makes sense. But *if* it does help, it means such finit_module() situations / stresses are much larger than we ever anticipated.
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Please collect systemd-analyze given lack of any other tool to evaluate any deltas. Can't think of anything else to gather other than seeing if it booted.
Issue is that some services (kdump, tuned) seem to take sometimes ages on that system to start for some reason,
How about disabling that?
It seems to be random services. On my debug kernel with KASAN everything is just super slow. I'll try to measure on a !debug kernel.
Got it thanks!
Luis
Quoted 43 lines · Luis Chamberlain
Quoted 42 lines · David Hildenbrand
Quoted 41 lines · Luis Chamberlain
Quoted 40 lines · David Hildenbrand
Quoted 38 lines · Luis Chamberlain
Quoted 28 lines · David Hildenbrand
Quoted 19 lines · David Hildenbrand
Quoted 18 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
I expect to have a machine (with a crazy number of CPUs/devices) available in a couple of days (1-2), so no need to rush.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The original machine I was able to reproduce with is blocked for a little bit longer; so I hope the alternative I looked up will similarly trigger the issue easily.
OK give this a spin:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230316-module-alloc-opts
Today I am up to here:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230317-module-alloc-opts
Quoted 7 lines
Quoted 2 lines
The last patch really would have no justification yet at all unless it does help your case.
Still waiting on the system (the replacement system I was able to grab broke ...).
I'll let you know once I succeeded in reproducing + testing your fixes.
Quoted 7 lines
Okay, I have a system where I can reproduce.
Should I give
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230319-module-alloc-opts
from yesterday a churn?
Yes please give that a run.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Reproduced with v6.3.0-rc1 (on 1st try)
By reproduced, you mean it fails to boot?
It boots but we get vmap allocation warnings, because the ~440 CPUs manage to completely exhaust the module vmap area due to KASAN.
Thanks, can you post a trace?
See
https://lkml.kernel.org/r/[email protected]
where I also describe the issue in more detail.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
It boots and I don't get the vmap allocation warnings.
Wonderful!
I'm still compiling/testing the debug kernels (20230319-module-alloc-opts-adjust + single revert of the rcu patch). I should have some systemd-analyze results for !debug kernels later.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · Luis Chamberlain
Quoted 1 line · David Hildenbrand
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Quoted 8 lines
Quoted 2 lines
Oh wow, so to clarify, it boots OK?
Now that we know that tree works, I'm curious also now if you can confirm just re-ordering the patches still works (it should)
So far no vmap errors booting the debug/kasan kernel (2 tries).
Quoted 3 lines
And although it's *probably* just noise, but I'm very curious how much, if any difference there is if you just revert "module: use
list_add_tail_rcu()when adding module".
Dito, no vmap errors booting the debug/kasan kernel (2 tries).
Quoted 5 lines
The data on that commit log is pretty small as I have a low end system, and I'm not yet done beating the hell out of a system with stress-ng, but getting some data froma pretty large system would be great. Specially if this series seems to prove fixing boot on them.
2x booting RHEL9.1 on a !debug kernel. Something went wrong with kdump in 2 runs (think I had to delete the kdump initrd to make space for another kernel), but we can just mostly ignore that. I wanted to rerun with kdump disabled completely, but I'm out of time for today.
1) v6.3-rc1:
#1
Startup finished in 25.354s (kernel) + 7.662s (initrd) + 1min 8.805s (userspace) = 1min 41.822s multi-user.target reached after 29.186s in userspace
47.178s kdump.service
14.898s tuned.service
11.394s chrony-wait.service
7.486s systemd-udev-settle.service
7.334s NetworkManager-wait-online.service
2.908s initrd-switch-root.service
2.451s smartd.service
2.316s dracut-initqueue.service
2.057s polkit.service
1.290s NetworkManager.service
1.046s cups.service
...
#2
Startup finished in 25.375s (kernel) + 7.497s (initrd) + 29.428s (userspace) = 1min 2.301s multi-user.target reached after 29.392s in userspace
14.552s tuned.service
9.410s chrony-wait.service
8.126s systemd-udev-settle.service
7.502s NetworkManager-wait-online.service
2.871s initrd-switch-root.service
2.401s kdump.service
2.297s polkit.service
2.116s dracut-initqueue.service
2.027s smartd.service
1.262s NetworkManager.service
1.102s cups.service
1.011s sshd.service
...
2) 20230319-module-alloc-opts-adjust + revert of list_add_tail_rcu():
#1
Startup finished in 25.441s (kernel) + 7.285s (initrd) + 1min 7.644s (userspace) = 1min 40.371s multi-user.target reached after 27.213s in userspace
47.232s kdump.service
14.235s tuned.service
8.220s chrony-wait.service
7.444s NetworkManager-wait-online.service
5.986s systemd-udev-settle.service
2.881s initrd-switch-root.service
2.236s smartd.service
1.899s dracut-initqueue.service
1.812s polkit.service
1.554s NetworkManager.service
1.140s ModemManager.service
...
#2
Startup finished in 25.377s (kernel) + 7.271s (initrd) + 28.247s (userspace) = 1min 897ms multi-user.target reached after 28.210s in userspace
15.435s tuned.service
11.365s chrony-wait.service
7.512s NetworkManager-wait-online.service
5.962s systemd-udev-settle.service
2.889s initrd-switch-root.service
2.846s smartd.service
2.819s kdump.service
2.228s polkit.service
1.872s dracut-initqueue.service
1.312s NetworkManager.service
1.152s ModemManager.service
1.011s sshd.service
...
3) 20230319-module-alloc-opts-adjust:
#1
Startup finished in 25.320s (kernel) + 7.192s (initrd) + 1min 6.511s (userspace) = 1min 39.024s multi-user.target reached after 28.205s in userspace
46.307s kdump.service
14.199s tuned.service
13.358s chrony-wait.service
7.468s NetworkManager-wait-online.service
6.329s systemd-udev-settle.service
2.910s initrd-switch-root.service
2.752s smartd.service
2.142s polkit.service
1.909s dracut-initqueue.service
1.210s NetworkManager.service
1.041s ModemManager.service
925ms sshd.service
...
#2
Startup finished in 25.368s (kernel) + 7.303s (initrd) + 1min 6.897s (userspace) = 1min 39.569s multi-user.target reached after 27.326s in userspace
45.626s kdump.service
14.707s tuned.service
13.246s chrony-wait.service
7.428s NetworkManager-wait-online.service
6.507s systemd-udev-settle.service
3.038s initrd-switch-root.service
3.001s smartd.service
2.057s polkit.service
1.746s dracut-initqueue.service
1.221s NetworkManager.service
...
I think we primarily only care about systemd-udev-settle.service.
That is fastest without the rcu patch (~6s), compared to with the rcu patch (~6.5s) and with stock (~7.5s -- 8s).
Looks like dracut-initqueue also might be a bit faster with your changes, but maybe it's mostly noise (would have to do more runs).
So maybe drop that rcu patch? But of course, there could be other scenarios where it's helpful ...
Signature · 3 lines
Thanks, David / dhildenb
Quoted 154 lines · David Hildenbrand
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · Luis Chamberlain
Quoted 1 line · David Hildenbrand
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Quoted 8 lines
Quoted 2 lines
Oh wow, so to clarify, it boots OK?
Now that we know that tree works, I'm curious also now if you can confirm just re-ordering the patches still works (it should)
So far no vmap errors booting the debug/kasan kernel (2 tries).
Quoted 3 lines
And although it's *probably* just noise, but I'm very curious how much, if any difference there is if you just revert "module: use
list_add_tail_rcu()when adding module".Dito, no vmap errors booting the debug/kasan kernel (2 tries).
Quoted 5 lines
The data on that commit log is pretty small as I have a low end system, and I'm not yet done beating the hell out of a system with stress-ng, but getting some data froma pretty large system would be great. Specially if this series seems to prove fixing boot on them.
2x booting RHEL9.1 on a !debug kernel. Something went wrong with kdump in 2 runs (think I had to delete the kdump initrd to make space for another kernel), but we can just mostly ignore that. I wanted to rerun with kdump disabled completely, but I'm out of time for today.
1) v6.3-rc1:
#1
Startup finished in 25.354s (kernel) + 7.662s (initrd) + 1min 8.805s (userspace) = 1min 41.822s multi-user.target reached after 29.186s in userspace
47.178s kdump.service
14.898s tuned.service
11.394s chrony-wait.service
7.486s systemd-udev-settle.service
7.334s NetworkManager-wait-online.service
2.908s initrd-switch-root.service
2.451s smartd.service
2.316s dracut-initqueue.service
2.057s polkit.service
1.290s NetworkManager.service
1.046s cups.service
...#2
Startup finished in 25.375s (kernel) + 7.497s (initrd) + 29.428s (userspace) = 1min 2.301s multi-user.target reached after 29.392s in userspace
14.552s tuned.service
9.410s chrony-wait.service
8.126s systemd-udev-settle.service
7.502s NetworkManager-wait-online.service
2.871s initrd-switch-root.service
2.401s kdump.service
2.297s polkit.service
2.116s dracut-initqueue.service
2.027s smartd.service
1.262s NetworkManager.service
1.102s cups.service
1.011s sshd.service
...2) 20230319-module-alloc-opts-adjust + revert of
list_add_tail_rcu():#1
Startup finished in 25.441s (kernel) + 7.285s (initrd) + 1min 7.644s (userspace) = 1min 40.371s multi-user.target reached after 27.213s in userspace
47.232s kdump.service
14.235s tuned.service
8.220s chrony-wait.service
7.444s NetworkManager-wait-online.service
5.986s systemd-udev-settle.service
2.881s initrd-switch-root.service
2.236s smartd.service
1.899s dracut-initqueue.service
1.812s polkit.service
1.554s NetworkManager.service
1.140s ModemManager.service
...#2
Startup finished in 25.377s (kernel) + 7.271s (initrd) + 28.247s (userspace) = 1min 897ms multi-user.target reached after 28.210s in userspace
15.435s tuned.service
11.365s chrony-wait.service
7.512s NetworkManager-wait-online.service
5.962s systemd-udev-settle.service
2.889s initrd-switch-root.service
2.846s smartd.service
2.819s kdump.service
2.228s polkit.service
1.872s dracut-initqueue.service
1.312s NetworkManager.service
1.152s ModemManager.service
1.011s sshd.service
...3) 20230319-module-alloc-opts-adjust:
#1
Startup finished in 25.320s (kernel) + 7.192s (initrd) + 1min 6.511s (userspace) = 1min 39.024s multi-user.target reached after 28.205s in userspace
46.307s kdump.service
14.199s tuned.service
13.358s chrony-wait.service
7.468s NetworkManager-wait-online.service
6.329s systemd-udev-settle.service
2.910s initrd-switch-root.service
2.752s smartd.service
2.142s polkit.service
1.909s dracut-initqueue.service
1.210s NetworkManager.service
1.041s ModemManager.service
925ms sshd.service
...#2
Startup finished in 25.368s (kernel) + 7.303s (initrd) + 1min 6.897s (userspace) = 1min 39.569s multi-user.target reached after 27.326s in userspace
45.626s kdump.service
14.707s tuned.service
13.246s chrony-wait.service
7.428s NetworkManager-wait-online.service
6.507s systemd-udev-settle.service
3.038s initrd-switch-root.service
3.001s smartd.service
2.057s polkit.service
1.746s dracut-initqueue.service
1.221s NetworkManager.service
...I think we primarily only care about systemd-udev-settle.service.
Quoted 8 lines
That is fastest without the rcu patch (~6s), compared to with the rcu patch (~6.5s) and with stock (~7.5s -- 8s).
Looks like dracut-initqueue also might be a bit faster with your changes, but maybe it's mostly noise (would have to do more runs).
So maybe drop that rcu patch? But of course, there could be other scenarios where it's helpful ...
Are there any other things you would like me to measure/test? I'll have to hand back that test machine soonish.
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 9 lines · David Hildenbrand
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 1 line · David Hildenbrand
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Now that we know that tree works, I'm curious also now if you can confirm just re-ordering the patches still works (it should)
So far no vmap errors booting the debug/kasan kernel (2 tries).
<-- snip -->
Quoted 10 lines
Quoted 10 lines
I think we primarily only care about systemd-udev-settle.service.
That is fastest without the rcu patch (~6s), compared to with the rcu patch (~6.5s) and with stock (~7.5s -- 8s).
Looks like dracut-initqueue also might be a bit faster with your changes, but maybe it's mostly noise (would have to do more runs).
So maybe drop that rcu patch? But of course, there could be other scenarios where it's helpful ...
Yes I confirm the RCU patch does not help at all now also using stress-ng.
Quoted 2 lines
Are there any other things you would like me to measure/test? I'll have to hand back that test machine soonish.
Yes please test the below. Perhaps its not the final form we want, but it *does* fix OOM'ing when thrashing with stress-ng now with the module option and even with 100 threads brings down max memory consumption by 259 MiB. The reason is that we also vmalloc during each finit_read_file() for each module as well way before we even do layout_and_allocate(), and so obviously if we fix the module path but not this path this will eventually catch up with us as. I'm not at all happy with the current approach given ideally we'd bump the counter when the user is done with the file, but we don't yet have any tracking of that for users, they just vfree the memory itself. And so this is just trying to catch heavy immediate abuse on the caller to fend off abuse of vmalloc uses in a lightway manner.
There's gotta be a better way to do this, but its just an idea I have so far. If we *want* to keep tabs until the user is done, we have to just modify most users of these APIs and intrudce our own free. I don't think we're in a rush to fix this so maybe that's the better approach.
And so I've managed to reproduce the issues you found now with my new stress-ng module stressor as well.
https://github.com/ColinIanKing/stress-ng.git
Even though you have 400 CPUs with stress-ng we can likely reproduce it with (use a module not loaded on your system):
./stress-ng --module 100 --module-name xfs
Without the patch below using 400 threads still OOMs easily due to the kread issue. Max threads allowed are 8192.
From ec5099b15bb74f154319034547184e81e4ad8ba0 Mon Sep 17 00:00:00 2001
From: Luis Chamberlain <[email protected]>
Date: Fri, 24 Mar 2023 10:35:41 -0700
Subject: [PATCH] fs/kernel_read_file: add a clutch
--- fs/kernel_read_file.c | 52 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-)
fs/kernel_read_file.c +50 -2
@@ -1,10 +1,52 @@// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt (fmt) "kread: " fmt +#include <linux/fs.h> #include <linux/fs_struct.h> #include <linux/kernel_read_file.h> #include <linux/security.h> #include <linux/vmalloc.h> +/* +* This clutch ensures we only allow a certain number concurrent threads at a +* time allocating space concurrently and they must all finish within the +* timeout specified. Anything more we know we're thrashing. +*/ +#define MAX_KREAD_CONCURRENT 20 +static atomic_t kread_concurrent_max =ATOMIC_INIT (MAX_KREAD_CONCURRENT ); +static DECLARE_WAIT_QUEUE_HEAD (kread_wq); + +/* +* How many seconds to wait for *all* MAX_KREAD_CONCURRENT threads running +* at the same time without returning. +*/ +#define MAX_KREAD_ALL_BUSY_TIMEOUT 1 + +static int kernel_read_check_concurrent (void ) +{ +int ret; + +if (atomic_dec_if_positive (&kread_concurrent_max) <0 ) { +pr_warn_ratelimited ("kread_concurrent_max (%u) close to 0 (max_loads: %u), throttling..." , +atomic_read (&kread_concurrent_max), +MAX_KREAD_CONCURRENT ); + ret =wait_event_killable_timeout (kread_wq, +atomic_dec_if_positive (&kread_concurrent_max) >=0 , +MAX_KREAD_ALL_BUSY_TIMEOUT *HZ ); +if (!ret) { +pr_warn_ratelimited ("reading cannot be processed, kernel busy with %d threads reading files now for more than %d seconds" , +MAX_KREAD_CONCURRENT ,MAX_KREAD_ALL_BUSY_TIMEOUT ); +return -ETIME ; + }else if (ret == -ERESTARTSYS ) { +pr_warn_ratelimited ("sigkill sent for kernel read, giving up" ); +return ret; + } + } + +return 0 ; +} +/** * kernel_read_file() - read file contents into a kernel buffer *
@@ -68,10 +110,14 @@ ssize_t kernel_read_file(struct file *file, loff_t offset, void **buf, goto out; } + ret =kernel_read_check_concurrent (); +if (ret) + goto out; + whole_file = (offset ==0 && i_size <= buf_size); ret =security_kernel_read_file (file, id, whole_file);if (ret) - goto out; + goto out_allow_new_read;if (file_size) *file_size = i_size;
@@ -117,7 +163,9 @@ ssize_t kernel_read_file(struct file *file, loff_t offset, void **buf, *buf =NULL ; } } - +out_allow_new_read: +atomic_inc (&kread_concurrent_max); +wake_up (&kread_wq); out:allow_write_access (file);return ret ==0 ? copied : ret;
Signature · 1 line
2.39.2
Quoted 3 lines · Luis Chamberlain
+/*
+ * This clutch ensures we only allow a certain number concurrent threads at a
kludge, not clutch.
And it's much worse than a kludge. It's just wrong and disgusting.
fs/kernel_read_file.c line 33
Quoted 3 lines
fs/kernel_read_file.c +3
-0+pr_warn_ratelimited ("kread_concurrent_max (%u) close to 0 (max_loads: %u), throttling..." , +atomic_read (&kread_concurrent_max), +MAX_KREAD_CONCURRENT );
This is also wrong, since it's not kernel_read_file() that is the problem, but whatever broken caller.
Yeah, yeah, in practice it's presumably always just finit_module() doing kernel_read_file_from_fd(), but it's still *completely* wrong to just say "function X is throttling" when "X" isn't the problem, and doesn't tell what the _real_ problem is.
I really think this all needs some core fixing at the module layer, not these kinds of horrific hacks.
Linus
Luis Chamberlain
maintainerQuoted 8 lines · Linus Torvalds
Quoted 3 lines · Luis Chamberlain
+/*
+ * This clutch ensures we only allow a certain number concurrent threads at akludge, not clutch.
And it's much worse than a kludge. It's just wrong and disgusting.
I wasn't happy with it either...
Quoted 11 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ pr_warn_ratelimited("kread_concurrent_max (%u) close to 0 (max_loads: %u), throttling...", + atomic_read(&kread_concurrent_max), + MAX_KREAD_CONCURRENT);This is also wrong, since it's not
kernel_read_file()that is the problem, but whatever broken caller.Yeah, yeah, in practice it's presumably always just
finit_module()doingkernel_read_file_from_fd(), but it's still *completely* wrong to just say "function X is throttling" when "X" isn't the problem, and doesn't tell what the _real_ problem is.
True.
Quoted 2 lines
I really think this all needs some core fixing at the module layer, not these kinds of horrific hacks.
On the modules side of things we can be super defensive on the second vmalloc allocation defensive [0] but other than this the initial kread also needs care too.
To address the kread abuse within finit_module we could just move the kludge to the modules side of things until each free happens as in the below alternative. That just means any easy user interfacing call with kernel_read*() would likely have to be as careful. Untested below.
[0] https://lkml.kernel.org/r/[email protected]
Luis
From 3c3f7e597ab35b4482ccb4064bb897eefa449071 Mon Sep 17 00:00:00 2001
From: Luis Chamberlain <[email protected]>
Date: Fri, 24 Mar 2023 12:51:44 -0700
Subject: [PATCH] module: kludge
--- kernel/module/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
kernel/module/main.c +44 -1
@@ -62,6 +62,16 @@#define CREATE_TRACE_POINTS #include <trace/events/module.h> +#define MAX_INITMOD_CONCURRENT 50 +static atomic_t initmod_concurrent_max =ATOMIC_INIT (MAX_INITMOD_CONCURRENT ); +static DECLARE_WAIT_QUEUE_HEAD (initmod_wq); + +/* +* How much time to wait for *all* MAX_INITMOD_CONCURRENT threads running +* at the same time without returning. +*/ +#define MAX_INITMOD_ALL_BUSY_TIMEOUT 5 +/* * Mutex protects: * 1) List of modules (also safely readable with preempt_disable),
@@ -3015,6 +3025,30 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,return load_module (&info, uargs,0 ); } +static int module_kread_concurrent (void ) +{ +int err; + +if (atomic_dec_if_positive (&initmod_concurrent_max) <0 ) { +pr_warn_ratelimited ("finit_module: initkmod_concurrent_max (%u) close to 0 (max_loads: %u), throttling..." , +atomic_read (&initmod_concurrent_max), +MAX_INITMOD_CONCURRENT ); + err =wait_event_killable_timeout (initmod_wq, +atomic_dec_if_positive (&initmod_concurrent_max) >=0 , +MAX_INITMOD_ALL_BUSY_TIMEOUT *HZ ); +if (!err) { +pr_warn_ratelimited ("finit_module: loading module cannot be processed, kernel busy with %d threads loading modules now for more than %d seconds" , +MAX_INITMOD_CONCURRENT ,MAX_INITMOD_ALL_BUSY_TIMEOUT ); +return -ETIME ; + }else if (err == -ERESTARTSYS ) { +pr_warn_ratelimited ("finit_module: sigkill sent for load_module giving up" ); +return err; + } + } + +return 0 ; +} + SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) {struct load_info info = { };
@@ -3033,6 +3067,10 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) |MODULE_INIT_COMPRESSED_FILE))return -EINVAL ; + err =module_kread_concurrent (); +if (err) +return err; + len =kernel_read_file_from_fd (fd,0 , &buf,INT_MAX ,NULL ,READING_MODULE );if (len <0 )
@@ -3048,7 +3086,12 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) info.len = len; } -return load_module (&info, uargs, flags); + err =load_module (&info, uargs, flags); + +atomic_inc (&initmod_concurrent_max); +wake_up (&initmod_wq); + +return err; }/* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
Signature · 1 line
2.39.2
Quoted 4 lines · Luis Chamberlain
On the modules side of things we can be super defensive on the second vmalloc allocation defensive [0] but other than this the initial kread also needs care too.
Please don't re-implement semaphores. They are a *classic* concurrency limiter.
In fact, probably *THE* classic one.
So just do something like this instead:
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2937,6 +2937,11 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
return load_module(&info, uargs, 0);
} +#define CONCURRENCY_LIMITER(name, n) \
+ struct semaphore name = __SEMAPHORE_INITIALIZER(name, n)
+
+static CONCURRENCY_LIMITER(module_loading_concurrency, 50); +
SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs,
int, flags)
{
struct load_info info = { };
@@ -2955,8 +2960,12 @@ SYSCALL_DEFINE3(finit_module, int, fd, const
char __user *, uargs, int, flags)
|MODULE_INIT_COMPRESSED_FILE))
return -EINVAL; + err = down_killable(&module_loading_concurrency);
+ if (err)
+ return err;
len = kernel_read_file_from_fd(fd, 0, &buf, INT_MAX, NULL,
READING_MODULE);
+ up(&module_loading_concurrency);
if (len < 0)
return len;NOTE! Entirely untested. Surprise surprise.
I'm a tiny bit worried about deadlocks here, so somebody needs to make sure that the kernel_read_file_from_fd() case cannot possibly in turn cause a "request_module()" recursion.
We most definitely have had module recursion before, but I *think* it's always just in the module init function (ie one module requests another when ithe mod->init() function is called).
I think by the time we have opened the module file descriptors and are just reading the data, we should be ok and the above would never deadlock, but I want people to at least think about it.
Of course, with that "max 50 concurrent loaders" limit, maybe it's never an issue anyway. Even if you get a recursion a few deep, at most you just wait for somebody else to get out of their loaders. Unless *everybody* ends up waiting on some progress.
Linus
Luis Chamberlain
maintainerQuoted 37 lines · Linus Torvalds
Quoted 4 lines · Luis Chamberlain
On the modules side of things we can be super defensive on the second vmalloc allocation defensive [0] but other than this the initial kread also needs care too.
Please don't re-implement semaphores. They are a *classic* concurrency limiter.
In fact, probably *THE* classic one.
So just do something like this instead:
--- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2937,6 +2937,11 @@ SYSCALL_DEFINE3(init_module, void __user *, umod, return load_module(&info, uargs, 0); }+#define CONCURRENCY_LIMITER(name, n) \ + struct semaphore name = __SEMAPHORE_INITIALIZER(name, n) + +static CONCURRENCY_LIMITER(module_loading_concurrency, 50); + SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) { struct load_info info = { }; @@ -2955,8 +2960,12 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) |MODULE_INIT_COMPRESSED_FILE)) return -EINVAL;+ err =
down_killable(&module_loading_concurrency);
+ if (err)
+ return err;
len = kernel_read_file_from_fd(fd, 0, &buf,INT_MAX, NULL,
READING_MODULE);
Quoted 5 lines
+ up(&module_loading_concurrency); if (len < 0) return len;NOTE! Entirely untested. Surprise surprise.
I'll give it a good wack thanks.
But it still begs the question if *other* vmalloc user-interfacing places need similar practices. It's not just system calls that use it willy nilly but anything that could in the end use it. Surely a lot of "issues" could only happen in an insane pathological use case, but it's a generic thing to keep in mind in the end.
Quoted 3 lines
I'm a tiny bit worried about deadlocks here, so somebody needs to make sure that the
kernel_read_file_from_fd()case cannot possibly in turn cause a "request_module()" recursion.
Automount on a path where the module lies in a path for a modue not loaded yet triggering a kernel module autoload is the only thing I can think of that could cause that, but that just calls userspace modprobe. And I think that'd be an insane setup.
Quoted 3 lines
We most definitely have had module recursion before, but I *think* it's always just in the module init function (ie one module requests another when ithe
mod->init()function is called).
Since you up() right after the kernel_read_file_from_fd() we would not be racing module inits with this. If however we place the up() after the load_module() then that does incur that recurssion possibilty.
Quoted 8 lines
I think by the time we have opened the module file descriptors and are just reading the data, we should be ok and the above would never deadlock, but I want people to at least think about it.
Of course, with that "max 50 concurrent loaders" limit, maybe it's never an issue anyway. Even if you get a recursion a few deep, at most you just wait for somebody else to get out of their loaders. Unless *everybody* ends up waiting on some progress.
Yeah, these certainly are pathalogical corner cases. I'm more interested in solving doing something sane for 1000 CPUs or 2000 CPUs for now, even if the issue was the kernel (not userspace) to blame (and even if those use cases are being fixed now like the queued up linux-next ACPI CPU frequency modules per CPU).
Luis
Luis Chamberlain
maintainerQuoted 3 lines · Luis Chamberlain
Quoted 1 line · Linus Torvalds
+static CONCURRENCY_LIMITER(module_loading_concurrency, 50);I'll give it a good wack thanks.
Using a value of 20 above matches what I to get up to 100 stress-ng module ops without any OOM (which seems to mimick a 400 CPU environment):
echo 0 > /proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfs
I'll go with that and evaluate max memory usage as well, but this is still inviting us to consider other users interfacing areas with an implicated vmalloc and the scale of this as we grow number of CPU counts.
A magic values of 20 is completely empirical.
Luis
Quoted 2 lines · Luis Chamberlain
A magic values of 20 is completely empirical.
I suspect a magic value is fine in this context. I do not believe that "hundreds of concurrent module loads" is a valid real-life load. It sounds more like a "systemd does horrible things at startup".
20 sounds plenty big enough to me.
But I guess this is one of those "only real life will tell".
Linus
Quoted 37 lines · Luis Chamberlain
Quoted 9 lines · David Hildenbrand
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Luis Chamberlain
Quoted 5 lines · Luis Chamberlain
Quoted 1 line · David Hildenbrand
Not able to reproduce with 20230319-module-alloc-opts so far (2 tries).
Oh wow, so to clarify, it boots OK?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Now that we know that tree works, I'm curious also now if you can confirm just re-ordering the patches still works (it should)
So far no vmap errors booting the debug/kasan kernel (2 tries).
<-- snip -->
Quoted 10 lines
Quoted 10 lines
I think we primarily only care about systemd-udev-settle.service.
That is fastest without the rcu patch (~6s), compared to with the rcu patch (~6.5s) and with stock (~7.5s -- 8s).
Looks like dracut-initqueue also might be a bit faster with your changes, but maybe it's mostly noise (would have to do more runs).
So maybe drop that rcu patch? But of course, there could be other scenarios where it's helpful ...
Yes I confirm the RCU patch does not help at all now also using stress-ng.
Quoted 2 lines
Are there any other things you would like me to measure/test? I'll have to hand back that test machine soonish.
Quoted 11 lines
Yes please test the below. Perhaps its not the final form we want, but it *does* fix OOM'ing when thrashing with stress-ng now with the module option and even with 100 threads brings down max memory consumption by 259 MiB. The reason is that we also vmalloc during each
finit_read_file()for each module as well way before we even dolayout_and_allocate(), and so obviously if we fix the module path but not this path this will eventually catch up with us as. I'm not at all happy with the current approach given ideally we'd bump the counter when the user is done with the file, but we don't yet have any tracking of that for users, they just vfree the memory itself. And so this is just trying to catch heavy immediate abuse on the caller to fend off abuse of vmalloc uses in a lightway manner.
Understood. (I'm planning on review one I have time some spare cycles)
Quoted 8 lines
There's gotta be a better way to do this, but its just an idea I have so far. If we *want* to keep tabs until the user is done, we have to just modify most users of these APIs and intrudce our own free. I don't think we're in a rush to fix this so maybe that's the better approach.
And so I've managed to reproduce the issues you found now with my new stress-ng module stressor as well.
Nice!
Quoted 7 lines
https://github.com/ColinIanKing/stress-ng.git
Even though you have 400 CPUs with stress-ng we can likely reproduce it with (use a module not loaded on your system):
./stress-ng --module 100 --module-name xfs
I'll give that a churn on that machine with the updated patch ...
Quoted 4 lines
Without the patch below using 400 threads still OOMs easily due to the kread issue. Max threads allowed are 8192.
... do you have an updated patch/branch that includes the feedback from Linus so I can give it a churn tomorrow?
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 2 lines · David Hildenbrand
... do you have an updated patch/branch that includes the feedback from Linus so I can give it a churn tomorrow?
Yeah sure:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230327-module-alloc-opts
The commit log needs updateing to reflect the results I just collected:
With the alloc patch ("module: avoid allocation if module is already present and ready") I see 145 MiB in memory difference in comparison to its last patch, "module: extract patient module check into helper". So I think that's a clear keeper and should help large CPU count boots.
The patch "module: add concurrency limiter" which puts the concurency delimiter on the kread only saves about 2 MiB with 100 stress-ng ops, which seems to be what I needed to reproduce your 400 CPU count original issue.
The program used to reproduce is stress-ng with the new module option:
echo 0 > /proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfs
To see how much max memory I use, I just use:
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > foo.log
Run the test in another window, CTRL-C the test when above finishes after 40 seconds and then:
sort -n -r foo.log | head -1
If you have xfs loaded already you probably wanna pick module just as big that you don't have loaded. You must have dependencies loaded already as it doesn't call modprobe, it just finit_module's the module.
The last patch "modules/kmod: replace implementation with a sempahore" just takes Linus' simplification suggestion to replace kmod's solution. I tested it with:
tools/testing/selftests/kmod/kmod.sh -t 0008
This stress tests the kmod autoloading. Using time, the timing is similar, perhaps mildly slower, but I like the simplification. I'm still not happy with the "module: add concurrency limiter", specially it doesn't seem to really buy us much, 2 MiB seems like within noise. But stress-ng clearly shows it is a possible source of issue as we grow the ops. So it may make sense to just use the idea to replace the delimiter for kmod for now, unless you see different results.
The stress-ng module test can at least be used now to replicate insane setups at bootup.
Let me know if you get other useful results.
Luis
Quoted 8 lines · Luis Chamberlain
Quoted 2 lines · David Hildenbrand
... do you have an updated patch/branch that includes the feedback from Linus so I can give it a churn tomorrow?
Yeah sure:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230327-module-alloc-opts
I gave that one a go and get for system bootup:
#1:
13.761s tuned.service
12.261s chrony-wait.service
7.386s NetworkManager-wait-online.service
5.227s systemd-udev-settle.service
2.893s initrd-switch-root.service
2.148s polkit.service
2.137s smartd.service
1.893s dracut-initqueue.service
1.290s NetworkManager.service
1.032s cups.service
#2
13.881s tuned.service
9.255s chrony-wait.service
7.404s NetworkManager-wait-online.service
5.826s systemd-udev-settle.service
2.859s initrd-switch-root.service
2.847s smartd.service
2.172s polkit.service
1.884s dracut-initqueue.service
1.371s NetworkManager.service
1.119s ModemManager.service
So we're a bit faster (0.2 -- 0.7s) than the original version without the rcu patch (~6s).
Quoted 12 lines
The commit log needs updateing to reflect the results I just collected:
With the alloc patch ("module: avoid allocation if module is already present and ready") I see 145 MiB in memory difference in comparison to its last patch, "module: extract patient module check into helper". So I think that's a clear keeper and should help large CPU count boots.
The patch "module: add concurrency limiter" which puts the concurency delimiter on the kread only saves about 2 MiB with 100 stress-ng ops, which seems to be what I needed to reproduce your 400 CPU count original issue.
Quoted 4 lines
The program used to reproduce is stress-ng with the new module option:
echo 0 >
/proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfs
Above command fills for me with nfs (but also ext4) the kernel log with:
...
[ 883.036035] nfs: Unknown symbol xdr_reserve_space (err -2) [ 883.042221] nfs: Unknown symbol rpc_init_wait_queue (err -2) [ 883.048549] nfs: Unknown symbol put_rpccred (err -2) [ 883.054104] nfs: Unknown symbol __fscache_invalidate (err -2) [ 883.060540] nfs: Unknown symbol __fscache_use_cookie (err -2) [ 883.066969] nfs: Unknown symbol rpc_clnt_xprt_switch_has_addr (err -2) [ 883.074264] nfs: Unknown symbol __fscache_begin_write_operation (err -2) [ 883.081743] nfs: Unknown symbol nlmclnt_init (err -2) [ 883.087396] nfs: Unknown symbol nlmclnt_done (err -2) [ 883.093074] nfs: Unknown symbol nfs_debug (err -2) [ 883.098429] nfs: Unknown symbol rpc_wait_for_completion_task (err -2) [ 883.105640] nfs: Unknown symbol __fscache_acquire_cookie (err -2) [ 883.163764] nfs: Unknown symbol rpc_put_task (err -2) [ 883.169461] nfs: Unknown symbol __fscache_acquire_volume (err -2) [ 883.176297] nfs: Unknown symbol rpc_proc_register (err -2) [ 883.182430] nfs: Unknown symbol rpc_shutdown_client (err -2) [ 883.188765] nfs: Unknown symbol rpc_clnt_show_stats (err -2) [ 883.195097] nfs: Unknown symbol __fscache_begin_read_operation (err -2)
...
I do *not* get these errors on manual morprobe/rmmod. BUG in concurrent handling or just side-effect of the concurrent loading?
Quoted 9 lines
To see how much max memory I use, I just use:
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > foo.log
Run the test in another window, CTRL-C the test when above finishes after 40 seconds and then:
sort -n -r foo.log | head -1
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | head -1 14254024
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | tail -1 12862528
So 1391496 (KiB I assume, so 1.3 GiB !?) difference compared to before the test (I first start capturing and then run stress-ng).
Quoted 4 lines
If you have xfs loaded already you probably wanna pick module just as big that you don't have loaded. You must have dependencies loaded already as it doesn't call modprobe, it just finit_module's the module.
My setup already has xfs in use. nfs and ext4 are a bit smaller, but still big.
Signature · 3 lines
Thanks, David / dhildenb
Luis Chamberlain
maintainerQuoted 3 lines · David Hildenbrand
So we're a bit faster (0.2 -- 0.7s) than the original version without the rcu patch (~6s).
Groovy.
Quoted 38 lines
Quoted 12 lines
The commit log needs updateing to reflect the results I just collected:
With the alloc patch ("module: avoid allocation if module is already present and ready") I see 145 MiB in memory difference in comparison to its last patch, "module: extract patient module check into helper". So I think that's a clear keeper and should help large CPU count boots.
The patch "module: add concurrency limiter" which puts the concurency delimiter on the kread only saves about 2 MiB with 100 stress-ng ops, which seems to be what I needed to reproduce your 400 CPU count original issue.
Quoted 4 lines
The program used to reproduce is stress-ng with the new module option:
echo 0 >
/proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfsAbove command fills for me with nfs (but also ext4) the kernel log with:
...
[ 883.036035] nfs: Unknown symbol xdr_reserve_space (err -2) [ 883.042221] nfs: Unknown symbol rpc_init_wait_queue (err -2) [ 883.048549] nfs: Unknown symbol put_rpccred (err -2) [ 883.054104] nfs: Unknown symbol __fscache_invalidate (err -2) [ 883.060540] nfs: Unknown symbol __fscache_use_cookie (err -2) [ 883.066969] nfs: Unknown symbol rpc_clnt_xprt_switch_has_addr (err -2) [ 883.074264] nfs: Unknown symbol __fscache_begin_write_operation (err -2) [ 883.081743] nfs: Unknown symbol nlmclnt_init (err -2) [ 883.087396] nfs: Unknown symbol nlmclnt_done (err -2) [ 883.093074] nfs: Unknown symbol nfs_debug (err -2) [ 883.098429] nfs: Unknown symbol rpc_wait_for_completion_task (err -2) [ 883.105640] nfs: Unknown symbol __fscache_acquire_cookie (err -2) [ 883.163764] nfs: Unknown symbol rpc_put_task (err -2) [ 883.169461] nfs: Unknown symbol __fscache_acquire_volume (err -2) [ 883.176297] nfs: Unknown symbol rpc_proc_register (err -2) [ 883.182430] nfs: Unknown symbol rpc_shutdown_client (err -2) [ 883.188765] nfs: Unknown symbol rpc_clnt_show_stats (err -2) [ 883.195097] nfs: Unknown symbol __fscache_begin_read_operation (err -2)
Quoted 5 lines
...
I do *not* get these errors on manual morprobe/rmmod. BUG in concurrent handling or just side-effect of the concurrent loading?
It is just because modprobe deals with module dependencies, stress-ng modprobe doesn't, it just calls finit_module() and expects dependencies to be loaded first.
Quoted 7 lines
Quoted 7 lines
To see how much max memory I use, I just use:
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > foo.log
Run the test in another window, CTRL-C the test when above finishes after 40 seconds and then:
Quoted 8 lines
Quoted 1 line
sort -n -r foo.log | head -1
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | head -1 14254024
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | tail -1 12862528So 1391496 (KiB I assume, so 1.3 GiB !?)
That is sadly correct.
Quoted 2 lines
difference compared to before the
test (I first start capturing and then run stress-ng).
That's a good chunk :-D
On a recent thread I do a full analysis of average module sizes [0], you can use that to also get an average size estimate of your currently loaded modules. Do a bit of math and that could give you the average memory pressure on real vmap allocations. For a synthentic test as with stress-ng modules we'd be doing twice the memory for a success load, and only one time allocation due to kread for a failed allocation, since we always allocate memory even for bogus modules on the kread side.
My xfs.ko is 42M on my test guest system, with 100 concurrent threads doing two allocations each that puts the expected vmap allocation at around:
42*2*100
8400
8400/1024
8.20312500000000000000
8.2 GiB
So on the worst case that's what we'd see. Since I saw seeing the patches helped overall around 145 MiB in difference let's see what that means. Let me re-test:
Idle memory: (note free -k uses kibibytes, KiB.
root@kmod ~ # free -k -s 1 -c 3 | grep Mem | awk '{print $3}' | sort -n -r | head -1 416452
So while idle, the system is using up 416452 KiB, so 406 MiB.
While running stress-ng with 100 module ops
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > 2023-03-28-kmodsem-stress-ng-v1.txt echo 0 > /proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfs
root@kmod ~ # sort -n -r 2023-03-28-kmodsem-stress-ng-v1.txt | head -1 4886492
4886492/1024
4771.96484375000000000000
4886492/1024/1024
4.66012191772460937500
So during the stress test we see memory highest usage was about 4771.96 MiB or ~4.66 GiB.
What's the difference between idle and after the stress test:
4886492 - 416452
4470040
4470040/1024
4365.27343750000000000000
4470040/1024/1024
4.26296234130859375000
So about 4365.27 MiB or 4.26 GiB.
Now, the upper limit for the test should have been a delta of 8.2 GiB and we get about 4.26, so it means we're rejecting more than half of the requests. Why half not just half? I only see 40 successful loads of XFS during a 40 second window:
dmesg -c > /dev/null
# run tests dmesg -c | grep XFS | wc -l
At 100 ops all running finit_module for 40 seconds those successful loads only should have consumed about 40 * 2 * size of XFS (42 MiB):
3360 MiB or 3.28 GiB. But at any point in time only one module could be loaded at a time, so in the *worst* consumption point a XFS in this test should only be consuming 2*size_of_XFS(42 MiB) so 84 MiB.
4365.27 - 84
4281.27
So about 4281.27 MiB (4.18 GiB) are consumed by the 98.07% of the failed module loads due to the kread*() calls from finit_module().
And get this... *if* you use module compression that also uses vmap() *after* the kernel_read*() call which uses vmalloc(). *At least* in that case we immediately free the buffer for the compressed module, but *still* -- that is 3 possible vmap space allocations for every module!
It'd be hard, but not impossible to collect stats for failed finit_modules(). *That* could be indicative of areas in the kernel we need to brush up on to stop doing stupid things, like we learned about for the CPU frequency scaling modules. As I wrote this paragraph I realized -- that this *is* what we really have wanted all along to help us debug these stupid things, so we can slowly learn where to point fingers at to help optimize things. Altough I recently did some tool scraping to collect stats and *wished* for this from userspace [0], it wasn't hard to just a debug option for this to help us debug these failures. So I added support for that and sent finally a new patch series.
[0] https://lkml.kernel.org/r/CAB=NE6UTC4VkNM57GGJ3XkG_PWLkMfXv2e2=yQJhtM6Fc-uMsQ@mail.gmail.com
Quoted 6 lines
Quoted 3 lines
If you have xfs loaded already you probably wanna pick module just as big that you don't have loaded. You must have dependencies loaded already as it doesn't call modprobe, it just finit_module's the module.
My setup already has xfs in use. nfs and ext4 are a bit smaller, but still big.
Sure.
Luis
Quoted 6 lines · Luis Chamberlain
Quoted 3 lines · David Hildenbrand
So we're a bit faster (0.2 -- 0.7s) than the original version without the rcu patch (~6s).
Groovy.
Just to clarify, it was up to 0.7s faster (I phrased it in a confusing way).
Quoted 42 lines
Quoted 42 lines
Quoted 13 lines
The commit log needs updateing to reflect the results I just collected:
With the alloc patch ("module: avoid allocation if module is already present and ready") I see 145 MiB in memory difference in comparison to its last patch, "module: extract patient module check into helper". So I think that's a clear keeper and should help large CPU count boots.
The patch "module: add concurrency limiter" which puts the concurency delimiter on the kread only saves about 2 MiB with 100 stress-ng ops, which seems to be what I needed to reproduce your 400 CPU count original issue.
Quoted 4 lines
The program used to reproduce is stress-ng with the new module option:
echo 0 >
/proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfsAbove command fills for me with nfs (but also ext4) the kernel log with:
...
[ 883.036035] nfs: Unknown symbol xdr_reserve_space (err -2) [ 883.042221] nfs: Unknown symbol rpc_init_wait_queue (err -2) [ 883.048549] nfs: Unknown symbol put_rpccred (err -2) [ 883.054104] nfs: Unknown symbol __fscache_invalidate (err -2) [ 883.060540] nfs: Unknown symbol __fscache_use_cookie (err -2) [ 883.066969] nfs: Unknown symbol rpc_clnt_xprt_switch_has_addr (err -2) [ 883.074264] nfs: Unknown symbol __fscache_begin_write_operation (err -2) [ 883.081743] nfs: Unknown symbol nlmclnt_init (err -2) [ 883.087396] nfs: Unknown symbol nlmclnt_done (err -2) [ 883.093074] nfs: Unknown symbol nfs_debug (err -2) [ 883.098429] nfs: Unknown symbol rpc_wait_for_completion_task (err -2) [ 883.105640] nfs: Unknown symbol __fscache_acquire_cookie (err -2) [ 883.163764] nfs: Unknown symbol rpc_put_task (err -2) [ 883.169461] nfs: Unknown symbol __fscache_acquire_volume (err -2) [ 883.176297] nfs: Unknown symbol rpc_proc_register (err -2) [ 883.182430] nfs: Unknown symbol rpc_shutdown_client (err -2) [ 883.188765] nfs: Unknown symbol rpc_clnt_show_stats (err -2) [ 883.195097] nfs: Unknown symbol __fscache_begin_read_operation (err -2)...
Quoted 6 lines
Quoted 2 lines
I do *not* get these errors on manual morprobe/rmmod. BUG in concurrent handling or just side-effect of the concurrent loading?
It is just because modprobe deals with module dependencies, stress-ng modprobe doesn't, it just calls
finit_module()and expects dependencies to be loaded first.
Oh, right. That makes sense.
Quoted 99 lines
Quoted 8 lines
Quoted 8 lines
To see how much max memory I use, I just use:
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > foo.log
Run the test in another window, CTRL-C the test when above finishes after 40 seconds and then:
Quoted 8 lines
Quoted 1 line
sort -n -r foo.log | head -1
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | head -1 14254024
[root@lenovo-sr950-01 fs]# sort -n -r foo.log | tail -1 12862528So 1391496 (KiB I assume, so 1.3 GiB !?)
That is sadly correct.
Quoted 2 lines
difference compared to before the
test (I first start capturing and then run stress-ng).That's a good chunk :-D
On a recent thread I do a full analysis of average module sizes [0], you can use that to also get an average size estimate of your currently loaded modules. Do a bit of math and that could give you the average memory pressure on real vmap allocations. For a synthentic test as with stress-ng modules we'd be doing twice the memory for a success load, and only one time allocation due to kread for a failed allocation, since we always allocate memory even for bogus modules on the kread side.
My xfs.ko is 42M on my test guest system, with 100 concurrent threads doing two allocations each that puts the expected vmap allocation at around:
42*2*100
8400
8400/1024
8.203125000000000000008.2 GiB
So on the worst case that's what we'd see. Since I saw seeing the patches helped overall around 145 MiB in difference let's see what that means. Let me re-test:
Idle memory: (note free -k uses kibibytes, KiB.
root@kmod ~ # free -k -s 1 -c 3 | grep Mem | awk '{print $3}' | sort -n -r | head -1 416452
So while idle, the system is using up 416452 KiB, so 406 MiB.
While running stress-ng with 100 module ops
free -k -s 1 -c 40 | grep Mem | awk '{print $3}' > 2023-03-28-kmodsem-stress-ng-v1.txt echo 0 >
/proc/sys/vm/oom_dump_tasks
./stress-ng --module 100 --module-name xfs
root@kmod ~ # sort -n -r 2023-03-28-kmodsem-stress-ng-v1.txt | head -1 48864924886492/1024
4771.96484375000000000000
4886492/1024/1024
4.66012191772460937500So during the stress test we see memory highest usage was about 4771.96 MiB or ~4.66 GiB.
What's the difference between idle and after the stress test:
4886492 - 416452
4470040
4470040/1024
4365.27343750000000000000
4470040/1024/1024
4.26296234130859375000So about 4365.27 MiB or 4.26 GiB.
Now, the upper limit for the test should have been a delta of 8.2 GiB and we get about 4.26, so it means we're rejecting more than half of the requests. Why half not just half? I only see 40 successful loads of XFS during a 40 second window:
dmesg -c >
/dev/null# run tests dmesg -c | grep XFS | wc -lAt 100 ops all running
finit_modulefor 40 seconds those successful loads only should have consumed about 40 * 2 * size of XFS (42 MiB):
3360 MiB or 3.28 GiB. But at any point in time only one module could be loaded at a time, so in the *worst* consumption point a XFS in this test should only be consuming 2*size_of_XFS(42 MiB) so 84 MiB.4365.27 - 84
4281.27
Quoted 8 lines
So about 4281.27 MiB (4.18 GiB) are consumed by the 98.07% of the failed module loads due to the kread*() calls from
finit_module().And get this... *if* you use module compression that also uses
vmap()*after* the kernel_read*() call which usesvmalloc(). *At least* in that case we immediately free the buffer for the compressed module, but *still* -- that is 3 possible vmap space allocations for every module!
:/
Quoted 12 lines
It'd be hard, but not impossible to collect stats for failed
finit_modules(). *That* could be indicative of areas in the kernel we need to brush up on to stop doing stupid things, like we learned about for the CPU frequency scaling modules. As I wrote this paragraph I realized -- that this *is* what we really have wanted all along to help us debug these stupid things, so we can slowly learn where to point fingers at to help optimize things. Altough I recently did some tool scraping to collect stats and *wished* for this from userspace [0], it wasn't hard to just a debug option for this to help us debug these failures. So I added support for that and sent finally a new patch series.
Makes sense to me.
I didn't have time to look at the code yet (currently traveling), I hope that the kasan vmap issues are at least history.
I'll do another test with debug kernels using your latest version on that machine before I have to hand it back.
Thanks!
Signature · 3 lines
Thanks, David / dhildenb