1

I am loading a kernel module at boot time, I added it to a config file in /etc/modules-load.d/, the module is loading correctly.

In my module I am using the wait_for_random_bytes() function from linux/random.h, so my module can have some delay in loading.

The modules are loaded sequentially? This module of mine can delay the loading of other modules? Thanks!

0

What the OS does ?

In my Debian (but i would bet that your CentOS just do the same), the module loading part of initialization is done by /etc/init.d/kmod.

Below is an extract of this script:

files=$(modules_files)
if [ "$files" ] ; then
  grep -h '^[^#]' $files |
  while read module args; do
    [ "$module" ] || continue
    load_module "$module" "$args"
  done
fi

Where:

  • modules_files is a shell function that parses various file and directories (including /etc/modules-load.d) and built a list of modules to be loaded.

  • load_module is a shell function that do the modprobe work + some logging if verbose flag is set.

So i would say that yes, modules are loaded sequentially and if one blocks, then it will block the other ones....

but ...

 What kernel does ?

When reading the source code of linux/modules.c we can see that:

  • The syscall is probably implemented by the function load_module(). We can see that it performs a lot of stuff (initialization, memory allocation, sanity checks, signature checks, etc..) and it returns with return do_init_module(mod); (line 3927

  • The do_init_module() function do at line 3574 the following operation and, if everything went ok, return 0.

    if (mod->init != NULL)
        ret = do_one_initcall(mod->init);
    if (ret < 0) {
        goto fail_free_freeinit;
    }

My conclusion is the syscall will return only when: 1. The module has been loaded in memory. 2. Its init() function has ran successfully.

So if your call to wait_for_random_bytes() is part of the init function of your module, then yes, it may block others modules loading.

  • Thank you for the very detailed answer! – Miso Mijatovic Nov 21 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.