From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B693AE1BA for ; Tue, 17 Mar 2026 11:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773747258; cv=none; b=AQGS45Lpvda9IBsCqU7hzEpMXDdfsg+HbvEko6vzgMTmk1b8BANGIUs3oZ1jriaR1tvcZnXpLw6aLrxhaAkXsXC9QwOgdpkFT1J8SrUhY3tjcOqHs0PT/0QSDzqr1UgyZ5wmkOxGAqFhz3PuRWNjIiJVEBX/AmCOlbwKmqhqR2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773747258; c=relaxed/simple; bh=E6a950fkgel9sZF1D3MXjaKyMwp4wN0aFkQLZeLkDHg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fJ9X16nshmp+7LuOv2nalV/XlX0BZs8m0CNYskXcAOu4oELOCr/cpZueNCMCkjlITZCSUarfTcD+PHh5i2klCEmOH/OBX4a/18lygm3lg8SAcFdlvUyONBUrBFDO9KprQ0JOwqF6Ne4tvfkLA0n0eCBilh1lQh5GcwCfHrgDCy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=M7lYv5Xp; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="M7lYv5Xp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fFGq4h2FsMq1y7NBHXlX2dn4AB2abDi/bzGCS8WpuJU=; b=M7lYv5Xp2lAjG/6SrXdNWmi37i K6UOtA4rybK6H6+eEOfmPiZ4Yp90PbIOMa0PJdA2kREOmzdF61EeJlqfGp1rssHuB0di5h4IcLsgq iIUZR2rUG10eOHuJQnGskZA8PiRw6y0HPG5gdeNwAeIoeisFnHgJ1i8EE3pMWn7vbMogrMwJX7SIL xOr/yhjkxyruHSti0MEaEQe6AhVpmy6XqguTeXwKljVCcPM/TqY9sb1yHgwxQ1ejT6ny+xLsVQJB5 T9udbYmUgVyumKFe/M4Ryc3ekjwSUOfU0vAQxTw3gBO+jnWuvAcQ9AiHTd2DoxbknGxfE8ZX+EEa8 uhIfOB/g==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1w2Sgf-00000008q9r-1N0M; Tue, 17 Mar 2026 11:34:13 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id D437A303244; Tue, 17 Mar 2026 12:34:12 +0100 (CET) Date: Tue, 17 Mar 2026 12:34:12 +0100 From: Peter Zijlstra To: Ard Biesheuvel Cc: Carlos Llamas , linux-arm-kernel@lists.infradead.org, Sami Tolvanen , Catalin Marinas , Will Deacon , Josh Poimboeuf , Mark Rutland , Kees Cook , Quentin Perret , Steven Rostedt , Will McVicker , Sean Christopherson , kernel-team@android.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7] arm64: implement support for static call trampolines Message-ID: <20260317113412.GH2872@noisy.programming.kicks-ass.net> References: <20260313061852.4025964-1-cmllamas@google.com> <6053b599-c00e-47d0-8f9c-4554fec6d288@app.fastmail.com> <20260317112453.GF2872@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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..