Commit Graph

3 Commits

Author SHA1 Message Date
Donald Dutile a27f75beb4 module: add debugging auto-load duplicate module support
JIRA: https://issues.redhat.com/browse/RHEL-28063

commit 8660484ed1cf3261e89e0bad94c6395597e87599
Author: Luis Chamberlain <mcgrof@kernel.org>
Date:   Thu Apr 13 22:28:39 2023 -0700

    module: add debugging auto-load duplicate module support

    The finit_module() system call can in the worst case use up to more than
    twice of a module's size in virtual memory. Duplicate finit_module()
    system calls are non fatal, however they unnecessarily strain virtual
    memory during bootup and in the worst case can cause a system to fail
    to boot. This is only known to currently be an issue on systems with
    larger number of CPUs.

    To help debug this situation we need to consider the different sources for
    finit_module(). Requests from the kernel that rely on module auto-loading,
    ie, the kernel's *request_module() API, are one source of calls. Although
    modprobe checks to see if a module is already loaded prior to calling
    finit_module() there is a small race possible allowing userspace to
    trigger multiple modprobe calls racing against modprobe and this not
    seeing the module yet loaded.

    This adds debugging support to the kernel module auto-loader (*request_module()
    calls) to easily detect duplicate module requests. To aid with possible bootup
    failure issues incurred by this, it will converge duplicates requests to a
    single request. This avoids any possible strain on virtual memory during
    bootup which could be incurred by duplicate module autoloading requests.

    Folks debugging virtual memory abuse on bootup can and should enable
    this to see what pr_warn()s come on, to see if module auto-loading is to
    blame for their wores. If they see duplicates they can further debug this
    by enabling the module.enable_dups_trace kernel parameter or by enabling
    CONFIG_MODULE_DEBUG_AUTOLOAD_DUPS_TRACE.

    Current evidence seems to point to only a few duplicates for module
    auto-loading. And so the source for other duplicates creating heavy
    virtual memory pressure due to larger number of CPUs should becoming
    from another place (likely udev).

    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:26 -04:00
Donald Dutile a1da4498e3 modules/kmod: replace implementation with a semaphore
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflicts: RHEL9 does not have upstrema 48380368dec148 which
           changed DEFINE_SEMAPHORE to take a number argument.
	   Implement the RHEL9 single arg version that open-codes
	   the initialization.

commit 25a1b5b518f4336bff934ac8348da6c57158363a
Author: Luis Chamberlain <mcgrof@kernel.org>
Date:   Fri Mar 24 18:38:00 2023 -0700

    modules/kmod: replace implementation with a semaphore

    Simplify the concurrency delimiter we use for kmod with the semaphore.
    I had used the kmod strategy to try to implement a similar concurrency
    delimiter for the kernel_read*() calls from the finit_module() path
    so to reduce vmalloc() memory pressure. That effort didn't provide yet
    conclusive results, but one thing that became clear is we can use
    the suggested alternative solution with semaphores which Linus hinted
    at instead of using the atomic / wait strategy.

    I've stress tested this with kmod test 0008:

    time /data/linux-next/tools/testing/selftests/kmod/kmod.sh -t 0008

    And I get only a *slight* delay. That delay however is small, a few
    seconds for a full test loop run that runs 150 times, for about ~30-40
    seconds. The small delay is worth the simplfication IMHO.

    Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:25 -04:00
Donald Dutile ccf1cf0a34 module: fold usermode helper kmod into modules directory
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflict: Dropped MAINTAINERS hunk because it wouldn't apply cleanly
          and not needed.

commit 25be451aa4c0e9a96c59a626ab0e93d5cb7f6f48
Author: Luis Chamberlain <mcgrof@kernel.org>
Date:   Sun Mar 19 14:35:42 2023 -0700

    module: fold usermode helper kmod into modules directory

    The kernel/kmod.c is already only built if we enabled modules, so
    just stuff it under kernel/module/kmod.c and unify the MAINTAINERS
    file for it.

    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:24 -04:00