]> git.ipfire.org Git - thirdparty/kmod.git/log
thirdparty/kmod.git
11 months agotestsuite/path: wrap 64 variants for _GLIBC_
Emil Velikov [Tue, 3 Sep 2024 21:31:04 +0000 (22:31 +0100)] 
testsuite/path: wrap 64 variants for _GLIBC_

Since musl v1.2.4 and Alpine 3.18, circa May 2023, the LFS64 variants
are no longer exported by libc.so.

In addition musl headers provide relevant "#define foo64 foo" macros,
when _LARGEFILE64_SOURCE is defined and symbol resolution is deferred to
the runtime linker. See musl commit 246f1c811448 ("remove LFS64 symbol
aliases; replace with dynamic linker remapping") more details.

Earlier versions of musl had the symbols exposed by libc, although the
^^ macros were also available when _GNU_SOURCE is set, as our build
does.

Most importantly, we do not explicitly use the 64 variants and musl
doesn't implicitly pull them either. So in practise building with musl,
the binaries do not have any 64 references, thus there is no need to
wrap them.

AFAICT there is no obvious way of detecting musl, apart from the lack of
of __GLIBC__, so pull features.h (which defines it) and check on that.

There is a small chance the __GLIBC__ check will miss-fire on other
implementations like bionic, dietlibc or ulibc(-ng). We don't run the
tests on those platforms (although we could) so it should be fine.

With that we can install tar (for make distcheck) and enable the tests
in CI \o/

Closes: https://github.com/kmod-project/kmod/issues/65
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/97
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agolibkmod: check for NULL in kmod_get_dirname
Tobias Stoeckmann [Wed, 4 Sep 2024 16:21:17 +0000 (18:21 +0200)] 
libkmod: check for NULL in kmod_get_dirname

The other KMOD_EXPORT'ed functions protect against ctx being NULL.
Add this to kmod_get_dirname purely for consistency reasons.

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/102
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agolibkmod: Improve signature parser on 32 bit archs
Tobias Stoeckmann [Tue, 3 Sep 2024 17:49:04 +0000 (19:49 +0200)] 
libkmod: Improve signature parser on 32 bit archs

During signature parser validation it is not enough to cast the end
result to 64 bit, because on 32 bit systems size_t is an unsigned 32 bit
integer, which implies that this will be the data type used to evaluate
the expression BEFORE casting it due to C standard.

Since the unsigned 32 bit calculation can overflow, cast the size_t
to int64_t, which makes the whole calculation safe.

This has no negative impact on 64 bit systems because the size_t
value is read as an unsigned 32 bit value from module.

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/95
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: add meson build permutation
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
ci: add meson build permutation

Note that we cannot use conditionals within the run actions, because
coreutils (for [ and test) are not installed on Debian/Ubuntu. Even
after doing so, the script consistently fails.

For meson dist to work, we need a full git repo, git and safe
directories setup, otherwise it fails as below. Meson issue was
reported ~2 years ago and we're about to get a fix soon (tm).

  Dist currently only works with Git or Mercurial repos

v2:
 - split git/checkout to separate patch
 - use build-dev.ini instead of meson.sh
v3:
 - use matrix for setting 'test' variable

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: build-dev.ini file
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: build-dev.ini file

Functionally identical to the autogen.sh c options. This allows devs
(and upcoming CI) to make use of a pre-defined set.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: add KDIR to the environment
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
ci: add KDIR to the environment

The environment variable is used in multiple places, so just set it
once.

While in there, check that only a single kernel is installed. It's
better to error out with a clear message.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: install git and checkout using it
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
ci: install git and checkout using it

Atm the checkout action pulls the whole repo as tarball, since git is
missing. Since we install packages via local actions, we need to first
do an initial sparse checkout, install the packages (git including) and
do a proper second checkout.

At which point, the second checkout action claims to set safe.directory
(it's the default) although in practise we need to do it again. Perhaps
it's getting tripped by our initial sparse checkout?

Either way, explicitly set the option so that git just works.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoci: remove no longer set matrix.configure
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
ci: remove no longer set matrix.configure

... and it doesn't seem like we'll need it in the future.

Fixes: fdcb656 ("testsuite: remove cached modules and --disable-test-modules")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: allow building the manpages
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: allow building the manpages

Not as brief as the pipeline and pattern matching that (auto)make can
do, although it's fully functional ;-)

v2:
 - move man/meson.build
 - move script under scripts/

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: add support for the testsuite
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: add support for the testsuite

Currently the stale tracking of modules/rootfs is non-existent and I
cannot quite find a way to fix that.

In addition, there is a long standing meson bug where the tests and by
extension their dependencies are always build even when annotated as
`build_by_default : false`. To workaround that, a new option is
introduced `build-tests`, defaulting to false.

Apart from that, all tests run and pass \o/

v2:
 - split from top-level meson.build to subdir one
 - add to EXTRA_DIST
 - scripts are in scripts/
 - add option to enable building tests
 - error out if building without tools

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: allow disabling the bash completion
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: allow disabling the bash completion

For the cases where you don't want (or cannot) install it. For example,
I've seen similar requests from the Nix people.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: enable PIE by default
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: enable PIE by default

The autotools build has PIC enabled by default, as do we. Take this a
step further by also enabling PIE.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: add support for the tools
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: add support for the tools

Nothing too spectacular, apart from a few meson quirks:
 - one can use both_libraries() alas, "install: true" will also install
   the static library, which we do not want
 - need to workaround kmod.pc empty variables, introduced in 1.4.0
 - wrapper script is needed for the symlink creation - see wrapper
   script for details
 - resulting binary exports optarg/optind/stderr/stdout and more

v2:
 - add kmod bash-completion hunk

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomeson: introduce meson, covering libkmod.so
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
meson: introduce meson, covering libkmod.so

The meson build system has been getting popularity, but for us that
means coverage and sanitisers OOTB et al.

The current patch, handles only libkmod.so and libkmod.pc. The rest will
follow-up.

Notable changes comparing against the autoconf:
 - more consistent dirnames
 - omit printing bash completion dir and compiler flags from summary
 - debug toggle is renamed to debug-messages
 - a few [C,LD]FLAGS were omitted - they're provided by meson itself
 - libkmod.pc has the more complete Requires.private over Libs.private
 - use the symver for libkmod.so, omit the version-info magic

Note: The minimal meson version is 0.60.0 akin to systemd and mesa.

v2:
 - use gnu11, list both LGPL and GPL licenses
 - add meson files to EXTRA_DIST
 - add temporary stdndupa workaround
 - move kmod bash-completion to later patch

v3:
 - switch to meson 0.60.0
 - remove stdndupa workaround

Loosely based on the work by: Dave Reisner <dreisner@archlinux.org>

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: split out setup-modules.sh
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: split out setup-modules.sh

So that we can reuse it from the upcoming meson build.

v2:
 - shellcheck fixes, add TODO, move to scripts/

v3:
 - set MAKEFLAGS="-j$(nproc)" if empty

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months ago.editorconfig: add sh(ell) section
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
.editorconfig: add sh(ell) section

The existing in-tree (two) shell scripts are of fairly mixed style.
With indent_size being 0, 4, 8 and indent_style both space and tab.

The more common instance seems to be 4 spaces, so add that to the
config. Updating existing scripts is deferred for another time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: move setup-rootfs.sh to scripts/
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: move setup-rootfs.sh to scripts/

There will be a few more scripts incoming, so let's give them a
dedicated location.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: tweak sed/find dance in setup-rootfs.sh
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: tweak sed/find dance in setup-rootfs.sh

Instead of doing the exact same search twice and using sub-shells, find
once and -exec the patterns.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: sprinkle more quotation marks in setup-rootfs.sh
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: sprinkle more quotation marks in setup-rootfs.sh

... as highlighted by shellcheck.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: correct the default KDIR
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: correct the default KDIR

Honor the user-provided module directory. At the moment things work,
because distros have compatibility /lib -> /usr/lib symlink.

While in there, avoid the use of deprecated backtick (shell) notation.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: split-out Kbuild from Makefile
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: split-out Kbuild from Makefile

The former is used by the kernel build system, while the latter is our
convenience wrapper. Split the two to indicate the distinction and make
things easier to parse.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: use standard make (modules|clean) targets
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: use standard make (modules|clean) targets

Drop the manual (and partial) module cleanup in favour of the clean
target. Similarly - explicitly use the modules target for the build.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: temporary drop cross compilation test, remove binaries
Emil Velikov [Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)] 
testsuite: temporary drop cross compilation test, remove binaries

The idea behind the test is that modinfo should work with foreign
modules - be that CPU architecture, endianess, bit width or otherwise.

On the other hand, having binary modules baked into the repo isn't great
since they can may be outdated wrt their in-tree source code, may
trigger warnings by various tools (the Debian linter flags them as
"source-not-available") and in general it's better if they're actually
generated via the in-tree Makefile.arch file.

Remove the binaries and temporarily drop the tests. We'll add proper
cross-compilation and re-enable them at a later stage.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agoshared: use memdup over stdndupa
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
shared: use memdup over stdndupa

The stdndupa has a couple of gotchas:
 - allocates memory on stack via alloca(3)... where we pass it a
   user-provided string in at least one instance
 - it's a GNU extension missing on musl and bionic

The mkdir_p() function is not a hot path, so using heap allocation is
perfectly fine. Swap the stdndupa for our local helper memdup.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/92
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: use bash strict mode for setup-rootfs.sh
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
testsuite: use bash strict mode for setup-rootfs.sh

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: swap ABS_TOP_BUILDDIR for TOOLS_DIR
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: swap ABS_TOP_BUILDDIR for TOOLS_DIR

All the remaining instances are used to track the tools directory (aka
the local symlinks to kmod). Rename accordingly and include the tools
sub-directory.

Similar to the OVERRIDE_LIBDIR change earlier, this is build system
specific layout, which shouldn't be in the tests.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite/path: match the full rootpath
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
testsuite/path: match the full rootpath

Our expectation is that the (full) rootpath is present, otherwise we
prepend it ourselves. Drop the ABS_TOP_BUILDDIR instance.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: set OVERRIDE_LIBDIR in the build system
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: set OVERRIDE_LIBDIR in the build system

The path is build-system specific, so set it there. Shortly we'll be
adding a meson build, where the value will be different.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: pass MODULE_DIRECTORY as arg to setup-rootfs.sh
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: pass MODULE_DIRECTORY as arg to setup-rootfs.sh

... just like the other 5 args passed to the script.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: fixup testsuite LDFLAGS
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: fixup testsuite LDFLAGS

Add the leading '-' for avoid-version, otherwise the module gets
versioned.

Drop the -export-dynamic, since the modules are built with
-fvisibility=hidden everything but the explicitly exported symbol is not
exported.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: alphabetically sort tests
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: alphabetically sort tests

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: alphabetically sort sources
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: alphabetically sort sources

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: remove linux/module.h check
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: remove linux/module.h check

We include the header for the UAPI MODULE_INIT_* constants, while we
also provide them locally.

At a glance, at least Arch and Alpine build kmod without the uapi
header, so just drop the check and ifndef guards all together.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: remove finit_module() check
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
build: remove finit_module() check

For over 10 years, init_module(2) has been pretty clear - glibc does not
provide a wrapper for the function. AFAICT musl never provided one
either.

Remove the always failing check.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomissing.h: remove be32toh wrapper
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
missing.h: remove be32toh wrapper

As the inline comment says, it is applicable for older distributions
like RHEL 5. The extended support for RHEL 5 ended in 2020 (4 years ago)
so we're safe to drop this.

According to the Alpine build logs - the symbol has been present in musl
for years.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agomissing.h: warn on missing __NR_finit_module
Emil Velikov [Thu, 22 Aug 2024 16:04:21 +0000 (17:04 +0100)] 
missing.h: warn on missing __NR_finit_module

Complain (somewhat) loudly if we don't have the syscall number, as the
default cannot work.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: set-but-unused variable KVER
Emil Velikov [Thu, 22 Aug 2024 16:04:20 +0000 (17:04 +0100)] 
testsuite: set-but-unused variable KVER

As far as I can see, nothing ever used the variable - be that within
kmod itself, or the Kbuild itself.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agotestsuite: remove cached modules and --disable-test-modules
Emil Velikov [Thu, 22 Aug 2024 16:04:20 +0000 (17:04 +0100)] 
testsuite: remove cached modules and --disable-test-modules

The option was added for distributions/maintainers lacking the linux
headers, while running the test-suite. It also aimed to resolve
licensing and "source-not-included" issues around the cached modules.

At a glance, it seems like only Debian is using the option these days,
Arch is using "any" linux headers available, while Fedora and Gentoo do
not run `make check` all together.

Debian's linter is complaining about "source-is-missing" and
"source-contains-prebuilt-binary", where the maintainer had to disable
those.

Removing the cache will make ^^ obsolete, while also simplifying the
check target. A nice side effect is making the (compressed) release
tarball 20% smaller.

Distributions are welcome to do something like Arch or not run the
target all together.

We are already running it in CI for Arch, Debian, Fedora and Ubuntu,
where more can be added as needed.

Effectively this reverts commit 23603f1f837caeff45c6960722c2cad690db801d

Lintian overrides:
https://salsa.debian.org/md/kmod/-/commit/8d6fc9e90b12fe88476c6c8f53ae25f9a0d5d634

Arch reference:
https://gitlab.archlinux.org/archlinux/packaging/packages/kmod/-/commit/b2d37d2bcc0ca2ef6187ce115ef8da105019d49f

The autopkgtest's copy of lsmod, ideally should use SPDX license
identifiers like we did in kmod v33.

Autopkgtest lsmod:
https://salsa.debian.org/md/kmod/-/commit/11793a49f6b65af8c442397a845e8b65008d0630

Cc: Marco d'Itri <md@linux.it>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
[ Fixup flag being passed in CI ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agobuild: remove --with-rootlibdir toggle
Emil Velikov [Thu, 22 Aug 2024 16:04:20 +0000 (17:04 +0100)] 
build: remove --with-rootlibdir toggle

At a glance this option was introduced with distributions migrating from
/lib to /usr/lib.

Checking with Debian, Arch, Alpine, Fedora and Gentoo - only Debian and
Alpine set it. In the former - it's explicitly set to the default
(libdir), while the latter uses /lib and /usr/lib respectively.

Looking at the implementation itself, we don't adjust the libkmod.pc
which lists libdir, while libkmod.so is installed in rootlibdir.

Considering the negligible user base and somewhat broken state, drop the
option.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agolibkmod: Treat illegal modinfo file as error
Tobias Stoeckmann [Wed, 21 Aug 2024 20:14:37 +0000 (22:14 +0200)] 
libkmod: Treat illegal modinfo file as error

The file modules.builtin.modinfo is supposed to consist of NUL
terminated strings. If the file contains a string which is not
properly NUL terminated, treat it as error.

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/83
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
11 months agolibkmod: Propagate correct errno values
Tobias Stoeckmann [Wed, 21 Aug 2024 20:42:32 +0000 (22:42 +0200)] 
libkmod: Propagate correct errno values

Make sure that errors never end up with errno being 0. These code paths
negate the errno value to get a negative value to propagate the fact
that an error occurred. -0 would be 0 again so errors are not detected.

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/83
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
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>