From patchwork Tue Jun 13 16:13:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 105386 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp486344qgd; Tue, 13 Jun 2017 09:15:16 -0700 (PDT) X-Received: by 10.157.83.29 with SMTP id g29mr640709oth.20.1497370515979; Tue, 13 Jun 2017 09:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497370515; cv=none; d=google.com; s=arc-20160816; b=E+3yVdn0d4aj05h8U1R/JttbdM8GMAU1cEWIfKISwjSCwP4YXTmRB46VhEu9ucAEqB Q5rxfvdEe3GVmMq5CGSZ1BJ0fNJ5ptP8LavqLu5GoqvwTQcLbcFKhKTMA1dHyXuX0lWn D5wc43ZTNCg9COL3//EiQf4cwyzOU3QOEX8hN9Ftwly1EPGI3fMdnEBuxXMaFanCY9eb eitKkef/2EPAmhCAlZ0wrYxwbvKDAQ/e2FjR19IVVDYfjnSsPY31PbbDhPINFcV74Lz0 Wwe/7iRBFzMbHql11qcTcoO8lJp5/IAda3P5OsW5GdKeoR+2hjCR5MVLlfCjQbGRbcy0 OidQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=a21w7YFp8hSHK3q1Mk9Tmitx71HChTZB5AejyAvJAVM=; b=NZJPlN3RNg0H2tWfdx82CH+badXe+qnaH4K329/wJ/Zgci9IEikcnoaSozde8Nx2ry +zLcGPPnevfCVkhsPFlECWey/DR5h3gkEMkgbquy2MxFCogiONg0PopmmzcsUy+BQ4FL djOQBhpc+A3s0OGAV5nF/TYZ+8szjNRsUN3PCGLFkTctFaghLTBD7l6wzZhvsuGgDEPH yZuZc7ATLH19jDqcskERab+ReXXo9z6pfYoQ0SZdrLx2D8nHE/mYbaWPswYFpakyXWbu ZqoIzfN9+zLD1rSbu3ttuma3/Nisjz9xCW5wEaAXAPZrq7hWGmuseaPYGbnnm/aX5cB5 yf7w== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x16si329205otd.133.2017.06.13.09.15.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 09:15:15 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKoS4-0008Uq-11; Tue, 13 Jun 2017 16:13:56 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKoS2-0008R8-KO for xen-devel@lists.xen.org; Tue, 13 Jun 2017 16:13:54 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 32/F9-03058-14F00495; Tue, 13 Jun 2017 16:13:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTdeR3yH SYOIWQYslHxezODB6HN39mymAMYo1My8pvyKBNePF2S8sBefkKvb+amNtYNwo0cXIxSEksJlR Yu7SGYwQzmlGiV9Xuli7GDk52AQ0Je58/sQEYosISEtc+3yZEcRmFoiQaFqwFywuLOAj0fz5M JjNIqAqsWHrcrAaXgEriWf/v7KB2BIC8hK72i6CzeQEil963gRWIyRgKdG8ez3TBEbuBYwMqx g1ilOLylKLdI1M9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAj3MAAQ7GFctCDz EKMnBpCTKu+WKTaQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCV57PodIIcGi1PTUirTMHGCowaQl OHiURHjvswCleYsLEnOLM9MhUqcYFaXEef/wAiUEQBIZpXlwbbDwvsQoKyXMywh0iBBPQWpRb mYJqvwrRnEORiVh3hYeoCk8mXklcNNfAS1mAlp8HeRm3uKSRISUVANjut9FLaWXUT4POSXyqz hedPItiPkhqpaVLjDBIdbnuWn88wvdQZsvNVx3cNh0ieu+7bTH6xZt8t93sL3i7I69QVsyitv mHe1fW8nS3d6/WdzO/eZeAau5ziH6Ca+0p3477r/bmLm5N7xFYVoj902vSKuidv6MugCRyZw7 DNZtC2jybi5Lu6XEUpyRaKjFXFScCACkqWbsagIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1497370432!102885192!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55612 invoked from network); 13 Jun 2017 16:13:53 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-27.messagelabs.com with SMTP; 13 Jun 2017 16:13:53 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 65ADB1596; Tue, 13 Jun 2017 09:13:52 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A07783F557; Tue, 13 Jun 2017 09:13:51 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 13 Jun 2017 17:13:19 +0100 Message-Id: <20170613161323.25196-21-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170613161323.25196-1-julien.grall@arm.com> References: <20170613161323.25196-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org, punit.agrawal@arm.com Subject: [Xen-devel] [PATCH 20/24] xen/arm: mm: Redefine virt_to_mfn to support typesafe X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" The file xen/arch/arm/mm.c is using the typesafe MFN in most of the place. This requires all caller of virt_to_mfn to prefixed by _mfn(...). To avoid the extra _mfn(...), re-defined virt_to_mfn within arch/arm/mm.c to handle typesafe MFN. This patch also introduce __virt_to_mfn, so virt_to_mfn can be re-defined easily. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 16 ++++++++++------ xen/include/asm-arm/mm.h | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 452c1e26c3..2ff1688f3f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -44,6 +44,10 @@ struct domain *dom_xen, *dom_io, *dom_cow; +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) + /* Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching * to the CPUs own pagetables. @@ -479,7 +483,7 @@ unsigned long domain_page_map_to_mfn(const void *ptr) unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK; if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END ) - return virt_to_mfn(va); + return mfn_x(virt_to_mfn(va)); ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES); ASSERT(map[slot].pt.avail != 0); @@ -764,7 +768,7 @@ int init_secondary_pagetables(int cpu) * domheap mapping pages. */ for ( i = 0; i < DOMHEAP_SECOND_PAGES; i++ ) { - pte = mfn_to_xen_entry(_mfn(virt_to_mfn(domheap+i*LPAE_ENTRIES)), + pte = mfn_to_xen_entry(virt_to_mfn(domheap+i*LPAE_ENTRIES), WRITEALLOC); pte.pt.table = 1; write_pte(&first[first_table_offset(DOMHEAP_VIRT_START+i*FIRST_SIZE)], pte); @@ -961,7 +965,7 @@ static int create_xen_table(lpae_t *entry) if ( p == NULL ) return -ENOMEM; clear_page(p); - pte = mfn_to_xen_entry(_mfn(virt_to_mfn(p)), WRITEALLOC); + pte = mfn_to_xen_entry(virt_to_mfn(p), WRITEALLOC); pte.pt.table = 1; write_pte(entry, pte); return 0; @@ -1216,7 +1220,7 @@ int xenmem_add_to_physmap_one( unsigned long idx, gfn_t gfn) { - unsigned long mfn = 0; + mfn_t mfn = INVALID_MFN; int rc; p2m_type_t t; struct page_info *page = NULL; @@ -1302,7 +1306,7 @@ int xenmem_add_to_physmap_one( return -EINVAL; } - mfn = page_to_mfn(page); + mfn = _mfn(page_to_mfn(page)); t = p2m_map_foreign; rcu_unlock_domain(od); @@ -1321,7 +1325,7 @@ int xenmem_add_to_physmap_one( } /* Map at new location. */ - rc = guest_physmap_add_entry(d, gfn, _mfn(mfn), 0, t); + rc = guest_physmap_add_entry(d, gfn, mfn, 0, t); /* If we fail to add the mapping, we need to drop the reference we * took earlier on foreign pages */ diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index b2e7ea7761..6e2b3c7f2b 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -264,7 +264,7 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags) #define __va(x) (maddr_to_virt(x)) /* Convert between Xen-heap virtual addresses and machine frame numbers. */ -#define virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) #define mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) /* @@ -274,6 +274,7 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags) */ #define mfn_to_page(mfn) __mfn_to_page(mfn) #define page_to_mfn(pg) __page_to_mfn(pg) +#define virt_to_mfn(va) __virt_to_mfn(va) /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v)