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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 081F9C4338F for ; Tue, 10 Aug 2021 15:05:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8731060F02 for ; Tue, 10 Aug 2021 15:05:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8731060F02 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D13738D0010; Tue, 10 Aug 2021 11:05:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC1D28D0001; Tue, 10 Aug 2021 11:05:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB1E28D0010; Tue, 10 Aug 2021 11:05:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 9EE148D0001 for ; Tue, 10 Aug 2021 11:05:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2A731824999B for ; Tue, 10 Aug 2021 15:05:49 +0000 (UTC) X-FDA: 78459495618.03.FEE7E49 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf04.hostedemail.com (Postfix) with ESMTP id 27B2D5001B64 for ; Tue, 10 Aug 2021 15:05:47 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10072"; a="213065391" X-IronPort-AV: E=Sophos;i="5.84,310,1620716400"; d="scan'208";a="213065391" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2021 08:02:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,310,1620716400"; d="scan'208";a="671795060" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 10 Aug 2021 08:02:43 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 84889142; Tue, 10 Aug 2021 18:02:16 +0300 (EEST) Date: Tue, 10 Aug 2021 18:02:16 +0300 From: "Kirill A. Shutemov" To: David Hildenbrand 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 , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] mm: Add support for unaccepted memory Message-ID: <20210810150216.dwn2rylcpzxx6b6l@black.fi.intel.com> References: <20210810062626.1012-1-kirill.shutemov@linux.intel.com> <20210810062626.1012-2-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 27B2D5001B64 Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf04.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Stat-Signature: 56mzf9jbgk519ha74m7kyewrzitqapfm X-HE-Tag: 1628607947-654275 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 Tue, Aug 10, 2021 at 09:48:04AM +0200, David Hildenbrand wrote: > On 10.08.21 08:26, Kirill A. Shutemov wrote: > > UEFI Specification version 2.9 introduces 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 Virtrual 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 > > acceptation until memory is needed. It lowers boot time and reduces > > memory overhead. > > > > Support of such memory requires few changes in core-mm code: > > > > - memblock has to accept memory on allocation; > > > > - page allocator has to accept memory on the first allocation of the > > page; > > > > Memblock change is trivial. > > > > Page allocator is modified to accept pages on the first allocation. > > PageOffline() is used to indicate that the page requires acceptance. > > The flag currently used by hotplug and balloon. Such pages are not > > available to page allocator. > > > > An architecture has to provide three helpers if it wants to support > > unaccepted memory: > > > > - accept_memory() makes a range of physical addresses accepted. > > > > - maybe_set_page_offline() marks a page PageOffline() if it requires > > acceptance. Used during boot to put pages on free lists. > > > > - clear_page_offline() clears makes a page accepted and clears > > PageOffline(). > > > > Signed-off-by: Kirill A. Shutemov > > --- > > mm/internal.h | 14 ++++++++++++++ > > mm/memblock.c | 1 + > > mm/page_alloc.c | 13 ++++++++++++- > > 3 files changed, 27 insertions(+), 1 deletion(-) > > > > diff --git a/mm/internal.h b/mm/internal.h > > index 31ff935b2547..d2fc8a17fbe0 100644 > > --- a/mm/internal.h > > +++ b/mm/internal.h > > @@ -662,4 +662,18 @@ void vunmap_range_noflush(unsigned long start, unsigned long end); > > int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, > > unsigned long addr, int page_nid, int *flags); > > +#ifndef CONFIG_UNACCEPTED_MEMORY > > +static inline void maybe_set_page_offline(struct page *page, unsigned int order) > > +{ > > +} > > + > > +static inline void clear_page_offline(struct page *page, unsigned int order) > > +{ > > +} > > + > > +static inline void accept_memory(phys_addr_t start, phys_addr_t end) > > +{ > > +} > > Can we find better fitting names for the first two? The function names are > way too generic. For example: > > accept_or_set_page_offline() > > accept_and_clear_page_offline() Sounds good. > I thought for a second if > PAGE_TYPE_OPS(Unaccepted, offline) > makes sense as well, not sure. I find Offline fitting the situation. Don't see a reason to add more terminology here. > Also, please update the description of PageOffline in page-flags.h to > include the additional usage with PageBuddy set at the same time. Okay. > I assume you don't have to worry about page_offline_freeze/thaw ... as we > only set PageOffline initially, but not later at runtime when other > subsystems (/proc/kcore) might stumble over it. I think so, but I would need to look at this code once again. -- Kirill A. Shutemov