platform/upstream/kmod.git
5 months agoAdd /lib/modules/modprobe.d to configuration search path accepted/tizen_base accepted/tizen_base_asan accepted/tizen_base_riscv tizen_base accepted/tizen/base/20231108.225818 accepted/tizen/base/asan/20240422.014939 accepted/tizen/base/riscv/20231123.094516
Karol Lewandowski [Thu, 8 Jul 2021 10:35:38 +0000 (12:35 +0200)]
Add /lib/modules/modprobe.d to configuration search path

This commit adds additional tizen-specific /lib/modules/modprobe.d
to kmod search path to allow for packages providing modules to also
provide its configuration.

In Tizen kernel and modules images are build separately from "platform"
image, meaning only limited paths can be used (/lib/modules, /hal) for
its files to be accessible from the system.

Change-Id: I6985339abd1234aecfb5802484bd57f36a64bab2
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
5 months agoadd packaging for kmod
Seung-Woo Kim [Mon, 24 Feb 2020 00:51:57 +0000 (09:51 +0900)]
add packaging for kmod

Add kmod v31 package to Tizen for supporting program to manage
Linux Kernel modules.

Note: Change history for previous Tizen package release is below:

kmod is packaged into Tizen with manifest domain of floor.
v15 is a required dependency for systemd v208 (see TIVI-2197).

Bump to v18 using upstream git repo instead of pristin-tar.
Bug-Tizen: TC-1921

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Alexandru Cornea <alexandru.cornea@intel.com>
Signed-off-by: Patrick McCarty <patrick.mccarty@linux.intel.com>
Signed-off-by: Kévin THIERRY <kevin.thierry@open.eurogiciel.org>
Applied ASLR (CFLAG=-fPIE LDFLAG=-pie) and license file wsa added to
/usr/share/licenses/kmod-compat and /usr/share/licneses/libkmod.

All packaging modifications are squashed into one commit and
bump to v24.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
[yj99.shin@samsung.com: packaging : disable %check section
  Currently, all tizen OBS projects don't run the %check section.
  I think the %check section is very good for reinforcing unit tests.
  But, there are some hurdles because of the qemu.
  For starting of enabling the %check section, I disable the %check section in the failed packages.]
Change-Id: Icdbea83b1625446abe492625ee424f25e377c476
Signed-off-by: Youngjae Shin <yj99.shin@samsung.com>
[sw0312.kim: bump version to v31 for Tizen 9.0
  bump version to v30 for Tizen 8.0
  Add kmod v29 package to Tizen 7.0 M1
  bump version to v27 for Tizen 6.5
  packaging: remove not really necessary kmod own includedir
  bump version to v27 for Tizen 6.0
  packaging: add -Wno-maybe-uninitialized to cflags and bump to v26
    The GCC has false positive warning about maybe-uninitialized with
    -O2 and -fexeceptions. Add -Wno-maybe-uninitialized to cflags to
    remove the false positive warnings.
]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
7 months agokmod 31 upstream v31
Lucas De Marchi [Fri, 29 Sep 2023 14:18:37 +0000 (09:18 -0500)]
kmod 31

7 months agolibkmod: add fallback MODULE_INIT_COMPRESSED_FILE define
Emil Velikov [Wed, 27 Sep 2023 15:38:05 +0000 (16:38 +0100)]
libkmod: add fallback MODULE_INIT_COMPRESSED_FILE define

The symbol was somewhat recently introduced by the kernel and not all
distributions may be have available.

The number is part of the ABI, so we can add a local fallback define.

Closes: https://github.com/kmod-project/kmod/issues/29
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 months agolibkmod: Use kernel decompression when available
Lucas De Marchi [Thu, 1 Jun 2023 22:40:01 +0000 (15:40 -0700)]
libkmod: Use kernel decompression when available

With the recent changes to bypass loading the file it's possible to
reduce the work in userspace and delegating it to the kernel. Without
any compression to illustrate:

Before:
read(3, "\177ELF\2\1", 6)               = 6
lseek(3, 0, SEEK_SET)                   = 0
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=238592, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 238592, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd85cbd1000
finit_module(3, "", 0)                  = 0
munmap(0x7fd85cbd1000, 238592)          = 0
close(3)                                = 0

After:
read(3, "\177ELF\2\1", 6)               = 6
lseek(3, 0, SEEK_SET)                   = 0
finit_module(3, "", 0)                  = 0
close(3)                                = 0

When using kernel compression now it's also possible to direct libkmod
to take the finit_module() path, avoiding the decompression in userspace
and just delegating it to the kernel.

Before:
read(3, "(\265/\375\244\0", 6)          = 6
lseek(3, 0, SEEK_SET)                   = 0
read(3, "(\265/\375\244", 5)            = 5
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa431e000
read(3, "\0\244\3\0\\y\6", 7)           = 7
mmap(NULL, 372736, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fa414f000
brk(0x55944c6a1000)                     = 0x55944c6a1000
read(3, "\356|\6G\27U\20 \312\260s\211\335\333\263\326\330\336\273O\211\356\306K\360Z\341\374U6\342\221"..., 53038) = 53038
mremap(0x7f3fa431e000, 135168, 266240, MREMAP_MAYMOVE) = 0x7f3fa410e000
read(3, ",;\3\nqf\311\362\325\211\7\341\375A\355\221\371L\\\5\7\375 \32\246<(\258=K\304"..., 20851) = 20851
mremap(0x7f3fa410e000, 266240, 397312, MREMAP_MAYMOVE) = 0x7f3fa40ad000
read(3, ")\36\250\213", 4)              = 4
read(3, "", 4)                          = 0
munmap(0x7f3fa414f000, 372736)          = 0
init_module(0x7f3fa40ad010, 238592, "") = 0
munmap(0x7f3fa40ad000, 397312)          = 0
close(3)                                = 0

After:
read(3, "(\265/\375\244P", 6)           = 6
lseek(3, 0, SEEK_SET)                   = 0
finit_module(3, "", 0x4 /* MODULE_INIT_??? */) = 0
close(3)                                = 0

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 months agolibkmod: Keep track of in-kernel compression support
Lucas De Marchi [Thu, 1 Jun 2023 22:40:00 +0000 (15:40 -0700)]
libkmod: Keep track of in-kernel compression support

When creating the context, read /sys/kernel/compression to check what's
the compression type supported by the kernel. This will later be used
when loading modules to check if the decompression step has to happen in
userspace or if it can be delegated to the kernel.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 months agolibkmod: Keep track of compression type
Lucas De Marchi [Thu, 1 Jun 2023 22:39:59 +0000 (15:39 -0700)]
libkmod: Keep track of compression type

Do not only set the type as direct, but also keep track of the
compression being used. This will allow using the in-kernel compression
in future.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 months agolibkmod: Extract finit_module vs init_module paths
Lucas De Marchi [Thu, 1 Jun 2023 22:39:58 +0000 (15:39 -0700)]
libkmod: Extract finit_module vs init_module paths

Extract 2 functions to handle finit_module vs init_modules differences,
with a fallback from the former to the latter.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
10 months agolibkmod: Do not inititialize file->memory on open
Lucas De Marchi [Thu, 1 Jun 2023 22:39:57 +0000 (15:39 -0700)]
libkmod: Do not inititialize file->memory on open

Add a separate function to load the file contents when it's needed.
When it's not needed on the path of loading modules via finit_module(),
there is no need to mmap the file. This will help support loading
modules with the in-kernel compression support.

This is done differently than the lazy initialization for
kmod_file_get_elf() because on the contents case there is also the
file->size to be updated. It would be a weird API to return the pointer
and have the size changed as a side-effect.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: avoid passing {NULL, 0} array to bsearch()
Dmitry Antipov [Fri, 19 May 2023 07:41:08 +0000 (10:41 +0300)]
shared: avoid passing {NULL, 0} array to bsearch()

Fix the following warning reported by UBSan (as of gcc-13.1.1):

shared/hash.c:244:35: runtime error: null pointer passed as
argument 2, which is declared to never be null

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
[ reshuffle the code to use return-early style ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agolibkmod: fix possible out-of-bounds memory access
Dmitry Antipov [Fri, 19 May 2023 07:46:38 +0000 (10:46 +0300)]
libkmod: fix possible out-of-bounds memory access

An attempt to pass too long module name to, say, rmmod, may
cause an out-of-bounds memory access (as repoted by UBSan):

$ rmmod $(for i in $(seq 0 4200); do echo -ne x; done)
libkmod/libkmod-module.c:1828:8: runtime error: index 4107 out of bounds for type 'char [4096]'

This is because 'snprintf(path, sizeof(path), ...)' may return the
value which exceeds 'sizeof(path)' (which happens when an output
gets truncated). To play it safe, such a suspicious output is
better to be rejected explicitly.

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://lore.kernel.org/r/20230519074638.402045-1-dmantipov@yandex.ru
11 months agolibkmod, depmod: prefer -ENODATA over -ENOENT if no section found
Dmitry Antipov [Fri, 19 May 2023 09:36:30 +0000 (12:36 +0300)]
libkmod, depmod: prefer -ENODATA over -ENOENT if no section found

When the module is definitely present but CONFIG_MODVERSIONS is
disabled, the following error message may be somewhat confusing:

modprobe --dump-modversions /path/to/module.ko.xz
modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No such file or directory

Choosing among the convenient errno values, I would suggest to use
ENODATA when the module lacks a particular ELF section (and vermagic
as well). So now it is expected to be:

modprobe: FATAL: could not get modversions of /path/to/module.ko.xz: No data available

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://lore.kernel.org/r/20230519093630.474185-1-dmantipov@yandex.ru
12 months agomodprobe: rmmod_do_module: Free kmod list of holders
Nicolas Schier [Tue, 18 Apr 2023 08:52:38 +0000 (10:52 +0200)]
modprobe: rmmod_do_module: Free kmod list of holders

Add a missing kmod_module_unref_list() to fix a memory leak.

Fixes: 42b32d30c38e ("modprobe: Fix holders removal")
Signed-off-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agoconfigure.ac: fix link with -llzma
Fabrice Fontaine [Thu, 2 Mar 2023 17:54:26 +0000 (18:54 +0100)]
configure.ac: fix link with -llzma

Add liblzma_LIBS to LIBS to avoid the following build failure when
building with a static-only liblzma.a:

/home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/11.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: libkmod/.libs/libkmod-internal.a(libkmod-file.o):(.text.xz_uncompress+0x10): undefined reference to `lzma_code'

For consistency, also update libzstd, zlib and libcrypto

Fixes:
 - http://autobuild.buildroot.org/results/83a4a7ecc77f39639d3e5bc8554bd01a62a3ede0

References: https://github.com/kmod-project/kmod/pull/25
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agoconfigure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES
Emil Velikov [Tue, 21 Feb 2023 13:19:29 +0000 (13:19 +0000)]
configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES

Replace the manual sed command, build rules and dist/clean for using
AC_CONFIG_FILES. It does the exact same thing, with an added bonus...

Currently we're missing version.py.in in the EXTRA_DIST. Thus a simple
"touch Makefile" should retrigger the regeneration of version.py. Which
would presumably fail, since the input file isn't in the distribution
tarball.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agoshared: annotate local API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:28 +0000 (13:19 +0000)]
shared: annotate local API as static

None of the API is used outside of the compilation unit.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agolibkmod: annotate kmod_builtin_iter API as static
Emil Velikov [Tue, 21 Feb 2023 13:19:27 +0000 (13:19 +0000)]
libkmod: annotate kmod_builtin_iter API as static

It's no longer used outside the compilation unit, as of last commit.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agolibkmod: remove unused kmod_module_get_builtin
Emil Velikov [Tue, 21 Feb 2023 13:19:26 +0000 (13:19 +0000)]
libkmod: remove unused kmod_module_get_builtin

The last and only user was removed with commit 0246e06 ("depmod: Stop
opening modules.modinfo once per module")

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: Handle different sysconfdir
Lucas De Marchi [Thu, 9 Feb 2023 19:19:46 +0000 (11:19 -0800)]
testsuite: Handle different sysconfdir

Instead of skipping tests if sysconfdir isn't /etc, just handle it
during the rootfs setup logic.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
14 months agotestsuite: Move setup-rootfs logic from Makefile to script
Lucas De Marchi [Thu, 9 Feb 2023 19:19:45 +0000 (11:19 -0800)]
testsuite: Move setup-rootfs logic from Makefile to script

It's easier to implement the logic outside of the Makefile, so rename
the populate-modules.sh script to setup-rootfs.sh and move the
additional logic from the makefile to the script.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
14 months agolibkmod: error out on unknown hash algorithm
Emil Velikov [Mon, 6 Feb 2023 14:32:59 +0000 (14:32 +0000)]
libkmod: error out on unknown hash algorithm

Currently if we see unknown algorithm, we'll do an OOB read in
pkey_hash_algo. This can happen for example if OPENSSL_NO_SM3 is set and
the kernel module uses a SM3 hash.

Cc: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite/depmod: use defines for the rootfs/lib_modules
Emil Velikov [Mon, 6 Feb 2023 14:04:49 +0000 (14:04 +0000)]
testsuite/depmod: use defines for the rootfs/lib_modules

The uname used across the tests is same, so drop "_ORDER" from the macro
name and use it throughout. Similarly - add respective LIB_MODULES
defines and use them in the tests.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: add function declarations for __xstat family
Emil Velikov [Mon, 6 Feb 2023 14:04:47 +0000 (14:04 +0000)]
testsuite: add function declarations for __xstat family

As the inline comment says - the declarations have been dropped with
glibc 2.32.9000, as a result the build throws a set of lovely warnings.

Inspired by umockdev, which bears the same license as this project.
https://github.com/martinpitt/umockdev/commit/f1b416400479d861deffb4c5a40422dcdf190e85

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotreewide: add some static const notations
Emil Velikov [Mon, 6 Feb 2023 14:04:46 +0000 (14:04 +0000)]
treewide: add some static const notations

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agodepmod: Introduce outdir option
Emil Velikov [Mon, 6 Feb 2023 13:18:34 +0000 (13:18 +0000)]
depmod: Introduce outdir option

This option is equivalent to basedir, with the small difference being
that's where the meta-data files are generated. In other words, this
allows us to have read-only input modules and modules.dep, while still
being able to generate the meta-data files.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Move files to a different dir so input files (produced by kernel build
  system is separate from the files generated by depmod (output) ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
14 months agoman/rmmod: explain why modprobe -r is more useful
Yauheni Kaliuta [Thu, 2 Feb 2023 13:47:36 +0000 (15:47 +0200)]
man/rmmod: explain why modprobe -r is more useful

Improve user experience by explaining the option so the user may
not search explanations in other manpages (modprobe).

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agomodprobe: Allow passing path to module
Gustavo Sousa [Fri, 13 Jan 2023 21:37:45 +0000 (18:37 -0300)]
modprobe: Allow passing path to module

This is useful to kernel module developers for testing a just compiled
module: instead of using insmod, they can load the module from the path
while getting all the benefits of modprobe (e.g. module dependency
resolution).

v2:
  - Add test for relative path as well. (Lucas)
  - Add note warning about modules with dependencies not matching the
    installed depmod database. (Lucas)

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agomodprobe: Move insertion block into separate function
Gustavo Sousa [Fri, 13 Jan 2023 21:37:44 +0000 (18:37 -0300)]
modprobe: Move insertion block into separate function

That same logic will be used for enabling modprobe for paths in the next
patch. As such, prepare for that by extracting that block into its own
function.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agotestsuite: Wrap chdir()
Gustavo Sousa [Fri, 13 Jan 2023 21:37:43 +0000 (18:37 -0300)]
testsuite: Wrap chdir()

One of the tests in an upcoming patch will need to change into a
specific directory to test loading a module from a relative path.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
16 months agokmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit
Florian Weimer [Sat, 17 Dec 2022 16:52:34 +0000 (17:52 +0100)]
kmod: configure.ac: In _Noreturn check, include <stdlib.h> for exit

Otherwise, an implicit functiona declaration is used, causing
a C99 compatibility issue.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agoautogen.sh: remove --with-rootprefix, it is gone since kmod-11
Adam Gołębiowski [Mon, 28 Nov 2022 09:05:31 +0000 (10:05 +0100)]
autogen.sh: remove --with-rootprefix, it is gone since kmod-11

Signed-off-by: Adam Gołębiowski <adamg@pld-linux.org>
19 months agolibkmod: do not crash on unknown signature algorithm
Mikhail Novosyolov [Sun, 25 Sep 2022 14:46:08 +0000 (17:46 +0300)]
libkmod: do not crash on unknown signature algorithm

Example kernel module:
https://file-store.rosalinux.ru/download/7281f97e0c04c0f818ad3f936706f4a407e8dc7e
(/lib/modules/5.15.67-generic-1rosa2021.1-x86_64/kernel/drivers/usb/host/xhci-pci.ko.zst)
It is signed with Streebog 512.

libkmod v30 crashed in libkmod-module.c:2413 in this code:

n = kmod_module_info_append(list,
"sig_hashalgo", strlen("sig_hashalgo"),
sig_info.hash_algo, strlen(sig_info.hash_algo));

because strlen() got null.

20 months agotestsuite: fix override of `stat` on 32-bit architectures
Julien Cristau [Mon, 5 Sep 2022 08:32:12 +0000 (10:32 +0200)]
testsuite: fix override of `stat` on 32-bit architectures

When _FILE_OFFSET_BITS is 64, glibc headers turn `stat` calls into
`stat64`, and our `stat` override into a `stat64` function.  However,
because we use dlsym to get the address of libc's `stat`, we end up
calling into the "real" `stat` function, which deals with 32-bit off_t,
and we treat its result as if it were returned from stat64.  On most
architectures this seems to have been harmless, but on 32-bit mips,
st_mode's offset in struct stat and struct stat64 are different, so we
read garbage.

To fix this, explicitly unset _FILE_OFFSET_BITS in path.c, to turn off
the redirect magic in glibc headers, and override both the 32-bit and
64-bit functions so each call ends up wrapping the right libc function.

Fixes #16 (https://github.com/kmod-project/kmod/issues/16)

22 months agomodprobe: Write error messages to syslog if stderr is unavailable
Quentin Armitage [Fri, 19 Nov 2021 18:33:49 +0000 (18:33 +0000)]
modprobe: Write error messages to syslog if stderr is unavailable

The man page modprobe(8) states for the --syslog option:
"This is also automatically enabled when stderr is unavailable."
but it wasn't happening.

This commit now makes modprobe write to syslog if stderr is closed.

22 months agobuild: enable building & running tests from a subdir
Dimitri John Ledkov [Thu, 24 Jun 2021 13:53:56 +0000 (14:53 +0100)]
build: enable building & running tests from a subdir

During dpkg build, in a subdir, it is currently not possible to run
tests. Building testsuite/modules due to non-existance of the
testsuite directory under the build dir. Thus create it, when it is
not there.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
22 months agotestsuite: repair read of uninitialized memory
Jan Engelhardt [Thu, 30 Jun 2022 16:47:25 +0000 (18:47 +0200)]
testsuite: repair read of uninitialized memory

Function ``test_backoff_time`` does not initialize ``delta``, and
``get_backoff_delta_msec`` then performs a read from uninitialized
memory with the ``!*delta`` expression.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agokmod 30 v30
Lucas De Marchi [Thu, 30 Jun 2022 15:19:17 +0000 (08:19 -0700)]
kmod 30

22 months agolibkmod: Support SM3 hash algorithm
HuaxinLu [Thu, 30 Jun 2022 06:36:05 +0000 (14:36 +0800)]
libkmod: Support SM3 hash algorithm

SM3 has been supported in kernel and cryptographic libraries like openssl.
This patch adds support for the SM3 algorithm of kmod.

Signed-off-by: HuaxinLu <luhuaxin1@huawei.com>
22 months agoREADME: Update optional dependencies
Lucas De Marchi [Wed, 29 Jun 2022 05:24:41 +0000 (22:24 -0700)]
README: Update optional dependencies

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agoKeep only one readme
Lucas De Marchi [Wed, 29 Jun 2022 05:23:34 +0000 (22:23 -0700)]
Keep only one readme

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agomodprobe: Add --wait
Lucas De Marchi [Fri, 3 Jun 2022 21:50:47 +0000 (14:50 -0700)]
modprobe: Add --wait

Retry module removal if it fails due to EAGAIN. This allows user to pass
--wait <timeout>, during which `modprobe -r` will keep trying to remove
the module.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agotestsuite: Add tests for sleep calculation
Lucas De Marchi [Fri, 3 Jun 2022 21:50:46 +0000 (14:50 -0700)]
testsuite: Add tests for sleep calculation

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agoutil: Add exponential backoff sleep
Lucas De Marchi [Fri, 3 Jun 2022 21:50:45 +0000 (14:50 -0700)]
util: Add exponential backoff sleep

Add simple functions to put the current thread to sleep using
exponential backoff to split the interval in smaller pieces.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agoutil: Add msec variants for time-related functions
Lucas De Marchi [Fri, 3 Jun 2022 21:50:44 +0000 (14:50 -0700)]
util: Add msec variants for time-related functions

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agoutil: Add time-related functions from testsuite
Lucas De Marchi [Fri, 3 Jun 2022 21:50:43 +0000 (14:50 -0700)]
util: Add time-related functions from testsuite

This will be useful in future not only to testsuite, but also to tools
and library.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agomodule-playground: Add debugfs entry in mod-simple
Lucas De Marchi [Fri, 3 Jun 2022 21:50:42 +0000 (14:50 -0700)]
module-playground: Add debugfs entry in mod-simple

Add a debugfs file in mod-simple for manual tests: insert the module and
open the file to have its refcount increased.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agolibkmod: Allow to ignore log message on module removal
Lucas De Marchi [Fri, 3 Jun 2022 21:50:41 +0000 (14:50 -0700)]
libkmod: Allow to ignore log message on module removal

Caller may want to handle retries, in which case the log message is not
appropriate.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agomodprobe: Move -R to "Query options"
Lucas De Marchi [Fri, 3 Jun 2022 21:50:40 +0000 (14:50 -0700)]
modprobe: Move -R to "Query options"

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agomodprobe: re-use modname variable
Lucas De Marchi [Fri, 3 Jun 2022 20:49:02 +0000 (13:49 -0700)]
modprobe: re-use modname variable

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
22 months agodepmod: Fix writing over array length
Lucas De Marchi [Fri, 3 Jun 2022 20:49:01 +0000 (13:49 -0700)]
depmod: Fix writing over array length

Make sure return value in flush_stream_to() is the length written
if the value didn't the size. Fix warning on gcc 12.1:

tools/depmod.c: In function ‘output_builtin_alias_bin’:
tools/depmod.c:2465:24: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds]
 2465 |                 modname[len] = '\0';
      |                 ~~~~~~~^~~~~
tools/depmod.c:2460:22: note: while referencing ‘modname’
 2460 |                 char modname[PATH_MAX];
      |                      ^~~~~~~
tools/depmod.c:2477:22: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds]
 2477 |                 value[len] = '\0';
      |                 ~~~~~^~~~~
tools/depmod.c:2461:22: note: while referencing ‘value’
 2461 |                 char value[PATH_MAX];
      |                      ^~~~~

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2 years agomodprobe: Make rmmod_do_module() contain all the removal sequence
Lucas De Marchi [Tue, 29 Mar 2022 09:05:40 +0000 (02:05 -0700)]
modprobe: Make rmmod_do_module() contain all the removal sequence

Move the remaining part of the removal sequence dangling in
rmmod_do_remove_module() to rmmod_do_module() so we can consider this
function is the one controlling all the module removals.

While at it, add some comments about the removal order and normalize
coding style in this function.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agomodprobe: move check for remove_holders to caller
Lucas De Marchi [Tue, 29 Mar 2022 09:05:39 +0000 (02:05 -0700)]
modprobe: move check for remove_holders to caller

Do not mix the flags with and additional boolean from arguments.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agomodprobe: Fix holders removal
Lucas De Marchi [Tue, 29 Mar 2022 09:05:37 +0000 (02:05 -0700)]
modprobe: Fix holders removal

The idea behind --remove-dependencies was to remove other modules that
depend on the current module being removed. It's the reverse
dependency list, not the dependency list of the current module: that
never works since the current module would still hold a ref on it.

Fix it by replacing the call to kmod_module_get_dependencies() with
kmod_module_get_holders() when using that option. Also try to cleanup
the confusion by renaming the option to --remove-holders: "holder" is
the name used in sysfs and by libkmod to refer to a "live" reverse
dependency like what we are interested in.

Before:
./tools/modprobe -D -r --remove-dependencies video
rmmod video

After:
./tools/modprobe -D -r --remove-holders video
rmmod i915
rmmod thinkpad_acpi
rmmod video

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agomodprobe: remove unneeded variable str_start
Masahiro Yamada [Thu, 10 Feb 2022 02:14:23 +0000 (11:14 +0900)]
modprobe: remove unneeded variable str_start

The variable 'str_start' is not useful here.

Replace it with 'str'.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agomodprobe: fix the NULL-termination of new_argv
Masahiro Yamada [Thu, 10 Feb 2022 02:14:22 +0000 (11:14 +0900)]
modprobe: fix the NULL-termination of new_argv

The number of new arguments is (i + argc - 1) as it is set to *p_argc
one line below.

The correct location of NULL termination is new_argv[i + argc - 1].

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agodepmod: Add support for excluding a directory
Saul Wold [Thu, 31 Mar 2022 21:56:28 +0000 (14:56 -0700)]
depmod: Add support for excluding a directory

This adds support to depmod to enable a new exclude directive in
the depmod.d/*.conf configuration file. Currently depmod
already excludes directories named source or build. This change
will allow additional directories like .debug to be excluded also
via a new exclude directive.

depmod.d/exclude.conf example:
exclude .debug

Signed-off-by: Saul Wold <saul.wold@windriver.com>
[ Fix warnings and make should_exclude_dir() return bool ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agomodprobe: Rename rmmod_do_deps_list
Lucas De Marchi [Tue, 29 Mar 2022 06:55:03 +0000 (23:55 -0700)]
modprobe: Rename rmmod_do_deps_list

It's used not only for dependencies, but also for pre and post softdep.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agodocs: Add missing functions to documentation
Lucas De Marchi [Thu, 3 Mar 2022 08:57:10 +0000 (00:57 -0800)]
docs: Add missing functions to documentation

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agolibkmod: Fix use of sizeof instead of ARRAY_SIZE
Lucas De Marchi [Wed, 23 Feb 2022 18:19:13 +0000 (10:19 -0800)]
libkmod: Fix use of sizeof instead of ARRAY_SIZE

Link: https://github.com/kmod-project/kmod/issues/12
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agomodinfo: Allow to force arg as module name
Lucas De Marchi [Wed, 16 Feb 2022 07:36:49 +0000 (23:36 -0800)]
modinfo: Allow to force arg as module name

If the Linux kernel or userspace sets an alias with the same name as a
module, they force the tools to use that. However in some situations it
may be desired to query the module itself. Getting the module
information through modinfo is one such situation. So, add a option to
modinfo to explicitly instruct it to handle the argument as a module
name.

Example, when trying to output information about the crc32 module that
is builtin:

$ modinfo crc32
filename:       /lib/modules/5.15.19-1-MANJARO/kernel/arch/x86/crypto/crc32-pclmul.ko.zst
alias:          crypto-crc32-pclmul
alias:          crc32-pclmul
alias:          crypto-crc32
alias:          crc32
license:        GPL
author:         Alexander Boyko <alexander_boyko@xyratex.com>
srcversion:     B6B2FF9236731E69418A2E5
alias:          cpu:type:x86,ven*fam*mod*:feature:*0081*
depends:
retpoline:      Y
intree:         Y
name:           crc32_pclmul
vermagic:       5.15.19-1-MANJARO SMP preempt mod_unload
sig_id:         PKCS#7
signer:         Build time autogenerated kernel key
sig_key:        77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37
sig_hashalgo:   sha512
signature:      30:65:02:31:00:B0:D4:49:9D:1D:F1:71:4C:3C:BB:70:B2:3E:46:5D:
38:5A:F1:00:95:FD:7A:96:C4:2C:24:35:A2:1B:0B:A8:1C:29:6F:02:
7A:68:EE:BA:A4:1C:01:4B:86:39:15:3E:66:02:30:7F:7A:66:5E:F2:
2F:98:73:3D:AD:96:66:81:8B:94:6E:F3:3F:44:0F:85:E1:73:3A:9E:
F9:C4:BE:9B:88:02:BD:83:04:B9:2E:72:0B:93:BC:82:B6:A1:1B:6A:
C2:ED:8C
filename:       /lib/modules/5.15.19-1-MANJARO/kernel/crypto/crc32_generic.ko.zst
alias:          crypto-crc32-generic
alias:          crc32-generic
alias:          crypto-crc32
alias:          crc32
license:        GPL
description:    CRC32 calculations wrapper for lib/crc32
author:         Alexander Boyko <alexander_boyko@xyratex.com>
srcversion:     F08036C38DDB06BCD1E6091
depends:
retpoline:      Y
intree:         Y
name:           crc32_generic
vermagic:       5.15.19-1-MANJARO SMP preempt mod_unload
sig_id:         PKCS#7
signer:         Build time autogenerated kernel key
sig_key:        77:FB:AA:BD:48:78:A4:C6:56:18:9A:7E:A6:F3:29:3E:C5:6B:E9:37
sig_hashalgo:   sha512
signature:      30:65:02:31:00:E3:9E:C8:80:15:0E:D7:74:96:B5:25:EA:32:F7:DF:
E9:FC:3C:82:D9:B9:B9:37:C5:20:8D:06:31:02:62:B3:54:E8:DF:F2:
7E:E2:7C:A4:CF:49:17:CB:75:DF:2C:7A:2F:02:30:25:DE:7C:2A:2C:
97:3F:65:16:76:B3:71:FB:62:DB:8F:F3:33:65:77:98:F3:57:ED:D7:
87:78:FF:C2:04:55:70:00:10:63:1E:B2:FE:22:D8:E5:6D:5F:95:4E:
7D:2C:6B

That is because the Linux kernel exports "crc32" as an alias to those modules,
besides being a module itself:

$ grep crc32 /lib/modules/$(uname -r)/modules.builtin
kernel/lib/crc32.ko
$ $ grep "alias crc32 " /lib/modules/$(uname -r)/modules.alias
alias crc32 crc32_pclmul
alias crc32 crc32_generic

With the new -m|--modname option it's possible to query the information about this (builtin)
module explicitly:

$ modinfo --modname crc32
name:           crc32
filename:       (builtin)
license:        GPL
file:           lib/crc32
description:    Various CRC32 calculations
author:         Matt Domsch <Matt_Domsch@dell.com>

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agomodinfo: Update help message with "modulename"
Lucas De Marchi [Wed, 16 Feb 2022 07:16:33 +0000 (23:16 -0800)]
modinfo: Update help message with "modulename"

man page correctly states the a module name can be used in place of a
file name:

modinfo [-0] [-F field] [-k kernel] [modulename|filename...]

Update the help message accordingly.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agolibkmod: Add lookup from module name
Lucas De Marchi [Wed, 16 Feb 2022 07:10:58 +0000 (23:10 -0800)]
libkmod: Add lookup from module name

Slightly different than kmod_module_new_from_lookup(): it doesn't
consider aliases, only module names. This is useful for cases we want to
force a tool to handle something as the module name, without trying to
interpret it as an alias.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agolibkmod: Update docs about indexes order
Lucas De Marchi [Wed, 16 Feb 2022 06:47:06 +0000 (22:47 -0800)]
libkmod: Update docs about indexes order

New indexes were created without updating the documentation about the
order in kmod_module_new_from_lookup(). Add them to the documentation.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agolibkmod: Add helper function to iterate lookup options
Lucas De Marchi [Wed, 16 Feb 2022 03:12:05 +0000 (19:12 -0800)]
libkmod: Add helper function to iterate lookup options

The CHECK_ERR_AND_FINISH macro with conditional code flow changes has
been a source of bugs. Get rid of it replacing with a helper function
to iterate an array of lookup functions. This helper may also be useful
in future to create different lookup APIs in libkmod.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agogitignore: ignore gtk-doc.make
Lucas De Marchi [Wed, 16 Feb 2022 01:28:53 +0000 (17:28 -0800)]
gitignore: ignore gtk-doc.make

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agolibkmod-module: Fix return code for kmod_module_new_from_lookup()
Lucas De Marchi [Tue, 15 Feb 2022 22:09:14 +0000 (14:09 -0800)]
libkmod-module: Fix return code for kmod_module_new_from_lookup()

When kmod_module_new_from_lookup() resolves to an alias, `err` will be
set to a positive value from the lookup function. Do not return a
positive value to follow the behavior when it matches a module name
and the documentation.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agotest-initstate: Check for negative value on error
Lucas De Marchi [Tue, 15 Feb 2022 22:05:13 +0000 (14:05 -0800)]
test-initstate: Check for negative value on error

Documentation says kmod_module_new_from_lookup() returns < 0 on error
and 0 otherwise. There are bugs in libkmod however making it return
a positive value in some situations, that need to be fixed. However
it's best to check for the error explicitly like is done in the rest
of the library to avoid this kind of issues.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2 years agodepmod: Stop opening modules.modinfo once per module
Lucas De Marchi [Thu, 10 Feb 2022 02:07:03 +0000 (18:07 -0800)]
depmod: Stop opening modules.modinfo once per module

Since the addition of modules.aliases.bin, depmod has to open that
index multiple times and parse it over and over again:

$ sudo strace -e openat  ./tools/depmod 2>&1 | grep modules.builtin.modinfo  | wc -l
299
$ time sudo  ./tools/depmod
real    0m7.814s
user    0m7.571s
sys     0m0.237s

Rework the logic in depmod so it does everything: open, read and parse. The
format is very straightforward and we don't need to keep it in a data structure
since we only want to add the result to a index. New output:

$ sudo strace -e openat  ./tools/depmod 2>&1 | grep modules.builtin.modinfo  | wc -l
1
$ time sudo  ./tools/depmod
real    0m7.663s
user    0m7.516s
sys     0m0.139s

Indexes still match:

$ cmp /tmp/modules.builtin.alias.bin.new
/tmp/modules.builtin.alias.bin.old; echo $?
0

Fix: https://github.com/kmod-project/kmod/issues/11

2 years agodepmod: Do not duplicate builtin index
Lucas De Marchi [Thu, 10 Feb 2022 02:46:34 +0000 (18:46 -0800)]
depmod: Do not duplicate builtin index

Now that libkmod uses modules.builtin.bin again, we don't need to add
the module names in modules.builtin.alias.bin and just add the aliases.

After this change, here are the new sizes for the indexes:

Before After index
21k 6.4K modules.builtin.alias.bin
11k  11K modules.builtin.bin

2 years agolibkmod: Prefer builtin index over builtin.alias
Lucas De Marchi [Thu, 10 Feb 2022 02:21:03 +0000 (18:21 -0800)]
libkmod: Prefer builtin index over builtin.alias

The modules.builtin.alias.bin is way larger than the
modules.builtin.bin.  On a normal "distro kernel":

21k modules.builtin.alias.bin
11k modules.builtin.bin

From the kernel we get both modules.builtin and modules.builtin.modinfo.
depmod generates modules.builtin.bin and modules.builtin.alias.bin
from them respectively. modules.bultin is not going away: it's not
deprecated by the new index added. So, let's just stop duplicating the
information inside modules.builtin.alias.bin and just use the other
index.

2 years agolibkmod: Set builtin to no when module is created from path.
Michal Suchanek [Wed, 18 Aug 2021 20:52:00 +0000 (22:52 +0200)]
libkmod: Set builtin to no when module is created from path.

A recent bug report showed that modinfo doesn't give the signature
information for certain modules, and it turned out to happen only on
the modules that are built-in on the running kernel; then modinfo
skips the signature check, as if the target module file never exists.
The behavior is, however, inconsistent when modinfo is performed for
external modules (no matter which kernel version is) and the module
file path is explicitly given by a command-line argument, which
guarantees the presence of the module file itself.

Fixes: e7e2cb61fa9f ("modinfo: Show information about built-in modules")
Link: https://lore.kernel.org/linux-modules/CAKi4VAJVvY3=JdSZm-GD1hJqyCPYaYz-jBJ_REeY5BakVb6_ww@mail.gmail.com/
BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1189537
Suggested-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2 years agolibkmod: add a library notice log level print
Luis Chamberlain [Tue, 10 Aug 2021 05:16:00 +0000 (22:16 -0700)]
libkmod: add a library notice log level print

When you use pass the -v argument to modprobe we bump
the log level from the default modprobe log level of
LOG_WARNING (4) to LOG_NOTICE (5), however the library
only has avaiable to print:

 #define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
 #define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
 #define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)

LOG_INFO (6) however is too high of a level for it to be
effective at printing anything when modprobe -v is passed.
And so the only way in which modprobe -v can trigger the
library to print a verbose message is to use ERR() but that
always prints something and we don't want that in some
situations.

We need to add a new log level macro which uses LOG_NOTICE (5)
for a "normal but significant condition" which users and developers
can use to look underneath the hood to confirm if a situation is
happening.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2 years agolibkmod-module: check "new_from_name" return value in get_builtin
Yauheni Kaliuta [Tue, 8 Jun 2021 06:29:22 +0000 (09:29 +0300)]
libkmod-module: check "new_from_name" return value in get_builtin

kmod_module_new_from_name() may fail and return error value. It is
handled properly across the code, but in this particular place the
check is missing.

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2 years agokmod 29 v29
Lucas De Marchi [Thu, 20 May 2021 23:02:57 +0000 (16:02 -0700)]
kmod 29

2 years agotestsuite: update gitignore
Lucas De Marchi [Tue, 11 May 2021 16:57:10 +0000 (09:57 -0700)]
testsuite: update gitignore

2 years agodepmod: fix modules.builtin.alias.bin output
Lucas De Marchi [Tue, 11 May 2021 16:48:04 +0000 (09:48 -0700)]
depmod: fix modules.builtin.alias.bin output

Due to wrong documentation on kmod_module_get_info() we ended up
checking for 0 as return. Check for > 0 to decided if we want to write
the index to the file, otherwise we would output a 0-sized index on
success.

2 years agoFix return value doc for kmod_module_get_info()
Lucas De Marchi [Tue, 11 May 2021 16:47:09 +0000 (09:47 -0700)]
Fix return value doc for kmod_module_get_info()

We don't return 0 on success, we return the number of elements we added
to the list.

3 years agolibkmod: fix possible double free with wrong modules.builtin.modinfo
Seung-Woo Kim [Tue, 13 Apr 2021 11:23:15 +0000 (20:23 +0900)]
libkmod: fix possible double free with wrong modules.builtin.modinfo

Fix double free for *modinfo with non '\0' terminated wrong
modules.builtin.modinfo, which is because EOF is minus value.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
3 years agolibkmod: fix an overflow with wrong modules.builtin.modinfo
Seung-Woo Kim [Tue, 13 Apr 2021 11:23:14 +0000 (20:23 +0900)]
libkmod: fix an overflow with wrong modules.builtin.modinfo

Fix a possbile overflow with exact PATH_MAX length modname
in wrong modules.builtin.modinfo.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
3 years agogitignore: ignore .mbx and .cover for b4 integration
Lucas De Marchi [Sat, 17 Apr 2021 20:39:12 +0000 (13:39 -0700)]
gitignore: ignore .mbx and .cover for b4 integration

Lately I'm using b4 to work with the patches in the mailing list. Better
to start ignoring .cover and .mbx files since they get created by b4.

3 years agolibkmod-config: fix a memory leak when kmod_list_append() fails
Seung-Woo Kim [Fri, 9 Apr 2021 09:44:23 +0000 (18:44 +0900)]
libkmod-config: fix a memory leak when kmod_list_append() fails

From kmod_config_new(), when kmod_list_append() fails,
fix not list-appended kmod_config_path leak.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
3 years agolibkmod-config: more chars allowed as space
Lucas De Marchi [Wed, 10 Mar 2021 16:33:01 +0000 (08:33 -0800)]
libkmod-config: more chars allowed as space

Recently in a discussion I noticed that kernel allows more chars to be
considered as space in the kernel command line. Switch to the equivalent
of isspace() instead of considering only ' '.

3 years agotest-modprobe: share single function for kcmdline tests
Lucas De Marchi [Fri, 12 Feb 2021 09:45:24 +0000 (01:45 -0800)]
test-modprobe: share single function for kcmdline tests

3 years agotestsuite: allow to re-use single function for tests
Lucas De Marchi [Fri, 12 Feb 2021 09:45:23 +0000 (01:45 -0800)]
testsuite: allow to re-use single function for tests

Add a new DEFINE_TEST_WITH_FUNC() that accepts the function
alongside the test name. This will allow us to share a single function
for different tests.

3 years agolibkmod-config: re-quote option from kernel cmdline
Lucas De Marchi [Fri, 12 Feb 2021 09:45:22 +0000 (01:45 -0800)]
libkmod-config: re-quote option from kernel cmdline

It was reported that grub mangles the kernel cmdline. It turns

acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf"

into

"acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf"

However, even though we could blame grub for doing that, the kernel
happily accepts and re-quotes it when the module is built-in.
So, it's better if kmod also understands it this way and does the same.

Here we basically add additional code to un-mangle it, moving the quote
in way that is acceptable to pass through init_module(). Note that the
interface [f]init_module() gives us mandates the quote to be part of the
value: the module name is not passed and the options are separated by
space.

Reported-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Jessica Yu <jeyu@kernel.org>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
3 years agolibkmod-config: revamp kcmdline parsing into a state machine
Lucas De Marchi [Fri, 12 Feb 2021 09:45:21 +0000 (01:45 -0800)]
libkmod-config: revamp kcmdline parsing into a state machine

The handling of spaces and quotes is becoming hard to maintain. Convert
the parser into a state machine so we can check all the states. This
should make it easier to fix a corner case we have right now:
The kernel also accepts a quote before the module name instead of the
value. But this additional is left for later. This is purely an
algorithm change with no behavior change.

Tested-by: Jessica Yu <jeyu@kernel.org>
3 years agotestsuite: also test xz compression
Lucas De Marchi [Sat, 30 Jan 2021 02:34:30 +0000 (18:34 -0800)]
testsuite: also test xz compression

Reviewed-by: Petr Vorel <pvorel@suse.cz>
3 years agotestsuite: compress modules if feature is enabled
Lucas De Marchi [Sat, 30 Jan 2021 02:28:38 +0000 (18:28 -0800)]
testsuite: compress modules if feature is enabled

Since the output needs to be the same, regardless if the module is
compressed, change populate-modules.sh to conditionally compress the
module if that feature is enabled.

This way we can execute the tests with any build-time configuration and
it should still pass.

Suggested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Michal Suchánek <msuchanek@suse.de>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
3 years agopopulate-modules: Use more bash, more quotes
Dave Reisner [Wed, 25 Mar 2020 15:03:58 +0000 (11:03 -0400)]
populate-modules: Use more bash, more quotes

We're already using associatives arrays, so there's no reason we should
be using 'test'.

3 years agoREADME: make github mirror official
Lucas De Marchi [Thu, 21 Jan 2021 02:50:33 +0000 (18:50 -0800)]
README: make github mirror official

For some time I've been maintaining a read-only mirror on github.
I think it's time to allow patches flowing from there besides the
mailing list: I created a new org to host the project:

https://github.com/kmod-project/kmod

3 years agoSupport /usr/local for configuration files
Lucas De Marchi [Tue, 19 Jan 2021 02:22:31 +0000 (18:22 -0800)]
Support /usr/local for configuration files

Add /usr/local to the search path for configuration files. These are
intended for local installs, provided /usr/local is given as prefix.

3 years agodepmod: fix precedence order
Lucas De Marchi [Tue, 19 Jan 2021 02:13:25 +0000 (18:13 -0800)]
depmod: fix precedence order

Configuration in /etc should have higher prio than /run.
Given how rarely configuration in /run is used with depmod, this is
likely not to cause any problems, even if it's a change in behavior.

3 years agolibkmod: Fix documentation on config precedence order
Lucas De Marchi [Tue, 19 Jan 2021 02:05:09 +0000 (18:05 -0800)]
libkmod: Fix documentation on config precedence order

/etc is has higher priority than /run.

3 years agoFix "modinfo -F always shows name for built-ins"
Marco d'Itri [Fri, 8 Jan 2021 04:17:48 +0000 (20:17 -0800)]
Fix "modinfo -F always shows name for built-ins"

Bug reported by Ben Hutchings <ben@decadent.org.uk>:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970871

Now that the kernel provides module information for potentially
modular code that's actually built-in, it's possible to query these
built-ins with "modinfo -F".  However, this doesn't work quite right:

$ modinfo -Flicense e1000e
GPL v2
$ modinfo -Flicense bitrev
name:           bitrev
GPL

3 years agoREADME: remove leftover from semaphoreci
Lucas De Marchi [Fri, 8 Jan 2021 03:51:40 +0000 (19:51 -0800)]
README: remove leftover from semaphoreci

We are not currently using semaphoreci, so remove leftover status from
README.

3 years agotestsuite: Automatically skip tests that fail when sysconfdir != /etc.
Marius Bakke [Sat, 1 Aug 2020 16:02:22 +0000 (18:02 +0200)]
testsuite: Automatically skip tests that fail when sysconfdir != /etc.

3 years agotestsuite: Add facility to skip tests.
Marius Bakke [Sat, 1 Aug 2020 16:02:21 +0000 (18:02 +0200)]
testsuite: Add facility to skip tests.

The Makefile helpfully warns that some tests will fail when
--sysconfdir != /etc, but there are no provisions to easily disable
those.  This commit provides an escape hatch.

[ Lucas: add comment detailing the purpose of the field ]

3 years agokmod 28 v28
Lucas De Marchi [Thu, 7 Jan 2021 18:43:36 +0000 (10:43 -0800)]
kmod 28

3 years agobuild: add comment with rules for libtool version update
Lucas De Marchi [Thu, 7 Jan 2021 18:26:12 +0000 (10:26 -0800)]
build: add comment with rules for libtool version update

3 years agobuild: fix distcheck due to missing zstd
Lucas De Marchi [Mon, 28 Dec 2020 01:00:43 +0000 (17:00 -0800)]
build: fix distcheck due to missing zstd

Enable zstd since it's used in the testsuite.