[PATCH 1/3] arm64: module: Keep executable init sections in the core text region
Ard Biesheuvel
ardb at kernel.org
Wed Nov 25 01:12:49 PST 2026
On Tue, 24 Nov 2026, at 22:40, Nick Desaulniers wrote:
> On Thu, Nov 19, 2026 at 8:58 AM Ard Biesheuvel <ardb+git at google.com> wrote:
>>
>> From: Ard Biesheuvel <ardb at kernel.org>
>>
>> Since commit 3e35d303ab7d ("arm64: module: rework module VA range
>> selection"), the core and init text regions of a module may end up more
>> than 128 MiB apart, i.e., out of direct branching range of each other.
>> This is why the module loader maintains a separate .init.plt section for
>> branches emitted into .init.text, and a separate ftrace trampoline for
>> ftrace callsites in .init.text.
>
> (Sorry, for picking nits in the commit message, but still think this
> could use a stronger problem statement up front, particularly some
> mention of BTI since without BTI this is a non-issue)
>
> "This is a problem because the compiler may omit BTI landing pads for
> such cross section calls, which can lead to BTI exceptions for large
> kernel modules that are built with BTI and make calls between
> .init.text and .text" (or something to that effect).
>
> i.e. commit message doesn't mention BTI at all, and BTI is why having
> those too-large-to-encode operands in a direct jump are problems.
>
> (two comments below on configs and includes)
>
>>
>> __init code typically makes up only a small fraction of a module's code,
>> so instead, keep .init.text in the core text region, by overriding
>> module_init_section(). Do the same for .exit.text in
>> module_exit_section(), which is only consulted when CONFIG_MODULE_UNLOAD
>> is disabled, in which case .exit sections are moved into the init region
>> too.
>>
>> On arm64 allmodconfig (10604 modules, disregarding modules with 'test' or
>> 'torture' in their name), this grows the aggregate size of the modules'
>> core text regions by 2.6 MB (+0.58%), or 243 bytes per module on
>> average. As this only costs an additional page at runtime if a module's
>> core text region happens to end within that many bytes of a page
>> boundary, this is expected to affect ~5.5% of modules. In practice, 527
>> modules (5%) grow by at least one page, of which 16 by more than one,
>> adding up to 567 pages of 4 KiB. Given that allmodconfig enables KASAN,
>> KCOV, UBSAN and GCOV instrumentation, which inflates __init code by
>> 1.5-2x, these figures should be taken as an upper bound.
>>
>> On a distro-style configuration without sanitizers (1023 modules), the
>> average growth is 104 bytes per module, or ~10 KiB per 100 loaded
>> modules, which is expected to cost ~2.5 additional pages of 4 KiB (or
>> ~0.6 pages of 16 KiB).
>>
>> This permits the separate init PLT and init ftrace trampoline to be
>> removed in a subsequent patch.
>
> Maybe not worth the trouble ("over configuration"), but I do wonder if
> you'd want to make either of the below changes conditional on BTI or
> MODULE_UNLOAD (as is, they are unconditional)? i.e. don't pay for what
> you don't use?
>
Replying here to both points:
Currently, we are paying for what we are rarely using, given that
.text is next to .init.text in 99% of the cases in practice, and so
the logic for .init PLT veneers and the alternative ftrace trampoline
is rarely exercised. Getting rid of those, as patch #3 does, is already
worth it imo.
But yes, BTI is the driver for this change, so it should be mentioned
as well.
>>
>> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
>> ---
>> arch/arm64/kernel/module.c | 33 ++++++++++++++++++++
>> 1 file changed, 33 insertions(+)
>>
>> diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
>> index 24adb581af0e..39e7a50733a9 100644
>> --- a/arch/arm64/kernel/module.c
>> +++ b/arch/arm64/kernel/module.c
>> @@ -25,6 +25,39 @@
>> #include <asm/sections.h>
>> #include <asm/text-patching.h>
>>
>> +/*
>> + * The module loader allocates the core and init text regions of a module
>> + * independently, and so they may end up out of direct branching range of each
>> + * other. This complicates the handling of PLTs and ftrace trampolines, which
>> + * need to be emitted within range of the branch instructions that use them.
>> + *
>> + * So keep executable .init sections in the core text region instead. This
>> + * costs a bit of memory, as __init code will no longer be freed after the
>> + * module's init routine returns, but this is usually a small fraction of the
>> + * overall size of the module. Non-executable .init sections are not affected.
>> + */
>> +bool module_init_section(const char *name)
>> +{
>> + if (strstarts(name, ".init.text"))
>
> #include <linux/string.h> # IWYU
>
Ack.
More information about the linux-arm-kernel
mailing list