From patchwork Thu Sep 26 09:45:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C0B913BD for ; Thu, 26 Sep 2019 09:49:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08662222C0 for ; Thu, 26 Sep 2019 09:49:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="FF0d+H7G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08662222C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQNZ-00043J-47; Thu, 26 Sep 2019 09:48:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQNX-00040s-EB for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:48:03 +0000 X-Inumbo-ID: b81891da-e042-11e9-8628-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by localhost (Halon) with ESMTPS id b81891da-e042-11e9-8628-bc764e2007e4; Thu, 26 Sep 2019 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491277; x=1601027277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=6giu/6ArwPKfshJRzAHbKeKdI/4RdevVJDy7m7l1cF4=; b=FF0d+H7Gjwrcd6rO6yoXQUgIDUH530so10zF8Y1J1VVB3+B42pgVyKIN kToPnD9kNIJKF7Voe3JKSm2CMxvM5HLxTRPaLuYjnyXFgU3JZORiJ5Ybx CXPblCmQm/KAaGBTNrWR4jwkFyfRpkeYGqcZHLyIEgUrOWIxJ/mDzAKEI E=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="787535042" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 26 Sep 2019 09:47:56 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 39F51A2A65; Thu, 26 Sep 2019 09:47:54 +0000 (UTC) Received: from EX13P01UWA004.ant.amazon.com (10.43.160.127) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:47:27 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13P01UWA004.ant.amazon.com (10.43.160.127) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:47:26 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.58) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 26 Sep 2019 09:47:25 +0000 From: To: Date: Thu, 26 Sep 2019 10:45:41 +0100 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [RFC PATCH 18/84] x86/mm: drop lXe_to_lYe invocations in map_pages_to_xen X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu Map and unmap page tables where necessary. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 267e4ceef5..2333e93151 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5141,8 +5141,10 @@ int map_pages_to_xen( else { l2_pgentry_t *l2t; + mfn_t l2t_mfn = l3e_get_mfn(ol3e); + + l2t = map_xen_pagetable_new(l2t_mfn); - l2t = l3e_to_l2e(ol3e); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { ol2e = l2t[i]; @@ -5154,10 +5156,12 @@ int map_pages_to_xen( { unsigned int j; l1_pgentry_t *l1t; + mfn_t l1t_mfn = l2e_get_mfn(ol2e); - l1t = l2e_to_l1e(ol2e); + l1t = map_xen_pagetable_new(l1t_mfn); for ( j = 0; j < L1_PAGETABLE_ENTRIES; j++ ) flush_flags(l1e_get_flags(l1t[j])); + UNMAP_XEN_PAGETABLE_NEW(l1t); } } flush_area(virt, flush_flags); @@ -5166,9 +5170,9 @@ int map_pages_to_xen( ol2e = 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); + free_xen_pagetable_new(l2t_mfn); } } @@ -5274,12 +5278,14 @@ int map_pages_to_xen( else { l1_pgentry_t *l1t; + mfn_t l1t_mfn = l2e_get_mfn(ol2e); - l1t = l2e_to_l1e(ol2e); + l1t = map_xen_pagetable_new(l1t_mfn); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) flush_flags(l1e_get_flags(l1t[i])); flush_area(virt, flush_flags); - free_xen_pagetable(l1t); + UNMAP_XEN_PAGETABLE_NEW(l1t); + free_xen_pagetable_new(l1t_mfn); } } @@ -5293,12 +5299,14 @@ int map_pages_to_xen( /* Normal page mapping. */ if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { + /* XXX This forces page table to be populated */ pl1e = virt_to_xen_l1e(virt); if ( pl1e == NULL ) { ASSERT(rc == -ENOMEM); goto out; } + UNMAP_XEN_PAGETABLE_NEW(pl1e); } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { @@ -5362,9 +5370,11 @@ int map_pages_to_xen( } } - pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(virt); + pl1e = map_xen_pagetable_new(l2e_get_mfn((*pl2e))); + pl1e += l1_table_offset(virt); ol1e = *pl1e; l1e_write_atomic(pl1e, l1e_from_mfn(mfn, flags)); + UNMAP_XEN_PAGETABLE_NEW(pl1e); if ( (l1e_get_flags(ol1e) & _PAGE_PRESENT) ) { unsigned int flush_flags = FLUSH_TLB | FLUSH_ORDER(0); @@ -5385,6 +5395,7 @@ int map_pages_to_xen( { unsigned long base_mfn; l1_pgentry_t *l1t; + mfn_t l1t_mfn; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5408,12 +5419,15 @@ int map_pages_to_xen( goto check_l3; } - l1t = l2e_to_l1e(ol2e); + l1t_mfn = l2e_get_mfn(ol2e); + l1t = map_xen_pagetable_new(l1t_mfn); + base_mfn = l1e_get_pfn(l1t[0]) & ~(L1_PAGETABLE_ENTRIES - 1); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) if ( (l1e_get_pfn(l1t[i]) != (base_mfn + i)) || (l1e_get_flags(l1t[i]) != flags) ) break; + UNMAP_XEN_PAGETABLE_NEW(l1t); if ( i == L1_PAGETABLE_ENTRIES ) { l2e_write_atomic(pl2e, l2e_from_pfn(base_mfn, @@ -5423,7 +5437,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(l1t_mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5439,6 +5453,7 @@ int map_pages_to_xen( { unsigned long base_mfn; l2_pgentry_t *l2t; + mfn_t l2t_mfn; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5456,7 +5471,9 @@ int map_pages_to_xen( goto end_of_loop; } - l2t = l3e_to_l2e(ol3e); + l2t_mfn = l3e_get_mfn(ol3e); + l2t = map_xen_pagetable_new(l2t_mfn); + base_mfn = l2e_get_pfn(l2t[0]) & ~(L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES - 1); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) @@ -5464,6 +5481,7 @@ int map_pages_to_xen( (base_mfn + (i << PAGETABLE_ORDER))) || (l2e_get_flags(l2t[i]) != l1f_to_lNf(flags)) ) break; + UNMAP_XEN_PAGETABLE_NEW(l2t); if ( i == L2_PAGETABLE_ENTRIES ) { l3e_write_atomic(pl3e, l3e_from_pfn(base_mfn, @@ -5473,7 +5491,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(l2t_mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock);