Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3163085iog; Mon, 27 Jun 2022 10:25:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s0yi6885UpVS0Of0Ds3jSIU+o0nuL/lP5S4GqkGx91p5YRxLiL15oWtWxnDZ9ETrLF2D4j X-Received: by 2002:a17:907:6e26:b0:726:97af:9846 with SMTP id sd38-20020a1709076e2600b0072697af9846mr9024449ejc.300.1656350735539; Mon, 27 Jun 2022 10:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656350735; cv=none; d=google.com; s=arc-20160816; b=T3M95GTxDxaavaE8U+ORdDvlAWp+vn/Pe0VnHa7DYI1yOnErNdt5HxQt4msRykCXu3 ItCAQwjfpb8ZMOHD7m//MNzQdL5/p8KlK0QdLDxrvMKeVJvdyVvXA9XGGwW0MuOrKfqh pf1ZB26yPFtz6gAHrMcylzVpuf2dRk78PqRq8W7jP5aGUP/DWYEbZOjiOwAkQE/KlyK/ BlyXNaj8Z6tuNURJM9Z1w0qlIMp3be1i+Amt0lJbqnawjgqRTg1Y/zifas9byz34Lq0D 4f7J+Pkteksj/pg8mblLlUHvI+O5nm8WeIfkjGFGEEkmiiMnQS4/8fVnygbMbgF75oZw HCIQ== 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=/SrPj904ouZSQFbqV4kyfH3imhY4twalKi5RBsFEDXg=; b=z5xBVMZsW5NDDS2g1fPtT/aKPbpxsRa23Js/2llXZJ+Eg3eAMCxrJ3I/53BhBsp04u 7ykGIhkM1tTtyZgAYU4+OMji1dOgO6WNkKc1ZUavmPECdlaxbizHDY/SwzAuYM4afFYc Jr7tuTgOFXdUC5Y422gTvvEenTApxYRts3jNiSbOe3tqDGNWo8fTurkCUUG7dDgha4+o C8bSypRJi5PR7soBjxxpgBpYQjvbeTvxG5sAIsJorgqxhHoE5NgrkRTf88Y07F2+M7ZH gDFJIaYoyWl35/8+4vkvGQgRWL0teFeGHMlWrC1oXhAhSjX027rJkK3wkkUN8umZOanC EEHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hOiOupAl; 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 qa7-20020a170907868700b006fe4c66b711si14063268ejc.46.2022.06.27.10.25.10; Mon, 27 Jun 2022 10:25:35 -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=hOiOupAl; 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 S239473AbiF0QeI (ORCPT + 99 others); Mon, 27 Jun 2022 12:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234722AbiF0QeH (ORCPT ); Mon, 27 Jun 2022 12:34:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDE77DEA2; Mon, 27 Jun 2022 09:34:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id 97040B818E1; Mon, 27 Jun 2022 16:34:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F12AC341CB; Mon, 27 Jun 2022 16:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656347643; bh=/SrPj904ouZSQFbqV4kyfH3imhY4twalKi5RBsFEDXg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hOiOupAlz0TGohr1zjOI5lFppGqzRMTEsnXwUTjo+AoOMM6Gpog71SfivxPwIX7NV iXB4scHnRb8F21nU9UWDw3UJPTycIN4itNmgWilRZJoxPN/ykb4KNUwBCASRz2g8B5 ozEcRcl0G9O6t24gpWsacxQyuRb82ttrYlvzpT5chxphOl/fxEh/ZzLG6Iwp5yyJBa I6G7FBcxCOwrsgR4to3Kezu+lQsavJbnz+NbIJG4Iin/YGpbkXyITEBWjaEAY7wjGG zm3V3Dpkg2/z1CzyK/M+yUiv7tHtUQTptE2M+6o50uuxDkrnO+NPnVCHt0JoBNBozO Fy8qOM9M2nZGg== Received: by mail-oi1-f177.google.com with SMTP id r82so4854036oig.2; Mon, 27 Jun 2022 09:34:03 -0700 (PDT) X-Gm-Message-State: AJIora9EoGDfDF3q1tabo+eDjhUAKOGyv/WVxXd4k5vDJl2FQbpp1ZcL r4qSU9zPWeoOtiJRu2f8zSYBJJjIy4ozMqnIV6U= X-Received: by 2002:a05:6808:300e:b0:32c:425e:df34 with SMTP id ay14-20020a056808300e00b0032c425edf34mr8224110oib.126.1656347642388; Mon, 27 Jun 2022 09:34:02 -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: From: Ard Biesheuvel Date: Mon, 27 Jun 2022 18:33:51 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCHv7 00/14] mm, x86/cc: Implement support for unaccepted memory To: Peter Gonda Cc: "Kirill A. Shutemov" , 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=-7.5 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,T_SCC_BODY_TEXT_LINE 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 Mon, 27 Jun 2022 at 18:17, Peter Gonda wrote: > > 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? > Why would this need a change in the EFI spec? Not every EFI protocol needs to be in the spec.