Commit Graph

1375 Commits

Author SHA1 Message Date
Lucas De Marchi 61a93a043a gitignore: ignore gtk-doc.make
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Lucas De Marchi ec8818bcfb libkmod-module: Fix return code for kmod_module_new_from_lookup()
When kmod_module_new_from_lookup() resolves to an alias, `err` will be
set to a positive value from the lookup function. Do not return a
positive value to follow the behavior when it matches a module name
and the documentation.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Lucas De Marchi 9dc4e5ccd4 test-initstate: Check for negative value on error
Documentation says kmod_module_new_from_lookup() returns < 0 on error
and 0 otherwise. There are bugs in libkmod however making it return
a positive value in some situations, that need to be fixed. However
it's best to check for the error explicitly like is done in the rest
of the library to avoid this kind of issues.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Lucas De Marchi 0246e06340 depmod: Stop opening modules.modinfo once per module
Since the addition of modules.aliases.bin, depmod has to open that
index multiple times and parse it over and over again:

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

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

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

Indexes still match:

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

Fix: https://github.com/kmod-project/kmod/issues/11
2022-02-11 22:06:34 -08:00
Lucas De Marchi 7a0f593de3 depmod: Do not duplicate builtin index
Now that libkmod uses modules.builtin.bin again, we don't need to add
the module names in modules.builtin.alias.bin and just add the aliases.

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

Before	After	index
21k	6.4K	modules.builtin.alias.bin
11k	 11K	modules.builtin.bin
2022-02-11 22:06:34 -08:00
Lucas De Marchi a965641625 libkmod: Prefer builtin index over builtin.alias
The modules.builtin.alias.bin is way larger than the
modules.builtin.bin.  On a normal "distro kernel":

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

From the kernel we get both modules.builtin and modules.builtin.modinfo.
depmod generates modules.builtin.bin and modules.builtin.alias.bin
from them respectively. modules.bultin is not going away: it's not
deprecated by the new index added. So, let's just stop duplicating the
information inside modules.builtin.alias.bin and just use the other
index.
2022-02-11 22:06:33 -08:00
Michal Suchanek 4e391ac92d libkmod: Set builtin to no when module is created from path.
A recent bug report showed that modinfo doesn't give the signature
information for certain modules, and it turned out to happen only on
the modules that are built-in on the running kernel; then modinfo
skips the signature check, as if the target module file never exists.
The behavior is, however, inconsistent when modinfo is performed for
external modules (no matter which kernel version is) and the module
file path is explicitly given by a command-line argument, which
guarantees the presence of the module file itself.

Fixes: e7e2cb61fa ("modinfo: Show information about built-in modules")
Link: https://lore.kernel.org/linux-modules/CAKi4VAJVvY3=JdSZm-GD1hJqyCPYaYz-jBJ_REeY5BakVb6_ww@mail.gmail.com/
BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1189537
Suggested-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2022-01-20 00:46:13 -08:00
Luis Chamberlain 43bdf97ce1 libkmod: add a library notice log level print
When you use pass the -v argument to modprobe we bump
the log level from the default modprobe log level of
LOG_WARNING (4) to LOG_NOTICE (5), however the library
only has avaiable to print:

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

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

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

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
2021-09-23 00:59:38 -07:00
Yauheni Kaliuta 64541d6aad libkmod-module: check "new_from_name" return value in get_builtin
kmod_module_new_from_name() may fail and return error value. It is
handled properly across the code, but in this particular place the
check is missing.

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2021-06-09 10:21:15 -07:00
Lucas De Marchi b6ecfc916a kmod 29 2021-05-20 16:02:57 -07:00
Lucas De Marchi b07bfb4a10 testsuite: update gitignore 2021-05-11 09:57:10 -07:00
Lucas De Marchi f0a1360761 depmod: fix modules.builtin.alias.bin output
Due to wrong documentation on kmod_module_get_info() we ended up
checking for 0 as return. Check for > 0 to decided if we want to write
the index to the file, otherwise we would output a 0-sized index on
success.
2021-05-11 09:49:35 -07:00
Lucas De Marchi 729f0f6853 Fix return value doc for kmod_module_get_info()
We don't return 0 on success, we return the number of elements we added
to the list.
2021-05-11 09:47:09 -07:00
Seung-Woo Kim 675410c3b3 libkmod: fix possible double free with wrong modules.builtin.modinfo
Fix double free for *modinfo with non '\0' terminated wrong
modules.builtin.modinfo, which is because EOF is minus value.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-04-17 13:41:42 -07:00
Seung-Woo Kim 1cab02ecf6 libkmod: fix an overflow with wrong modules.builtin.modinfo
Fix a possbile overflow with exact PATH_MAX length modname
in wrong modules.builtin.modinfo.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-04-17 13:41:42 -07:00
Lucas De Marchi ed892ff4ed gitignore: ignore .mbx and .cover for b4 integration
Lately I'm using b4 to work with the patches in the mailing list. Better
to start ignoring .cover and .mbx files since they get created by b4.
2021-04-17 13:39:12 -07:00
Seung-Woo Kim 39dd171623 libkmod-config: fix a memory leak when kmod_list_append() fails
From kmod_config_new(), when kmod_list_append() fails,
fix not list-appended kmod_config_path leak.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
2021-04-09 08:12:01 -07:00
Lucas De Marchi 8742be0aa5 libkmod-config: more chars allowed as space
Recently in a discussion I noticed that kernel allows more chars to be
considered as space in the kernel command line. Switch to the equivalent
of isspace() instead of considering only ' '.
2021-03-10 08:33:01 -08:00
Lucas De Marchi d8b31c34a6 test-modprobe: share single function for kcmdline tests 2021-02-15 11:53:43 -08:00
Lucas De Marchi b77251f08d testsuite: allow to re-use single function for tests
Add a new DEFINE_TEST_WITH_FUNC() that accepts the function
alongside the test name. This will allow us to share a single function
for different tests.
2021-02-15 11:53:43 -08:00
Lucas De Marchi d3a1fe67b6 libkmod-config: re-quote option from kernel cmdline
It was reported that grub mangles the kernel cmdline. It turns

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

	into

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

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

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

Reported-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Jessica Yu <jeyu@kernel.org>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
2021-02-15 11:53:43 -08:00
Lucas De Marchi 01ed9af61e libkmod-config: revamp kcmdline parsing into a state machine
The handling of spaces and quotes is becoming hard to maintain. Convert
the parser into a state machine so we can check all the states. This
should make it easier to fix a corner case we have right now:
The kernel also accepts a quote before the module name instead of the
value. But this additional is left for later. This is purely an
algorithm change with no behavior change.

Tested-by: Jessica Yu <jeyu@kernel.org>
2021-02-15 11:53:38 -08:00
Lucas De Marchi fd71604da9 testsuite: also test xz compression
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-02-05 19:54:31 -08:00
Lucas De Marchi 1921c370c2 testsuite: compress modules if feature is enabled
Since the output needs to be the same, regardless if the module is
compressed, change populate-modules.sh to conditionally compress the
module if that feature is enabled.

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

Suggested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Michal Suchánek <msuchanek@suse.de>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-02-05 19:52:00 -08:00
Dave Reisner 3cee67ddd7 populate-modules: Use more bash, more quotes
We're already using associatives arrays, so there's no reason we should
be using 'test'.
2021-01-23 11:06:15 -08:00
Lucas De Marchi 63fd63077d README: make github mirror official
For some time I've been maintaining a read-only mirror on github.
I think it's time to allow patches flowing from there besides the
mailing list: I created a new org to host the project:

	https://github.com/kmod-project/kmod
2021-01-20 18:52:53 -08:00
Lucas De Marchi 9319b0f4cb Support /usr/local for configuration files
Add /usr/local to the search path for configuration files. These are
intended for local installs, provided /usr/local is given as prefix.
2021-01-18 18:26:36 -08:00
Lucas De Marchi 1c10f32483 depmod: fix precedence order
Configuration in /etc should have higher prio than /run.
Given how rarely configuration in /run is used with depmod, this is
likely not to cause any problems, even if it's a change in behavior.
2021-01-18 18:26:36 -08:00
Lucas De Marchi 67e43bbe04 libkmod: Fix documentation on config precedence order
/etc is has higher priority than /run.
2021-01-18 18:26:36 -08:00
Marco d'Itri fa67110f89 Fix "modinfo -F always shows name for built-ins"
Bug reported by Ben Hutchings <ben@decadent.org.uk>:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=970871

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

	$ modinfo -Flicense e1000e
	GPL v2
	$ modinfo -Flicense bitrev
	name:           bitrev
	GPL
2021-01-07 20:17:48 -08:00
Lucas De Marchi c3771eddcb README: remove leftover from semaphoreci
We are not currently using semaphoreci, so remove leftover status from
README.
2021-01-07 19:51:40 -08:00
Marius Bakke 847247a4a8 testsuite: Automatically skip tests that fail when sysconfdir != /etc. 2021-01-07 19:44:50 -08:00
Marius Bakke b5683f45d9 testsuite: Add facility to skip tests.
The Makefile helpfully warns that some tests will fail when
--sysconfdir != /etc, but there are no provisions to easily disable
those.  This commit provides an escape hatch.

[ Lucas: add comment detailing the purpose of the field ]
2021-01-07 19:44:20 -08:00
Lucas De Marchi 1ccfe99428 kmod 28 2021-01-07 10:43:36 -08:00
Lucas De Marchi d977b0daf4 build: add comment with rules for libtool version update 2021-01-07 10:27:49 -08:00
Lucas De Marchi d83f488c60 build: fix distcheck due to missing zstd
Enable zstd since it's used in the testsuite.
2020-12-27 17:02:19 -08:00
Lucas De Marchi 30c9c4d90f testsuite: add test for empty modules.builtin.aliases.bin 2020-12-27 16:40:08 -08:00
Lucas De Marchi e4a72e4754 shared: fix UNIQ definition
We need a macro indirection for UNIQ to work. Otherwise it won't be
unique at all since it will just append "UNIQ" to the name:

In file included from testsuite/test-init.c:30:

testsuite/testsuite.h:142:27: error: redefinition of ‘stest_load_resourcesUNIQ’
2020-12-27 16:40:08 -08:00
Lucas De Marchi 220b4c55ec depmod: unconditionally write builtin.alias.bin
The file is always created and unless we return an error, the temporary
file is renamed to its final destination. All other places write the
index without checking if the index is empty, so just do the same.

Reported-by: Joe Buehler <aspam@cox.net>
2020-12-27 16:40:08 -08:00
Lucas De Marchi 4bd8586c20 ci: remove semaphoreci
It's currently failing and we are already covered by travis-ci.
2020-12-03 19:34:28 -08:00
Lucas De Marchi f9928f44ed ci: update travis distro
Don't bother with gcc 4.8 vs 4.9, just use the latest one for the
distro. Update travis to ubuntu 20.04 so we can get current
dependencies.
2020-12-03 19:34:04 -08:00
Shuo Wang c72433254e NEWS: fix typo 2020-12-03 01:46:11 -08:00
Yauheni Kaliuta 95ed3e7536 libkmod: kmod_log_null: qualify ctx argument as const
kmod_log_null() does not change ctx (does nothing).

Fix warnings

In file included from libkmod/libkmod-index.c:33:
libkmod/libkmod-index.c: In function ‘index_mm_open’:
libkmod/libkmod-index.c:757:6: warning: passing argument 1 of ‘kmod_log_null’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  757 |  DBG(ctx, "file=%s\n", filename);

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01 00:44:17 -08:00
Yauheni Kaliuta bd96d05256 depmod: output_builtin_alias_bin: free idx on error path
idx is allocated in the beginning but it's not freed if there is
a failure after the allocation.

Change the error path: return immediately if idx allocation fails
and then free it in both success and error path at the end.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01 00:44:17 -08:00
Yauheni Kaliuta 47807c4cfa libkmod: kmod_builtin_get_modinfo: free modinfo on error
The function allocates array but on building it if get_string()
fails it returns the error leaving the array allocated. The caller
does not care about it in error case either.

Free it to fix memory leak.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2020-12-01 00:44:17 -08:00
Samanta Navarro 2f38000256 man: fix typo 2020-10-19 09:12:53 -07:00
Torge Matthies 2e4ef3da55 testsuite: add test for zstd-compressed module
I took away one module from the gzip-compressed modules for this purpose.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-09-10 21:55:01 -07:00
Torge Matthies 3821e1971e add Zstandard compression support
I changed the style of the hackargs variable in autogen.sh to multiline
because said line was becoming a bit long with the new --with-zstd arg
added.

A previous version of this patch has been running on my two Arch Linux
installations (with an accompanying mkinitcpio patch) for several months
over many kernel updates without any issues.
Any additional testing and/or patch review would of course be appreciated.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-09-10 21:55:01 -07:00
Lucas De Marchi f5434cf5fc testsuite: add check for kmod_load_resources
Make sure we can call kmod_load_resources when we do have all the
mandatory indexes in place.
2020-03-23 12:39:58 -07:00
Lucas De Marchi d8d1d54051 libkmod: allow modules.alias.builtin to be optional 2020-03-23 12:37:51 -07:00