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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 97ABFC4338F for ; Tue, 10 Aug 2021 15:21:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1917B61008 for ; Tue, 10 Aug 2021 15:21:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1917B61008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7F7C78D0014; Tue, 10 Aug 2021 11:21:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 780998D0001; Tue, 10 Aug 2021 11:21:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620B68D0014; Tue, 10 Aug 2021 11:21:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 457428D0001 for ; Tue, 10 Aug 2021 11:21:54 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EC25E18034ACC for ; Tue, 10 Aug 2021 15:21:53 +0000 (UTC) X-FDA: 78459536106.36.79D6CCE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 76A90B0001AF for ; Tue, 10 Aug 2021 15:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628608912; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hyIW1Dsj80BNyB5Ez6rsRZ4nA63bgzsrvBHJJMAzsHw=; b=a1AQsabBQ9bhZMGLn4JDUjRYveZ2zzx293OO6aLHmzqYyigLdjJ+iw0EGZac/RO2bN9e7g F05lsO4ZdjhDmQLwF5OK9w5yz5k28MYJ+41L7NEbfk8o5IcjRuv+Ldr+nSotJFWEY16JuF HySdXdLHR/rUk5wDmPmWQeDUDP6BrqQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-9batfiuzNGy81L7EqcbWrQ-1; Tue, 10 Aug 2021 11:21:51 -0400 X-MC-Unique: 9batfiuzNGy81L7EqcbWrQ-1 Received: by mail-wm1-f69.google.com with SMTP id g70-20020a1c20490000b02902e6753bf473so1200845wmg.0 for ; Tue, 10 Aug 2021 08:21:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=hyIW1Dsj80BNyB5Ez6rsRZ4nA63bgzsrvBHJJMAzsHw=; b=Ju0ZK0DTF0MGJCcuXQpF8SPhjFEocS7b+r3KyV4y7Ees0vpQd7XhHIgkRv0j+VHcW8 tu5PtvCvBAXMtwdxf4GcJvgtq07cPJSCVHjDNI/tFh0IHnWSxkh79UFXXrfcMXNzxi7K WOEo5kbPL5p+rk24+wLXLkNHh+X7YAc2OdvYvC6/zHQW4did65N0M/Qt1BApnYY++ISN 3Yqx7Rx2af0ZTcQX2EUum1MXT/4Bk9ei6JvR85FQZDbx2+rdKeQwTfjJ6SponCJKhiPo 9QqutGJ99uDwEWEjgSf7mPznDKh9pVggWieMPXEdGWjPpS3AcMDCZNO9tLoJmjBGA5pj c2zA== X-Gm-Message-State: AOAM532OZO1NY1XokEfjVcwZHkDrw3TR58eLsVupFSAUWef5K5y3OTJr 2JaoDdt7GM1RjMrAsabVzFX6Y3KLxHHl9ji6S/pCsNY81vlmU8CDG7J03jaY7XibYzFoVkBAEy+ jcVJpHhxEB2M= X-Received: by 2002:a05:600c:a41:: with SMTP id c1mr22407127wmq.109.1628608910337; Tue, 10 Aug 2021 08:21:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz03IKHIRAmztBUt6G7hOjfqYECPVuLCftxaXW1EHq3wL9Jce0hR3y5svOifsUZdEMPqRHSYg== X-Received: by 2002:a05:600c:a41:: with SMTP id c1mr22407098wmq.109.1628608910064; Tue, 10 Aug 2021 08:21:50 -0700 (PDT) Received: from ?IPv6:2003:d8:2f0a:7f00:fad7:3bc9:69d:31f? (p200300d82f0a7f00fad73bc9069d031f.dip0.t-ipconnect.de. [2003:d8:2f0a:7f00:fad7:3bc9:69d:31f]) by smtp.gmail.com with ESMTPSA id n8sm2931132wms.11.2021.08.10.08.21.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Aug 2021 08:21:49 -0700 (PDT) To: "Kirill A. Shutemov" 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 References: <20210810062626.1012-1-kirill.shutemov@linux.intel.com> <20210810062626.1012-2-kirill.shutemov@linux.intel.com> <20210810150216.dwn2rylcpzxx6b6l@black.fi.intel.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 1/5] mm: Add support for unaccepted memory Message-ID: <2e45209d-6a99-9496-6cb0-111291bd481a@redhat.com> Date: Tue, 10 Aug 2021 17:21:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210810150216.dwn2rylcpzxx6b6l@black.fi.intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a1AQsabB; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: j6owtcwswsxwf6swtsnpaeqrupf3wd3m X-Rspamd-Queue-Id: 76A90B0001AF X-Rspamd-Server: rspam01 X-HE-Tag: 1628608913-161106 Content-Transfer-Encoding: quoted-printable 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 10.08.21 17:02, Kirill A. Shutemov wrote: > 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 acceptanc= e: >>> 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 requir= es >>> 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, u= nsigned long end); >>> int numa_migrate_prep(struct page *page, struct vm_area_struct *vm= a, >>> unsigned long addr, int page_nid, int *flags); >>> +#ifndef CONFIG_UNACCEPTED_MEMORY >>> +static inline void maybe_set_page_offline(struct page *page, unsigne= d int order) >>> +{ >>> +} >>> + >>> +static inline void clear_page_offline(struct page *page, unsigned in= t 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() >=20 > Sounds good. >=20 >> I thought for a second if >> PAGE_TYPE_OPS(Unaccepted, offline) >> makes sense as well, not sure. >=20 > I find Offline fitting the situation. Don't see a reason to add more > terminology here. >=20 >> Also, please update the description of PageOffline in page-flags.h to >> include the additional usage with PageBuddy set at the same time. >=20 > Okay. >=20 >> 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. >=20 > I think so, but I would need to look at this code once again. >=20 Another thing to look into would be teaching makedumpfile via vmcoreinfo=20 about these special buddy pages: makedumpfile will naturally skip all PageOffline pages and skip=20 PageBuddy pages if requested to skip free pages. It detects these pages=20 via the mapcount value. You will want makedumpfile to treat them like=20 PageOffline pages: kernel/crash_core.c #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy) VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); We could export PAGE_BUDDY_OFFLINE_MAPCOUNT_VALUE or just compute it=20 inside makedumpfile from the other two values. --=20 Thanks, David / dhildenb