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 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 7E1E6C4321E for ; Sat, 26 Nov 2022 14:18:33 +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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7ZjiwlPzyP+gQzeVRIA2xHv8DQ2n2zUWeryER78bTIA=; b=hKQZjx3cHgYIrT cL83aSUN31nh+avo55B1uXpOAZMzVVcdRlelloGDZBf6DaqQC/UVhavowJCTb1HU6pmopohL4nhR+ IAISQytTjd8Hlaxdmuh7G5tljmEC7quk09e+sHKDNH24ui93UhTb8iDQccpxomEeRfSVkuE9uYA9m e5lwiP/zakBvoj/VDsdB9TXFizHA21HQvU5lWdJJMN+zLNIuDX9lHFnvHlt37XDQumZ0kjeY8DpEk 1fuFEN6JiLShkmtH1EdnV9jbRuD0I12IhGCjtmk2ymTj7T9//GpR6POvNm6KwW/NOwv+lyY9TmN+E 3f0Z3hIr4etqSP4m484g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oyvzp-006XH5-1a; Sat, 26 Nov 2022 14:17:33 +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 1oyvzl-006XFk-PL for linux-arm-kernel@lists.infradead.org; Sat, 26 Nov 2022 14:17:31 +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 3601360BB1 for ; Sat, 26 Nov 2022 14:17:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F12C43470 for ; Sat, 26 Nov 2022 14:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669472248; bh=DJK8fNeHfQxPHhzQPXs0XsZYEE+qp1g4/Pf81zviOUo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N3ge7Y4d9O6G3mq3/mZgwElOeiFs9ZyvNUG8YbZLkpOBMLPyPsFgTjqCtNsicMeCD 3SomGNC6mpDfiNrHVwITB5UEJ4Bp/OgzHl8iPaZVHRWQgdP3WkkIXFztHn8TqZ4Gpa 9zETuUN9jqOg2kg5v6U1nYcsUD58bE+DdHU4JK/dlaI0UsfW+Ilf49PA5TnrJ4YiJz bRS9T93AO6to/GvhBEU9Bkns3pATapsn5s3OwbVITkCz08XDY3AiKCUmE+uosYtHQr yGHMeMWmnwEXMo4jVhvAQcxoZygXfjqCF/vqQgr2ePux2wBDDZJQeiEBRn0tDJnB61 QsF5zKqqduUXw== Received: by mail-lf1-f53.google.com with SMTP id g7so10854452lfv.5 for ; Sat, 26 Nov 2022 06:17:28 -0800 (PST) X-Gm-Message-State: ANoB5pkW6zuygd1la+IzHx+AIYiNHFYixrjOCbEGum1nWYs4hvL/qldT E/t+EUfNdjNb6VntDEm+76YNDwAw+WbIGmOgQPE= X-Google-Smtp-Source: AA0mqf59qp2MotPQ6XEsC9PfjqNx7SNJ86aTwjY4Th7qIsXWtx33pjkJHLv/YvXTPK7kmcPh5umWuLui3G//NWuCSdk= X-Received: by 2002:a19:6b19:0:b0:4a2:740b:5b02 with SMTP id d25-20020a196b19000000b004a2740b5b02mr13860920lfa.122.1669472246516; Sat, 26 Nov 2022 06:17:26 -0800 (PST) MIME-Version: 1.0 References: <20221108182204.2447664-1-ardb@kernel.org> <20221115111658.GA32523@willie-the-truck> <20221115113134.GC32523@willie-the-truck> In-Reply-To: From: Ard Biesheuvel Date: Sat, 26 Nov 2022 15:17:15 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 0/7] arm64: efi: leave MMU and caches on at boot To: Will Deacon Cc: Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, keescook@chromium.org, Catalin Marinas , Marc Zyngier X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221126_061729_939012_1D3D8CF9 X-CRM114-Status: GOOD ( 39.43 ) 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: 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 Sat, 26 Nov 2022 at 15:16, Ard Biesheuvel wrote: > > On Tue, 15 Nov 2022 at 12:31, Will Deacon wrote: > > > > On Tue, Nov 15, 2022 at 12:21:55PM +0100, Ard Biesheuvel wrote: > > > On Tue, 15 Nov 2022 at 12:17, Will Deacon wrote: > > > > > > > > On Fri, Nov 11, 2022 at 05:36:19PM +0000, Mark Rutland wrote: > > > > > On Tue, Nov 08, 2022 at 07:21:57PM +0100, Ard Biesheuvel wrote: > > > > > > The purpose of this series is to remove any explicit cache maintenance > > > > > > for coherency during early boot that 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. > > > > > > > > > > As a high-level thing, I'm still very much not keen on entering the kernel with > > > > > the MMU on. Given that we have to support booting with the MMU off for !EFI > > > > > boot (including kexec when EFI is in use), I think this makes it harder to > > > > > reason about the boot code overall (e.g. due to the conditional maintenance > > > > > added to head.S), and adds more scope for error, even if it simplifies the EFI > > > > > stub itself. > > > > > > > > As discussed offline, two things that would help the current series are: > > > > > > > > (1) Some performance numbers comparing MMU off vs MMU on boot > > > > > > Finally got around to measuring this - I lost access to my TX2 machine > for a couple of days during the past week, > > With the patch below applied to mainline, I measure ~6 ms spent > cleaning the entire image to the PoC (which is the bulk of it) and > subsequently populating the initial ID map and activating it. > > This drops to about 0.6 ms with my changes applied. This is unlikely > to ever matter in practice, perhaps, but I will note that booting a VM > in EFI mode using Tianocore/EDK2 from the point where KVM clears the > counter to the point where we start user space can be done (on the > same machine) in 500-700 ms so it is not entirely insignificant > either. > > I could try and measure it on bare metal as well, but I suppose that > launch times are even less relevant there so I didn't bother. diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 61a87fa1c3055e26..27f59784a1c0be2c 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -22,6 +22,7 @@ SYM_CODE_START(efi_enter_kernel) ldr w2, =primary_entry_offset add x19, x0, x2 // relocated Image entrypoint mov x20, x1 // DTB address + mrs x27, cntvct_el0 /* * Clean the copied Image to the PoC, and ensure it is not shadowed by diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 2196aad7b55bcef0..068a7d111836382b 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -430,6 +430,8 @@ SYM_FUNC_START_LOCAL(__primary_switched) str_l x21, __fdt_pointer, x5 // Save FDT pointer + str_l x27, boot_args + 8, x5 + ldr_l x4, kimage_vaddr // Save the offset between sub x4, x4, x0 // the kernel virtual and str_l x4, kimage_voffset, x5 // physical mappings @@ -797,6 +799,10 @@ SYM_FUNC_START_LOCAL(__primary_switch) adrp x1, reserved_pg_dir adrp x2, init_idmap_pg_dir bl __enable_mmu + + mrs x0, cntvct_el0 + sub x27, x0, x27 + #ifdef CONFIG_RELOCATABLE adrp x23, KERNEL_START and x23, x23, MIN_KIMG_ALIGN - 1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel