From patchwork Tue Jun 13 16:13:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 105387 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp486348qgd; Tue, 13 Jun 2017 09:15:16 -0700 (PDT) X-Received: by 10.107.39.1 with SMTP id n1mr838984ion.8.1497370516250; Tue, 13 Jun 2017 09:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497370516; cv=none; d=google.com; s=arc-20160816; b=Ouw8SREn9h2U/crziOC2UYQS6hwZKq0WgayamYTZ8jXbtQgoJdEtjC4B/ZxpUeyQp4 Klc0XPosLJ+k3DgK9NUfb6BWDeYy7z0lB5vMK3Jdn+51xsvFbxfi7G5CX3Y2ZUxDhDts QSA3jUKm5DVc5Kpd6BJoexvb5cQ834vOTcoieKPv7XKIOtSeA/PgHMUDthM4QCn+3kAA D1G9MkvY5AIOwpqqw/V5yJt6vu9UHm+gM8q5Orh+/zY1/5W3Nsr0LmPRr0ekmoWLtn79 6Pn2GdaMdu94MGmRJYQuTQQyqF+BRw5fakC7YuMv4OHgWSEjmzGyLkifyadIyhI5XDXB CzVw== 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=kRmqPLkv+R3xeONHf8j8Q2SunSsAl/Yd5pGatikTVYA=; b=FRcNYkgY5bovqvalaI9RCyAPRGdEoYBd/UAJNrd68CmCtG1jV1XSmieDcVvaLM2EGa iKXI7Kt5OeAQqe9BbetgW/kzoqskUmQM94nAZ6DFka8mxOkiqOTWxcC+ysOqN34dzwKS hsTLQOa628JtC0VUsQ0kTcs/cWw1+1ZQO6ebyUHBN4cWS0qDBw5qgSBCVYpuMpTX61p+ Fe//Qa11lqb8q5jlwXyMxlxoVqlSC1e/GKKnVFWNj8nxY2pktqqR2g5KrLsCoBMswhS6 V35hZpm5EPDT0xBB3bxX2hTBNMeTGSZbrAYW/IiUPSjkEyL1uZj8KlTFHp1mT5G+Eygl Da+A== 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 f86si417420ioj.92.2017.06.13.09.15.11 (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 1dKoS0-0008NE-4z; Tue, 13 Jun 2017 16:13:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKoRy-0008Jx-G0 for xen-devel@lists.xen.org; Tue, 13 Jun 2017 16:13:50 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 34/81-03557-D3F00495; Tue, 13 Jun 2017 16:13:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsVysyfVTdeW3yH S4MIZboslHxezODB6HN39mymAMYo1My8pvyKBNePj/J9MBauMKhadnMfawDhPvYuRi0NIYDOj xN2Ze5khnNOMEhdeT2PqYuTkYBPQlLjz+ROYLSIgLXHt82VGEJtZIEKiacFesLiwgJvEm+vv2 EBsFgFVib1X+oBsDg5eASuJy1tiQcISAvISu9ousoLYnEDhS8+bwMYICVhKNO9ezzSBkXsBI8 MqRo3i1KKy1CJdQwu9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYxA/zIAwQ7Gmxs DDjFKcjApifJuuWITKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC157PIVJIsCg1PbUiLTMHGGgw aQkOHiUR3vssQGne4oLE3OLMdIjUKUZdjg2r139hEmLJy89LlRLnnQAyQwCkKKM0D24ELOgvM cpKCfMyAh0lxFOQWpSbWYIq/4pRnINRSZi3hQdoCk9mXgncpldARzABHXEd5H7e4pJEhJRUA2 OOWeYl32mLWL+3hke3lh+ZPPnJf59PM2tYLn62l7JUzcsTTuLOkuOJK/y8pOi2j0zt3qNl3jH Gj/YyvFXj+/vY48TZN1XHjjFsD798trXtznYxXW/5E00HxM8uXHN5thHb3Xe+34M7b8zLW7Fz i91lhz2hLmnT13wSu2fgtTJbNlSw6qPJkqdKLMUZiYZazEXFiQA37zNNdQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1497370428!95059963!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 34558 invoked from network); 13 Jun 2017 16:13:48 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-27.messagelabs.com with SMTP; 13 Jun 2017 16:13:48 -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 5B59C15A2; Tue, 13 Jun 2017 09:13:48 -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 94F4F3F557; Tue, 13 Jun 2017 09:13:47 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 13 Jun 2017 17:13:15 +0100 Message-Id: <20170613161323.25196-17-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 16/24] xen/arm: mm: Use typesafe mfn for xenheap_mfn_* 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" Add more safety when using xenheap_mfn_*. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 16 ++++++++-------- xen/arch/arm/setup.c | 18 +++++++++--------- xen/include/asm-arm/mm.h | 11 ++++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 0014c24ecc..fb01f01879 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -138,8 +138,8 @@ uint64_t init_ttbr; static paddr_t phys_offset; /* Limits of the Xen heap */ -unsigned long xenheap_mfn_start __read_mostly = ~0UL; -unsigned long xenheap_mfn_end __read_mostly; +mfn_t xenheap_mfn_start __read_mostly = INVALID_MFN; +mfn_t xenheap_mfn_end __read_mostly; vaddr_t xenheap_virt_end __read_mostly; #ifdef CONFIG_ARM_64 vaddr_t xenheap_virt_start __read_mostly; @@ -801,8 +801,8 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, /* Record where the xenheap is, for translation routines. */ xenheap_virt_end = XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; - xenheap_mfn_start = base_mfn; - xenheap_mfn_end = base_mfn + nr_mfns; + xenheap_mfn_start = _mfn(base_mfn); + xenheap_mfn_end = _mfn(base_mfn + nr_mfns); } #else /* CONFIG_ARM_64 */ void __init setup_xenheap_mappings(unsigned long base_mfn, @@ -816,16 +816,16 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, mfn = base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); /* First call sets the xenheap physical and virtual offset. */ - if ( xenheap_mfn_start == ~0UL ) + if ( mfn_eq(xenheap_mfn_start, INVALID_MFN) ) { - xenheap_mfn_start = base_mfn; + xenheap_mfn_start = _mfn(base_mfn); xenheap_virt_start = DIRECTMAP_VIRT_START + (base_mfn - mfn) * PAGE_SIZE; } - if ( base_mfn < xenheap_mfn_start ) + if ( base_mfn < mfn_x(xenheap_mfn_start) ) panic("cannot add xenheap mapping at %lx below heap start %lx", - base_mfn, xenheap_mfn_start); + base_mfn, mfn_x(xenheap_mfn_start)); end_mfn = base_mfn + nr_mfns; diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index ab4d8e4218..3b34855668 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -555,8 +555,8 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) * and enough mapped pages for copying the DTB. */ dtb_pages = (dtb_size + PAGE_SIZE-1) >> PAGE_SHIFT; - boot_mfn_start = xenheap_mfn_end - dtb_pages - 1; - boot_mfn_end = xenheap_mfn_end; + boot_mfn_start = mfn_x(xenheap_mfn_end) - dtb_pages - 1; + boot_mfn_end = mfn_x(xenheap_mfn_end); init_boot_pages(pfn_to_paddr(boot_mfn_start), pfn_to_paddr(boot_mfn_end)); @@ -591,11 +591,11 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) e = bank_end; /* Avoid the xenheap */ - if ( s < pfn_to_paddr(xenheap_mfn_start+xenheap_pages) - && pfn_to_paddr(xenheap_mfn_start) < e ) + if ( s < mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_pages)) + && mfn_to_maddr(xenheap_mfn_start) < e ) { - e = pfn_to_paddr(xenheap_mfn_start); - n = pfn_to_paddr(xenheap_mfn_start+xenheap_pages); + e = mfn_to_maddr(xenheap_mfn_start); + n = mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_pages)); } dt_unreserved_regions(s, e, init_boot_pages, 0); @@ -610,7 +610,7 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) /* Add xenheap memory that was not already added to the boot allocator. */ - init_xenheap_pages(pfn_to_paddr(xenheap_mfn_start), + init_xenheap_pages(mfn_to_maddr(xenheap_mfn_start), pfn_to_paddr(boot_mfn_start)); } #else /* CONFIG_ARM_64 */ @@ -662,8 +662,8 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) total_pages += ram_size >> PAGE_SHIFT; xenheap_virt_end = XENHEAP_VIRT_START + ram_end - ram_start; - xenheap_mfn_start = ram_start >> PAGE_SHIFT; - xenheap_mfn_end = ram_end >> PAGE_SHIFT; + xenheap_mfn_start = maddr_to_mfn(ram_start); + xenheap_mfn_end = maddr_to_mfn(ram_end); /* * Need enough mapped pages for copying the DTB. diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index a42da20f0a..3dab6dc9a1 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -115,7 +115,7 @@ struct page_info #define PGC_count_width PG_shift(9) #define PGC_count_mask ((1UL<= xenheap_mfn_start && _mfn < xenheap_mfn_end); \ + (_mfn >= mfn_x(xenheap_mfn_start) && \ + _mfn < mfn_x(xenheap_mfn_end)); \ }) #else #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap) @@ -235,7 +236,7 @@ static inline paddr_t __virt_to_maddr(vaddr_t va) static inline void *maddr_to_virt(paddr_t ma) { ASSERT(is_xen_heap_mfn(ma >> PAGE_SHIFT)); - ma -= pfn_to_paddr(xenheap_mfn_start); + ma -= mfn_to_maddr(xenheap_mfn_start); return (void *)(unsigned long) ma + XENHEAP_VIRT_START; } #else @@ -243,7 +244,7 @@ static inline void *maddr_to_virt(paddr_t ma) { ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT)); return (void *)(XENHEAP_VIRT_START - - pfn_to_paddr(xenheap_mfn_start) + + mfn_to_maddr(xenheap_mfn_start) + ((ma & ma_va_bottom_mask) | ((ma & ma_top_mask) >> pfn_pdx_hole_shift))); } @@ -284,7 +285,7 @@ static inline struct page_info *virt_to_page(const void *v) ASSERT(va < xenheap_virt_end); pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT; - pdx += pfn_to_pdx(xenheap_mfn_start); + pdx += pfn_to_pdx(mfn_x(xenheap_mfn_start)); return frame_table + pdx - frametable_base_pdx; }