From patchwork Tue Nov 29 16:14:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13058802 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 8D6F1C4167B for ; Tue, 29 Nov 2022 16:16:40 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=C41J00ttFI7U8D2x48DdrGDjCF5NSnIRcSQzABuA4aQ=; b=pFQFHjVJpbDcE7 wmf9Dl0d54y66nhx+pDue4D3uat8FTUoyue82qGWTGA0QQDviYEmOveS6AtfkaxxdPgMiS8PaIDy7 YkLNnP6OVUyi0m46aOcnJfBi3IZ4JoR8P1MM/G1m7D7kaOXqwcNu84CXSNtjAitdL1qTQn7EEaFJj RWTPpauK7LQOxpdSLj+2aN271HH0BdAMccrEwfPpAMoOQmW1oKSv1Qz5bfIjc6RFuA8j39Tp7RIAs VGIgQLW7gtjVbfdcPN62RPolfYDC154cFoGkvGmYOO4s9fqs2J+D8W3uy7XrjN7H20jEomf1R1zPr RRB3rpASv2jOBPjS2GSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p03Gm-00A0ry-Jr; Tue, 29 Nov 2022 16:15:40 +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 1p03FZ-00A0Vv-Qj for linux-arm-kernel@lists.infradead.org; Tue, 29 Nov 2022 16:14:27 +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 7E43F617D5; Tue, 29 Nov 2022 16:14:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 910A6C433C1; Tue, 29 Nov 2022 16:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669738463; bh=WQeEI1SZgeidT19/EcC8w7h2WmobuNCj98QqBxYFcOw=; h=From:To:Cc:Subject:Date:From; b=P8g3Plat9c4NJ207dM4PiwZd5qaIgBGDOLvIYJWbmYzsaqak/TfFcNWX+Fgn5ah3V ckC6UaJkVm2QS7Zv32pse5Wuz+vxl8MezNastDnYgDPmfbGuuJKV4RNe89H14gPECY ogGyPpUpYYW3xvsrNIxrHDHHIPLpPBildoI32Twg8fD8lZSjTuX9fYtkf9IasnHF4E SB5/4/fdLjmtVB4guRmPomkqVnExyQOysOLvvh+mKdekk23S6UdfYSW2CsLT5wmr/k cSvaHlgQ8XwVQdtE/yYfcQjIoY9I+CsuHP/AsOihgPZRzQ87YF3Pf1WXTXbWqP5sfV 5rj+wMTltDl7Q== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Will Deacon , Catalin Marinas , Marc Zyngier , Mark Rutland Subject: [PATCH v6 0/6] arm64: Permit EFI boot with MMU and caches on Date: Tue, 29 Nov 2022 17:14:12 +0100 Message-Id: <20221129161418.1968319-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3448; i=ardb@kernel.org; h=from:subject; bh=WQeEI1SZgeidT19/EcC8w7h2WmobuNCj98QqBxYFcOw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjhi/OYz+jVun4/vet0y/vmIXtOFZ3lf2kBbbXuWse Io1aOu6JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY4YvzgAKCRDDTyI5ktmPJODgDA CqkOUaUKlKz6cEPPtpzXRJNxrvJ4WTl/o7JS06pjEIT3odV1U11qCfdM1rEbUvOX4KtG9DV0CI/ulm rP+GRxvw7eGamx3An6XaK5O3lg5zrUe7K8CtTaVr9Jnrvgf2Qv2TyII5gAgrKPW1DbQsSbmGsPblRM vAGcCsnvr1vSAOZkzmKcEuAzMQZ1nSYF9mTKYcoY7eDvV9RXURU02T/doiEZR+CDgzxdt8bdgDvtH6 OGW/FKlo32uI6WgmOfCW+QPpXTe4BDe+DA7QNu+NSa3rzIB66qa8egu9QAPLQOO/y6hmBqS67mh+d4 wN1i4MLcAUmkhAReu4aCUsA4d4NLj47nVULdwaQlEc5k5uICNkHsegclQUWOudbpnNiGIQj5Qo3Xqk KDxoRMgPXuSLnlH742LZRnaF3oyhlMu1+a0tQYVvKR2fPT3n6kcKhxbwECi5mVtGzLLGYVFuPIOldG MirkXcNNbDY78obZ1pA9s2dNthKH/2IR4Es1L5iJXkv8c= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221129_081426_008212_7575DBFE X-CRM114-Status: GOOD ( 23.30 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The purpose of this series is to remove any explicit cache maintenance for coherency during early boot. Software managed coherency is error prone and tedious, and running with the MMU off is generally bad for performance, and it becomes unnecessary if we simply retain the cacheable 1:1 mapping of all of system RAM provided by EFI, and use it to populate the ID map page tables. After setting up this preliminary ID map, we disable the MMU, drop to EL1, reprogram the MAIR, TCR and SCTLR registers as before, and proceed as usual, avoiding the need for any manipulations of memory while the MMU and caches are off. The only properties of the firmware provided 1:1 map we rely on is that it does not require any explicit cache maintenance for coherency, and that it covers the entire memory footprint of the image, including the BSS and padding at the end - all else is under control of the kernel itself, as before. Patch #6 is optional, and moved to the end. It reduces the likelihood that an image needs to be moved around in memory only to align the swapper vmap'ed stack, but it only affects 64k granule configurations, and with KASLR, the image is usually copied around anyway. Changes since v5: - add a special entry point into the boot sequence that is to be used by EFI only, and only permit booting with the MMU enabled when using that boot path; - omit the final patch that would need to go via the EFI tree in any case - adding the new entrypoint specific for EFI makes it conflict even more badly, and I'll try to revisit this during the merge window or simply defer the final piece for the next release; Changes since v4: - add patch to align the callers of finalise_el2() - also clean HYP text to the PoC when booting at EL2 with the MMU on - add a warning and a taint when doing non-EFI boot with the MMU and caches enabled - rebase onto zboot changes in efi/next - this means that patches #6 and #7 will not apply onto arm64/for-next so a shared stable branch will be needed if we want to queue this up for v6.2 Changes since v3: - drop EFI_LOADER_CODE memory type patch that has been queued in the mean time - rebased onto [partial] series that moves efi-entry.S into the libstub/ source directory - fixed a correctness issue in patch #2 Cc: Will Deacon Cc: Catalin Marinas Cc: Marc Zyngier Cc: Mark Rutland Ard Biesheuvel (6): arm64: head: Move all finalise_el2 calls to after __enable_mmu arm64: kernel: move identity map out of .text mapping arm64: head: record the MMU state at primary entry arm64: head: avoid cache invalidation when entering with the MMU on arm64: head: Clean the ID map and the HYP text to the PoC if needed arm64: lds: reduce effective minimum image alignment to 64k arch/arm64/include/asm/efi.h | 7 -- arch/arm64/kernel/head.S | 99 +++++++++++++++----- arch/arm64/kernel/image-vars.h | 2 +- arch/arm64/kernel/setup.c | 9 +- arch/arm64/kernel/sleep.S | 6 +- arch/arm64/kernel/vmlinux.lds.S | 13 ++- arch/arm64/mm/proc.S | 2 - drivers/firmware/efi/libstub/arm64-stub.c | 2 +- include/linux/efi.h | 6 +- 9 files changed, 104 insertions(+), 42 deletions(-)