From patchwork Mon Sep 30 10:33:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11166465 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 C94FF13BD for ; Mon, 30 Sep 2019 10:37:05 +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 A4B4221A4A for ; Mon, 30 Sep 2019 10:37:05 +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="R/+wm0m/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4B4221A4A 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 1iEt2S-0001SG-GI; Mon, 30 Sep 2019 10:36:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iEt2Q-0001Pi-TJ for xen-devel@lists.xenproject.org; Mon, 30 Sep 2019 10:36:18 +0000 X-Inumbo-ID: 0eb28838-e36e-11e9-8628-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by localhost (Halon) with ESMTPS id 0eb28838-e36e-11e9-8628-bc764e2007e4; Mon, 30 Sep 2019 10:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569839744; x=1601375744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SS0f3zuZ4ltH/WUPJ9Ye+o8RgJZJ0qn7mK/0DOMB//E=; b=R/+wm0m/y+ffz8VZ8wVNqCAIRo7FRPZw7XMRCm7G/Se0J8irqil69me6 9WRXvpdGECT//yi7LIUjjCxOb6+8gaa2J/u1EjTCdLrklKxl3+1TR62Fu ue16/IZSNSx+ulu/vViOp/HzDUcxf68/Pl5F10t6KUFSNprAETIXTgAYI 8=; X-IronPort-AV: E=Sophos;i="5.64,565,1559520000"; d="scan'208";a="838005587" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 30 Sep 2019 10:34:44 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com (Postfix) with ESMTPS id E45CAA123B; Mon, 30 Sep 2019 10:34:31 +0000 (UTC) Received: from EX13D14UEE001.ant.amazon.com (10.43.62.238) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:06 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D14UEE001.ant.amazon.com (10.43.62.238) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:05 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.78) by mail-relay.amazon.com (10.43.62.226) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 30 Sep 2019 10:34:04 +0000 From: Hongyan Xia To: Date: Mon, 30 Sep 2019 11:33:09 +0100 Message-ID: <2ab0430ed5105bf946116dcadff3a14479f9a795.1569833766.git.hongyax@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 17/55] 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 , Jan Beulich , =?utf-8?q?Roger_Pau_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 5bb86935f4..08af71a261 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); } } @@ -5273,12 +5277,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); } } @@ -5292,12 +5298,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 ) { @@ -5360,9 +5368,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); @@ -5383,6 +5393,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); @@ -5406,12 +5417,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, @@ -5421,7 +5435,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); @@ -5437,6 +5451,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); @@ -5454,7 +5469,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++ ) @@ -5462,6 +5479,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, @@ -5471,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(l2t_mfn); } else if ( locking ) spin_unlock(&map_pgdir_lock);