Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp661777iog; Fri, 24 Jun 2022 11:10:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uPeK83LNzeaoGYz99tmsNVuRy05g1KmVQVMKolzHsvBsk9SH6dT8QHRG0KvKSw9Z1eFS5N X-Received: by 2002:a17:906:216:b0:711:f623:8bb0 with SMTP id 22-20020a170906021600b00711f6238bb0mr297034ejd.174.1656094236300; Fri, 24 Jun 2022 11:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656094236; cv=none; d=google.com; s=arc-20160816; b=R857se3ZqysjFCwpCl1m6voZ/OKwmimUSSCdM4lPxfb4tBU8OT63ui1RnEfZfVoScW Lhsoxvvpflhf8jhq4hN3lka+dcXfLiv2APV2tfHu+0mfw7lmVa9hqRi5O2KhjShESMWZ KnIPEr6ApVXy8Gf+dMxyaxSDPwXHZjyO/fbtwydqXxv++F2WkjynMGDNuQZ6em2+uwAY GfMQgAxjLfhdQ4bL3appB92veVza8Hych/kEz/kVdFgx/FTZnTov6rXZITgq6wWbITRS EpDyxKpoKx7Hk4/qivhjiOPVrgCr+o0AXGHfNv1MMl1AcBp/j03ed9aS9brROtLDcouK ILjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=amHl1LwfBMa5KDjXqZHtC9+AbtdwaHnaESVYa8U2byA=; b=FasCYgyTy9mwjptPzWgZ0JnEMxgBn6VzR9DrVLZGEUBnOPH80cQVU2EdXnaIsG+H1d LeozqSMkncolY/fdrJvLiYSYvbShgscp/i+sOO+0/Dm7qdNdcn/U97UDdmVpCGC6p2t0 q2Kg1sDEWr/QnM0mxGwdmgML2dNUqcCBWoWoyiU+V/QhYuYBsjpDU6RFikfo6OUVQdi1 Ebsj/DEOendkX4DaLZ71eyfoGwARf3DcG5WgO4r80WMGtIzM+1lIoHvbdZBSq070B0pS YfifSCT+tftnCRbYdetoifK4aZdXuL4kDVu2tFEWIfiZj95h7q5Hs1kNa5SR1e0yzGP2 AqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=H3sKSrgk; 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 gn9-20020a1709070d0900b007235473b2fbsi3985385ejc.680.2022.06.24.11.10.09; Fri, 24 Jun 2022 11:10:36 -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=H3sKSrgk; 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 S230145AbiFXSFz (ORCPT + 99 others); Fri, 24 Jun 2022 14:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiFXSFw (ORCPT ); Fri, 24 Jun 2022 14:05:52 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6988D77074 for ; Fri, 24 Jun 2022 11:05:50 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id a13so5757348lfr.10 for ; Fri, 24 Jun 2022 11:05:50 -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:content-transfer-encoding; bh=amHl1LwfBMa5KDjXqZHtC9+AbtdwaHnaESVYa8U2byA=; b=H3sKSrgk4dk9/Hswlf5QYJecr2rGepFCacSgMNlU5bXC/icuTUS4zFuhsYf8UFjjCl 7/uIbmhnQiOjSjUOFuIuBSts3AMRMzgWX3yVxFfx3qaF3if0Z9wLFrEPzXxT6ROgcn0l gaMeTc9x99Xx1Wx+cZ9YaO54F8L5PBMeuY0cPogpowiUHI3o8nS6Q72kFDv3YskTyoW6 ei3dsCuqyqMjnfD+uwcmzgj2yWMVDCsAxOUG/UsCydZsHdLxr7Pr0cfTobtEFm6CV0JK gWUVtOIWoX1tS164asj2tha1HSnVTDEw1BECD2k7dNu62R2ysxNEmQ41MUY+c/3LHM49 C0eQ== 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:content-transfer-encoding; bh=amHl1LwfBMa5KDjXqZHtC9+AbtdwaHnaESVYa8U2byA=; b=7PBHkw6Sp9LkY1uSNjx3pFxxWpXa2FDD43iWrepnYyriDN4GP0AOlV6lQkVvhxVc15 q5I4d3ZmbE3znyREadAg+2V1Nv6498P6zqHKkUXHCk5wv1qlhbfPRGlJw8QwP/NrBHGt 4GzonPYIr0iZAz8jGDKkUhlkx0czpS2B4WQ7DV/JpTdzgHToYbtMugoWXR/WPAVlrQBF 4a6Vdq6QhLY0hDFGjUOjqT9K8RBQLU/TyHdUW4Eklrd4HjmZhM4uPAWXuPYyMTR2LcM7 sSaJeYhnMsfsTY9CNtTrHjr3Sj6+igcOCfsa7Xew5xkttI8UKcG4HzxBHCzQFgp8EKLh eNqw== X-Gm-Message-State: AJIora8/L045u49QRhfZc9lLLHC6xXVVW7ruYQ7xsNBOXzvTuNJBwpF5 NYA7dc3r/wRmIYAWj96a7SI+mosLEF7+0chdUs0bxw== X-Received: by 2002:a05:6512:a94:b0:47f:6621:cf2a with SMTP id m20-20020a0565120a9400b0047f6621cf2amr73823lfu.193.1656093948467; Fri, 24 Jun 2022 11:05:48 -0700 (PDT) MIME-Version: 1.0 References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <20220624174057.72dwo7v36lokmoub@amd.com> In-Reply-To: <20220624174057.72dwo7v36lokmoub@amd.com> From: Peter Gonda Date: Fri, 24 Jun 2022 12:05:36 -0600 Message-ID: Subject: Re: [PATCHv7 00/14] mm, x86/cc: Implement support for unaccepted memory To: Michael Roth Cc: "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , 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 , tim.gardner@canonical.com, Khalid ElMously , philip.cox@canonical.com, "the arch/x86 maintainers" , linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Fri, Jun 24, 2022 at 11:41 AM Michael Roth 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 lead= s > > > to table fragmentation, but there's a limited number of entries in th= e > > > 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 me= mory > > > such as SEV-SNP. > > > > > > The tree can be found here: > > > > > > https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fg= ithub.com%2Fintel%2Ftdx.git&data=3D05%7C01%7Cmichael.roth%40amd.com%7C7= 3bacba017c84291482a08da55ffd481%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%= 7C637916854542432349%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2= luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DP%2FUJOL30= 5xo85NLXGxGouQVGHgzLJpmBdNyZ7Re5%2FB0%3D&reserved=3D0 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. > > Not sure if you've seen this thread or not, but there's also been some > discussion around this in the context of the UEFI support: > > https://patchew.org/EDK2/cover.1654420875.git.min.m.xu@intel.com/cce5ea= 2aaaeddd9ce9df6fa7ac1ef52976c5c7e6.1654420876.git.min.m.xu@intel.com/#20220= 608061805.vvsjiqt55rqnl3fw@sirius.home.kraxel.org > > 2 things being discussed there really, which I think roughly boil down > to: > > 1) how to configure OVMF to enable/disable lazy acceptance > - compile time option most likely: accept-all/accept-minimum/accept-1= GB > > 2) how to introduce an automatic mode in the future where OVMF does the > right thing based on what the guest supports. Gerd floated the idea o= f > tying it to ExitBootServices as well, but not sure there's a solid > plan on what to do here yet. > > If that's accurate, it seems like the only 'safe' option is to disable it= via > #1 (accept-all), and then when #2 comes along, compile OVMF to just Do Th= e > Right Thing. > > Users who know their VMs implement lazy acceptance can force it on via > accept-all OVMF compile option. Thanks for this Mike! I will bring this to the EDK2 community. The issue for us is our users use a GCE built EDK2 not their own compiled version so they don't have the choice. Reading the Azure docs it seems the same for them, and for AWS so I don't know how often customers actually get to bring their own firmware. > > -Mike