Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp441326pxb; Mon, 25 Oct 2021 11:15:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH9vH+FtbMdtnJSqfkgvLEAxT74zeTxFMG7Njs511aUTtU70A6Lq3Qb1lgsTk6r4Q9znJq X-Received: by 2002:a17:907:2638:: with SMTP id aq24mr12234770ejc.95.1635185720149; Mon, 25 Oct 2021 11:15:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635185720; cv=none; d=google.com; s=arc-20160816; b=KzK72x2LIMgNftQRF4CDa+5+ss+aY+v9FNCraWJvgV6BdSPHesFL7yILK+3kTXB5TV ijkSzAMYFTKJMz2i4426tubZnOA3J+j8p2r2TPmaUS0WXGKvG1s64U7YgxrSMU1OtPGq oJDzBJgFSNP+6V9T+kcZanAggXwvWdHEslIpzjxzxZy6c9iV1T4zcP80C0e/kCRyqt2b jIArGEKDIlg+Bv+qhjRv2sDzuFdLpeoxCdPD3hmv4FysAg6I2TH/5X8IoV4UuiDOllzW gQ1Ay6qW2cVT0vnEysRC7ghNCP21scPHujuXqMQlvtq2dm7wE/3dosm/pDXBPPjxWin/ kB/g== 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=ZzANZLVGiwLe+6KxV4JCByazHPOzOeWQ69t7fMgGi2E=; b=lu1lJL5q+TGZTbs5zjDZBnGEfkSUloo7xr/lOKfHzpkPd3fgDvRMkh/QZcXwwZCcdA lhCaqSqAS9I27iQSOCiRHxMqxHKLpS0+9szrApPreYDhYBlUh29qf5xCVhWqr6WFYy7j 0TDS50AXqfl+pv5Wzt1HrET6CEnmED8kSQxGml4kf9hg7RpQ2woqKpvXr/740AJPIWgo B93KgcAHqj7p1XSIIsEMyP7IxaA1OhEU/XYhZKw8iCZBzzBCqM/GwG2W3Pa/dqbuOAnK Yj33bY27sbiJ1rgfyz94bvzPqHmJF6GdXG2kSObL1rfn88lJCi5asM00lw4lmnOxE0t5 i82A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kBNwx69b; 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 b10si32933285edz.150.2021.10.25.11.14.55; Mon, 25 Oct 2021 11:15:20 -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=kBNwx69b; 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 S233532AbhJYOeJ (ORCPT + 99 others); Mon, 25 Oct 2021 10:34:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:60216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbhJYOeI (ORCPT ); Mon, 25 Oct 2021 10:34:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30C4C61040 for ; Mon, 25 Oct 2021 14:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635172306; bh=YQoHO4ZpYmdFlmGOcwSkvmsVimif+mkXV5GbbYqtXAk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kBNwx69bzjyxzoQsy2AuBpJGr5/qNxR8SbS7we12Y1zuM4BQaZ49/8TNX5OJbMA6Q Xgf1NVjhGDJWPGNo7FpLjmkRSx/2e/iSqtuAo240hF49zhvvIq/kgtCsDO+edy9dzk HQgIl/TYOaXwdaVUEPE/Z1e0SRlSfgQ2J/jPiOnl+HIY0f/jcGtBzgzSfKrnSvbcOU VRexAipW51rEDtJmn1X8n9atYTEhMkDiMwolRIgXouNNRSrtESYhUtZwshOLPIllQF +D6R37Y+0KxhQX36SoBI2NQPlhE7RA0KWRrE/tP59UW/bzZivdEGbNVgmPNCupirEF Pnx7V2t2SJ9vw== Received: by mail-oi1-f178.google.com with SMTP id y207so15780058oia.11 for ; Mon, 25 Oct 2021 07:31:46 -0700 (PDT) X-Gm-Message-State: AOAM533ros80imxu00Ydz4sOMDU3DD1sJU0KcSHvvYDTQViNTzEIuWoE kweazfoxfmSQuNEhQGu7rlrM0dq5qlrxo03ho2c= X-Received: by 2002:a05:6808:1805:: with SMTP id bh5mr22615854oib.47.1635172305463; Mon, 25 Oct 2021 07:31:45 -0700 (PDT) MIME-Version: 1.0 References: <20211025122102.46089-1-frederic@kernel.org> <20211025122102.46089-3-frederic@kernel.org> <1b19fbeccf3d4a75a5ed3a507d29f7dd@AcuMS.aculab.com> In-Reply-To: <1b19fbeccf3d4a75a5ed3a507d29f7dd@AcuMS.aculab.com> From: Ard Biesheuvel Date: Mon, 25 Oct 2021 16:31:34 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/4] arm64: implement support for static call trampolines To: David Laight Cc: Frederic Weisbecker , Peter Zijlstra , LKML , James Morse , Quentin Perret , Catalin Marinas , Will Deacon , Mark Rutland Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Oct 2021 at 16:25, David Laight wrote: > > From: Frederic Weisbecker > > Sent: 25 October 2021 13:21 > > > > Implement arm64 support for the 'unoptimized' static call variety, which > > routes all calls through a single trampoline that is patched to perform a > > tail call to the selected function. > > > > It is expected that the direct branch instruction will be able to cover > > the common case. However, given that static call targets may be located > > in modules loaded out of direct branching range, we need a fallback path > > that loads the address into R16 and uses a branch-to-register (BR) > > instruction to perform an indirect call. > > > ... > > +void arch_static_call_transform(void *site, void *tramp, void *func, bool tail) > > +{ > > + /* > > + * -0x8 > > + * 0x0 bti c <--- trampoline entry point > > + * 0x4 > > + * 0x8 ldr x16, > > + * 0xc cbz x16, 20 > > + * 0x10 br x16 > > + * 0x14 ret > > + */ > > Since the 'ldr x16, ' is just a 32bit constant > (for a pc-relative load). > I don't follow. Are you saying it is a 32-bit opcode? This applies to all AArch64 opcodes. > Can't you save a word by making offset 0x4 > ? > > Or am I missing something? > On arm64, we can only patch NOPs into branch instructions or vice versa, or we'd have to run the whole thing under stop_machine() to ensure that other cores don't fetch garbage.