Lucas De Marchi [Mon, 7 Jul 2025 16:42:41 +0000 (11:42 -0500)]
testsuite: Fix build warning on kernel 6.15
The module description is now required, otherwise a warning is emitted
by modpost:
WARNING: modpost: missing MODULE_DESCRIPTION() in mod-loop-k.o
Fix all of them with:
sed -i '/MODULE_LICENSE("LGPL");/a MODULE_DESCRIPTION("dummy test module");' testsuite/module-playground/mod-*.c
sed -i '/MODULE_LICENSE("GPL");/a MODULE_DESCRIPTION("dummy test module");' testsuite/module-playground/mod-simple.c
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 16 Jun 2025 23:30:40 +0000 (00:30 +0100)]
ci: 'temporary' disable sanitizers for 32bit builds
Currently running 32bit tests alongside sanitizers, segfaults due to our
syscall wrapper. Just disable the sanitizers, which means we get at
least some 32bit test coverage.
On a couple of attempts, I wasn't able to get a proper/robust solution,
as outlined in init_module.c - we need vsyscall() which does not exist.
Considering some distributions are dropping 32bit/i686 support, it may
be that we'll nuke these builds from CI sooner than later.
Emil Velikov [Sat, 21 Jun 2025 10:13:15 +0000 (11:13 +0100)]
CONTRIBUTING.md: make it common markdown compatible
Adjust the markdown variant, so it renders correctly in both GitHub and
cgit (... vim also seems happier fwiw). AFAICT the latter is using
CommonMarkdown as handled by python-markdown.
Emil Velikov [Sat, 21 Jun 2025 10:09:50 +0000 (11:09 +0100)]
README.md: make it common markdown compatible
Adjust the markdown variant, so it renders correctly in both GitHub and
cgit (... vim also seems happier fwiw). AFAICT the latter is using
CommonMarkdown as handled by python-markdown.
Earlier commit used a global sed to remove the no-longer needed
exit(EXIT_FAILURE) calls. In the process it also removed one instance
in the error path, which should remain.
Fixes: e09acf2e ("testsuite: remove exit from EXEC_TOOL tests") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/379 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Co-authored-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Link: https://github.com/kmod-project/kmod/pull/378 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Fri, 13 Jun 2025 16:45:34 +0000 (17:45 +0100)]
testsuite: always exit() from the child process
Update the existing code-paths to always exit() for the child process.
We already handle that in a few places, but the error-paths are
(understandably) off.
Emil Velikov [Fri, 13 Jun 2025 18:48:18 +0000 (19:48 +0100)]
testsuite: use ARRAY_SIZE() for iteration
Currently we use a mix of ARRAY_SIZE() and iterator pointer, where the
latter needs an extra instance for the NULL sentinel. Plus as evidenced
by the EXIT_SUCCESS -> EXIT_FAILURE changes in test-new-module - is
error prone.
Consistently use ARRAY_SIZE(), fixing the logical error in the test
which was flagged by ASan as memory leak :-)
Emil Velikov [Fri, 13 Jun 2025 18:44:25 +0000 (19:44 +0100)]
testsuite: static const annotate the remaining test data
A while ago we annotated a bunch of of the tests although I missed some
during grepping. Update the final instances, taking the chance to move
the strdup instances into the test loop and failing the test should the
duplication fails.
Lucas De Marchi [Fri, 13 Jun 2025 18:57:08 +0000 (13:57 -0500)]
tools/modprobe: Fix odd --remove-holders behavior
--remove-holders was not implying --remove, which means that if the user
called `modprobe --remove-holders xe` it would actually try to insert
the xe module. Fix it and spell it out in the man page about one option
implying the other.
Emil Velikov [Mon, 16 Jun 2025 06:32:06 +0000 (07:32 +0100)]
ci: remove Alpine -Ddocs=false WA
A while ago the Alpine gtk-doc tool chain was having issues building our
docs. That got resolved at some point over the past months, so we can
drop this local workaround.
Emil Velikov [Mon, 19 May 2025 20:08:26 +0000 (21:08 +0100)]
tools/modprobe: accept module name with --show-modversions
Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
- modprobe --show-modversions drm-vram-helper, alongside the existing
- modprobe --show-modversions /full/path/to/the/module/drm_vram_helper.ko
Emil Velikov [Mon, 19 May 2025 20:08:26 +0000 (21:08 +0100)]
tools/modprobe: accept module name with --show-exports
Use the newly introduced helper module_new_from_any(), so we accept both
files as well as modules. This means you can now do:
- modprobe --show-exports drm-vram-helper, alongside the existing
- modprobe --show-exports /full/path/to/the/module/drm_vram_helper.ko
Emil Velikov [Fri, 30 May 2025 18:11:48 +0000 (19:11 +0100)]
tools/modprobe: standardize on --show-foo, deprecate the rest
Currently we have a range of options which show specific details,
although they vary in prefix or spelling:
- prefix: dump vs resolve vs show
- with and without dash after show
Converge on --show-foo and deprecate the rest. The old options are still
accepted but will throw a warning. Only the (new) consistent names are
listed in --help, while the manual page lists both but spells out that
the old ones will be removed.
To avoid any confusion with --show (aka --dry-run) the option is also
soft-deprecated.
Emil Velikov [Fri, 30 May 2025 18:23:04 +0000 (19:23 +0100)]
man/modprobe.8: document --remove-holders
The option was introduced a few years ago, yet the manual page went
without an update. Add some basic documentation.
Cc: Lucas De Marchi <lucas.demarchi@intel.com> Fixes: 42b32d30 ("modprobe: Fix holders removal") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/353 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)]
tools/depmod: don't use %m on kmod_new() failure
The KMOD API returns NULL on error and getting the exact means why it
failed is undefined. In practise the errno is set in _some_ of the error
paths, but not all.
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)]
libkmod: don't use %m on read_str_ulong() failure
The function returns the actual error itself, identically to the signed
variant - read_str_long(). Unlike the signed variant, one of ulong's
users incorrectly uses %m instead of strerror(-err).
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)]
libkmod: don't use %m on strbuf_to_vector() failure
The function does not set the errno on overflow conditions, so the ERR()
will produce (somewhat) arbitrary strerror. Similar to other places
throughout the code base - just use ENOMEM.
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)]
Use explicit ENOMEM when {m,re}alloc fails
Currently our codebase has a mix of explicitly using ENOMEM and
propagating the errno... The latter of which is guaranteed to be ENOMEM
as documented in the manual pages.
Consolidate on ENOMEM, both for consistency sake and to remove a few
bytes off our binaries ;-)
Emil Velikov [Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)]
libkmod: return ENOMEM when strbuf_pushchar(s) fails
Currently get_strings() assumes that errno is set when either function
fails. This is not the case when our overflow checks kick in. The other
case where these functions fail is memory exhaustion.
In practice we cannot do anything if either of those trigger, plus I
don't see a compelling reason to set errno to EOVERFLOW... Something
which other parts of the codebase don't do.
So let's just return ENOMEM and avoid the corner case of returning
success from get_strings(), when it should be failing.
Fixes: 1005e99e ("libkmod: refactor builtin module handling") Fixes: 952bf223 ("strbuf: Add strbuf_reserve_extra()") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/368 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The function signature for our printers is uniform, even though in one
of the instances a parameter is unused. There is not much we can do
here, just silence the compiler warning.
The implementation of our "hash_free" function varies in that the hash
data itself is not freed. Thus the function argument is unused, leading
to annoying compiler warning. Since there is nothing to be done here,
just silence it.
Emil Velikov [Thu, 29 May 2025 14:31:36 +0000 (15:31 +0100)]
testsuite/{init,delete}_module: add TODOs for args validation
Currently we pass arguments to our *_module wrappers, which are lacking
any validation. Add a few TODO notes and silence the unused argument
compiler warnings.
Emil Velikov [Fri, 30 May 2025 10:52:27 +0000 (11:52 +0100)]
libkmod: silence unused param warnings for kmod_file_load_*() stubs
When building without compression, the respective load functions are
static inline header stubs. In which case the struct kmod_file *file is
always unused and the compiler rightfully warns about it.
Not much we can do here, other than annotate them to silence the
warnings.
Emil Velikov [Fri, 30 May 2025 10:00:13 +0000 (11:00 +0100)]
shared: properly __attribute__ all macros
Handful of the attributes were missing the trailing double underscore.
Thus they were not picked by our git grep combo and ultimately missing
from .clang-format.
Emil Velikov [Tue, 3 Jun 2025 17:55:03 +0000 (18:55 +0100)]
clang-format: update attribute macros
Use the command to update the attribute macros list. Seemingly we've
updated the list manually, which meant that a) some symbols were not
annotated the expected way and b) some macros were not picked up.
First we start with auto-generating the list, the other issues will be
handled as follow-ups.
Emil Velikov [Tue, 3 Jun 2025 22:06:48 +0000 (23:06 +0100)]
ci: install and use bash across the board
The upcoming CI rework will hard depend on some bash constructs. While
theoretically possible to make them dash compliant, I'm not sure it's
worth the effort. Just install bash and carry on.
Emil Velikov [Tue, 3 Jun 2025 21:46:47 +0000 (22:46 +0100)]
ci: use meson bla -C builddir/
Use builddir/ as indicated in our README, which makes it obvious that
what the argument is. While there, remove a few instances of mkdir/cd -
meson and ninja can handle it themselves.
On Arch (at least) the shell chokes when the CC variable contains space,
for the given construct - $("$CC" foobar).
Since we variable is likely to contain the executable and arguments, the
quotation is wrong. Drop it and ultimately resolve the LD_PRELOAD
issues... That said, the tests still fail over here, segfault-ing in (or
due to) the LD_PRELOAD library init-modules.so.
Fixes: f5b4ff82 ("Add support for clang sanitizers") Fixes: c7686797 ("scripts/sanitizer-env.sh: support new clang 19 DSO") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/365 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
dependabot[bot] [Sun, 1 Jun 2025 01:46:06 +0000 (01:46 +0000)]
ci: bump the all-actions group with 2 updates
Bumps the all-actions group with 2 updates: [github/codeql-action](https://github.com/github/codeql-action) and [codecov/codecov-action](https://github.com/codecov/codecov-action).
Updates `github/codeql-action` from 3.28.16 to 3.28.18
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/28deaeda66b76a05916b6923827895f2b14ab387...ff0a06e83cb2de871e5a09832bc6a81e7276941f)
Updates `codecov/codecov-action` from 5.4.2 to 5.4.3
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/ad3126e916f78f00edff4ed0317cf185271ccc2d...18283e04ce6e62d37312384ff67231eb8fd56d24)
Emil Velikov [Sat, 24 May 2025 15:10:11 +0000 (16:10 +0100)]
tools/depmod: use nsec granularity when checking timestamps
Current code uses the POSIX.1-2001 stat::st_mtime which has one second
granularity. Considering the depmod execution time may be smaller, we
should be using the POSIX.1-2008 stat::st_mtim which has nano-second
granularity instead.
Emil Velikov [Sat, 24 May 2025 14:40:49 +0000 (15:40 +0100)]
Remove dietlibc stat::st_mtim workaround
Some versions of dietlibc lack struct stat::st_mtim, which was
introduced with POSIX.1-2008.
Considering the slow development cycle of dietlibc (last three releases
are 2024, 2018 and 2013) and there's no popular user (nor one in CI) of
it, let's remove the workaround.
All the other runtimes that we target - glibc, bionic and musl - have
the struct member.
Iff needed we can reintroduce the workaround at a later stage alongside
a CI permutation.
Emil Velikov [Thu, 29 May 2025 09:26:29 +0000 (10:26 +0100)]
README: update C runtime library section
Our readme lists uClibc which has been EOL for over a decade and
superseded by uClibc-ng. In addition, in one place our code-base tries
to support dietlibc for some pre POSIX.1-2008 functionality.
Explicitly list POSIX.1-2008 alongside the C runtime libraries, which
are known to work.
If your favourite C library does not work with kmod, feel free to send
us patches - plus ideally one which adds a CI action for us to test.
Emil Velikov [Thu, 29 May 2025 09:21:47 +0000 (10:21 +0100)]
README: explicitly document compiler requirements
Document C11 + GNU extensions as the requirement, omitting the exact
list of extensions since it's quite a bit.
The minimum compiler versions are somewhat arbitrary - we don't check
for them, so your experience may vary. Patches to update the README, or
to make kmod more widely buildable are welcome.
Emil Velikov [Sat, 24 May 2025 15:21:18 +0000 (16:21 +0100)]
Convert most #ifdef HAVE_FOO checks to #if HAVE_FOO
The former is somewhat error prone, since the pre-processor will
evaluate the presence of the define, which might have been omitted due
to wrong include or otherwise.
Swap for the other solution we already have in-tree - always set the
relevant define(s) and evaluate them numerically. That combined with
-Wundef means that we'll get meaningful compiler warning when we get
something wrong.
The strto* family of functions may fail if the input string contains
a number which is too large for the designated data type. In such
cases, errno is set to ERANGE. Check for this error condition and if
subsequent casts would truncate the value.
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/357 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Thu, 29 May 2025 08:30:58 +0000 (09:30 +0100)]
Remove default initializer for static variables
The spec dictates that static variables are initialized to 0/NULL.
Remove the unnecessary explicit initialization - on older compilers this
sheds a few bytes off the data section of respective binaries.
Emil Velikov [Sat, 24 May 2025 18:18:27 +0000 (19:18 +0100)]
libkmod: s/* const/*const/ style nitpick
Portion of the header is annotated as clang-format off, to prevent
unwanted over formatting by clang. At the same time, a few erroneous
spaces slipped in.
Emil Velikov [Sat, 24 May 2025 15:03:08 +0000 (16:03 +0100)]
tools/depmod: remove set but unused timeval
No longer needed since the introduction of tmpfile-util.
Fixes: aae48bc9 ("depmod: add tmpfile-util to generate temporary file") Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/358 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Sat, 24 May 2025 12:23:09 +0000 (13:23 +0100)]
testsuite/path: defer and inline get_rootpath()
In a handful of use-cases, we don't need to trap the respective libc
function. Although at that point we have already fetched the rootfs
environment variable.
Defer it until it's needed and in the process inline the function. As
result we have a) less duplication in the wrappers and b) the rootpath
handling is no longer split across multiple functions.
Emil Velikov [Sat, 24 May 2025 11:57:11 +0000 (12:57 +0100)]
testsuite: fprintf() + abort() when dlsym() returns NULL
Currently each of our three dlsym() instances behaves differently. From
seg-faulting, to abort() to assert(). Just use abort throughout, since
assert() is no-op when NDEBUG is defined.
Emil Velikov [Sat, 24 May 2025 11:06:13 +0000 (12:06 +0100)]
libkmod: use strlen() for string literals
Older compilers had struggles expanding strlen(string-literal) to a
constant compile time expression. Thus our code-base used sizeof() - 1
instead.
This has been resolved for years, so let's use the correct function. As
a bonus point, we can remove a few variable making the code tad easier
to follow.
Emil Velikov [Sat, 24 May 2025 16:40:47 +0000 (17:40 +0100)]
meson: disable Wdeclaration-after-statement
Having declarations after statement is a C90 requirement, which was
relaxed with C99. While there are some arguments for having it enabled
in new code, there are benefits to the contrary which are more appealing
IMHO.
Namely, by keeping the declarations where the variables are used, better
outlines the scope, reduces chances of shadowing and helps us avoid
"unused variable" compiler warning in some paths.
Flip the warning to -Wno for now and future patches can remove some of
the workarounds we have in-tree.
We don't have any moversion/vermagic tests. This patch add testsuite
--force-{vermagic,modversion} for modprobe.
Link: https://github.com/kmod-project/kmod/pull/344 Signed-off-by: Rong Tao <rongtao@cestc.cn> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Wed, 7 May 2025 17:58:11 +0000 (18:58 +0100)]
libkmod: update remaining function to return the error code
Rework the function signature and return the error code instead of the
stripped module. Thus we no longer explicitly set errno.
v2:
- kmod_file_open() - use _cleanup_free_, return errno instead of ENOMEM
Reference: https://github.com/kmod-project/kmod/issues/244 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/346 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>