]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
authorJessica Yu <jeyu@kernel.org>
Tue, 23 Mar 2021 12:15:41 +0000 (13:15 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 May 2022 07:18:01 +0000 (09:18 +0200)
commit030de84d453a8ec3d99294246f8c07d845bb3828
tree46ecb352fb76c0f9958a8b32a274fb6f8482232c
parent355141fdbfef75b91973d2d34049accd1c06fd9e
module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD

commit 33121347fb1c359bd6e3e680b9f2c6ced5734a81 upstream.

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/20210323142756.11443-1-jeyu@kernel.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Cc: Joerg Vehlow <lkml@jv-coder.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/module.c