Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2847420pxb; Tue, 21 Sep 2021 08:56:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxzFqml+/iL1mnO/qHHOGr9Pj+mKJshjxChK8BRm4XYD/h1r7Et717eFzQQ4DFebpSguF9 X-Received: by 2002:a05:6638:4122:: with SMTP id ay34mr642059jab.28.1632239789619; Tue, 21 Sep 2021 08:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632239789; cv=none; d=google.com; s=arc-20160816; b=VtggTiueNEzvLhPjyh1R0r8J+xuVVpEg78gDz7+seBjWq03kr+DySyHO+UJNf1KkaT bJuC1rJ+mPQjLV07tnLTGGn6G0lrdJU4QCgCuJ0EEvg8J3bBBEKakw/JZ+KTKBnqQRxv R6CdoZP2Ac1OiERujzicqXtvuloNscm9T2GfH2yEnlYBsOWVE1B0gUO19oSc1j5Yo1DR XBGKdRsPCtJXgKitLDdNTLwJb6Mfvym7Vbr/K6+UcDLFHPCiFKXKXnmvqTAXgyRtGQ5p jQ62xxgpopb3iY6AsAMM1Z8ar8dEZas3wSXyS09dil4c4ml7fcwks2qQkTmZkYF7AWl5 vW9A== 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=TT8DoZK+3xTsdP/HEhBUloD2GksvUPDRReGunsFrcOg=; b=QFh7xfnnG28slLBB5rakLBSKs2mzA8Lt8O0x7MYn2RJ75u3zrzuyA2T36CoPpFhuPj GmiUmsTkvpAOdN7ijE+SNwflnihnDnsZfWntYvK1BMzbDIXDK10iugjebKMBRQW1xTqY WkhRhopniA1EBBQpX678Vh1c8/SoRhtpWtHIZs+5Fxma0sAfE+Iffo7UsE8oyFAAe37/ gQgMZrWd7ZQItyXyZuozBQ+33HivRX5Ve4Aow1WpS2TYUHcxe8Vs0lxbpqZ9lYgjmMBY TjeyQ8VZZTfmjDlWchXh45lDTGvJWK41LRRXo2/g6ZyVTVZ2sKB4W5WL42ZtC+x+mlfR UXOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hGGtKQIe; 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 x6si17779023ilv.93.2021.09.21.08.56.17; Tue, 21 Sep 2021 08:56:29 -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=hGGtKQIe; 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 S232702AbhIUP4w (ORCPT + 99 others); Tue, 21 Sep 2021 11:56:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:42078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbhIUP4w (ORCPT ); Tue, 21 Sep 2021 11:56:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 89C4161186 for ; Tue, 21 Sep 2021 15:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632239723; bh=kDPtX/MRkj65TFHRvsxE7KeGMXH+4kcMkYw/S9qrDFI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hGGtKQIeLEGP6qDq0CnYhl1jn+cgq1VjEtwyH/pW5qpNL3cIpFQr96G/xV9PiF+hJ vMLk5CGH3xrBzgzTYsSpddR4tU7Tvr7VnJKxcSvQ9huVEs5fXvYSH+oHfkz2a0xxF4 vCPD6SDcv8eeL7uAYO3WAZLZElRXilA6PvA027IAPYz6KOxRxPmpCBHUDV4mlo/+Gv I+af0bLIkYgU3msqwDkb5mOk+eAOvPEXcPAiND/sMkwXFe2TdxXfY7MVY4TbJ0SmLt sZDjCeFkTvd3UVsqQ1spBN6ZcRIXq5gD24pZrmYzRjc6C9Z5C8js+z3VhCvfdBOCtw 2EzsdNw/T80ig== Received: by mail-ot1-f47.google.com with SMTP id c8-20020a9d6c88000000b00517cd06302dso28903134otr.13 for ; Tue, 21 Sep 2021 08:55:23 -0700 (PDT) X-Gm-Message-State: AOAM532zAGFJMUECsCX5OEuj6Fzcf+CLjvXwNoexGezI9BWnX4EzqaTi JmXaDKt2l2n0TklJ02K1zBz8aBSoDPiHl81avJU= X-Received: by 2002:a9d:200b:: with SMTP id n11mr25952913ota.30.1632239722938; Tue, 21 Sep 2021 08:55:22 -0700 (PDT) MIME-Version: 1.0 References: <20210920233237.90463-1-frederic@kernel.org> <20210920233237.90463-3-frederic@kernel.org> <20210921153352.GC35846@C02TD0UTHF1T.local> In-Reply-To: <20210921153352.GC35846@C02TD0UTHF1T.local> From: Ard Biesheuvel Date: Tue, 21 Sep 2021 17:55:11 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/4] arm64: implement support for static call trampolines To: Mark Rutland Cc: Peter Zijlstra , Frederic Weisbecker , Catalin Marinas , Will Deacon , LKML , James Morse , Quentin Perret , 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 17:33, Mark Rutland wrote: > > On Tue, Sep 21, 2021 at 04:44:56PM +0200, Ard Biesheuvel wrote: > > On Tue, 21 Sept 2021 at 09:10, Peter Zijlstra wrote: ... > > > > > > 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. > > I think so, yes. We can do sligntly better with an inline literal pool > and a PC-relative LDR to fold the ADRP+LDR, e.g. > > .align 3 > tramp: > BTI C > {B | RET | NOP} > LDR X16, 1f > BR X16 > 1: .quad > > Since that's in the .text, it's RO for regular accesses anyway. > I tried to keep the literal in .rodata to avoid inadvertent gadgets and/or anticipate exec-only mappings of .text, but that may be a bit overzealous. > > But I must be missing something here, or why did we have that long > > discussion before? > > I think the long discussion was because v2 had some more complex options > (mostly due to trying to use ADRP+ADD) and atomicity/preemption issues > meant we could only transition between some of those one-way, and it was > subtle/complex: > > https://lore.kernel.org/linux-arm-kernel/20201028184114.6834-1-ardb@kernel.org/ > Ah yes, I was trying to use ADRP/ADD to avoid the load, and this is what created all the complexity. > For v3, that was all gone, but we didn't have a user. > > Since the common case *should* be handled by {B | RET | NOP }, I > reckon it's fine to have just that and the literal pool fallback (which > I'll definitely need for the sorts of kernel I run when fuzzing, where > the kernel Image itself can be 100s of MiBs). Ack. So I'll respin this along these lines. Do we care deeply about the branch and the literal being transiently out of sync?