arm64: ftrace: fix unreachable PLT for ftrace_caller in init_module with CONFIG_DYNAM...
authorpanfan <panfan@qti.qualcomm.com>
Fri, 5 Sep 2025 03:22:36 +0000 (20:22 -0700)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 5 Sep 2025 15:56:20 +0000 (16:56 +0100)
commita7ed7b9d0ebb038db9963d574da0311cab0b666a
tree48c19be83c71d60954d8cbfc0a9787ac084972be
parentf3ef7110924b897f4b79db9f7ac75d319ec09c4a
arm64: ftrace: fix unreachable PLT for ftrace_caller in init_module with CONFIG_DYNAMIC_FTRACE

On arm64, it has been possible for a module's sections to be placed more
than 128M away from each other since commit:

  commit 3e35d303ab7d ("arm64: module: rework module VA range selection")

Due to this, an ftrace callsite in a module's .init.text section can be
out of branch range for the module's ftrace PLT entry (in the module's
.text section). Any attempt to enable tracing of that callsite will
result in a BRK being patched into the callsite, resulting in a fatal
exception when the callsite is later executed.

Fix this by adding an additional trampoline for .init.text, which will
be within range.

No additional trampolines are necessary due to the way a given
module's executable sections are packed together. Any executable
section beginning with ".init" will be placed in MOD_INIT_TEXT,
and any other executable section, including those beginning with ".exit",
 will be placed in MOD_TEXT.

Fixes: 3e35d303ab7d ("arm64: module: rework module VA range selection")
Cc: <stable@vger.kernel.org> # 6.5.x
Signed-off-by: panfan <panfan@qti.qualcomm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20250905032236.3220885-1-panfan@qti.qualcomm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/module.h
arch/arm64/include/asm/module.lds.h
arch/arm64/kernel/ftrace.c
arch/arm64/kernel/module-plts.c
arch/arm64/kernel/module.c