Thread (9 messages) 9 messages, 5 authors, 2026-03-30

Re: [PATCH v7] arm64: implement support for static call trampolines

From: Carlos Llamas <cmllamas@google.com>
Date: 2026-03-13 17:15:36
Also in: lkml

On Fri, Mar 13, 2026 at 04:48:56PM +0000, Sami Tolvanen wrote:
On Fri, Mar 13, 2026 at 06:18:52AM +0000, Carlos Llamas wrote:
quoted
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>
Does this need a Co-developed-by tag as well?
The bulk of modifications came from the rebase itself and suggestions
from Ard. I skipped the Co-developed-by tag for this reason.
quoted
---
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.

 arch/arm64/Kconfig                   |  1 +
 arch/arm64/include/asm/static_call.h | 33 ++++++++++++++++++++++++++++
 arch/arm64/kernel/Makefile           |  1 +
 arch/arm64/kernel/static_call.c      | 20 +++++++++++++++++
 arch/arm64/kernel/vmlinux.lds.S      |  1 +
 5 files changed, 56 insertions(+)
 create mode 100644 arch/arm64/include/asm/static_call.h
 create mode 100644 arch/arm64/kernel/static_call.c
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 38dba5f7e4d2..9ea19b74b6c3 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -252,6 +252,7 @@ config ARM64
 	select HAVE_RSEQ
 	select HAVE_RUST if RUSTC_SUPPORTS_ARM64
 	select HAVE_STACKPROTECTOR
+	select HAVE_STATIC_CALL if CFI
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
diff --git a/arch/arm64/include/asm/static_call.h b/arch/arm64/include/asm/static_call.h
new file mode 100644
index 000000000000..331580542fd4
--- /dev/null
+++ b/arch/arm64/include/asm/static_call.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_STATIC_CALL_H
+#define _ASM_STATIC_CALL_H
+
+#define __ARCH_DEFINE_STATIC_CALL_TRAMP(name, target)			    \
+	asm("	.pushsection .static_call.text, \"ax\"			\n" \
+	    "	.align	3						\n" \
+	    "	.globl	" STATIC_CALL_TRAMP_STR(name) "			\n" \
+	    STATIC_CALL_TRAMP_STR(name) ":				\n" \
+	    "	hint	34	/* BTI C */				\n" \
It doesn't really matter either way, but do we still support toolchains
that don't understand "bti c"?
I tested with this early. A 8.2 gcc from the arm archives and it failed
to build:

   Error: selected processor does not support `bti c'

However, this was _before_ I added the conditional on CFI. Maybe clang
doesn't have this problem and technically speaking CFI would gate the
"bti c" usage? Because you can't have CFI and "old" gcc.

The CFI conditional might be later removed though so maybe lets keep it
as is?

--
Carlos Llamas
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help