From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0274C433EF for ; Mon, 27 Jun 2022 16:17:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 138346B0071; Mon, 27 Jun 2022 12:17:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09BE56B0072; Mon, 27 Jun 2022 12:17:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E55CB8E0001; Mon, 27 Jun 2022 12:17:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CEC686B0071 for ; Mon, 27 Jun 2022 12:17:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id A7B8C80F76 for ; Mon, 27 Jun 2022 16:17:45 +0000 (UTC) X-FDA: 79624521690.02.56956FD Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by imf05.hostedemail.com (Postfix) with ESMTP id 39181100016 for ; Mon, 27 Jun 2022 16:17:44 +0000 (UTC) Received: by mail-lj1-f171.google.com with SMTP id q9so11614661ljp.4 for ; Mon, 27 Jun 2022 09:17:43 -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=dcbnnmM5y3fIRUbrlwxL0n2p96qg0VAQfSxWMUtXYSPXN9Dh1QcBIGFtXlOGVCLdIj L+rgRnQ3cr2KRdU0EgoRBUGCqCqB41U96nCOmV/IijJlVckLOenqrSluzkzG+q9YeTqx RJOjKQqMtD+2aZMOd8wpaPQnL8boAa1Jkn0FqPvpIeI9yjhpmAkyRsUcx8ivii28x18O pma1jAeNCyVTy/mCLY7CPAtkuY8lx54AV1KdmGHKjX5TcXZaZ9gakwXNyFuCayQWUTeA rY8uIVezWX5ur/c2FYTOP3ktgDXgnpb1N3DOdPJGh/BvmTSJL/85an36mzFfYCsJT2iI fc8A== X-Gm-Message-State: AJIora+LRS1hx2Bm4T6EkOzAdB2p3kDZgoQkomspGUDB5Fr6SL7kGNbK XJ7jlkXdWXG8VAPmJYlDNNzJ4o6zqcQMGnVOuBIeUA== X-Google-Smtp-Source: AGRyM1vc1fb6tmRtoRk2eM/MqjNyTJsbg6uxDwz3tmaaoZLLhGU4yZSRiGKND6kPOWF/35tdb79NK/jTJhNQx6rZTQc= 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" ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sH054xMJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of pgonda@google.com designates 209.85.208.171 as permitted sender) smtp.mailfrom=pgonda@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656346665; a=rsa-sha256; cv=none; b=LTerm/dsWHNm4x9oR6tIlEU4aGOgIkRy3ufYshwWfC7L7dpc2O7MDuXAgCLONT4yUXkQ8W mN3XA38SHQ3w+s8ihbcCr/TlLH5wyf0Gsc35B8X7O5apxBgvjZA2bGqgW1Z3NOgOxL41Yd yrlxQmkJIQnTFcy6Y9bPjNvFyEVR13M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656346665; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IFCSeMWa9h9GX5PoDNQOnkciA1SMKLpehV1m9QrYxug=; b=WCRBUIWFucVZPDE4K0gZ4i/dOwwUsgOhHjDtmTNamIDY79DIiKiQzkiYE5RCcT6tg591qq SF9IwJejqfA+SaCT7/yWt9RlHpJ1RE0fO+nBTJ6hHPddtGdF2TnqtCjw1AFLH/2QX90rca 7zWdXHpXWWC8FtuGXLvlBKYrG313Bfc= X-Stat-Signature: x8kijbfow1n4wp4fpbju9pk83muuz6ni X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 39181100016 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sH054xMJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of pgonda@google.com designates 209.85.208.171 as permitted sender) smtp.mailfrom=pgonda@google.com X-HE-Tag: 1656346664-697007 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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