Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp328188rwl; Wed, 5 Apr 2023 00:53:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ba9Y/k1GZykLN2OoBsKJBm28LjDmLf8OExL0mooK8W1bXBbwIMQAdtajFLv1umK/2FmOSK X-Received: by 2002:aa7:cd45:0:b0:502:9459:a69c with SMTP id v5-20020aa7cd45000000b005029459a69cmr883599edw.40.1680681219815; Wed, 05 Apr 2023 00:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680681219; cv=none; d=google.com; s=arc-20160816; b=YGTaQ8/t/c0H/chIlUgYdD6EAd4++wi7uV2IB7xbbRkQZyq1hUrdZpbbpCXS5WG+Hc 16EqEG3nQAM5rYa4gJkak//4wkZar3WaCZie5Ywa61Fbo1DPY6WIH8n6BVdl+KT/sDhb jrPF4Kj6bYyu6ZOZh09gVjyzJ7aEpsDq8R1bAd7L/ow9DrGoviZnuhzNHkzK7qC23Zc0 QLCSzRP7Kc00Lgv3upSdctPQdrbL1laGk/XdDY/sFXbjf/ncjP0VmGSFyWeFLCdFSfkw YdgQEf2PGqHMBrCj0pFhAIJ+aiSOANoPR2JokankupRtq//r60X7Jceg7N9MXYJ9BB95 5mJQ== 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=Rf45gj7yaH2xct8MzmXmzGHSI9izaNDwXlW3MLidwr4=; b=H+9BRfaI2E/RRPw9yYOx6CBq3aZ5LPOA2DjTOT4/jOEQU6S+TK2dS+MCqUuhJTs9+L SfO6dRERnB8YwDX5SQc1xPdi7YfE7c2KEjwpk/X/0QUUw8KK1EW0VDTw0U4iTsyErpru oZVyiHQskBV5T5ZnCIpBWYcma/P3RX9c+9prF0yY92y74LsiA+O7x0/Nr+Vlhm1x1nWc iwMLOy6Tr0a8obXQUFNonkYRovu6FmYlD75pVpQMGTeF5ytdTMEF+HX9mcjuEWZ2VHtJ R9PJVJRw1f78XzQl4kH5OPbAGHTYf9y01/aSqc3gx6LBMQZIjjgdSAqmJiz9Z0seG3yr t2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DopNfQzV; 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 b20-20020a05640202d400b00501db4ea3e9si3086934edx.173.2023.04.05.00.53.15; Wed, 05 Apr 2023 00:53:39 -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=DopNfQzV; 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 S237121AbjDEHrQ (ORCPT + 99 others); Wed, 5 Apr 2023 03:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjDEHrP (ORCPT ); Wed, 5 Apr 2023 03:47:15 -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 6FF9810FA for ; Wed, 5 Apr 2023 00:47:14 -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 0CA056236D for ; Wed, 5 Apr 2023 07:47:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71898C4339E for ; Wed, 5 Apr 2023 07:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680680833; bh=9bNF/I6QlFCyYXGIyEeaRXvEBKgeXQGlZhZV7R9dgfc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DopNfQzVVbvFG0SpozNw6r0oR+Lu5gkilIAenuGCnlAPjMfZw2gXVd5bhpsxKHMfI 5jm0aupU7B7DRoUajmiFOWAuHTXI4/6omopBfs0CqWfCBu8u4yBawXY2/aXs+hfTmL 9Itu0HG1WTC9v5np59GFE4WCSXfsWjgpfv78gBCOUW911hOTIggM42MV157szqEn8r QA8J+n4wmTmHuPCbl/EjTBqzP6mwUL58Ud0QLb4pQd8LvhH6T7WDJRaNrWYePSda+q cWoVibE07wv+Z29WPzxlDZZ71TJR6CoThrKMDegvsBRHVwu70ZHiZLRB/5t1HFKrJW ny1dRSUAJK2pw== Received: by mail-lj1-f178.google.com with SMTP id e9so21133902ljq.4 for ; Wed, 05 Apr 2023 00:47:13 -0700 (PDT) X-Gm-Message-State: AAQBX9cf61iQtw6f1sAWngeM7Mzx3wqnLX1ZXs9KySwJdmVcg1aDH1Ga GmZBClbnfjozO+HC6mL3BKS4QIF7I/xSCx+Ua7A= X-Received: by 2002:a2e:9013:0:b0:2a6:16b4:a554 with SMTP id h19-20020a2e9013000000b002a616b4a554mr688480ljg.3.1680680831396; Wed, 05 Apr 2023 00:47:11 -0700 (PDT) MIME-Version: 1.0 References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> <1d38d28c2731075d66ac65b56b813a138900f638.1680628986.git.thomas.lendacky@amd.com> <20230404174506.pjdikxvk2fsyy4au@box.shutemov.name> <20230404180917.4fsgkzcdhqvph6io@box.shutemov.name> <20230404202445.6qkl7hz67qgievqz@box.shutemov.name> <20230404210153.tll2mojlglx4rfsa@box.shutemov.name> In-Reply-To: <20230404210153.tll2mojlglx4rfsa@box.shutemov.name> From: Ard Biesheuvel Date: Wed, 5 Apr 2023 09:46:59 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 6/6] x86/efi: Safely enable unaccepted memory in UEFI To: "Kirill A. Shutemov" Cc: Dave Hansen , Tom Lendacky , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Michael Roth , Joerg Roedel , Dionna Glaze , Andy Lutomirski , Peter Zijlstra , "Min M. Xu" , Gerd Hoffmann , James Bottomley , Jiewen Yao , Erdem Aktas , "Kirill A. Shutemov" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 Tue, 4 Apr 2023 at 23:02, Kirill A. Shutemov wrote: > > On Tue, Apr 04, 2023 at 10:41:02PM +0200, Ard Biesheuvel wrote: > > On Tue, 4 Apr 2023 at 22:24, Kirill A. Shutemov wrote: > > > > > > On Tue, Apr 04, 2023 at 09:49:52PM +0200, Ard Biesheuvel wrote: > > > > On Tue, 4 Apr 2023 at 20:09, Kirill A. Shutemov wrote: > > > > > > > > > > On Tue, Apr 04, 2023 at 10:57:52AM -0700, Dave Hansen wrote: > > > > > > On 4/4/23 10:45, Kirill A. Shutemov wrote: > > > > > > > I still think it is a bad idea. > > > > > > > > > > > > > > As I asked before, please include my > > > > > > > > > > > > > > Nacked-by: Kirill A. Shutemov > > > > > > > > > > > > > > into the patch. > > > > > > > > > > > > I was pretty opposed to this when I first saw it too. But, Tom and > > > > > > company have worn down my opposition a bit. > > > > > > > > > > > > The fact is that we have upstream kernels out there with SEV-SNP support > > > > > > that don't know anything about unaccepted memory. They're either > > > > > > relegated to using the pre-accepted memory (4GB??) or _some_ entity > > > > > > needs to accept the memory. That entity obviously can't be the kernel > > > > > > unless we backport unaccepted memory support. > > > > > > > > > > > > This both lets the BIOS be the page-accepting entity _and_ allows the > > > > > > entity to delegate that to the kernel when it needs to. > > > > > > > > > > > > As much as I want to nak this and pretend that that those existing > > > > > > kernel's don't exist, my powers of self-delusion do have their limits. > > > > > > > > > > > > If our AMD friends don't do this, what is their alternative? > > > > > > > > > > The alternative is coordination on the host side: VMM can load a BIOS that > > > > > pre-accepts all memory if the kernel is older. > > > > > > > > > > > > > And how does one identify such a kernel? How does the VMM know which > > > > kernel the guest is going to load after it boots? > > > > > > VMM has to know what it is running. Yes, it is cumbersome. But enabling > > > phase for a feature is often rough. It will get smoother overtime. > > > > > > > So how does the VMM get informed about what it is running? How does it > > distinguish between kernels that support unaccepted memory and ones > > that don't? And how does it predict which kernel a guest is going to > > load? > > User will specify if it wants unaccepted memory or not for the VM. And if > it does it is his responsibility to have kernel that supports it. > > And you have not addressed my question: > > How is it different from any other feature the kernel is not [yet] aware > of? > It is the same problem, but this is just a better solution. Having a BIOS menu option (or similar) to choose between unaccepted memory or not (or to expose CXL memory via the EFI memory map, which is another hack I have seen) is just unnecessary complication, if the kernel can simply inform the loader about what it supports. We do this all the time with things like OsIndications. We can phase out the protocol implementation from the firmware once we no longer need it, at which point the LocateProtocol() call just becomes a NOP (we do the same thing for UGA support, which has disappeared a long time ago, but we still look for the protocol in the EFI stub). Once the firmware stops exposing this protocol (and ceases to accept memory on the OS's behalf), we can phase it out from the kernel as well. The only other potential solution I see is exposing the unaccepted memory as coldplugged ACPI memory objects, and implementing the accept calls via PRM methods. But PRM has had very little test coverage, so it is anybody's guess whether it works for the stable kernels that we need to support with this. It would also mean that the new unaccepted memory logic would need to be updated and cross reference these memory regions with EFI unaccepted memory regions and avoid claiming them both.