From patchwork Wed Jul 20 05:46:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12923517 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 2C16CC433EF for ; Wed, 20 Jul 2022 05:47:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.371354.603256 (Exim 4.92) (envelope-from ) id 1oE2Y0-0000xF-9A; Wed, 20 Jul 2022 05:47:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 371354.603256; Wed, 20 Jul 2022 05:47:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oE2Y0-0000x6-4H; Wed, 20 Jul 2022 05:47:00 +0000 Received: by outflank-mailman (input) for mailman id 371354; Wed, 20 Jul 2022 05:46:58 +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 1oE2Xy-0006lV-SD for xen-devel@lists.xenproject.org; Wed, 20 Jul 2022 05:46:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 5e165305-07ef-11ed-bd2d-47488cf2e6aa; Wed, 20 Jul 2022 07:46: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 A154D1042; Tue, 19 Jul 2022 22:46: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 C18A13F70D; Tue, 19 Jul 2022 22:46:53 -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: 5e165305-07ef-11ed-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 , Julien Grall Subject: [PATCH v9 7/8] xen: introduce prepare_staticmem_pages Date: Wed, 20 Jul 2022 13:46:10 +0800 Message-Id: <20220720054611.2695787-8-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220720054611.2695787-1-Penny.Zheng@arm.com> References: <20220720054611.2695787-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 a568be55e3..9e150946f9 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2686,26 +2686,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); @@ -2716,7 +2703,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; } @@ -2740,6 +2727,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. @@ -2748,14 +2767,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; } /*