Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1219407rwb; Thu, 6 Oct 2022 09:57:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Nscu2F841EMFc75qvLn5wozTpdQFUcBSbYoOJ61Mhxf54UnFNZkbE1JQKi7L2uOE/VWmy X-Received: by 2002:a17:907:270e:b0:78d:2a14:b98d with SMTP id w14-20020a170907270e00b0078d2a14b98dmr632436ejk.688.1665075449120; Thu, 06 Oct 2022 09:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665075449; cv=none; d=google.com; s=arc-20160816; b=ai2DR8WKgZvpOk6TnV3OlZrGBPWjGSYrkbAETfryZ0N/iZj6r+yiCPmynYwDCE7E0m POYxfd3PV7UnCr+9vXzMGgJRxjQ3V4DjId6G2Klhf6j25uR6fFV0W1X4I7lUWrydc0Ia ONWVA8e9Vd+8dTj6a+fCL2vUi0mSaw/oCmjfvsvVSPzf11gi3hlfHNn1FJCxXTjxxhrL 1npj/YjBYPq4ItvnaL6r5gXDb7Y+ZYZ1jhvXEkciZa8bjQBLIMNohQH+AU+PhX6xtgba yW6FclINhmtjpLHpFbfn0NG/83OV3rwGj0Ix6N331l/Zrm1KDL0fwxkqvtanzhq90ANK 3UrA== 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=vQWIirMpuqMKlT1rv9F1bl/VOHishj2NKS0LR7EtQN0=; b=Kdn0y9hIGRcoaiOpHrx5SQz0AuYYWVz07PyN02venb2H8JNL0y57lesb4h4qlBtxM0 Q4EvEsnFvQzZKGq1MZsOVBLQurabKpwxKUSh7NepTf0lOp/y14fmRpSvI9STGvnXJZ3L eaAOVirpQ1ltm54sF0zBZKc4o4Z2FP41bXPrsMESSQt1+SmMHjcziUcDKJCYhI+KnQQG QeV6aQ81LSX6VvUrEoZWLq5TEAzL2mETmi1OKsSGbDuLVZRiRImUf6EHmGPbaQVrSL8t GFnB/BEejbIWmfWGnt30Nuhswo+BE+5GS3NlpckARdS/1HfLkzs5MX8XYnAxl6flpvWb D3iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UldnsAG4; 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 he39-20020a1709073da700b0077b21283d09si19194483ejc.349.2022.10.06.09.57.03; Thu, 06 Oct 2022 09:57:29 -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=UldnsAG4; 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 S230116AbiJFQT6 (ORCPT + 99 others); Thu, 6 Oct 2022 12:19:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbiJFQTw (ORCPT ); Thu, 6 Oct 2022 12:19:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B47BA440; Thu, 6 Oct 2022 09:19:50 -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 0DF7561A25; Thu, 6 Oct 2022 16:19:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71B92C43470; Thu, 6 Oct 2022 16:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665073189; bh=Pld45Z4CvZ++lrOaJAma6PphMOkb0rHF45RNmYeXg10=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UldnsAG4GNAIf3bSaBgda3uTevViDMdSSwclyZxwkqmgQnRVyLusdJP9LFmQjQgPL 6dc2ARIw+4qhmVft10VEiQxS4WjjjpS7eEdNFITa2Y6weVWFQlwfltXCOjB5Kx/X2D lNCiuw7/chMSMBwwCq+u8niyobby8oFZDrFVytzozRs2abSVgosb+OAmKyke28YcFF S/hQ8y6GdVTIkkj9pEuuUsSbei47zrqjuab0cZohdZJyVU9QpAWJihH8FJXDc4z8+D 5YQLd5f8HOyxE8/tgmNcxoN8SeberFpSx9nWGH5SEg7UN+Rgca1fyH/dCzviVQ1nqd Sc2XcdsSjVHjA== Received: by mail-lf1-f48.google.com with SMTP id g1so3433925lfu.12; Thu, 06 Oct 2022 09:19:49 -0700 (PDT) X-Gm-Message-State: ACrzQf2iEmW3FcbOhksFQvwkvmpODRunECi9rU/gD5sp8X7otIgh8VFC fKmAKWJVQ/7hv1KomfdWKB8SLoActW1+GYIPhUk= X-Received: by 2002:ac2:4d1c:0:b0:4a2:4119:f647 with SMTP id r28-20020ac24d1c000000b004a24119f647mr270568lfi.426.1665073187373; Thu, 06 Oct 2022 09:19:47 -0700 (PDT) MIME-Version: 1.0 References: <01d22092-8292-8ed7-ece7-9ca32d15bbce@suse.com> In-Reply-To: From: Ard Biesheuvel Date: Thu, 6 Oct 2022 18:19:35 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 1/2] Avoid using EFI tables Xen may have clobbered To: Demi Marie Obenour Cc: Jan Beulich , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , =?UTF-8?Q?Marek_Marczykowski=2DG=C3=B3recki?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 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 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 Thu, 6 Oct 2022 at 16:43, Demi Marie Obenour wrote: > > On Thu, Oct 06, 2022 at 09:31:47AM +0200, Ard Biesheuvel wrote: > > On Thu, 6 Oct 2022 at 03:41, Demi Marie Obenour > > wrote: > > > > > > On Wed, Oct 05, 2022 at 11:28:29PM +0200, Ard Biesheuvel wrote: > > > > On Wed, 5 Oct 2022 at 20:11, Demi Marie Obenour > > > > wrote: > > > > > > > > > > On Wed, Oct 05, 2022 at 08:15:07AM +0200, Jan Beulich wrote: > > > > > > On 04.10.2022 17:46, Demi Marie Obenour wrote: > > > > > > > Linux has a function called efi_mem_reserve() that is used to reserve > > > > > > > EfiBootServicesData memory that contains e.g. EFI configuration tables. > > > > > > > This function does not work under Xen because Xen could have already > > > > > > > clobbered the memory. efi_mem_reserve() not working is the whole reason > > > > > > > for this thread, as it prevents EFI tables that are in > > > > > > > EfiBootServicesData from being used under Xen. > > > > > > > > > > > > > > A much nicer approach would be for Xen to reserve boot services memory > > > > > > > unconditionally, but provide a hypercall that dom0 could used to free > > > > > > > the parts of EfiBootServicesData memory that are no longer needed. This > > > > > > > would allow efi_mem_reserve() to work normally. > > > > > > > > > > > > efi_mem_reserve() actually working would be a layering violation; > > > > > > controlling the EFI memory map is entirely Xen's job. > > > > > > > > > > Doing this properly would require Xen to understand all of the EFI > > > > > tables that could validly be in EfiBootServices* and which could be of > > > > > interest to dom0. It might (at least on some very buggy firmware) > > > > > require a partial ACPI and/or SMBIOS implementation too, if the firmware > > > > > decided to put an ACPI or SMBIOS table in EfiBootServices*. > > > > > > > > > > > As to the hypercall you suggest - I wouldn't mind its addition, but only > > > > > > for the case when -mapbs is used. As I've indicated before, I'm of the > > > > > > opinion that default behavior should be matching the intentions of the > > > > > > spec, and the intention of EfiBootServices* is for the space to be > > > > > > reclaimed. Plus I'm sure you realize there's a caveat with Dom0 using > > > > > > that hypercall: It might use it for regions where data lives which it > > > > > > wouldn't care about itself, but which an eventual kexec-ed (or alike) > > > > > > entity would later want to consume. Code/data potentially usable by > > > > > > _anyone_ between two resets of the system cannot legitimately be freed > > > > > > (and hence imo is wrong to live in EfiBootServices* regions). > > > > > > > > > > I agree, but currently some such data *is* in EfiBootServices* regions, > > > > > sadly. When -mapbs is *not* used, I recommend uninstalling all of the > > > > > configuration tables that point to EfiBootServicesData memory before > > > > > freeing that memory. > > > > > > > > > > > > > That seems like a reasonable approach to me. Tables like MEMATTR or > > > > RT_PROP are mostly relevant for bare metal where the host kernel maps > > > > the runtime services, and in general, passing on these tables without > > > > knowing what they do is kind of fishy anyway. You might even argue > > > > that only known table types should be forwarded in the first place, > > > > regardless of the memory type. > > > > > > Which tables are worth handling in Xen? I know about ACPI, SMBIOS, and > > > ESRT, but I am curious which others Xen should preserve. Currently, Xen > > > does not know about RT_PROP or MEMATTR; could this be a cause of > > > problems? > > > > dom0 only has access to paravirtualized EFI runtime services, so > > consuming RT_PROP or MEMATTR should be up to Xen (they describe which > > runtime services remain available at runtime, and which permission > > attributes to use for the runtime services memory regions, > > respectively) > > Xen does not do this right now. I wonder if this could be the cause of > compatibility issues with various firmware implementations. > > > Looking through the kernel code, I don't think there are any that dom0 > > should care about beyond ACPI, SMBIOS and ESRT. But as you suggest, > > that means Xen should just mask them in the view of the EFI system > > table it exposes so dom0. Otherwise, the kernel may still try to map > > and parse them. > > What about the BGRT and MOKvar? I agree that Xen should not expose the > others. Should it just hide the tables, or should it actually uninstall > them? My intuition is that the second would be technically more > correct, but also more likely to trigger bugs in various firmware > implementations. BGRT is a ACPI table not a EFI configuration table, so I'd assume it is treated the same way as other ACPI tables MOKvar is a fallback for systems where it doesn't fit into a volatile variable IIRC but I am not sure if it is actually implemented anywhere, and what type of memory region it is expected to use. However, I'm not sure if it even matters, given that Xen loads the dom0 kernel not the firmware, right?