From patchwork Mon Sep 30 10:32:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11166371 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 309A213BD for ; Mon, 30 Sep 2019 10:35:21 +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 0CEA8216F4 for ; Mon, 30 Sep 2019 10:35:21 +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="CFUmvNf8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CEA8216F4 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 1iEt0B-0006kP-QI; Mon, 30 Sep 2019 10:33:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iEt0A-0006k6-3S for xen-devel@lists.xenproject.org; Mon, 30 Sep 2019 10:33:58 +0000 X-Inumbo-ID: cefc0110-e36d-11e9-bf31-bc764e2007e4 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by localhost (Halon) with ESMTPS id cefc0110-e36d-11e9-bf31-bc764e2007e4; Mon, 30 Sep 2019 10:33: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=1569839637; x=1601375637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ylxx4KY9/y4YFgv7nP3EOYtykrPz1aPjA0nz6rqmeOA=; b=CFUmvNf8M6DIop0+/bdrK104EjJFnNishWmoXSnn8iojNJtCJP2urSTN 1ytvLo51zpIgqPEsZLF8kMyDNT5EBsV6P6sxmzm+AIITUpRQY5wN8JSDk e9jGZTYAuhZx9MXxQrEzuiyNTzxLD1Op8vIyWf8DNWfh7OInSXMJO+2wZ k=; X-IronPort-AV: E=Sophos;i="5.64,565,1559520000"; d="scan'208";a="754242108" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 30 Sep 2019 10:33:55 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id 4E30B241835; Mon, 30 Sep 2019 10:33:54 +0000 (UTC) Received: from EX13D09UEE003.ant.amazon.com (10.43.62.56) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:33:54 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D09UEE003.ant.amazon.com (10.43.62.56) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:33:53 +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:33:52 +0000 From: Hongyan Xia To: Date: Mon, 30 Sep 2019 11:32:57 +0100 Message-ID: <8806ac6c0bc4e4a80da0c9ddb4ddf9256fd56a60.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 05/55] x86/mm: introduce l{1, 2}t local variables to modify_xen_mappings 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 The pl2e and pl1e variables are heavily (ab)used in that function. It is fine at the moment because all page tables are always mapped so there is no need to track the life time of each variable. We will soon have the requirement to map and unmap page tables. We need to track the life time of each variable to avoid leakage. Introduce some l{1,2}t variables with limited scope so that we can track life time of pointers to xen page tables more easily. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 68 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 2ae8a7736f..063cacffb8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5428,6 +5428,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( l3e_get_flags(*pl3e) & _PAGE_PSE ) { + l2_pgentry_t *l2t; + if ( l2_table_offset(v) == 0 && l1_table_offset(v) == 0 && ((e - v) >= (1UL << L3_PAGETABLE_SHIFT)) ) @@ -5443,11 +5445,11 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) } /* PAGE1GB: shatter the superpage and fall through. */ - pl2e = alloc_xen_pagetable(); - if ( !pl2e ) + l2t = alloc_xen_pagetable(); + if ( !l2t ) return -ENOMEM; for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) - l2e_write(pl2e + i, + l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + (i << PAGETABLE_ORDER), l3e_get_flags(*pl3e))); @@ -5456,14 +5458,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) && (l3e_get_flags(*pl3e) & _PAGE_PSE) ) { - l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(pl2e), + l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t), __PAGE_HYPERVISOR)); - pl2e = NULL; + l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl2e ) - free_xen_pagetable(pl2e); + if ( l2t ) + free_xen_pagetable(l2t); } /* @@ -5497,12 +5499,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) } else { + l1_pgentry_t *l1t; + /* PSE: shatter the superpage and try again. */ - pl1e = alloc_xen_pagetable(); - if ( !pl1e ) + l1t = alloc_xen_pagetable(); + if ( !l1t ) return -ENOMEM; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - l1e_write(&pl1e[i], + l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, l2e_get_flags(*pl2e) & ~_PAGE_PSE)); if ( locking ) @@ -5510,19 +5514,19 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && (l2e_get_flags(*pl2e) & _PAGE_PSE) ) { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(pl1e), + l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), __PAGE_HYPERVISOR)); - pl1e = NULL; + l1t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl1e ) - free_xen_pagetable(pl1e); + if ( l1t ) + free_xen_pagetable(l1t); } } else { - l1_pgentry_t nl1e; + l1_pgentry_t nl1e, *l1t; /* * Ordinary 4kB mapping: The L2 entry has been verified to be @@ -5569,9 +5573,9 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) continue; } - pl1e = l2e_to_l1e(*pl2e); + l1t = l2e_to_l1e(*pl2e); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - if ( l1e_get_intpte(pl1e[i]) != 0 ) + if ( l1e_get_intpte(l1t[i]) != 0 ) break; if ( i == L1_PAGETABLE_ENTRIES ) { @@ -5580,7 +5584,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(pl1e); + free_xen_pagetable(l1t); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5609,21 +5613,25 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) continue; } - pl2e = l3e_to_l2e(*pl3e); - for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) - if ( l2e_get_intpte(pl2e[i]) != 0 ) - break; - if ( i == L2_PAGETABLE_ENTRIES ) { - /* Empty: zap the L3E and free the L2 page. */ - l3e_write_atomic(pl3e, l3e_empty()); - if ( locking ) + l2_pgentry_t *l2t; + + l2t = l3e_to_l2e(*pl3e); + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) + if ( l2e_get_intpte(l2t[i]) != 0 ) + break; + if ( i == L2_PAGETABLE_ENTRIES ) + { + /* Empty: zap the L3E and free the L2 page. */ + l3e_write_atomic(pl3e, l3e_empty()); + if ( locking ) + spin_unlock(&map_pgdir_lock); + flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ + free_xen_pagetable(l2t); + } + else if ( locking ) spin_unlock(&map_pgdir_lock); - flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(pl2e); } - else if ( locking ) - spin_unlock(&map_pgdir_lock); } flush_area(NULL, FLUSH_TLB_GLOBAL);