Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2791732pxb; Tue, 21 Sep 2021 07:46:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2eWrjD0moeGccVeTFPDTX0xfs9pJYSLUdWreMahyEavdyfSX64e4M0o6seGoPmzK7UHIA X-Received: by 2002:a05:6602:1484:: with SMTP id a4mr322236iow.32.1632235582502; Tue, 21 Sep 2021 07:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632235582; cv=none; d=google.com; s=arc-20160816; b=t47qM1bFxSUwp+hRrSgNOJl7LUe2hmvuSNGnnHgf2+pJjJ/ltfzJ8+CJA4NNqvP/yn 3rcPqEqoGAIcugW3UMRVxYLvi1BKNdT3aECo3eR62R0C6awXTyXAIWFZl6zM+K7Vaowf Cse/6xOgW2NzLV6TJx62sMLkyld2t2d9NGMhdkXQknpf9sSbgirDsLnH0U0UpNVLjweP iZTpkzx+EgzZKtryrGX0UPsL4BrgInGaRkqDYubPxofMPhOBnoxqfYZfeAVLGSM0mtna 5M3Bh+yUhWMd3goBPZuMOxDRZBSnP6NoPW1UGbgU69mNWxH9sWwXXIgpLez+YeOI53og V7dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4KxGQseuLaslQ8CA4WEcKpSdsKqrh4N2Y0U1/Inwcrs=; b=pnQ0eMdGS3FnYA5kbdmZntUIoaI19NWwM7f7BrR8jqM7mRhvp19FAPSdwjL3DEVoJH P8qI1vWw/BWmICq0W3U7QXYpvIAuexkTMdJ8Z63K/2ABgWJr/TVlCCC6u+ZLJZgrDCE+ Ir2peL48HA7HvgMkooRpvGAoDlQvq8Rv1Gitk0D1hlOKZLzu27dtt8wPxbjSf7W8U5ZC dnWX6Zy8ZRJc4xBMUA1SKaudejTSPPN6maMyko5FsjE+oXdlWGZnREDlwC05+DtYUk9z fCRC+3LgEOQYb5P1UdxOSrYPnn+OjTHZbEyISKfsRIrrPntiVG0p3czspzMfkcbx1SP7 NeZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dDjtbQRd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si5220542ilv.9.2021.09.21.07.46.10; Tue, 21 Sep 2021 07:46:22 -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=@kernel.org header.s=k20201202 header.b=dDjtbQRd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233644AbhIUOqh (ORCPT + 99 others); Tue, 21 Sep 2021 10:46:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:37866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233602AbhIUOqg (ORCPT ); Tue, 21 Sep 2021 10:46:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 13DDC60F6E for ; Tue, 21 Sep 2021 14:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632235508; bh=yw0Lb+r3sKAkv29z7Ae8zME50OqwTA4KGuEpEDmu8is=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dDjtbQRd/Ynw2hUGVI77ILO3A8Z49AgAMHpoM//kZ//QMVd7kNc3ZIeBzfuq8VRjy CFs5A61KuDssQUVOZ3J3e+jQkpE+pKnpkJqOiMfNLv4YSGFeTShrfl+epDxDZU5DeR z1x0eD8MeMhGvf88S+kB/1NAG26vL1xe3rBg5CA2RaW3YX5wKvSROn7R+lfJwtLjkj 1ckFY85O5HrdUfLfQcTrZD20jkrkbWkXlC3TdEOnDoCXMgddyJzUThK8jc1VKHymP0 uB8ZPZeAPReIjiLA+Az1JgHmQ9HtBBwWyaRsURp9BVaKhOJ3CAOqr1oKOl/1dMtMMR elvDjLLJLnI9g== Received: by mail-ot1-f41.google.com with SMTP id c42-20020a05683034aa00b0051f4b99c40cso28669658otu.0 for ; Tue, 21 Sep 2021 07:45:08 -0700 (PDT) X-Gm-Message-State: AOAM531TYGJhbgk62MwcZ2LB1HDZm4vpnjJ9/jWJrodDDP7ngR+tSDcg WMX7SgoGUG8smX1pnyv2hV/9tOxNvxZyLE/089Q= X-Received: by 2002:a05:6830:3189:: with SMTP id p9mr23036206ots.147.1632235507451; Tue, 21 Sep 2021 07:45:07 -0700 (PDT) MIME-Version: 1.0 References: <20210920233237.90463-1-frederic@kernel.org> <20210920233237.90463-3-frederic@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Tue, 21 Sep 2021 16:44:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/4] arm64: implement support for static call trampolines To: Peter Zijlstra Cc: Frederic Weisbecker , Catalin Marinas , Will Deacon , LKML , James Morse , Quentin Perret , Mark Rutland , Christophe Leroy Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 21 Sept 2021 at 09:10, Peter Zijlstra wrote: > > On Tue, Sep 21, 2021 at 01:32:35AM +0200, Frederic Weisbecker 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" \ > > + " .popsection \n" \ > > + " .pushsection .rodata, \"a\" \n" \ > > + " .align 3 \n" \ > > + "1: .quad " target " \n" \ > > + " .popsection \n") > > So I like what Christophe did for PPC32: > > https://lkml.kernel.org/r/6ec2a7865ed6a5ec54ab46d026785bafe1d837ea.1630484892.git.christophe.leroy@csgroup.eu > > Where he starts with an unconditional jmp and uses that IFF the offset > fits and only does the data load when it doesn't. Ard, woulnd't that > also make sense on ARM64? I'm thinking most in-kernel function pointers > would actually fit, it's just the module muck that gets to have too > large pointers, no? > Yeah, I'd have to page that back in. But it seems like the following bti c adrp x16, ldr x16, [x16, ...] br x16 with either set to 'b target' for the near targets, 'ret' for the NULL target, and 'nop' for the far targets should work, and the architecture permits patching branches into NOPs and vice versa without special synchronization. But I must be missing something here, or why did we have that long discussion before?