From nobody Tue Feb 10 00:59:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677130933709143.04406863652548; Wed, 22 Feb 2023 21:42:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.499874.771216 (Exim 4.92) (envelope-from ) id 1pV4MU-0002e8-RC; Thu, 23 Feb 2023 05:41:46 +0000 Received: by outflank-mailman (output) from mailman id 499874.771216; Thu, 23 Feb 2023 05:41:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pV4MU-0002cs-Jj; Thu, 23 Feb 2023 05:41:46 +0000 Received: by outflank-mailman (input) for mailman id 499874; Thu, 23 Feb 2023 05:41:45 +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 1pV4MT-0001BN-1U for xen-devel@lists.xenproject.org; Thu, 23 Feb 2023 05:41:45 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id c13553b7-b33c-11ed-88bb-e56d68cac8db; Thu, 23 Feb 2023 06:41:44 +0100 (CET) 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 8A74D1FB; Wed, 22 Feb 2023 21:42:26 -0800 (PST) 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 D7F443F587; Wed, 22 Feb 2023 21:41:40 -0800 (PST) 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: c13553b7-b33c-11ed-88bb-e56d68cac8db From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v2 7/8] xen/p2m: put reference for superpage Date: Thu, 23 Feb 2023 13:41:04 +0800 Message-Id: <20230223054105.2357217-8-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230223054105.2357217-1-Penny.Zheng@arm.com> References: <20230223054105.2357217-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1677130934283100014 Content-Type: text/plain; charset="utf-8" We are doing foreign memory mapping for static shared memory, and there is a great possibility that it could be super mapped. But today, p2m_put_l3_page could not handle superpages. This commits implements a new function p2m_put_superpage to handle superpag= es, specifically for helping put extra references for foreign superpages. Signed-off-by: Penny Zheng --- v1 -> v2: - new commit --- xen/arch/arm/p2m.c | 60 +++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 948f199d84..e8fa61fcbc 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -851,17 +851,9 @@ static int p2m_mem_access_radix_set(struct p2m_domain = *p2m, gfn_t gfn, return rc; } =20 -/* - * Put any references on the single 4K page referenced by pte. - * TODO: Handle superpages, for now we only take special references for le= af - * pages (specifically foreign ones, which can't be super mapped today). - */ -static void p2m_put_l3_page(const lpae_t pte) +/* Put any references on the single 4K page referenced by mfn. */ +static void p2m_put_l3_page(mfn_t mfn, unsigned type) { - mfn_t mfn =3D lpae_get_mfn(pte); - - ASSERT(p2m_is_valid(pte)); - /* * TODO: Handle other p2m types * @@ -869,16 +861,53 @@ static void p2m_put_l3_page(const lpae_t pte) * flush the TLBs if the page is reallocated before the end of * this loop. */ - if ( p2m_is_foreign(pte.p2m.type) ) + if ( p2m_is_foreign(type) ) { ASSERT(mfn_valid(mfn)); put_page(mfn_to_page(mfn)); } /* Detect the xenheap page and mark the stored GFN as invalid. */ - else if ( p2m_is_ram(pte.p2m.type) && is_xen_heap_mfn(mfn) ) + else if ( p2m_is_ram(type) && is_xen_heap_mfn(mfn) ) page_set_xenheap_gfn(mfn_to_page(mfn), INVALID_GFN); } =20 +/* Put any references on the superpage referenced by mfn. */ +static void p2m_put_superpage(mfn_t mfn, unsigned int next_level, unsigned= type) +{ + unsigned int i; + unsigned int level_order =3D XEN_PT_LEVEL_ORDER(next_level); + + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) + { + if ( next_level =3D=3D 3 ) + p2m_put_l3_page(mfn, type); + else + p2m_put_superpage(mfn, next_level + 1, type); + + mfn =3D mfn_add(mfn, 1 << level_order); + } +} + +/* Put any references on the page referenced by pte. */ +static void p2m_put_page(const lpae_t pte, unsigned int level) +{ + mfn_t mfn =3D lpae_get_mfn(pte); + + ASSERT(p2m_is_valid(pte)); + + /* + * We are either having a first level 1G superpage or a + * second level 2M superpage. + */ + if ( p2m_is_superpage(pte, level) ) + return p2m_put_superpage(mfn, level + 1, pte.p2m.type); + else + { + ASSERT(level =3D=3D 3); + return p2m_put_l3_page(mfn, pte.p2m.type); + } +} + /* Free lpae sub-tree behind an entry */ static void p2m_free_entry(struct p2m_domain *p2m, lpae_t entry, unsigned int level) @@ -907,9 +936,8 @@ static void p2m_free_entry(struct p2m_domain *p2m, #endif =20 p2m->stats.mappings[level]--; - /* Nothing to do if the entry is a super-page. */ - if ( level =3D=3D 3 ) - p2m_put_l3_page(entry); + p2m_put_page(entry, level); + return; } =20 @@ -1752,7 +1780,7 @@ void p2m_final_teardown(struct domain *d) * p2m_final_teardown() is called either after domain_relinquish_resou= rces() * where relinquish_p2m_mapping() has been called, or from failure pat= h of * domain_create()/arch_domain_create() where mappings that require - * p2m_put_l3_page() should never be created. For the latter case, als= o see + * p2m_put_page() should never be created. For the latter case, also s= ee * comment on top of the p2m_set_entry() for more info. */ =20 --=20 2.25.1