summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gladkov <gladkov.alexey@gmail.com>2019-04-29 12:11:14 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2019-05-07 08:50:24 -0400
commit898490c010b5d2e499e03b7e815fc214209ac583 (patch)
treefcd97072081ce9db13a84bb6463e55923479a171
parent4c11edfcf70bea4cb0a3f4992ac6a4852e8bdc31 (diff)
moduleparam: Save information about built-in modules in separate file
Problem: When a kernel module is compiled as a separate module, some important information about the kernel module is available via .modinfo section of the module. In contrast, when the kernel module is compiled into the kernel, that information is not available. Information about built-in modules is necessary in the following cases: 1. When it is necessary to find out what additional parameters can be passed to the kernel at boot time. 2. When you need to know which module names and their aliases are in the kernel. This is very useful for creating an initrd image. Proposal: The proposed patch does not remove .modinfo section with module information from the vmlinux at the build time and saves it into a separate file after kernel linking. So, the kernel does not increase in size and no additional information remains in it. Information is stored in the same format as in the separate modules (null-terminated string array). Because the .modinfo section is already exported with a separate modules, we are not creating a new API. It can be easily read in the userspace: $ tr '\0' '\n' < modules.builtin.modinfo ext4.softdep=pre: crc32c ext4.license=GPL ext4.description=Fourth Extended Filesystem ext4.author=Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others ext4.alias=fs-ext4 ext4.alias=ext3 ext4.alias=fs-ext3 ext4.alias=ext2 ext4.alias=fs-ext2 md_mod.alias=block-major-9-* md_mod.alias=md md_mod.description=MD RAID framework md_mod.license=GPL md_mod.parmtype=create_on_open:bool md_mod.parmtype=start_dirty_degraded:int ... Co-Developed-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org> Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org> Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com> Acked-by: Jessica Yu <jeyu@kernel.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
-rw-r--r--.gitignore1
-rw-r--r--Documentation/dontdiff1
-rw-r--r--Documentation/kbuild/kbuild.txt5
-rw-r--r--Makefile2
-rw-r--r--include/asm-generic/vmlinux.lds.h1
-rw-r--r--include/linux/module.h1
-rw-r--r--include/linux/moduleparam.h12
-rwxr-xr-xscripts/link-vmlinux.sh3
8 files changed, 19 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index e7bb6c6edbae..2fb1765c33b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,6 +58,7 @@ modules.builtin
58/vmlinuz 58/vmlinuz
59/System.map 59/System.map
60/Module.markers 60/Module.markers
61/modules.builtin.modinfo
61 62
62# 63#
63# RPM spec file (make rpm-pkg) 64# RPM spec file (make rpm-pkg)
diff --git a/Documentation/dontdiff b/Documentation/dontdiff
index ef25a066d952..512fa0239ebf 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -178,6 +178,7 @@ mktables
178mktree 178mktree
179modpost 179modpost
180modules.builtin 180modules.builtin
181modules.builtin.modinfo
181modules.order 182modules.order
182modversions.h* 183modversions.h*
183nconf 184nconf
diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt
index 8a3830b39c7d..9c230ea71963 100644
--- a/Documentation/kbuild/kbuild.txt
+++ b/Documentation/kbuild/kbuild.txt
@@ -11,6 +11,11 @@ modules.builtin
11This file lists all modules that are built into the kernel. This is used 11This file lists all modules that are built into the kernel. This is used
12by modprobe to not fail when trying to load something builtin. 12by modprobe to not fail when trying to load something builtin.
13 13
14modules.builtin.modinfo
15--------------------------------------------------
16This file contains modinfo from all modules that are built into the kernel.
17Unlike modinfo of a separate module, all fields are prefixed with module name.
18
14 19
15Environment variables 20Environment variables
16 21
diff --git a/Makefile b/Makefile
index 85dd977f4232..9a8b3f94633d 100644
--- a/Makefile
+++ b/Makefile
@@ -1308,6 +1308,7 @@ _modinst_:
1308 fi 1308 fi
1309 @cp -f $(objtree)/modules.order $(MODLIB)/ 1309 @cp -f $(objtree)/modules.order $(MODLIB)/
1310 @cp -f $(objtree)/modules.builtin $(MODLIB)/ 1310 @cp -f $(objtree)/modules.builtin $(MODLIB)/
1311 @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
1311 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1312 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1312 1313
1313# This depmod is only for convenience to give the initial 1314# This depmod is only for convenience to give the initial
@@ -1348,6 +1349,7 @@ endif # CONFIG_MODULES
1348 1349
1349# Directories & files removed with 'make clean' 1350# Directories & files removed with 'make clean'
1350CLEAN_DIRS += $(MODVERDIR) include/ksym 1351CLEAN_DIRS += $(MODVERDIR) include/ksym
1352CLEAN_FILES += modules.builtin.modinfo
1351 1353
1352# Directories & files removed with 'make mrproper' 1354# Directories & files removed with 'make mrproper'
1353MRPROPER_DIRS += include/config usr/include include/generated \ 1355MRPROPER_DIRS += include/config usr/include include/generated \
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f8f6f04c4453..bbb9e332f2fe 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -844,6 +844,7 @@
844 EXIT_CALL \ 844 EXIT_CALL \
845 *(.discard) \ 845 *(.discard) \
846 *(.discard.*) \ 846 *(.discard.*) \
847 *(.modinfo) \
847 } 848 }
848 849
849/** 850/**
diff --git a/include/linux/module.h b/include/linux/module.h
index 5bf5dcd91009..5f7007430d35 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -253,6 +253,7 @@ extern typeof(name) __mod_##type##__##name##_device_table \
253#define MODULE_VERSION(_version) MODULE_INFO(version, _version) 253#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
254#else 254#else
255#define MODULE_VERSION(_version) \ 255#define MODULE_VERSION(_version) \
256 MODULE_INFO(version, _version); \
256 static struct module_version_attribute ___modver_attr = { \ 257 static struct module_version_attribute ___modver_attr = { \
257 .mattr = { \ 258 .mattr = { \
258 .attr = { \ 259 .attr = { \
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index ba36506db4fb..5ba250d9172a 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -10,23 +10,21 @@
10 module name. */ 10 module name. */
11#ifdef MODULE 11#ifdef MODULE
12#define MODULE_PARAM_PREFIX /* empty */ 12#define MODULE_PARAM_PREFIX /* empty */
13#define __MODULE_INFO_PREFIX /* empty */
13#else 14#else
14#define MODULE_PARAM_PREFIX KBUILD_MODNAME "." 15#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
16/* We cannot use MODULE_PARAM_PREFIX because some modules override it. */
17#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
15#endif 18#endif
16 19
17/* Chosen so that structs with an unsigned long line up. */ 20/* Chosen so that structs with an unsigned long line up. */
18#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) 21#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
19 22
20#ifdef MODULE
21#define __MODULE_INFO(tag, name, info) \ 23#define __MODULE_INFO(tag, name, info) \
22static const char __UNIQUE_ID(name)[] \ 24static const char __UNIQUE_ID(name)[] \
23 __used __attribute__((section(".modinfo"), unused, aligned(1))) \ 25 __used __attribute__((section(".modinfo"), unused, aligned(1))) \
24 = __stringify(tag) "=" info 26 = __MODULE_INFO_PREFIX __stringify(tag) "=" info
25#else /* !MODULE */ 27
26/* This struct is here for syntactic coherency, it is not used */
27#define __MODULE_INFO(tag, name, info) \
28 struct __UNIQUE_ID(name) {}
29#endif
30#define __MODULE_PARM_TYPE(name, _type) \ 28#define __MODULE_PARM_TYPE(name, _type) \
31 __MODULE_INFO(parmtype, name##type, #name ":" _type) 29 __MODULE_INFO(parmtype, name##type, #name ":" _type)
32 30
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index dc0e8c5a1402..e4383e0f476e 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -193,6 +193,9 @@ modpost_link vmlinux.o
193# modpost vmlinux.o to check for section mismatches 193# modpost vmlinux.o to check for section mismatches
194${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o 194${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
195 195
196info MODINFO modules.builtin.modinfo
197${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo
198
196kallsymso="" 199kallsymso=""
197kallsyms_vmlinux="" 200kallsyms_vmlinux=""
198if [ -n "${CONFIG_KALLSYMS}" ]; then 201if [ -n "${CONFIG_KALLSYMS}" ]; then