Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1597401pxb; Fri, 20 Aug 2021 09:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB6pY5ELtGgB1ZASUfmY0p19TZuqx9VW1JcB7kudfGNE24uNvh1/eqkRsZWlJCwKMJVAg+ X-Received: by 2002:a05:6638:268f:: with SMTP id o15mr18710615jat.22.1629475934083; Fri, 20 Aug 2021 09:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629475934; cv=none; d=google.com; s=arc-20160816; b=op4sFdaySGfIczqCvP7nuve5dBxEqU77ZXKAVDHFujk5z8Lg5rPUb8WYbHoSjzWShK QhAC652W/snJ+pTKBSJvkMPkys8Yq0rOaW+2jLjdhObfEQK5gwuakL7JgaBc1uEMjFjg FA6AmqkeV4CEPLivc9S7PtLU6VKCnx962Jk24KaBzEM9AW0+spTWKtD4Hkl1V2X+M/TL VwbYmkUMuefF3gAollNKQEM3l5VPyclBFRdz6y4wW6bg73vdjWKJNBLX0TeM0tnynIdZ IPWMKTlGIUxIivQYxpCEnU72wH1oKGNEWkNQ70sDZAGGqW5qNk54ylssxoEuh9t/YzNY 362w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Qd0QQ7SDaTstIyql8+p36TnoTy2RQGLCVX4iF8Djv6g=; b=Jhegxpp8yPJaTbbXNTyUCPmOWzmtkngXnVydaFlYlyY9KQAKxUQyHh6eth5db+Dpp5 5c1uauzkjQciWWlFcOryJPED1roRtkq//1dweTSCzsoWRXd5GscbZq7gPOwIN2+Jz92h 0gvnlNRDhvz/m4fH5Z62g6/HhqpM0V8iQJUGEz+savKCyuMBFbTCZvS7ewrqWe5SRl2w l73HcOmOPCTRNQBfRWR+70Oia3qb5E3tLW3gUchtpbZcA0EdfQ7pz4fv7O9h9DdO0eRk wvUJO3pdKhxfhSkZqmtLMUFgelMFcDH2RcxE4AX+jf3OxztefevEhYyA6zj57wNppaLn Effw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r3si7867782ile.126.2021.08.20.09.12.00; Fri, 20 Aug 2021 09:12:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231448AbhHTQLr (ORCPT + 99 others); Fri, 20 Aug 2021 12:11:47 -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