From: Ard Biesheuvel <ardb+git@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org,
Ard Biesheuvel <ardb@kernel.org>,
Mark Brown <broonie@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH 1/3] arm64: module: Keep executable init sections in the core text region
Date: Thu, 19 Nov 2026 17:58:27 +0100 [thread overview]
Message-ID: <20261119165825.1793558-6-ardb+git@google.com> (raw)
In-Reply-To: <20261119165825.1793558-5-ardb+git@google.com>
From: Ard Biesheuvel <ardb@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.
__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.
Signed-off-by: Ard Biesheuvel <ardb@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"))
+ return false;
+
+ return strstarts(name, ".init");
+}
+
+/*
+ * Without CONFIG_MODULE_UNLOAD, the module loader places .exit sections into
+ * the init region, as they will never be used. Keep .exit.text in the core
+ * text region in this case too, so that branches emitted into it are always
+ * guaranteed to be in range of the core PLT.
+ */
+bool module_exit_section(const char *name)
+{
+ if (strstarts(name, ".exit.text"))
+ return false;
+
+ return strstarts(name, ".exit");
+}
+
enum aarch64_reloc_op {
RELOC_OP_NONE,
RELOC_OP_ABS,
--
2.56.1.708.g77570a6a1d-goog
next prev parent reply other threads:[~2026-11-19 16:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:58 [PATCH 0/3] arm64: Combine module .init.text with .text Ard Biesheuvel
2026-11-19 16:58 ` Ard Biesheuvel [this message]
2026-11-19 16:58 ` [PATCH 2/3] arm64: Re-enable kernel BTI for compatible linkers Ard Biesheuvel
2026-11-19 16:58 ` [PATCH 3/3] arm64: module: Revert separate init PLT and init ftrace trampoline Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119165825.1793558-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jpoimboe@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=ndesaulniers@google.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox