2021-01-11 14:24:17

by Jessica Yu

[permalink] [raw]
Subject: Re: Linux Kernel module notification bug

+++ Adam Zabrocki [10/01/21 18:54 +0100]:
>Hello,
>
>I believe that the following commit does introduce a gentle "functionality
>bug":
>
>"module: delay kobject uevent until after module init call":
>https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/kernel/module.c?id=38dc717e97153e46375ee21797aa54777e5498f3
>
>The official Linux Kernel API for the kernel module activities notification has
>been divided based on the readiness 'stage' for such module. We have the
>following stages:
>
> MODULE_STATE_LIVE, /* Normal state. */
> MODULE_STATE_COMING, /* Full formed, running module_init. */
> MODULE_STATE_GOING, /* Going away. */
> MODULE_STATE_UNFORMED, /* Still setting it up. */
>
>LIVE means that the kernel module is correctly running and all initialization
>work has been already done. Otherwise, we have event 'COMING' or 'UNFORMED'.
>
>In the described commit, creation of the KOBJECT has been moved after invoking
>a notficiation of the newly formed kernel module state (LIVE). That's somehow
>inconsistent from my understanding of the kernel modules notifiers logic.
>Creation of the new objects (like KOBJ) should be done before notification of
>the stage LIVE is invoked.

I'm confused. We're not creating any kobjects here. That is all done
in mod_sysfs_setup(), which is called while the module is still
COMING. What that commit does is delay telling userspace about the
module (specifically, systemd/udev) until the module is basically
ready. Systemd was basically receiving the uevent too early, before
the module has initialized, hence we decided to delay the uevent [1].

>This commit breaks some of the projects that rely on the LIVE notification to
>monitor when the newly loaded module is ready.

Hm, could you please explain specifically what is the issue you're seeing?
What projects is it breaking?

Thanks,

Jessica

[1] https://github.com/systemd/systemd/issues/17586