From nobody Thu May 2 09:18:44 2024 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=1587737382; cv=none; d=zohomail.com; s=zohoarc; b=apa3BrEw5Xz0AxUXrQ7mTWSN4u/GFxNdAn3AWt5bsXQ4rHG4eIICzdy2nKvo1K36Fs/rQ6eIjyFiI9xitGhi71nBEScA+R86J5FUj+t8wpsDsajXQwgd8vGtehldGhc7GA8MUFYyDiYlUAr4gnb/a3s6PmviLJERk8ASSTM9Huo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737382; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=wuKSH+etKo7Jo0+ZezG3H1XK7TumB7Bc+ci7lGz0PLk=; b=E7f4LIVjQSHSm3tdSfqx/8VF8j6sYgL5hliSeaW7qvr+Xy3KNZvTur5MdVJ2maNt/wSkhYQZsES2IZKqhWMKMhytz9RcPLdw6G0BAzhWKDUkMYOAoH8i1UUN2tH4Je595kxrBMWUptmt0lEh8aCn1HNm8qXrRjLD41igKuk8nKg= 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 1587737382651976.1714805629302; Fri, 24 Apr 2020 07:09:42 -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 1jRz1B-0002pp-2D; Fri, 24 Apr 2020 14:09:25 +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 1jRz1A-0002pb-LJ for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:24 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 310015c6-8635-11ea-94b0-12813bfff9fa; Fri, 24 Apr 2020 14:09:20 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz15-0001gC-Uk; Fri, 24 Apr 2020 14:09:19 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz15-0001fN-Iw; Fri, 24 Apr 2020 14:09:19 +0000 X-Inumbo-ID: 310015c6-8635-11ea-94b0-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=wuKSH+etKo7Jo0+ZezG3H1XK7TumB7Bc+ci7lGz0PLk=; b=bNL3GNbndE1LgY8gb7b+rytX5a CZqOmiD5+qjoarwPnP/ejsBi+JEsFbuD+biyMOifNBtKcx4NNw8eV9tJN6Svhw+1Ygk2H2DIkM4y4 OfL1z4WErTBNxP4vd6kXpJ/tU8NrWFClBVYpWX85EGxVFiD9I/4abtRckdK8yyHG6Gms=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 01/15] x86/mm: map_pages_to_xen would better have one exit path Date: Fri, 24 Apr 2020 15:08:52 +0100 Message-Id: <65a239b5c283890f83d2e637dbb6d01a673e586b.1587735799.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 , julien@xen.org, 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 We will soon rewrite the function to handle dynamically mapping and unmapping of page tables. Since dynamic mappings may map and unmap pages in different iterations of the while loop, we need to lift pl3e out of the loop. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- Changed since v4: - drop the end_of_loop goto label. Changed since v3: - remove asserts on rc since rc never gets changed to anything else. - reword commit message. --- xen/arch/x86/mm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 355c50ff91..0d7f1f1265 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5073,9 +5073,11 @@ int map_pages_to_xen( unsigned int flags) { bool locking =3D system_state > SYS_STATE_boot; + l3_pgentry_t *pl3e, ol3e; l2_pgentry_t *pl2e, ol2e; l1_pgentry_t *pl1e, ol1e; unsigned int i; + int rc =3D -ENOMEM; =20 #define flush_flags(oldf) do { \ unsigned int o_ =3D (oldf); \ @@ -5093,10 +5095,11 @@ int map_pages_to_xen( =20 while ( nr_mfns !=3D 0 ) { - l3_pgentry_t ol3e, *pl3e =3D virt_to_xen_l3e(virt); + pl3e =3D virt_to_xen_l3e(virt); =20 if ( !pl3e ) - return -ENOMEM; + goto out; + ol3e =3D *pl3e; =20 if ( cpu_has_page1gb && @@ -5186,7 +5189,7 @@ int map_pages_to_xen( =20 l2t =3D alloc_xen_pagetable(); if ( l2t =3D=3D NULL ) - return -ENOMEM; + goto out; =20 for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, @@ -5215,7 +5218,7 @@ int map_pages_to_xen( =20 pl2e =3D virt_to_xen_l2e(virt); if ( !pl2e ) - return -ENOMEM; + goto out; =20 if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & ((1u << PAGETABLE_ORDER) - 1)) =3D=3D 0) && @@ -5259,7 +5262,7 @@ int map_pages_to_xen( { pl1e =3D virt_to_xen_l1e(virt); if ( pl1e =3D=3D NULL ) - return -ENOMEM; + goto out; } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { @@ -5287,7 +5290,7 @@ int map_pages_to_xen( =20 l1t =3D alloc_xen_pagetable(); if ( l1t =3D=3D NULL ) - return -ENOMEM; + goto out; =20 for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], @@ -5433,7 +5436,10 @@ int map_pages_to_xen( =20 #undef flush_flags =20 - return 0; + rc =3D 0; + + out: + return rc; } =20 int populate_pt_range(unsigned long virt, unsigned long nr_mfns) --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737381; cv=none; d=zohomail.com; s=zohoarc; b=UO1JYrCCpeYolry6AC19MRdhSaUu4BMaUB7XBchrCQqOmYx1Q8STZv+5D3QxtonDLxkpJoYVx3+riQgSWtBhncHcPRugGEWhiViEHWO/1U0BN1gG/ZrFxHkG2fThFY3k/HtO41V6TjYVZCgbcg0XWV/oCAQRffDKqlgMNuS7E6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737381; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=oqERgF2yFHKDhOM0YC1cTIHrEB14UTlYTe0Bzj5cU0s=; b=RNMCPdxXeodX2a+eE9HhhiHRavdMddOKa4QDXrIJgWWyEyflzENaaNrl2k3iT6WWWAEdG+51KdTYH6oOljyt6DbRgqrEIHFk4jPRwrhZRBKAeSX9pH2LNBL/YL7ArSWJAPR9HnK8r6ZHvmPeZ+StxTw0MQLNuHOJLFIox+bFzRc= 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 1587737381081976.8226807870245; Fri, 24 Apr 2020 07:09:41 -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 1jRz19-0002p7-Pd; Fri, 24 Apr 2020 14:09:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz18-0002ou-EI for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 31fde20a-8635-11ea-b58d-bc764e2007e4; Fri, 24 Apr 2020 14:09:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz17-0001gK-EM; Fri, 24 Apr 2020 14:09:21 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz17-0001fN-2g; Fri, 24 Apr 2020 14:09:21 +0000 X-Inumbo-ID: 31fde20a-8635-11ea-b58d-bc764e2007e4 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=oqERgF2yFHKDhOM0YC1cTIHrEB14UTlYTe0Bzj5cU0s=; b=LS8ovfLB5o3NZfXfXBXoW4MvI2 kEBuCOSMUXExf+8V7iVXqmpcK+KU0XX8sSif8H0yHKsJcWWvnEGDEgqalbzMfNffHo2ANrUrA6muF CmOCTuTAUpK9RWbTxmLp492RYgvnBe5658SD/7lReX8pnZJnOnvpFhKeYsxAiPOm5+MI=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 02/15] x86/mm: make sure there is one exit path for modify_xen_mappings Date: Fri, 24 Apr 2020 15:08:53 +0100 Message-Id: <18200ef0e71dae402fbca394f653fb57c62a2cb9.1587735799.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 , julien@xen.org, 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 We will soon need to handle dynamically mapping / unmapping page tables in the said function. Since dynamic mappings may map and unmap pl3e in different iterations, lift pl3e out of the loop. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- Changed since v4: - drop the end_of_loop goto label. Changed since v3: - remove asserts on rc since it never gets changed to anything else. --- xen/arch/x86/mm.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 0d7f1f1265..13a34a8d57 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5462,10 +5462,12 @@ int populate_pt_range(unsigned long virt, unsigned = long nr_mfns) int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { bool locking =3D system_state > SYS_STATE_boot; + l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; l1_pgentry_t *pl1e; unsigned int i; unsigned long v =3D s; + int rc =3D -ENOMEM; =20 /* Set of valid PTE bits which may be altered. */ #define FLAGS_MASK (_PAGE_NX|_PAGE_RW|_PAGE_PRESENT) @@ -5476,7 +5478,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) =20 while ( v < e ) { - l3_pgentry_t *pl3e =3D virt_to_xen_l3e(v); + pl3e =3D virt_to_xen_l3e(v); =20 if ( !pl3e || !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { @@ -5509,7 +5511,8 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) /* PAGE1GB: shatter the superpage and fall through. */ l2t =3D alloc_xen_pagetable(); if ( !l2t ) - return -ENOMEM; + goto out; + for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + @@ -5566,7 +5569,8 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) /* PSE: shatter the superpage and try again. */ l1t =3D alloc_xen_pagetable(); if ( !l1t ) - return -ENOMEM; + goto out; + for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, @@ -5699,7 +5703,10 @@ int modify_xen_mappings(unsigned long s, unsigned lo= ng e, unsigned int nf) flush_area(NULL, FLUSH_TLB_GLOBAL); =20 #undef FLAGS_MASK - return 0; + rc =3D 0; + + out: + return rc; } =20 #undef flush_area --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737380; cv=none; d=zohomail.com; s=zohoarc; b=ZSK7Exrg812e3MCPQo3VMb54y8MvKJtGBoRBgVXjugIWSNrQ0taGcfP86Y8uyZdey9fLMhgVdLjJGm5yzIHVOp6mjQJk2a4M/vYA/EW1NEDlyUgtMKWGn9hHGJuQaqa1Lkv78e8JNGEwxt1x4ull3875crZGghbeGugPx3lLF7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737380; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ni2X3IEF9bCOanK+t7F3wzlp0i4MbnPB9Hxj61sNivc=; b=G0mJ4jGqwt7HTVi+k6RyEm+dhyNEVD9x1lxG0qbRzLy+9cqjKKlGLeVfyqTm75SisGO27PbDXQv7ho0a1RQfUr/uuWrwwqebLDgvJCJOuWhC8gOOh6PQfVFgtG1vxrdQAIH+f1jRp+hYSyz88lf8uupTMh4ipGDuGDEDz0t0dTE= 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 1587737380561440.7299718884134; Fri, 24 Apr 2020 07:09:40 -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 1jRz1E-0002rf-CO; Fri, 24 Apr 2020 14:09:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1D-0002rK-EY for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 331297e4-8635-11ea-b4f4-bc764e2007e4; Fri, 24 Apr 2020 14:09:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz19-0001gr-F8; Fri, 24 Apr 2020 14:09:23 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz18-0001fN-Vw; Fri, 24 Apr 2020 14:09:23 +0000 X-Inumbo-ID: 331297e4-8635-11ea-b4f4-bc764e2007e4 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=ni2X3IEF9bCOanK+t7F3wzlp0i4MbnPB9Hxj61sNivc=; b=d+Fp4d1aL9GH1b3g4j4+rxL4ta TwDbaZHa37u7Cvuv2wcy8UtKJJMDFugu8NFHLAxy/k9CU0SD3KOBeWLqGIouWz6vVQ5eTWGt2fPne s/JpPeUmH+d6fXquyu+urRL0yPmmt5TamkuRdRisSkt7w60t+Vt369HR3slwOVysMg3g=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 03/15] x86/mm: rewrite virt_to_xen_l*e Date: Fri, 24 Apr 2020 15:08:54 +0100 Message-Id: <949d2dc54fd7d3230db6a0934d73668a9999eb1a.1587735799.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: Stefano Stabellini , julien@xen.org, Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , 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 Rewrite those functions to use the new APIs. Modify its callers to unmap the pointer returned. Note that the change of virt_to_xen_l1e() also requires vmap_to_mfn() to unmap the page, which requires domain_page.h header in vmap. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/domain_page.c | 11 +++-- xen/arch/x86/mm.c | 85 +++++++++++++++++++++++++++----------- xen/common/vmap.c | 1 + xen/include/asm-x86/page.h | 8 +++- 4 files changed, 76 insertions(+), 29 deletions(-) diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index dd32712d2f..3a244bb500 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -333,21 +333,24 @@ void unmap_domain_page_global(const void *ptr) mfn_t domain_page_map_to_mfn(const void *ptr) { unsigned long va =3D (unsigned long)ptr; - const l1_pgentry_t *pl1e; + l1_pgentry_t l1e; =20 if ( va >=3D DIRECTMAP_VIRT_START ) return _mfn(virt_to_mfn(ptr)); =20 if ( va >=3D VMAP_VIRT_START && va < VMAP_VIRT_END ) { - pl1e =3D virt_to_xen_l1e(va); + const l1_pgentry_t *pl1e =3D virt_to_xen_l1e(va); + BUG_ON(!pl1e); + l1e =3D *pl1e; + unmap_domain_page(pl1e); } else { ASSERT(va >=3D MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END); - pl1e =3D &__linear_l1_table[l1_linear_offset(va)]; + l1e =3D __linear_l1_table[l1_linear_offset(va)]; } =20 - return l1e_get_mfn(*pl1e); + return l1e_get_mfn(l1e); } diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 13a34a8d57..3328d887c4 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4955,6 +4955,10 @@ void free_xen_pagetable_new(mfn_t mfn) =20 static DEFINE_SPINLOCK(map_pgdir_lock); =20 +/* + * For virt_to_xen_lXe() functions, they take a virtual address and return= a + * pointer to Xen's LX entry. Caller needs to unmap the pointer. + */ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) { l4_pgentry_t *pl4e; @@ -4963,33 +4967,36 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long = v) if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { bool locking =3D system_state > SYS_STATE_boot; - l3_pgentry_t *l3t =3D alloc_xen_pagetable(); + l3_pgentry_t *l3t; + mfn_t l3mfn =3D alloc_xen_pagetable_new(); =20 - if ( !l3t ) + if ( mfn_eq(l3mfn, INVALID_MFN) ) return NULL; + l3t =3D map_domain_page(l3mfn); clear_page(l3t); + UNMAP_DOMAIN_PAGE(l3t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { - l4_pgentry_t l4e =3D l4e_from_paddr(__pa(l3t), __PAGE_HYPERVIS= OR); + l4_pgentry_t l4e =3D l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); =20 l4e_write(pl4e, l4e); efi_update_l4_pgtable(l4_table_offset(v), l4e); - l3t =3D NULL; + l3mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( l3t ) - free_xen_pagetable(l3t); + free_xen_pagetable_new(l3mfn); } =20 - return l4e_to_l3e(*pl4e) + l3_table_offset(v); + return map_l3t_from_l4e(*pl4e) + l3_table_offset(v); } =20 static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) { l3_pgentry_t *pl3e; + l2_pgentry_t *pl2e; =20 pl3e =3D virt_to_xen_l3e(v); if ( !pl3e ) @@ -4998,31 +5005,40 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long = v) if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { bool locking =3D system_state > SYS_STATE_boot; - l2_pgentry_t *l2t =3D alloc_xen_pagetable(); + l2_pgentry_t *l2t; + mfn_t l2mfn =3D alloc_xen_pagetable_new(); =20 - if ( !l2t ) + if ( mfn_eq(l2mfn, INVALID_MFN) ) + { + UNMAP_DOMAIN_PAGE(pl3e); return NULL; + } + l2t =3D map_domain_page(l2mfn); clear_page(l2t); + UNMAP_DOMAIN_PAGE(l2t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - l3e_write(pl3e, l3e_from_paddr(__pa(l2t), __PAGE_HYPERVISOR)); - l2t =3D NULL; + l3e_write(pl3e, l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR)); + l2mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( l2t ) - free_xen_pagetable(l2t); + free_xen_pagetable_new(l2mfn); } =20 BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); - return l3e_to_l2e(*pl3e) + l2_table_offset(v); + pl2e =3D map_l2t_from_l3e(*pl3e) + l2_table_offset(v); + unmap_domain_page(pl3e); + + return pl2e; } =20 l1_pgentry_t *virt_to_xen_l1e(unsigned long v) { l2_pgentry_t *pl2e; + l1_pgentry_t *pl1e; =20 pl2e =3D virt_to_xen_l2e(v); if ( !pl2e ) @@ -5031,26 +5047,34 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { bool locking =3D system_state > SYS_STATE_boot; - l1_pgentry_t *l1t =3D alloc_xen_pagetable(); + l1_pgentry_t *l1t; + mfn_t l1mfn =3D alloc_xen_pagetable_new(); =20 - if ( !l1t ) + if ( mfn_eq(l1mfn, INVALID_MFN) ) + { + UNMAP_DOMAIN_PAGE(pl2e); return NULL; + } + l1t =3D map_domain_page(l1mfn); clear_page(l1t); + UNMAP_DOMAIN_PAGE(l1t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - l2e_write(pl2e, l2e_from_paddr(__pa(l1t), __PAGE_HYPERVISOR)); - l1t =3D NULL; + l2e_write(pl2e, l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR)); + l1mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( l1t ) - free_xen_pagetable(l1t); + free_xen_pagetable_new(l1mfn); } =20 BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE); - return l2e_to_l1e(*pl2e) + l1_table_offset(v); + pl1e =3D map_l1t_from_l2e(*pl2e) + l1_table_offset(v); + unmap_domain_page(pl2e); + + return pl1e; } =20 /* Convert to from superpage-mapping flags for map_pages_to_xen(). */ @@ -5073,8 +5097,8 @@ int map_pages_to_xen( unsigned int flags) { bool locking =3D system_state > SYS_STATE_boot; - l3_pgentry_t *pl3e, ol3e; - l2_pgentry_t *pl2e, ol2e; + l3_pgentry_t *pl3e =3D NULL, ol3e; + l2_pgentry_t *pl2e =3D NULL, ol2e; l1_pgentry_t *pl1e, ol1e; unsigned int i; int rc =3D -ENOMEM; @@ -5095,6 +5119,10 @@ int map_pages_to_xen( =20 while ( nr_mfns !=3D 0 ) { + /* Clean up mappings mapped in the previous iteration. */ + UNMAP_DOMAIN_PAGE(pl3e); + UNMAP_DOMAIN_PAGE(pl2e); + pl3e =3D virt_to_xen_l3e(virt); =20 if ( !pl3e ) @@ -5260,9 +5288,12 @@ int map_pages_to_xen( /* Normal page mapping. */ if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { + /* This forces the mapping to be populated. */ pl1e =3D virt_to_xen_l1e(virt); if ( pl1e =3D=3D NULL ) goto out; + + UNMAP_DOMAIN_PAGE(pl1e); } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { @@ -5439,6 +5470,8 @@ int map_pages_to_xen( rc =3D 0; =20 out: + UNMAP_DOMAIN_PAGE(pl2e); + UNMAP_DOMAIN_PAGE(pl3e); return rc; } =20 @@ -5462,7 +5495,7 @@ int populate_pt_range(unsigned long virt, unsigned lo= ng nr_mfns) int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { bool locking =3D system_state > SYS_STATE_boot; - l3_pgentry_t *pl3e; + l3_pgentry_t *pl3e =3D NULL; l2_pgentry_t *pl2e; l1_pgentry_t *pl1e; unsigned int i; @@ -5478,6 +5511,9 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) =20 while ( v < e ) { + /* Clean up mappings mapped in the previous iteration. */ + UNMAP_DOMAIN_PAGE(pl3e); + pl3e =3D virt_to_xen_l3e(v); =20 if ( !pl3e || !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) @@ -5706,6 +5742,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) rc =3D 0; =20 out: + UNMAP_DOMAIN_PAGE(pl3e); return rc; } =20 diff --git a/xen/common/vmap.c b/xen/common/vmap.c index faebc1ddf1..9964ab2096 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -1,6 +1,7 @@ #ifdef VMAP_VIRT_START #include #include +#include #include #include #include diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 5acf3d3d5a..8f711f4992 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -291,7 +291,13 @@ void copy_page_sse2(void *, const void *); #define pfn_to_paddr(pfn) __pfn_to_paddr(pfn) #define paddr_to_pfn(pa) __paddr_to_pfn(pa) #define paddr_to_pdx(pa) pfn_to_pdx(paddr_to_pfn(pa)) -#define vmap_to_mfn(va) _mfn(l1e_get_pfn(*virt_to_xen_l1e((unsigned lo= ng)(va)))) + +#define vmap_to_mfn(va) ({ = \ + const l1_pgentry_t *pl1e_ =3D virt_to_xen_l1e((unsigned long)(va))= ; \ + unsigned long pfn_ =3D l1e_get_pfn(*pl1e_); = \ + unmap_domain_page(pl1e_); = \ + _mfn(pfn_); }) + #define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va)) =20 #endif /* !defined(__ASSEMBLY__) */ --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737390; cv=none; d=zohomail.com; s=zohoarc; b=HmoKkDM9iZt0vGVNuLtvW6LV/yOeMasSnkSLHycTZPI76p2/DIprbW0pqiwAfDksaJ33uMgxxyTQVfzJAnRkix6eYbGMfk+D2lTujktwW3MtFRZ7647oV8R0I7gbEWCmgtvYhcoCmxIrv+fRYo5tQhPINto5JfyOshtiDr/wHFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737390; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=BvaGecZYLh8fva2MaUDmevLZoDzUJ3x7rJ02UJL3eh0=; b=dCaY5sdn7sFDU7Q79Zlnzi6TYZsGTOtqiT3KWq+FIq9zjCk7GskjFaS/wzrtCMaBgXBsLfs0/NsncIrrZeAsycKU2Jxoq6DDeXt/C2PkZuUOAWQHhrsv0pCsUMQP8AV5ySouw7tF22FoxjUBb083WcNkt6Ve6P5jxJ2UZS7AMG0= 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 1587737390972242.29437622412615; Fri, 24 Apr 2020 07:09:50 -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 1jRz1G-0002sh-LW; Fri, 24 Apr 2020 14:09:30 +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 1jRz1F-0002sM-LJ for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:29 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 342a1012-8635-11ea-94b0-12813bfff9fa; Fri, 24 Apr 2020 14:09:25 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1B-0001gx-30; Fri, 24 Apr 2020 14:09:25 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1A-0001fN-Ko; Fri, 24 Apr 2020 14:09:25 +0000 X-Inumbo-ID: 342a1012-8635-11ea-94b0-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=BvaGecZYLh8fva2MaUDmevLZoDzUJ3x7rJ02UJL3eh0=; b=yZOmjzxk54E+5o6w8mGOwIXU2N gQZytQ/IR8lt2CcNimBMkA+YEIYfQq4BS1oDOdmK+Wg5weRqaXP00KF7CvmOL3GRnwTQjhamqeZTQ rs2EjW58S+LDHSP0US51B+VqPokHcvIvMeGPMvsPq4Fm/xbnDNoLs/38HkDFaJztJmak=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 04/15] x86/mm: switch to new APIs in map_pages_to_xen Date: Fri, 24 Apr 2020 15:08:55 +0100 Message-Id: <8ad392497076eb440cd2d620eefda0f0199ddaea.1587735799.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 , julien@xen.org, 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 Page tables allocated in that function should be mapped and unmapped now. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/mm.c | 60 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 3328d887c4..2c14cdd83a 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5151,7 +5151,7 @@ int map_pages_to_xen( } else { - l2_pgentry_t *l2t =3D l3e_to_l2e(ol3e); + l2_pgentry_t *l2t =3D map_l2t_from_l3e(ol3e); =20 for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) { @@ -5163,10 +5163,11 @@ int map_pages_to_xen( else { unsigned int j; - const l1_pgentry_t *l1t =3D l2e_to_l1e(ol2e); + const l1_pgentry_t *l1t =3D map_l1t_from_l2e(o= l2e); =20 for ( j =3D 0; j < L1_PAGETABLE_ENTRIES; j++ ) flush_flags(l1e_get_flags(l1t[j])); + unmap_domain_page(l1t); } } flush_area(virt, flush_flags); @@ -5175,9 +5176,10 @@ int map_pages_to_xen( ol2e =3D l2t[i]; if ( (l2e_get_flags(ol2e) & _PAGE_PRESENT) && !(l2e_get_flags(ol2e) & _PAGE_PSE) ) - free_xen_pagetable(l2e_to_l1e(ol2e)); + free_xen_pagetable_new(l2e_get_mfn(ol2e)); } - free_xen_pagetable(l2t); + unmap_domain_page(l2t); + free_xen_pagetable_new(l3e_get_mfn(ol3e)); } } =20 @@ -5194,6 +5196,7 @@ int map_pages_to_xen( unsigned int flush_flags =3D FLUSH_TLB | FLUSH_ORDER(2 * PAGETABLE_ORDER); l2_pgentry_t *l2t; + mfn_t l2mfn; =20 /* Skip this PTE if there is no change. */ if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES * @@ -5215,15 +5218,17 @@ int map_pages_to_xen( continue; } =20 - l2t =3D alloc_xen_pagetable(); - if ( l2t =3D=3D NULL ) + l2mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; =20 + l2t =3D map_domain_page(l2mfn); for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(ol3e) + (i << PAGETABLE_ORDER), l3e_get_flags(ol3e))); + UNMAP_DOMAIN_PAGE(l2t); =20 if ( l3e_get_flags(ol3e) & _PAGE_GLOBAL ) flush_flags |=3D FLUSH_TLB_GLOBAL; @@ -5233,15 +5238,15 @@ int map_pages_to_xen( if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) && (l3e_get_flags(*pl3e) & _PAGE_PSE) ) { - l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t), - __PAGE_HYPERVISOR)); - l2t =3D NULL; + l3e_write_atomic(pl3e, + l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR)); + l2mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); - if ( l2t ) - free_xen_pagetable(l2t); + + free_xen_pagetable_new(l2mfn); } =20 pl2e =3D virt_to_xen_l2e(virt); @@ -5269,12 +5274,13 @@ int map_pages_to_xen( } else { - l1_pgentry_t *l1t =3D l2e_to_l1e(ol2e); + l1_pgentry_t *l1t =3D map_l1t_from_l2e(ol2e); =20 for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) flush_flags(l1e_get_flags(l1t[i])); flush_area(virt, flush_flags); - free_xen_pagetable(l1t); + unmap_domain_page(l1t); + free_xen_pagetable_new(l2e_get_mfn(ol2e)); } } =20 @@ -5300,6 +5306,7 @@ int map_pages_to_xen( unsigned int flush_flags =3D FLUSH_TLB | FLUSH_ORDER(PAGETABLE_ORDER); l1_pgentry_t *l1t; + mfn_t l1mfn; =20 /* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) + @@ -5319,14 +5326,16 @@ int map_pages_to_xen( goto check_l3; } =20 - l1t =3D alloc_xen_pagetable(); - if ( l1t =3D=3D NULL ) + l1mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; =20 + l1t =3D map_domain_page(l1mfn); for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, lNf_to_l1f(l2e_get_flags(*pl2e)= ))); + UNMAP_DOMAIN_PAGE(l1t); =20 if ( l2e_get_flags(*pl2e) & _PAGE_GLOBAL ) flush_flags |=3D FLUSH_TLB_GLOBAL; @@ -5336,20 +5345,21 @@ int map_pages_to_xen( if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && (l2e_get_flags(*pl2e) & _PAGE_PSE) ) { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), + l2e_write_atomic(pl2e, l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR)= ); - l1t =3D NULL; + l1mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); - if ( l1t ) - free_xen_pagetable(l1t); + + free_xen_pagetable_new(l1mfn); } =20 - pl1e =3D l2e_to_l1e(*pl2e) + l1_table_offset(virt); + pl1e =3D map_l1t_from_l2e(*pl2e) + l1_table_offset(virt); ol1e =3D *pl1e; l1e_write_atomic(pl1e, l1e_from_mfn(mfn, flags)); + UNMAP_DOMAIN_PAGE(pl1e); if ( (l1e_get_flags(ol1e) & _PAGE_PRESENT) ) { unsigned int flush_flags =3D FLUSH_TLB | FLUSH_ORDER(0); @@ -5393,12 +5403,13 @@ int map_pages_to_xen( goto check_l3; } =20 - l1t =3D l2e_to_l1e(ol2e); + l1t =3D map_l1t_from_l2e(ol2e); base_mfn =3D l1e_get_pfn(l1t[0]) & ~(L1_PAGETABLE_ENTRIES = - 1); for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) if ( (l1e_get_pfn(l1t[i]) !=3D (base_mfn + i)) || (l1e_get_flags(l1t[i]) !=3D flags) ) break; + UNMAP_DOMAIN_PAGE(l1t); if ( i =3D=3D L1_PAGETABLE_ENTRIES ) { l2e_write_atomic(pl2e, l2e_from_pfn(base_mfn, @@ -5408,7 +5419,7 @@ int map_pages_to_xen( flush_area(virt - PAGE_SIZE, FLUSH_TLB_GLOBAL | FLUSH_ORDER(PAGETABLE_ORDER)); - free_xen_pagetable(l2e_to_l1e(ol2e)); + free_xen_pagetable_new(l2e_get_mfn(ol2e)); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5441,7 +5452,7 @@ int map_pages_to_xen( continue; } =20 - l2t =3D l3e_to_l2e(ol3e); + l2t =3D map_l2t_from_l3e(ol3e); base_mfn =3D l2e_get_pfn(l2t[0]) & ~(L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES - 1); for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) @@ -5449,6 +5460,7 @@ int map_pages_to_xen( (base_mfn + (i << PAGETABLE_ORDER))) || (l2e_get_flags(l2t[i]) !=3D l1f_to_lNf(flags)) ) break; + UNMAP_DOMAIN_PAGE(l2t); if ( i =3D=3D L2_PAGETABLE_ENTRIES ) { l3e_write_atomic(pl3e, l3e_from_pfn(base_mfn, @@ -5458,7 +5470,7 @@ int map_pages_to_xen( flush_area(virt - PAGE_SIZE, FLUSH_TLB_GLOBAL | FLUSH_ORDER(2*PAGETABLE_ORDER)); - free_xen_pagetable(l3e_to_l2e(ol3e)); + free_xen_pagetable_new(l3e_get_mfn(ol3e)); } else if ( locking ) spin_unlock(&map_pgdir_lock); --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737393; cv=none; d=zohomail.com; s=zohoarc; b=DV0VJ2wT7Jl4gxWVLt0U+0N2YYHdaFSicSH/Rv7Q9iFY+XUYMw+pBPGSM5X3CVy64Nh1LNGIGkrAtcIHus7SpfXV0q0TQ9gNCZ6lHtLgiPLhoZa2ZFUN1eULgcbOlmqjP8eAD91PD/P1cQ4O85EHbzufesNPZQuXV41QNIB+ovI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737393; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=FRP5OT+p4pAgqXJ05UtHfE6HCl9wkp96YVneT3eOIa0=; b=DeE2YjgXlEJ3/RKOpc6T4T+ujwpT3EKSAtFisrD6vjtyg4zqER/cskHVtWUu3kxwFT12a+IMx5nk2+jlLz8YZH97h1RWY3YxpKT3aNutTYG6WzE53ck70UzNHbZLTkAaHM4/d03zagcmOkR0nIVv/WGtqePgejksZvXBZVqo+FE= 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 158773739372468.9027281525091; Fri, 24 Apr 2020 07:09:53 -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 1jRz1L-0002w7-Bh; Fri, 24 Apr 2020 14:09:35 +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 1jRz1K-0002vb-LV for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:34 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 347823c5-8635-11ea-94b0-12813bfff9fa; Fri, 24 Apr 2020 14:09:27 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1C-0001h4-JN; Fri, 24 Apr 2020 14:09:26 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1C-0001fN-9b; Fri, 24 Apr 2020 14:09:26 +0000 X-Inumbo-ID: 347823c5-8635-11ea-94b0-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=FRP5OT+p4pAgqXJ05UtHfE6HCl9wkp96YVneT3eOIa0=; b=uL8nkwnXd7QcfXGekCDou49Vil qwk/Lpqf50CRF7R4JN7hWqvBzc20bRiwggy4XvydDZfsMEykPhlChcrWAM9NvN1GvFZ+3Y2GOC6mF DY8UKpELidiG+g9d6d/g+EFgW1oL7ajCM5uhp2n5kcoyIUMbOfNsuhyr6rHBczpCusnE=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 05/15] x86/mm: switch to new APIs in modify_xen_mappings Date: Fri, 24 Apr 2020 15:08:56 +0100 Message-Id: <872b8f71cd391bc78933e9c018baab0b79b34c94.1587735799.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 , julien@xen.org, 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 Page tables allocated in that function should be mapped and unmapped now. Note that pl2e now maybe mapped and unmapped in different iterations, so we need to add clean-ups for that. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/mm.c | 57 ++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 2c14cdd83a..e8c16027d8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5508,7 +5508,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) { bool locking =3D system_state > SYS_STATE_boot; l3_pgentry_t *pl3e =3D NULL; - l2_pgentry_t *pl2e; + l2_pgentry_t *pl2e =3D NULL; l1_pgentry_t *pl1e; unsigned int i; unsigned long v =3D s; @@ -5524,6 +5524,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) while ( v < e ) { /* Clean up mappings mapped in the previous iteration. */ + UNMAP_DOMAIN_PAGE(pl2e); UNMAP_DOMAIN_PAGE(pl3e); =20 pl3e =3D virt_to_xen_l3e(v); @@ -5541,6 +5542,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( l3e_get_flags(*pl3e) & _PAGE_PSE ) { l2_pgentry_t *l2t; + mfn_t l2mfn; =20 if ( l2_table_offset(v) =3D=3D 0 && l1_table_offset(v) =3D=3D 0 && @@ -5557,35 +5559,38 @@ int modify_xen_mappings(unsigned long s, unsigned l= ong e, unsigned int nf) } =20 /* PAGE1GB: shatter the superpage and fall through. */ - l2t =3D alloc_xen_pagetable(); - if ( !l2t ) + l2mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; =20 + l2t =3D map_domain_page(l2mfn); for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + (i << PAGETABLE_ORDER), l3e_get_flags(*pl3e))); + UNMAP_DOMAIN_PAGE(l2t); + if ( locking ) spin_lock(&map_pgdir_lock); if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) && (l3e_get_flags(*pl3e) & _PAGE_PSE) ) { - l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t), - __PAGE_HYPERVISOR)); - l2t =3D NULL; + l3e_write_atomic(pl3e, + l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR)); + l2mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( l2t ) - free_xen_pagetable(l2t); + + free_xen_pagetable_new(l2mfn); } =20 /* * The L3 entry has been verified to be present, and we've dealt w= ith * 1G pages as well, so the L2 table cannot require allocation. */ - pl2e =3D l3e_to_l2e(*pl3e) + l2_table_offset(v); + pl2e =3D map_l2t_from_l3e(*pl3e) + l2_table_offset(v); =20 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { @@ -5613,41 +5618,45 @@ int modify_xen_mappings(unsigned long s, unsigned l= ong e, unsigned int nf) else { l1_pgentry_t *l1t; - /* PSE: shatter the superpage and try again. */ - l1t =3D alloc_xen_pagetable(); - if ( !l1t ) + mfn_t l1mfn =3D alloc_xen_pagetable_new(); + + if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; =20 + l1t =3D map_domain_page(l1mfn); for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, l2e_get_flags(*pl2e) & ~_PAGE_P= SE)); + UNMAP_DOMAIN_PAGE(l1t); + if ( locking ) spin_lock(&map_pgdir_lock); if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && (l2e_get_flags(*pl2e) & _PAGE_PSE) ) { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), + l2e_write_atomic(pl2e, l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR)= ); - l1t =3D NULL; + l1mfn =3D INVALID_MFN; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( l1t ) - free_xen_pagetable(l1t); + + free_xen_pagetable_new(l1mfn); } } else { l1_pgentry_t nl1e, *l1t; + mfn_t l1mfn; =20 /* * Ordinary 4kB mapping: The L2 entry has been verified to be * present, and we've dealt with 2M pages as well, so the L1 t= able * cannot require allocation. */ - pl1e =3D l2e_to_l1e(*pl2e) + l1_table_offset(v); + pl1e =3D map_l1t_from_l2e(*pl2e) + l1_table_offset(v); =20 /* Confirm the caller isn't trying to create new mappings. */ if ( !(l1e_get_flags(*pl1e) & _PAGE_PRESENT) ) @@ -5658,6 +5667,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) (l1e_get_flags(*pl1e) & ~FLAGS_MASK) | nf); =20 l1e_write_atomic(pl1e, nl1e); + UNMAP_DOMAIN_PAGE(pl1e); v +=3D PAGE_SIZE; =20 /* @@ -5687,10 +5697,12 @@ int modify_xen_mappings(unsigned long s, unsigned l= ong e, unsigned int nf) continue; } =20 - l1t =3D l2e_to_l1e(*pl2e); + l1mfn =3D l2e_get_mfn(*pl2e); + l1t =3D map_domain_page(l1mfn); for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ ) if ( l1e_get_intpte(l1t[i]) !=3D 0 ) break; + UNMAP_DOMAIN_PAGE(l1t); if ( i =3D=3D L1_PAGETABLE_ENTRIES ) { /* Empty: zap the L2E and free the L1 page. */ @@ -5698,7 +5710,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(l1t); + free_xen_pagetable_new(l1mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5729,11 +5741,13 @@ int modify_xen_mappings(unsigned long s, unsigned l= ong e, unsigned int nf) =20 { l2_pgentry_t *l2t; + mfn_t l2mfn =3D l3e_get_mfn(*pl3e); =20 - l2t =3D l3e_to_l2e(*pl3e); + l2t =3D map_domain_page(l2mfn); for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++ ) if ( l2e_get_intpte(l2t[i]) !=3D 0 ) break; + UNMAP_DOMAIN_PAGE(l2t); if ( i =3D=3D L2_PAGETABLE_ENTRIES ) { /* Empty: zap the L3E and free the L2 page. */ @@ -5741,7 +5755,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(l2t); + free_xen_pagetable_new(l2mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5754,6 +5768,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) rc =3D 0; =20 out: + UNMAP_DOMAIN_PAGE(pl2e); UNMAP_DOMAIN_PAGE(pl3e); return rc; } --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737403; cv=none; d=zohomail.com; s=zohoarc; b=QKZzJpQ30yrSJFSBCNuXRLKD1ZiepUiYlDGcwQzWrIU3x3QNni+9CXlZCQa/d40S83UiWUWdBj2hfr3a7EF3eRIVXw2LSEV0G1FtSR6QPr5rYFBQzTZ4vT3wiuSzx+Hav7S5MGxjNu4ZNf6xtUXPbGmxB1PZFQc5hjKKV4m3iYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737403; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=QEgbzBwJFIRd1ScLggvvofYSSDEx2eZQcbh7hVPo+uI=; b=P6P1quhMWkuFHfkPQpiGnP5ZRVZ/1NKORw2RMzQhtOEdYuxN073dLYqXhYf4cA9p7fbLcxv4sYK1ilKxJJkqzzS7jcLmk6+Hue1/N1Zbrc5hmKu5RAbKkIQla4XyClQPHmrcFbs5CnYmOIAmBTaLsWcjZhKt20Su4Abp+NNn7vg= 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 1587737403752637.140486485217; Fri, 24 Apr 2020 07:10:03 -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 1jRz1Q-00030I-Vh; Fri, 24 Apr 2020 14:09:40 +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 1jRz1P-0002zR-Le for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:39 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 35da7c9e-8635-11ea-94b0-12813bfff9fa; Fri, 24 Apr 2020 14:09:28 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1E-0001hB-6c; Fri, 24 Apr 2020 14:09:28 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1D-0001fN-QH; Fri, 24 Apr 2020 14:09:28 +0000 X-Inumbo-ID: 35da7c9e-8635-11ea-94b0-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=QEgbzBwJFIRd1ScLggvvofYSSDEx2eZQcbh7hVPo+uI=; b=wZarron7xIIzBW7E+eHmwQVMNa ViVyFwLfw3guf+v0i57cFEEtYMQWjHElbIxWjU9f0tDb8zbGioYDKi5QP0Lk3Kx2YaS+E3xSgyXNF +tzr9+2UFxZpUt78F9Bw8zgTKMxXhy2yjtzO4U+qLTdnr+TxcpeH0O/YZVSS7v3ntIow=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 06/15] x86_64/mm: introduce pl2e in paging_init Date: Fri, 24 Apr 2020 15:08:57 +0100 Message-Id: <40759ec2fa21e365ad8a59ab0de59b3f7f5fb42a.1587735799.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 , julien@xen.org, 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 Introduce pl2e so that we can use l2_ro_mpt to point to the page table itself. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/x86_64/mm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 6557255494..35f9de4ad4 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -479,7 +479,7 @@ void __init paging_init(void) unsigned long i, mpt_size, va; unsigned int n, memflags; l3_pgentry_t *l3_ro_mpt; - l2_pgentry_t *l2_ro_mpt =3D NULL; + l2_pgentry_t *pl2e =3D NULL, *l2_ro_mpt =3D NULL; struct page_info *l1_pg; =20 /* @@ -529,7 +529,7 @@ void __init paging_init(void) (L2_PAGETABLE_SHIFT - 3 + PAGE_SHIFT))); =20 if ( cpu_has_page1gb && - !((unsigned long)l2_ro_mpt & ~PAGE_MASK) && + !((unsigned long)pl2e & ~PAGE_MASK) && (mpt_size >> L3_PAGETABLE_SHIFT) > (i >> PAGETABLE_ORDER) ) { unsigned int k, holes; @@ -589,7 +589,7 @@ void __init paging_init(void) memset((void *)(RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT= )), 0xFF, 1UL << L2_PAGETABLE_SHIFT); } - if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) + if ( !((unsigned long)pl2e & ~PAGE_MASK) ) { if ( (l2_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) goto nomem; @@ -597,13 +597,14 @@ void __init paging_init(void) l3e_write(&l3_ro_mpt[l3_table_offset(va)], l3e_from_paddr(__pa(l2_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); + pl2e =3D l2_ro_mpt; ASSERT(!l2_table_offset(va)); } /* NB. Cannot be GLOBAL: guest user mode should not see it. */ if ( l1_pg ) - l2e_write(l2_ro_mpt, l2e_from_page( + l2e_write(pl2e, l2e_from_page( l1_pg, /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT= )); - l2_ro_mpt++; + pl2e++; } #undef CNT #undef MFN @@ -613,6 +614,7 @@ void __init paging_init(void) goto nomem; compat_idle_pg_table_l2 =3D l2_ro_mpt; clear_page(l2_ro_mpt); + pl2e =3D l2_ro_mpt; /* 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 ) @@ -625,7 +627,7 @@ void __init paging_init(void) sizeof(*compat_machine_to_phys_mapping)) BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \ sizeof(*compat_machine_to_phys_mapping)); - for ( i =3D 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++, l2_ro_mpt++ ) + for ( i =3D 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++, pl2e++ ) { memflags =3D MEMF_node(phys_to_nid(i << (L2_PAGETABLE_SHIFT - 2 + PAGE_SHIFT))); @@ -647,7 +649,7 @@ void __init paging_init(void) (i << L2_PAGETABLE_SHIFT)), 0xFF, 1UL << L2_PAGETABLE_SHIFT); /* NB. Cannot be GLOBAL as the ptes get copied into per-VM space. = */ - l2e_write(l2_ro_mpt, l2e_from_page(l1_pg, _PAGE_PSE|_PAGE_PRESENT)= ); + l2e_write(pl2e, l2e_from_page(l1_pg, _PAGE_PSE|_PAGE_PRESENT)); } #undef CNT #undef MFN --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737389; cv=none; d=zohomail.com; s=zohoarc; b=N0PQ+q97Y75SwyXLtQYf38+AMZ3FGLh9Jd7WVNwWiMUOsFWXkmRfS7JQ9qKoL60RTNhDjLYDFHiApWX4kituiZ5b+ocNR3NmHfxs64srfmPOSny+ualkbBg5gHk3G9gawrftz7XqFTFJf2Z760rZLDJc9stvNwpzCPosp1qUlqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737389; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=pNeKcQtUM57uOSxhr17X7t4TrlXzvDK3eAw9hbi5PGY=; b=e5jbzkQHAp5nNB9zDUKXeUTZx9qx3Zic9/nNQLYwkrK3zIkBercg2qyg6c++MF+3hHq5LmDMDM7uYGTY5ioYZTctyMCcTMlwk+BZSJhrcSMq9+6waby3D9F0eRGZqxqoD+strlD83UzBe5xKHvYRzGiwI8HelNu12u88HmjXx5M= 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 1587737389195287.0826474968553; Fri, 24 Apr 2020 07:09:49 -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 1jRz1K-0002v5-2f; Fri, 24 Apr 2020 14:09:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1I-0002uC-Eb for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36be5180-8635-11ea-9e09-bc764e2007e4; Fri, 24 Apr 2020 14:09:29 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1F-0001hM-LM; Fri, 24 Apr 2020 14:09:29 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1F-0001fN-BV; Fri, 24 Apr 2020 14:09:29 +0000 X-Inumbo-ID: 36be5180-8635-11ea-9e09-bc764e2007e4 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=pNeKcQtUM57uOSxhr17X7t4TrlXzvDK3eAw9hbi5PGY=; b=RFo4KtVx84sLcuT1KPnVt7fXiA bMcFW8macFJG+R0MrV9ZLOvQoZt18IV5I6U+ngAIq9+lBVvFzO3tTMmtkTwEJYoyR3ILZTZkCMoH6 Lcxf9h5T1lOZpsIY708/af3w89znPxI7mOI0ZuWfhp+Fi8gdl9F/L/lK9lEwvDpTT6tU=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 07/15] x86_64/mm: switch to new APIs in paging_init Date: Fri, 24 Apr 2020 15:08:58 +0100 Message-Id: <0655cc2d3dc27141ef102076c4ad390a37191b37.1587735799.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 , julien@xen.org, 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 --- xen/arch/x86/x86_64/mm.c | 43 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 35f9de4ad4..3cf699d27b 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -478,9 +478,10 @@ void __init paging_init(void) { unsigned long i, mpt_size, va; unsigned int n, memflags; - l3_pgentry_t *l3_ro_mpt; + l3_pgentry_t *l3_ro_mpt =3D NULL; l2_pgentry_t *pl2e =3D NULL, *l2_ro_mpt =3D NULL; struct page_info *l1_pg; + mfn_t l3_ro_mpt_mfn, l2_ro_mpt_mfn; =20 /* * We setup the L3s for 1:1 mapping if host support memory hotplug @@ -493,22 +494,28 @@ 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; + mfn_t l3mfn =3D alloc_xen_pagetable_new(); =20 - if ( !pl3t ) + if ( mfn_eq(l3mfn, INVALID_MFN) ) goto nomem; + + pl3t =3D map_domain_page(l3mfn); clear_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)); + unmap_domain_page(pl3t); } } =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_mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l3_ro_mpt_mfn, INVALID_MFN) ) goto nomem; + l3_ro_mpt =3D map_domain_page(l3_ro_mpt_mfn); 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(l3_ro_mpt_mfn, __PAGE_HYPERVISOR_RO | _PAGE_USE= R)); =20 /* * Allocate and map the machine-to-phys table. @@ -591,12 +598,17 @@ 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_mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) goto nomem; + + l2_ro_mpt =3D map_domain_page(l2_ro_mpt_mfn); 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(l2_ro_mpt_mfn, + __PAGE_HYPERVISOR_RO | _PAGE_USER)); pl2e =3D l2_ro_mpt; ASSERT(!l2_table_offset(va)); } @@ -608,13 +620,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 ) + l2_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(l2_ro_mpt_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(l2_ro_mpt_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 ) @@ -662,6 +677,8 @@ void __init paging_init(void) return; =20 nomem: + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + UNMAP_DOMAIN_PAGE(l3_ro_mpt); panic("Not enough memory for m2p table\n"); } =20 --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737391; cv=none; d=zohomail.com; s=zohoarc; b=hddHcq8XxnJ53hcqqyUFJPmKC22Fce94GxDyha9E7zBnpQZ6iYaQXZ2noEHxmhw0iENuKm3FqFfQXNUk404iIrd4hwxZSb+yVG5Drnf+3qyIa2PboJkOdsf+v/qWSLvnO9Sb7hMk+0Cn6U19WZ5ntdiFS+2/i3cL7BqHo8B1FZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737391; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fRkSpuClFodnft3WeIOUG75ZUCmfP/WLuHx0luTOIk0=; b=kU/vj401K2d2hIv+WDkWdvnB7K15RN2xgOLYaxzjr9S7EFI5dgnX55oRS+jNCiL6zxC2BzdLfTbKL1RROuZ/vtLz+8bCk+C6QVwQmUdEUt6KMp9fUYBTTQuz/aSNejj03Ubivt/0nmSFtTu5T/f/A/JZoE3jT+G0O1p3nxqZCNo= 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 1587737391314506.4532881657125; Fri, 24 Apr 2020 07:09:51 -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 1jRz1O-0002yZ-LU; Fri, 24 Apr 2020 14:09:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1N-0002xq-Eu for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 37a37e36-8635-11ea-b58d-bc764e2007e4; Fri, 24 Apr 2020 14:09:31 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1H-0001hY-77; Fri, 24 Apr 2020 14:09:31 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1G-0001fN-Rd; Fri, 24 Apr 2020 14:09:31 +0000 X-Inumbo-ID: 37a37e36-8635-11ea-b58d-bc764e2007e4 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=fRkSpuClFodnft3WeIOUG75ZUCmfP/WLuHx0luTOIk0=; b=UcF2ZDXTxspxFWqMo8u0pUjDco KWijGwEGxYWD5cuD29mhl1j3+gwF7TffeFBF6eB5j529681ajhs1Yz1XXA0sZ6yL7nJsMD1roTDeQ I7qO/kbcb708/ZdcGdKOYRc4yvuM9/lQFfD8S1M26YuiI0rMiVnT4aoPnN0is+F/AuMc=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 08/15] x86_64/mm: switch to new APIs in setup_m2p_table Date: Fri, 24 Apr 2020 15:08:59 +0100 Message-Id: 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 , julien@xen.org, 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 Also reduce the scope of l2_ro_mpt as it is only used inside the loop, and remove two lines of l2_ro_mpt check which serve no purpose. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/x86_64/mm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 3cf699d27b..12e9dc6eb2 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -379,13 +379,13 @@ static int setup_m2p_table(struct mem_hotadd_info *in= fo) { unsigned long i, va, smap, emap; unsigned int n; - l2_pgentry_t *l2_ro_mpt =3D NULL; l3_pgentry_t *l3_ro_mpt =3D NULL; int ret =3D 0; =20 ASSERT(l4e_get_flags(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]) & _PAGE_PRESENT); - l3_ro_mpt =3D l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_STA= RT)]); + l3_ro_mpt =3D map_l3t_from_l4e( + idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]); =20 smap =3D (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 3)) -1))); emap =3D ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) & @@ -424,6 +424,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) break; if ( n < CNT ) { + l2_pgentry_t *l2_ro_mpt; mfn_t mfn =3D alloc_hotadd_mfn(info); =20 ret =3D map_pages_to_xen( @@ -440,30 +441,30 @@ static int setup_m2p_table(struct mem_hotadd_info *in= fo) _PAGE_PSE)); if ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & _PAGE_PRESENT ) - l2_ro_mpt =3D l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]) + - l2_table_offset(va); + l2_ro_mpt =3D map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(v= a)]); else { - l2_ro_mpt =3D alloc_xen_pagetable(); - if ( !l2_ro_mpt ) + mfn_t l2_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + + if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) { ret =3D -ENOMEM; goto error; } =20 + l2_ro_mpt =3D map_domain_page(l2_ro_mpt_mfn); 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= )); - l2_ro_mpt +=3D l2_table_offset(va); + l3e_from_mfn(l2_ro_mpt_mfn, + __PAGE_HYPERVISOR_RO | _PAGE_USER)); } + l2_ro_mpt +=3D l2_table_offset(va); =20 /* NB. Cannot be GLOBAL: guest user mode should not see it. */ l2e_write(l2_ro_mpt, l2e_from_mfn(mfn, /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); + unmap_domain_page(l2_ro_mpt); } - if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) - l2_ro_mpt =3D NULL; i +=3D ( 1UL << (L2_PAGETABLE_SHIFT - 3)); } #undef CNT @@ -471,6 +472,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) =20 ret =3D setup_compat_m2p_table(info); error: + UNMAP_DOMAIN_PAGE(l3_ro_mpt); return ret; } =20 --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587737398; cv=none; d=zohomail.com; s=zohoarc; b=SsEFawBVEGwOynfKVLGLJ/qQAkeeBPyzNOUaa5wAa7ZG7vJn+dMc+u9wyIbbh6jLrUgmV2ueHZ3ruuQGrh4fJvs+kdDUoMpQnNCrz9dSVUgUxI8iUS7uOHvAgiutJvN1KL0kB8dUH5WCrUB2+S9iDizBjF1hDaUKeGjRMcpKYU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587737398; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=i73GryKu2F55P7dpYQ8AYC2nWGmKgcztTRkoevvtces=; b=Ee8B1lVeCysEgjUCEr/uAf7eVw29tW6GpsmxUOhOvK5kl0hfg99GEwI4USQ8etMk0eMTrEfQLXCNgxThVghvFpo41KogCAIxRYPrwuHQ8yl87nWk0xm2xKLEotSiZakeyWZoEhFPl6HN9rO62OLmOWSn2fYJ8KVpDREwuLwSsoY= 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 1587737398694856.3639247785718; Fri, 24 Apr 2020 07:09:58 -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 1jRz1T-00032p-Ci; Fri, 24 Apr 2020 14:09:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1S-00031w-F9 for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:09:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 385d13f0-8635-11ea-b58d-bc764e2007e4; Fri, 24 Apr 2020 14:09:32 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRz1I-0001he-AR; Fri, 24 Apr 2020 14:09:32 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1H-0001fN-Uj; Fri, 24 Apr 2020 14:09:32 +0000 X-Inumbo-ID: 385d13f0-8635-11ea-b58d-bc764e2007e4 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=i73GryKu2F55P7dpYQ8AYC2nWGmKgcztTRkoevvtces=; b=ifCSB49tKxVEMTt06aZ/ovgvXd t1kpGS79L8/8OmM9hEi/dgd4F9cGlvrTrmvj8P1XtE41DVKzPKukZDFIK7+TWMMHw7CaXksJVBmO6 MwZ6JX1GW/YZZBV7LR1N9aUar7fp1HCXfx1SU4fjf4xfPACBU270w13b5bcB7iwyc8y0=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 09/15] efi: use new page table APIs in copy_mapping Date: Fri, 24 Apr 2020 15:09:00 +0100 Message-Id: <6c27c79964eb16eba4743515689b9fd7eb3409d1.1587735799.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: julien@xen.org, Jan Beulich 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 After inspection ARM doesn't have alloc_xen_pagetable so this function is x86 only, which means it is safe for us to change. Signed-off-by: Wei Liu --- xen/common/efi/boot.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index a6f84c945a..8e96ef8de2 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1454,16 +1454,20 @@ static __init void copy_mapping(unsigned long mfn, = unsigned long end, continue; if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - l3dst =3D alloc_xen_pagetable(); - BUG_ON(!l3dst); + mfn_t l3mfn =3D alloc_xen_pagetable_new(); + + BUG_ON(mfn_eq(l3mfn, INVALID_MFN)); + l3dst =3D map_domain_page(l3mfn); clear_page(l3dst); efi_l4_pgtable[l4_table_offset(mfn << PAGE_SHIFT)] =3D - l4e_from_paddr(virt_to_maddr(l3dst), __PAGE_HYPERVISOR); + l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); } else - l3dst =3D l4e_to_l3e(l4e); - l3src =3D l4e_to_l3e(idle_pg_table[l4_table_offset(va)]); + l3dst =3D map_l3t_from_l4e(l4e); + l3src =3D map_l3t_from_l4e(idle_pg_table[l4_table_offset(va)]); l3dst[l3_table_offset(mfn << PAGE_SHIFT)] =3D l3src[l3_table_offse= t(va)]; + unmap_domain_page(l3src); + unmap_domain_page(l3dst); } } =20 --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738038; cv=none; d=zohomail.com; s=zohoarc; b=mrckcgV+YTp9Q9X1X5MAszxkvGSvT+3cMoPCE3E8uUUQRsbjAU60qE35NLO8Dk2FedoxdEkzLTjBd7Q5stsLM6gLcPP/iYh13EawTiG0ppesjx6jR6fKrt8+ETLN/4bz1Hp2YDTBT5gmKiw5rHoKAUcMRHzCSjhXO2TQBkidwbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738038; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=j6haYfYul3hln7GE8AxrUee2uyGJwIwRiYNu/Xr2Q+o=; b=LSwbKxHJczyZN1K574y2hHEPKFginvB4NUlQToYBUiUaWu3h1xcBGLkJ4NG0NVjhgemHAdpYDbRFh5d3KERCiJSiNnm6hN8Kl1+t2RghpaZpoLTUOmwgpFPvFa5HTQKfCy15ixKYFq+wq5xsIgqOi20Ya7ET5qyuHRBf5HDYvKo= 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 1587738038355198.87775480210223; Fri, 24 Apr 2020 07:20:38 -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 1jRzBm-0005FM-He; Fri, 24 Apr 2020 14:20:22 +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 1jRzBl-0005F3-PO for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:21 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b4c74f4a-8636-11ea-94b3-12813bfff9fa; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001xL-DP; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1J-0001fN-EK; Fri, 24 Apr 2020 14:09:33 +0000 X-Inumbo-ID: b4c74f4a-8636-11ea-94b3-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=j6haYfYul3hln7GE8AxrUee2uyGJwIwRiYNu/Xr2Q+o=; b=LRZNLjPf6lK2q6BoGoT2L5LM2p 345gz94VwTNpsaI178Fc1uyE+zfRnNnNxb9xCjfiIGw53UxXgM2FAhHZzfBvcfpRZkVWTOTBy0p5x aV16XGyd7D3JCD2zEVwBsXJxlAvFie2V/iubLiaQLlveMNLGt/RAfo70aPP6B/ZWEDHI=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 10/15] efi: switch to new APIs in EFI code Date: Fri, 24 Apr 2020 15:09:01 +0100 Message-Id: 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 , julien@xen.org, 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 Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/efi/runtime.h | 10 +++++++-- xen/common/efi/boot.c | 46 ++++++++++++++++++++++++++------------ xen/common/efi/efi.h | 3 ++- xen/common/efi/runtime.c | 8 +++---- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/efi/runtime.h b/xen/arch/x86/efi/runtime.h index d9eb8f5c27..d2483645c6 100644 --- a/xen/arch/x86/efi/runtime.h +++ b/xen/arch/x86/efi/runtime.h @@ -1,12 +1,18 @@ +#include +#include #include #include =20 #ifndef COMPAT -l4_pgentry_t *__read_mostly efi_l4_pgtable; +mfn_t __read_mostly efi_l4_mfn =3D INVALID_MFN_INITIALIZER; =20 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { - if ( efi_l4_pgtable ) + if ( !mfn_eq(efi_l4_mfn, INVALID_MFN) ) + { + l4_pgentry_t *efi_l4_pgtable =3D map_domain_page(efi_l4_mfn); l4e_write(efi_l4_pgtable + l4idx, l4e); + unmap_domain_page(efi_l4_pgtable); + } } #endif diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 8e96ef8de2..715217d2a9 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -1442,6 +1443,7 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, unsigned long emfn)) { unsigned long next; + l4_pgentry_t *efi_l4_pgtable =3D map_domain_page(efi_l4_mfn); =20 for ( ; mfn < end; mfn =3D next ) { @@ -1469,6 +1471,8 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, unmap_domain_page(l3src); unmap_domain_page(l3dst); } + + unmap_domain_page(efi_l4_pgtable); } =20 static bool __init ram_range_valid(unsigned long smfn, unsigned long emfn) @@ -1489,6 +1493,7 @@ static bool __init rt_range_valid(unsigned long smfn,= unsigned long emfn) void __init efi_init_memory(void) { unsigned int i; + l4_pgentry_t *efi_l4_pgtable; struct rt_extra { struct rt_extra *next; unsigned long smfn, emfn; @@ -1603,8 +1608,9 @@ void __init efi_init_memory(void) * Set up 1:1 page tables for runtime calls. See SetVirtualAddressMap(= ) in * efi_exit_boot(). */ - efi_l4_pgtable =3D alloc_xen_pagetable(); - BUG_ON(!efi_l4_pgtable); + efi_l4_mfn =3D alloc_xen_pagetable_new(); + BUG_ON(mfn_eq(efi_l4_mfn, INVALID_MFN)); + efi_l4_pgtable =3D map_domain_page(efi_l4_mfn); clear_page(efi_l4_pgtable); =20 copy_mapping(0, max_page, ram_range_valid); @@ -1637,39 +1643,45 @@ void __init efi_init_memory(void) =20 if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - pl3e =3D alloc_xen_pagetable(); - BUG_ON(!pl3e); + mfn_t l3mfn =3D alloc_xen_pagetable_new(); + + BUG_ON(mfn_eq(l3mfn, INVALID_MFN)); + pl3e =3D map_domain_page(l3mfn); clear_page(pl3e); efi_l4_pgtable[l4_table_offset(addr)] =3D - l4e_from_paddr(virt_to_maddr(pl3e), __PAGE_HYPERVISOR); + l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); } else - pl3e =3D l4e_to_l3e(l4e); + pl3e =3D map_l3t_from_l4e(l4e); pl3e +=3D l3_table_offset(addr); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - pl2e =3D alloc_xen_pagetable(); - BUG_ON(!pl2e); + mfn_t l2mfn =3D alloc_xen_pagetable_new(); + + BUG_ON(mfn_eq(l2mfn, INVALID_MFN)); + pl2e =3D map_domain_page(l2mfn); clear_page(pl2e); - *pl3e =3D l3e_from_paddr(virt_to_maddr(pl2e), __PAGE_HYPERVISO= R); + *pl3e =3D l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR); } else { BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); - pl2e =3D l3e_to_l2e(*pl3e); + pl2e =3D map_l2t_from_l3e(*pl3e); } pl2e +=3D l2_table_offset(addr); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - l1t =3D alloc_xen_pagetable(); - BUG_ON(!l1t); + mfn_t l1mfn =3D alloc_xen_pagetable_new(); + + BUG_ON(mfn_eq(l1mfn, INVALID_MFN)); + l1t =3D map_domain_page(l1mfn); clear_page(l1t); - *pl2e =3D l2e_from_paddr(virt_to_maddr(l1t), __PAGE_HYPERVISOR= ); + *pl2e =3D l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR); } else { BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE); - l1t =3D l2e_to_l1e(*pl2e); + l1t =3D map_l1t_from_l2e(*pl2e); } for ( i =3D l1_table_offset(addr); i < L1_PAGETABLE_ENTRIES && extra->smfn < extra->emfn; @@ -1681,11 +1693,17 @@ void __init efi_init_memory(void) extra_head =3D extra->next; xfree(extra); } + + unmap_domain_page(l1t); + unmap_domain_page(pl2e); + unmap_domain_page(pl3e); } =20 /* Insert Xen mappings. */ for ( i =3D l4_table_offset(HYPERVISOR_VIRT_START); i < l4_table_offset(DIRECTMAP_VIRT_END); ++i ) efi_l4_pgtable[i] =3D idle_pg_table[i]; + + unmap_domain_page(efi_l4_pgtable); } #endif diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 2e38d05f3d..e364bae3e0 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include =20 @@ -29,7 +30,7 @@ extern UINTN efi_memmap_size, efi_mdesc_size; extern void *efi_memmap; =20 #ifdef CONFIG_X86 -extern l4_pgentry_t *efi_l4_pgtable; +extern mfn_t efi_l4_mfn; #endif =20 extern const struct efi_pci_rom *efi_pci_roms; diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 95367694b5..375b94229e 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -85,7 +85,7 @@ struct efi_rs_state efi_rs_enter(void) static const u32 mxcsr =3D MXCSR_DEFAULT; struct efi_rs_state state =3D { .cr3 =3D 0 }; =20 - if ( !efi_l4_pgtable ) + if ( mfn_eq(efi_l4_mfn, INVALID_MFN) ) return state; =20 state.cr3 =3D read_cr3(); @@ -111,7 +111,7 @@ struct efi_rs_state efi_rs_enter(void) lgdt(&gdt_desc); } =20 - switch_cr3_cr4(virt_to_maddr(efi_l4_pgtable), read_cr4()); + switch_cr3_cr4(mfn_to_maddr(efi_l4_mfn), read_cr4()); =20 return state; } @@ -140,9 +140,9 @@ void efi_rs_leave(struct efi_rs_state *state) =20 bool efi_rs_using_pgtables(void) { - return efi_l4_pgtable && + return !mfn_eq(efi_l4_mfn, INVALID_MFN) && (smp_processor_id() =3D=3D efi_rs_on_cpu) && - (read_cr3() =3D=3D virt_to_maddr(efi_l4_pgtable)); + (read_cr3() =3D=3D mfn_to_maddr(efi_l4_mfn)); } =20 unsigned long efi_get_time(void) --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738034; cv=none; d=zohomail.com; s=zohoarc; b=RIV1hcb/GhNxyDNzX/ml7QhgH1RRmWQvUY6cbAjIojM8w3/y6O9vXCrmipVX7eGf/uCZfu3YdWN7rNzCrzmwfxMVglGyahqMLA74bp4HlnWhARxEhwj+/LitNHriOL3e4aTFAdVxK9plBvv4Pz1rd+K3yzG5WPY+9nKbF1q3xBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738034; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=WuHZzCeYG5C/b2g02WeZNMxfNBzADEMLdtqdGqvTvAU=; b=SH4wA/uJ3rJIuLNA5TrFSszLG4e/V9T1KIPN22kPBnsVr7Qk+gTEOBH4U5cwWEQzQJ6CiedEfN2pb4q+aAO9b6yoRLvazhH2F1uHkGPI0spXJDIQ/j4FNIbLbzmvpz9V+MWNaFj+Gc/U3wwex2VA7/9NOUQ3l5BEMTiJxXUNdvk= 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 1587738034918314.0802587709769; Fri, 24 Apr 2020 07:20:34 -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 1jRzBh-0005Cs-Ur; Fri, 24 Apr 2020 14:20:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBg-0005Cb-1p for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:16 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b4b7478a-8636-11ea-b58d-bc764e2007e4; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001xB-99; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1K-0001fN-VT; Fri, 24 Apr 2020 14:09:35 +0000 X-Inumbo-ID: b4b7478a-8636-11ea-b58d-bc764e2007e4 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=WuHZzCeYG5C/b2g02WeZNMxfNBzADEMLdtqdGqvTvAU=; b=CGmFqXrswBnXEgsEUtJqz1C1Y5 HUvGO2SmQtdlfTptXzTOW0DFxw44kXES8+86535RR/2O/aXlYD9rOcISb4t7dw5p3rKnglMNNEqoN w3dxw24uM2rV+bhCrWRTvJHKX9EdIas5o6vFa2oC/ERqzwNARSgPB/edOticec6jhS9k=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 11/15] x86/smpboot: clone_mapping should have one exit path Date: Fri, 24 Apr 2020 15:09:02 +0100 Message-Id: <7c84de54ad0ae7a2e7c0c36ac7fa43860f8de995.1587735799.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 , julien@xen.org, 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 We will soon need to clean up page table mappings in the exit path. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/smpboot.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 275ce7661d..5b0e24f925 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -675,6 +675,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; l1_pgentry_t *pl1e; + int rc =3D -ENOMEM; =20 /* * Sanity check 'linear'. We only allow cloning from the Xen virtual @@ -715,7 +716,10 @@ static int clone_mapping(const void *ptr, root_pgentry= _t *rpt) pl1e =3D l2e_to_l1e(*pl2e) + l1_table_offset(linear); flags =3D l1e_get_flags(*pl1e); if ( !(flags & _PAGE_PRESENT) ) - return 0; + { + rc =3D 0; + goto out; + } pfn =3D l1e_get_pfn(*pl1e); } } @@ -724,7 +728,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) { pl3e =3D alloc_xen_pagetable(); if ( !pl3e ) - return -ENOMEM; + goto out; clear_page(pl3e); l4e_write(&rpt[root_table_offset(linear)], l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR)); @@ -738,7 +742,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) { pl2e =3D alloc_xen_pagetable(); if ( !pl2e ) - return -ENOMEM; + goto out; clear_page(pl2e); l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR)); } @@ -754,7 +758,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) { pl1e =3D alloc_xen_pagetable(); if ( !pl1e ) - return -ENOMEM; + goto out; clear_page(pl1e); l2e_write(pl2e, l2e_from_paddr(__pa(pl1e), __PAGE_HYPERVISOR)); } @@ -775,7 +779,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) else l1e_write(pl1e, l1e_from_pfn(pfn, flags)); =20 - return 0; + rc =3D 0; + out: + return rc; } =20 DEFINE_PER_CPU(root_pgentry_t *, root_pgt); --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738031; cv=none; d=zohomail.com; s=zohoarc; b=A2bsEDKbzOp4UrRmkJTkW/LYbZJvUHjLODbBeAgedzqhHDXDyCbsAaYIfknWETst1XBuhy+UTFomYhm9juxFj3Nu03hpuEYSsI98WQr2gldLL/edAq/+KtrXliUyub6Be8eI0ELiHYMZzrkQQ4nUMvGdCF9r5ZksxN1x1PYam40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738031; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=rVqrmVsGdg3zpwD9FEpHmV6lLm/2eKe7Noqaodw3sA0=; b=WbLUE1EOmksf79tj1eWgHg2AMaMNeP1/7r9RKdpIozkRJluDWiPxshEATaQP7PdLFPV/D9gWqWEGr9+M1hwSpu9jjb9HBTaticicJbpPDLqGgyM0QA83bNkQKXpxnuGH4+xgkZ49I11BwpIrVD/Cm0r5ftGoNO+dr6FFUpT8RzA= 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 1587738031618451.21812296222083; Fri, 24 Apr 2020 07:20:31 -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 1jRzBc-0005CB-D7; Fri, 24 Apr 2020 14:20:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBb-0005C1-7r for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:11 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b49af0d0-8636-11ea-b58d-bc764e2007e4; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001xD-AC; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1M-0001fN-FH; Fri, 24 Apr 2020 14:09:36 +0000 X-Inumbo-ID: b49af0d0-8636-11ea-b58d-bc764e2007e4 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=rVqrmVsGdg3zpwD9FEpHmV6lLm/2eKe7Noqaodw3sA0=; b=V8FbMqzOcf8cIbYeZPQzZWj/KA p7AYo5DE3aekQCANOc1ZUCpiC/yXyRvfKoPVrse5MTGHE3fyfo6EOVHo/gF1gNh8ppSwVS7s5SZbB BKZzSSzyZ76nwv41UdueYbSOX1zieiD5sxgDbGC6I/dT8LPLGBJILeSx3JvvTWgwE/u4=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 12/15] x86/smpboot: switch pl*e to use new APIs in clone_mapping Date: Fri, 24 Apr 2020 15:09:03 +0100 Message-Id: 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 , julien@xen.org, 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 Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/smpboot.c | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 5b0e24f925..0e0ae56c76 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -672,9 +672,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) { unsigned long linear =3D (unsigned long)ptr, pfn; unsigned int flags; - l3_pgentry_t *pl3e; - l2_pgentry_t *pl2e; - l1_pgentry_t *pl1e; + l3_pgentry_t *pl3e =3D NULL; + l2_pgentry_t *pl2e =3D NULL; + l1_pgentry_t *pl1e =3D NULL; int rc =3D -ENOMEM; =20 /* @@ -689,8 +689,8 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) (linear >=3D XEN_VIRT_END && linear < DIRECTMAP_VIRT_START) ) return -EINVAL; =20 - pl3e =3D l4e_to_l3e(idle_pg_table[root_table_offset(linear)]) + - l3_table_offset(linear); + pl3e =3D map_l3t_from_l4e(idle_pg_table[root_table_offset(linear)]); + pl3e +=3D l3_table_offset(linear); =20 flags =3D l3e_get_flags(*pl3e); ASSERT(flags & _PAGE_PRESENT); @@ -702,7 +702,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) } else { - pl2e =3D l3e_to_l2e(*pl3e) + l2_table_offset(linear); + pl2e =3D map_l2t_from_l3e(*pl3e) + l2_table_offset(linear); flags =3D l2e_get_flags(*pl2e); ASSERT(flags & _PAGE_PRESENT); if ( flags & _PAGE_PSE ) @@ -713,7 +713,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) } else { - pl1e =3D l2e_to_l1e(*pl2e) + l1_table_offset(linear); + pl1e =3D map_l1t_from_l2e(*pl2e) + l1_table_offset(linear); flags =3D l1e_get_flags(*pl1e); if ( !(flags & _PAGE_PRESENT) ) { @@ -724,48 +724,61 @@ static int clone_mapping(const void *ptr, root_pgentr= y_t *rpt) } } =20 + UNMAP_DOMAIN_PAGE(pl1e); + UNMAP_DOMAIN_PAGE(pl2e); + UNMAP_DOMAIN_PAGE(pl3e); + if ( !(root_get_flags(rpt[root_table_offset(linear)]) & _PAGE_PRESENT)= ) { - pl3e =3D alloc_xen_pagetable(); - if ( !pl3e ) + mfn_t l3mfn =3D alloc_xen_pagetable_new(); + + if ( mfn_eq(l3mfn, INVALID_MFN) ) goto out; + + pl3e =3D map_domain_page(l3mfn); clear_page(pl3e); l4e_write(&rpt[root_table_offset(linear)], - l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR)); + l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR)); } else - pl3e =3D l4e_to_l3e(rpt[root_table_offset(linear)]); + pl3e =3D map_l3t_from_l4e(rpt[root_table_offset(linear)]); =20 pl3e +=3D l3_table_offset(linear); =20 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - pl2e =3D alloc_xen_pagetable(); - if ( !pl2e ) + mfn_t l2mfn =3D alloc_xen_pagetable_new(); + + if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; + + pl2e =3D map_domain_page(l2mfn); clear_page(pl2e); - l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR)); + l3e_write(pl3e, l3e_from_mfn(l2mfn, __PAGE_HYPERVISOR)); } else { ASSERT(!(l3e_get_flags(*pl3e) & _PAGE_PSE)); - pl2e =3D l3e_to_l2e(*pl3e); + pl2e =3D map_l2t_from_l3e(*pl3e); } =20 pl2e +=3D l2_table_offset(linear); =20 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - pl1e =3D alloc_xen_pagetable(); - if ( !pl1e ) + mfn_t l1mfn =3D alloc_xen_pagetable_new(); + + if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; + + pl1e =3D map_domain_page(l1mfn); clear_page(pl1e); - l2e_write(pl2e, l2e_from_paddr(__pa(pl1e), __PAGE_HYPERVISOR)); + l2e_write(pl2e, l2e_from_mfn(l1mfn, __PAGE_HYPERVISOR)); } else { ASSERT(!(l2e_get_flags(*pl2e) & _PAGE_PSE)); - pl1e =3D l2e_to_l1e(*pl2e); + pl1e =3D map_l1t_from_l2e(*pl2e); } =20 pl1e +=3D l1_table_offset(linear); @@ -781,6 +794,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) =20 rc =3D 0; out: + UNMAP_DOMAIN_PAGE(pl1e); + UNMAP_DOMAIN_PAGE(pl2e); + UNMAP_DOMAIN_PAGE(pl3e); return rc; } =20 --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738038; cv=none; d=zohomail.com; s=zohoarc; b=KpoFRO1HhnGRClR14wNS8BUd6thRow8/lc22UU+BNYwHjTu8dTtUG/rsIoglGLdPH7HnNZdqymGm0FULIXeE7nIbcsXFft0C4khu8AI2QUw14DDn+/j6imPA5z0qnUhnOdRU1JH9u3Rut1O7vPnO0EaFIFXIwKqjQWMJpupe5JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738038; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=MuoSnDotjegD/IU7znqfvoq0uHwGPTkrgw7f3PEnI1Y=; b=KV9+IQeOZvYlWGryW+dFPpJCPVN236nDege850lEoK03+O3LMt7s54jUJwjBCfJY78vZBYNTH0MmfYrXRMZLvfP+ImLCYCxBezoTQfB6bnwO6Ks4WgyanmSSPjv+BdC4z/kVxolhH8Zy3717Rj9rD7frBJC9CkgSur/MkYmUdzo= 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 1587738038338571.2363065291469; Fri, 24 Apr 2020 07:20:38 -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 1jRzBc-0005CH-La; Fri, 24 Apr 2020 14:20:12 +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 1jRzBb-0005C6-Qx for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:11 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b48f0997-8636-11ea-94b3-12813bfff9fa; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001xF-BL; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1N-0001fN-Vq; Fri, 24 Apr 2020 14:09:38 +0000 X-Inumbo-ID: b48f0997-8636-11ea-94b3-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=MuoSnDotjegD/IU7znqfvoq0uHwGPTkrgw7f3PEnI1Y=; b=xuA5mu6b8VNL589aA1Dry2Zr7c rLLViASjctGpaQ2FWRDrple3fV/d87zRCksnfmo+4OvQymTISmzDNAOdbdLq4BC0H5IDho41Q/hNO XZKWeBUqsT70ClXNZYnGxqNZslsJp4oh+XRb2WwX0MmJDtx2qbrlUoKZ6e+uG8FMjH8Q=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 13/15] x86/mm: drop old page table APIs Date: Fri, 24 Apr 2020 15:09:04 +0100 Message-Id: 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 , julien@xen.org, 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: Hongyan Xia Two sets of old APIs, alloc/free_xen_pagetable() and lXe_to_lYe(), are now dropped to avoid the dependency on direct map. There are two special cases which still have not been re-written into the new APIs, thus need special treatment: rpt in smpboot.c cannot use ephemeral mappings yet. The problem is that rpt is read and written in context switch code, but the mapping infrastructure is NOT context-switch-safe, meaning we cannot map rpt in one domain and unmap in another. Before the mapping infrastructure supports context switches, rpt has to be globally mapped. Also, lXe_to_lYe() during Xen image relocation cannot be converted into map/unmap pairs. We cannot hold on to mappings while the mapping infrastructure is being relocated! It is enough to remove the direct map in the second e820 pass, so we still use the direct map (<4GiB) in Xen relocation (which is during the first e820 pass). Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- xen/arch/x86/mm.c | 14 -------------- xen/arch/x86/setup.c | 4 ++-- xen/arch/x86/smpboot.c | 4 ++-- xen/include/asm-x86/mm.h | 2 -- xen/include/asm-x86/page.h | 5 ----- 5 files changed, 4 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index e8c16027d8..749b6f23e5 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4913,20 +4913,6 @@ int mmcfg_intercept_write( return X86EMUL_OKAY; } =20 -void *alloc_xen_pagetable(void) -{ - mfn_t mfn =3D alloc_xen_pagetable_new(); - - return mfn_eq(mfn, INVALID_MFN) ? NULL : mfn_to_virt(mfn_x(mfn)); -} - -void free_xen_pagetable(void *v) -{ - mfn_t mfn =3D v ? virt_to_mfn(v) : INVALID_MFN; - - free_xen_pagetable_new(mfn); -} - /* * For these PTE APIs, the caller must follow the alloc-map-unmap-free * lifecycle, which means explicitly mapping the PTE pages before accessing diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 885919d5c3..c76fbf80dc 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1114,7 +1114,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) continue; *pl4e =3D l4e_from_intpte(l4e_get_intpte(*pl4e) + xen_phys_start); - pl3e =3D l4e_to_l3e(*pl4e); + pl3e =3D __va(l4e_get_paddr(*pl4e)); for ( j =3D 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ ) { /* Not present, 1GB mapping, or already relocated? */ @@ -1124,7 +1124,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) continue; *pl3e =3D l3e_from_intpte(l3e_get_intpte(*pl3e) + xen_phys_start); - pl2e =3D l3e_to_l2e(*pl3e); + pl2e =3D __va(l3e_get_paddr(*pl3e)); for ( k =3D 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ ) { /* Not present, PSE, or already relocated? */ diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 0e0ae56c76..71d61794ec 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -815,7 +815,7 @@ static int setup_cpu_root_pgt(unsigned int cpu) if ( !opt_xpti_hwdom && !opt_xpti_domu ) return 0; =20 - rpt =3D alloc_xen_pagetable(); + rpt =3D alloc_xenheap_page(); if ( !rpt ) return -ENOMEM; =20 @@ -919,7 +919,7 @@ static void cleanup_cpu_root_pgt(unsigned int cpu) free_xen_pagetable_new(l3mfn); } =20 - free_xen_pagetable(rpt); + free_xenheap_page(rpt); =20 /* Also zap the stub mapping for this CPU. */ if ( stub_linear ) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 3d3f9d49ac..cf855b48fd 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -583,8 +583,6 @@ int vcpu_destroy_pagetables(struct vcpu *); void *do_page_walk(struct vcpu *v, unsigned long addr); =20 /* Allocator functions for Xen pagetables. */ -void *alloc_xen_pagetable(void); -void free_xen_pagetable(void *v); mfn_t alloc_xen_pagetable_new(void); void free_xen_pagetable_new(mfn_t mfn); =20 diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 8f711f4992..2e3056c08e 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -188,11 +188,6 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, = unsigned int flags) #define l4e_has_changed(x,y,flags) \ ( !!(((x).l4 ^ (y).l4) & ((PADDR_MASK&PAGE_MASK)|put_pte_flags(flags))= ) ) =20 -/* Pagetable walking. */ -#define l2e_to_l1e(x) ((l1_pgentry_t *)__va(l2e_get_paddr(x))) -#define l3e_to_l2e(x) ((l2_pgentry_t *)__va(l3e_get_paddr(x))) -#define l4e_to_l3e(x) ((l3_pgentry_t *)__va(l4e_get_paddr(x))) - #define map_l1t_from_l2e(x) (l1_pgentry_t *)map_domain_page(l2e_get= _mfn(x)) #define map_l2t_from_l3e(x) (l2_pgentry_t *)map_domain_page(l3e_get= _mfn(x)) #define map_l3t_from_l4e(x) (l3_pgentry_t *)map_domain_page(l4e_get= _mfn(x)) --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738036; cv=none; d=zohomail.com; s=zohoarc; b=H5rxNe/yNxHnjbHGsnqtwSFmAJbtlYBc6fZPL8gKOjfjsI4Vvz/m5xXFwE0SXXAQvHiBvVGQ+ZIJgC9U85gfikoDuzx4JTXNT5mrebaMWe7yE3E9Uh1y+6FNkm99qAhTOH/HfUd6j0UyojnP5MMKVksmoxBS99R+gm3SIwLv7fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738036; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=beV1du9ph6uMZY01rLgboEpxeFyXrD+9xnH+UQh67O0=; b=iPMfqCR4Vdnbp2HzXLidSalJTfcyYvnwoUXZX3xUZv3Gnh3TXElnP9XDhY1vQBZ0e0aVpYjS3v0A6B8TNzAkICpgvZ8JTKzONSdHbiRuQAoxvU3Fs8wCV0Qo/nxY5PwMu14bazHCUyj9eIGPlD6VjTxFolWfe8NMgv9eTeRMJS4= 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 158773803687391.76483066937976; Fri, 24 Apr 2020 07:20:36 -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 1jRzBi-0005DY-7h; Fri, 24 Apr 2020 14:20:18 +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 1jRzBg-0005Ci-P8 for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:16 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b48f0996-8636-11ea-94b3-12813bfff9fa; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001x9-7D; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1P-0001fN-FM; Fri, 24 Apr 2020 14:09:39 +0000 X-Inumbo-ID: b48f0996-8636-11ea-94b3-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=beV1du9ph6uMZY01rLgboEpxeFyXrD+9xnH+UQh67O0=; b=1N2DbrFADG5vUIVnUYc+z8LPWW +4fwBJid6FLzmIz6h8SixZRB5AJVwC03aLdR+0c4uHNwO3fxAu5I0RKmTmAMphUVW/S3A4ciG323u fO09oUoELw3KZXx/2ZYI8/wdi4uzdc45nHtb0r6QiZR5pVR5FgIxDEyG2GngWAhVFAgM=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 14/15] x86: switch to use domheap page for page tables Date: Fri, 24 Apr 2020 15:09:05 +0100 Message-Id: <6cf43a3d1cd3d18c600515b1ead65f41c2996e92.1587735799.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 , julien@xen.org, 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: Hongyan Xia Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/mm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 749b6f23e5..7e212cc3e0 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4923,10 +4923,11 @@ mfn_t alloc_xen_pagetable_new(void) { if ( system_state !=3D SYS_STATE_early_boot ) { - void *ptr =3D alloc_xenheap_page(); =20 - BUG_ON(!hardware_domain && !ptr); - return ptr ? virt_to_mfn(ptr) : INVALID_MFN; + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + BUG_ON(!hardware_domain && !pg); + return pg ? page_to_mfn(pg) : INVALID_MFN; } =20 return alloc_boot_pages(1, 1); @@ -4936,7 +4937,7 @@ mfn_t alloc_xen_pagetable_new(void) void free_xen_pagetable_new(mfn_t mfn) { if ( system_state !=3D SYS_STATE_early_boot && !mfn_eq(mfn, INVALID_MF= N) ) - free_xenheap_page(mfn_to_virt(mfn_x(mfn))); + free_domheap_page(mfn_to_page(mfn)); } =20 static DEFINE_SPINLOCK(map_pgdir_lock); --=20 2.24.1.AMZN From nobody Thu May 2 09:18:44 2024 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=1587738049; cv=none; d=zohomail.com; s=zohoarc; b=lTqlFP0hjWA5YAWbKtH5A2T+8rs9nDunyaarzEbYsxeQ0g241ldIuM+vV7sG6kjl3fOaooNHKXx1z6HfK9pswFt7v3i3XWZKTuT3TBcuBJtrpeJx7OvLydiwUNAhd65vRbyoqrjUNHK9I1N5gJvJi5Zr5AoK96DH5f97VhpfVU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587738049; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=o5SnQls1sfBymIOf+4o9qpecybtOaO0mboyyYZ2aKLQ=; b=jwfkWMUgrwlEOCLwPBiR31JaoQctTXwOx9tYuMDs5/Iif20SsAB9QI7qE6MEYvcm8EmeL5lm2yDYw0UgPnDkqzuo3xv1KOicOjFnp+vbWKwiT8xqHd4+I7sDrIc4fJ7TMY2Ex4FkooQWBS+AJO0x6jaH81w6FCOl4qPbnKUb0NI= 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 1587738049196269.2252287715587; Fri, 24 Apr 2020 07:20:49 -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 1jRzBs-0005Js-0B; Fri, 24 Apr 2020 14:20:28 +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 1jRzBq-0005IQ-PR for xen-devel@lists.xenproject.org; Fri, 24 Apr 2020 14:20:26 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b4c0268e-8636-11ea-94b3-12813bfff9fa; Fri, 24 Apr 2020 14:20:10 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jRzBa-0001xJ-CN; Fri, 24 Apr 2020 14:20:10 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jRz1R-0001fN-1h; Fri, 24 Apr 2020 14:09:41 +0000 X-Inumbo-ID: b4c0268e-8636-11ea-94b3-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=o5SnQls1sfBymIOf+4o9qpecybtOaO0mboyyYZ2aKLQ=; b=Hg19jqtVuBc+wGTbHQcBF73XMV NwqJi9b8qMUOOywxbAmYS7TBtCOv7xp37h0CLLUb7GGsyz2KTC+KfvBCBn8SQDiAgid+J558maWD9 +FBLqgWWybabeoSoFW+rHKgsxsShMmkODR+CZvDNDbtvRmMc5PZVC5DWHRdAzTrSL0wA=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v6 15/15] x86/mm: drop _new suffix for page table APIs Date: Fri, 24 Apr 2020 15:09:06 +0100 Message-Id: <9ff8ad5d4ba7602f3d7137a650aba5de52dacd80.1587735799.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 , julien@xen.org, 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 No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Acked-by: Jan Beulich --- xen/arch/x86/mm.c | 48 ++++++++++++++++++++-------------------- xen/arch/x86/smpboot.c | 12 +++++----- xen/arch/x86/x86_64/mm.c | 10 ++++----- xen/common/efi/boot.c | 10 ++++----- xen/include/asm-x86/mm.h | 4 ++-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7e212cc3e0..a17ae0004a 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -356,7 +356,7 @@ void __init arch_init_memory(void) ASSERT(root_pgt_pv_xen_slots < ROOT_PAGETABLE_PV_XEN_SLOTS); if ( l4_table_offset(split_va) =3D=3D l4_table_offset(split_va= - 1) ) { - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 if ( !mfn_eq(l3mfn, INVALID_MFN) ) { @@ -4919,7 +4919,7 @@ int mmcfg_intercept_write( * them. The caller must check whether the allocation has succeeded, and o= nly * pass valid MFNs to map_domain_page(). */ -mfn_t alloc_xen_pagetable_new(void) +mfn_t alloc_xen_pagetable(void) { if ( system_state !=3D SYS_STATE_early_boot ) { @@ -4934,7 +4934,7 @@ mfn_t alloc_xen_pagetable_new(void) } =20 /* mfn can be INVALID_MFN */ -void free_xen_pagetable_new(mfn_t mfn) +void free_xen_pagetable(mfn_t mfn) { if ( system_state !=3D SYS_STATE_early_boot && !mfn_eq(mfn, INVALID_MF= N) ) free_domheap_page(mfn_to_page(mfn)); @@ -4955,7 +4955,7 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) { bool locking =3D system_state > SYS_STATE_boot; l3_pgentry_t *l3t; - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l3mfn, INVALID_MFN) ) return NULL; @@ -4974,7 +4974,7 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) } if ( locking ) spin_unlock(&map_pgdir_lock); - free_xen_pagetable_new(l3mfn); + free_xen_pagetable(l3mfn); } =20 return map_l3t_from_l4e(*pl4e) + l3_table_offset(v); @@ -4993,7 +4993,7 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) { bool locking =3D system_state > SYS_STATE_boot; l2_pgentry_t *l2t; - mfn_t l2mfn =3D alloc_xen_pagetable_new(); + mfn_t l2mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l2mfn, INVALID_MFN) ) { @@ -5012,7 +5012,7 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) } if ( locking ) spin_unlock(&map_pgdir_lock); - free_xen_pagetable_new(l2mfn); + free_xen_pagetable(l2mfn); } =20 BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); @@ -5035,7 +5035,7 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) { bool locking =3D system_state > SYS_STATE_boot; l1_pgentry_t *l1t; - mfn_t l1mfn =3D alloc_xen_pagetable_new(); + mfn_t l1mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l1mfn, INVALID_MFN) ) { @@ -5054,7 +5054,7 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) } if ( locking ) spin_unlock(&map_pgdir_lock); - free_xen_pagetable_new(l1mfn); + free_xen_pagetable(l1mfn); } =20 BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE); @@ -5163,10 +5163,10 @@ int map_pages_to_xen( ol2e =3D l2t[i]; if ( (l2e_get_flags(ol2e) & _PAGE_PRESENT) && !(l2e_get_flags(ol2e) & _PAGE_PSE) ) - free_xen_pagetable_new(l2e_get_mfn(ol2e)); + free_xen_pagetable(l2e_get_mfn(ol2e)); } unmap_domain_page(l2t); - free_xen_pagetable_new(l3e_get_mfn(ol3e)); + free_xen_pagetable(l3e_get_mfn(ol3e)); } } =20 @@ -5205,7 +5205,7 @@ int map_pages_to_xen( continue; } =20 - l2mfn =3D alloc_xen_pagetable_new(); + l2mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; =20 @@ -5233,7 +5233,7 @@ int map_pages_to_xen( spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); =20 - free_xen_pagetable_new(l2mfn); + free_xen_pagetable(l2mfn); } =20 pl2e =3D virt_to_xen_l2e(virt); @@ -5267,7 +5267,7 @@ int map_pages_to_xen( flush_flags(l1e_get_flags(l1t[i])); flush_area(virt, flush_flags); unmap_domain_page(l1t); - free_xen_pagetable_new(l2e_get_mfn(ol2e)); + free_xen_pagetable(l2e_get_mfn(ol2e)); } } =20 @@ -5313,7 +5313,7 @@ int map_pages_to_xen( goto check_l3; } =20 - l1mfn =3D alloc_xen_pagetable_new(); + l1mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; =20 @@ -5340,7 +5340,7 @@ int map_pages_to_xen( spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); =20 - free_xen_pagetable_new(l1mfn); + free_xen_pagetable(l1mfn); } =20 pl1e =3D map_l1t_from_l2e(*pl2e) + l1_table_offset(virt); @@ -5406,7 +5406,7 @@ int map_pages_to_xen( flush_area(virt - PAGE_SIZE, FLUSH_TLB_GLOBAL | FLUSH_ORDER(PAGETABLE_ORDER)); - free_xen_pagetable_new(l2e_get_mfn(ol2e)); + free_xen_pagetable(l2e_get_mfn(ol2e)); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5457,7 +5457,7 @@ int map_pages_to_xen( flush_area(virt - PAGE_SIZE, FLUSH_TLB_GLOBAL | FLUSH_ORDER(2*PAGETABLE_ORDER)); - free_xen_pagetable_new(l3e_get_mfn(ol3e)); + free_xen_pagetable(l3e_get_mfn(ol3e)); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5546,7 +5546,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) } =20 /* PAGE1GB: shatter the superpage and fall through. */ - l2mfn =3D alloc_xen_pagetable_new(); + l2mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; =20 @@ -5570,7 +5570,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); =20 - free_xen_pagetable_new(l2mfn); + free_xen_pagetable(l2mfn); } =20 /* @@ -5606,7 +5606,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) { l1_pgentry_t *l1t; /* PSE: shatter the superpage and try again. */ - mfn_t l1mfn =3D alloc_xen_pagetable_new(); + mfn_t l1mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; @@ -5630,7 +5630,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); =20 - free_xen_pagetable_new(l1mfn); + free_xen_pagetable(l1mfn); } } else @@ -5697,7 +5697,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable_new(l1mfn); + free_xen_pagetable(l1mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5742,7 +5742,7 @@ int modify_xen_mappings(unsigned long s, unsigned lon= g e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable_new(l2mfn); + free_xen_pagetable(l2mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 71d61794ec..06c8e3ddf0 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -730,7 +730,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) =20 if ( !(root_get_flags(rpt[root_table_offset(linear)]) & _PAGE_PRESENT)= ) { - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l3mfn, INVALID_MFN) ) goto out; @@ -747,7 +747,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) =20 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - mfn_t l2mfn =3D alloc_xen_pagetable_new(); + mfn_t l2mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l2mfn, INVALID_MFN) ) goto out; @@ -766,7 +766,7 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) =20 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - mfn_t l1mfn =3D alloc_xen_pagetable_new(); + mfn_t l1mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l1mfn, INVALID_MFN) ) goto out; @@ -908,15 +908,15 @@ static void cleanup_cpu_root_pgt(unsigned int cpu) continue; =20 ASSERT(!(l2e_get_flags(l2t[i2]) & _PAGE_PSE)); - free_xen_pagetable_new(l2e_get_mfn(l2t[i2])); + free_xen_pagetable(l2e_get_mfn(l2t[i2])); } =20 unmap_domain_page(l2t); - free_xen_pagetable_new(l2mfn); + free_xen_pagetable(l2mfn); } =20 unmap_domain_page(l3t); - free_xen_pagetable_new(l3mfn); + free_xen_pagetable(l3mfn); } =20 free_xenheap_page(rpt); diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 12e9dc6eb2..d37f6a3755 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -444,7 +444,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) l2_ro_mpt =3D map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(v= a)]); else { - mfn_t l2_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + mfn_t l2_ro_mpt_mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) { @@ -497,7 +497,7 @@ void __init paging_init(void) _PAGE_PRESENT) ) { l3_pgentry_t *pl3t; - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 if ( mfn_eq(l3mfn, INVALID_MFN) ) goto nomem; @@ -511,7 +511,7 @@ void __init paging_init(void) } =20 /* Create user-accessible L2 directory to map the MPT for guests. */ - l3_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + l3_ro_mpt_mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l3_ro_mpt_mfn, INVALID_MFN) ) goto nomem; l3_ro_mpt =3D map_domain_page(l3_ro_mpt_mfn); @@ -602,7 +602,7 @@ void __init paging_init(void) { UNMAP_DOMAIN_PAGE(l2_ro_mpt); =20 - l2_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + l2_ro_mpt_mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) goto nomem; =20 @@ -626,7 +626,7 @@ void __init paging_init(void) UNMAP_DOMAIN_PAGE(l3_ro_mpt); =20 /* Create user-accessible L2 directory to map the MPT for compat guest= s. */ - l2_ro_mpt_mfn =3D alloc_xen_pagetable_new(); + l2_ro_mpt_mfn =3D alloc_xen_pagetable(); if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) goto nomem; compat_idle_pg_table_l2 =3D map_domain_page_global(l2_ro_mpt_mfn); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 715217d2a9..d70d06084c 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1456,7 +1456,7 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, continue; if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 BUG_ON(mfn_eq(l3mfn, INVALID_MFN)); l3dst =3D map_domain_page(l3mfn); @@ -1608,7 +1608,7 @@ void __init efi_init_memory(void) * Set up 1:1 page tables for runtime calls. See SetVirtualAddressMap(= ) in * efi_exit_boot(). */ - efi_l4_mfn =3D alloc_xen_pagetable_new(); + efi_l4_mfn =3D alloc_xen_pagetable(); BUG_ON(mfn_eq(efi_l4_mfn, INVALID_MFN)); efi_l4_pgtable =3D map_domain_page(efi_l4_mfn); clear_page(efi_l4_pgtable); @@ -1643,7 +1643,7 @@ void __init efi_init_memory(void) =20 if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - mfn_t l3mfn =3D alloc_xen_pagetable_new(); + mfn_t l3mfn =3D alloc_xen_pagetable(); =20 BUG_ON(mfn_eq(l3mfn, INVALID_MFN)); pl3e =3D map_domain_page(l3mfn); @@ -1656,7 +1656,7 @@ void __init efi_init_memory(void) pl3e +=3D l3_table_offset(addr); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - mfn_t l2mfn =3D alloc_xen_pagetable_new(); + mfn_t l2mfn =3D alloc_xen_pagetable(); =20 BUG_ON(mfn_eq(l2mfn, INVALID_MFN)); pl2e =3D map_domain_page(l2mfn); @@ -1671,7 +1671,7 @@ void __init efi_init_memory(void) pl2e +=3D l2_table_offset(addr); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - mfn_t l1mfn =3D alloc_xen_pagetable_new(); + mfn_t l1mfn =3D alloc_xen_pagetable(); =20 BUG_ON(mfn_eq(l1mfn, INVALID_MFN)); l1t =3D map_domain_page(l1mfn); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index cf855b48fd..ef7a20ac7d 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -583,8 +583,8 @@ int vcpu_destroy_pagetables(struct vcpu *); void *do_page_walk(struct vcpu *v, unsigned long addr); =20 /* Allocator functions for Xen pagetables. */ -mfn_t alloc_xen_pagetable_new(void); -void free_xen_pagetable_new(mfn_t mfn); +mfn_t alloc_xen_pagetable(void); +void free_xen_pagetable(mfn_t mfn); =20 l1_pgentry_t *virt_to_xen_l1e(unsigned long v); =20 --=20 2.24.1.AMZN