Fixups before RUST modversions support
Subsystems (2)
cover Fixups before RUST modversions support
- Fix s32 -> u32
- Make printf() format consistent
Matthew Maurer is adding more 's32'.
I need to fix the code now.
Otherwise, I would need to fix more places.
Masahiro Yamada (2):
module: get symbol crc back to unsigned
modpost: zero-pad CRC values in modversion_info array
include/linux/module.h | 4 ++-- kernel/module/internal.h | 10 +++++----- kernel/module/main.c | 2 +- kernel/module/version.c | 2 +- scripts/mod/modpost.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 module: get symbol crc back to unsigned
Commit 71810db27c1c ("modversions: treat symbol CRCs as 32 bit quantities") changed the CRC fields to s32 because the __kcrctab and __kcrctab_gpl sections contained relative references to the actual CRC values stored in the .rodata section when CONFIG_MODULE_REL_CRCS=y.
Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS") removed this complexity. Now, the __kcrctab and __kcrctab_gpl sections directly contain the CRC values in all cases.
The genksyms tool outputs unsigned 32-bit CRC values, so u32 is preferred over s32.
No functional changes are intended.
Regardless of this change, the CRC value is assigned to the u32 variable, 'crcval' before the comparison, as seen in kernel/module/version.c:
crcval = *crc;
---
include/linux/module.h | 4 ++-- kernel/module/internal.h | 10 +++++----- kernel/module/main.c | 2 +- kernel/module/version.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-)
include/linux/module.h +2 -2
@@ -430,7 +430,7 @@ struct module {/* Exported symbols */ const struct kernel_symbol *syms; -const s32 *crcs; +const u32 *crcs;unsigned int num_syms;#ifdef CONFIG_ARCH_USES_CFI_TRAPS
@@ -448,7 +448,7 @@ struct module {/* GPL-only exported symbols. */ unsigned int num_gpl_syms;const struct kernel_symbol *gpl_syms; -const s32 *gpl_crcs; +const u32 *gpl_crcs;bool using_gplonly_symbols;#ifdef CONFIG_MODULE_SIG
kernel/module/internal.h +5 -5
@@ -55,8 +55,8 @@ extern const struct kernel_symbol __start___ksymtab[];extern const struct kernel_symbol __stop___ksymtab[];extern const struct kernel_symbol __start___ksymtab_gpl[];extern const struct kernel_symbol __stop___ksymtab_gpl[]; -extern const s32 __start___kcrctab[]; -extern const s32 __start___kcrctab_gpl[]; +extern const u32 __start___kcrctab[]; +extern const u32 __start___kcrctab_gpl[];struct load_info {const char *name;
@@ -102,7 +102,7 @@ struct find_symbol_arg {/* Output */ struct module *owner; -const s32 *crc; +const u32 *crc;const struct kernel_symbol *sym;enum mod_license license; };
@@ -384,7 +384,7 @@ static inline void init_param_lock(struct module *mod) { }#ifdef CONFIG_MODVERSIONS int check_version (const struct load_info *info, -const char *symname,struct module *mod,const s32 *crc); +const char *symname,struct module *mod,const u32 *crc);void module_layout (struct module *mod,struct modversion_info *ver,struct kernel_param *kp,struct kernel_symbol *ks,struct tracepoint *const *tp);int check_modstruct_version (const struct load_info *info,struct module *mod);
@@ -393,7 +393,7 @@ int same_magic(const char *amagic, const char *bmagic, bool has_crcs);static inline int check_version (const struct load_info *info,const char *symname,struct module *mod, -const s32 *crc) +const u32 *crc) {return 1 ; }
kernel/module/main.c +1 -1
@@ -86,7 +86,7 @@ struct mod_tree_root mod_tree __cacheline_aligned = {struct symsearch {const struct kernel_symbol *start, *stop; -const s32 *crcs; +const u32 *crcs;enum mod_license license; };
kernel/module/version.c +1 -1
@@ -13,7 +13,7 @@int check_version (const struct load_info *info,const char *symname,struct module *mod, -const s32 *crc) +const u32 *crc) {Elf_Shdr *sechdrs = info->sechdrs;unsigned int versindex = info->index.vers;
Signature · 1 line
2.43.0
Re: [PATCH 1/2] module: get symbol crc back to unsigned
Quoted 13 lines · Masahiro Yamada
Commit
71810db27c1c("modversions: treat symbol CRCs as 32 bit quantities") changed the CRC fields to s32 because the__kcrctaband__kcrctab_gplsections contained relative references to the actual CRC values stored in the .rodata section whenCONFIG_MODULE_REL_CRCS=y.Commit
7b4537199a4a("kbuild: link symbol CRCs at final link, removingCONFIG_MODULE_REL_CRCS") removed this complexity. Now, the__kcrctaband__kcrctab_gplsections directly contain the CRC values in all cases.The genksyms tool outputs unsigned 32-bit CRC values, so u32 is preferred over s32.
Quoted 6 lines
No functional changes are intended.
Regardless of this change, the CRC value is assigned to the u32 variable, 'crcval' before the comparison, as seen in
kernel/module/version.c:crcval = *crc;
[Just in case for confused reviewers]
It was previously mandatory (but now optional) in order to avoid sign extension because the following line previously compared 'unsigned long' and 's32':
if (versions[i].crc == crcval)
return 1;versions[i].crc is still 'unsigned long' for backward compatibility.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 1/2] module: get symbol crc back to unsigned
In reply to Masahiro YamadaQuoted 12 lines · Masahiro Yamada
Commit
71810db27c1c("modversions: treat symbol CRCs as 32 bit quantities") changed the CRC fields to s32 because the__kcrctaband__kcrctab_gplsections contained relative references to the actual CRC values stored in the .rodata section whenCONFIG_MODULE_REL_CRCS=y.Commit
7b4537199a4a("kbuild: link symbol CRCs at final link, removingCONFIG_MODULE_REL_CRCS") removed this complexity. Now, the__kcrctaband__kcrctab_gplsections directly contain the CRC values in all cases.The genksyms tool outputs unsigned 32-bit CRC values, so u32 is preferred over s32.
Quoted 8 lines
No functional changes are intended.
Regardless of this change, the CRC value is assigned to the u32 variable, 'crcval' before the comparison, as seen in
kernel/module/version.c:crcval = *crc;Signed-off-by Masahiro Yamada <[email protected]>
I understand the plan is for this to go through the kbuild tree with the rest of the extended modversions + Rust support.
Signature · 2 lines
Thanks, Petr
Re: [PATCH 1/2] module: get symbol crc back to unsigned
Quoted 19 lines · Petr Pavlu
Quoted 17 lines · Masahiro Yamada
Commit
71810db27c1c("modversions: treat symbol CRCs as 32 bit quantities") changed the CRC fields to s32 because the__kcrctaband__kcrctab_gplsections contained relative references to the actual CRC values stored in the .rodata section whenCONFIG_MODULE_REL_CRCS=y.Commit
7b4537199a4a("kbuild: link symbol CRCs at final link, removingCONFIG_MODULE_REL_CRCS") removed this complexity. Now, the__kcrctaband__kcrctab_gplsections directly contain the CRC values in all cases.The genksyms tool outputs unsigned 32-bit CRC values, so u32 is preferred over s32.
No functional changes are intended.
Regardless of this change, the CRC value is assigned to the u32 variable, 'crcval' before the comparison, as seen in
kernel/module/version.c:
Quoted 8 lines
Quoted 3 lines
crcval = *crc;Signed-off-by Masahiro Yamada <[email protected]>Reviewed-by Petr Pavlu <[email protected]>I understand the plan is for this to go through the kbuild tree with the rest of the extended modversions + Rust support.
Yes.
Now applied to linux-kbuild.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 2/2 modpost: zero-pad CRC values in modversion_info array
In reply to Masahiro YamadaI do not think the '#' flag is useful here because adding the explicit '0x' is clearer. Add the '0' flag to zero-pad the CRC values.
This change gives better alignment in the generated *.mod.c files. There is no impact to the compiled modules.
[Before]
$ grep -A5 modversion_info fs/efivarfs/efivarfs.mod.c
static const struct modversion_info ____versions[]
__used __section("__versions") = {
{ 0x907d14d, "blocking_notifier_chain_register" },
{ 0x53d3b64, "simple_inode_init_ts" },
{ 0x65487097, "__x86_indirect_thunk_rax" },
{ 0x122c3a7e, "_printk" },[After]
$ grep -A5 modversion_info fs/efivarfs/efivarfs.mod.c
static const struct modversion_info ____versions[]
__used __section("__versions") = {
{ 0x0907d14d, "blocking_notifier_chain_register" },
{ 0x053d3b64, "simple_inode_init_ts" },
{ 0x65487097, "__x86_indirect_thunk_rax" },
{ 0x122c3a7e, "_printk" },---
scripts/mod/modpost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/modpost.c +1 -1
@@ -1832,7 +1832,7 @@ static void add_versions(struct buffer *b, struct module *mod) s->name, mod->name);break ; } -buf_printf (b,"\t{ %#8x, \"%s\" },\n" , +buf_printf (b,"\t{ 0x%08x, \"%s\" },\n" , s->crc, s->name); }
Signature · 1 line
2.43.0