From patchwork Mon Jun 19 16:57:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9796845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2197A600C5 for ; Mon, 19 Jun 2017 17:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0965027F8F for ; Mon, 19 Jun 2017 17:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F26CC281F9; Mon, 19 Jun 2017 17:00:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8FD8827F8F for ; Mon, 19 Jun 2017 17:00:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN009-0003jV-21; Mon, 19 Jun 2017 16:58:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN007-0003ir-Ol for xen-devel@lists.xen.org; Mon, 19 Jun 2017 16:58:07 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id C1/BB-03058-F9208495; Mon, 19 Jun 2017 16:58:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTXcek0e kwbd7qhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a0dX9ZC+bJV6y+Poe9gfG1RBcjF4eQwGZG iTnXPjBCOKcZJZb9X8TaxcjJwSagKXHn8ycmEFtEQFri2ufLjCA2s4CDxJuP91hAbGEBf4n/3 9aB1bMIqEq8f3sSrIZXwFLi3auHzCC2hIC8xK62i2A1nAJWEt/nXwOrEQKqOf7kFtsERu4FjA yrGDWKU4vKUot0jYz0kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r1kvNzNzECPcwABDsY18w PPMQoycGkJMo76797pBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXlVGj0ghwaLU9NSKtMwcYKjB pCU4eJREeGt+A7XyFhck5hZnpkOkTjEqSonzKoD0CYAkMkrz4Npg4X2JUVZKmJcR6BAhnoLUo tzMElT5V4ziHIxKwrxdIJfxZOaVwE1/BbSYCWgx8xkXkMUliQgpqQZGU4EtAXrf5cw2FsosXc jyg+NV65119aFMxbeScoz6prE9n/3vuuPri75KMnt6c1Zt2FzYxCCwf8Mt35lSxz/c81utz1K /yCNFkuPz1nCPdV37fU+93iCX1fTMfeazG5ZROvPefMldqdJsHrPh0elO1owrMznDKi+svLOH T8Hx4C7NNjajuqfpSizFGYmGWsxFxYkA54KxjmoCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1497891486!108525070!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 52637 invoked from network); 19 Jun 2017 16:58:06 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-9.tower-27.messagelabs.com with SMTP; 19 Jun 2017 16:58:06 -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 B611115BE; Mon, 19 Jun 2017 09:58:05 -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 123333F41F; Mon, 19 Jun 2017 09:58:04 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 19 Jun 2017 17:57:42 +0100 Message-Id: <20170619165753.25049-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170619165753.25049-1-julien.grall@arm.com> References: <20170619165753.25049-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 05/16] 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Use __virt_to_mfn rather than mfn_x(virt_to_mfn()). --- 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..5612834dfc 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 __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)