From b74d7bb7ca2412ab37bab782591573b5f265872b Mon Sep 17 00:00:00 2001 From: Luis Chamberlain Date: Wed, 14 Dec 2022 15:17:18 -0800 Subject: [PATCH 1/6] kbuild: Modify default INSTALL_MOD_DIR from extra to updates The default INSTALL_MOD_DIR of using the /lib/modules/$(uname -r)/extra directory for external modules assumes distributions will have something like /etc/depmod.d/dist.conf with: search updates extra built-in However, only some Red Hat releases have and use the "extra" stuff for years now. Meanwhile, the depmod.c tool in kmod has *forever* used the "updates" directory as part of the search path by default *if* your distribution does not have any depmod.d configuration. If you compile and install an external module today, even upstream kernel mock drivers (tools/testing/cxl) the modules_install target will pick up the new drivers but will not allow override of drivers from updates to override built-in ones. Since module-init-tools was deprecated over 11 years ago and now kmod has since its inception used the "updates" directory as part of its default search path to allow overrides, and since the "extra" stuff was in practice only used by Red Hat stuff, use the more distro agnostic override path "updates" to allow external modules to also override proper production kernel modules. This would allow mocking drivers tools to not have to muck with depmod.d config files or assume that your distro will have extra on a configuration file over built-in. With today's default you end up actually *crashing* Linux when trying to load cxl_test with the default "extra" [0] directory being used. This fixes that and allows other mocking drivers to do less work. [0] https://lkml.kernel.org/r/20221209062919.1096779-1-mcgrof@kernel.org Signed-off-by: Luis Chamberlain Acked-by: Dan Williams Acked-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.modinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 836391e5d209..f598eb83f776 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -14,7 +14,7 @@ modules := $(call read-file, $(MODORDER)) ifeq ($(KBUILD_EXTMOD),) dst := $(MODLIB)/kernel else -INSTALL_MOD_DIR ?= extra +INSTALL_MOD_DIR ?= updates dst := $(MODLIB)/$(INSTALL_MOD_DIR) endif From c093a74dac1c008daee92d6d613e9e3fe20b6585 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Mon, 2 Jan 2023 13:16:05 -0800 Subject: [PATCH 2/6] test_kmod: stop kernel-doc warnings Use kernel-doc notation to prevent warnings: lib/test_kmod.c:58: warning: contents before sections lib/test_kmod.c:94: warning: cannot understand function prototype: 'struct kmod_test_device_info ' lib/test_kmod.c:119: warning: cannot understand function prototype: 'struct kmod_test_device ' Signed-off-by: Randy Dunlap Cc: Luis Chamberlain Cc: linux-modules@vger.kernel.org Signed-off-by: Luis Chamberlain --- lib/test_kmod.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/test_kmod.c b/lib/test_kmod.c index 6423df9fa8dd..43d9dfd57ab7 100644 --- a/lib/test_kmod.c +++ b/lib/test_kmod.c @@ -51,12 +51,11 @@ static int num_test_devs; /** * enum kmod_test_case - linker table test case - * - * If you add a test case, please be sure to review if you need to se - * @need_mod_put for your tests case. - * * @TEST_KMOD_DRIVER: stress tests request_module() * @TEST_KMOD_FS_TYPE: stress tests get_fs_type() + * + * If you add a test case, please be sure to review if you need to set + * @need_mod_put for your tests case. */ enum kmod_test_case { __TEST_KMOD_INVALID = 0, @@ -78,7 +77,7 @@ struct test_config { struct kmod_test_device; /** - * kmod_test_device_info - thread info + * struct kmod_test_device_info - thread info * * @ret_sync: return value if request_module() is used, sync request for * @TEST_KMOD_DRIVER @@ -101,7 +100,7 @@ struct kmod_test_device_info { }; /** - * kmod_test_device - test device to help test kmod + * struct kmod_test_device - test device to help test kmod * * @dev_idx: unique ID for test device * @config: configuration for the test From def7b92efd868a6c78da86770704c1a03506016e Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Sat, 14 Jan 2023 10:08:13 +0100 Subject: [PATCH 3/6] kernel/params.c: Use kstrtobool() instead of strtobool() strtobool() is the same as kstrtobool(). However, the latter is more used within the kernel. In order to remove strtobool() and slightly simplify kstrtox.h, switch to the other function name. While at it, include the corresponding header file () Signed-off-by: Christophe JAILLET Reviewed-by: Miroslav Benes Signed-off-by: Luis Chamberlain --- kernel/params.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/params.c b/kernel/params.c index 14d66070757b..6e34ca89ebae 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -310,7 +311,7 @@ int param_set_bool(const char *val, const struct kernel_param *kp) if (!val) val = "1"; /* One of =[yYnN01] */ - return strtobool(val, kp->arg); + return kstrtobool(val, kp->arg); } EXPORT_SYMBOL(param_set_bool); From fbed4fea6422a237382bf317db88a37993955f3b Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Tue, 1 Nov 2022 22:14:06 +0100 Subject: [PATCH 4/6] module: Use kstrtobool() instead of strtobool() strtobool() is the same as kstrtobool(). However, the latter is more used within the kernel. In order to remove strtobool() and slightly simplify kstrtox.h, switch to the other function name. While at it, include the corresponding header file () Signed-off-by: Christophe JAILLET Reviewed-by: Luis Chamberlain Reviewed-by: Aaron Tomlin Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 4ac3fe43e6c8..d3be89de706d 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -2675,7 +2676,7 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname, int ret; if (strcmp(param, "async_probe") == 0) { - if (strtobool(val, &mod->async_probe_requested)) + if (kstrtobool(val, &mod->async_probe_requested)) mod->async_probe_requested = true; return 0; } From eca0edaf6caa66b6eb26277a7dce5d7296cedfca Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Fri, 3 Feb 2023 09:22:21 -0300 Subject: [PATCH 5/6] module.h: Document klp_modinfo struct using kdoc Previously the documentation existed only in Documentation/livepatch directory. Signed-off-by: Marcos Paulo de Souza Signed-off-by: Luis Chamberlain --- include/linux/module.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/module.h b/include/linux/module.h index 8c5909c0076c..6449ea59c074 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -352,6 +352,14 @@ struct mod_kallsyms { }; #ifdef CONFIG_LIVEPATCH +/** + * struct klp_modinfo - Elf information preserved from the livepatch module + * + * @hdr: Elf header + * @sechdrs: Section header table + * @secstrings: String table for the section headers + * @symndx: The symbol table section index + */ struct klp_modinfo { Elf_Ehdr hdr; Elf_Shdr *sechdrs; From f412eef03938d3a40d4f6f5a79d0f98ed89b596d Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Fri, 3 Feb 2023 09:22:22 -0300 Subject: [PATCH 6/6] Documentation: livepatch: module-elf-format: Remove local klp_modinfo definition Refer to klp_modinfo declaration using kdoc. Signed-off-by: Marcos Paulo de Souza Signed-off-by: Luis Chamberlain --- Documentation/livepatch/module-elf-format.rst | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Documentation/livepatch/module-elf-format.rst b/Documentation/livepatch/module-elf-format.rst index 7347638895a0..d48f530c0881 100644 --- a/Documentation/livepatch/module-elf-format.rst +++ b/Documentation/livepatch/module-elf-format.rst @@ -298,12 +298,5 @@ A livepatch module's symbol table is accessible through module->symtab. Since apply_relocate_add() requires access to a module's section headers, symbol table, and relocation section indices, Elf information is preserved for livepatch modules and is made accessible by the module loader through -module->klp_info, which is a klp_modinfo struct. When a livepatch module loads, -this struct is filled in by the module loader. Its fields are documented below:: - - struct klp_modinfo { - Elf_Ehdr hdr; /* Elf header */ - Elf_Shdr *sechdrs; /* Section header table */ - char *secstrings; /* String table for the section headers */ - unsigned int symndx; /* The symbol table section index */ - }; +module->klp_info, which is a :c:type:`klp_modinfo` struct. When a livepatch module +loads, this struct is filled in by the module loader.