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

Peter Zijlstra peterz at infradead.org
Tue Mar 17 04:24:53 PDT 2026


On Tue, Mar 17, 2026 at 11:59:49AM +0100, Ard Biesheuvel wrote:

> > +#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" \
> > +	    "	adrp	x16, 1f						\n" \
> > +	    "	ldr	x16, [x16, :lo12:1f]				\n" \
> > +	    "	cbz	x16, 0f						\n" \
> > +	    "	br	x16						\n" \
> > +	    "0:	ret							\n" \
> > +	    "	.type	" STATIC_CALL_TRAMP_STR(name) ", %function	\n" \
> > +	    "	.size	" STATIC_CALL_TRAMP_STR(name) ", . - " 
> > STATIC_CALL_TRAMP_STR(name) " \n" \
> > +	    "	.popsection						\n" \
> > +	    "	.pushsection .rodata, \"a\"				\n" \
> > +	    "	.align	3						\n" \
> > +	    "1:	.quad	" target "					\n" \
> > +	    "	.popsection						\n")

> > +void arch_static_call_transform(void *site, void *tramp, void *func, 
> > bool tail)
> > +{
> > +	u64 literal;
> > +	int ret;
> > +
> 
> Here, set func to &__static_call_return0 if it is NULL.

I'm confused. NULL is for the static_call_cond() case, where we NO-OP.
And the trampoline above does that cbz 0f to ret. So far so good.

But ret0 should return 0, and IIRC arm64 uses x0 for the return value.
But I don't see the above clearing it. Hmm?

> > +	/* decode the instructions to discover the literal address */
> > +	literal = ALIGN_DOWN((u64)tramp + 4, SZ_4K) +
> > +		  aarch64_insn_adrp_get_offset(le32_to_cpup(tramp + 4)) +
> > +		  8 * aarch64_insn_decode_immediate(AARCH64_INSN_IMM_12,
> > +						    le32_to_cpup(tramp + 8));
> > +
> > +	ret = aarch64_insn_write_literal_u64((void *)literal, (u64)func);
> > +	WARN_ON_ONCE(ret);
> > +}
> > +EXPORT_SYMBOL_GPL(arch_static_call_transform);



More information about the linux-arm-kernel mailing list