From nobody Mon Feb 9 23:40:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1662450008274664.143950740741; Tue, 6 Sep 2022 00:40:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.399537.640766 (Exim 4.92) (envelope-from ) id 1oVTBV-0008BP-SN; Tue, 06 Sep 2022 07:39:49 +0000 Received: by outflank-mailman (output) from mailman id 399537.640766; Tue, 06 Sep 2022 07:39:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oVTBV-0008BG-ON; Tue, 06 Sep 2022 07:39:49 +0000 Received: by outflank-mailman (input) for mailman id 399537; Tue, 06 Sep 2022 07:39:48 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oVTBU-0007HG-9E for xen-devel@lists.xenproject.org; Tue, 06 Sep 2022 07:39:48 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 14cfded2-2db7-11ed-a016-b9edf5238543; Tue, 06 Sep 2022 09:39:47 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D9596176A; Tue, 6 Sep 2022 00:39:52 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 96A743F73D; Tue, 6 Sep 2022 00:40:11 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 14cfded2-2db7-11ed-a016-b9edf5238543 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Penny Zheng , Julien Grall Subject: [PATCH v12 3/6] xen: unpopulate memory when domain is static Date: Tue, 6 Sep 2022 15:39:16 +0800 Message-Id: <20220906073919.941934-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073919.941934-1-Penny.Zheng@arm.com> References: <20220906073919.941934-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1662450009549100005 Content-Type: text/plain; charset="utf-8" Today when a domain unpopulates the memory on runtime, they will always hand the memory back to the heap allocator. And it will be a problem if dom= ain is static. Pages as guest RAM for static domain shall be reserved to only this domain and not be used for any other purposes, so they shall never go back to heap allocator. This commit puts reserved page on the new list resv_page_list after it has been freed. Signed-off-by: Penny Zheng Acked-by: Jan Beulich Acked-by: Julien Grall --- v12 changes: - no change --- v11 change: - commit message tweak --- v10 change: - Do not skip the list addition in that one special case --- v9 change: - remove macro helper put_static_page, and just expand its code inside free_domstatic_page --- v8 changes: - adapt this patch for newly introduced free_domstatic_page - order as a parameter is not needed here, as all staticmem operations are limited to order-0 regions - move d->page_alloc_lock after operation on d->resv_page_list --- v7 changes: - Add page on the rsv_page_list *after* it has been freed --- v6 changes: - refine in-code comment - move PGC_static !CONFIG_STATIC_MEMORY definition to common header --- v5 changes: - adapt this patch for PGC_staticmem --- v4 changes: - no changes --- v3 changes: - have page_list_del() just once out of the if() - remove resv_pages counter - make arch_free_heap_page be an expression, not a compound statement. --- v2 changes: - put reserved pages on resv_page_list after having taken them off the "normal" list --- xen/common/domain.c | 4 ++++ xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 7062393e37..c23f449451 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -604,6 +604,10 @@ struct domain *domain_create(domid_t domid, INIT_PAGE_LIST_HEAD(&d->page_list); INIT_PAGE_LIST_HEAD(&d->extra_page_list); INIT_PAGE_LIST_HEAD(&d->xenpage_list); +#ifdef CONFIG_STATIC_MEMORY + INIT_PAGE_LIST_HEAD(&d->resv_page_list); +#endif + =20 spin_lock_init(&d->node_affinity_lock); d->node_affinity =3D NODE_MASK_ALL; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 0c50dee4c5..26a2fad4e3 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2741,10 +2741,13 @@ void free_domstatic_page(struct page_info *page) =20 drop_dom_ref =3D !domain_adjust_tot_pages(d, -1); =20 - spin_unlock_recursive(&d->page_alloc_lock); - free_staticmem_pages(page, 1, scrub_debug); =20 + /* Add page on the resv_page_list *after* it has been freed. */ + page_list_add_tail(page, &d->resv_page_list); + + spin_unlock_recursive(&d->page_alloc_lock); + if ( drop_dom_ref ) put_domain(d); } diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 1cf629e7ec..956e0f9dca 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -381,6 +381,9 @@ struct domain struct page_list_head page_list; /* linked list */ struct page_list_head extra_page_list; /* linked list (size extra_page= s) */ struct page_list_head xenpage_list; /* linked list (size xenheap_pages= ) */ +#ifdef CONFIG_STATIC_MEMORY + struct page_list_head resv_page_list; /* linked list */ +#endif =20 /* * This field should only be directly accessed by domain_adjust_tot_pa= ges() --=20 2.25.1