From patchwork Mon Aug 14 14:23:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9899011 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 5D43C6038C for ; Mon, 14 Aug 2017 14:27:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E758284D1 for ; Mon, 14 Aug 2017 14:27:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41A4728686; Mon, 14 Aug 2017 14:27:21 +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 C93FD2866D for ; Mon, 14 Aug 2017 14:27:18 +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 1dhGIP-0000L6-1D; Mon, 14 Aug 2017 14:24:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhGIN-0000Fh-PC for xen-devel@lists.xen.org; Mon, 14 Aug 2017 14:24:43 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id BB/8E-03937-BA2B1995; Mon, 14 Aug 2017 14:24:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMLMWRWlGSWpSXmKPExsVysyfVTXfVpom RBlsmWlgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkLHp1nLJguUXHn6HPGBsbzQl2MXBxCApsZ Ja7uuMMK4ZxmlFgx+QJzFyMnB5uApsSdz5+YQGwRAWmJa58vM4LYzAKREoc//GAHsYUFPCTuH r4NZrMIqEp8vnwNrJdXwFLiy+y7YHEJAXmJXW0XWUFsTgEric67O1lAbCGgmhOrZ7NNYORewM iwilGjOLWoLLVI18hML6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMalYLzk/dxMj0MMMQLCD8cy CwEOMkhxMSqK8CT69kUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeFM3TowUEixKTU+tSMvMAYYa TFqCg0dJhPcGSJq3uCAxtzgzHSJ1ilGX49WE/9+YhFjy8vNSpcR5y0GKBECKMkrz4EbAwv4So 6yUMC8j0FFCPAWpRbmZJajyrxjFORiVhHk3g0zhycwrgdv0CugIJqAj+kDu5y0uSURISTUwzj Y5pKei9uibtp2xi8WXicpr6o+ejNQ4faOKPzlZXv7H92kf5B/q7Lm08vRx78bix0uPe+4wdTF 4OCvUpEPIXEf3lhcbq86Og6ne11ac/Lyysrt6RfrluQ2P5lrvTOV1MvkYJZR3wlxTReqvRu6b uvLpVyMn36mKKNl+zPzs1Rk3v3Es2so8W4mlOCPRUIu5qDgRAEuQArN2AgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1502720682!111835689!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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57328 invoked from network); 14 Aug 2017 14:24:42 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-9.tower-27.messagelabs.com with SMTP; 14 Aug 2017 14:24:42 -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 360C61713; Mon, 14 Aug 2017 07:24:42 -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 4A6B33F483; Mon, 14 Aug 2017 07:24:41 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 14 Aug 2017 15:23:58 +0100 Message-Id: <20170814142418.13267-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170814142418.13267-1-julien.grall@arm.com> References: <20170814142418.13267-1-julien.grall@arm.com> Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH 07/27] xen/arm: mm: Redefine mfn_to_virt to use 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 This add a bit more safety in the memory subsystem code. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b3def63ed7..349ac58ffe 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -47,6 +47,8 @@ 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)) +#undef mfn_to_virt +#define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn)) /* Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching @@ -837,7 +839,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, * Virtual address aligned to previous 1GB to match physical * address alignment done above. */ - vaddr = (vaddr_t)mfn_to_virt(base_mfn) & FIRST_MASK; + vaddr = (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; while ( mfn < end_mfn ) { @@ -849,7 +851,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, /* mfn_to_virt is not valid on the 1st 1st mfn, since it * is not within the xenheap. */ first = slot == xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(p->pt.base); + xenheap_first_first : __mfn_to_virt(p->pt.base); } else if ( xenheap_first_first_slot == -1) { @@ -866,11 +868,11 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, { mfn_t first_mfn = alloc_boot_pages(1, 1); - clear_page(mfn_to_virt(mfn_x(first_mfn))); + clear_page(mfn_to_virt(first_mfn)); pte = mfn_to_xen_entry(first_mfn, WRITEALLOC); pte.pt.table = 1; write_pte(p, pte); - first = mfn_to_virt(mfn_x(first_mfn)); + first = mfn_to_virt(first_mfn); } pte = mfn_to_xen_entry(_mfn(mfn), WRITEALLOC); @@ -909,10 +911,10 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) /* Compute the number of second level pages. */ nr_second = ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; second_base = alloc_boot_pages(nr_second, 1); - second = mfn_to_virt(mfn_x(second_base)); + second = mfn_to_virt(second_base); for ( i = 0; i < nr_second; i++ ) { - clear_page(mfn_to_virt(mfn_x(mfn_add(second_base, i)))); + clear_page(mfn_to_virt(mfn_add(second_base, i))); pte = mfn_to_xen_entry(mfn_add(second_base, i), WRITEALLOC); pte.pt.table = 1; write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i], pte); @@ -1005,7 +1007,7 @@ static int create_xen_entries(enum xenmap_operation op, BUG_ON(!lpae_valid(*entry)); - third = mfn_to_virt(entry->pt.base); + third = __mfn_to_virt(entry->pt.base); entry = &third[third_table_offset(addr)]; switch ( op ) {