From patchwork Thu Jul 7 09:22:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48A22C433EF for ; Thu, 7 Jul 2022 09:23:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362800.593026 (Exim 4.92) (envelope-from ) id 1o9Nj3-00032z-8h; Thu, 07 Jul 2022 09:23:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362800.593026; Thu, 07 Jul 2022 09:23:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9Nj3-00032o-57; Thu, 07 Jul 2022 09:23:09 +0000 Received: by outflank-mailman (input) for mailman id 362800; Thu, 07 Jul 2022 09:23:07 +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 1o9Nj1-00032J-CI for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:07 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 682b3be6-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23: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 BBEA81063; Thu, 7 Jul 2022 02:23:05 -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 5CB9D3F792; Thu, 7 Jul 2022 02:23:01 -0700 (PDT) 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: 682b3be6-fdd6-11ec-924f-1f966e50362f 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 v8 1/9] xen/arm: rename PGC_reserved to PGC_static Date: Thu, 7 Jul 2022 17:22:36 +0800 Message-Id: <20220707092244.485936-2-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 --- v8 changes - no change --- v7 changes: - no change --- 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 c4bc3cd1e5..8b2481c1f3 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 fe0e15429a..ed56379b96 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 != NULL) #endif -#ifndef PGC_reserved -#define PGC_reserved 0 +#ifndef PGC_static +#define PGC_static 0 #endif /* @@ -2286,7 +2286,7 @@ int assign_pages( for ( i = 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 refcnt. */ pg[i].count_info = - (pg[i].count_info & (PGC_extra | PGC_reserved)) | PGC_allocated | 1; + (pg[i].count_info & (PGC_extra | PGC_static)) | PGC_allocated | 1; 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); } - /* In case initializing page of static memory, mark it PGC_reserved. */ - pg[i].count_info |= PGC_reserved; + /* In case initializing page of static memory, mark it PGC_static. */ + pg[i].count_info |= PGC_static; } } @@ -2682,8 +2682,8 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, for ( i = 0; i < nr_mfns; i++ ) { - /* The page should be reserved and not yet allocated. */ - if ( pg[i].count_info != (PGC_state_free | PGC_reserved) ) + /* The page should be static and not yet allocated. */ + if ( pg[i].count_info != (PGC_state_free | PGC_static) ) { printk(XENLOG_ERR "pg[%lu] Static MFN %"PRI_mfn" c=%#lx t=%#x\n", @@ -2697,10 +2697,10 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, &tlbflush_timestamp); /* - * Preserve flag PGC_reserved and change page state + * Preserve flag PGC_static and change page state * to PGC_state_inuse. */ - pg[i].count_info = PGC_reserved | PGC_state_inuse; + pg[i].count_info = PGC_static | PGC_state_inuse; /* Initialise fields which have other uses for free pages. */ pg[i].u.inuse.type_info = 0; page_set_owner(&pg[i], NULL); @@ -2722,7 +2722,7 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, out_err: while ( i-- ) - pg[i].count_info = PGC_reserved | PGC_state_free; + pg[i].count_info = PGC_static | PGC_state_free; spin_unlock(&heap_lock); From patchwork Thu Jul 7 09:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C6BEC43334 for ; Thu, 7 Jul 2022 09:23:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362801.593036 (Exim 4.92) (envelope-from ) id 1o9Nj7-0003Ls-G2; Thu, 07 Jul 2022 09:23:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362801.593036; Thu, 07 Jul 2022 09:23:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9Nj7-0003Lf-DB; Thu, 07 Jul 2022 09:23:13 +0000 Received: by outflank-mailman (input) for mailman id 362801; Thu, 07 Jul 2022 09:23:11 +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 1o9Nj5-00032J-GI for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:11 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 6abb262f-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23:10 +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 1A1881063; Thu, 7 Jul 2022 02:23:10 -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 E85133F792; Thu, 7 Jul 2022 02:23:05 -0700 (PDT) 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: 6abb262f-fdd6-11ec-924f-1f966e50362f 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 v8 2/9] xen: do not free reserved memory into heap Date: Thu, 7 Jul 2022 17:22:37 +0800 Message-Id: <20220707092244.485936-3-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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. This commit introduces a new helper free_domstatic_page to free static page in runtime, and free_staticmem_pages will be called by it in runtime, so let's drop the __init flag. Signed-off-by: Penny Zheng --- v8 changes: - introduce new helper free_domstatic_page - let put_page call free_domstatic_page for static page, when last ref drops - #define PGC_static zero when !CONFIG_STATIC_MEMORY in xen/mm.h, as it is used outside page_alloc.c --- v7 changes: - protect free_staticmem_pages with heap_lock to match its reverse function acquire_staticmem_pages --- 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 only 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/arch/arm/mm.c | 2 ++ xen/common/page_alloc.c | 51 ++++++++++++++++++++++++++++++----- xen/include/xen/mm.h | 7 +++-- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 8b2481c1f3..f1640bbda4 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/arch/arm/mm.c b/xen/arch/arm/mm.c index 009b8cd9ef..a3bc6d7a24 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1622,6 +1622,8 @@ void put_page(struct page_info *page) if ( unlikely((nx & PGC_count_mask) == 0) ) { + if ( unlikely(nx & PGC_static) ) + free_domstatic_page(page); free_domheap_page(page); } } diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index ed56379b96..9a80ca10fa 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 != NULL) #endif -#ifndef PGC_static -#define PGC_static 0 -#endif - /* * Comma-separated list of hexadecimal page numbers containing bad bytes. * e.g. 'badpage=0x3f45,0x8a321'. @@ -2636,12 +2632,14 @@ struct domain *get_pg_owner(domid_t domid) #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_mfns, - bool need_scrub) +void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, + bool need_scrub) { mfn_t mfn = page_to_mfn(pg); unsigned long i; + spin_lock(&heap_lock); + for ( i = 0; i < nr_mfns; i++ ) { mark_page_free(&pg[i], mfn_add(mfn, i)); @@ -2652,9 +2650,48 @@ void __init free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, scrub_one_page(pg); } - /* In case initializing page of static memory, mark it PGC_static. */ pg[i].count_info |= PGC_static; } + + spin_unlock(&heap_lock); +} + +void free_domstatic_page(struct page_info *page) +{ + struct domain *d = page_get_owner(page); + bool drop_dom_ref, need_scrub; + + ASSERT_ALLOC_CONTEXT(); + + if ( likely(d) ) + { + /* NB. May recursively lock from relinquish_memory(). */ + spin_lock_recursive(&d->page_alloc_lock); + + arch_free_heap_page(d, page); + + /* + * Normally we expect a domain to clear pages before freeing them, + * if it cares about the secrecy of their contents. However, after + * a domain has died we assume responsibility for erasure. We do + * scrub regardless if option scrub_domheap is set. + */ + need_scrub = d->is_dying || scrub_debug || opt_scrub_domheap; + + drop_dom_ref = !domain_adjust_tot_pages(d, -1); + + spin_unlock_recursive(&d->page_alloc_lock); + } + else + { + drop_dom_ref = false; + need_scrub = true; + } + + free_staticmem_pages(page, 1, need_scrub); + + if ( drop_dom_ref ) + put_domain(d); } /* diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 3be754da92..f1a7d5c991 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -85,13 +85,12 @@ bool scrub_free_pages(void); } while ( false ) #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0) -#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); +void free_domstatic_page(struct page_info *page); int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_mfns, unsigned int memflags); -#endif /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( @@ -212,6 +211,10 @@ extern struct domain *dom_cow; #include +#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); From patchwork Thu Jul 7 09:22:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E555C43334 for ; Thu, 7 Jul 2022 09:23:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362802.593048 (Exim 4.92) (envelope-from ) id 1o9Nj9-0003ed-Tn; Thu, 07 Jul 2022 09:23:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362802.593048; Thu, 07 Jul 2022 09:23:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9Nj9-0003eW-QN; Thu, 07 Jul 2022 09:23:15 +0000 Received: by outflank-mailman (input) for mailman id 362802; Thu, 07 Jul 2022 09:23: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 1o9Nj8-0002ms-Qg for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:14 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6d2b33af-fdd6-11ec-bd2d-47488cf2e6aa; Thu, 07 Jul 2022 11:23:14 +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 DBBA7106F; Thu, 7 Jul 2022 02:23: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 4BDF13F792; Thu, 7 Jul 2022 02:23:10 -0700 (PDT) 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: 6d2b33af-fdd6-11ec-bd2d-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 v8 3/9] xen: update SUPPORT.md for static allocation Date: Thu, 7 Jul 2022 17:22:38 +0800 Message-Id: <20220707092244.485936-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 --- v8 changes: - no change --- v7 changes: - no change --- 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 70e98964cb..8e040d1c1e 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -286,6 +286,13 @@ to boot with memory < maxmem. Status, x86 HVM: Supported +### 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 Allow sharing of identical pages between guests From patchwork Thu Jul 7 09:22:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD174C43334 for ; Thu, 7 Jul 2022 09:23:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362804.593059 (Exim 4.92) (envelope-from ) id 1o9NjF-00043U-7E; Thu, 07 Jul 2022 09:23:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362804.593059; Thu, 07 Jul 2022 09:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9NjF-00043D-2T; Thu, 07 Jul 2022 09:23:21 +0000 Received: by outflank-mailman (input) for mailman id 362804; Thu, 07 Jul 2022 09:23:19 +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 1o9NjD-00032J-TR for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 6f575f0c-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23: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 E2DAD113E; Thu, 7 Jul 2022 02:23: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 10FB73F792; Thu, 7 Jul 2022 02:23:13 -0700 (PDT) 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: 6f575f0c-fdd6-11ec-924f-1f966e50362f 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 v8 4/9] xen: do not merge reserved pages in free_heap_pages() Date: Thu, 7 Jul 2022 17:22:39 +0800 Message-Id: <20220707092244.485936-5-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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_pages() 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 --- v8 changes: - no change --- v7 changes: - no change --- 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 9a80ca10fa..3260490688 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1475,6 +1475,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) != order) || (phys_to_nid(page_to_maddr(predecessor)) != node) ) break; @@ -1498,6 +1499,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) != order) || (phys_to_nid(page_to_maddr(successor)) != node) ) break; From patchwork Thu Jul 7 09:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCF05C43334 for ; Thu, 7 Jul 2022 09:23:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362807.593070 (Exim 4.92) (envelope-from ) id 1o9NjJ-0004T4-E5; Thu, 07 Jul 2022 09:23:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362807.593070; Thu, 07 Jul 2022 09:23:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9NjJ-0004Sv-Au; Thu, 07 Jul 2022 09:23:25 +0000 Received: by outflank-mailman (input) for mailman id 362807; Thu, 07 Jul 2022 09:23:24 +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 1o9NjH-00032J-Ve for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:24 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7243478b-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23:22 +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 BA6C91063; Thu, 7 Jul 2022 02:23:22 -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 1E64C3F792; Thu, 7 Jul 2022 02:23:17 -0700 (PDT) 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: 7243478b-fdd6-11ec-924f-1f966e50362f 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 v8 5/9] xen: add field "flags" to cover all internal CDF_XXX Date: Thu, 7 Jul 2022 17:22:40 +0800 Message-Id: <20220707092244.485936-6-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 --- v8 changes: - no change --- v7 changes: - no change --- 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 2f8eaab7b5..4722988ee7 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 - d->arch.directmap = flags & CDF_directmap; - /* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 ) goto fail; diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.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 -#define is_domain_direct_mapped(d) (d)->arch.directmap +#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) /* * Is the domain using the host memory layout? @@ -103,7 +103,6 @@ struct arch_domain void *tee; #endif - bool directmap; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/common/domain.c b/xen/common/domain.c index 3b1169d79b..875730df50 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 = domid; + /* Holding CDF_* internal flags. */ + d->cdf = flags; + /* Debug sanity. */ ASSERT(is_system_domain(d) ? config == NULL : config != NULL); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index b9515eb497..98e8001c89 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; }; static inline struct page_list_head *page_to_list( From patchwork Thu Jul 7 09:22:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7E3EC43334 for ; Thu, 7 Jul 2022 09:23:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362810.593081 (Exim 4.92) (envelope-from ) id 1o9NjN-0004z8-PT; Thu, 07 Jul 2022 09:23:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362810.593081; Thu, 07 Jul 2022 09:23:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9NjN-0004yw-LR; Thu, 07 Jul 2022 09:23:29 +0000 Received: by outflank-mailman (input) for mailman id 362810; Thu, 07 Jul 2022 09:23:28 +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 1o9NjM-00032J-EM for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:28 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7505a66f-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23:27 +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 680B21063; Thu, 7 Jul 2022 02:23:27 -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 EDCB73F792; Thu, 7 Jul 2022 02:23:22 -0700 (PDT) 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: 7505a66f-fdd6-11ec-924f-1f966e50362f 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 v8 6/9] xen/arm: introduce CDF_staticmem Date: Thu, 7 Jul 2022 17:22:41 +0800 Message-Id: <20220707092244.485936-7-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 In order to have an easy and quick way to find out whether this domain memory is statically configured, this commit introduces a new flag CDF_staticmem and a new helper is_domain_using_staticmem() to tell. Signed-off-by: Penny Zheng Acked-by: Jan Beulich Acked-by: Julien Grall --- v8 changes: - #ifdef-ary around is_domain_using_staticmem() is not needed anymore --- v7 changes: - IS_ENABLED(CONFIG_STATIC_MEMORY) would not be needed anymore --- 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 3fd1186b53..b76a84e8f5 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; + if ( dt_find_property(node, "xen,static-mem", NULL) ) + flags |= CDF_staticmem; + if ( dt_property_read_bool(node, "direct-map") ) { - if ( !IS_ENABLED(CONFIG_STATIC_MEMORY) || !dt_find_property(node, "xen,static-mem", NULL) ) + if ( !(flags & CDF_staticmem) ) panic("direct-map is not valid for domain %s without static allocation.\n", dt_node_name(node)); diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 628b14b086..2c8116afba 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -35,6 +35,14 @@ void arch_get_domain_info(const struct domain *d, /* Should domain memory be directly mapped? */ #define CDF_directmap (1U << 1) #endif +/* Is domain memory on static allocation? */ +#ifdef CONFIG_STATIC_MEMORY +#define CDF_staticmem (1U << 2) +#else +#define CDF_staticmem 0 +#endif + +#define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem) /* * Arch-specifics. From patchwork Thu Jul 7 09:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ABF8C43334 for ; Thu, 7 Jul 2022 09:23:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362816.593092 (Exim 4.92) (envelope-from ) id 1o9NjS-0005cD-8A; Thu, 07 Jul 2022 09:23:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362816.593092; Thu, 07 Jul 2022 09:23:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9NjS-0005bq-27; Thu, 07 Jul 2022 09:23:34 +0000 Received: by outflank-mailman (input) for mailman id 362816; Thu, 07 Jul 2022 09:23:32 +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 1o9NjQ-0002ms-Jv for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:32 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7799a294-fdd6-11ec-bd2d-47488cf2e6aa; Thu, 07 Jul 2022 11:23:31 +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 515631063; Thu, 7 Jul 2022 02:23:31 -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 9AD033F792; Thu, 7 Jul 2022 02:23:27 -0700 (PDT) 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: 7799a294-fdd6-11ec-bd2d-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 v8 7/9] xen/arm: unpopulate memory when domain is static Date: Thu, 7 Jul 2022 17:22:42 +0800 Message-Id: <20220707092244.485936-8-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 domain 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 --- 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 | 10 ++++++++-- xen/include/xen/mm.h | 6 ++++++ xen/include/xen/sched.h | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 875730df50..4043498ffa 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 + spin_lock_init(&d->node_affinity_lock); d->node_affinity = NODE_MASK_ALL; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 3260490688..b01272a59a 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2681,8 +2681,6 @@ void free_domstatic_page(struct page_info *page) need_scrub = d->is_dying || scrub_debug || opt_scrub_domheap; drop_dom_ref = !domain_adjust_tot_pages(d, -1); - - spin_unlock_recursive(&d->page_alloc_lock); } else { @@ -2692,6 +2690,14 @@ void free_domstatic_page(struct page_info *page) free_staticmem_pages(page, 1, need_scrub); + if ( likely(d) ) + { + /* Add page on the resv_page_list *after* it has been freed. */ + if ( !drop_dom_ref ) + put_static_page(d, page); + spin_unlock_recursive(&d->page_alloc_lock); + } + if ( drop_dom_ref ) put_domain(d); } diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index f1a7d5c991..07b8a45f1a 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -91,6 +91,12 @@ void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, void free_domstatic_page(struct page_info *page); int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_mfns, unsigned int memflags); +#ifdef CONFIG_STATIC_MEMORY +#define put_static_page(d, page) \ + page_list_add_tail((page), &(d)->resv_page_list) +#else +#define put_static_page(d, page) ((void)(d), (void)(page)) +#endif /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 98e8001c89..d4fbd3dea7 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_pages) */ 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 /* * This field should only be directly accessed by domain_adjust_tot_pages() From patchwork Thu Jul 7 09:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1258C43334 for ; Thu, 7 Jul 2022 09:32:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362864.593125 (Exim 4.92) (envelope-from ) id 1o9NrU-0001VG-Px; Thu, 07 Jul 2022 09:31:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362864.593125; Thu, 07 Jul 2022 09:31:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9NrU-0001V9-L7; Thu, 07 Jul 2022 09:31:52 +0000 Received: by outflank-mailman (input) for mailman id 362864; Thu, 07 Jul 2022 09:31:52 +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 1o9NjX-00032J-2a for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:39 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 79d1636a-fdd6-11ec-924f-1f966e50362f; Thu, 07 Jul 2022 11:23:35 +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 75F361063; Thu, 7 Jul 2022 02:23:35 -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 89C893F792; Thu, 7 Jul 2022 02:23:31 -0700 (PDT) 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: 79d1636a-fdd6-11ec-924f-1f966e50362f 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 v8 8/9] xen: introduce prepare_staticmem_pages Date: Thu, 7 Jul 2022 17:22:43 +0800 Message-Id: <20220707092244.485936-9-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 Acked-by: Julien Grall --- v8 changes: - no change --- v7 changes: - no change --- 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 b01272a59a..6112f6a3ed 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2702,26 +2702,13 @@ void free_domstatic_page(struct page_info *page) put_domain(d); } -/* - * 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 memflags) +static bool __init prepare_staticmem_pages(struct page_info *pg, + unsigned long nr_mfns, + unsigned int memflags) { bool need_tlbflush = false; uint32_t tlbflush_timestamp = 0; unsigned long i; - struct page_info *pg; - - ASSERT(nr_mfns); - for ( i = 0; i < nr_mfns; i++ ) - if ( !mfn_valid(mfn_add(smfn, i)) ) - return NULL; - - pg = mfn_to_page(smfn); spin_lock(&heap_lock); @@ -2732,7 +2719,7 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, { printk(XENLOG_ERR "pg[%lu] Static MFN %"PRI_mfn" c=%#lx t=%#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; } @@ -2756,6 +2743,38 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, if ( need_tlbflush ) filtered_flush_tlb_mask(tlbflush_timestamp); + return true; + + out_err: + while ( i-- ) + pg[i].count_info = 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 memflags) +{ + unsigned long i; + struct page_info *pg; + + ASSERT(nr_mfns); + for ( i = 0; i < nr_mfns; i++ ) + if ( !mfn_valid(mfn_add(smfn, i)) ) + return NULL; + + pg = 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. @@ -2764,14 +2783,6 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, flush_page_to_ram(mfn_x(smfn) + i, !(memflags & MEMF_no_icache_flush)); return pg; - - out_err: - while ( i-- ) - pg[i].count_info = PGC_static | PGC_state_free; - - spin_unlock(&heap_lock); - - return NULL; } /* From patchwork Thu Jul 7 09:22:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12909277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D443C433EF for ; Thu, 7 Jul 2022 09:23:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.362821.593102 (Exim 4.92) (envelope-from ) id 1o9Nja-0006RW-HB; Thu, 07 Jul 2022 09:23:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 362821.593102; Thu, 07 Jul 2022 09:23:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9Nja-0006RN-Dr; Thu, 07 Jul 2022 09:23:42 +0000 Received: by outflank-mailman (input) for mailman id 362821; Thu, 07 Jul 2022 09:23:40 +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 1o9NjY-0002ms-KR for xen-devel@lists.xenproject.org; Thu, 07 Jul 2022 09:23:40 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7c5996ea-fdd6-11ec-bd2d-47488cf2e6aa; Thu, 07 Jul 2022 11:23:39 +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 624DC1063; Thu, 7 Jul 2022 02:23:39 -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 AE2E53F792; Thu, 7 Jul 2022 02:23:35 -0700 (PDT) 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: 7c5996ea-fdd6-11ec-bd2d-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 v8 9/9] xen: retrieve reserved pages on populate_physmap Date: Thu, 7 Jul 2022 17:22:44 +0800 Message-Id: <20220707092244.485936-10-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707092244.485936-1-Penny.Zheng@arm.com> References: <20220707092244.485936-1-Penny.Zheng@arm.com> MIME-Version: 1.0 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 work. Signed-off-by: Penny Zheng --- v8 changes: - As concurrent free/allocate could modify the resv_page_list, we still need the lock --- v7 changes: - remove the lock, since we add the page to rsv_page_list after it has been totally freed. --- v6 changes: - drop the lock before returning --- v5 changes: - extract common codes for assigning pages into a helper assign_domstatic_pages - 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: - 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) mfn = _mfn(gpfn); } + else if ( is_domain_using_staticmem(d) ) + { + /* + * No easy way to guarantee the retrieved pages are contiguous, + * so forbid non-zero-order requests here. + */ + if ( a->extent_order != 0 ) + { + gdprintk(XENLOG_WARNING, + "Cannot allocate static order-%u pages for static %pd\n", + a->extent_order, d); + goto out; + } + + mfn = 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 = alloc_domheap_pages(d, a->extent_order, a->memflags); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 6112f6a3ed..390a9c002d 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2702,9 +2702,8 @@ void free_domstatic_page(struct page_info *page) put_domain(d); } -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 = false; uint32_t tlbflush_timestamp = 0; @@ -2785,21 +2784,9 @@ static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, return pg; } -/* - * 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 memflags) +static int assign_domstatic_pages(struct domain *d, struct page_info *pg, + unsigned int nr_mfns, unsigned int memflags) { - struct page_info *pg; - - ASSERT_ALLOC_CONTEXT(); - - pg = acquire_staticmem_pages(smfn, nr_mfns, memflags); - if ( !pg ) - return -ENOENT; - if ( !d || (memflags & (MEMF_no_owner | MEMF_no_refcount)) ) { /* @@ -2818,6 +2805,55 @@ int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, 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 memflags) +{ + struct page_info *pg; + + ASSERT_ALLOC_CONTEXT(); + + pg = 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; + + /* Acquire a page from reserved page list(resv_page_list). */ + spin_lock(&d->page_alloc_lock); + page = 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 /* diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 07b8a45f1a..559264b55d 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -97,6 +97,7 @@ int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_mfns, #else #define put_static_page(d, page) ((void)(d), (void)(page)) #endif +mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags); /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen(