From nobody Mon Feb 9 05:42:53 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; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1617707201; cv=none; d=zohomail.com; s=zohoarc; b=ZZ34u/n//xxAt3dd1ibxNJLE0brewGLRnyjkPAYWmYKv1Y2yZkvCm7WH7SBN6/Y80dH3RVGqBwtE5NjPYHMLd1EKwcpDmOegO36njA0up7LCGnaaQubUhqeEtaxqNz2D17axbNte0pTaYNPCPREGQ8KgHa3L/VkOjBlQWFTOShI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617707201; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=DhjC1F6SkPBikln4izzyHzb4RHHtmb3wCYV7VN5lv1s=; b=ECxTKEn2odwWj23wz77KFbwv0YC3D9Q4+AQddA8h15sieYW8JSR8GaqGeCKcWpYVw4ysu+9ALI2EtdxykkebKCSZ0BIZAODiwWXUybkuK0VgjN4c5GmQolEz9Th4Hxkk6LGmpmxEDhSlwuVchmWhTN1ZeXujUEee79Pwm0G5Duo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161770720195789.1595196706628; Tue, 6 Apr 2021 04:06:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.105803.202404 (Exim 4.92) (envelope-from ) id 1lTjXO-0004Mo-HO; Tue, 06 Apr 2021 11:06:26 +0000 Received: by outflank-mailman (output) from mailman id 105803.202404; Tue, 06 Apr 2021 11:06:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXO-0004Ma-CS; Tue, 06 Apr 2021 11:06:26 +0000 Received: by outflank-mailman (input) for mailman id 105803; Tue, 06 Apr 2021 11:06:25 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXN-0004LF-1q for xen-devel@lists.xenproject.org; Tue, 06 Apr 2021 11:06:25 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lTjXM-00053H-Sy; Tue, 06 Apr 2021 11:06:24 +0000 Received: from 54-240-197-238.amazon.com ([54.240.197.238] helo=ua82172827c7b5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTjXM-0002qD-DN; Tue, 06 Apr 2021 11:06:24 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From; bh=DhjC1F6SkPBikln4izzyHzb4RHHtmb3wCYV7VN5lv1s=; b=L oYPM4nf88I0nCVJj3cm+4fIRf+TGjHZNssBs4sXOnAfcyRegK8KSave6kScWHyYtRwb1ZWi7seoIy kRtATa7odCnpyvQDSvy9dvf3Ijv47kh8ih2u1l40KTanMGUmB+AQhPnuwrBzvpF1QOaH6qh8W8/oI yDJcV7DTeA3N9wZ0=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Cc: jgrall@amazon.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v9 05/13] x86_64/mm: switch to new APIs in paging_init Date: Tue, 6 Apr 2021 12:05:53 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Map and unmap pages instead of relying on the direct map. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v9: - remove an unnecessary l3mfn variable. Changed in v8: - replace l3/2_ro_mpt_mfn with just mfn since their lifetimes do not overlap Changed in v7: - use the new alloc_map_clear_xen_pt() helper. - move the unmap of pl3t up a bit. - remove the unmaps in the nomem path. --- xen/arch/x86/x86_64/mm.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index c5a47df01bde..da239f097703 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -498,6 +498,7 @@ void __init paging_init(void) l3_pgentry_t *l3_ro_mpt; l2_pgentry_t *pl2e =3D NULL, *l2_ro_mpt =3D NULL; struct page_info *l1_pg; + mfn_t mfn; =20 /* * We setup the L3s for 1:1 mapping if host support memory hotplug @@ -510,22 +511,22 @@ void __init paging_init(void) if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & _PAGE_PRESENT) ) { - l3_pgentry_t *pl3t =3D alloc_xen_pagetable(); + l3_pgentry_t *pl3t =3D alloc_map_clear_xen_pt(&mfn); =20 if ( !pl3t ) goto nomem; - clear_page(pl3t); + UNMAP_DOMAIN_PAGE(pl3t); l4e_write(&idle_pg_table[l4_table_offset(va)], - l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW)); + l4e_from_mfn(mfn, __PAGE_HYPERVISOR_RW)); } } =20 /* Create user-accessible L2 directory to map the MPT for guests. */ - if ( (l3_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + l3_ro_mpt =3D alloc_map_clear_xen_pt(&mfn); + if ( !l3_ro_mpt ) goto nomem; - clear_page(l3_ro_mpt); l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)], - l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE= _USER)); + l4e_from_mfn(mfn, __PAGE_HYPERVISOR_RO | _PAGE_USER)); =20 /* * Allocate and map the machine-to-phys table. @@ -608,12 +609,14 @@ void __init paging_init(void) } if ( !((unsigned long)pl2e & ~PAGE_MASK) ) { - if ( (l2_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + + l2_ro_mpt =3D alloc_map_clear_xen_pt(&mfn); + if ( !l2_ro_mpt ) goto nomem; - clear_page(l2_ro_mpt); + l3e_write(&l3_ro_mpt[l3_table_offset(va)], - l3e_from_paddr(__pa(l2_ro_mpt), - __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l3e_from_mfn(mfn, __PAGE_HYPERVISOR_RO | _PAGE_USER)= ); pl2e =3D l2_ro_mpt; ASSERT(!l2_table_offset(va)); } @@ -625,15 +628,18 @@ void __init paging_init(void) } #undef CNT #undef MFN + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + UNMAP_DOMAIN_PAGE(l3_ro_mpt); =20 /* Create user-accessible L2 directory to map the MPT for compat guest= s. */ if ( opt_pv32 ) { - if ( (l2_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(mfn, INVALID_MFN) ) goto nomem; - compat_idle_pg_table_l2 =3D l2_ro_mpt; - clear_page(l2_ro_mpt); - pl2e =3D l2_ro_mpt; + compat_idle_pg_table_l2 =3D map_domain_page_global(mfn); + clear_page(compat_idle_pg_table_l2); + pl2e =3D compat_idle_pg_table_l2; =20 /* Allocate and map the compatibility mode machine-to-phys table. = */ mpt_size =3D (mpt_size >> 1) + (1UL << (L2_PAGETABLE_SHIFT - 1)); --=20 2.23.3