Re: [PATCH v7] arm64: implement support for static call trampolines
From: Will Deacon <will@kernel.org>
Date: 2026-03-30 11:34:08
Also in:
lkml
Hi Carlos, On Fri, Mar 13, 2026 at 06:18:52AM +0000, Carlos Llamas wrote:
From: Ard Biesheuvel <ardb@kernel.org>
Implement arm64 support for the 'unoptimized' static call variety, which
routes all calls through a single trampoline that is patched to perform a
tail call to the selected function.
Since static call targets may be located in modules loaded out of direct
branching range, we need to use a ADRP/ADD pair to load the branch target
into R16 and use a branch-to-register (BR) instruction to perform an
indirect call. Unlike on x86, there is no pressing need on arm64 to avoid
indirect calls at all cost, but hiding it from the compiler as is done
here does have some benefits:
- the literal is located in .rodata, which gives us the same robustness
advantage that code patching does;
- no performance hit on CFI enabled Clang builds that decorate compiler
emitted indirect calls with branch target validity checks.
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
v7:
- Took Ard's v3 patch (as it leaves the code patching logic out) and
rebased it on top of mainline 7.0-rc3.
- Dropped the changes to arch/arm64/lib/insn.c and instead switched to
the (now) existing aarch64_insn_write_literal_u64().
- Added the RET0 trampoline define which points to the generic stub
__static_call_return0.
- Made the HAVE_STATIC_CALL conditional on CFI as suggested by Ard.
- Added .type and .size sections to the trampoline definition to
support ABI tools.Are you planning to respin this based on Ard's comments? Cheers, Will