From nobody Fri Mar 29 13:53:58 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=1595859768; cv=none; d=zohomail.com; s=zohoarc; b=HMlHdcQt9fOB8t/py65jQ4AiauSiBo7z23+nu9qRbXkkrgg5FGlZZKasr1d1z8YuKYckB46XG20F2v8vYquEllaO27OaDGvlk/jp2ZigMHEtieHonleRNc3uSFGHrVu9IZ/uAT8y+q5mVH13j2yHh5swW3K5kHb1hhbaHIXU+T8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859768; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=d2dy+O8HMS2n5aYbf6tbA9h3T1JBERn3K5gYW9x8m4c=; b=GW5gvGydUH46hzeu9QHmQQrW7IY2idZGAYcCL+XOdEIFnFi/lYFG3M3g9s61nHvKLJRJ+2Q4N/DV8Z0oNVhzI1uuj2mZNB9mBr5RChBZcSx3QiTNaO5yyX25L7nmmKvbrhHdO2WKNs5Y1ctzXWREB5IvpzEmpM4tzue+F3fQ1PQ= 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 1595859768101838.5092387730095; Mon, 27 Jul 2020 07:22:48 -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 1k041F-000766-41; Mon, 27 Jul 2020 14:22:21 +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 1k041D-00075u-Pm for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:19 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 930a170d-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:18 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041C-0001Mj-CH; Mon, 27 Jul 2020 14:22:18 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041C-0002w6-1i; Mon, 27 Jul 2020 14:22:18 +0000 X-Inumbo-ID: 930a170d-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=d2dy+O8HMS2n5aYbf6tbA9h3T1JBERn3K5gYW9x8m4c=; b=tzYtqK51jVjeJbI/PqrQpGv6f5 UYzSv7pwygTT35iG/5CeZTZHyKIptE9fQU/oeoogDQjmBnbqIS5hegfEQO0j3b7aQedxesOW2W+wo 03bDsDS7BwxR/QcvPLqtvm0zyEn7VQB9RI4JbGl+lJz2YFrnimT+H/EPiZPyyeRzD76o=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 01/15] x86/mm: map_pages_to_xen would better have one exit path Date: Mon, 27 Jul 2020 15:21:51 +0100 Message-Id: <45a087b2be2f04567af99c630a0bed6500785463.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu 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 82bc676553..0ade9b3917 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5085,9 +5085,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); \ @@ -5105,10 +5107,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 && @@ -5198,7 +5201,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, @@ -5227,7 +5230,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) && @@ -5271,7 +5274,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 ) { @@ -5299,7 +5302,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], @@ -5445,7 +5448,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595859768; cv=none; d=zohomail.com; s=zohoarc; b=IsrOuH7YP8MrPx3AzE4qiZH70XbGnU5xTHRTiPs1gj7b+UKHZKzzc68ksQINKS0nmOYflpFjljAbyYUwdAXNj8jAuoYmT49f1GD5iXJRglMU/7AO8lvIIOClzeOg7beDF2NimEJOR7lC2NOtf07HaUGnmvjMwxkb/c2b2HRF1vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859768; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=BqJIywzpGYOOk00xzU2J1b4Z+JiGyqnjXWw3J7dS0fY=; b=LDl4ift+XCRMeQCfe0IPAtrmZcJ7SXYSRob4vx5v48yr3Kv6ZiMMN9FipQZ5utfG9wFTAVUx2nNHbtcZKNWQRXuXc3xcFvwnp9lcTz95jwd9pDzWVYl5dRCcpxOWdPw2+bBJTk6CAAot6mrfmQ4u4c4uztRPRtf9Q256Na7NAk4= 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 1595859767964260.24570715803225; Mon, 27 Jul 2020 07:22:47 -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 1k041K-00077x-FI; Mon, 27 Jul 2020 14:22:26 +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 1k041I-00075u-OI for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:24 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 94bb3e8c-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:20 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041D-0001NK-RB; Mon, 27 Jul 2020 14:22:19 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041D-0002w6-GJ; Mon, 27 Jul 2020 14:22:19 +0000 X-Inumbo-ID: 94bb3e8c-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BqJIywzpGYOOk00xzU2J1b4Z+JiGyqnjXWw3J7dS0fY=; b=rS7WFKLQNzKO+aHcR6aQGvADsm DT8CtwbAgC95miE7A08kZKob3pG6Rd6X44F8HkOOpjXhGuoHXf85gJwb23byhcUqkE1Nbv8pfmOhg gS7zo368UpRU5XhOX/366+oB2vECNywbsCjjG8iWh8CP4v9s5wEkPq9+paVBkYSBqiYY=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 02/15] x86/mm: make sure there is one exit path for modify_xen_mappings Date: Mon, 27 Jul 2020 15:21:52 +0100 Message-Id: <8864d7e68842dc68090bfa5b0b50253d0eb695d8.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu 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 0ade9b3917..7a11d022c9 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5474,10 +5474,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_DIRTY|_PAGE_ACCESSED|_PAGE_RW|_PAGE_PRE= SENT) @@ -5488,7 +5490,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) ) { @@ -5521,7 +5523,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) + @@ -5578,7 +5581,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, @@ -5711,7 +5715,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595859769; cv=none; d=zohomail.com; s=zohoarc; b=RXKuf8VPIB7dneT1viNkSKjt50a2RcIP/OJovol8shAMmRZ5IAzKH7qLVmDQJqtMWuuQK7nYhchjbFxTxEPpYY3QVDwuZHyIyfrZT6+MwAA1PsindhAn0eP7JVWhcULaKeYdxCDqka2sjojyJjAVskiE4UcfUcAT0ISdjWq65No= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859769; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ocpaxy196EOPlPXfon4lDI7Bm2winkx9grPvtKNISJ4=; b=fqilsjeQv6+oeWNk7ZwOgvz64r4ooDH0sKFj+m9FXzKpshG/xfYBtto0ygZmnXQrQ/qM9pAzTFFtaszorPraEMwAXDrkisGn82njYA9ywAUfJ21XE/M5af4bgy47WNGPAsqHb5o52xmVjtG7k/OjRAELvyOsR8LR0jusd809hHM= 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 1595859769210210.8559875784241; Mon, 27 Jul 2020 07:22: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 1k041O-00079M-PG; Mon, 27 Jul 2020 14:22: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 1k041N-00075u-Oc for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:29 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 96193afe-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041F-0001NS-Sb; Mon, 27 Jul 2020 14:22:21 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041F-0002w6-Em; Mon, 27 Jul 2020 14:22:21 +0000 X-Inumbo-ID: 96193afe-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ocpaxy196EOPlPXfon4lDI7Bm2winkx9grPvtKNISJ4=; b=r5vQueOv2ciYdgPxMTLL62sfnp hv08MX1PHrv9hFQlKg1nbz0GAKsyhciJr1IGTPDlh9dduSPXruXh1Cy9s1/fDCXrJ1wDKKczVtyar 9YxcWFNnVVGS0HTiZit0XyVSlbX/N2ehkyMFW1B543LPhBbgi6Qddmzksvhh/GgZYAAM=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 03/15] x86/mm: rewrite virt_to_xen_l*e Date: Mon, 27 Jul 2020 15:21:53 +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: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , jgrall@amazon.com, 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. Since alloc_xen_pagetable_new() is almost never useful unless accompanied by page clearing and a mapping, introduce a helper alloc_map_clear_xen_pt() for this sequence. 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 Reviewed-by: Jan Beulich --- Changed in v8: - s/virtual address/linear address/. - BUG_ON() on NULL return in vmap_to_mfn(). Changed in v7: - remove a comment. - use l1e_get_mfn() instead of converting things back and forth. - add alloc_map_clear_xen_pt(). - unmap before the next mapping to reduce mapcache pressure. - use normal unmap calls instead of the macro in error paths because unmap can handle NULL now. --- xen/arch/x86/domain_page.c | 11 ++++-- xen/arch/x86/mm.c | 96 +++++++++++++++++++++++++++++++++---------= ---- xen/common/vmap.c | 1 + xen/include/asm-x86/mm.h | 1 + xen/include/asm-x86/page.h | 10 ++++- 5 files changed, 88 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index b03728e18e..dc8627c1b5 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 7a11d022c9..fd416c0282 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4965,8 +4965,28 @@ void free_xen_pagetable_new(mfn_t mfn) free_xenheap_page(mfn_to_virt(mfn_x(mfn))); } =20 +void *alloc_map_clear_xen_pt(mfn_t *pmfn) +{ + mfn_t mfn =3D alloc_xen_pagetable_new(); + void *ret; + + if ( mfn_eq(mfn, INVALID_MFN) ) + return NULL; + + if ( pmfn ) + *pmfn =3D mfn; + ret =3D map_domain_page(mfn); + clear_page(ret); + + return ret; +} + static DEFINE_SPINLOCK(map_pgdir_lock); =20 +/* + * For virt_to_xen_lXe() functions, they take a linear 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; @@ -4975,33 +4995,33 @@ 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(); + mfn_t l3mfn; + l3_pgentry_t *l3t =3D alloc_map_clear_xen_pt(&l3mfn); =20 if ( !l3t ) return NULL; - 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; + l3_pgentry_t *pl3e, l3e; =20 pl3e =3D virt_to_xen_l3e(v); if ( !pl3e ) @@ -5010,31 +5030,37 @@ 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(); + mfn_t l2mfn; + l2_pgentry_t *l2t =3D alloc_map_clear_xen_pt(&l2mfn); =20 if ( !l2t ) + { + unmap_domain_page(pl3e); return NULL; - 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); + l3e =3D *pl3e; + unmap_domain_page(pl3e); + + return map_l2t_from_l3e(l3e) + l2_table_offset(v); } =20 l1_pgentry_t *virt_to_xen_l1e(unsigned long v) { - l2_pgentry_t *pl2e; + l2_pgentry_t *pl2e, l2e; =20 pl2e =3D virt_to_xen_l2e(v); if ( !pl2e ) @@ -5043,26 +5069,32 @@ 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(); + mfn_t l1mfn; + l1_pgentry_t *l1t =3D alloc_map_clear_xen_pt(&l1mfn); =20 if ( !l1t ) + { + unmap_domain_page(pl2e); return NULL; - 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); + l2e =3D *pl2e; + unmap_domain_page(pl2e); + + return map_l1t_from_l2e(l2e) + l1_table_offset(v); } =20 /* Convert to from superpage-mapping flags for map_pages_to_xen(). */ @@ -5085,8 +5117,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; @@ -5107,6 +5139,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 ) @@ -5275,6 +5311,8 @@ int map_pages_to_xen( 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 ) { @@ -5451,6 +5489,8 @@ int map_pages_to_xen( rc =3D 0; =20 out: + unmap_domain_page(pl2e); + unmap_domain_page(pl3e); return rc; } =20 @@ -5474,7 +5514,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; @@ -5490,6 +5530,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) ) @@ -5718,6 +5761,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/mm.h b/xen/include/asm-x86/mm.h index 7e74996053..5b76308948 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -586,6 +586,7 @@ 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); +void *alloc_map_clear_xen_pt(mfn_t *pmfn); =20 l1_pgentry_t *virt_to_xen_l1e(unsigned long v); =20 diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index f632affaef..608a048c28 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -291,7 +291,15 @@ 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))= ; \ + mfn_t mfn_; = \ + BUG_ON(!pl1e_); = \ + mfn_ =3D l1e_get_mfn(*pl1e_); = \ + unmap_domain_page(pl1e_); = \ + mfn_; }) + #define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va)) =20 #endif /* !defined(__ASSEMBLY__) */ --=20 2.16.6 From nobody Fri Mar 29 13:53:58 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=1595859771; cv=none; d=zohomail.com; s=zohoarc; b=ZqyMMwaN9nX/pJXvDZUnyiGGAhvsMK4hi5HYjIl3PHcSI3qgAgSpSd3IkBrlbalVjBI2T48dmbwzIRcAP5UKNXeV6qzQZkxt5shVPsln3SuoJdXnGiWCbdesfUa6EKDu32JBoCS7N3Szg8oFeB38Yv93lL9dT3rBjFHyyKGbuFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859771; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=rrvEqUYSNkuezZ5dZTBgKV5PBSNHpJAjMPmahuBCeZs=; b=KKeaQpODsUiwnvbU40asEzk8We8sUPYb2stqXD5MBezJAK81VW0O4WP7u8pwtsuTRMetfgnXaPDue2ScBCgSPg+peXkP2g6FL1AMUUugXj/8o96ZZbZyxbfMVTWtDNYimmWXTUx6Knuz8iCSL+3nbaHzpm2Y7oAtnELSi3P7Jqo= 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 1595859771179682.134551830915; Mon, 27 Jul 2020 07:22: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 1k041U-0007BE-1s; Mon, 27 Jul 2020 14:22:36 +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 1k041S-00075u-Oh for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:34 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 96c539ee-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041H-0001NZ-AF; Mon, 27 Jul 2020 14:22:23 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041H-0002w6-1D; Mon, 27 Jul 2020 14:22:23 +0000 X-Inumbo-ID: 96c539ee-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rrvEqUYSNkuezZ5dZTBgKV5PBSNHpJAjMPmahuBCeZs=; b=Unt2X3o3HL7/gE5t6VkgQ38lpd pNcOcfD+m8KiwACwOtMGa4rO/kfLMrD5+EkksjJn/2s/Gm/y8cy0kFhcsLNSr3NLxZBzqCI/3MKEc cWtkSDCy4DV6bzgsnyJQeumLE49kdhBZbSZHmatvrN40lWhZafSpVti0BDHyBcISqc+M=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 04/15] x86/mm: switch to new APIs in map_pages_to_xen Date: Mon, 27 Jul 2020 15:21:54 +0100 Message-Id: <248e86f82ae0d0d6bf661e6a180874437efacca4.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Page tables allocated in that function should be mapped and unmapped now. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- 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 fd416c0282..edcf164742 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5171,7 +5171,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++ ) { @@ -5183,10 +5183,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); @@ -5195,9 +5196,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 @@ -5214,6 +5216,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 * @@ -5235,15 +5238,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; @@ -5253,15 +5258,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); @@ -5289,12 +5294,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 @@ -5319,6 +5325,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)) + @@ -5338,14 +5345,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; @@ -5355,20 +5364,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); @@ -5412,12 +5422,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, @@ -5427,7 +5438,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); @@ -5460,7 +5471,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++ ) @@ -5468,6 +5479,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, @@ -5477,7 +5489,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595859778; cv=none; d=zohomail.com; s=zohoarc; b=mYlDTJwK4/m3hjsA2AZOKA9nHJY/1LomEuqUtAlZWDK7PsS4Jn8rLFLPIEZxkKeeA4TtCCJqYxJh+WZErxE5goRChZGwxo5o4TlaYaqmq/LznzVtA82Vo2igXzsl+ynoYc+FCmpnsSUcu02H3x2Xf2HdtsB73yZXuKA8/28TVA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859778; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=AzKnclrIuNpwqMYiGGxlH4mfYS6y6TwghSOhmo8lMtw=; b=D0k6XzrJ51/hJ7oZoGQkbs167IB2hvu4BmAjigXgKrwuYFYkdpcUc+BvtxqigABVInrLuoZA7wMsakTSy/36UD7q47k3JskU7x4eJO0jsoai1SDGl+SAoqBJvgFX7PuerzP0813GdO+yt+lMGXFSKXd9RDiTIEwLLIKzzzrNKT4= 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 1595859778488202.17345943047837; Mon, 27 Jul 2020 07:22: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 1k041Z-0007EB-FR; Mon, 27 Jul 2020 14:22:41 +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 1k041X-00075u-Oi for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:39 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 97b8bd62-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:25 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041I-0001Nh-Oc; Mon, 27 Jul 2020 14:22:24 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041I-0002w6-FS; Mon, 27 Jul 2020 14:22:24 +0000 X-Inumbo-ID: 97b8bd62-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AzKnclrIuNpwqMYiGGxlH4mfYS6y6TwghSOhmo8lMtw=; b=G79OtY2+doo2xGMiNfvs+QXMm3 idsuWZkZf8PIsbZnByjOzZIWad+7pdqIgaktWer5y2WBE1l6HE5jazFy+M05I0b1FGjk5ZmMjbaKD ieAfsjCGbvRMMGO0OB0IrSD4VRiMFeucNz6FYir+9ncEc/fC1A6JEvUl9+89mdn/q7Cw=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 05/15] x86/mm: switch to new APIs in modify_xen_mappings Date: Mon, 27 Jul 2020 15:21:55 +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 , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu 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 Reviewed-by: Jan Beulich --- Changed in v7: - use normal unmap in the error path. --- 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 edcf164742..199940a345 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5527,7 +5527,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; @@ -5543,6 +5543,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); @@ -5560,6 +5561,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 && @@ -5576,35 +5578,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) ) { @@ -5632,41 +5637,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) ) @@ -5677,6 +5686,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 /* @@ -5706,10 +5716,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. */ @@ -5717,7 +5729,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); @@ -5748,11 +5760,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. */ @@ -5760,7 +5774,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); @@ -5773,6 +5787,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595859781; cv=none; d=zohomail.com; s=zohoarc; b=ZUlAnHLDWKDTUm/2ngRGFqXt4B8vz2tlEIIG62luKRuZS1HJ8/sYfp44Vjk/9diN9W4UiXfbAemnKyJJ6EO29v5TQ69QJWr5vD3qMYf3ObNycP7TvNPvmAqENpvfeNjgeAr9o+OXLd+IyeWdvbWFbdB3aGg07QqB0SXaVvnzW/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859781; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=p+Zha4UMAvAuCQ2vvLKkoAQIt1J/pkiKRu6ISLJk4/g=; b=TRi53CCGLEiu477Z246OCTibyIzHATW0rAZg1hu5ig86fXCnYnzuE/38AsAl307LrFh5jyZt33T6E9lH/NjkMW5GwIve19c8S0qYdOead+E/Hh1Gt86t3ru73Dr3eyLtZIfy5oYS6D1nXSvRqDwrOuPNcUKhu10OXGdHWhygnCw= 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 1595859781577114.94606450799483; Mon, 27 Jul 2020 07:23:01 -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 1k041e-0007Gl-Pm; Mon, 27 Jul 2020 14:22:46 +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 1k041c-00075u-Os for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 989d5e54-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:26 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041K-0001Nr-74; Mon, 27 Jul 2020 14:22:26 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041J-0002w6-U2; Mon, 27 Jul 2020 14:22:26 +0000 X-Inumbo-ID: 989d5e54-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=p+Zha4UMAvAuCQ2vvLKkoAQIt1J/pkiKRu6ISLJk4/g=; b=a+BF/QpCrT3d6dXzIQMg8IhgX5 cxuYa+p3SMX7YBl6wvl86e4p5d8FHsc5qeauSykhH8NQtQ+Y3m25QQMWX11sceooBuh3HCb557jXa rvCUsxJdqpsh2Z7zrfTCWf3VA6Yq9yxTv66UgOEBx2ZF4Gle1y9ZQryQr+8C7ih/KGmw=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 06/15] x86_64/mm: introduce pl2e in paging_init Date: Mon, 27 Jul 2020 15:21:56 +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 , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu We will soon map and unmap pages in paging_init(). 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 Acked-by: Jan Beulich --- Changed in v7: - reword commit message. --- 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 102079a801..243014a119 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.16.6 From nobody Fri Mar 29 13:53:58 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=1595859786; cv=none; d=zohomail.com; s=zohoarc; b=W6Ut+NXgVHZQCwq4y6pWQLzdTn1gK/FlnERmG2/OL/tbAFBttSOO6ut310Kt9wKzuV9/6hdZ1ARqPR+/wFfGp+E+LaumeT6x0TlOlisL0AqupFg/v7UunBWWnl5ev+6Q2K7B6Je9Tq2eLDMkg422VVnKLpmXM4xyYde7FpGFSbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859786; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=SodIzhOZtWgd7aTAQdqyttar/iXLlUvG2VmsW7l5TFQ=; b=jBS++EV0RlrQW/ODZOnv1R3U6ynhIJnS/NcqSr+4V7MKPcwtuaqLlvQVZxzNJdiLEPfhNA0fke2az0crjbcjkpoyf9v8jxPiRCPR3O1ybK+7u2W5QPUrufd0nOHSIDY9ikSIbz0BpI9bKLl1BEfA16zMXvoTQEHRBZPqbV7kiKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1595859786406724.0225906618496; Mon, 27 Jul 2020 07:23:06 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041j-0007J5-2L; Mon, 27 Jul 2020 14:22:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041h-00075u-Ot for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:49 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 997d665c-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:28 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041L-0001Nz-Lu; Mon, 27 Jul 2020 14:22:27 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041L-0002w6-CO; Mon, 27 Jul 2020 14:22:27 +0000 X-Inumbo-ID: 997d665c-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=SodIzhOZtWgd7aTAQdqyttar/iXLlUvG2VmsW7l5TFQ=; b=0MxQzMgiFwdBg7PVvBvEoRmhDU E+yUT9+or+HWVwiyfn/D/ThmQHPkk8ENXofnZKH/Tfg7+dgXzV2n89oCGEDP/GnS7rUgoa2ouApYP qD2CqRZUMkoZNz3vX6myjYybY7nPLHpXECQsEwCrb2ihUbISBsHacV1vS0wDBa3No5Fg=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 07/15] x86_64/mm: switch to new APIs in paging_init Date: Mon, 27 Jul 2020 15:21:57 +0100 Message-Id: <9919850a82a7f189de2b5dcc62c55bc9d5337c4b.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Map and unmap pages instead of relying on the direct map. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v8: - replace l3/2_ro_mpt_mfn with just mfn since their lifetimes do not overlap Changed in v7: - use the new alloc_map_clear_xen_pt() helper. - move the unmap of pl3t up a bit. - remove the unmaps in the nomem path. --- xen/arch/x86/x86_64/mm.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 243014a119..ebf21d505b 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -481,6 +481,7 @@ void __init paging_init(void) l3_pgentry_t *l3_ro_mpt; l2_pgentry_t *pl2e =3D NULL, *l2_ro_mpt =3D NULL; struct page_info *l1_pg; + mfn_t mfn; =20 /* * We setup the L3s for 1:1 mapping if host support memory hotplug @@ -493,22 +494,23 @@ void __init paging_init(void) if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & _PAGE_PRESENT) ) { - l3_pgentry_t *pl3t =3D alloc_xen_pagetable(); + mfn_t l3mfn; + l3_pgentry_t *pl3t =3D alloc_map_clear_xen_pt(&l3mfn); =20 if ( !pl3t ) goto nomem; - clear_page(pl3t); + UNMAP_DOMAIN_PAGE(pl3t); l4e_write(&idle_pg_table[l4_table_offset(va)], - l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW)); + l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR_RW)); } } =20 /* Create user-accessible L2 directory to map the MPT for guests. */ - if ( (l3_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + l3_ro_mpt =3D alloc_map_clear_xen_pt(&mfn); + if ( !l3_ro_mpt ) goto nomem; - clear_page(l3_ro_mpt); l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)], - l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE= _USER)); + l4e_from_mfn(mfn, __PAGE_HYPERVISOR_RO | _PAGE_USER)); =20 /* * Allocate and map the machine-to-phys table. @@ -591,12 +593,14 @@ void __init paging_init(void) } if ( !((unsigned long)pl2e & ~PAGE_MASK) ) { - if ( (l2_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + + l2_ro_mpt =3D alloc_map_clear_xen_pt(&mfn); + if ( !l2_ro_mpt ) goto nomem; - clear_page(l2_ro_mpt); + l3e_write(&l3_ro_mpt[l3_table_offset(va)], - l3e_from_paddr(__pa(l2_ro_mpt), - __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l3e_from_mfn(mfn, __PAGE_HYPERVISOR_RO | _PAGE_USER)= ); pl2e =3D l2_ro_mpt; ASSERT(!l2_table_offset(va)); } @@ -608,13 +612,16 @@ void __init paging_init(void) } #undef CNT #undef MFN + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + UNMAP_DOMAIN_PAGE(l3_ro_mpt); =20 /* Create user-accessible L2 directory to map the MPT for compat guest= s. */ - if ( (l2_ro_mpt =3D alloc_xen_pagetable()) =3D=3D NULL ) + mfn =3D alloc_xen_pagetable_new(); + if ( mfn_eq(mfn, INVALID_MFN) ) goto nomem; - compat_idle_pg_table_l2 =3D l2_ro_mpt; - clear_page(l2_ro_mpt); - pl2e =3D l2_ro_mpt; + compat_idle_pg_table_l2 =3D map_domain_page_global(mfn); + clear_page(compat_idle_pg_table_l2); + pl2e =3D compat_idle_pg_table_l2; /* Allocate and map the compatibility mode machine-to-phys table. */ mpt_size =3D (mpt_size >> 1) + (1UL << (L2_PAGETABLE_SHIFT - 1)); if ( mpt_size > RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START ) --=20 2.16.6 From nobody Fri Mar 29 13:53:58 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=1595859791; cv=none; d=zohomail.com; s=zohoarc; b=e9xLY+3IqcO8h4ozXnlCO2j1kx2dhhZKrfIArv+bWknZtrjf923K7rCk+hTuVsIFlIuaq2fbWZ/5xLDhtfArFz5CwsKZv9wWbJCrdPpu+HVN8A1RZpscKxNZvA+KDtjgjUEoFd8A2rK4V0brzC5SxKVnexc+mr/YRvYqssmymjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859791; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fUz58rQHZzbX7UbQq79ICRTvYmlrlPqPrctCYP9EW/8=; b=Iml8mx4bXWogO5yUCWoSFMzsnlWOv/EvEwjogoyqDd5QpoQC+q7gGTYsEMTZbL2GRsCGy4oQbTAb2nhhMeFwbaO73Fq3rF5Da/S9wD730axdZLPMQo5Y4TbIxIXtc078iH8hkLEKfr7Ow6t3NGw6UKGYGezrMGAEymLdO//7PZo= 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 1595859791900713.1850497182637; Mon, 27 Jul 2020 07:23:11 -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 1k041o-0007MW-Cz; Mon, 27 Jul 2020 14:22:56 +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 1k041m-00075u-P5 for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:54 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9a3215de-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:29 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041N-0001O5-3P; Mon, 27 Jul 2020 14:22:29 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041M-0002w6-Qc; Mon, 27 Jul 2020 14:22:29 +0000 X-Inumbo-ID: 9a3215de-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fUz58rQHZzbX7UbQq79ICRTvYmlrlPqPrctCYP9EW/8=; b=iAvA+u+KbfebHtfq3XewBXJjf7 gw+Fp0x0DhASWsqn/5/3m5NtHvbLdf9QEznYZqKlGZATniUgtxZauAzvI2o5vmpMF+ccTHImYLUek 4M4IfMES0LIbHGLfjQ8r1VgxL7gg+JTnb9QGOfNtbZA68Ui+B3OZrI2qCjL+k3feZVLA=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 08/15] x86_64/mm: switch to new APIs in setup_m2p_table Date: Mon, 27 Jul 2020 15:21:58 +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 , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu While doing so, avoid repetitive mapping of l2_ro_mpt by keeping it across loops, and only unmap and map it when crossing 1G boundaries. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v8: - re-structure if condition around l2_ro_mpt. - reword the commit message. Changed in v7: - avoid repetitive mapping of l2_ro_mpt. - edit commit message. - switch to alloc_map_clear_xen_pt(). --- xen/arch/x86/x86_64/mm.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index ebf21d505b..640f561faf 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -385,7 +385,8 @@ static int setup_m2p_table(struct mem_hotadd_info *info) =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 )) & @@ -403,6 +404,10 @@ static int setup_m2p_table(struct mem_hotadd_info *inf= o) i =3D smap; while ( i < emap ) { + if ( (RO_MPT_VIRT_START + i * sizeof(*machine_to_phys_mapping)) & + ((1UL << L3_PAGETABLE_SHIFT) - 1) ) + UNMAP_DOMAIN_PAGE(l2_ro_mpt); + switch ( m2p_mapped(i) ) { case M2P_1G_MAPPED: @@ -438,32 +443,31 @@ static int setup_m2p_table(struct mem_hotadd_info *in= fo) =20 ASSERT(!(l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & _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); + if ( l2_ro_mpt ) + /* nothing */; + else if ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & + _PAGE_PRESENT ) + l2_ro_mpt =3D map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(v= a)]); else { - l2_ro_mpt =3D alloc_xen_pagetable(); + mfn_t l2_ro_mpt_mfn; + + l2_ro_mpt =3D alloc_map_clear_xen_pt(&l2_ro_mpt_mfn); if ( !l2_ro_mpt ) { ret =3D -ENOMEM; goto error; } =20 - 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)); } =20 /* NB. Cannot be GLOBAL: guest user mode should not see it. */ - l2e_write(l2_ro_mpt, l2e_from_mfn(mfn, + l2e_write(&l2_ro_mpt[l2_table_offset(va)], l2e_from_mfn(mfn, /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); } - if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) - l2_ro_mpt =3D NULL; i +=3D ( 1UL << (L2_PAGETABLE_SHIFT - 3)); } #undef CNT @@ -471,6 +475,8 @@ static int setup_m2p_table(struct mem_hotadd_info *info) =20 ret =3D setup_compat_m2p_table(info); error: + unmap_domain_page(l2_ro_mpt); + unmap_domain_page(l3_ro_mpt); return ret; } =20 --=20 2.16.6 From nobody Fri Mar 29 13:53:58 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=1595859796; cv=none; d=zohomail.com; s=zohoarc; b=dLuo8uvKKOoGOFvYgOxfvXLy+WMJsSkwj9oGYm46VDeUPzoCN3lCdkpQOIxyrk9PcDEOtDfxH4OrSeos/9VLux2719xPPO0yq4MMtUfiWRj0xUhgHQ9Xnze/hvEpQNhUSAmBlO5lZOTwmHLonhR0G5rh9UEILg2ZNBvoulLZy7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595859796; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=y74N3TUfvk3AYiEnS0qck1kYQhbnuTest5No5Q+t0p8=; b=Yi+Oy54wwW3TiXH6XNyf2Uzac9RjX2xwxgHMpeldfKYaKr2KyT0bIDB2eeMeb18suzkQ2F3UzYmbSPb3nz/y1mgKfgNljxDA1enmnLlK1hbb4ASJt6w3qJFe28UGdLuNou6oV9dPdDMRpShLyArcdNv9jXMj3CGOovsdvVRe8PU= 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 1595859796325255.4981854551479; Mon, 27 Jul 2020 07:23:16 -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 1k041s-0007RR-Rd; Mon, 27 Jul 2020 14:23:00 +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 1k041r-00075u-P6 for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:22:59 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9a3215df-d014-11ea-a7d9-12813bfff9fa; Mon, 27 Jul 2020 14:22:30 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k041O-0001OC-5W; Mon, 27 Jul 2020 14:22:30 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041N-0002w6-SZ; Mon, 27 Jul 2020 14:22:30 +0000 X-Inumbo-ID: 9a3215df-d014-11ea-a7d9-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=y74N3TUfvk3AYiEnS0qck1kYQhbnuTest5No5Q+t0p8=; b=JbCvw1xbywxErlbJoPNr88Lugh iZ3LfHY6W9ihNpKRjpIGRvgVGSHgso8/IEEyyIrIdpG22awMosHugnTLCTjubtUuID2QmPzTBxiIU jCE5PP/EvUmucSpThm8wFkEOMdMT/So67ls45lF9oEYFtWK8lOqCyje1symr6jnV/qc0=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 09/15] efi: use new page table APIs in copy_mapping Date: Mon, 27 Jul 2020 15:21:59 +0100 Message-Id: <971376c3e2c04248ca0e5ef53ce59b8207bf1c6e.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: jgrall@amazon.com, 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 Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v8: - remove redundant commit message. - unmap l3src based on va instead of mfn. - re-structure if condition around l3dst. Changed in v7: - hoist l3 variables out of the loop to avoid repetitive mappings. --- xen/common/efi/boot.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 5a520bf21d..f116759538 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,29 +1443,42 @@ static __init void copy_mapping(unsigned long mfn, = unsigned long end, unsigned long emfn)) { unsigned long next; + l3_pgentry_t *l3src =3D NULL, *l3dst =3D NULL; =20 for ( ; mfn < end; mfn =3D next ) { l4_pgentry_t l4e =3D efi_l4_pgtable[l4_table_offset(mfn << PAGE_SH= IFT)]; - l3_pgentry_t *l3src, *l3dst; unsigned long va =3D (unsigned long)mfn_to_virt(mfn); =20 + if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) ) + UNMAP_DOMAIN_PAGE(l3dst); + if ( !(va & ((1UL << L4_PAGETABLE_SHIFT) - 1)) ) + UNMAP_DOMAIN_PAGE(l3src); next =3D mfn + (1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)); if ( !is_valid(mfn, min(next, end)) ) continue; - if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) + + if ( l3dst ) + /* nothing */; + else if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - l3dst =3D alloc_xen_pagetable(); + mfn_t l3mfn; + + l3dst =3D alloc_map_clear_xen_pt(&l3mfn); BUG_ON(!l3dst); - 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); + + if ( !l3src ) + 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 static bool __init ram_range_valid(unsigned long smfn, unsigned long emfn) --=20 2.16.6 From nobody Fri Mar 29 13:53:58 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=1595860819; cv=none; d=zohomail.com; s=zohoarc; b=Y/W7Bcx/3ohnmm95Qcz5yhbau42JZzXLQV5p2hUO1Cfg/eR968PjHrn04Hie+EvIEpPhTqDQtnEvYkUF+Z0sR/Rb2Z1K+PVRZsISQgY4UnWG/zHR88Fe4Xo0tDrx51W//2n60KHeOWeRsxkojPQFsJ2bJRqJ+MYHgfbaQ5dKNls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860819; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=W32xTjpvUmjvkngH88KQETVFnfyWGChOM6HrUWd8JKI=; b=LWw3Bj4bIqJ5BHx1YIA9/fS3XEFcC6kBQIYvwZJU4d97598Fu3Ns8zikKdZrEe+xX8H8HnBFGb1U2IQCxrGf2yA0vGo5Kl520NclEyBFJ/2+EOk6pk7FNvFsCgcfgZ7gXUEsMYtOK2dgKMz3FdcY/4lEiv41TthmVFZv4JRe83M= 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 1595860819241579.0753850746489; Mon, 27 Jul 2020 07:40:19 -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 1k04IN-0000r2-17; Mon, 27 Jul 2020 14:40:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IL-0000dt-8s for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:40:01 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 06d6f414-d017-11ea-8ac7-bc764e2007e4; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IA-0001kt-9C; Mon, 27 Jul 2020 14:39:50 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041P-0002w6-AP; Mon, 27 Jul 2020 14:22:31 +0000 X-Inumbo-ID: 06d6f414-d017-11ea-8ac7-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=W32xTjpvUmjvkngH88KQETVFnfyWGChOM6HrUWd8JKI=; b=OzLNH4tNvAMKFTottAU2hdC/tf aLEbyJxKp5lYQvkMXBeeLnzpSwljDA/awYuX7ZJWGW2CN+BwLhdsJmjHxfCOznkrKXWXrPb1QIZJb rCj0kJnKoZYjXxNgWee5JGh2lqcBWlVrWYJriGP6bXFPCyaJWfu33XHPoltRUaObrbjI=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 10/15] efi: switch to new APIs in EFI code Date: Mon, 27 Jul 2020 15:22:00 +0100 Message-Id: <9f824496cf87c1f282d774562456ba5d51ce7979.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v7: - add blank line after declaration. - rename efi_l4_pgtable into efi_l4t. - pass the mapped efi_l4t to copy_mapping() instead of map it again. - use the alloc_map_clear_xen_pt() API. - unmap pl3e, pl2e, l1t earlier. --- xen/arch/x86/efi/runtime.h | 13 ++++++++--- xen/common/efi/boot.c | 55 +++++++++++++++++++++++++++---------------= ---- xen/common/efi/efi.h | 3 ++- xen/common/efi/runtime.c | 8 +++---- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/efi/runtime.h b/xen/arch/x86/efi/runtime.h index d9eb8f5c27..77866c5f21 100644 --- a/xen/arch/x86/efi/runtime.h +++ b/xen/arch/x86/efi/runtime.h @@ -1,12 +1,19 @@ +#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 ) - l4e_write(efi_l4_pgtable + l4idx, l4e); + if ( !mfn_eq(efi_l4_mfn, INVALID_MFN) ) + { + l4_pgentry_t *efi_l4t =3D map_domain_page(efi_l4_mfn); + + l4e_write(efi_l4t + l4idx, l4e); + unmap_domain_page(efi_l4t); + } } #endif diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index f116759538..f2f1dbbc77 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1440,14 +1440,15 @@ custom_param("efi", parse_efi_param); =20 static __init void copy_mapping(unsigned long mfn, unsigned long end, bool (*is_valid)(unsigned long smfn, - unsigned long emfn)) + unsigned long emfn), + l4_pgentry_t *efi_l4t) { unsigned long next; l3_pgentry_t *l3src =3D NULL, *l3dst =3D NULL; =20 for ( ; mfn < end; mfn =3D next ) { - l4_pgentry_t l4e =3D efi_l4_pgtable[l4_table_offset(mfn << PAGE_SH= IFT)]; + l4_pgentry_t l4e =3D efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)]; unsigned long va =3D (unsigned long)mfn_to_virt(mfn); =20 if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) ) @@ -1466,7 +1467,7 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, =20 l3dst =3D alloc_map_clear_xen_pt(&l3mfn); BUG_ON(!l3dst); - efi_l4_pgtable[l4_table_offset(mfn << PAGE_SHIFT)] =3D + efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)] =3D l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR); } else @@ -1499,6 +1500,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_l4t; struct rt_extra { struct rt_extra *next; unsigned long smfn, emfn; @@ -1613,11 +1615,10 @@ 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); - clear_page(efi_l4_pgtable); + efi_l4t =3D alloc_map_clear_xen_pt(&efi_l4_mfn); + BUG_ON(!efi_l4t); =20 - copy_mapping(0, max_page, ram_range_valid); + copy_mapping(0, max_page, ram_range_valid, efi_l4t); =20 /* Insert non-RAM runtime mappings inside the direct map. */ for ( i =3D 0; i < efi_memmap_size; i +=3D efi_mdesc_size ) @@ -1633,58 +1634,64 @@ void __init efi_init_memory(void) copy_mapping(PFN_DOWN(desc->PhysicalStart), PFN_UP(desc->PhysicalStart + (desc->NumberOfPages << EFI_PAGE_SHIFT)), - rt_range_valid); + rt_range_valid, efi_l4t); } =20 /* Insert non-RAM runtime mappings outside of the direct map. */ while ( (extra =3D extra_head) !=3D NULL ) { unsigned long addr =3D extra->smfn << PAGE_SHIFT; - l4_pgentry_t l4e =3D efi_l4_pgtable[l4_table_offset(addr)]; + l4_pgentry_t l4e =3D efi_l4t[l4_table_offset(addr)]; l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; l1_pgentry_t *l1t; =20 if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) { - pl3e =3D alloc_xen_pagetable(); + mfn_t l3mfn; + + pl3e =3D alloc_map_clear_xen_pt(&l3mfn); BUG_ON(!pl3e); - clear_page(pl3e); - efi_l4_pgtable[l4_table_offset(addr)] =3D - l4e_from_paddr(virt_to_maddr(pl3e), __PAGE_HYPERVISOR); + efi_l4t[l4_table_offset(addr)] =3D + 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(); + mfn_t l2mfn; + + pl2e =3D alloc_map_clear_xen_pt(&l2mfn); BUG_ON(!pl2e); - 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); } + UNMAP_DOMAIN_PAGE(pl3e); pl2e +=3D l2_table_offset(addr); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - l1t =3D alloc_xen_pagetable(); + mfn_t l1mfn; + + l1t =3D alloc_map_clear_xen_pt(&l1mfn); BUG_ON(!l1t); - 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); } + UNMAP_DOMAIN_PAGE(pl2e); for ( i =3D l1_table_offset(addr); i < L1_PAGETABLE_ENTRIES && extra->smfn < extra->emfn; ++i, ++extra->smfn ) l1t[i] =3D l1e_from_pfn(extra->smfn, extra->prot); + UNMAP_DOMAIN_PAGE(l1t); =20 if ( extra->smfn =3D=3D extra->emfn ) { @@ -1696,6 +1703,8 @@ void __init efi_init_memory(void) /* 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]; + efi_l4t[i] =3D idle_pg_table[i]; + + unmap_domain_page(efi_l4t); } #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.16.6 From nobody Fri Mar 29 13:53:58 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=1595860813; cv=none; d=zohomail.com; s=zohoarc; b=N95oaTpbFAZNZWzzOLiOSq+lb3vQQ3iJbnYOB0YRi18NqqaQuS29izoNQwuTls4E2wvD7QIVJ85LJKhwmA+NJRA8eR63BNNzybLZMH/IhXzgTxknKTdomjwDOerQZAXrn03veXmjx8tzvhBcXKyF9qnKbN4mtX4/TJPxoeGoEqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860813; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0SVN7QjGjE3dnCfA1k5zj/jcGmdnfLnwdJ2VVUqhG5k=; b=O8DvKvKPcNeZFyfmsW0GIYMyl5nNxZyg1G8l/GpNnkHEktFXgQ+ID8INnLZcF5c6tknvCmGE+0pU4PzbbUkU20E0yGl51CQN7tvbyxtlF0b+q/IM4iX/ZC8/I2IOKKBOQKqUMALNF5vo14gnWUGZfGj5nOSa6ov4Oqajjg3z8gM= 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 1595860813393922.1212404447488; Mon, 27 Jul 2020 07:40:13 -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 1k04IC-0000e4-MU; Mon, 27 Jul 2020 14:39:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IB-0000dt-9p for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:39:51 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 06c97230-d017-11ea-8ac7-bc764e2007e4; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IA-0001kp-60; Mon, 27 Jul 2020 14:39:50 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041Q-0002w6-OG; Mon, 27 Jul 2020 14:22:33 +0000 X-Inumbo-ID: 06c97230-d017-11ea-8ac7-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=0SVN7QjGjE3dnCfA1k5zj/jcGmdnfLnwdJ2VVUqhG5k=; b=WonXnoIWsAqA230psvX0In7bWl uVzIRmyiajs2qXzMAeSNEdQ1atSLNx1KeTWA4BDng/75VqLa26X70uHJi5Q4lg2bAI7T94IdQGQx0 4AxmW14Ua6+sqiJr6c/EDM6OLN/uFEwFC10xYOK41gepNkgHc40jZN6JCKfbMn4sS+t4=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 11/15] x86/smpboot: add exit path for clone_mapping() Date: Mon, 27 Jul 2020 15:22: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 , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu 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 --- Changed in v7: - edit commit message. - begin with rc =3D 0 and set it to -ENOMEM ahead of if(). --- 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 5708573c41..05df08f945 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -676,6 +676,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 0; =20 /* * Sanity check 'linear'. We only allow cloning from the Xen virtual @@ -716,7 +717,7 @@ 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; + goto out; pfn =3D l1e_get_pfn(*pl1e); } } @@ -724,8 +725,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) if ( !(root_get_flags(rpt[root_table_offset(linear)]) & _PAGE_PRESENT)= ) { pl3e =3D alloc_xen_pagetable(); + rc =3D -ENOMEM; if ( !pl3e ) - return -ENOMEM; + goto out; clear_page(pl3e); l4e_write(&rpt[root_table_offset(linear)], l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR)); @@ -738,8 +740,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { pl2e =3D alloc_xen_pagetable(); + rc =3D -ENOMEM; if ( !pl2e ) - return -ENOMEM; + goto out; clear_page(pl2e); l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR)); } @@ -754,8 +757,9 @@ static int clone_mapping(const void *ptr, root_pgentry_= t *rpt) if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { pl1e =3D alloc_xen_pagetable(); + rc =3D -ENOMEM; if ( !pl1e ) - return -ENOMEM; + goto out; clear_page(pl1e); l2e_write(pl2e, l2e_from_paddr(__pa(pl1e), __PAGE_HYPERVISOR)); } @@ -776,7 +780,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595860818; cv=none; d=zohomail.com; s=zohoarc; b=MBojfQ0lpWSCHPcua0eLcwMbLrY8xFKvVs4AXeNVIuYeRbOZvgbbRLzRBzQEnslNG9VQ6tcr9feCdzomjp4YRS7fxlbDJXD0d1KXmnI6Mf9GIM+9VXgtWx6BZY8ZVNmv+ukqp5pkg2m2Avnkw8380EWEFFmvb4+AHNL3CpmQQKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860818; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=UfyYK+8DzrY89B6vi2RzWDTZyEViNsi3rlfmpn5A0tM=; b=nIXReJAMLR2KRNGxqku/fO1X50k3i7kPpb93X5nbX64r1YmQX93k7aHMbscANax6TlDCyHPahLNB3eegnymX/V/41siy0u1ss5hkn8FWoFAVuL31oStdm11nnLc38RBVTQdr/oTqbNTTrGymuDjZgLoKkx3oFDEnieYPNF/PWLI= 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 1595860818709206.53581057756037; Mon, 27 Jul 2020 07:40:18 -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 1k04IN-0000s0-Bg; Mon, 27 Jul 2020 14:40:03 +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 1k04IL-0000dz-TU for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:40:01 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 06d48f12-d017-11ea-a7dc-12813bfff9fa; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IA-0001kr-7h; Mon, 27 Jul 2020 14:39:50 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041S-0002w6-6H; Mon, 27 Jul 2020 14:22:34 +0000 X-Inumbo-ID: 06d48f12-d017-11ea-a7dc-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=UfyYK+8DzrY89B6vi2RzWDTZyEViNsi3rlfmpn5A0tM=; b=CVI2Iz220Wao66SJqlzH+EpNvH q0mK8/PRAd6FkYSxyhbxBoSVsSUDhZq//saCiP6K9cZdK6PUporf2SQazRjjGzCoAf03cvD2nsIQ8 v4khyY/ctwk+7bovHMOxBp93meAi0Ud9LFgFRzAKEA2aHg+UZdA6mwRIN1vdypNigTXk=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 12/15] x86/smpboot: switch clone_mapping() to new APIs Date: Mon, 27 Jul 2020 15:22:02 +0100 Message-Id: <31b850b40373f4499f5f51a6e8c7f00f7adb67ec.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v7: - change patch title - remove initialiser of pl3e. - combine the initialisation of pl3e into a single assignment. - use the new alloc_map_clear() helper. - use the normal map_domain_page() in the error path. --- xen/arch/x86/smpboot.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 05df08f945..c965222e19 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -674,8 +674,8 @@ 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; + l2_pgentry_t *pl2e =3D NULL; + l1_pgentry_t *pl1e =3D NULL; int rc =3D 0; =20 /* @@ -690,7 +690,7 @@ 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)]) + + pl3e =3D map_l3t_from_l4e(idle_pg_table[root_table_offset(linear)]) + l3_table_offset(linear); =20 flags =3D l3e_get_flags(*pl3e); @@ -703,7 +703,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 ) @@ -714,7 +714,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) ) goto out; @@ -722,51 +722,58 @@ 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(); + mfn_t l3mfn; + + pl3e =3D alloc_map_clear_xen_pt(&l3mfn); rc =3D -ENOMEM; if ( !pl3e ) goto out; - 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(); + mfn_t l2mfn; + + pl2e =3D alloc_map_clear_xen_pt(&l2mfn); rc =3D -ENOMEM; if ( !pl2e ) goto out; - 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(); + mfn_t l1mfn; + + pl1e =3D alloc_map_clear_xen_pt(&l1mfn); rc =3D -ENOMEM; if ( !pl1e ) goto out; - 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); @@ -782,6 +789,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.16.6 From nobody Fri Mar 29 13:53:58 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=1595860816; cv=none; d=zohomail.com; s=zohoarc; b=XgIP1ovT1Zz9KbFjNKEr5grjbPbok0GH50FPo++Xr5Gq9Uijkd3r5vbOpPdAuPrd6o9GqNx4ZgqpvwVmiebkZMddo4k1b1tBisaM5q5mIjeJ64TzzXlSEraVY/Qdwzz2pEi6iV0o6TmRDasiSj7y1WOei70QUGTy1N3UD/Q7oug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860816; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Uq+2iB5atuihy3Lh1/f+rppWdOqqwU8mCB8CS1E3Jiw=; b=bhufWgKPNYT8qfJ7uvPZ+cuYdQHf+Zf/T46e7X+cltbhEtGABgsgJ7KIcOJkzh7Hs0USGBcRjufKFkIxktBNatLh3eHifDMX5YT/VlbA7oYaSRHRHvcUAOxRZqyfXlojnnM1pM5nyXM4/AsNutir8pn8woQyBy/5gNV1sYQK0z0= 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 159586081641839.60412094488777; Mon, 27 Jul 2020 07:40:16 -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 1k04II-0000g8-5q; Mon, 27 Jul 2020 14:39:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IG-0000dt-8j for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:39:56 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 06c71b7a-d017-11ea-8ac7-bc764e2007e4; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IA-0001kn-3c; Mon, 27 Jul 2020 14:39:50 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041T-0002w6-Ky; Mon, 27 Jul 2020 14:22:35 +0000 X-Inumbo-ID: 06c71b7a-d017-11ea-8ac7-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=Uq+2iB5atuihy3Lh1/f+rppWdOqqwU8mCB8CS1E3Jiw=; b=DBexqBYbHXsR73yk2bwDOmRR9F TJNRLR0NhDxNYHENtnhQQD7kqJ+vk926FhM50KXyAREqVIrT68sagGLIpvMPa/XxG9w/dtuAryyKs C5VwzEPPDjLKRTOw4bBPOckokc7PLg+wRuxbXmI8f7I8Q0uWsfBWfKvDN/behUCUvOQE=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 13/15] x86/mm: drop old page table APIs Date: Mon, 27 Jul 2020 15:22: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 , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: 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 199940a345..76b8c681c9 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4925,20 +4925,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 c9b6af826d..1f73589d5b 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1247,7 +1247,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? */ @@ -1257,7 +1257,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 c965222e19..f431f526da 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -810,7 +810,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 @@ -913,7 +913,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 5b76308948..1bd8198133 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -582,8 +582,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); void *alloc_map_clear_xen_pt(mfn_t *pmfn); diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 608a048c28..45ed561772 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.16.6 From nobody Fri Mar 29 13:53:58 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=1595860813; cv=none; d=zohomail.com; s=zohoarc; b=KBME8X5GfThR0opxndfUR5JDvIA+I00tefuPPhBFtJYyrIFuArW/FwwDg995dSw9cDEvxa4XxtEh12qCR01buXFdthf+XBel5VlwrdafTrBHzBQ0iBoudYRVWmfKbppjW2lXoihJFpkWXYw0gI9q8UzXomHuXbYIrb2qr6rzM+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860813; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5NW5X4tKkJdncJ3jCsyAFhkJXBFKJtHVYTfU6S+d5S0=; b=OZYSEdewFtkvsCRqWiYVUnCZurz2Tb/9D64Tvco9T3ypv0WlwNZ2QY8ukLMz42uOJG3jwIz6IpTGwW3bPn9bR1BkdhjkGTP5VxgVFv3MggdFANGAfkD9Z6SzGwOYeQAknEpy1Kv2jlA459LK9E5XdILX3xhYD4DCznae7DEcaac= 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 1595860813809871.5634987931688; Mon, 27 Jul 2020 07:40:13 -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 1k04II-0000gX-GF; Mon, 27 Jul 2020 14:39:58 +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 1k04IG-0000dz-TH for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:39:56 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 06b3e7f8-d017-11ea-a7dc-12813bfff9fa; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04I9-0001kj-Uo; Mon, 27 Jul 2020 14:39:49 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041V-0002w6-2v; Mon, 27 Jul 2020 14:22:37 +0000 X-Inumbo-ID: 06b3e7f8-d017-11ea-a7dc-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=5NW5X4tKkJdncJ3jCsyAFhkJXBFKJtHVYTfU6S+d5S0=; b=nD6Ce3tQfWBHg/ctqxHn3jozva xe8pRF309lfmlRrapwqOKGfGgV+d3/dcHc6OjmX1GDQfdDdTxcD9RfSrvfkY8buKwd3VQRy02v2BB iDDl2nRpjgIPcDX/3w88eQtFOpUkLzrv2M4eGIxdfKDfSIVBgIOFPy1/MgVHQC6SATBk=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 14/15] x86: switch to use domheap page for page tables Date: Mon, 27 Jul 2020 15:22:04 +0100 Message-Id: <53c9d3ced017091305a5fcf94bf3d74c58735c63.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v8: - const qualify pg in alloc_xen_pagetable_new(). --- xen/arch/x86/mm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 76b8c681c9..8348f6329f 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4935,10 +4935,10 @@ mfn_t alloc_xen_pagetable_new(void) { if ( system_state !=3D SYS_STATE_early_boot ) { - void *ptr =3D alloc_xenheap_page(); + const struct page_info *pg =3D alloc_domheap_page(NULL, 0); =20 - BUG_ON(!hardware_domain && !ptr); - return ptr ? virt_to_mfn(ptr) : INVALID_MFN; + BUG_ON(!hardware_domain && !pg); + return pg ? page_to_mfn(pg) : INVALID_MFN; } =20 return alloc_boot_pages(1, 1); @@ -4948,7 +4948,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 void *alloc_map_clear_xen_pt(mfn_t *pmfn) --=20 2.16.6 From nobody Fri Mar 29 13:53:58 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=1595860813; cv=none; d=zohomail.com; s=zohoarc; b=MSDUfI9XS+hj6sADwYBrToLSo9OLx0OkE+4bcK/Q4PDvx8TEfdS+uvOcKXGrqEBX1CYURcNd1e8FNe6Jx44eMgmjoKF5fNeSFYzgzFFvMY/miH/G9XxSBmD4brT6JVpp4z598XoLO15onV8aJRR4mek4nP+ldMhIQuDy3UmRDh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595860813; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ky65fKbvqZ7A8L5Gk8ErEdsQ2qdgoYphiYBmd6L4iJg=; b=SGewcRiINatzkkFwPwPxcUXpxKyNcZy0rV0hEfhyh3JuRkhMU2GX9R+X8vOk69+3seIPsLGPuiNaIGvkJSARMQSOlpyOzMYAjRyoUkcOtZQdpp6xPR1gZKkL03iAdBOG33REqAzH9MzdxgnyuBOSN2cosaSu0fF0dO71nNGNSPI= 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 1595860813359470.6750219979526; Mon, 27 Jul 2020 07:40:13 -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 1k04IC-0000eA-UD; Mon, 27 Jul 2020 14:39:52 +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 1k04IC-0000dz-0t for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 14:39:52 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 06c48874-d017-11ea-a7dc-12813bfff9fa; Mon, 27 Jul 2020 14:39:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k04IA-0001kl-1W; Mon, 27 Jul 2020 14:39:50 +0000 Received: from 54-240-197-233.amazon.com ([54.240.197.233] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k041W-0002w6-H1; Mon, 27 Jul 2020 14:22:38 +0000 X-Inumbo-ID: 06c48874-d017-11ea-a7dc-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=ky65fKbvqZ7A8L5Gk8ErEdsQ2qdgoYphiYBmd6L4iJg=; b=DVityTAwQyVGVd1B7Zqmo7qwz0 vevx4Ecb6lvT+slCDPePZ0AhFfzNmvQOEyGc77ehhHQM/d0F6+xt3YgPwihcyWRboZ9N9bpyXrDg3 NdHVJvlhalWof5smlhW08eCrKeI7PUxMmDjryzY5ypRY9/zl2nrZfWOnndl+WcofOeas=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH v8 15/15] x86/mm: drop _new suffix for page table APIs Date: Mon, 27 Jul 2020 15:22:05 +0100 Message-Id: <5ee357f27bb604305dca480fecb8b56e9de5d8d3.1595857947.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Liu No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Acked-by: Jan Beulich --- xen/arch/x86/mm.c | 44 ++++++++++++++++++++++---------------------- xen/arch/x86/smpboot.c | 6 +++--- xen/arch/x86/x86_64/mm.c | 2 +- xen/include/asm-x86/mm.h | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 8348f6329f..465a5bf0df 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) ) { @@ -4931,7 +4931,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 ) { @@ -4945,7 +4945,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)); @@ -4953,7 +4953,7 @@ void free_xen_pagetable_new(mfn_t mfn) =20 void *alloc_map_clear_xen_pt(mfn_t *pmfn) { - mfn_t mfn =3D alloc_xen_pagetable_new(); + mfn_t mfn =3D alloc_xen_pagetable(); void *ret; =20 if ( mfn_eq(mfn, INVALID_MFN) ) @@ -4999,7 +4999,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); @@ -5034,7 +5034,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); @@ -5073,7 +5073,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); @@ -5182,10 +5182,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 @@ -5224,7 +5224,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 @@ -5252,7 +5252,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); @@ -5286,7 +5286,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 @@ -5331,7 +5331,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 @@ -5358,7 +5358,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); @@ -5424,7 +5424,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); @@ -5475,7 +5475,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); @@ -5564,7 +5564,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 @@ -5588,7 +5588,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 /* @@ -5624,7 +5624,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; @@ -5648,7 +5648,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 @@ -5715,7 +5715,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); @@ -5760,7 +5760,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 f431f526da..a01412a986 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -902,15 +902,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 640f561faf..74c0bbb4aa 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -622,7 +622,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. */ - mfn =3D alloc_xen_pagetable_new(); + mfn =3D alloc_xen_pagetable(); if ( mfn_eq(mfn, INVALID_MFN) ) goto nomem; compat_idle_pg_table_l2 =3D map_domain_page_global(mfn); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 1bd8198133..908d67664d 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -582,8 +582,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); void *alloc_map_clear_xen_pt(mfn_t *pmfn); =20 l1_pgentry_t *virt_to_xen_l1e(unsigned long v); --=20 2.16.6