Skip to content

Commit 3312134

Browse files
author
Jessica Yu
committed
module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
Dynamic code patching (alternatives, jump_label and static_call) can have sites in __exit code, even it __exit is never executed. Therefore __exit must be present at runtime, at least for as long as __init code is. Additionally, for jump_label and static_call, the __exit sites must also identify as within_module_init(), such that the infrastructure is aware to never touch them after module init -- alternatives are only ran once at init and hence don't have this particular constraint. By making __exit identify as __init for MODULE_UNLOAD, the above is satisfied. So, when !CONFIG_MODULE_UNLOAD, the section ordering should look like the following, with the .exit sections moved to the init region of the module. Core section allocation order: .text .rodata __ksymtab_gpl __ksymtab_strings .note.* sections .bss .data .gnu.linkonce.this_module Init section allocation order: .init.text .exit.text .symtab .strtab [jeyu: thanks to Peter Zijlstra for most of changelog] Link: https://lore.kernel.org/lkml/YFiuphGw0RKehWsQ@gunter/ Link: https://lore.kernel.org/r/[email protected] Acked-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Jessica Yu <[email protected]>
1 parent 1e28eed commit 3312134

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

kernel/module.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,11 @@ void * __weak module_alloc(unsigned long size)
28022802

28032803
bool __weak module_init_section(const char *name)
28042804
{
2805+
#ifndef CONFIG_MODULE_UNLOAD
2806+
return strstarts(name, ".init") || module_exit_section(name);
2807+
#else
28052808
return strstarts(name, ".init");
2809+
#endif
28062810
}
28072811

28082812
bool __weak module_exit_section(const char *name)
@@ -3116,11 +3120,6 @@ static int rewrite_section_headers(struct load_info *info, int flags)
31163120
*/
31173121
shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
31183122

3119-
#ifndef CONFIG_MODULE_UNLOAD
3120-
/* Don't load .exit sections */
3121-
if (module_exit_section(info->secstrings+shdr->sh_name))
3122-
shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
3123-
#endif
31243123
}
31253124

31263125
/* Track but don't keep modinfo and version sections. */

0 commit comments

Comments
 (0)