Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1395583rwr; Wed, 26 Apr 2023 14:32:20 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7YW/sNsJP75kRSKpe3FW6PVnSAMmA8r2wiShC1h8SyFJMWJXVfcLZrWTmdzLK/mCs9Cui X-Received: by 2002:a05:6a20:8f0d:b0:ef:5f:3c15 with SMTP id b13-20020a056a208f0d00b000ef005f3c15mr29378294pzk.47.1682544739825; Wed, 26 Apr 2023 14:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682544739; cv=none; d=google.com; s=arc-20160816; b=UE7do75QPmXaKmsmybijWMren+ZoRSFEG1VFAljUok7VCPY1r4NQ/EPi44D/TBXUU/ wBLO46RBfdUL3s7yPyFgXeQTQ+mudN6MJ42VePN+0WEEpIk5JsngRbkzzQa0VSo7nbq4 CfKMIPBVaPG9SDr81a/bHGLgGLzIcWXqQBG8lwaTkEsZjIvA2ZS2kDIrfyclbpP4/VR8 GyOqgJJyRwAfYGC1cSuPjXyak6DbtSe+25aDvwiUxVVR7cBxBmEri+3cRnuQWwQiFRec gssGIRN145rQh4pFf6Yu+QuKv1zKJP1r0GUAOVcWHhXYUTfz53iQ+m5MaxU6vFc0qxRP j/aQ== 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=uamOA6gyqrmEVbibMyFK1W1MansuzKlcMhq1YSrnzC0=; b=nl5MAOZBTCFwytm2oxRDJ7++pnpUpaBlCSTSpeXWdAEe3m9GjOkJvYw1NTIfT83EVj mu+WsjSTyKVIWFMLJ0HAg0EpaMbE80tMN9F7L77ehVYDEaR37X0uHJfKTH6fp6+PhyQL luli6zQQ9DglP0v+77nsA0qKfpYG0/89O7Ds4Ujwkp4pw9IUm6j64KQfLyWcQISmStn5 NMv5MQrd+lnE4F3ZFsqYV9mgUMsctGSTbCjaXkoKewWUVODojyAOAIMrA++PR9YQSGRs k2V6R3+4g32ztEnU6x7rMf+82DXiw1TjLzU+cJS7oMY70i1rqWZie6qg+zh101eGJ0A3 v9mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQMer08d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a63eb0a000000b0052069c10102si17058585pgh.75.2023.04.26.14.32.05; Wed, 26 Apr 2023 14:32:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQMer08d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240084AbjDZVa0 (ORCPT + 99 others); Wed, 26 Apr 2023 17:30:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240168AbjDZVaF (ORCPT ); Wed, 26 Apr 2023 17:30:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E04E40C8; Wed, 26 Apr 2023 14:29:52 -0700 (PDT) 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 8AC386394C; Wed, 26 Apr 2023 21:29:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3C62C433A1; Wed, 26 Apr 2023 21:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682544591; bh=yLi2JTeqjSBCZyJRqKGRsMaMom6VAZo/Dwzd3fLD8nk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UQMer08dWmP8i4EiUN/cLZ3ZUb7RgcamF/k5bFz6xHSkug0SQZUORXx7VcAoCVk9P qTMKow2h70Pgpy5xsxOL8jjuCVhg8yip10kC9sEQcphp98AHMXp7HEggB07BJl8Gyc Vm5LIGU2qj5GzjOU8WxT1hpjxtoa4icfod1gvgCTFCbEeJIwvdUE+iIU3O48HxJ2Ck VgXOk//PfM/CpARvNR0ZyhGABL82TFAuGuFOEfmK+vNRqCrp9X83BkilCFPIfvP1+v lNHDjt/tnEq/o2MEw5CPFtHxAjJFdLPoDKLgKf/ZJl4wvVq1oGlXFdSjyTbGjyEPyS aJj+vf5/9Uqcw== Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-4ec816c9d03so8460030e87.2; Wed, 26 Apr 2023 14:29:50 -0700 (PDT) X-Gm-Message-State: AAQBX9dIOOyMXH3HE0MSznhpNvwUf1M2wiYRYj9KtH9DaoSjHrKG/Q9e PLSXewC8G/GnFReytrF6dQ//aHopr69wXZbMBy0= X-Received: by 2002:a19:a40d:0:b0:4ed:cb37:7d95 with SMTP id q13-20020a19a40d000000b004edcb377d95mr5947487lfc.44.1682544589032; Wed, 26 Apr 2023 14:29:49 -0700 (PDT) MIME-Version: 1.0 References: <20230424165726.2245548-1-ardb@kernel.org> <20230424165726.2245548-5-ardb@kernel.org> <20230426104200.drmuewhwmhh3xljh@box.shutemov.name> In-Reply-To: <20230426104200.drmuewhwmhh3xljh@box.shutemov.name> From: Ard Biesheuvel Date: Wed, 26 Apr 2023 22:29:38 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/6] x86: efistub: Perform 4/5 level paging switch from the stub To: "Kirill A . Shutemov" Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , Linus Torvalds Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 26 Apr 2023 at 11:42, Kirill A . Shutemov wrote: > > On Mon, Apr 24, 2023 at 06:57:24PM +0200, Ard Biesheuvel wrote: > > In preparation for updating the EFI stub boot flow to avoid the bare > > metal decompressor code altogether, implement the support code for > > switching between 4 and 5 levels of paging before jumping to the kernel > > proper. > > I must admit it is neat. I like it a lot. > Thanks! > Any chance we can share the code with the traditional decompressor? > There's not much that EFI specific here. It should be possible to isolate > it from the rest, no? > I agree. The EFI boot code should still avoid the bare metal trampoline allocation/deallocation, but the actual payload could be the same - it's just an indirect call with the GDT and page table pointers as arguments. > > > @@ -792,6 +925,14 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, > > (get_efi_config_table(ACPI_20_TABLE_GUID) ?: > > get_efi_config_table(ACPI_TABLE_GUID)); > > > > +#ifdef CONFIG_X86_64 > > + status = efi_setup_5level_paging(); > > + if (status != EFI_SUCCESS) { > > + efi_err("efi_setup_5level_paging() failed!\n"); > > + goto fail; > > + } > > +#endif > > + > > /* > > * If the kernel isn't already loaded at a suitable address, > > * relocate it. > > @@ -910,6 +1051,10 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, > > goto fail; > > } > > > > +#ifdef CONFIG_X86_64 > > + efi_5level_switch(); > > +#endif > > + > > return bzimage_addr; > > fail: > > efi_err("efi_main() failed!\n"); > > Maybe use IS_ENABLED() + dummy efi_setup_5level_paging()/efi_5level_switch() > instead of #ifdefs? > These are functions returning void so I can just move the #ifdef into the function implementation. Wo do need #ifdefs at some level, as i386 does not provide a definition for __KERNEL32_CS