Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp449149pxb; Mon, 25 Oct 2021 11:24:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Zf4i1jOas21W3V05AWKc+pwLqt12elhzPuE19qj+EhnNzfjmvVr6SM7KZI/HTwgnCjnZ X-Received: by 2002:a17:907:6e04:: with SMTP id sd4mr5619048ejc.40.1635186285006; Mon, 25 Oct 2021 11:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635186284; cv=none; d=google.com; s=arc-20160816; b=a9u7OCGlkpoJU1oUfVL4PkW3zQQJ+3+6uhQJ9WWtE9F76WdAZjQ++DsfDY2wAH9yRS EDIGea4Q96KpPcBbjRDAH2ilmbNh2enjRGE0FPdU80sOEGPbD29SqYhnMrVYxv4S4yQ9 IqOzAqmPioCCiEAySSfP2cofefNxrsCZNn1zPmuQwhNlsDU5L2EwbpJ6QrrX+Wsotode /uygXWvO06N01jEOzEYnHS1CUCqipcDThjU/RdvqT9rdOQ2+vAYrPxrj6SyAeBmWZJy8 38tqL9gLecX8AXe6n+Kc6196256JP9DTGwFL8KoD/xnrjRlrqzDv0RAP0q7h6B8UW2oF WP4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7JEK7+9XyR/LYEB+jCRSfqzJeyFXsGmCq275MlF6qHY=; b=QGCNaf7Cc/F/ETxFjhD53T0N01mp8azQV+nKYWAwjEPINB/JQh/xknn4HuJWKcJm6w njbvqOScSfFzZosDs5CAMAv4XlswuS+RzP5T7q8ajO887I4PnSg3r0zbVQ1b5D4AmF3L 4pdVxxy6NttITHaH0veNZDNcJ57HiimuDmKgKO+qotTAbD+WFhBqi0cgJ9PUpbCZnf44 DjR5pBZAfvua9xRoFlqYDC/6ozhTd7/zh3yZjrQSGEMiZgp3u3+HKCJDV0AZlZnYarl9 wS+26taVyK5PgE1UkT6l8OYRV1MRLn1jX+ndpINEznis4rpz6rynseE+3duuJi0MkxjF funw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Z3h+TDRZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn18si1798771ejc.579.2021.10.25.11.24.17; Mon, 25 Oct 2021 11:24:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Z3h+TDRZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233848AbhJYPIQ (ORCPT + 99 others); Mon, 25 Oct 2021 11:08:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbhJYPIN (ORCPT ); Mon, 25 Oct 2021 11:08:13 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C909EC061745 for ; Mon, 25 Oct 2021 08:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=7JEK7+9XyR/LYEB+jCRSfqzJeyFXsGmCq275MlF6qHY=; b=Z3h+TDRZci3jvRNL81hvKKd4ym Ucy3uISgZ3tbccPbsSc+Bv7dYzY3wjvJxkEl9blnrS1P1TT0F3toFnFN9q6yhUj0aeoFqMOjJODjl 50VY9VGU60rTICMyAgRfGG20m1g76Z1yniP204ZH952ZqMER97tml/qc6UYEwuDudfuaOX2FcWekY 1RKcO77iO0df/XSXpqtV5cb0idFw7FIxn45zEDkiN5ULzr4oEAg4vW+E0pbbvV5bPGALGj9o6i6M9 Mw+F2gErKEKU8FKbHz4QDl9emqPQaiXSfBy0g3X7MrtyYgRkyv0WQHpHJBhDQ9biygergu+IGJj3f g/+nfQoQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mf1V8-00GCjZ-4N; Mon, 25 Oct 2021 15:03:25 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D8B263002AE; Mon, 25 Oct 2021 17:03:00 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C1D462B7E450C; Mon, 25 Oct 2021 17:03:00 +0200 (CEST) Date: Mon, 25 Oct 2021 17:03:00 +0200 From: Peter Zijlstra To: Ard Biesheuvel Cc: Frederic Weisbecker , LKML , James Morse , David Laight , Quentin Perret , Catalin Marinas , Will Deacon , Mark Rutland Subject: Re: [PATCH 2/4] arm64: implement support for static call trampolines Message-ID: References: <20211025122102.46089-1-frederic@kernel.org> <20211025122102.46089-3-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021 at 04:55:17PM +0200, Ard Biesheuvel wrote: > On Mon, 25 Oct 2021 at 16:47, Peter Zijlstra wrote: > > Perhaps a little something like so.. Shaves 2 instructions off each > > trampoline. > > > > --- a/arch/arm64/include/asm/static_call.h > > +++ b/arch/arm64/include/asm/static_call.h > > @@ -11,9 +11,7 @@ > > " hint 34 /* BTI C */ \n" \ > > insn " \n" \ > > " ldr x16, 0b \n" \ > > - " cbz x16, 1f \n" \ > > " br x16 \n" \ > > - "1: ret \n" \ > > " .popsection \n") > > > > #define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func) \ > > --- a/arch/arm64/kernel/patching.c > > +++ b/arch/arm64/kernel/patching.c > > @@ -90,6 +90,11 @@ int __kprobes aarch64_insn_write(void *a > > return __aarch64_insn_write(addr, &i, AARCH64_INSN_SIZE); > > } > > > > +asm("__static_call_ret: \n" > > + " ret \n") > > + > > This breaks BTI as it lacks the landing pad, and it will be called indirectly. Argh! > > +extern void __static_call_ret(void); > > + > > Better to have an ordinary C function here (with consistent linkage), > but we need to take the address in a way that works with Clang CFI. There is that. > As the two additional instructions are on an ice cold path anyway, I'm > not sure this is an obvious improvement tbh. For me it's both simpler -- by virtue of being more consistent, and smaller. So double win :-) That is; you're already relying on the literal being unconditionally updated for the normal B foo -> NOP path, and having the RET -> NOP path be handled differently is just confusing. At least, that's how I'm seeing it today...