Modules updates for v5.11

Summary of modules changes for the 5.11 merge window:

- Fix a race condition between systemd/udev and the module loader.
  The module loader was sending a uevent before the module was fully
  initialized (i.e., before its init function has been called). This means
  udev can start processing the module uevent before the module has
  finished initializing, and some udev rules expect that the module has
  initialized already upon receiving the uevent. This resulted in some
  systemd mount units failing if udev processes the event faster than the
  module can finish init. This is fixed by delaying the uevent until after
  the module has called its init routine.

- Make the linker array sections for kernel params and module version
  attributes more robust by switching to use the alignment of the type in
  question. Namely, linker section arrays will be constructed using the
  alignment required by the struct (using __alignof__()) as opposed to a
  specific value such as sizeof(void *) or sizeof(long). This is less
  likely to cause breakages should the size of the type ever change (from
  Johan Hovold)

- Fix module state inconsistency by setting it back to GOING when a module
  fails to load and is on its way out (from Miroslav Benes)

- Some comment and code cleanups (from Sergey Shtylyov)

Signed-off-by: Jessica Yu <jeyu@kernel.org>
module: delay kobject uevent until after module init call

Apparently there has been a longstanding race between udev/systemd and
the module loader. Currently, the module loader sends a uevent right
after sysfs initialization, but before the module calls its init
function. However, some udev rules expect that the module has
initialized already upon receiving the uevent.

This race has been triggered recently (see link in references) in some
systemd mount unit files. For instance, the configfs module creates the
/sys/kernel/config mount point in its init function, however the module
loader issues the uevent before this happens. sys-kernel-config.mount
expects to be able to mount /sys/kernel/config upon receipt of the
module loading uevent, but if the configfs module has not called its
init function yet, then this directory will not exist and the mount unit
fails. A similar situation exists for sys-fs-fuse-connections.mount, as
the fuse sysfs mount point is created during the fuse module's init
function. If udev is faster than module initialization then the mount
unit would fail in a similar fashion.

To fix this race, delay the module KOBJ_ADD uevent until after the
module has finished calling its init routine.

References: https://github.com/systemd/systemd/issues/17586
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-By: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
1 file changed