From nobody Mon Feb 9 09:43:12 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=1619014575; cv=none; d=zohomail.com; s=zohoarc; b=IWNHYnbV+r/x1NMJFhomihRrLs7g97GzdBUperXJCLe6lGU5Wc29r5fe/3bCab0FkgSEx23hQE6evTEQ0OclT7rBYBmQMWPUI+PTYjigoXqN23KJOsgeCNtkSVEtweoTzhJ9250mtZtEBU1rEfHV84OQVwpimDsuIQqpyBuIBB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619014575; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=zIa4KSc9eY5+u86tvfAqgOLSwC2kF+yKnqDbni3id/E=; b=g9KHM6R71i8Ao0Pp2Db2GDMtyBZf5t546I7/Pp+3FTssGpROWolfOqNLRUHfkrDP3C7pO1OqD96BkPZX9WJkS416JXKW0gHNy30/1gGtreTjBb0OZ+X5PqgI+AnLgvNbnr+V6fEK1ZMBCKPhTMonXmMiXcUzV7yM5Mehp6zbKS4= 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 1619014575565855.2269671511932; Wed, 21 Apr 2021 07:16:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.114547.218371 (Exim 4.92) (envelope-from ) id 1lZDe5-00080t-UP; Wed, 21 Apr 2021 14:16:01 +0000 Received: by outflank-mailman (output) from mailman id 114547.218371; Wed, 21 Apr 2021 14:16: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 1lZDe5-00080Z-OR; Wed, 21 Apr 2021 14:16:01 +0000 Received: by outflank-mailman (input) for mailman id 114547; Wed, 21 Apr 2021 14:16:00 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZDe3-0007xD-SZ for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:15:59 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZDe3-0000xp-N9; Wed, 21 Apr 2021 14:15:59 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] 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 1lZDe3-00045m-Bf; Wed, 21 Apr 2021 14:15:59 +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=zIa4KSc9eY5+u86tvfAqgOLSwC2kF+yKnqDbni3id/E=; b=6 i+Q35aMSdQV28yzdnck8dK2x4nVtsi9j1PjkoCBoLcv/+MoejyIrL1COWP4e5TvoJ3OCG4iQouyDe /wVhQUJjyeXOa9Es8BAQVa0cMdQq5ZQk3TzcPsagugA5aDa7aXplFCEsasgg9M7hOCDk+ztJrZxXi cqapSbu2UmWgwrx4=; 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 v10 05/13] x86_64/mm: switch to new APIs in paging_init Date: Wed, 21 Apr 2021 15:15:33 +0100 Message-Id: <037bc533d8cc88c73825a9613b4b0e7209cecb11.1619014052.git.hongyxia@amazon.com> 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 59049bdf8e83..3e40d529bbf3 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_mapped_pagetable(&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_mapped_pagetable(&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_mapped_pagetable(&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.4