]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
11 months agolibkmod: Fix memory leak on error path
Tobias Stoeckmann [Wed, 21 Aug 2024 20:06:58 +0000 (22:06 +0200)] 
libkmod: Fix memory leak on error path

If realloc fails, do not override the still valid pointer with NULL.
Otherwise freeing the iterator won't free the previously allocated
buffer.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/82
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: use proper data types in freadline_wrapped
Tobias Stoeckmann [Tue, 20 Aug 2024 20:52:41 +0000 (22:52 +0200)] 
shared: use proper data types in freadline_wrapped

Do not use signed data types if unsigned arithmetic is expected,
i.e. use size_t if processing sizes and unsigned int for line numbers
due to given API of freadline_wrapped.

This fixes a possible signed integer overflow on 64 bit systems.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/81
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: bump codespell-project/actions-codespell in the all-actions group
dependabot[bot] [Mon, 19 Aug 2024 01:29:51 +0000 (01:29 +0000)] 
ci: bump codespell-project/actions-codespell in the all-actions group

Bumps the all-actions group with 1 update: [codespell-project/actions-codespell](https://github.com/codespell-project/actions-codespell).

Updates `codespell-project/actions-codespell` from 2.0 to 2.1
- [Release notes](https://github.com/codespell-project/actions-codespell/releases)
- [Commits](https://github.com/codespell-project/actions-codespell/compare/94259cd8be02ad2903ba34a22d9c13de21a74461...406322ec52dd7b488e48c1c4b82e2a8b3a1bf630)

---
updated-dependencies:
- dependency-name: codespell-project/actions-codespell
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/80
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agodepmod: Remove unneeded check
Tobias Stoeckmann [Fri, 16 Aug 2024 21:54:57 +0000 (23:54 +0200)] 
depmod: Remove unneeded check

Calling free(NULL) is valid. No need for previous if-check.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/79
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoVerify absolute path creation
Tobias Stoeckmann [Fri, 16 Aug 2024 21:49:18 +0000 (23:49 +0200)] 
Verify absolute path creation

If a relative path is supplied, the conversion to an absolute path can
fail, e.g. if current working directory does not exist anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/79
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: Add Debian with --disable-test-modules
Lucas De Marchi [Fri, 16 Aug 2024 13:57:27 +0000 (08:57 -0500)] 
ci: Add Debian with --disable-test-modules

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/78
11 months agobuild: Set AM_DISTCHECK_CONFIGURE_FLAGS
Lucas De Marchi [Fri, 16 Aug 2024 19:01:22 +0000 (14:01 -0500)] 
build: Set AM_DISTCHECK_CONFIGURE_FLAGS

Follow the usual approach for flags in autotools: Set the AM_ variant
so the user may set the non-AM variant that is appended. This is needed
to pass additional flags from the configure to the configure call done
while creating the dist tarball if something doesn't match the default.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/78
11 months agobuild: Add mod-weakdep.ko to cache
Lucas De Marchi [Fri, 16 Aug 2024 13:41:11 +0000 (08:41 -0500)] 
build: Add mod-weakdep.ko to cache

A long forgotten feature of the build system: we commit the built
modules from playground so distros can build without linux-headers
available.

Cc: Marco d'Itri <md@linux.it>
Closes: https://lore.kernel.org/linux-modules/Zr3A96SfR21UjdL1@bongo.bofh.it
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/78
11 months agoci: add weekly scheduled runs
Emil Velikov [Fri, 16 Aug 2024 15:46:41 +0000 (16:46 +0100)] 
ci: add weekly scheduled runs

The toolchain and dependencies can be updated, flagging new warning
and/or errors. Schedule a weekly run, to flag those.

Otherwise, we easily end with a new PR which is flagged as problematic,
due to pre-existing issues.

Currently it triggers on Sun at 2:30am

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: use read-only workflow tokens
Emil Velikov [Fri, 16 Aug 2024 15:41:28 +0000 (16:41 +0100)] 
ci: use read-only workflow tokens

Seemingly the defaults are write-all, which means the action can push
pages, accept PRs and others.

This is another suggestion I've seen by the GOSST folks.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: use hash-pinned workflow actions, update checkout
Emil Velikov [Fri, 16 Aug 2024 15:19:38 +0000 (16:19 +0100)] 
ci: use hash-pinned workflow actions, update checkout

The tags are mutable and groups like Google Open Source Security Team
(GOSST) are suggesting use of hash-pinned (alongside the tag as comment)
actions.

The dependabot just introduced, can handle the format automatically.

Ref: https://github.com/libarchive/libarchive/issues/1959
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: add dependabot.yml
Emil Velikov [Fri, 16 Aug 2024 13:48:35 +0000 (14:48 +0100)] 
ci: add dependabot.yml

It's a scheduled action, which checks if any of the actions used are out
of date. If so, it will open a PR with a summary of the changes in the
new version.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: add codespell action
Emil Velikov [Fri, 16 Aug 2024 13:45:53 +0000 (14:45 +0100)] 
ci: add codespell action

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoAddress all codespell (flagged) typos
Emil Velikov [Fri, 16 Aug 2024 13:28:11 +0000 (14:28 +0100)] 
Address all codespell (flagged) typos

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months ago.codespellignore: add ignore file
Emil Velikov [Fri, 16 Aug 2024 13:22:12 +0000 (14:22 +0100)] 
.codespellignore: add ignore file

The codespell tool miss-detects a few instances as typos. Namely:
 - tar caf -> it suggests calf ;-)
 - parm (module params) -> param

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months ago.editorconfig: add initial config file
Emil Velikov [Fri, 16 Aug 2024 13:39:57 +0000 (14:39 +0100)] 
.editorconfig: add initial config file

Most editors support the config format out of the box and with some
upcoming new yml files, I think it's great to have something in-tree to
avoid miss-matched style.

Copy-pasted from Mesa, with minor changes - tab for indent (C), remove
irrelevant sections. Keep the meson section - meson patches will be
comings shortly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/76
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: Rename test-user
Lucas De Marchi [Fri, 16 Aug 2024 04:17:11 +0000 (23:17 -0500)] 
testsuite: Rename test-user

First version of the patches implementing weakdep called them "user
dep", hence the name of the test. That doesn't make sense anymore after
the rename.  Rename the test accordingly.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/75
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: unify array trim handling
Tobias Stoeckmann [Tue, 13 Aug 2024 17:51:24 +0000 (19:51 +0200)] 
shared: unify array trim handling

An error during array_realloc is always ignored if the idea
was to save memory by trimming an array.

Move two occurrences of same code into a single function for
easier reviewing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/68
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: Add defensive measures to array handling
Tobias Stoeckmann [Tue, 13 Aug 2024 17:44:48 +0000 (19:44 +0200)] 
shared: Add defensive measures to array handling

- Make sure that SIZE_MAX boundaries are never crossed
- Clear pointer address in struct during array_free_array
- Do nothing if array_pop is called with empty array

Also added test case for pop behavior and extended tests with
more checks.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/68
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: switch array API to size_t
Tobias Stoeckmann [Tue, 13 Aug 2024 17:36:46 +0000 (19:36 +0200)] 
shared: switch array API to size_t

The position in array_remove_at could be theoretically larger
than unsigned int. Switch to size_t to stay in sync with all
other such arguments in array context.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/68
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agodepmod: Handle array memory issues
Tobias Stoeckmann [Tue, 13 Aug 2024 17:33:00 +0000 (19:33 +0200)] 
depmod: Handle array memory issues

If array operations fail, forward the error instead of silently
ignoring it and continuing the operation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/68
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agodepmod: Improve P argument check
Tobias Stoeckmann [Wed, 14 Aug 2024 15:52:18 +0000 (17:52 +0200)] 
depmod: Improve P argument check

The command line option P takes one argument, which is supposed to
contain exactly one character. The current check performs an out
of boundary read if an empty string is supplied.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/73
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agodepmod: Fix out of boundary write with long paths
Tobias Stoeckmann [Wed, 14 Aug 2024 15:40:40 +0000 (17:40 +0200)] 
depmod: Fix out of boundary write with long paths

If a root path is specified which is PATH_MAX - 1 characters long
and option -A is specified, then depfile_up_to_date_dir triggers
an out of boundary write during slash addition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: fix path for test-user
Christian Hesse [Wed, 14 Aug 2024 07:58:16 +0000 (09:58 +0200)] 
testsuite: fix path for test-user

... as this just does not find its paths.

Closes: https://github.com/kmod-project/kmod/issues/69
Fixes: 9d1fb31 ("libkmod, depmod, modprobe: Make directory for kernel modules configurable")
Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoFix typos
Tobias Stoeckmann [Tue, 13 Aug 2024 17:20:12 +0000 (19:20 +0200)] 
Fix typos

Typos found with codespell.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agokmod 33 v33
Lucas De Marchi [Tue, 13 Aug 2024 17:14:13 +0000 (12:14 -0500)] 
kmod 33

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agolibkmod: avoid undefined behaviour in libkmod-builtin.c:get_string
Eugene Syromiatnikov [Tue, 13 Aug 2024 14:17:27 +0000 (16:17 +0200)] 
libkmod: avoid undefined behaviour in libkmod-builtin.c:get_string

Static analysis has reported a potential UB:

    kmod-31/libkmod/libkmod-builtin.c:125: use_invalid: Using "nullp", which points to an out-of-scope variable "buf".
    #  123|    size_t linesz = 0;
    #  124|
    #  125|->  while (!nullp) {
    #  126|    char buf[BUFSIZ];
    #  127|    ssize_t sz;

It seems to be indeed an UB, as nullp is getting assined an address
inside object buf, which has a lifetime of the while loop body,
and is not available outside of it (specifically, in the while
condition, where nullp is checked for NULL).  Fix it by putting
buf definition in the outer block.

12 months agoRemove outdated TODO file
Lucas De Marchi [Thu, 8 Aug 2024 07:03:53 +0000 (02:03 -0500)] 
Remove outdated TODO file

TODO entries migrated to github issues:
https://github.com/kmod-project/kmod/issues

Link: https://github.com/kmod-project/kmod/pull/66
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agobuild: Add s-o-b to release commit
Lucas De Marchi [Tue, 30 Jul 2024 15:47:03 +0000 (10:47 -0500)] 
build: Add s-o-b to release commit

Once upon a time kmod didn't use s-o-b. Now that it does, better to also
add it to the release commit.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/66
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agom4: remove verbose license exception clause
Emil Velikov [Sat, 10 Aug 2024 12:25:16 +0000 (13:25 +0100)] 
m4: remove verbose license exception clause

It is already encoded in the SPDX license identifier.

Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Fixes: b5a2cd0 ("Use SPDX header for license")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agom4: reinstate CC_CHECK_FLAG_APPEND summary
Emil Velikov [Sat, 10 Aug 2024 12:25:15 +0000 (13:25 +0100)] 
m4: reinstate CC_CHECK_FLAG_APPEND summary

Earlier commit was reducing the license boilerplate to SPDX license
identifiers and erroneously dropped the function summary section.

Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Fixes: b5a2cd0 ("Use SPDX header for license")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agodepmod: Remove license/copyright from the middle
Lucas De Marchi [Tue, 23 Jul 2024 18:59:21 +0000 (13:59 -0500)] 
depmod: Remove license/copyright from the middle

The top license is enough as it's the same. Just move the copyright to
the top and remove notice about code that was copied and modified: that
comment doesn't age well as source is updated.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240723185921.1005569-4-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agoDrop the one line short description on sources
Lucas De Marchi [Tue, 23 Jul 2024 18:59:20 +0000 (13:59 -0500)] 
Drop the one line short description on sources

Some are outdated, misleading or just repeat the same thing over and
over. Remove them as they are not needed.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240723185921.1005569-3-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agoUse SPDX header for license
Lucas De Marchi [Tue, 23 Jul 2024 18:59:19 +0000 (13:59 -0500)] 
Use SPDX header for license

Drop the lengthy license from each file and just use SPDX like most
projects nowadays. This doesn't have any change to license, just how
they are recorded in each file.

This follows the kernel approach: header files use '/*' for comments
while .c files use '//'. For .m4, use "#".

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240723185921.1005569-2-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agolibkmod: Move zstd-related functions to separate file
Lucas De Marchi [Tue, 9 Jul 2024 06:33:40 +0000 (01:33 -0500)] 
libkmod: Move zstd-related functions to separate file

Move zstd-related function to a separate file so it's easier to isolate
the dependency on each decompression library.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/58
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agolibkmod: Move zlib-related functions to separate file
Lucas De Marchi [Tue, 9 Jul 2024 06:27:59 +0000 (01:27 -0500)] 
libkmod: Move zlib-related functions to separate file

Move zlib-related function to a separate file so it's easier to isolate
the dependency on each decompression library.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/58
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agolibkmod: Move xz-related functions to separate file
Lucas De Marchi [Tue, 9 Jul 2024 06:08:56 +0000 (01:08 -0500)] 
libkmod: Move xz-related functions to separate file

Move xz-related function to a separate file so it's easier to isolate
the dependency on each decompression library.

Declare struct kmod_file in a shared libkmod-internal-file.h that will
be included only by sources implementing kmod_file decompression
routines.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/58
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agobuild: Always run distcheck with all compression libraries
Lucas De Marchi [Wed, 24 Jul 2024 03:42:44 +0000 (22:42 -0500)] 
build: Always run distcheck with all compression libraries

Make sure to pass enable all compression libraries so all sources are
included.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/58
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
12 months agolibkmod: move new weak API to separate section
Emil Velikov [Fri, 19 Jul 2024 16:12:43 +0000 (17:12 +0100)] 
libkmod: move new weak API to separate section

Add the new weak API, to a separate section in the version script. These
will be exposed with the upcoming v33 release and not with v5 as the
symbol tag implies.

Cc: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Fixes: 05828b4 ("libkmod: add weak dependecies")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20240719-abi-fixes-v1-3-1e6d99a2846b@gmail.com
12 months agolibkmod: correctly tag kmod_module_new_from_name_lookup
Emil Velikov [Fri, 19 Jul 2024 16:12:42 +0000 (17:12 +0100)] 
libkmod: correctly tag kmod_module_new_from_name_lookup

The symbol was introduced with v30, yet was erroneously added in the v5
section. Move it to the correct place.

In theory this might cause an issue - severity depends on how the
runtime linker is setup. From a harmless warning (on stderr/stdout) to
failure to load the library.

In practise this shouldn't be a problem, since there are seemingly no
external users of the API.

Fixes: 9becaae ("libkmod: Add lookup from module name")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20240719-abi-fixes-v1-2-1e6d99a2846b@gmail.com
12 months agolibkmod: document KMOD_INDEX_MODULES_BUILTIN_ALIAS in kmod_dump_index()
Emil Velikov [Fri, 19 Jul 2024 16:12:41 +0000 (17:12 +0100)] 
libkmod: document KMOD_INDEX_MODULES_BUILTIN_ALIAS in kmod_dump_index()

The extra enum was introduced a few years ago, although the (only)
function using it did not have it's documentation updated.

The commit itself has caused an ABI break with kmod v27, since the
KMOD_INDEX_MODULES_BUILTIN value has changed.

A search through Google, Github and Arch packages have shown one user of
kmod_dump_index() - the only API that uses the enum.

In that case and all others, no projects referencing the changed enum
were found. Although since recent and/or supported distros use kmod v27
or later we've decided to only update the documentation.

Cc: Alexey Gladkov <gladkov.alexey@gmail.com>
Fixes: b866b21 ("Lookup aliases in the modules.builtin.modinfo")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20240719-abi-fixes-v1-1-1e6d99a2846b@gmail.com
12 months agokmod: remove .alias config files for modprobe.d
Emil Velikov [Wed, 17 Jul 2024 17:26:45 +0000 (18:26 +0100)] 
kmod: remove .alias config files for modprobe.d

The use of .alias (alongside .conf) was added for compatibility with the
original module-init-tools project and has been living in kmod ever
since.

In practise, all the linux distributions that I can see are using .conf
files alone, as instructed by modprobe.d(5) and the only instance of an
.alias file is the modules.alias as shipped in the kernel.

The latter is already handled by other parts of the kmod project, so
let's enforce what our documentation says.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20240717-rm-alias-v1-1-58874caf343a@gmail.com
12 months agoci: Add Alpine
Lucas De Marchi [Fri, 12 Jul 2024 19:10:29 +0000 (14:10 -0500)] 
ci: Add Alpine

Add setup action for Alpine and start building it. Unfortunately the
testsuite is not ready yet and fails to build like this:

../testsuite/path.c:219:14: error: conflicting types for '__xstat64';
have 'int(int,  const char *, struct stat64 *)'
  219 | WRAP_VERSTAT(__x,64);
      |              ^~~

Add everything needed on the setup action, so when the underlying issue
is fixed, the testsuite can be enabled in CI.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/44
12 months agoci: Add Fedora
Lucas De Marchi [Fri, 12 Jul 2024 18:12:10 +0000 (13:12 -0500)] 
ci: Add Fedora

Add an action to setup latest Fedora and use it for the initial setup.
Add hack on /usr/lib/modules so /usr/lib/modules/*/build can still be
used in the rest of the workflow as the KDIR.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/44
12 months agoci: Add Archlinux
Lucas De Marchi [Fri, 12 Jul 2024 17:06:42 +0000 (12:06 -0500)] 
ci: Add Archlinux

Add an action to setup Archlinux and use it for the initial setup.
The rest of the workflow can stay the same.

Currently the Arch container in docker hub is not very up-to-date with
some expired keys and other keys not yet in the package. Workaround
that by wiping the current db and reinstalling the keyring. As requested
by Emil, add a comment in this part of the github-action about why
that is done.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/44
12 months agoci: Use a container and expand versions
Lucas De Marchi [Fri, 12 Jul 2024 16:06:07 +0000 (11:06 -0500)] 
ci: Use a container and expand versions

Use containers to build/test so it's not restricted to the OS versions
supported by Github runners. A few changes are needed to the workflow to
support using containers:

1) No need for sudo, so remove it
2) Explicitly install missing zlib
3) Explicitly pass KDIR= while building kernel modules, since it
   won't match `uname -r`. This assumes the container has just
   one kernel installed and so /usr/lib/modules/*/build can be
   used as the single symlink to the kernel headers. This should
   be common to other distros to be added, too.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/44
12 months agoci: Replace package installation with local action
Lucas De Marchi [Fri, 12 Jul 2024 15:58:32 +0000 (10:58 -0500)] 
ci: Replace package installation with local action

Separate the package installation step with a local action so
it's easier to support more versions and distros.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/44
12 months agoREADME: update to a decade+ later
Lucas De Marchi [Fri, 12 Jul 2024 13:24:49 +0000 (08:24 -0500)] 
README: update to a decade+ later

- State support for clang and other libc's
- Fix typos
- Reword the compatibility with module-init-tools section,
  removing most of the specific examples as we didn't keep
  track of all of them, and they are not important anymore
  in year 2024

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240712132449.780421-1-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agolibkmod: improve realloc behavior for zstd outbuffer
q66 [Mon, 17 Jun 2024 23:22:06 +0000 (01:22 +0200)] 
libkmod: improve realloc behavior for zstd outbuffer

The allocator in glibc has a particular quirk that successive
reallocs on the same pointer are cheap, at the cost of excess
memory fragmentation. Other allocators generally do not do this,
so excessive reallocs become relatively expensive.

Reducing the number of reallocations by using a more agressive
strategy for buffer size increase makes performance better on
those setups, e.g. musl libc, or generally any other allocator;
on my Chimera Linux setup with Scudo allocator (LLVM) it doubles
to triples the performance of running e.g. depmod.

Signed-off-by: q66 <q66@chimera-linux.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoci: Add github workflow
Lucas De Marchi [Tue, 9 Jul 2024 13:50:07 +0000 (08:50 -0500)] 
ci: Add github workflow

Add a minimal github workflow to test kmod. This can be incremented in
future to test more distros, compilers and libc.

Link: https://lore.kernel.org/r/20240709135007.104325-2-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agobuild: Add mod-weakdep.c to EXTRA_DIST
Lucas De Marchi [Tue, 9 Jul 2024 04:47:57 +0000 (23:47 -0500)] 
build: Add mod-weakdep.c to EXTRA_DIST

Fix distcheck failure:
make[5]: *** No rule to make target
'/home/runner/work/kmod/kmod/build/kmod-32/_build/sub/testsuite/module-playground/mod-weakdep.o',
needed by
'/home/runner/work/kmod/kmod/build/kmod-32/_build/sub/testsuite/module-playground/'.
Stop.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: list options one per line
Emil Velikov [Mon, 8 Jul 2024 13:43:25 +0000 (14:43 +0100)] 
man: list options one per line

Somewhat inspired by my selfish use of VIM as man pager. Namely, when
there are multiple options on the same line, only the first one gets
properly rendered.

A good bonus point is that very long instances, like modinfo's legacy
"--author, --description ..." look a bit neater now.

With this is also more consistently handle short/long options which take
an argument.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: rework AUTHORS section
Emil Velikov [Mon, 8 Jul 2024 13:43:24 +0000 (14:43 +0100)] 
man: rework AUTHORS section

Replace the partial listing with suggestion to check through git
shortlog and git blame.

Explicitly spell out the current maintainer, alongside giving Jon
attribution for the original project.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: remove the "Maintained by" references
Emil Velikov [Mon, 8 Jul 2024 13:43:23 +0000 (14:43 +0100)] 
man: remove the "Maintained by" references

At a glance through my system, around 2% of the man pages include such
statement.

Looking through git log, Jon has been active in a while and presumably
have moved on.

Most importantly the Copyright section isn't the best place to reference
the maintainer/contact person.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe: remove hard-coded /etc/modprobe.d references
Emil Velikov [Mon, 8 Jul 2024 13:43:22 +0000 (14:43 +0100)] 
man: modprobe: remove hard-coded /etc/modprobe.d references

Point the users to modprobe.d(5) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add few mentions about MODPROBE_OPTIONS
Emil Velikov [Mon, 8 Jul 2024 13:43:21 +0000 (14:43 +0100)] 
man: add few mentions about MODPROBE_OPTIONS

The environment variable may alter config file ordering, so mention it
in the man page.

In addition, highlight that the format is intentionally undocumented
since the use by third parties is discouraged.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe.d: factor out a CONFIGURATION FORMAT section
Emil Velikov [Mon, 8 Jul 2024 13:43:20 +0000 (14:43 +0100)] 
man: modprobe.d: factor out a CONFIGURATION FORMAT section

Keep the description neat and tidy.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: modprobe.d: document the config file order handling
Emil Velikov [Mon, 8 Jul 2024 13:43:19 +0000 (14:43 +0100)] 
man: modprobe.d: document the config file order handling

The modprobe.d configuration order/handling aligns with existing tools
such as sysctl.d, even though there is no mention in the manual.

Reorder the list in SYNOPSIS and add a bit of verbiage describing things.

Section is inspired by sysctl.d(5) and sysctl(8).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod: remove hard-coded /etc/depmod.d references
Emil Velikov [Mon, 8 Jul 2024 13:43:18 +0000 (14:43 +0100)] 
man: depmod: remove hard-coded /etc/depmod.d references

Point the users to depmod.d(5) instead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: rework the opening description sentence
Emil Velikov [Mon, 8 Jul 2024 13:43:17 +0000 (14:43 +0100)] 
man: depmod.d: rework the opening description sentence

Use a slightly longer, more gradual introduction.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: factor out a CONFIGURATION FORMAT section
Emil Velikov [Mon, 8 Jul 2024 13:43:16 +0000 (14:43 +0100)] 
man: depmod.d: factor out a CONFIGURATION FORMAT section

Keep the description neat and tidy.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: depmod.d: document the config file order handling
Emil Velikov [Mon, 8 Jul 2024 13:43:15 +0000 (14:43 +0100)] 
man: depmod.d: document the config file order handling

The depmod.d configuration order/handling aligns with existing tools
such as sysctl.d, even though there is no mention in the manual.

Reorder the list in SYNOPSIS and add a bit of verbiage describing things.

Section is inspired by sysctl.d(5) and sysctl(8).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: stop removing DISTCONFDIR lines
Emil Velikov [Mon, 8 Jul 2024 13:43:14 +0000 (14:43 +0100)] 
man: stop removing DISTCONFDIR lines

Presently when DISTCONFDIR is identical to /lib we remove the whole
line, since the man pages already have an /lib instance.

At the same time, there are in-text DISTCONFDIR entries, and removing
the whole line outright breaks the documentation.

Drop the removal line - worst case scenario we get a duplicate entry in
the synopsis.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: couple of grammar/language fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:13 +0000 (14:43 +0100)] 
man: couple of grammar/language fixes

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: some options take an argument, mention that
Emil Velikov [Mon, 8 Jul 2024 13:43:12 +0000 (14:43 +0100)] 
man: some options take an argument, mention that

For example modinfo -F requires the field name, although the
documentation was missing the "field".

Similarly modprobe has omissions, so let's fix those as well.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: misc punctuation fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:11 +0000 (14:43 +0100)] 
man: misc punctuation fixes

Some commas and a full stop was missing ;-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: white space fixes
Emil Velikov [Mon, 8 Jul 2024 13:43:10 +0000 (14:43 +0100)] 
man: white space fixes

These were present in the original xml files and I opted to keep them
separate fix to make the transition/comparison easier.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add some extra bold/italic annotations
Emil Velikov [Mon, 8 Jul 2024 13:43:09 +0000 (14:43 +0100)] 
man: add some extra bold/italic annotations

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: remove no longer used XML files
Emil Velikov [Tue, 11 Jun 2024 15:05:04 +0000 (16:05 +0100)] 
man: remove no longer used XML files

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agobuild: Require scdoc if building man pages
Lucas De Marchi [Wed, 3 Jul 2024 15:07:12 +0000 (10:07 -0500)] 
build: Require scdoc if building man pages

Instead of creating invalid man pages, make sure the configure step
fails if scdoc is not available.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agogitignore: ignore gtk-doc.m4
Lucas De Marchi [Wed, 3 Jul 2024 15:04:19 +0000 (10:04 -0500)] 
gitignore: ignore gtk-doc.m4

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: build the scdoc based man pages
Emil Velikov [Tue, 11 Jun 2024 15:05:03 +0000 (16:05 +0100)] 
man: build the scdoc based man pages

Note that scdoc does not handle natively handle the dummy
modules.dep.bin.5 entry, so we need to create one manually.

Not a big deal, since it's single static line anyway.

Also: pkg-config --variable=scdoc scdoc, produces the full executable
and path, although for now we stick with the AC_PATH_PROG approach.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Do not add the stub man page (modules.dep.bin.5) to CLEANFILES
  to avoid removing a file that is tracked by git. Also fix a typo
  s/AM_V_SCDOR_/AM_V_SCDOC_/ to make silent rules to work ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
13 months agoman: add scdoc based man pages
Emil Velikov [Tue, 11 Jun 2024 15:05:02 +0000 (16:05 +0100)] 
man: add scdoc based man pages

Working with xml is quite fiddly. Swap that for scdoc, which has very
trivial markup-like syntax.

We have opted for scdoc since it's available on practically any linux
distribution. Implementation-wise it's a trivial C99 project, at 1k LoC.

If using scdoc proves to be a burden, we can trivially port these to
pandoc or similar - 90% of the content will stay the same.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: add tests for weak dependencies
Jose Ignacio Tornos Martinez [Thu, 30 May 2024 07:08:27 +0000 (09:08 +0200)] 
testsuite: add tests for weak dependencies

The following tests to verify weak dependencies have been implemented:
1) modprobe test to check that related weakdep modules are not loaded
   due to being a weakdep.
2) depmod test to check weakdep output.
3) user test to check that configuration files with weakdep are parsed
   correctly and related weakdep modules can be read correctly from user
   applications.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Link: https://lore.kernel.org/r/20240530070836.9438-1-jtornosm@redhat.com
[ Minor whitespace issues and define MODULE_WEAKDEP if it's not defined
  already ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months ago.mailmap: Forward to my personal email
Emil Velikov [Tue, 11 Jun 2024 14:34:56 +0000 (15:34 +0100)] 
.mailmap: Forward to my personal email

My Collabora email is bouncing, so forward to my personal Gmail.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240611-mailmap-v1-1-69ce7f7ffbe6@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: Add missing.h include
Lucas De Marchi [Tue, 11 Jun 2024 13:09:19 +0000 (08:09 -0500)] 
testsuite: Add missing.h include

basename() moved to missing.h when the libc doesn't provide it, but
testsuite is not including it. Add missing include.

Fixes: 11eb9bc67c31 ("Use portable implementation for basename API")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agodepmod: Fix warning with -D_TIME_BITS=64
Lucas De Marchi [Tue, 11 Jun 2024 13:02:26 +0000 (08:02 -0500)] 
depmod: Fix warning with -D_TIME_BITS=64

Printing time_t, suseconds_t, useconds_t in 32bits with -D_TIME_BITS=64
leads to the following warning:

../tools/depmod.c:2641:61: warning: format ‘%li’ expects argument of type ‘long int’, but argument 6 has type ‘__suseconds64_t’ {aka ‘long long int’} [-Wformat=]
 2641 |                         snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(),
      |                                                           ~~^
      |                                                             |
      |                                                             long int
      |                                                           %lli
 2642 |                                         tv.tv_usec, tv.tv_sec);
      |                                         ~~~~~~~~~~

Paper it over by casting the argument to 64 bits and switching to long long.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agotestsuite: wrap _{l,}stat64_time64 in test
Shengjing Zhu [Thu, 18 Apr 2024 14:29:51 +0000 (22:29 +0800)] 
testsuite: wrap _{l,}stat64_time64 in test

Fix building with -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 on 32bit arch.

Closes: https://github.com/kmod-project/kmod/issues/37
Bug: https://bugs.debian.org/1065973
Co-authored-by: Jochen Sprickerhof <github@jochen.sprickerhof.de>
Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
14 months agoUse portable implementation for basename API
Khem Raj [Sun, 10 Dec 2023 01:35:59 +0000 (17:35 -0800)] 
Use portable implementation for basename API

musl has removed the non-prototype declaration of basename from
string.h [1] which now results in build errors with clang-17+ compiler

Implement GNU basename behavior using strchr which is portable across libcs

Fixes
../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
71 | "Commands:\n", basename(argv[0]));
| ^

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Suggested-by: Rich Felker
Signed-off-by: Khem Raj <raj.khem@gmail.com>
[ Implement a basename() function in missing.h and ensure we always use
  the right include rather than having a separate gnu_basename() ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: add weak dependecies
Jose Ignacio Tornos Martinez [Wed, 27 Mar 2024 14:11:16 +0000 (15:11 +0100)] 
libkmod: add weak dependecies

It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.

In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.

The idea is to create a new type of dependency, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.

A new function 'kmod_module_get_weakdeps' in libkmod will be added for
this to avoid breaking the API and maintain backward compatibility. This
general procedure could be useful for other similar cases (not only for
dynamic phy loading).

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Link: https://lore.kernel.org/r/20240327141116.97587-1-jtornosm@redhat.com
15 months agolibkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types
Emil Velikov [Mon, 12 Feb 2024 17:23:13 +0000 (17:23 +0000)] 
libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types

It's cleaner to handle all compression types and load functions in the
same style.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: move load_reg() further up
Emil Velikov [Mon, 12 Feb 2024 17:23:12 +0000 (17:23 +0000)] 
libkmod: move load_reg() further up

We're about to reference it in comp_types with next commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: tidy-up kmod_file_open()
Emil Velikov [Mon, 12 Feb 2024 17:23:11 +0000 (17:23 +0000)] 
libkmod: tidy-up kmod_file_open()

This commit cleans up the indentation and the error path of the
function. It bears no functional changes.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
[ Move assert to avoid warning with -Wdeclaration-after-statement ]
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: swap alloca usage for a few assert_cc
Emil Velikov [Mon, 12 Feb 2024 17:23:10 +0000 (17:23 +0000)] 
libkmod: swap alloca usage for a few assert_cc

Since all the compression magic is always available now, we don't need
to loop at runtime nor use alloca - latter of which comes with a handful
of caveats.

Simply throw in a few assert_cc(), which will trigger at build-time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: always detect the module compression
Emil Velikov [Mon, 12 Feb 2024 17:23:09 +0000 (17:23 +0000)] 
libkmod: always detect the module compression

Currently, when built w/o given compression we'll incorrectly report a
"compression_none".

As we reach do_finit_module(), we'll naively assume that the kernel can
handle the compressed module, yet omit the MODULE_INIT_COMPRESSED_FILE
flag.

As result the kernel will barf at us, do_finit_module will fail with non
-ENOSYS and we won't end in the do_init_module codepath (which will also
fail).

In other words: with this change, you can build kmod without zstd, xz
and zlib support and the kernel will load the modules, assuming it
supports the format \o/

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: move kmod_file_load_contents as applicable
Emil Velikov [Mon, 12 Feb 2024 17:23:08 +0000 (17:23 +0000)] 
libkmod: move kmod_file_load_contents as applicable

When dealing with an elf, we don't know or care about loading the file.
The kmod_elf subsystem/API will deal with the required parts itself.

Which in this case, already calls kmod_file_load_contents() as
applicable.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: propagate {zstd,xz,zlib}_load errors
Emil Velikov [Mon, 12 Feb 2024 17:23:07 +0000 (17:23 +0000)] 
libkmod: propagate {zstd,xz,zlib}_load errors

Propagate any errors during decompression further up the call stack.
Without this we could easily pass NULL as mem to init_module(2).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: nuke struct file_ops
Emil Velikov [Mon, 12 Feb 2024 17:23:06 +0000 (17:23 +0000)] 
libkmod: nuke struct file_ops

With the previous commits, we removed the need for a distinct unload
callback.

So nuke the struct all together and only use/keep the load one around.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: clear file->memory if map fails
Emil Velikov [Mon, 12 Feb 2024 17:23:05 +0000 (17:23 +0000)] 
libkmod: clear file->memory if map fails

On mmap failure file->memory is set to -1, which we'll happily pass down
to munmap later on.

More importantly, since we do a NULL check in kmod_file_load_contents()
we will exit the function without (re)attempting the load again.

Since we ignore the return code for the load function(s), one can end up
calling kmod_elf_get_memory() and feed that -1 into init_module.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: remove kmod_file::{zstd,xz}_used flags
Emil Velikov [Mon, 12 Feb 2024 17:23:04 +0000 (17:23 +0000)] 
libkmod: remove kmod_file::{zstd,xz}_used flags

These are used to protect a free(file->memory), within their respective
unload functions. Where the sole caller of the unload function already
does a NULL check prior.

Even so, free(NULL) is guaranteed to be safe by the standard.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: keep gzFile gzf local to load_zlib()
Emil Velikov [Mon, 12 Feb 2024 17:23:03 +0000 (17:23 +0000)] 
libkmod: keep gzFile gzf local to load_zlib()

There is no need to keep the root gzFile context open for the whole
duration. Once we've copied the decompressed module to file->memory we
can close the handle.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agolibkmod: use a dup()'d fd for zlib
Emil Velikov [Mon, 12 Feb 2024 17:23:02 +0000 (17:23 +0000)] 
libkmod: use a dup()'d fd for zlib

The gzdopen() API used, takes ownership of the fd. To make that more
explicit we clear it (-1) as applicable.

Yet again, kmod has explicit API to return the fd to the user - which
currently is used solely when uncompressed, so we're safe.

Regardless - simply duplicate the fd locally and use that with zlib.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agobuild: Ignore directories commonly used for out-of-tree build
Lucas De Marchi [Tue, 30 Apr 2024 14:26:20 +0000 (09:26 -0500)] 
build: Ignore directories commonly used for out-of-tree build

build/ and build-*/ are commonly used to have multiple out-out-tree
builds. Add them to gitignore.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
15 months agotestsuite: Fix warnings due to -Wmissing-prototypes
Lucas De Marchi [Mon, 29 Apr 2024 21:19:12 +0000 (16:19 -0500)] 
testsuite: Fix warnings due to -Wmissing-prototypes

/testsuite/module-playground/mod-foo-b.c:13:6: warning: no previous prototype for ‘print_fooB’ [-Wmissing-prototypes]
   13 | void print_fooB(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-foo-a.c:13:6: warning: no previous prototype for ‘print_fooA’ [-Wmissing-prototypes]
   13 | void print_fooA(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-foo-c.c:13:6: warning: no previous prototype for ‘print_fooC’ [-Wmissing-prototypes]
   13 | void print_fooC(void)
      |      ^~~~~~~~~~
/testsuite/module-playground/mod-fake-scsi-mod.c:15:6: warning: no previous prototype for ‘dummy_export’ [-Wmissing-prototypes]
   15 | void dummy_export(void)
      |      ^~~~~~~~~~~~

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agoInstall kmod.pc in ${datadir}/pkgconfig
Mike Gilbert [Fri, 8 Mar 2024 19:06:19 +0000 (14:06 -0500)] 
Install kmod.pc in ${datadir}/pkgconfig

The data in this file isn't related to installed libraries, so put it in
an abi-neutral location.

pkg.m4 provides macros that also allow the user to override the location
with configure switches.

Bug: https://bugs.gentoo.org/926431
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agobuild: Allow to install over dirty dir
Lucas De Marchi [Wed, 6 Mar 2024 14:58:04 +0000 (08:58 -0600)] 
build: Allow to install over dirty dir

Before commit e98cef6f3f8c ("make: install/uninstall tools symlinks to
kmod") it was possible to call `make install DESTDIR=<dir>` multiple
times. Use `ln -sf` so the symlink is always re-created.

It would be preferred to remove install in an empty dir, but there's
not a bad consequence of re-using the same, so let the user decide.
Fixes the following errors while installing for the second time:

ln: failed to create symbolic link '/tmp/inst/usr/bin/insmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/lsmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/rmmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/depmod': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modprobe': File exists
ln: failed to create symbolic link '/tmp/inst/usr/bin/modinfo': File exists
make[3]: *** [Makefile:2679: install-exec-hook] Error 1
make[2]: *** [Makefile:2553: install-exec-am] Error 2
make[1]: *** [Makefile:2439: install-am] Error 2
make: *** [Makefile:1848: install-recursive] Error 1

Cc: Emil Velikov <emil.l.velikov@gmail.com>
Closes: https://github.com/kmod-project/kmod/issues/35
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240306145804.135709-1-lucas.de.marchi@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agokmod 32 v32
Lucas De Marchi [Wed, 6 Mar 2024 03:27:42 +0000 (21:27 -0600)] 
kmod 32

17 months agoRemove unmaintained experimental tools
Emil Velikov [Mon, 12 Feb 2024 17:07:57 +0000 (17:07 +0000)] 
Remove unmaintained experimental tools

The kmod insert/remove tools were introduced back in 2015. Since then
they have recieved zero attention, unlike the insmod/rmmod variants.

Glancing around - neither of the following distributions (Arch, Fedora,
Gentoo, Debian) build them, so we're safe to say they have no users.

Remove them and alongside it the --enable-experimental toggle, which no
longer controls anything.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240212-rm-experimental-v1-1-b97ab3004ae3@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
17 months agoman: silence autoconf warnings
Emil Velikov [Sat, 17 Feb 2024 16:01:26 +0000 (16:01 +0000)] 
man: silence autoconf warnings

Currently we have a pattern rule, which effective states that two output
files are produced - %.5 and %.8. Although that's not the case in
practise, since each input xml will be generated to a single manual
page.

Add the manpage section as part of the xml filename and tweak the
pattern (match) rule, accordingly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://lore.kernel.org/r/20240217-autoconf-manpage-warns-v1-1-e1570cfc286e@gmail.com
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
18 months agomake: install/uninstall tools symlinks to kmod
Emil Velikov [Fri, 26 Jan 2024 14:43:51 +0000 (14:43 +0000)] 
make: install/uninstall tools symlinks to kmod

Currently we create symlinks like modprobe (pointing to kmod), during
the normal `make` build. Although those were never installed.

Add a few lines in the install-exec-hook, to ensure they're present at
`make install` time. Thus one can actually use those without additional
changes. As an added bonus, distributions can drop the similar hunk from
their packaging.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Use a relative symlink ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>