From nobody Sun May 19 04:05:28 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 1654587093313640.0716679309326; Tue, 7 Jun 2022 00:31:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342883.567993 (Exim 4.92) (envelope-from ) id 1nyTg0-0003PL-4d; Tue, 07 Jun 2022 07:30:56 +0000 Received: by outflank-mailman (output) from mailman id 342883.567993; Tue, 07 Jun 2022 07:30:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nyTg0-0003PE-1e; Tue, 07 Jun 2022 07:30:56 +0000 Received: by outflank-mailman (input) for mailman id 342883; Tue, 07 Jun 2022 07:30:55 +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 1nyTfz-00039i-3y for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:30:55 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id c3340c00-e633-11ec-b605-df0040e90b76; Tue, 07 Jun 2022 09:30:53 +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 0A790143D; Tue, 7 Jun 2022 00:30:53 -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 511293F66F; Tue, 7 Jun 2022 00:30:49 -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: c3340c00-e633-11ec-b605-df0040e90b76 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 v6 1/9] xen/arm: rename PGC_reserved to PGC_static Date: Tue, 7 Jun 2022 15:30:23 +0800 Message-Id: <20220607073031.722174-2-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587094450100003 Content-Type: text/plain; charset="utf-8" PGC_reserved could be ambiguous, and we have to tell what the pages are reserved for, so this commit intends to rename PGC_reserved to PGC_static, which clearly indicates the page is reserved for static memory. Signed-off-by: Penny Zheng Acked-by: Jan Beulich Acked-by: Julien Grall --- v6 changes: - rename PGC_staticmem to PGC_static --- v5 changes: - new commit --- xen/arch/arm/include/asm/mm.h | 6 +++--- xen/common/page_alloc.c | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 424aaf2823..fbff11c468 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -108,9 +108,9 @@ struct page_info /* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2) #define PGC_xen_heap PG_mask(1, 2) - /* Page is reserved */ -#define _PGC_reserved PG_shift(3) -#define PGC_reserved PG_mask(1, 3) + /* Page is static memory */ +#define _PGC_static PG_shift(3) +#define PGC_static PG_mask(1, 3) /* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 319029140f..9e5c757847 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -151,8 +151,8 @@ #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg !=3D NULL) #endif =20 -#ifndef PGC_reserved -#define PGC_reserved 0 +#ifndef PGC_static +#define PGC_static 0 #endif =20 /* @@ -2286,7 +2286,7 @@ int assign_pages( =20 for ( i =3D 0; i < nr; i++ ) { - ASSERT(!(pg[i].count_info & ~(PGC_extra | PGC_reserved))); + ASSERT(!(pg[i].count_info & ~(PGC_extra | PGC_static))); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2346,7 +2346,7 @@ int assign_pages( page_set_owner(&pg[i], d); smp_wmb(); /* Domain pointer must be visible before updating refcn= t. */ pg[i].count_info =3D - (pg[i].count_info & (PGC_extra | PGC_reserved)) | PGC_allocate= d | 1; + (pg[i].count_info & (PGC_extra | PGC_static)) | PGC_allocated = | 1; =20 page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } @@ -2652,8 +2652,8 @@ void __init free_staticmem_pages(struct page_info *pg= , unsigned long nr_mfns, scrub_one_page(pg); } =20 - /* In case initializing page of static memory, mark it PGC_reserve= d. */ - pg[i].count_info |=3D PGC_reserved; + /* In case initializing page of static memory, mark it PGC_static.= */ + pg[i].count_info |=3D PGC_static; } } =20 @@ -2682,8 +2682,8 @@ static struct page_info * __init acquire_staticmem_pa= ges(mfn_t smfn, =20 for ( i =3D 0; i < nr_mfns; i++ ) { - /* The page should be reserved and not yet allocated. */ - if ( pg[i].count_info !=3D (PGC_state_free | PGC_reserved) ) + /* The page should be static and not yet allocated. */ + if ( pg[i].count_info !=3D (PGC_state_free | PGC_static) ) { printk(XENLOG_ERR "pg[%lu] Static MFN %"PRI_mfn" c=3D%#lx t=3D%#x\n", @@ -2697,10 +2697,10 @@ static struct page_info * __init acquire_staticmem_= pages(mfn_t smfn, &tlbflush_timestamp); =20 /* - * Preserve flag PGC_reserved and change page state + * Preserve flag PGC_static and change page state * to PGC_state_inuse. */ - pg[i].count_info =3D PGC_reserved | PGC_state_inuse; + pg[i].count_info =3D PGC_static | PGC_state_inuse; /* Initialise fields which have other uses for free pages. */ pg[i].u.inuse.type_info =3D 0; page_set_owner(&pg[i], NULL); @@ -2722,7 +2722,7 @@ static struct page_info * __init acquire_staticmem_pa= ges(mfn_t smfn, =20 out_err: while ( i-- ) - pg[i].count_info =3D PGC_reserved | PGC_state_free; + pg[i].count_info =3D PGC_static | PGC_state_free; =20 spin_unlock(&heap_lock); =20 --=20 2.25.1 From nobody Sun May 19 04:05:28 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 1654587092722202.45785350219933; Tue, 7 Jun 2022 00:31:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342884.568004 (Exim 4.92) (envelope-from ) id 1nyTg5-0003hg-Kw; Tue, 07 Jun 2022 07:31:01 +0000 Received: by outflank-mailman (output) from mailman id 342884.568004; Tue, 07 Jun 2022 07:31: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 1nyTg5-0003hX-FW; Tue, 07 Jun 2022 07:31:01 +0000 Received: by outflank-mailman (input) for mailman id 342884; Tue, 07 Jun 2022 07:30:59 +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 1nyTg3-0003fm-GI for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:30:59 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id c599db1d-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:30:57 +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 3282B1480; Tue, 7 Jun 2022 00:30:57 -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 770003F66F; Tue, 7 Jun 2022 00:30:53 -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: c599db1d-e633-11ec-bd2c-47488cf2e6aa 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 v6 2/9] xen: do not free reserved memory into heap Date: Tue, 7 Jun 2022 15:30:24 +0800 Message-Id: <20220607073031.722174-3-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587094277100001 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 Acked-by: Jan Beulich --- v6 changes: - adapt to PGC_static - remove #ifdef aroud function declaration --- v5 changes: - In order to avoid stub functions, we #define PGC_staticmem to non-zero on= ly when CONFIG_STATIC_MEMORY - use "unlikely()" around pg->count_info & PGC_staticmem - remove pointless "if", since mark_page_free() is going to set count_info to PGC_state_free and by consequence clear PGC_staticmem - move #define PGC_staticmem 0 to mm.h --- 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/arch/arm/include/asm/mm.h | 4 +++- xen/common/page_alloc.c | 12 +++++++++--- xen/include/xen/mm.h | 2 -- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index fbff11c468..7442893e77 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -108,9 +108,11 @@ struct page_info /* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2) #define PGC_xen_heap PG_mask(1, 2) - /* Page is static memory */ +#ifdef CONFIG_STATIC_MEMORY +/* Page is static memory */ #define _PGC_static PG_shift(3) #define PGC_static PG_mask(1, 3) +#endif /* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 9e5c757847..6876869fa6 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1443,6 +1443,13 @@ static void free_heap_pages( =20 ASSERT(order <=3D MAX_ORDER); =20 + if ( unlikely(pg->count_info & PGC_static) ) + { + /* Pages of static memory shall not go back to the heap. */ + free_staticmem_pages(pg, 1UL << order, need_scrub); + return; + } + spin_lock(&heap_lock); =20 for ( i =3D 0; i < (1 << order); i++ ) @@ -2636,8 +2643,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; @@ -2652,7 +2659,6 @@ void __init free_staticmem_pages(struct page_info *pg= , unsigned long nr_mfns, scrub_one_page(pg); } =20 - /* In case initializing page of static memory, mark it PGC_static.= */ pg[i].count_info |=3D PGC_static; } } diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 3be754da92..1c4ddb336b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -85,13 +85,11 @@ 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); int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_= mfns, unsigned int memflags); -#endif =20 /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( --=20 2.25.1 From nobody Sun May 19 04:05:28 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 1654587094445890.8989230064772; Tue, 7 Jun 2022 00:31:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342885.568015 (Exim 4.92) (envelope-from ) id 1nyTg7-0003xu-0e; Tue, 07 Jun 2022 07:31:03 +0000 Received: by outflank-mailman (output) from mailman id 342885.568015; Tue, 07 Jun 2022 07:31: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 1nyTg6-0003wc-SC; Tue, 07 Jun 2022 07:31:02 +0000 Received: by outflank-mailman (input) for mailman id 342885; Tue, 07 Jun 2022 07:31:02 +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 1nyTg6-0003fm-6H for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:02 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id c7d1595a-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:01 +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 D72931480; Tue, 7 Jun 2022 00:31:00 -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 9F30C3F66F; Tue, 7 Jun 2022 00:30:57 -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: c7d1595a-e633-11ec-bd2c-47488cf2e6aa 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 v6 3/9] xen: update SUPPORT.md for static allocation Date: Tue, 7 Jun 2022 15:30:25 +0800 Message-Id: <20220607073031.722174-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587096166100005 Content-Type: text/plain; charset="utf-8" SUPPORT.md doesn't seem to explicitly say whether static memory is supported, so this commit updates SUPPORT.md to add feature static allocation tech preview for now. Signed-off-by: Penny Zheng Reviewed-by: Stefano Stabellini --- v6 changes: - use domain instead of sub-systems --- v5 changes: - new commit --- SUPPORT.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index ee2cd319e2..f50bc3a0fd 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -278,6 +278,13 @@ to boot with memory < maxmem. =20 Status, x86 HVM: Supported =20 +### Static Allocation + +Static allocation refers to domains for which memory areas are +pre-defined by configuration using physical address ranges. + + Status, ARM: Tech Preview + ### Memory Sharing =20 Allow sharing of identical pages between guests --=20 2.25.1 From nobody Sun May 19 04:05:28 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 16545870975961019.5837806649116; Tue, 7 Jun 2022 00:31:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342889.568026 (Exim 4.92) (envelope-from ) id 1nyTgF-0004QG-Ba; Tue, 07 Jun 2022 07:31:11 +0000 Received: by outflank-mailman (output) from mailman id 342889.568026; Tue, 07 Jun 2022 07:31: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 1nyTgF-0004Pv-75; Tue, 07 Jun 2022 07:31:11 +0000 Received: by outflank-mailman (input) for mailman id 342889; Tue, 07 Jun 2022 07:31:10 +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 1nyTgE-0003fm-AY for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ca2f7dd8-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:05 +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 C0F93143D; Tue, 7 Jun 2022 00:31:04 -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 503663F66F; Tue, 7 Jun 2022 00:31:01 -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: ca2f7dd8-e633-11ec-bd2c-47488cf2e6aa 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 , Julien Grall , Penny Zheng Subject: [PATCH v6 4/9] xen: do not merge reserved pages in free_heap_pages() Date: Tue, 7 Jun 2022 15:30:26 +0800 Message-Id: <20220607073031.722174-5-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587098242100011 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. Suggested-by: Julien Grall Signed-off-by: Penny Zheng Reviewed-by: Jan Beulich Reviewed-by: Julien Grall --- v6 changes: - adapt to PGC_static --- v5 changes: - change PGC_reserved to adapt to PGC_staticmem --- v4 changes: - no changes --- 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 6876869fa6..7fb28e2e07 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1486,6 +1486,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_static) || (PFN_ORDER(predecessor) !=3D order) || (phys_to_nid(page_to_maddr(predecessor)) !=3D node) ) break; @@ -1509,6 +1510,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_static) || (PFN_ORDER(successor) !=3D order) || (phys_to_nid(page_to_maddr(successor)) !=3D node) ) break; --=20 2.25.1 From nobody Sun May 19 04:05:28 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 1654587096741941.7857075304213; Tue, 7 Jun 2022 00:31:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342890.568037 (Exim 4.92) (envelope-from ) id 1nyTgG-0004ic-Lr; Tue, 07 Jun 2022 07:31:12 +0000 Received: by outflank-mailman (output) from mailman id 342890.568037; Tue, 07 Jun 2022 07:31:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nyTgG-0004hH-Gl; Tue, 07 Jun 2022 07:31:12 +0000 Received: by outflank-mailman (input) for mailman id 342890; Tue, 07 Jun 2022 07:31:11 +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 1nyTgF-0003fm-Af for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:11 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ccceee0a-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:09 +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 34CCF1480; Tue, 7 Jun 2022 00:31:09 -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 3A1303F66F; Tue, 7 Jun 2022 00:31:04 -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: ccceee0a-e633-11ec-bd2c-47488cf2e6aa 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 v6 5/9] xen: add field "flags" to cover all internal CDF_XXX Date: Tue, 7 Jun 2022 15:30:27 +0800 Message-Id: <20220607073031.722174-6-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587098044100008 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 --- v6 changes: - no change --- v5 changes: - no change --- 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 7570eae91a..a3ef991bd1 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 463d41ffb6..5191853c18 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -596,6 +596,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 Sun May 19 04:05:28 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 1654587099209264.9708371497644; Tue, 7 Jun 2022 00:31:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342896.568047 (Exim 4.92) (envelope-from ) id 1nyTgK-0005IB-Tm; Tue, 07 Jun 2022 07:31:16 +0000 Received: by outflank-mailman (output) from mailman id 342896.568047; Tue, 07 Jun 2022 07:31: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 1nyTgK-0005GX-OC; Tue, 07 Jun 2022 07:31:16 +0000 Received: by outflank-mailman (input) for mailman id 342896; Tue, 07 Jun 2022 07:31:14 +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 1nyTgI-0003fm-Od for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:14 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id cf482a9e-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:13 +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 68A6B143D; Tue, 7 Jun 2022 00:31:13 -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 A11323F66F; Tue, 7 Jun 2022 00:31:09 -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: cf482a9e-e633-11ec-bd2c-47488cf2e6aa 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 v6 6/9] xen/arm: introduce CDF_staticmem Date: Tue, 7 Jun 2022 15:30:28 +0800 Message-Id: <20220607073031.722174-7-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587100038100013 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 --- v6 changes: - move non-zero is_domain_using_staticmem() from ARM header to common header --- v5 changes: - guard "is_domain_using_staticmem" under CONFIG_STATIC_MEMORY - #define is_domain_using_staticmem zero if undefined --- 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/include/xen/domain.h | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 7ddd16c26d..f6e2e44c1e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3287,9 +3287,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/include/xen/domain.h b/xen/include/xen/domain.h index 1c3c88a14d..c847452414 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -34,6 +34,14 @@ 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 + +#ifdef CONFIG_STATIC_MEMORY +#define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem) +#else +#define is_domain_using_staticmem(d) ((void)(d), false) #endif =20 /* --=20 2.25.1 From nobody Sun May 19 04:05:28 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 1654587228133854.3975904081532; Tue, 7 Jun 2022 00:33:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342932.568070 (Exim 4.92) (envelope-from ) id 1nyTiR-0007Z6-Jq; Tue, 07 Jun 2022 07:33:27 +0000 Received: by outflank-mailman (output) from mailman id 342932.568070; Tue, 07 Jun 2022 07:33:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nyTiR-0007Yz-G0; Tue, 07 Jun 2022 07:33:27 +0000 Received: by outflank-mailman (input) for mailman id 342932; Tue, 07 Jun 2022 07:33:26 +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 1nyTgN-0003fm-7S for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id d1c68291-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:18 +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 9A2BA1480; Tue, 7 Jun 2022 00:31:17 -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 D68233F66F; Tue, 7 Jun 2022 00:31:13 -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: d1c68291-e633-11ec-bd2c-47488cf2e6aa 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 v6 7/9] xen/arm: unpopulate memory when domain is static Date: Tue, 7 Jun 2022 15:30:29 +0800 Message-Id: <20220607073031.722174-8-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587228843100003 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 Acked-by: Jan Beulich --- 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/arch/arm/include/asm/mm.h | 12 ++++++++++++ xen/common/domain.c | 4 ++++ xen/common/page_alloc.c | 4 ---- xen/include/xen/mm.h | 4 ++++ xen/include/xen/sched.h | 3 +++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 7442893e77..2ce4d80796 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -360,6 +360,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_static ) \ + 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 a3ef991bd1..a49574fa24 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 7fb28e2e07..886b5d82a2 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -151,10 +151,6 @@ #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg !=3D NULL) #endif =20 -#ifndef PGC_static -#define PGC_static 0 -#endif - /* * Comma-separated list of hexadecimal page numbers containing bad bytes. * e.g. 'badpage=3D0x3f45,0x8a321'. diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 1c4ddb336b..e80b4bdcde 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -210,6 +210,10 @@ extern struct domain *dom_cow; =20 #include =20 +#ifndef PGC_static +#define PGC_static 0 +#endif + static inline bool is_special_page(const struct page_info *page) { return is_xen_heap_page(page) || (page->count_info & PGC_extra); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 5191853c18..bd2782b3c5 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 From nobody Sun May 19 04:05:28 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 1654587255629241.9889633415396; Tue, 7 Jun 2022 00:34:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342958.568081 (Exim 4.92) (envelope-from ) id 1nyTir-0008Sd-U2; Tue, 07 Jun 2022 07:33:53 +0000 Received: by outflank-mailman (output) from mailman id 342958.568081; Tue, 07 Jun 2022 07:33:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nyTir-0008SW-Q1; Tue, 07 Jun 2022 07:33:53 +0000 Received: by outflank-mailman (input) for mailman id 342958; Tue, 07 Jun 2022 07:33:52 +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 1nyTgR-0003fm-B3 for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:23 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id d40a8812-e633-11ec-bd2c-47488cf2e6aa; Tue, 07 Jun 2022 09:31:21 +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 47AD5143D; Tue, 7 Jun 2022 00:31:21 -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 17FD33F66F; Tue, 7 Jun 2022 00:31:17 -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: d40a8812-e633-11ec-bd2c-47488cf2e6aa 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 v6 8/9] xen: introduce prepare_staticmem_pages Date: Tue, 7 Jun 2022 15:30:30 +0800 Message-Id: <20220607073031.722174-9-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587256967100001 Content-Type: text/plain; charset="utf-8" Later, we want to use acquire_domstatic_pages() for populating memory for static domain on runtime, however, there are a lot of pointless work (checking mfn_valid(), scrubbing the free part, cleaning the cache...) considering we know the page is valid and belong to the guest. This commit splits acquire_staticmem_pages() in two parts, and introduces prepare_staticmem_pages to bypass all "pointless work". Signed-off-by: Penny Zheng Acked-by: Jan Beulich --- v6 changes: - adapt to PGC_static --- v5 changes: - new commit --- xen/common/page_alloc.c | 61 ++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 886b5d82a2..9004dd41c1 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2661,26 +2661,13 @@ void free_staticmem_pages(struct page_info *pg, uns= igned long nr_mfns, } } =20 -/* - * Acquire nr_mfns contiguous reserved pages, starting at #smfn, of - * static memory. - * This function needs to be reworked if used outside of boot. - */ -static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, - unsigned long nr_= mfns, - unsigned int memf= lags) +static bool __init prepare_staticmem_pages(struct page_info *pg, + unsigned long nr_mfns, + unsigned int memflags) { bool need_tlbflush =3D false; uint32_t tlbflush_timestamp =3D 0; unsigned long i; - struct page_info *pg; - - ASSERT(nr_mfns); - for ( i =3D 0; i < nr_mfns; i++ ) - if ( !mfn_valid(mfn_add(smfn, i)) ) - return NULL; - - pg =3D mfn_to_page(smfn); =20 spin_lock(&heap_lock); =20 @@ -2691,7 +2678,7 @@ static struct page_info * __init acquire_staticmem_pa= ges(mfn_t smfn, { printk(XENLOG_ERR "pg[%lu] Static MFN %"PRI_mfn" c=3D%#lx t=3D%#x\n", - i, mfn_x(smfn) + i, + i, mfn_x(page_to_mfn(pg)) + i, pg[i].count_info, pg[i].tlbflush_timestamp); goto out_err; } @@ -2715,6 +2702,38 @@ static struct page_info * __init acquire_staticmem_p= ages(mfn_t smfn, if ( need_tlbflush ) filtered_flush_tlb_mask(tlbflush_timestamp); =20 + return true; + + out_err: + while ( i-- ) + pg[i].count_info =3D PGC_static | PGC_state_free; + + spin_unlock(&heap_lock); + + return false; +} + +/* + * Acquire nr_mfns contiguous reserved pages, starting at #smfn, of + * static memory. + * This function needs to be reworked if used outside of boot. + */ +static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, + unsigned long nr_= mfns, + unsigned int memf= lags) +{ + unsigned long i; + struct page_info *pg; + + ASSERT(nr_mfns); + for ( i =3D 0; i < nr_mfns; i++ ) + if ( !mfn_valid(mfn_add(smfn, i)) ) + return NULL; + + pg =3D mfn_to_page(smfn); + if ( !prepare_staticmem_pages(pg, nr_mfns, memflags) ) + return NULL; + /* * Ensure cache and RAM are consistent for platforms where the guest * can control its own visibility of/through the cache. @@ -2723,14 +2742,6 @@ static struct page_info * __init acquire_staticmem_p= ages(mfn_t smfn, flush_page_to_ram(mfn_x(smfn) + i, !(memflags & MEMF_no_icache_flu= sh)); =20 return pg; - - out_err: - while ( i-- ) - pg[i].count_info =3D PGC_static | PGC_state_free; - - spin_unlock(&heap_lock); - - return NULL; } =20 /* --=20 2.25.1 From nobody Sun May 19 04:05:28 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 1654587225743253.66790189017286; Tue, 7 Jun 2022 00:33:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.342915.568059 (Exim 4.92) (envelope-from ) id 1nyTiM-0007DK-96; Tue, 07 Jun 2022 07:33:22 +0000 Received: by outflank-mailman (output) from mailman id 342915.568059; Tue, 07 Jun 2022 07:33:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nyTiM-0007DD-5F; Tue, 07 Jun 2022 07:33:22 +0000 Received: by outflank-mailman (input) for mailman id 342915; Tue, 07 Jun 2022 07:33:21 +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 1nyTgV-00039i-FE for xen-devel@lists.xenproject.org; Tue, 07 Jun 2022 07:31:27 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id d61425d5-e633-11ec-b605-df0040e90b76; Tue, 07 Jun 2022 09:31:25 +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 E218D143D; Tue, 7 Jun 2022 00:31:24 -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 B40613F66F; Tue, 7 Jun 2022 00:31:21 -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: d61425d5-e633-11ec-b605-df0040e90b76 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 v6 9/9] xen: retrieve reserved pages on populate_physmap Date: Tue, 7 Jun 2022 15:30:31 +0800 Message-Id: <20220607073031.722174-10-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607073031.722174-1-Penny.Zheng@arm.com> References: <20220607073031.722174-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1654587226902100001 When a static domain populates memory through populate_physmap at runtime, it shall retrieve reserved pages from resv_page_list to make sure that guest RAM is still restricted in statically configured memory regions. This commit also introduces a new helper acquire_reserved_page to make it w= ork. Signed-off-by: Penny Zheng --- v6 changes: - drop the lock before returning --- v5 changes: - extract common codes for assigning pages into a helper assign_domstatic_p= ages - refine commit message - remove stub function acquire_reserved_page - Alloc/free of memory can happen concurrently. So access to rsv_page_list needs to be protected with a spinlock --- 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 | 70 +++++++++++++++++++++++++++++++---------- xen/include/xen/mm.h | 1 + 3 files changed, 77 insertions(+), 17 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 9004dd41c1..57d28304df 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2661,9 +2661,8 @@ void free_staticmem_pages(struct page_info *pg, unsig= ned long nr_mfns, } } =20 -static bool __init prepare_staticmem_pages(struct page_info *pg, - unsigned long nr_mfns, - unsigned int memflags) +static bool prepare_staticmem_pages(struct page_info *pg, unsigned long nr= _mfns, + unsigned int memflags) { bool need_tlbflush =3D false; uint32_t tlbflush_timestamp =3D 0; @@ -2744,21 +2743,9 @@ static struct page_info * __init acquire_staticmem_p= ages(mfn_t smfn, return pg; } =20 -/* - * 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) +static int assign_domstatic_pages(struct domain *d, struct page_info *pg, + unsigned int nr_mfns, unsigned int memfl= ags) { - struct page_info *pg; - - ASSERT(!in_irq()); - - pg =3D acquire_staticmem_pages(smfn, nr_mfns, memflags); - if ( !pg ) - return -ENOENT; - if ( !d || (memflags & (MEMF_no_owner | MEMF_no_refcount)) ) { /* @@ -2777,6 +2764,55 @@ int __init acquire_domstatic_pages(struct domain *d,= mfn_t smfn, =20 return 0; } + +/* + * 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) +{ + struct page_info *pg; + + ASSERT(!in_irq()); + + pg =3D acquire_staticmem_pages(smfn, nr_mfns, memflags); + if ( !pg ) + return -ENOENT; + + if ( assign_domstatic_pages(d, pg, nr_mfns, memflags) ) + return -EINVAL; + + 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; + + spin_lock(&d->page_alloc_lock); + /* Acquire a page from reserved page list(resv_page_list). */ + page =3D page_list_remove_head(&d->resv_page_list); + spin_unlock(&d->page_alloc_lock); + if ( unlikely(!page) ) + return INVALID_MFN; + + if ( !prepare_staticmem_pages(page, 1, memflags) ) + goto fail; + + if ( assign_domstatic_pages(d, page, 1, memflags) ) + goto fail; + + return page_to_mfn(page); + + fail: + page_list_add_tail(page, &d->resv_page_list); + return INVALID_MFN; +} #endif =20 /* diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index e80b4bdcde..e100151e50 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -90,6 +90,7 @@ void free_staticmem_pages(struct page_info *pg, unsigned = long nr_mfns, bool need_scrub); int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_= mfns, unsigned int memflags); +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