Add generated modalias to modules.builtin.modinfo
Subsystems (10)
v4 cover Add generated modalias to modules.builtin.modinfo
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to get information about builtin modules. Among other information about the module, information about module aliases is stored. This is very important to determine that a particular modalias will be handled by a module that is inside the kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the MODULE_ALIAS of the macro. In this case, the aliases go into the '.modinfo' section of the module if it is compiled separately or into vmlinux.o if it is builtin into the kernel.
The second is the use of MODULE_DEVICE_TABLE followed by the use of the modpost utility. In this case, vmlinux.o no longer has this information and does not get it into modules.builtin.modinfo.
For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.
$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller Driver
The builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
To fix this it is necessary to add the generated by modpost modalias to modules.builtin.modinfo.
Fortunately modpost already generates .vmlinux.export.c for exported symbols. It is possible to use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.
Notes:
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/[email protected]/
- v3:
* Add Reviewed-by tag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/
- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/[email protected]/
Alexey Gladkov (3):
scsi: Always define blogic_pci_tbl structure
modpost: Add modname to mod_device_table alias
modpost: Create modalias for builtin modules
Masahiro Yamada (4):
module: remove meaningless 'name' parameter from __MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
drivers/scsi/BusLogic.c | 2 - include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 21 ++++----- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- rust/kernel/device_id.rs | 8 ++-- scripts/Makefile.vmlinux | 74 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 6 +++ scripts/mod/file2alias.c | 34 ++++++++++++-- scripts/mod/modpost.c | 17 ++++++- scripts/mod/modpost.h | 2 + 13 files changed, 131 insertions(+), 78 deletions(-)
Signature · 1 line
2.49.0
PATCH v4 1/7 module: remove meaningless 'name' parameter from __MODULE_INFO()
From: Masahiro Yamada <[email protected]>
The symbol names in the .modinfo section are never used and already randomized by the __UNIQUE_ID() macro.
Therefore, the second parameter of __MODULE_INFO() is meaningless and can be removed to simplify the code.
With this change, the symbol names in the .modinfo section will be prefixed with __UNIQUE_ID_modinfo, making it clearer that they originate from MODULE_INFO().
[Before]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_license560 0000000000000011 r __UNIQUE_ID_file559 0000000000000030 r __UNIQUE_ID_description558 0000000000000074 r __UNIQUE_ID_license580 000000000000008e r __UNIQUE_ID_file579 00000000000000bd r __UNIQUE_ID_description578 00000000000000e6 r __UNIQUE_ID_license581 00000000000000ff r __UNIQUE_ID_file580 0000000000000134 r __UNIQUE_ID_description579 0000000000000179 r __UNIQUE_ID_uncore_no_discover578
[After]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_modinfo560 0000000000000011 r __UNIQUE_ID_modinfo559 0000000000000030 r __UNIQUE_ID_modinfo558 0000000000000074 r __UNIQUE_ID_modinfo580 000000000000008e r __UNIQUE_ID_modinfo579 00000000000000bd r __UNIQUE_ID_modinfo578 00000000000000e6 r __UNIQUE_ID_modinfo581 00000000000000ff r __UNIQUE_ID_modinfo580 0000000000000134 r __UNIQUE_ID_modinfo579 0000000000000179 r __UNIQUE_ID_modinfo578
--- include/crypto/algapi.h | 4 ++-- include/linux/module.h | 3 --- include/linux/moduleparam.h | 9 +++++---- include/net/tcp.h | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-)
include/crypto/algapi.h +2 -2
@@ -43,8 +43,8 @@* alias. */ #define MODULE_ALIAS_CRYPTO (name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_crypto, "crypto-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "crypto-" name)struct crypto_aead ;struct crypto_instance ;
include/linux/module.h +0 -3
@@ -164,9 +164,6 @@ extern void cleanup_module(void);struct module_kobject *lookup_or_create_module_kobject (const char *name); -/* Generic info of form tag = "info" */ -#define MODULE_INFO (tag, info) __MODULE_INFO(tag, tag, info) -/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias)
include/linux/moduleparam.h +5 -4
@@ -20,18 +20,19 @@/* Chosen so that structs with an unsigned long line up. */ #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) -#define __MODULE_INFO (tag, name, info) \ - static const char __UNIQUE_ID(name)[] \ +/* Generic info of form tag = "info" */ +#define MODULE_INFO (tag, info) \ + static const char __UNIQUE_ID(modinfo)[] \ __used __section(".modinfo") __aligned(1) \ = __MODULE_INFO_PREFIX __stringify(tag) "=" info#define __MODULE_PARM_TYPE (name, _type) \ - __MODULE_INFO(parmtype, name##type, #name ":" _type) + MODULE_INFO(parmtype, #name ":" _type)/* One for each parameter, describing how to use it. Some files do multiple of these per line, so can't just use MODULE_INFO. */ #define MODULE_PARM_DESC (_parm, desc) \ - __MODULE_INFO(parm, _parm, #_parm ":" desc) + MODULE_INFO(parm, #_parm ":" desc)struct kernel_param ;
include/net/tcp.h +2 -2
@@ -2662,8 +2662,8 @@ void tcp_update_ulp(struct sock *sk, struct proto *p, void (*write_space)(struct sock *sk));#define MODULE_ALIAS_TCP_ULP (name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_tcp_ulp, "tcp-ulp-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "tcp-ulp-" name)#ifdef CONFIG_NET_SOCK_MSG struct sk_msg ;
Signature · 1 line
2.49.0
PATCH v4 2/7 kbuild: always create intermediate vmlinux.unstripped
In reply to Alexey GladkovFrom: Masahiro Yamada <[email protected]>
Generate the intermediate vmlinux.unstripped regardless of CONFIG_ARCH_VMLINUX_NEEDS_RELOCS.
If CONFIG_ARCH_VMLINUX_NEEDS_RELOCS is unset, vmlinux.unstripped and vmlinux are identiacal.
This simplifies the build rule, and allows to strip more sections by adding them to remove-section-y.
--- scripts/Makefile.vmlinux | 45 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
scripts/Makefile.vmlinux +22 -23
@@ -9,20 +9,6 @@ include $(srctree)/scripts/Makefile.lib targets := -ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS -vmlinux-final := vmlinux.unstripped - -quiet_cmd_strip_relocs = RSTRIP $@ - cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' --remove-section=!'.rel*.dyn' $< $@ - -vmlinux: $(vmlinux-final) FORCE - $(call if_changed,strip_relocs) - -targets += vmlinux -else -vmlinux-final := vmlinux -endif - %.o: %.c FORCE $(call if_changed_rule,cc_o_c)
@@ -61,19 +47,19 @@ targets += .builtin-dtbs-list ifdef CONFIG_GENERIC_BUILTIN_DTB targets += .builtin-dtbs.S .builtin-dtbs.o -$(vmlinux-final): .builtin-dtbs.o +vmlinux.unstripped: .builtin-dtbs.o endif -# vmlinux +# vmlinux.unstripped # --------------------------------------------------------------------------- ifdef CONFIG_MODULES targets += .vmlinux.export.o -$(vmlinux-final): .vmlinux.export.o +vmlinux.unstripped: .vmlinux.export.o endif ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX -$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o +vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
@@ -86,17 +72,30 @@ cmd_link_vmlinux = \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) -targets += $(vmlinux-final) -$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +targets += vmlinux.unstripped +vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +$(call if_changed_dep,link_vmlinux) ifdef CONFIG_DEBUG_INFO_BTF -$(vmlinux-final): $(RESOLVE_BTFIDS) +vmlinux.unstripped: $(RESOLVE_BTFIDS) endif ifdef CONFIG_BUILDTIME_TABLE_SORT -$(vmlinux-final): scripts/sorttable +vmlinux.unstripped: scripts/sorttable endif +# vmlinux +# --------------------------------------------------------------------------- + +remove-section-y := +remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' + +quiet_cmd_strip_relocs = OBJCOPY $@ + cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@ + +targets += vmlinux +vmlinux: vmlinux.unstripped FORCE + $(call if_changed,strip_relocs) + # modules.builtin.ranges # --------------------------------------------------------------------------- ifdef CONFIG_BUILTIN_MODULE_RANGES
@@ -110,7 +109,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ modules.builtin vmlinux.map vmlinux.o.map FORCE $(call if_changed,modules_builtin_ranges) -vmlinux.map: $(vmlinux-final) +vmlinux.map: vmlinux.unstripped @: endif
Signature · 1 line
2.49.0
PATCH v4 3/7 kbuild: keep .modinfo section in vmlinux.unstripped
In reply to Alexey GladkovFrom: Masahiro Yamada <[email protected]>
Keep the .modinfo section during linking, but strip it from the final vmlinux.
Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
This change will allow the next commit to extract the .modinfo section from the vmlinux.unstripped intermediate.
--- include/asm-generic/vmlinux.lds.h | 2 +- scripts/Makefile.vmlinux | 2 +- scripts/mksysmap | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-)
include/asm-generic/vmlinux.lds.h +1 -1
@@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)/* Required sections not related to debugging. */ #define ELF_DETAILS \ + .modinfo : { *(.modinfo) } \ .comment 0 : { *(.comment) } \ .symtab 0 : { *(.symtab) } \ .strtab 0 : { *(.strtab) } \
@@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) *(.discard.*) \ *(.export_symbol) \ *(.no_trim_symbol) \ - *(.modinfo) \/* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \
scripts/Makefile.vmlinux +1 -1
@@ -86,7 +86,7 @@ endif # vmlinux # --------------------------------------------------------------------------- -remove-section-y := +remove-section-y := .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' quiet_cmd_strip_relocs = OBJCOPY $@
scripts/mksysmap +3 -0
@@ -79,6 +79,9 @@ / _SDA_BASE_$/d / _SDA2_BASE_$/d +# MODULE_INFO() +/ __UNIQUE_ID_modinfo[0-9]*$/d + # --------------------------------------------------------------------------- # Ignored patterns # (symbols that contain the pattern are ignored)
Signature · 1 line
2.49.0
PATCH v4 4/7 kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
In reply to Alexey GladkovFrom: Masahiro Yamada <[email protected]>
Currently, we assume all the data for modules.builtin.modinfo are available in vmlinux.o.
This makes it impossible for modpost, which is invoked after vmlinux.o, to add additional module info.
This commit moves the modules.builtin.modinfo rule after modpost.
--- scripts/Makefile.vmlinux | 26 ++++++++++++++++++++++++++ scripts/Makefile.vmlinux_o | 26 +------------------------- 2 files changed, 27 insertions(+), 25 deletions(-)
scripts/Makefile.vmlinux +26 -0
@@ -96,6 +96,32 @@ targets += vmlinux vmlinux: vmlinux.unstripped FORCE $(call if_changed,strip_relocs) +# modules.builtin.modinfo +# --------------------------------------------------------------------------- + +OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary + +targets += modules.builtin.modinfo +modules.builtin.modinfo: vmlinux.unstripped FORCE + $(call if_changed,objcopy) + +# modules.builtin +# --------------------------------------------------------------------------- + +__default: modules.builtin + +# The second line aids cases where multiple modules share the same object. + +quiet_cmd_modules_builtin = GEN $@ + cmd_modules_builtin = \ + tr '\0' '\n' < $< | \ + sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ + tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ + +targets += modules.builtin +modules.builtin: modules.builtin.modinfo FORCE + $(call if_changed,modules_builtin) + # modules.builtin.ranges # --------------------------------------------------------------------------- ifdef CONFIG_BUILTIN_MODULE_RANGES
scripts/Makefile.vmlinux_o +1 -25
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only PHONY := __default -__default: vmlinux.o modules.builtin.modinfo modules.builtin +__default: vmlinux.o include include/config/auto.conf include $(srctree)/scripts/Kbuild.include
@@ -73,30 +73,6 @@ vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE targets += vmlinux.o -# modules.builtin.modinfo -# --------------------------------------------------------------------------- - -OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary - -targets += modules.builtin.modinfo -modules.builtin.modinfo: vmlinux.o FORCE - $(call if_changed,objcopy) - -# modules.builtin -# --------------------------------------------------------------------------- - -# The second line aids cases where multiple modules share the same object. - -quiet_cmd_modules_builtin = GEN $@ - cmd_modules_builtin = \ - tr '\0' '\n' < $< | \ - sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ - tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ - -targets += modules.builtin -modules.builtin: modules.builtin.modinfo FORCE - $(call if_changed,modules_builtin) - # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # ---------------------------------------------------------------------------
Signature · 1 line
2.49.0
PATCH v4 5/7 scsi: Always define blogic_pci_tbl structure
In reply to Alexey GladkovThe blogic_pci_tbl structure is used by the MODULE_DEVICE_TABLE macro. There is no longer a need to protect it with the MODULE condition, since this no longer causes the compiler to warn about an unused variable.
--- drivers/scsi/BusLogic.c | 2 -- 1 file changed, 2 deletions(-)
drivers/scsi/BusLogic.c +0 -2
@@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void)__setup ("BusLogic=" , blogic_setup); -#ifdef MODULE /*static const struct pci_device_id blogic_pci_tbl[] = { { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@@ -3731,7 +3730,6 @@ static const struct pci_device_id blogic_pci_tbl[] = { {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, {0, }, }; -#endifMODULE_DEVICE_TABLE (pci, blogic_pci_tbl);module_init (blogic_init);
Signature · 1 line
2.49.0
PATCH v4 6/7 modpost: Add modname to mod_device_table alias
In reply to Alexey GladkovAt this point, if a symbol is compiled as part of the kernel, information about which module the symbol belongs to is lost.
To save this it is possible to add the module name to the alias name. It's not very pretty, but it's possible for now.
--- include/linux/module.h | 14 +++++++++++--- rust/kernel/device_id.rs | 8 ++++---- scripts/mod/file2alias.c | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-)
include/linux/module.h +11 -3
@@ -243,11 +243,19 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* What your module does. */ #define MODULE_DESCRIPTION (_description) MODULE_INFO(description, _description) +/* Format: __mod_device_table__kmod_<modname>__<type>__<name> */ +#define __mod_device_table (type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__KBUILD_MODNAME, \ + __PASTE(__, \ + __PASTE(type, \ + __PASTE(__, name))))) +#ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ -#define MODULE_DEVICE_TABLE (type, name) \ -extern typeof(name) __mod_device_table__##type##__##name \ - __attribute__ ((unused, alias(__stringify(name)))) +#define MODULE_DEVICE_TABLE (type, name) \ +static typeof(name) __mod_device_table(type, name) \ + __attribute__ ((used, alias(__stringify(name))))#else /* !MODULE */ #define MODULE_DEVICE_TABLE (type, name)#endif
rust/kernel/device_id.rs +4 -4
@@ -154,10 +154,10 @@ macro_rules! module_device_table { ($table_type: literal, $module_table_name:ident, $table_name:ident) => {#[rustfmt::skip] #[export_name = -concat! ( "__mod_device_table__" , $table_type, -"__" , module_path! (), -"_" , line! (), -"_" , stringify! ($table_name)) +concat! ( "__mod_device_table__" , line! (), +"__kmod_" , module_path! (), +"__" , $table_type, +"__" , stringify! ($table_name)) ] static $module_table_name: [::core::mem::MaybeUninit<u8>; $table_name.raw_ids().size()] =unsafe { ::core::mem::transmute_copy ($table_name.raw_ids ()) };
scripts/mod/file2alias.c +14 -4
@@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, {void *symval;char *zeros =NULL ; -const char *type, *name; -size_t typelen; +const char *type, *name, *modname; +size_t typelen, modnamelen;static const char *prefix ="__mod_device_table__" ;/* We're looking for a section relative symbol */
@@ -1488,10 +1488,20 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,if (ELF_ST_TYPE (sym->st_info) !=STT_OBJECT )return ; -/* All our symbols are of form __mod_device_table__<type>__<name>. */ +/* All our symbols are of form __mod_device_table__kmod_<modname>__<type>__<name>. */ if (!strstarts (symname, prefix))return ; - type = symname +strlen (prefix); + + modname =strstr (symname,"__kmod_" ); +if (!modname) +return ; + modname +=strlen ("__kmod_" ); + + type =strstr (modname,"__" ); +if (!type) +return ; + modnamelen = type - modname; + type +=strlen ("__" ); name =strstr (type,"__" );if (!name)
Signature · 1 line
2.49.0
Re: [PATCH v4 6/7] modpost: Add modname to mod_device_table alias
Quoted 2 lines · Alexey Gladkov
rust/kernel/device_id.rs | 8 ++++----
Cc'ing maintainers and list.
Cheers,
Miguel
Re: [PATCH v4 6/7] modpost: Add modname to mod_device_table alias
In reply to Alexey GladkovQuoted 2 lines · Alexey Gladkov
+/* Format: __mod_device_table__kmod_<modname>__<type>__<name> */
Should we mention that __kmod_ and __ will be the search strings, or otherwise the Rust formatting (i.e. that is carries a line etc.)?
Cc'ing Tomo: do we need an update on rust/kernel/net/phy.rs? Should we factor out the formatting?
Thanks!
Cheers,
Miguel
Re: [PATCH v4 6/7] modpost: Add modname to mod_device_table alias
Quoted 6 lines · Miguel Ojeda
Quoted 2 lines · Alexey Gladkov
+/* Format: __mod_device_table__kmod_<modname>__<type>__<name> */
Should we mention that
__kmod_and__will be the search strings, or otherwise the Rust formatting (i.e. that is carries a line etc.)?
Ok. Make sense.
Basically there's a comment for the MODULE_DEVICE_TABLE macro that tells where and how that symbol is parsed.
Quoted 8 lines
Cc'ing Tomo: do we need an update on
rust/kernel/net/phy.rs? Should we factor out the formatting?Thanks!
Cheers,
Miguel
Signature · 1 line
Rgrds, legion
Re: [PATCH v4 6/7] modpost: Add modname to mod_device_table alias
In reply to Miguel OjedaQuoted 9 lines · On Sat, 21 Jun 2025 17:20:49 +0200 Miguel Ojeda…
Quoted 2 lines · Alexey Gladkov
+/* Format: __mod_device_table__kmod_<modname>__<type>__<name> */
Should we mention that
__kmod_and__will be the search strings, or otherwise the Rust formatting (i.e. that is carries a line etc.)?Cc'ing Tomo: do we need an update on
rust/kernel/net/phy.rs? Should we factor out the formatting?
Yeah, looks like the update is necessary. Thanks for the heads-up.
I've just send a patchset to convert the PHY abstractions to use device_id crate:
PATCH v4 7/7 modpost: Create modalias for builtin modules
In reply to Alexey GladkovFor some modules, modalias is generated using the modpost utility and the section is added to the module file.
When a module is added inside vmlinux, modpost does not generate modalias for such modules and the information is lost.
As a result kmod (which uses modules.builtin.modinfo in userspace) cannot determine that modalias is handled by a builtin kernel module.
$ cat /sys/devices/pci0000:00/0000:00:14.0/modalias pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller Driver
Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
To fix this it is necessary to generate the same modalias for vmlinux as for the individual modules. Fortunately '.vmlinux.export.o' is already generated from which '.modinfo' can be extracted in the same way as for vmlinux.o.
--- include/linux/module.h | 4 ---- scripts/Makefile.vmlinux | 5 ++++- scripts/mksysmap | 3 +++ scripts/mod/file2alias.c | 16 ++++++++++++++++ scripts/mod/modpost.c | 17 ++++++++++++++++- scripts/mod/modpost.h | 2 ++ 6 files changed, 41 insertions(+), 6 deletions(-)
include/linux/module.h +0 -4
@@ -251,14 +251,10 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name); __PASTE(type, \ __PASTE(__, name))))) -#ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ #define MODULE_DEVICE_TABLE (type, name) \ static typeof(name) __mod_device_table(type, name) \ __attribute__ ((used, alias(__stringify(name)))) -#else /* !MODULE */ -#define MODULE_DEVICE_TABLE (type, name) -#endif /* Version of form [<epoch>:]<version>[-<extra-version>]. * Or for CVS/RCS ID version, everything but the number is stripped.
scripts/Makefile.vmlinux +4 -1
@@ -89,8 +89,11 @@ endif remove-section-y := .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' +remove-symbols := -w --strip-symbol='__mod_device_table__*' + quiet_cmd_strip_relocs = OBJCOPY $@ - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@ + cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \ + $(remove-symbols) $< $@ targets += vmlinux vmlinux: vmlinux.unstripped FORCE
scripts/mksysmap +3 -0
@@ -59,6 +59,9 @@ # EXPORT_SYMBOL (namespace) / __kstrtabns_/d +# MODULE_DEVICE_TABLE (symbol name) +/ __mod_device_table__/d + # --------------------------------------------------------------------------- # Ignored suffixes # (do not forget '$' after each pattern)
scripts/mod/file2alias.c +16 -0
@@ -1527,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, } } +if (mod->is_vmlinux) { +struct module_alias *alias; + +/* +* If this is vmlinux, record the name of the builtin module. +* Traverse the linked list in the reverse order, and set the +* builtin_modname unless it has already been set in the +* previous call. +*/ +list_for_each_entry_reverse (alias, &mod->aliases, node) { +if (alias->builtin_modname) +break ; + alias->builtin_modname =xstrndup (modname, modnamelen); + } + } +free (zeros); }
scripts/mod/modpost.c +16 -1
@@ -2021,11 +2021,26 @@ static void write_if_changed(struct buffer *b, const char *fname)static void write_vmlinux_export_c_file (struct module *mod) {struct buffer buf = { }; +struct module_alias *alias, *next;buf_printf (&buf, -"#include <linux/export-internal.h>\n" ); +"#include <linux/export-internal.h>\n" +"#include <linux/module.h>\n" );add_exported_symbols (&buf, mod); + +buf_printf (&buf, +"#undef __MODULE_INFO_PREFIX\n" +"#define __MODULE_INFO_PREFIX\n" ); + +list_for_each_entry_safe (alias, next, &mod->aliases, node) { +buf_printf (&buf,"MODULE_INFO(%s.alias, \"%s\");\n" , + alias->builtin_modname, alias->str); +list_del (&alias->node); +free (alias->builtin_modname); +free (alias); + } +write_if_changed (&buf,".vmlinux.export.c" );free (buf.p); }
scripts/mod/modpost.h +2 -0
@@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len);* struct module_alias - auto-generated MODULE_ALIAS() * * @node: linked to module::aliases +* @modname: name of the builtin module (only for vmlinux) * @str: a string for MODULE_ALIAS() */ struct module_alias {struct list_head node; +char *builtin_modname;char str[]; };
Signature · 1 line
2.49.0
Quoted 31 lines · Alexey Gladkov
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to get information about builtin modules. Among other information about the module, information about module aliases is stored. This is very important to determine that a particular modalias will be handled by a module that is inside the kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the
MODULE_ALIASof the macro. In this case, the aliases go into the '.modinfo' section of the module if it is compiled separately or into vmlinux.o if it is builtin into the kernel.The second is the use of
MODULE_DEVICE_TABLEfollowed by the use of the modpost utility. In this case, vmlinux.o no longer has this information and does not get it into modules.builtin.modinfo.For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller DriverThe builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
Quoted 7 lines
To fix this it is necessary to add the generated by modpost modalias to modules.builtin.modinfo.
Fortunately modpost already generates
.vmlinux.export.cfor exported symbols. It is possible to use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.
Masahiro Yamada, does this version of the patchset look better to you ?
Quoted 50 lines
Notes:
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/[email protected]/- v3:
* AddReviewed-bytag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/[email protected]/Alexey Gladkov (3):
scsi: Always defineblogic_pci_tblstructure
modpost: Add modname tomod_device_tablealias
modpost: Create modalias for builtin modulesMasahiro Yamada (4):
module: remove meaningless 'name' parameter from__MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstrippeddrivers/scsi/BusLogic.c | 2 - include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 21 ++++----- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- rust/kernel/device_id.rs | 8 ++-- scripts/Makefile.vmlinux | 74 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 6 +++ scripts/mod/file2alias.c | 34 ++++++++++++-- scripts/mod/modpost.c | 17 ++++++- scripts/mod/modpost.h | 2 + 13 files changed, 131 insertions(+), 78 deletions(-)Signature · 1 line
2.49.0
Signature · 1 line
Rgrds, legion
Hi, sorry for the delay.
Quoted 36 lines · Alexey Gladkov
Quoted 34 lines · Alexey Gladkov
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to get information about builtin modules. Among other information about the module, information about module aliases is stored. This is very important to determine that a particular modalias will be handled by a module that is inside the kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the
MODULE_ALIASof the macro. In this case, the aliases go into the '.modinfo' section of the module if it is compiled separately or into vmlinux.o if it is builtin into the kernel.The second is the use of
MODULE_DEVICE_TABLEfollowed by the use of the modpost utility. In this case, vmlinux.o no longer has this information and does not get it into modules.builtin.modinfo.For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller DriverThe builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
To fix this it is necessary to add the generated by modpost modalias to modules.builtin.modinfo.
Quoted 6 lines
Quoted 4 lines
Fortunately modpost already generates
.vmlinux.export.cfor exported symbols. It is possible to use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.Masahiro Yamada, does this version of the patchset look better to you ?
Looks better, but this may break s390 build:
https://lore.kernel.org/linux-kbuild/[email protected]/
I have not taken a close look at it.
If we do not find how to fix the warning, we would end up with the original solution.
Quoted 54 lines
Quoted 47 lines
Notes:
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/[email protected]/- v3:
* AddReviewed-bytag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/[email protected]/Alexey Gladkov (3):
scsi: Always defineblogic_pci_tblstructure
modpost: Add modname tomod_device_tablealias
modpost: Create modalias for builtin modulesMasahiro Yamada (4):
module: remove meaningless 'name' parameter from__MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstrippeddrivers/scsi/BusLogic.c | 2 - include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 21 ++++----- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- rust/kernel/device_id.rs | 8 ++-- scripts/Makefile.vmlinux | 74 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 6 +++ scripts/mod/file2alias.c | 34 ++++++++++++-- scripts/mod/modpost.c | 17 ++++++- scripts/mod/modpost.h | 2 + 13 files changed, 131 insertions(+), 78 deletions(-)Quoted 3 lines
--
2.49.0--
Rgrds, legion
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 47 lines · Masahiro Yamada
Hi, sorry for the delay.
Quoted 36 lines · Alexey Gladkov
Quoted 34 lines · Alexey Gladkov
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to get information about builtin modules. Among other information about the module, information about module aliases is stored. This is very important to determine that a particular modalias will be handled by a module that is inside the kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the
MODULE_ALIASof the macro. In this case, the aliases go into the '.modinfo' section of the module if it is compiled separately or into vmlinux.o if it is builtin into the kernel.The second is the use of
MODULE_DEVICE_TABLEfollowed by the use of the modpost utility. In this case, vmlinux.o no longer has this information and does not get it into modules.builtin.modinfo.For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller DriverThe builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
To fix this it is necessary to add the generated by modpost modalias to modules.builtin.modinfo.
Quoted 6 lines
Quoted 4 lines
Fortunately modpost already generates
.vmlinux.export.cfor exported symbols. It is possible to use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.Masahiro Yamada, does this version of the patchset look better to you ?
Quoted 7 lines
Looks better, but this may break s390 build:
https://lore.kernel.org/linux-kbuild/[email protected]/
I have not taken a close look at it.
If we do not find how to fix the warning, we would end up with the original solution.
I haven't gotten any messages from kernel test robot about this message since these patches were published.
I've pushed the patches to my brunch and will wait for test results until the weekend. I will see what happens.
Quoted 60 lines
Quoted 54 lines
Quoted 47 lines
Notes:
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/[email protected]/- v3:
* AddReviewed-bytag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/[email protected]/Alexey Gladkov (3):
scsi: Always defineblogic_pci_tblstructure
modpost: Add modname tomod_device_tablealias
modpost: Create modalias for builtin modulesMasahiro Yamada (4):
module: remove meaningless 'name' parameter from__MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstrippeddrivers/scsi/BusLogic.c | 2 - include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 21 ++++----- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- rust/kernel/device_id.rs | 8 ++-- scripts/Makefile.vmlinux | 74 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 6 +++ scripts/mod/file2alias.c | 34 ++++++++++++-- scripts/mod/modpost.c | 17 ++++++- scripts/mod/modpost.h | 2 + 13 files changed, 131 insertions(+), 78 deletions(-)Quoted 3 lines
--
2.49.0--
Rgrds, legionSignature · 2 lines
Best Regards Masahiro Yamada
Signature · 1 line
Rgrds, legion
Quoted 47 lines · Masahiro Yamada
Hi, sorry for the delay.
Quoted 36 lines · Alexey Gladkov
Quoted 34 lines · Alexey Gladkov
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to get information about builtin modules. Among other information about the module, information about module aliases is stored. This is very important to determine that a particular modalias will be handled by a module that is inside the kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the
MODULE_ALIASof the macro. In this case, the aliases go into the '.modinfo' section of the module if it is compiled separately or into vmlinux.o if it is builtin into the kernel.The second is the use of
MODULE_DEVICE_TABLEfollowed by the use of the modpost utility. In this case, vmlinux.o no longer has this information and does not get it into modules.builtin.modinfo.For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.$ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller DriverThe builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately.
To fix this it is necessary to add the generated by modpost modalias to modules.builtin.modinfo.
Quoted 6 lines
Quoted 4 lines
Fortunately modpost already generates
.vmlinux.export.cfor exported symbols. It is possible to use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.Masahiro Yamada, does this version of the patchset look better to you ?
Quoted 7 lines
Looks better, but this may break s390 build:
https://lore.kernel.org/linux-kbuild/[email protected]/
I have not taken a close look at it.
If we do not find how to fix the warning, we would end up with the original solution.
I think I found a problem. I just pushed fix to my branch. I'll make a new version of the patchset in a few days. I want to test it a bit longer.
Quoted 60 lines
Quoted 54 lines
Quoted 47 lines
Notes:
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/[email protected]/- v3:
* AddReviewed-bytag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/[email protected]/Alexey Gladkov (3):
scsi: Always defineblogic_pci_tblstructure
modpost: Add modname tomod_device_tablealias
modpost: Create modalias for builtin modulesMasahiro Yamada (4):
module: remove meaningless 'name' parameter from__MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstrippeddrivers/scsi/BusLogic.c | 2 - include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 21 ++++----- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- rust/kernel/device_id.rs | 8 ++-- scripts/Makefile.vmlinux | 74 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 6 +++ scripts/mod/file2alias.c | 34 ++++++++++++-- scripts/mod/modpost.c | 17 ++++++- scripts/mod/modpost.h | 2 + 13 files changed, 131 insertions(+), 78 deletions(-)Quoted 3 lines
--
2.49.0--
Rgrds, legionSignature · 2 lines
Best Regards Masahiro Yamada
Signature · 1 line
Rgrds, legion