Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3117726iog; Mon, 27 Jun 2022 09:28:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3kl0XN3K3NSIKRCFKmfnxbUmpVgr6TKT+vQJs26rt9NjtafY0Vb2OC9zdCBdocpGZiQJH X-Received: by 2002:a05:6402:4414:b0:434:f58c:ee2e with SMTP id y20-20020a056402441400b00434f58cee2emr17378413eda.362.1656347322851; Mon, 27 Jun 2022 09:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656347322; cv=none; d=google.com; s=arc-20160816; b=TiD2xQXRVjfdzYPw4EEgc7fotQ7OORM88GgmuhQPj8S9kKE6XwuGlqm14EOpyZKMiS LWH1JtomVwoGvIGYYLA1mNOgx5vTdN6hnkjSUhl5CsSCrXda1jStmDMItJmSUR9NwQlv Fg0zg5DbO5/OsFT0x8O2YMg/piSCMTMYwmBtEN07LN3sI3fbh7I942PjIQLcq3am7Xi8 91ed83LOSTrWQhbhC0AraxK2yJ9PWBhAEEG1zEvLrbtA0ZJ3KZLQnWm7MtBecMRY0VnS JXYdciYJ3u1BXF6cg4IV7w+oONSq8kK1layhawedXsdu7JOE80n80aB8o6TSd9hn+7nK iPxQ== 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=IFCSeMWa9h9GX5PoDNQOnkciA1SMKLpehV1m9QrYxug=; b=JsD1rXcpqZ2UGqOcFUfidmNpdSZSiwxVu54c5iWcXyfd9RPif8Nx+e2vRq9G3t85zM lemQRCgJR54V5jZnJvHMJFkk8D0NwvV9eQOCQlOhmcGM8D9Kwiclpap9wLjgjUND/49g SwPxKCyQKedEcApOzKbnLE+BPXO7lKGfHpq71sFyPeUfwLgeJjTrv3pb5kWDsZuKb7XQ ruk2QkyI8gLA9C2sHQN1NL1KSisJqebhyJFjOxIqkMrwljKRLLO42XHsr2LlVgbZNEqv 1bs1zJg31DEDwuDJKuq3hLNoJ/w+xlO4PFVUmDDCYpT1OmzdmocFEQm8ceoLKLe8Nqbr T4ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sH054xMJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hy28-20020a1709068a7c00b00722ef86e263si10676438ejc.140.2022.06.27.09.28.17; Mon, 27 Jun 2022 09:28:42 -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=@google.com header.s=20210112 header.b=sH054xMJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238091AbiF0QRu (ORCPT + 99 others); Mon, 27 Jun 2022 12:17:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239191AbiF0QRp (ORCPT ); Mon, 27 Jun 2022 12:17:45 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBF118B36 for ; Mon, 27 Jun 2022 09:17:44 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id s14so11632565ljs.3 for ; Mon, 27 Jun 2022 09:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IFCSeMWa9h9GX5PoDNQOnkciA1SMKLpehV1m9QrYxug=; b=sH054xMJMWAdWEQgNnIeDaI9aRGZam9yTrCSC25x7I92aDv5SqHaKk2Pa/VnQl6gP8 hmPPwdPRdI8pGMC2ajGI6dabju8PRmFnla72eH4OnSDS7NdJPkHGiisBfiQhOjy5Td8W pm4/RzsdVvsQSvTAuuEfcwpjZ2OYiAktQ3UQdLwHQDXnhM7LKdBCw9UMSNb3QWHNePTz Lyupfd+C7UYPCqWan8PIhebM/OHO4oPumZBBNR5lCH42XHcSSZtpzwSradM39VjliALk 3krX/fpzeDB9di9ABbqT2rYyoHgIVw1dMN5fcFbki3C117cxcMnLwDZPPexy3vygsRVv ED3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IFCSeMWa9h9GX5PoDNQOnkciA1SMKLpehV1m9QrYxug=; b=j9GG+FNzM4Xxjy/giiN/43vrE5vgOF+w8C29JYDO/4tjo0/eAKl2I3ba0OnoqjWxvk CeCjsK4zi4b6ps1aF2G8BkmpS85ErpHCCSATD69Xphpqd29L5u3xOdiho8M1uOb0Vvm9 JalSOvpAjV0gnV5qW/KP923SBbJ7TsjOKaN9jNoZQxX8ekqlOVBqzhnjhH5Iya/q7PyG 3ve2A4bkEWNnuYb6i48YIKfg8kX/bx7geSToiWSrHuM3VcWC2iExw6oisk/z8g0ajMTc d4mNvIIDd/FreABKjfcwz4joKdzNm2WS2HUT5HTJvbLodhwE6AHetrUFmOAU2B32s7Uz uARg== X-Gm-Message-State: AJIora831BAT+kF2+eEzoMZUtzFGJgAHhAqYWU36vPPIvAXuQ7TkcPtw kLrEi5FvZ0nkqXb5pbRmB9FdETO+Y3LIz6IHM8tEdA== X-Received: by 2002:a2e:1f01:0:b0:25a:5960:3c39 with SMTP id f1-20020a2e1f01000000b0025a59603c39mr7162503ljf.282.1656346662295; Mon, 27 Jun 2022 09:17:42 -0700 (PDT) MIME-Version: 1.0 References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <20220627113019.3q62luiay7izhehr@black.fi.intel.com> <20220627122230.7eetepoufd5w3lxd@black.fi.intel.com> In-Reply-To: <20220627122230.7eetepoufd5w3lxd@black.fi.intel.com> From: Peter Gonda Date: Mon, 27 Jun 2022 10:17:30 -0600 Message-ID: Subject: Re: [PATCHv7 00/14] mm, x86/cc: Implement support for unaccepted memory To: "Kirill A. Shutemov" Cc: Ard Biesheuvel , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , Marcelo Cerri , tim.gardner@canonical.com, Khalid ElMously , philip.cox@canonical.com, "the arch/x86 maintainers" , Linux Memory Management List , linux-coco@lists.linux.dev, linux-efi , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Mon, Jun 27, 2022 at 6:22 AM Kirill A. Shutemov wrote: > > On Mon, Jun 27, 2022 at 01:54:45PM +0200, Ard Biesheuvel wrote: > > On Mon, 27 Jun 2022 at 13:30, Kirill A. Shutemov > > wrote: > > > > > > On Fri, Jun 24, 2022 at 10:37:10AM -0600, Peter Gonda wrote: > > > > On Tue, Jun 14, 2022 at 6:03 AM Kirill A. Shutemov > > > > wrote: > > > > > > > > > > UEFI Specification version 2.9 introduces the concept of memory > > > > > acceptance: some Virtual Machine platforms, such as Intel TDX or AMD > > > > > SEV-SNP, requiring memory to be accepted before it can be used by the > > > > > guest. Accepting happens via a protocol specific for the Virtual > > > > > Machine platform. > > > > > > > > > > Accepting memory is costly and it makes VMM allocate memory for the > > > > > accepted guest physical address range. It's better to postpone memory > > > > > acceptance until memory is needed. It lowers boot time and reduces > > > > > memory overhead. > > > > > > > > > > The kernel needs to know what memory has been accepted. Firmware > > > > > communicates this information via memory map: a new memory type -- > > > > > EFI_UNACCEPTED_MEMORY -- indicates such memory. > > > > > > > > > > Range-based tracking works fine for firmware, but it gets bulky for > > > > > the kernel: e820 has to be modified on every page acceptance. It leads > > > > > to table fragmentation, but there's a limited number of entries in the > > > > > e820 table > > > > > > > > > > Another option is to mark such memory as usable in e820 and track if the > > > > > range has been accepted in a bitmap. One bit in the bitmap represents > > > > > 2MiB in the address space: one 4k page is enough to track 64GiB or > > > > > physical address space. > > > > > > > > > > In the worst-case scenario -- a huge hole in the middle of the > > > > > address space -- It needs 256MiB to handle 4PiB of the address > > > > > space. > > > > > > > > > > Any unaccepted memory that is not aligned to 2M gets accepted upfront. > > > > > > > > > > The approach lowers boot time substantially. Boot to shell is ~2.5x > > > > > faster for 4G TDX VM and ~4x faster for 64G. > > > > > > > > > > TDX-specific code isolated from the core of unaccepted memory support. It > > > > > supposed to help to plug-in different implementation of unaccepted memory > > > > > such as SEV-SNP. > > > > > > > > > > The tree can be found here: > > > > > > > > > > https://github.com/intel/tdx.git guest-unaccepted-memory > > > > > > > > Hi Kirill, > > > > > > > > I have a couple questions about this feature mainly about how cloud > > > > customers can use this, I assume since this is a confidential compute > > > > feature a large number of the users of these patches will be cloud > > > > customers using TDX and SNP. One issue I see with these patches is how > > > > do we as a cloud provider know whether a customer's linux image > > > > supports this feature, if the image doesn't have these patches UEFI > > > > needs to fully validate the memory, if the image does we can use this > > > > new protocol. In GCE we supply our VMs with a version of the EDK2 FW > > > > and the customer doesn't input into which UEFI we run, as far as I can > > > > tell from the Azure SNP VM documentation it seems very similar. We > > > > need to somehow tell our UEFI in the VM what to do based on the image. > > > > The current way I can see to solve this issue would be to have our > > > > customers give us metadata about their VM's image but this seems kinda > > > > burdensome on our customers (I assume we'll have more features which > > > > both UEFI and kernel need to both support inorder to be turned on like > > > > this one) and error-prone, if a customer incorrectly labels their > > > > image it may fail to boot.. Has there been any discussion about how to > > > > solve this? My naive thoughts were what if UEFI and Kernel had some > > > > sort of feature negotiation. Maybe that could happen via an extension > > > > to exit boot services or a UEFI runtime driver, I'm not sure what's > > > > best here just some ideas. > > > > > > Just as an idea, we can put info into UTS_VERSION which can be read from > > > the built bzImage. We have info on SMP and preeption there already. > > > > > > > Instead of hacking this into the binary, couldn't we define a protocol > > that the kernel will call from the EFI stub (before EBS()) to identify > > itself as an image that understands unaccepted memory, and knows how > > to deal with it? > > > > That way, the firmware can accept all the memory on behalf of the OS > > at ExitBootServices() time, unless the OS has indicated there is no > > need to do so. > > I agree it would be better. But I think it would require change to EFI > spec, no? Could this somehow be amended on to the UEFI Specification version 2.9 change which added all of the unaccepted memory features? > > -- > Kirill A. Shutemov