Re: [PATCH] module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD

From: Peter Zijlstra
Date: Tue Mar 23 2021 - 10:54:21 EST


On Tue, Mar 23, 2021 at 03:27:56PM +0100, Jessica Yu wrote:
> Dynamic code patching (alternatives, jump_label and static_call) can
> have sites in __exit code, even if __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 the section ordering should look like the following when
> !CONFIG_MODULE_UNLOAD, 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 the changelog]
>
> Link: https://lore.kernel.org/lkml/YFiuphGw0RKehWsQ@gunter/
> Signed-off-by: Jessica Yu <jeyu@xxxxxxxxxx>

Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

> ---
>
> Do you want to take this patch with the other static_call patches? Or
> should I take this through modules-next?

Take it through modules-next, I haven't seen an actual report on this
and it's been broken forever afaict. I only found it by accident while
chasing this other problem.