From: Peter Zijlstra <peterz@infradead.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Carlos Llamas <cmllamas@google.com>,
linux-arm-kernel@lists.infradead.org,
Sami Tolvanen <samitolvanen@google.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, Kees Cook <kees@kernel.org>,
Quentin Perret <qperret@google.com>,
Steven Rostedt <rostedt@goodmis.org>,
Will McVicker <willmcvicker@google.com>,
Sean Christopherson <seanjc@google.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7] arm64: implement support for static call trampolines
Date: Tue, 17 Mar 2026 12:34:12 +0100 [thread overview]
Message-ID: <20260317113412.GH2872@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <f7ca0540-12d4-49eb-9baf-0ed254d3f340@app.fastmail.com>
On Tue, Mar 17, 2026 at 12:31:51PM +0100, Ard Biesheuvel wrote:
>
> On Tue, 17 Mar 2026, at 12:24, Peter Zijlstra wrote:
> > 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?
> >
(your MUA seems busted and generates these silly long lines, let me
reflow again)
> The RET0 case will tail call __static_call_return0() which will take
> care of this.
>
> I am just saying that the NULL case could just do the same, rather
> than have a conditional branch in the trampoline, as even in that
> case, the surrounding code must assume that X0 is clobbered.
> Alternatively, we could tail call __static_call_nop(), which would do
> just the 'ret'.
>
> IOW, if we guarantee that the target is always set to something
> appropriate, we can elide the NULL check, and __static_call_return0()
> and __static_call_nop() are equally appropriate for the NULL case.
Ah, yes that is possible. Trade that cbz for an unconditional branch to
a function. That works fine.
Do whatever is best for the uarch etc..
prev parent reply other threads:[~2026-03-17 11:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 6:18 [PATCH v7] arm64: implement support for static call trampolines Carlos Llamas
2026-03-13 8:52 ` Peter Zijlstra
2026-03-13 16:48 ` Sami Tolvanen
2026-03-13 17:15 ` Carlos Llamas
2026-03-17 10:59 ` Ard Biesheuvel
2026-03-17 11:24 ` Peter Zijlstra
2026-03-17 11:31 ` Ard Biesheuvel
2026-03-17 11:34 ` Peter Zijlstra [this message]
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=20260317113412.GH2872@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=cmllamas@google.com \
--cc=jpoimboe@kernel.org \
--cc=kees@kernel.org \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=qperret@google.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=seanjc@google.com \
--cc=will@kernel.org \
--cc=willmcvicker@google.com \
/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