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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 C68DBC432BE for ; Fri, 20 Aug 2021 16:11:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6AFB60FE8 for ; Fri, 20 Aug 2021 16:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbhHTQLt (ORCPT ); Fri, 20 Aug 2021 12:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbhHTQLn (ORCPT ); Fri, 20 Aug 2021 12:11:43 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F22C08EB27; Fri, 20 Aug 2021 09:04:51 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 8A63A95D; Fri, 20 Aug 2021 18:04:47 +0200 (CEST) Date: Fri, 20 Aug 2021 18:04:18 +0200 From: Joerg Roedel To: David Laight Cc: 'Ard Biesheuvel' , "x86@kernel.org" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "hpa@zytor.com" , Joerg Roedel , Kees Cook , Andy Lutomirski , Uros Bizjak , Arvind Sankar , "linux-kernel@vger.kernel.org" , Fabio Aiuto , "stable@vger.kernel.org" Subject: Re: [PATCH] x86/efi: Restore Firmware IDT in before ExitBootServices() Message-ID: References: <20210820073429.19457-1-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 20, 2021 at 03:46:11PM +0000, David Laight wrote: > So load a temporary IDT so that you can detect invalid instructions > and restore the UEFI IDT immediately afterwards? Going forward with SEV-SNP, the IDT is not only needed for special instructions, but also to detect when the hypervisor is doing fishy things with the guests memory, which could happen at _any_ instruction boundary. > I'm guessing the GDT is changed in order to access all of physical > memory (well enough to load the kernel). The kernels GDT is needed to switch from 32-bit protected mode to long mode, where it calls ExitBootServices(). I think the reason is to avoid compiling a 64-bit and a 32-bit EFI library into the decompressor stub. With a 32-bit library the kernel could call ExitBootServices() right away before it jumps to startup_32. But it only has the 64-bit library, so it has to switch to long-mode first before it make subsequent EFI calls. > Could that be done using the LDT? > It is unlikely that the UEFI cares about that? Well, I guess it could work via the LDT too, but the current GDT switching code if proven to work on exiting BIOSes and I'd rather not change it to something less proven when there is no serious problem with it. > Is this 32bit non-paged code? > Running that with a physical memory offset made my head hurt. Yes, 32-bit EFI launches the kernel in 32-bit protected mode, paging disabled. I think that it also has to use a flat segmentation model without offsets. But someone who knows the EFI spec better than me can correct me here :) Regards, Joerg