Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B738ECAAD1 for ; Wed, 31 Aug 2022 10:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hCKJcqD7lPhV7UU5XXeblkFj5YU11JtuxNQKed/sxe4=; b=EmIpC6gZSJTEFbkLrZL/YFxGZB XhZXxHdFq/4pAG8VoZYyoYr9OHVM7DhA2idqf2gZVrecKd4xg750J0V2VFxaG4KaZNNgDgICE1jZK rNI2j1MyVXdHe6T41MZf1Ik3+jdv7v/wOZknikkQMIZOn3aAx2zjrQ1k3aV7M5lSx/lrmqhCuuKaI /de9IZoLgkcMJ6QknCu/N7zkPHB0Qkyrmp7ZPuj1Xin8imO5g8C1FEQ1d9URAnF553ZgT/xtT29eR Z9zs+3Nd4+gEzp3gAjEtx02rLDoGUbFB/+K0h8Xla/3kjsyJRXacDCpOW5v0Jjj4b+GnPuaSVnRob kT3JwyFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTLAR-005iYW-VF; Wed, 31 Aug 2022 10:41:56 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTLAO-005iWs-04 for linux-arm-kernel@lists.infradead.org; Wed, 31 Aug 2022 10:41:53 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D61B0614A0; Wed, 31 Aug 2022 10:41:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09168C433D6; Wed, 31 Aug 2022 10:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661942510; bh=ycBRJeTMvHFZgT6JA6cDryfQitK/UlOK7JWNXx3RyGY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Wzrh+zG123m20peLaODKKUzc77ie1xcTaD2os/mRRoAT+/8qdffQM+6x5Fd+DH0sW IVUYOesLCGRczZG/Jht9KGqL0Xm3kYVYlGm2y9iUaktrp3Bz2cyhyLECcdJjkUJSMk nFx9GfaNlA3tCcfPOggwOghLSWU7z9RFCGcK68x9PisUNYnoz2dJqoNmnt3Cmm1UVq GlEOHjc9e3vxZH7Yd1WN1Pd6cmi9lVd4LBoCLERiYymJDGby6vQk93ACeFFrCJHIDB r9Jze3xiKI3KYz/VuRykgH9CekUjh3DXC9a7EqpuOGD6q9HyiyC5cIuG30dKKDzI8u ce+gpa7/l3zBg== Date: Wed, 31 Aug 2022 11:41:45 +0100 From: Mark Brown To: D Scott Phillips Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , patches@amperecomputing.com Subject: Re: [PATCH] arm64: Work around missing `bti c` in modules Message-ID: References: <20220830200826.1432338-1-scott@os.amperecomputing.com> MIME-Version: 1.0 In-Reply-To: <20220830200826.1432338-1-scott@os.amperecomputing.com> X-Cookie: It's later than you think. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220831_034152_152878_8EC1AC68 X-CRM114-Status: GOOD ( 25.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============6613395792777553622==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============6613395792777553622== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="aP2T7fLnDtLnhJbL" Content-Disposition: inline --aP2T7fLnDtLnhJbL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Aug 30, 2022 at 01:08:26PM -0700, D Scott Phillips wrote: > GCC does not insert a `bti c` instruction at the beginning of a function > when all callers reach the function through a direct branch[1]. In the case > of cross-section calls (like __init to non __init), a thunk may be inserted > which uses an indirect branch. If that happens, the first instruction in > the callee function will result in a Branch Target Exception due to the > missing `bti c`. Oh, nice - I think this is a good approach. I'd been poking at things but not come up with anything yet and didn't want to just disable BTI since it'd disable BTI for the fairly large set of users with small enough kernels. It does weaken the protection but is clearly better than just disabling it. > + /* > + * GCC does not insert a `bti c` instruction at the beginning > + * of a function when all callers reach the function through a > + * direct branch. In the case of cross-section calls (like > + * __init to non __init), a thunk may be inserted which uses > + * an indirect branch. If that happens, the first instruction > + * in the callee function will result in a Branch Target > + * Exception due to the missing `bti c`. > + * > + * If that's the case here, clear PSTATE.BTYPE and resume. > + */ This comment should reference the bug, I'm assuming GCC will fix this at which point we should stop doing this. > + if (IS_ENABLED(CONFIG_CC_IS_GCC)) { I think we should add a new Kconfig symbol for this which is currently just def_bool y for GCC but which we can add a version check for when there is a fix so that kernels built with an unaffected toolchain don't have the workaround code. We could do that incrementally but we're more likely to remember if the placeholder is there already. --aP2T7fLnDtLnhJbL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmMPOugACgkQJNaLcl1U h9D3cgf/fbrQudVCYet8ZvwO8+Dpd28w82AF7uqyfm1dQ+oG8X5l7KF7412fzd1y hi9ceDsTQ1c3ZI+IGl0GM7gMkMo7qQsiXTHOWxCTRNorBmMezUNUn4QK6lgHmBLY PFqgqI+50PLytmmnkh9dz30KCS9/pdesiLP5PE3PKFZtnluH6TPDqNVa9odKDArC f//+ijWoZ96nUgW4B9gd57yZ3USUx16g8U/1wV2hI2fWSZmJ6hWdZxWBYO1BkH4S OcxWnLyiE6SOvk2NiQLl31/o/xYKT/GC80l1WHkfY4wbTRTZ6Tqsv32gG4p73tSc l1kZdWsANApabaerrV6MiA9Jk+6jrQ== =f6F3 -----END PGP SIGNATURE----- --aP2T7fLnDtLnhJbL-- --===============6613395792777553622== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============6613395792777553622==--