From patchwork Thu Sep 26 09:45:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162067 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 C077213B1 for ; Thu, 26 Sep 2019 09:49:12 +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 9C6DA222C0 for ; Thu, 26 Sep 2019 09:49:12 +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="c4VjpE2F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C6DA222C0 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 1iDQNP-0003qj-JJ; Thu, 26 Sep 2019 09:47:55 +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.89) (envelope-from ) id 1iDQNO-0003om-F5 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:47:54 +0000 X-Inumbo-ID: b57367e9-e042-11e9-964c-12813bfff9fa Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by localhost (Halon) with ESMTPS id b57367e9-e042-11e9-964c-12813bfff9fa; Thu, 26 Sep 2019 09:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491273; x=1601027273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=hTkmNlwsOjF0Hl2l2Hvic+lIfqYsmmXAm8fsLU5GbNQ=; b=c4VjpE2Fr6RVuJfmSRwtaEdNqnqV6WXjwVThXASF74BTVkkG+8j140jI 4T2cVgYTXrUWVpPGruXLSJS9KTc/0Y2eH+bH7DKPuFYPahaE0CwsW7q6w sG5FcRLCLPE6gzb7OlDBUcQ7mx7Xg/jO5M290ZEjuLuz6Pi/CIZj5QYs+ 4=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="423750415" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 26 Sep 2019 09:47:53 +0000 Received: from EX13MTAUWA001.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 3AA862421A1; Thu, 26 Sep 2019 09:47:50 +0000 (UTC) Received: from EX13D31UWA003.ant.amazon.com (10.43.160.130) 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:20 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D31UWA003.ant.amazon.com (10.43.160.130) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:47:19 +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:18 +0000 From: To: Date: Thu, 26 Sep 2019 10:45:37 +0100 Message-ID: <022d5088caa43d0eaf35f55630e0b66987b4fdea.1569489002.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] [RFC PATCH 14/84] x86/mm: rewrite xen_to_virt_l2e 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 Rewrite that function to use the new APIs. Modify its callers to unmap the pointer returned. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 1dcd4289d1..ad0d7a0b80 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4952,6 +4952,10 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) return pl3e; } +/* + * Given a virtual address, return a pointer to xen's L2 entry. Caller + * needs to unmap the pointer. + */ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) { l3_pgentry_t *pl3e; @@ -4964,27 +4968,44 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { bool locking = system_state > SYS_STATE_boot; - l2_pgentry_t *l2t = alloc_xen_pagetable(); + l2_pgentry_t *l2t; + mfn_t mfn; - if ( !l2t ) + mfn = alloc_xen_pagetable_new(); + if ( mfn_eq(mfn, INVALID_MFN) ) goto out; + l2t = map_xen_pagetable_new(mfn); + if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { clear_page(l2t); - l3e_write(pl3e, l3e_from_paddr(__pa(l2t), __PAGE_HYPERVISOR)); + l3e_write(pl3e, l3e_from_mfn(mfn, __PAGE_HYPERVISOR)); + pl2e = l2t + l2_table_offset(v); l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); + if ( l2t ) - free_xen_pagetable(l2t); + { + ASSERT(!pl2e); + ASSERT(!mfn_eq(mfn, INVALID_MFN)); + UNMAP_XEN_PAGETABLE_NEW(l2t); + free_xen_pagetable_new(mfn); + } } BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); - pl2e = l3e_to_l2e(*pl3e) + l2_table_offset(v); + + if ( !pl2e ) + { + ASSERT(l3e_get_flags(*pl3e) & _PAGE_PRESENT); + pl2e = (l2_pgentry_t *)map_xen_pagetable_new(l3e_get_mfn(*pl3e)) + + l2_table_offset(v); + } out: UNMAP_XEN_PAGETABLE_NEW(pl3e); @@ -4994,10 +5015,11 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) l1_pgentry_t *virt_to_xen_l1e(unsigned long v) { l2_pgentry_t *pl2e; + l1_pgentry_t *pl1e = NULL; pl2e = virt_to_xen_l2e(v); if ( !pl2e ) - return NULL; + goto out; if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { @@ -5005,7 +5027,7 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) l1_pgentry_t *l1t = alloc_xen_pagetable(); if ( !l1t ) - return NULL; + goto out; if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) @@ -5021,7 +5043,11 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) } BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE); - return l2e_to_l1e(*pl2e) + l1_table_offset(v); + pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(v); + + out: + UNMAP_XEN_PAGETABLE_NEW(pl2e); + return pl1e; } /* Convert to from superpage-mapping flags for map_pages_to_xen(). */ @@ -5045,7 +5071,7 @@ int map_pages_to_xen( { bool locking = system_state > SYS_STATE_boot; l3_pgentry_t *pl3e = NULL, ol3e; - l2_pgentry_t *pl2e, ol2e; + l2_pgentry_t *pl2e = NULL, ol2e; l1_pgentry_t *pl1e, ol1e; unsigned int i; int rc = -ENOMEM; @@ -5421,6 +5447,7 @@ int map_pages_to_xen( spin_unlock(&map_pgdir_lock); } end_of_loop: + UNMAP_XEN_PAGETABLE_NEW(pl2e); UNMAP_XEN_PAGETABLE_NEW(pl3e); } @@ -5429,6 +5456,7 @@ int map_pages_to_xen( rc = 0; out: + UNMAP_XEN_PAGETABLE_NEW(pl2e); UNMAP_XEN_PAGETABLE_NEW(pl3e); return rc; }