From nobody Mon Feb 9 09:00:18 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=fail; 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=1595859786; cv=none; d=zohomail.com; s=zohoarc; b=W6Ut+NXgVHZQCwq4y6pWQLzdTn1gK/FlnERmG2/OL/tbAFBttSOO6ut310Kt9wKzuV9/6hdZ1ARqPR+/wFfGp+E+LaumeT6x0TlOlisL0AqupFg/v7UunBWWnl5ev+6Q2K7B6Je9Tq2eLDMkg422VVnKLpmXM4xyYde7FpGFSbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859786; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=SodIzhOZtWgd7aTAQdqyttar/iXLlUvG2VmsW7l5TFQ=; b=jBS++EV0RlrQW/ODZOnv1R3U6ynhIJnS/NcqSr+4V7MKPcwtuaqLlvQVZxzNJdiLEPfhNA0fke2az0crjbcjkpoyf9v8jxPiRCPR3O1ybK+7u2W5QPUrufd0nOHSIDY9ikSIbz0BpI9bKLl1BEfA16zMXvoTQEHRBZPqbV7kiKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1595859786406724.0225906618496; Mon, 27 Jul 2020 07:23:06 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041j-0007J5-2L; Mon, 27 Jul 2020 14:22:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041h-00075u-Ot for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:49 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 997d665c-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:28 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041L-0001Nz-Lu; Mon, 27 Jul 2020 14:22:27 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041L-0002w6-CO; Mon, 27 Jul 2020 14:22:27 +0000 X-Inumbo-ID: 997d665c-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=SodIzhOZtWgd7aTAQdqyttar/iXLlUvG2VmsW7l5TFQ=; b=0MxQzMgiFwdBg7PVvBvEoRmhDU E+yUT9+or+HWVwiyfn/D/ThmQHPkk8ENXofnZKH/Tfg7+dgXzV2n89oCGEDP/GnS7rUgoa2ouApYP qD2CqRZUMkoZNz3vX6myjYybY7nPLHpXECQsEwCrb2ihUbISBsHacV1vS0wDBa3No5Fg=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 07/15] x86_64/mm: switch to new APIs in paging_init Date: Mon, 27 Jul 2020 15:21:57 +0100 Message-Id: <9919850a82a7f189de2b5dcc62c55bc9d5337c4b.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 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 | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 243014a119..ebf21d505b 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -481,6 +481,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 @@ -493,22 +494,23 @@ 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(); + mfn_t l3mfn; + l3_pgentry_t *pl3t =3D alloc_map_clear_xen_pt(&l3mfn); =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(l3mfn, __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. @@ -591,12 +593,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)); } @@ -608,13 +612,16 @@ 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 ( (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; /* Allocate and map the compatibility mode machine-to-phys table. */ mpt_size =3D (mpt_size >> 1) + (1UL << (L2_PAGETABLE_SHIFT - 1)); if ( mpt_size > RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START ) --=20 2.16.6