Extended MODVERSIONS Support
Subsystems (5)
v13 cover Extended MODVERSIONS Support
This patch series is intended for use alongside the Implement DWARF modversions series [1] to enable RUST and MODVERSIONS at the same time.
Elsewhere, we've seen a desire for long symbol name support for LTO symbol names [2], and the previous series came up [3] as a possible solution rather than hashing, which some have objected [4] to.
This series adds a MODVERSIONS format which uses a section per column. This avoids userspace tools breaking if we need to make a similar change to the format in the future - we would do so by adding a new section, rather than editing the struct definition. In the new format, the name section is formatted as a concatenated sequence of NUL-terminated strings, which allows for arbitrary length names.
Emitting the extended format is guarded by CONFIG_EXTENDED_MODVERSIONS, but the kernel always knows how to validate both the original and extended formats.
Emitting the existing format is now guarded by CONFIG_BASIC_MODVERSIONS, but it is enabled by default when MODVERSIONS is enabled and must be explicitly disabled by the user.
Disabling CONFIG_BASIC_MODVERSIONS may cause some userspace tools to be unable to retrieve CRCs until they are patched to understand the new location. Even with CONFIG_BASIC_MODVERSIONS enabled, those tools will be unable to read the CRCs for long symbols until they are updated to read the new format. This is not expected to interfere with normal operation, as the primary use for CRCs embedded in the module is load-time verification by the kernel. Recording and monitoring of CRCs is typically done through Module.symvers.
Selecting RUST and MODVERSIONS is now possible if GENDWARFKSYMS is selected, and will implicitly select EXTENDED_MODVERSIONS.
This series depends upon DWARF-based versions [1] and Masahiro's u32 fixup patch [5].
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/linux-kbuild/[email protected]
Changes in v13:
- Fixed up missed s32 usage (Thanks Sami).
v12: https://lore.kernel.org/r/[email protected]
- Rebased on top of Masahiro's cleanup patch
- Switched modpost to Masahiro's new types, including using u32 instead
of s32
- Eliminated comment noise per Masahiro's suggestion
- Fixed typo in patch 3 commit message
- Set default of BASIC_MODVERSIONS to y instead of MODVERSIONS, per Masahiro's suggestion
v11: https://lore.kernel.org/r/[email protected]
- Fixed documentation about where strings are stored per Petr's
suggestion.
- Rebased on to the latest version of Sami's series on linux-next
v10: https://lore.kernel.org/r/[email protected]
- Fixed accidental selects / default confusion in previous patch
- Re-ran tests (check for section presence in Y/Y, Y/N, N/Y, N/N, check
all module kinds load)
v9: https://lore.kernel.org/r/[email protected]
- Rebased onto the latest version of Sami's series, on top of linux-next
- Added BASIC_MODVERSIONS to allow using *only* EXTENDED_MODVERSIONS
- Documented where symbol data is stored and format limitations
v8: https://lore.kernel.org/r/[email protected]
- Rebased onto latest version of Sami's series, on top of v6.12-rc5
- Pass --stable when KBUILD_GENDWARFKSYMS_STABLE is set.
- Flipped MODVERSIONS/GENDWARFKSYMS order in deps for CONFIG_RUST
- Picked up trailers
v7: https://lore.kernel.org/r/[email protected]
- Fix modpost to detect EXTENDED_MODVERSIONS based on a flag
- Drop patches to fix export_report.pl
- Switch from conditional compilation in .mod.c to conditional emission
in modpost
- Factored extended modversion emission into its own function
- Allow RUST + MODVERSIONS if GENDWARFKSYMS is enabled by selecting EXTENDED_MODVERSIONS
v6: https://lore.kernel.org/lkml/[email protected]/
- Splits verification refactor Luis requested out to a separate change
- Clarifies commits around export_report.pl repairs
- Add CONFIG_EXTENDED_MODVERSIONS to control whether extended information is included in the module, per Luis's request.
v5: https://lore.kernel.org/all/[email protected]/
- Addresses Sami's comments from v3 that I missed in v4 (missing early return, extra parens)
v4: https://lore.kernel.org/asahi/[email protected]/
- Fix incorrect dot munging in PPC
v3: https://lore.kernel.org/lkml/[email protected]/T/
- Split up the module verification refactor into smaller patches, per Greg K-H's suggestion.
v2: https://lore.kernel.org/all/[email protected]/
- Add loading/verification refactor before modifying, per Luis's request
v1: https://lore.kernel.org/rust-for-linux/[email protected]/
--
2.47.0.rc1.288.g06298d1525-goog
---
Matthew Maurer (4):
modules: Support extended MODVERSIONS info
modpost: Produce extended MODVERSIONS information
modules: Allow extended modversions without basic MODVERSIONS Documentation/kbuild: Document storage of symbol information
Sami Tolvanen (1):
rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Documentation/kbuild/modules.rst | 20 +++++++++ arch/powerpc/kernel/module_64.c | 24 ++++++++++- init/Kconfig | 3 +- kernel/module/Kconfig | 25 +++++++++++ kernel/module/internal.h | 11 +++++ kernel/module/main.c | 92 ++++++++++++++++++++++++++++++++++++---- kernel/module/version.c | 45 ++++++++++++++++++++ rust/Makefile | 34 ++++++++++++++- scripts/Makefile.modpost | 2 + scripts/mod/modpost.c | 69 +++++++++++++++++++++++++++--- 10 files changed, 307 insertions(+), 18 deletions(-)
---
base-commit: b2c5bc987160cbc8478b982991f34f53189af909
change-id: 20241022-extended-modversions-a7b44dfbfff1
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: d5b0940f47a19d475020f6fd2e916703b803a137
prerequisite-patch-id: a8ac50c440ac3247c60227d2ea2c10f3d3e433c1
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 8a6a82b2f1858ee1483f41a1aa72c8cb030559ac
prerequisite-patch-id: 5b22bc2e7f592e464d5d1dd4341efa2fb2afb9d0
prerequisite-patch-id: 220585cf1a8d66ec722cf1d6ec474af6dc3b6a02
prerequisite-patch-id: 8ae7cb66d809f902968f81354706edeb99a3d3fa
prerequisite-patch-id: 4d6a826429c519b581d01215e1d9c7373fdfd8c6
prerequisite-patch-id: 0dcd84187b222adf52696dbcab303d683d087dd2
prerequisite-patch-id: 0abe8634eb844a85e8dc51c1cd3970cf96cc494a
prerequisite-patch-id: 5fabb630792f9304f200b5996314f3c2ae4c83ae
prerequisite-patch-id: 2772364d4b2132c9ede451f320162fc40c6f3d09
prerequisite-patch-id: a5cf20d27871bf63be64ac79cc81e5eb9d117b89
prerequisite-patch-id: 930230702709fe769b171a8ae94955e5d1de13ea
prerequisite-patch-id: b43c0bc886a312e3b14be04a8fdad25badf4d834
prerequisite-patch-id: 839b0c4859bdc8447d67bfe4b09f762140e747e7
prerequisite-patch-id: 3c55d1e58a1d7aebfc3ea85ef5497a7262022040
prerequisite-patch-id: 5a190c60e140cdf33caf4f4da03186a2bd75a531
prerequisite-patch-id: 57d2fe708769154a6494fb1fece56911dea00687
prerequisite-patch-id: 7e046331b05c61a87e1adc923b763b68a580cd03
prerequisite-patch-id: 91c6131ab67a6f0fd8cf8bc95fa45144a868f095
Best regards,
Signature · 1 line
Matthew Maurer <[email protected]>
PATCH v13 1/5 modules: Support extended MODVERSIONS info
Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer).
Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information.
--- arch/powerpc/kernel/module_64.c | 24 ++++++++++- kernel/module/internal.h | 11 +++++ kernel/module/main.c | 92 +++++++++++++++++++++++++++++++++++++---- kernel/module/version.c | 45 ++++++++++++++++++++ 4 files changed, 162 insertions(+), 10 deletions(-)
arch/powerpc/kernel/module_64.c +22 -2
@@ -369,6 +369,24 @@ static void dedotify_versions(struct modversion_info *vers, } } +/* Same as normal versions, remove a leading dot if present. */ +static void dedotify_ext_version_names (char *str_seq,unsigned long size) +{ +unsigned long out =0 ; +unsigned long in; +char last ='\0' ; + +for (in =0 ; in < size; in++) { +/* Skip one leading dot */ +if (last =='\0' && str_seq[in] =='.' ) + in++; + last = str_seq[in]; + str_seq[out++] = last; + } +/* Zero the trailing portion of the names table for robustness */ +memset (&str_seq[out],0 , size - out); +} +/* * Undefined symbols which refer to .funcname, hack to funcname. Make .TOC. * seem to be defined (value set later).
@@ -438,10 +456,12 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr, me->arch.toc_section = i;if (sechdrs[i].sh_addralign <8 ) sechdrs[i].sh_addralign =8 ; - } -else if (strcmp (secstrings+sechdrs[i].sh_name,"__versions" )==0 ) + }else if (strcmp (secstrings + sechdrs[i].sh_name,"__versions" ) ==0 )dedotify_versions ((void *)hdr + sechdrs[i].sh_offset, sechdrs[i].sh_size); +else if (strcmp (secstrings + sechdrs[i].sh_name,"__version_ext_names" ) ==0 ) +dedotify_ext_version_names ((void *)hdr + sechdrs[i].sh_offset, + sechdrs[i].sh_size);if (sechdrs[i].sh_type ==SHT_SYMTAB ) dedotify((void *)hdr + sechdrs[i].sh_offset,
kernel/module/internal.h +11 -0
@@ -86,6 +86,8 @@ struct load_info {unsigned int vers;unsigned int info;unsigned int pcpu; +unsigned int vers_ext_crc; +unsigned int vers_ext_name; } index; };
@@ -389,6 +391,15 @@ void module_layout(struct module *mod, struct modversion_info *ver, struct kerne struct kernel_symbol *ks, struct tracepoint * const *tp);int check_modstruct_version (const struct load_info *info,struct module *mod);int same_magic (const char *amagic,const char *bmagic,bool has_crcs); +struct modversion_info_ext { +size_t remaining; +const u32 *crc; +const char *name; +}; +void modversion_ext_start (const struct load_info *info,struct modversion_info_ext *ver); +void modversion_ext_advance (struct modversion_info_ext *ver); +#define for_each_modversion_info_ext (ver, info) \ + for (modversion_ext_start(info, &ver); ver.remaining > 0; modversion_ext_advance(&ver))#else /* !CONFIG_MODVERSIONS */ static inline int check_version(const struct load_info *info, const char *symname,
kernel/module/main.c +84 -8
116 lines not on this page · raw message
kernel/module/version.c +45 -0
62 lines not on this page · raw message
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH v13 2/5 modpost: Produce extended MODVERSIONS information
In reply to Matthew MaurerGenerate both the existing modversions format and the new extended one when running modpost. Presence of this metadata in the final .ko is guarded by CONFIG_EXTENDED_MODVERSIONS.
We no longer generate an error on long symbols in modpost if CONFIG_EXTENDED_MODVERSIONS is set, as they can now be appropriately encoded in the extended section. These symbols will be skipped in the previous encoding. An error will still be generated if CONFIG_EXTENDED_MODVERSIONS is not set.
--- kernel/module/Kconfig | 10 ++++++++ scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 62 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 4 deletions(-)
kernel/module/Kconfig +10 -0
@@ -207,6 +207,16 @@ config ASM_MODVERSIONS assembly. This can be enabled only when the target architecture supports it. +config EXTENDED_MODVERSIONS + bool "Extended Module Versioning Support" + depends on MODVERSIONS + help + This enables extended MODVERSIONs support, allowing long symbol + names to be versioned. + + The most likely reason you would enable this is to enable Rust + support. If unsure, say N. + config MODULE_SRCVERSION_ALL bool "Source checksum for all modules" help
scripts/Makefile.modpost +1 -0
@@ -43,6 +43,7 @@ MODPOST = $(objtree)/scripts/mod/modpost modpost-args = \ $(if $(CONFIG_MODULES),-M) \ $(if $(CONFIG_MODVERSIONS),-m) \ + $(if $(CONFIG_EXTENDED_MODVERSIONS),-x) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_MODPOST_WARN),-w) \
scripts/mod/modpost.c +58 -4
98 lines not on this page · raw message
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH v13 3/5 modules: Allow extended modversions without basic MODVERSIONS
In reply to Matthew MaurerIf you know that your kernel modules will only ever be loaded by a newer kernel, you can disable BASIC_MODVERSIONS to save space. This also allows easy creation of test modules to see how tooling will respond to modules that only have the new format.
--- kernel/module/Kconfig | 15 +++++++++++++++ scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 9 +++++++-- 3 files changed, 23 insertions(+), 2 deletions(-)
kernel/module/Kconfig +15 -0
@@ -217,6 +217,21 @@ config EXTENDED_MODVERSIONS The most likely reason you would enable this is to enable Rust support. If unsure, say N. +config BASIC_MODVERSIONS + bool "Basic Module Versioning Support" + depends on MODVERSIONS + default y + help + This enables basic MODVERSIONS support, allowing older tools or + kernels to potentially load modules. + + Disabling this may cause older `modprobe` or `kmod` to be unable + to read MODVERSIONS information from built modules. With this + disabled, older kernels may treat this module as unversioned. + + This is enabled by default when MODVERSIONS are enabled. + If unsure, say Y. + config MODULE_SRCVERSION_ALL bool "Source checksum for all modules" help
scripts/Makefile.modpost +1 -0
@@ -43,6 +43,7 @@ MODPOST = $(objtree)/scripts/mod/modpost modpost-args = \ $(if $(CONFIG_MODULES),-M) \ $(if $(CONFIG_MODVERSIONS),-m) \ + $(if $(CONFIG_BASIC_MODVERSIONS),-b) \ $(if $(CONFIG_EXTENDED_MODVERSIONS),-x) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
scripts/mod/modpost.c +7 -2
@@ -33,6 +33,8 @@ static bool module_enabled;static bool modversions;/* Is CONFIG_MODULE_SRCVERSION_ALL set? */ static bool all_versions; +/* Is CONFIG_BASIC_MODVERSIONS set? */ +static bool basic_modversions;/* Is CONFIG_EXTENDED_MODVERSIONS set? */ static bool extended_modversions;/* If we are modposting external module set to 1 */
@@ -1856,7 +1858,7 @@ static void add_versions(struct buffer *b, struct module *mod) {struct symbol *s; -if (!modversions) +if (!basic_modversions)return ;buf_printf (b,"\n" );
@@ -2176,7 +2178,7 @@ int main(int argc, char **argv)LIST_HEAD (dump_lists);struct dump_list *dl, *dl2; -while ((opt =getopt (argc, argv,"ei:MmnT:to:au:WwENd:x" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ei:MmnT:to:au:WwENd:xb" )) !=-1 ) {switch (opt) {case 'e' : external_module = true;
@@ -2225,6 +2227,9 @@ int main(int argc, char **argv)case 'd' : missing_namespace_deps = optarg;break ; +case 'b' : + basic_modversions = true; +break ;case 'x' : extended_modversions = true;break ;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH v13 4/5 Documentation/kbuild: Document storage of symbol information
In reply to Matthew MaurerDocument where exported and imported symbols are kept, format options, and limitations.
--- Documentation/kbuild/modules.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Documentation/kbuild/modules.rst +20 -0
@@ -423,6 +423,26 @@ Symbols From the Kernel (vmlinux + modules) 1) It lists all exported symbols from vmlinux and all modules. 2) It lists the CRC if CONFIG_MODVERSIONS is enabled. +Version Information Formats +--------------------------- + + Exported symbols have information stored in __ksymtab or __ksymtab_gpl + sections. Symbol names and namespaces are stored in __ksymtab_strings, + using a format similar to the string table used for ELF. If + CONFIG_MODVERSIONS is enabled, the CRCs corresponding to exported + symbols will be added to the __kcrctab or __kcrctab_gpl. + + If CONFIG_BASIC_MODVERSIONS is enabled (default with + CONFIG_MODVERSIONS), imported symbols will have their symbol name and + CRC stored in the __versions section of the importing module. This + mode only supports symbols of length up to 64 bytes. + + If CONFIG_EXTENDED_MODVERSIONS is enabled (required to enable both + CONFIG_MODVERSIONS and CONFIG_RUST at the same time), imported symbols + will have their symbol name recorded in the __version_ext_names + section as a series of concatenated, null-terminated strings. CRCs for + these symbols will be recorded in the __version_ext_crcs section. + Symbols and External Modules ----------------------------
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH v13 5/5 rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
In reply to Matthew MaurerFrom: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONS addresses the first point, and CONFIG_GENDWARFKSYMS the second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.
--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)
init/Kconfig +2 -1
@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
rust/Makefile +32 -2
@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports)
@@ -401,11 +402,36 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) __ashlti3 __lshrti3 endif +ifdef CONFIG_MODVERSIONS +cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \ + $(call rust_exports,$@,"%s\n",$$3) | \ + scripts/gendwarfksyms/gendwarfksyms \ + $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) \ + $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \ + $@ >> $(dot-target).cmd) +endif + define rule_rustc_library $(call cmd_and_fixdep,rustc_library) $(call cmd,gen_objtooldep) + $(call cmd,gendwarfksyms) endef +define rule_rust_cc_library + $(call if_changed_rule,cc_o_c) + $(call cmd,force_checksrc) + $(call cmd,gendwarfksyms) +endef + +# helpers.o uses the same export mechanism as Rust libraries, so ensure symbol +# versions are calculated for the helpers too. +$(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE + +$(call if_changed_rule,rust_cc_library) + +# Disable symbol versioning for exports.o to avoid conflicts with the actual +# symbol versions generated from Rust objects. +$(obj)/exports.o: private skip_gendwarfksyms = 1 + $(obj)/core.o: private skip_clippy = 1 $(obj)/core.o: private skip_flags = -Wunreachable_pub $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
@@ -417,13 +443,16 @@ ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) $(obj)/core.o: scripts/target.json endif +$(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*' $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE +$(call if_changed_rule,rustc_library) +$(obj)/build_error.o: private skip_gendwarfksyms = 1 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_rule,rustc_library) +$(obj)/ffi.o: private skip_gendwarfksyms = 1 $(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_rule,rustc_library)
@@ -435,6 +464,7 @@ $(obj)/bindings.o: $(src)/bindings/lib.rs \ +$(call if_changed_rule,rustc_library) $(obj)/uapi.o: private rustc_target_flags = --extern ffi +$(obj)/uapi.o: private skip_gendwarfksyms = 1 $(obj)/uapi.o: $(src)/uapi/lib.rs \ $(obj)/ffi.o \ $(obj)/uapi/uapi_generated.rs FORCE
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v13 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Quoted 43 lines · Matthew Maurer
From: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONSaddresses the first point, andCONFIG_GENDWARFKSYMSthe second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.Signed-off-by Sami Tolvanen <[email protected]>Co-developed-by Matthew Maurer <[email protected]>Signed-off-by Matthew Maurer <[email protected]>--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)init/Kconfig +2
-1@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDErust/Makefile +0
-0
rust/Makefile $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · line 336
Quoted 10 lines
rust/Makefile +3
-2@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@
I noticed a nit:
Both of the two callsites of rust_exports pass '$$3' to the last parameter instead of hardcoding it.
Is it a flexibility for future extensions?
I cannot think of any other use except for printing the third column, i.e. symbol name.
Signature · 2 lines
Best Regards Masahiro Yamada
Sami Tolvanen
maintainerRe: [PATCH v13 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Hi Masahiro,
Quoted 58 lines · Masahiro Yamada
Quoted 43 lines · Matthew Maurer
From: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONSaddresses the first point, andCONFIG_GENDWARFKSYMSthe second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.Signed-off-by Sami Tolvanen <[email protected]>Co-developed-by Matthew Maurer <[email protected]>Signed-off-by Matthew Maurer <[email protected]>--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)init/Kconfig +2
-1@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDErust/Makefile +0
-0rust/Makefile $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · line 336
Quoted 10 lines
rust/Makefile +3
-2@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@I noticed a nit:
Quoted 7 lines
Both of the two callsites of
rust_exportspass '$$3' to the last parameter instead of hardcoding it.Is it a flexibility for future extensions?
I cannot think of any other use except for printing the third column, i.e. symbol name.
Good catch, the last parameter isn't necessary anymore. It was used in early versions of the series to also pass symbol addresses to gendwarfksyms, but that's not needed since we read the symbol table directly now.
Sami
Re: [PATCH v13 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Quoted 67 lines · Sami Tolvanen
Hi Masahiro,
Quoted 63 lines · Masahiro Yamada
Quoted 43 lines · Matthew Maurer
From: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONSaddresses the first point, andCONFIG_GENDWARFKSYMSthe second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.Signed-off-by Sami Tolvanen <[email protected]>Co-developed-by Matthew Maurer <[email protected]>Signed-off-by Matthew Maurer <[email protected]>--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)init/Kconfig +2
-1@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDErust/Makefile +0
-0rust/Makefile $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · line 336
Quoted 10 lines
rust/Makefile +3
-2@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@I noticed a nit:
Both of the two callsites of
rust_exportspass '$$3' to the last parameter instead of hardcoding it.Is it a flexibility for future extensions?
Quoted 7 lines
Quoted 2 lines
I cannot think of any other use except for printing the third column, i.e. symbol name.
Good catch, the last parameter isn't necessary anymore. It was used in early versions of the series to also pass symbol addresses to gendwarfksyms, but that's not needed since we read the symbol table directly now.
If you submit a diff, I will squash it to 5/5. (You do not need to input commit description body)
Signature · 2 lines
Best Regards Masahiro Yamada
Sami Tolvanen
maintainerRe: [PATCH v13 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · Sami Tolvanen
Hi Masahiro,
Quoted 65 lines · Masahiro Yamada
Quoted 43 lines · Matthew Maurer
From: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONSaddresses the first point, andCONFIG_GENDWARFKSYMSthe second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.Signed-off-by Sami Tolvanen <[email protected]>Co-developed-by Matthew Maurer <[email protected]>Signed-off-by Matthew Maurer <[email protected]>--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)init/Kconfig +2
-1@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDErust/Makefile +0
-0rust/Makefile $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · line 336
Quoted 10 lines
rust/Makefile +3
-2@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@I noticed a nit:
Both of the two callsites of
rust_exportspass '$$3' to the last parameter instead of hardcoding it.Is it a flexibility for future extensions?
I cannot think of any other use except for printing the third column, i.e. symbol name.
Quoted 7 lines
Quoted 4 lines
Good catch, the last parameter isn't necessary anymore. It was used in early versions of the series to also pass symbol addresses to gendwarfksyms, but that's not needed since we read the symbol table directly now.
If you submit a diff, I will squash it to 5/5. (You do not need to input commit description body)
Thanks, here's a diff that drops the last parameter.
Sami
rust/Makefile +3 -3
@@ -329,11 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) -rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$$3 }' quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports)
@@ -404,7 +404,7 @@ endif ifdef CONFIG_MODVERSIONS cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \ - $(call rust_exports,$@,"%s\n",$$3) | \ + $(call rust_exports,$@,"%s\n") | \ scripts/gendwarfksyms/gendwarfksyms \ $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) \ $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \
Re: [PATCH v13 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS
Quoted 78 lines · Sami Tolvanen
Quoted 76 lines · Masahiro Yamada
Quoted 74 lines · Sami Tolvanen
Hi Masahiro,
Quoted 58 lines · Masahiro Yamada
Quoted 43 lines · Matthew Maurer
From: Sami Tolvanen <[email protected]>
Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the original versions table
2. Rust types cannot be properly hashed by the existing genksyms approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust, not just the source type declaration.
CONFIG_EXTENDED_MODVERSIONSaddresses the first point, andCONFIG_GENDWARFKSYMSthe second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features.Signed-off-by Sami Tolvanen <[email protected]>Co-developed-by Matthew Maurer <[email protected]>Signed-off-by Matthew Maurer <[email protected]>--- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-)init/Kconfig +2
-1@@ -1959,7 +1959,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDErust/Makefile +0
-0rust/Makefile $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · line 336
Quoted 10 lines
rust/Makefile +3
-2@@ -329,10 +329,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE $(call if_changed_dep,bindgen) +rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@I noticed a nit:
Quoted 7 lines
Both of the two callsites of
rust_exportspass '$$3' to the last parameter instead of hardcoding it.Is it a flexibility for future extensions?
I cannot think of any other use except for printing the third column, i.e. symbol name.
Good catch, the last parameter isn't necessary anymore. It was used in early versions of the series to also pass symbol addresses to gendwarfksyms, but that's not needed since we read the symbol table directly now.
Quoted 4 lines
Quoted 2 lines
If you submit a diff, I will squash it to 5/5. (You do not need to input commit description body)
Thanks, here's a diff that drops the last parameter.
Squashed.
Thanks!
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 39 lines · Matthew Maurer
This patch series is intended for use alongside the Implement DWARF modversions series [1] to enable RUST and MODVERSIONS at the same time.
Elsewhere, we've seen a desire for long symbol name support for LTO symbol names [2], and the previous series came up [3] as a possible solution rather than hashing, which some have objected [4] to.
This series adds a MODVERSIONS format which uses a section per column. This avoids userspace tools breaking if we need to make a similar change to the format in the future - we would do so by adding a new section, rather than editing the struct definition. In the new format, the name section is formatted as a concatenated sequence of NUL-terminated strings, which allows for arbitrary length names.
Emitting the extended format is guarded by
CONFIG_EXTENDED_MODVERSIONS, but the kernel always knows how to validate both the original and extended formats.Emitting the existing format is now guarded by
CONFIG_BASIC_MODVERSIONS, but it is enabled by default when MODVERSIONS is enabled and must be explicitly disabled by the user.Disabling
CONFIG_BASIC_MODVERSIONSmay cause some userspace tools to be unable to retrieve CRCs until they are patched to understand the new location. Even withCONFIG_BASIC_MODVERSIONSenabled, those tools will be unable to read the CRCs for long symbols until they are updated to read the new format. This is not expected to interfere with normal operation, as the primary use for CRCs embedded in the module is load-time verification by the kernel. Recording and monitoring of CRCs is typically done through Module.symvers.Selecting RUST and MODVERSIONS is now possible if GENDWARFKSYMS is selected, and will implicitly select
EXTENDED_MODVERSIONS.This series depends upon DWARF-based versions [1] and Masahiro's u32 fixup patch [5].
Quoted 8 lines
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/linux-kbuild/[email protected]Changes in v13:
- Fixed up missed s32 usage (Thanks Sami).
Applied to linux-kbuild.
Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada