public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
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:24:53 +0100	[thread overview]
Message-ID: <20260317112453.GF2872@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <6053b599-c00e-47d0-8f9c-4554fec6d288@app.fastmail.com>

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);


  reply	other threads:[~2026-03-17 11:25 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 [this message]
2026-03-17 11:31     ` Ard Biesheuvel
2026-03-17 11:34       ` Peter Zijlstra

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=20260317112453.GF2872@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