From nobody Fri Apr 19 14:22:47 2024 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 1652149697578678.4581437649523; Mon, 9 May 2022 19:28:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325092.547538 (Exim 4.92) (envelope-from ) id 1noFbW-0003SS-8K; Tue, 10 May 2022 02:28:02 +0000 Received: by outflank-mailman (output) from mailman id 325092.547538; Tue, 10 May 2022 02:28:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbW-0003SH-3n; Tue, 10 May 2022 02:28:02 +0000 Received: by outflank-mailman (input) for mailman id 325092; Tue, 10 May 2022 02:28:00 +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 1noFbU-0003Ap-8b for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:00 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id cee46989-d008-11ec-a406-831a346695d4; Tue, 10 May 2022 04:27:59 +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 9CB9F12FC; Mon, 9 May 2022 19:27:58 -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 424D13F66F; Mon, 9 May 2022 19:27:54 -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: cee46989-d008-11ec-a406-831a346695d4 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 Subject: [PATCH v4 1/6] xen: do not free reserved memory into heap Date: Tue, 10 May 2022 10:27:28 +0800 Message-Id: <20220510022733.2422581-2-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149698626100002 Content-Type: text/plain; charset="utf-8" Pages used as guest RAM for static domain, shall be reserved to this domain only. So in case reserved pages being used for other purpose, users shall not free them back to heap, even when last ref gets dropped. free_staticmem_pages will be called by free_heap_pages in runtime for static domain freeing memory resource, so let's drop the __init flag. Signed-off-by: Penny Zheng --- v4 changes: - no changes --- v3 changes: - fix possible racy issue in free_staticmem_pages() - introduce a stub free_staticmem_pages() for the !CONFIG_STATIC_MEMORY case - move the change to free_heap_pages() to cover other potential call sites - fix the indentation --- v2 changes: - new commit --- xen/common/page_alloc.c | 17 ++++++++++++++--- xen/include/xen/mm.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 319029140f..5e569a48a2 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1443,6 +1443,10 @@ static void free_heap_pages( =20 ASSERT(order <=3D MAX_ORDER); =20 + if ( pg->count_info & PGC_reserved ) + /* Reserved page shall not go back to the heap. */ + return free_staticmem_pages(pg, 1UL << order, need_scrub); + spin_lock(&heap_lock); =20 for ( i =3D 0; i < (1 << order); i++ ) @@ -2636,8 +2640,8 @@ struct domain *get_pg_owner(domid_t domid) =20 #ifdef CONFIG_STATIC_MEMORY /* Equivalent of free_heap_pages to free nr_mfns pages of static memory. */ -void __init free_staticmem_pages(struct page_info *pg, unsigned long nr_mf= ns, - bool need_scrub) +void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, + bool need_scrub) { mfn_t mfn =3D page_to_mfn(pg); unsigned long i; @@ -2653,7 +2657,8 @@ void __init free_staticmem_pages(struct page_info *pg= , unsigned long nr_mfns, } =20 /* In case initializing page of static memory, mark it PGC_reserve= d. */ - pg[i].count_info |=3D PGC_reserved; + if ( !(pg[i].count_info & PGC_reserved) ) + pg[i].count_info |=3D PGC_reserved; } } =20 @@ -2762,6 +2767,12 @@ int __init acquire_domstatic_pages(struct domain *d,= mfn_t smfn, =20 return 0; } +#else +void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, + bool need_scrub) +{ + ASSERT_UNREACHABLE(); +} #endif =20 /* diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 3be754da92..9fd95deaec 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -85,10 +85,10 @@ bool scrub_free_pages(void); } while ( false ) #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0) =20 -#ifdef CONFIG_STATIC_MEMORY /* These functions are for static memory */ void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, bool need_scrub); +#ifdef CONFIG_STATIC_MEMORY int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_= mfns, unsigned int memflags); #endif --=20 2.25.1 From nobody Fri Apr 19 14:22:47 2024 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 1652149703580366.3614473293279; Mon, 9 May 2022 19:28:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325093.547549 (Exim 4.92) (envelope-from ) id 1noFbZ-0003ls-IO; Tue, 10 May 2022 02:28:05 +0000 Received: by outflank-mailman (output) from mailman id 325093.547549; Tue, 10 May 2022 02:28:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbZ-0003lf-EW; Tue, 10 May 2022 02:28:05 +0000 Received: by outflank-mailman (input) for mailman id 325093; Tue, 10 May 2022 02:28:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbY-0003k7-FD for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:04 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id d1426c74-d008-11ec-8fc4-03012f2f19d4; Tue, 10 May 2022 04:28:03 +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 C100A12FC; Mon, 9 May 2022 19:28:02 -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 215A33F66F; Mon, 9 May 2022 19:27:58 -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: d1426c74-d008-11ec-8fc4-03012f2f19d4 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 v4 2/6] xen: do not merge reserved pages in free_heap_pages() Date: Tue, 10 May 2022 10:27:29 +0800 Message-Id: <20220510022733.2422581-3-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149704646100001 Content-Type: text/plain; charset="utf-8" The code in free_heap_pages() will try to merge pages with the successor/predecessor if pages are suitably aligned. So if the pages reserved are right next to the pages given to the heap allocator, free_heap_pages() will merge them, and give the reserved pages to heap allocator accidently as a result. So in order to avoid the above scenario, this commit updates free_heap_page= s() to check whether the predecessor and/or successor has PGC_reserved set, when trying to merge the about-to-be-freed chunk with the predecessor and/or successor. Signed-off-by: Penny Zheng Suggested-by: Julien Grall Reviewed-by: Jan Beulich Reviewed-by: Julien Grall --- v4 changes: - commit message refinement --- v3 changes: - no changes --- v2 changes: - new commit --- xen/common/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 5e569a48a2..290526adaf 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1483,6 +1483,7 @@ static void free_heap_pages( /* Merge with predecessor block? */ if ( !mfn_valid(page_to_mfn(predecessor)) || !page_state_is(predecessor, free) || + (predecessor->count_info & PGC_reserved) || (PFN_ORDER(predecessor) !=3D order) || (phys_to_nid(page_to_maddr(predecessor)) !=3D node) ) break; @@ -1506,6 +1507,7 @@ static void free_heap_pages( /* Merge with successor block? */ if ( !mfn_valid(page_to_mfn(successor)) || !page_state_is(successor, free) || + (successor->count_info & PGC_reserved) || (PFN_ORDER(successor) !=3D order) || (phys_to_nid(page_to_maddr(successor)) !=3D node) ) break; --=20 2.25.1 From nobody Fri Apr 19 14:22:47 2024 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 1652149708936480.64859978190407; Mon, 9 May 2022 19:28:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325095.547560 (Exim 4.92) (envelope-from ) id 1noFbf-0004B6-UX; Tue, 10 May 2022 02:28:11 +0000 Received: by outflank-mailman (output) from mailman id 325095.547560; Tue, 10 May 2022 02:28:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbf-0004As-PO; Tue, 10 May 2022 02:28:11 +0000 Received: by outflank-mailman (input) for mailman id 325095; Tue, 10 May 2022 02:28:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbe-0003k7-7I for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id d40deea3-d008-11ec-8fc4-03012f2f19d4; Tue, 10 May 2022 04:28:08 +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 73DE512FC; Mon, 9 May 2022 19:28:07 -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 458EE3F66F; Mon, 9 May 2022 19:28:03 -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: d40deea3-d008-11ec-8fc4-03012f2f19d4 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Penny Zheng , Julien Grall Subject: [PATCH v4 3/6] xen: add field "flags" to cover all internal CDF_XXX Date: Tue, 10 May 2022 10:27:30 +0800 Message-Id: <20220510022733.2422581-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149710574100001 Content-Type: text/plain; charset="utf-8" With more and more CDF_xxx internal flags in and to save the space, this commit introduces a new field "flags" in struct domain to store CDF_* internal flags directly. Another new CDF_xxx will be introduced in the next patch. Signed-off-by: Penny Zheng Acked-by: Julien Grall --- v4 changes: - no change --- v3 changes: - change fixed width type uint32_t to unsigned int - change "flags" to a more descriptive name "cdf" --- v2 changes: - let "flags" live in the struct domain. So other arch can take advantage of it in the future - fix coding style --- xen/arch/arm/domain.c | 2 -- xen/arch/arm/include/asm/domain.h | 3 +-- xen/common/domain.c | 3 +++ xen/include/xen/sched.h | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 8110c1df86..74189d9878 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -709,8 +709,6 @@ int arch_domain_create(struct domain *d, ioreq_domain_init(d); #endif =20 - d->arch.directmap =3D flags & CDF_directmap; - /* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc =3D iommu_domain_init(d, config->iommu_opts)) !=3D 0 ) goto fail; diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/d= omain.h index ed63c2b6f9..fe7a029ebf 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -29,7 +29,7 @@ enum domain_type { #define is_64bit_domain(d) (0) #endif =20 -#define is_domain_direct_mapped(d) (d)->arch.directmap +#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) =20 /* * Is the domain using the host memory layout? @@ -103,7 +103,6 @@ struct arch_domain void *tee; #endif =20 - bool directmap; } __cacheline_aligned; =20 struct arch_vcpu diff --git a/xen/common/domain.c b/xen/common/domain.c index 8d2c2a9897..6373407047 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -567,6 +567,9 @@ struct domain *domain_create(domid_t domid, /* Sort out our idea of is_system_domain(). */ d->domain_id =3D domid; =20 + /* Holding CDF_* internal flags. */ + d->cdf =3D flags; + /* Debug sanity. */ ASSERT(is_system_domain(d) ? config =3D=3D NULL : config !=3D NULL); =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index ed8539f6d2..49415a113a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -591,6 +591,9 @@ struct domain struct ioreq_server *server[MAX_NR_IOREQ_SERVERS]; } ioreq_server; #endif + + /* Holding CDF_* constant. Internal flags for domain creation. */ + unsigned int cdf; }; =20 static inline struct page_list_head *page_to_list( --=20 2.25.1 From nobody Fri Apr 19 14:22:47 2024 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 1652149715099833.9853730986267; Mon, 9 May 2022 19:28:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325102.547571 (Exim 4.92) (envelope-from ) id 1noFbk-0004dP-6Z; Tue, 10 May 2022 02:28:16 +0000 Received: by outflank-mailman (output) from mailman id 325102.547571; Tue, 10 May 2022 02:28:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbk-0004dG-1e; Tue, 10 May 2022 02:28:16 +0000 Received: by outflank-mailman (input) for mailman id 325102; Tue, 10 May 2022 02:28:15 +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 1noFbi-0003Ap-U3 for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:14 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id d6ccfa6f-d008-11ec-a406-831a346695d4; Tue, 10 May 2022 04:28:12 +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 D937B12FC; Mon, 9 May 2022 19:28:11 -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 EE5533F66F; Mon, 9 May 2022 19:28:07 -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: d6ccfa6f-d008-11ec-a406-831a346695d4 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Penny Zheng Subject: [PATCH v4 4/6] xen/arm: introduce CDF_staticmem Date: Tue, 10 May 2022 10:27:31 +0800 Message-Id: <20220510022733.2422581-5-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149716411100001 Content-Type: text/plain; charset="utf-8" In order to have an easy and quick way to find out whether this domain memo= ry is statically configured, this commit introduces a new flag CDF_staticmem a= nd a new helper is_domain_using_staticmem() to tell. Signed-off-by: Penny Zheng Reviewed-by: Stefano Stabellini --- v4 changes: - no changes --- v3 changes: - change name from "is_domain_static()" to "is_domain_using_staticmem" --- v2 changes: - change name from "is_domain_on_static_allocation" to "is_domain_static()" --- xen/arch/arm/domain_build.c | 5 ++++- xen/arch/arm/include/asm/domain.h | 2 ++ xen/include/xen/domain.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 1472ca4972..6830a282a0 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3190,9 +3190,12 @@ void __init create_domUs(void) if ( !dt_device_is_compatible(node, "xen,domain") ) continue; =20 + if ( dt_find_property(node, "xen,static-mem", NULL) ) + flags |=3D CDF_staticmem; + if ( dt_property_read_bool(node, "direct-map") ) { - if ( !IS_ENABLED(CONFIG_STATIC_MEMORY) || !dt_find_property(no= de, "xen,static-mem", NULL) ) + if ( !IS_ENABLED(CONFIG_STATIC_MEMORY) || !(flags & CDF_static= mem) ) panic("direct-map is not valid for domain %s without stati= c allocation.\n", dt_node_name(node)); =20 diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/d= omain.h index fe7a029ebf..110c672589 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -31,6 +31,8 @@ enum domain_type { =20 #define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) =20 +#define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem) + /* * Is the domain using the host memory layout? * diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 1c3c88a14d..35dc7143a4 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -34,6 +34,8 @@ void arch_get_domain_info(const struct domain *d, #ifdef CONFIG_ARM /* Should domain memory be directly mapped? */ #define CDF_directmap (1U << 1) +/* Is domain memory on static allocation? */ +#define CDF_staticmem (1U << 2) #endif =20 /* --=20 2.25.1 From nobody Fri Apr 19 14:22:47 2024 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 1652149714856265.4714990671956; Mon, 9 May 2022 19:28:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325106.547582 (Exim 4.92) (envelope-from ) id 1noFbn-0005AF-GW; Tue, 10 May 2022 02:28:19 +0000 Received: by outflank-mailman (output) from mailman id 325106.547582; Tue, 10 May 2022 02:28:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFbn-00059x-Bx; Tue, 10 May 2022 02:28:19 +0000 Received: by outflank-mailman (input) for mailman id 325106; Tue, 10 May 2022 02:28:18 +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 1noFbl-0003Ap-Uc for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:17 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id d96cd610-d008-11ec-a406-831a346695d4; Tue, 10 May 2022 04:28:17 +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 49FDB12FC; Mon, 9 May 2022 19:28:16 -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 5E0043F66F; Mon, 9 May 2022 19:28:12 -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: d96cd610-d008-11ec-a406-831a346695d4 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Penny Zheng Subject: [PATCH v4 5/6] xen/arm: unpopulate memory when domain is static Date: Tue, 10 May 2022 10:27:32 +0800 Message-Id: <20220510022733.2422581-6-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149716413100002 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 pages on the new list resv_page_list only after having taken them off the "normal" list, when the last ref dropped. Signed-off-by: Penny Zheng --- 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/arch/arm/include/asm/mm.h | 12 ++++++++++++ xen/common/domain.c | 4 ++++ xen/include/xen/sched.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 424aaf2823..c6426c1705 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -358,6 +358,18 @@ void clear_and_clean_page(struct page_info *page); =20 unsigned int arch_get_dma_bitsize(void); =20 +/* + * Put free pages on the resv page list after having taken them + * off the "normal" page list, when pages from static memory + */ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page(d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif + #endif /* __ARCH_ARM_MM__ */ /* * Local variables: diff --git a/xen/common/domain.c b/xen/common/domain.c index 6373407047..13fe7cecff 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/include/xen/sched.h b/xen/include/xen/sched.h index 49415a113a..368e5c1c53 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -376,6 +376,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 (size resv_pages)= */ +#endif =20 /* * This field should only be directly accessed by domain_adjust_tot_pa= ges() --=20 2.25.1 From nobody Fri Apr 19 14:22:47 2024 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 1652149947667996.7896913697308; Mon, 9 May 2022 19:32:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325121.547592 (Exim 4.92) (envelope-from ) id 1noFfN-0007bn-1Q; Tue, 10 May 2022 02:32:01 +0000 Received: by outflank-mailman (output) from mailman id 325121.547592; Tue, 10 May 2022 02:32:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noFfM-0007bI-UX; Tue, 10 May 2022 02:32:00 +0000 Received: by outflank-mailman (input) for mailman id 325121; Tue, 10 May 2022 02:32:00 +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 1noFbq-0003Ap-Kt for xen-devel@lists.xenproject.org; Tue, 10 May 2022 02:28:22 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id dba07557-d008-11ec-a406-831a346695d4; Tue, 10 May 2022 04:28:20 +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 2738012FC; Mon, 9 May 2022 19:28:20 -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 C2C0E3F66F; Mon, 9 May 2022 19:28:16 -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: dba07557-d008-11ec-a406-831a346695d4 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 Subject: [PATCH v4 6/6] xen: retrieve reserved pages on populate_physmap Date: Tue, 10 May 2022 10:27:33 +0800 Message-Id: <20220510022733.2422581-7-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510022733.2422581-1-Penny.Zheng@arm.com> References: <20220510022733.2422581-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652149949115100001 When static domain populates memory through populate_physmap on runtime, other than allocating from heap, it shall retrieve reserved pages from resv_page_list to make sure that guest RAM is still restricted in statically configured memory regions. And this commit introduces a new helper acquire_reserved_page to make it work. Signed-off-by: Penny Zheng --- v4 changes=EF=BC=9A - miss dropping __init in acquire_domstatic_pages - add the page back to the reserved list in case of error - remove redundant printk - refine log message and make it warn level --- v3 changes: - move is_domain_using_staticmem to the common header file - remove #ifdef CONFIG_STATIC_MEMORY-ary - remove meaningless page_to_mfn(page) in error log --- v2 changes: - introduce acquire_reserved_page to retrieve reserved pages from resv_page_list - forbid non-zero-order requests in populate_physmap - let is_domain_static return ((void)(d), false) on x86 --- xen/common/memory.c | 23 +++++++++++++++++++++++ xen/common/page_alloc.c | 35 +++++++++++++++++++++++++++++++++-- xen/include/xen/domain.h | 4 ++++ xen/include/xen/mm.h | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index f2d009843a..cb330ce877 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -245,6 +245,29 @@ static void populate_physmap(struct memop_args *a) =20 mfn =3D _mfn(gpfn); } + else if ( is_domain_using_staticmem(d) ) + { + /* + * No easy way to guarantee the retrieved pages are contig= uous, + * so forbid non-zero-order requests here. + */ + if ( a->extent_order !=3D 0 ) + { + gdprintk(XENLOG_WARNING, + "Cannot allocate static order-%u pages for st= atic %pd\n", + a->extent_order, d); + goto out; + } + + mfn =3D acquire_reserved_page(d, a->memflags); + if ( mfn_eq(mfn, INVALID_MFN) ) + { + gdprintk(XENLOG_WARNING, + "%pd: failed to retrieve a reserved page\n", + d); + goto out; + } + } else { page =3D alloc_domheap_pages(d, a->extent_order, a->memfla= gs); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 290526adaf..06e7037a28 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2740,8 +2740,8 @@ static struct page_info * __init acquire_staticmem_pa= ges(mfn_t smfn, * Acquire nr_mfns contiguous pages, starting at #smfn, of static memory, * then assign them to one specific domain #d. */ -int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, - unsigned int nr_mfns, unsigned int memf= lags) +int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_= mfns, + unsigned int memflags) { struct page_info *pg; =20 @@ -2769,12 +2769,43 @@ int __init acquire_domstatic_pages(struct domain *d= , mfn_t smfn, =20 return 0; } + +/* + * Acquire a page from reserved page list(resv_page_list), when populating + * memory for static domain on runtime. + */ +mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags) +{ + struct page_info *page; + mfn_t smfn; + + /* Acquire a page from reserved page list(resv_page_list). */ + page =3D page_list_remove_head(&d->resv_page_list); + if ( unlikely(!page) ) + return INVALID_MFN; + + smfn =3D page_to_mfn(page); + + if ( acquire_domstatic_pages(d, smfn, 1, memflags) ) + { + page_list_add_tail(page, &d->resv_page_list); + return INVALID_MFN; + } + + return smfn; +} #else void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, bool need_scrub) { ASSERT_UNREACHABLE(); } + +mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags) +{ + ASSERT_UNREACHABLE(); + return INVALID_MFN; +} #endif =20 /* diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 35dc7143a4..c613afa57e 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -38,6 +38,10 @@ void arch_get_domain_info(const struct domain *d, #define CDF_staticmem (1U << 2) #endif =20 +#ifndef is_domain_using_staticmem +#define is_domain_using_staticmem(d) ((void)(d), false) +#endif + /* * Arch-specifics. */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 9fd95deaec..74810e1f54 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -92,6 +92,7 @@ void free_staticmem_pages(struct page_info *pg, unsigned = long nr_mfns, int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_= mfns, unsigned int memflags); #endif +mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags); =20 /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( --=20 2.25.1