From patchwork Mon Sep 30 10:33:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11166459 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 98AA516B1 for ; Mon, 30 Sep 2019 10:36:51 +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 7507920679 for ; Mon, 30 Sep 2019 10:36:51 +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="Cgk7xJLU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7507920679 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 1iEt2C-00010U-JJ; Mon, 30 Sep 2019 10:36:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iEt2B-0000z7-Ug for xen-devel@lists.xenproject.org; Mon, 30 Sep 2019 10:36:03 +0000 X-Inumbo-ID: 05795f62-e36e-11e9-8628-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by localhost (Halon) with ESMTPS id 05795f62-e36e-11e9-8628-bc764e2007e4; Mon, 30 Sep 2019 10:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569839729; x=1601375729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=hTkmNlwsOjF0Hl2l2Hvic+lIfqYsmmXAm8fsLU5GbNQ=; b=Cgk7xJLUvaqCFgCf9Bx9b0BkHTkDY22STw6P84tLZeDaaOcC9APvlnxd pMTq9G6q+jT9rQLT/3heTek6ZpGHOzh5+qpNqOrM6fh55UuJLdis51bo1 tKhN+Mlwu/0kAL4bRQRBdnWAKzztWCKJWJMXBxNZIBAH9aQXygsw9vW3O 4=; X-IronPort-AV: E=Sophos;i="5.64,565,1559520000"; d="scan'208";a="838005541" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1d-f273de60.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:29 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-f273de60.us-east-1.amazon.com (Postfix) with ESMTPS id CE25CA2EBA; Mon, 30 Sep 2019 10:34:16 +0000 (UTC) Received: from EX13D15UEE002.ant.amazon.com (10.43.62.80) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:02 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D15UEE002.ant.amazon.com (10.43.62.80) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:01 +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:01 +0000 From: Hongyan Xia To: Date: Mon, 30 Sep 2019 11:33:06 +0100 Message-ID: <12674b11445769ccf7aae2d732580a711bc25bd2.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 14/55] 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 , Jan Beulich , =?utf-8?q?Roger_Pau_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; }