From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 698C1C433DF for ; Thu, 2 Jul 2020 11:58:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36B4E20737 for ; Thu, 2 Jul 2020 11:58:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OOCuFqlo"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="iPcAwwkK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36B4E20737 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=M6Uw0OoKez8C9vB4+eOTVU66kc8CLziChnARwn+hEAU=; b=OOCuFqlonGFLNo2UdCLVTBB20 5rTLJFJemcn2yxVM7KGrL5IJQtdCmsOCtmWTOoUwN//RsAC6CLMvlj/UXXw6sUp3pIihGaJhw8ltl fW5IR0rlhUgjlQU2Q1UyR5fLj/b0zHAw4yNG5vz3QoKYyGnh2kXOKXKMV15KnlQEFciMh5FwJ3p0i ou81ZotY6MO8oG9aT0LQOjr49AOGB6kKxaEkUVWN6E60xHO5JPmc/8LKtsEEmtRKhIOTFmw4Sq3aL hRFitBkfBhpJ/jKLyq+4jOr2WQC8/7AYaydHPj2L7I9sCOEeao1/Ongr96hK0nyq83YXPO6jOfYwC UusgPepCQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqxps-00017C-M9; Thu, 02 Jul 2020 11:57:00 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqxpo-00015p-MS for linux-arm-kernel@lists.infradead.org; Thu, 02 Jul 2020 11:56:58 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1A74920737; Thu, 2 Jul 2020 11:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593691015; bh=EjxlXTj7ssiZIzlhD0qbn2OzPNKdjFxHxvGC9fKsIuM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iPcAwwkKV3MO4ReexI5CLqqHji+/S1zOjqVoFDUevLxWldta/V8AE8DmV0P458EEg BCnuyc4+mmDxMkaoF1AXdxp6Se1aQbSEkao3hqeXNYKQ/jQKgkbn6deBqEFA/MSj1F 6B6fuTpRxyK8nj8BH9uNtlbYVD8IGfF6z+Eb51Ao= Date: Thu, 2 Jul 2020 12:56:50 +0100 From: Will Deacon To: Ard Biesheuvel Subject: Re: [PATCH] arm64/alternatives: use subsections for replacement sequences Message-ID: <20200702115650.GC16499@willie-the-truck> References: <20200630081921.13443-1-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200630081921.13443-1-ardb@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200702_075656_880004_32D7E427 X-CRM114-Status: GOOD ( 24.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, anders.roxell@linaro.org, arnd@arndb.de, Suzuki K Poulose , catalin.marinas@arm.com, James Morse , Andre Przywara , Dave P Martin , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 30, 2020 at 10:19:21AM +0200, Ard Biesheuvel wrote: > When building very large kernels, the logic that emits replacement > sequences for alternatives fails when relative branches are present > in the code that is emitted into the .altinstr_replacement section > and patched in at the original site and fixed up. The reason is that > the linker will insert veneers if relative branches go out of range, > and due to the relative distance of the .altinstr_replacement from > the .text section where its branch targets usually live, veneers > may be emitted at the end of the .altinstr_replacement section, with > the relative branches in the sequence pointed at the veneers instead > of the actual target. > > The alternatives patching logic will attempt to fix up the branch to > point to its original target, which will be the veneer in this case, > but given that the patch site is likely to be far away as well, it > will be out of range and so patching will fail. There are other cases > where these veneers are problematic, e.g., when the target of the > branch is in .text while the patch site is in .init.text, in which > case putting the replacement sequence inside .text may not help either. > > So let's use subsections to emit the replacement code as closely as > possible to the patch site, to ensure that veneers are only likely to > be emitted if they are required at the patch site as well, in which > case they will be in range for the replacement sequence both before > and after it is transported to the patch site. > > This will prevent alternative sequences in non-init code from being > released from memory after boot, but this is tolerable given that the > entire section is only 512 KB on an allyesconfig build (which weighs in > at 500+ MB for the entire Image). Also, note that modules today carry > the replacement sequences in non-init sections as well, and any of > those that target init code will be emitted into init sections after > this change. > > This fixes an early crash when booting an allyesconfig kernel on a > system where any of the alternatives sequences containing relative > branches are activated at boot (e.g., ARM64_HAS_PAN on TX2) Given that this fixes a runtime failure with large kernel images (and potentially modules), I'll take this as a fix for 5.8 and we can rework it later on depending on how the discussion here winds up. Cheers. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel