From patchwork Mon Aug 14 14:23:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 110025 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp4282144obb; Mon, 14 Aug 2017 07:26:48 -0700 (PDT) X-Received: by 10.36.167.70 with SMTP id s6mr5658354iti.156.1502720808620; Mon, 14 Aug 2017 07:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502720808; cv=none; d=google.com; s=arc-20160816; b=lR387AF+tN4w03h2UJR3ixk8tD6GfElluFcyMIK3XIbY1fips/RQ4k2FJUwrXgSZCw c1txbsHwEAtSlYyHOV2BZ58W7S4J48kzxgF50k5dOZ7cH+fKbToc8BddVTgGcLoSOFl/ VDTu3lu629uzPyaBrfXTf7l3w2jDi2xYt2VE/7eOmly1OkVRZGGmMrdGPJhh4LBQHn4Q Ay2cbVmK+Y42LKpavptcXOhOynTPGaOPvAuellgsgUjLcEOn3YWI5UfZREmMjneut0KC orD44ZV3U83dTkEfSqLQLSboDnt/d4iyVhN6epDOK8RVbnhSylaOR59z23chhaNmH6pb STfQ== 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=hyZmSgZAwCmFOZEwG45J+uvYpyeh+VTujyi+woe+L2Y=; b=jGr3Y1FD3gv9H4/RuFYQbOiJ6NX4D7YZik5pZSx8NkA2Zjf4OvByrtAKdpjs7n8rVu 3K7siuhZF+SbviryVdEIfm+YEY6XaT9jKo5VzkACk6WtQQ0DpuCvYmgtE3KjhiPXlSR8 uTOif7SGDKkdsfY9Yn6f0L2lEpdgo+BmAcBN0uQ+LXRSYNOxnN7CvksuYfkJM4ZJRvxY hNdjfQbHuUTvlzCDIqjcxdmoLAtZFcxy7FFy7Cxz8njp0m8jD9a7sbxCcia/x/r/F2Be XuLm57NP+ASnN0m8WdWd5kMXfIq2KpZ5rouyIyo0mWMnAa5F1ykBt7k8PtxguGprHkF2 XIoA== 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 i14si7042439ioa.297.2017.08.14.07.26.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 07:26:48 -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 1dhGIM-0000Ht-Fa; Mon, 14 Aug 2017 14:24:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dhGIL-0000Fh-8e for xen-devel@lists.xen.org; Mon, 14 Aug 2017 14:24:41 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id C0/7E-03937-8A2B1995; Mon, 14 Aug 2017 14:24:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrFLMWRWlGSWpSXmKPExsVysyfVTXf5pom RBut6NC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyP3yaxFzxyqGjae4u9gXGKSRcjF4eQwGZG ibk9/cwQzmlGics/zjJ1MXJysAloStz5/AnMFhGQlrj2+TIjSBGzwGsmic9btzGDJIQFvCUer n7ECmKzCKhKdHxqZASxeQUsJaZ/3wBmSwjIS+xquwhWwylgJdF5dycLiC0EVHNi9Wy2CYzcCx gZVjFqFKcWlaUW6RoZ6CUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBPqYAQh2MP5 aFnCIUZKDSUmUN8GnN1KILyk/pTIjsTgjvqg0J7X4EKMMB4eSBG/qxomRQoJFqempFWmZOcBg g0lLcPAoifCu3QCU5i0uSMwtzkyHSJ1iNObYsHr9FyaOVxP+f2MSYsnLz0uVEud9BVIqAFKaU ZoHNwgWBZcYZaWEeRmBThPiKUgtys0sQZV/xSjOwagkzFsJcg9PZl4J3L5XQKcwAZ3SB/IFb3 FJIkJKqoFxV3nH1FDLy0Ki75NizPoEz1Q9NDE9duhQ55Iyj7mO/dMsa61fbtu/oWJDh7d3wMz abQ1760wNr558fap7zUnzD0sOPVG1ZPypHH9h55WOvs6Y8OWbzGY2HckMsn56ZLc3YyKnwPq3 S4otC2cqV/1e0NfQnOTObqbzf2cAs7Avb2Puvktv3QyUWIozEg21mIuKEwGPkTwnfQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1502720679!100827900!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 13571 invoked from network); 14 Aug 2017 14:24:39 -0000 Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-8.tower-27.messagelabs.com with SMTP; 14 Aug 2017 14:24:39 -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 CE64B1682; Mon, 14 Aug 2017 07:24:38 -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 DDAF93F483; Mon, 14 Aug 2017 07:24:36 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 14 Aug 2017 15:23:56 +0100 Message-Id: <20170814142418.13267-6-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: sstabellini@kernel.org, Wei Liu , George Dunlap , andre.przywara@arm.com, Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH 05/27] xen/mm: Use typesafe MFN for alloc_boot_pages return 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" At the moment, most of the callers will have to use mfn_x. However follow-up patches will remove some of them by propagating the typesafe a bit further. Signed-off-by: Julien Grall --- Cc: Stefano Stabellini Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu --- xen/arch/arm/mm.c | 26 ++++++++++++++------------ xen/arch/arm/setup.c | 4 ++-- xen/arch/x86/mm.c | 4 ++-- xen/arch/x86/numa.c | 2 +- xen/arch/x86/srat.c | 2 +- xen/common/page_alloc.c | 7 +++---- xen/drivers/acpi/osl.c | 2 +- xen/include/xen/mm.h | 3 +-- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index a810a056d7..b3def63ed7 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -864,13 +864,13 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, } else { - unsigned long first_mfn = alloc_boot_pages(1, 1); + mfn_t first_mfn = alloc_boot_pages(1, 1); - clear_page(mfn_to_virt(first_mfn)); - pte = mfn_to_xen_entry(_mfn(first_mfn), WRITEALLOC); + clear_page(mfn_to_virt(mfn_x(first_mfn))); + pte = mfn_to_xen_entry(first_mfn, WRITEALLOC); pte.pt.table = 1; write_pte(p, pte); - first = mfn_to_virt(first_mfn); + first = mfn_to_virt(mfn_x(first_mfn)); } pte = mfn_to_xen_entry(_mfn(mfn), WRITEALLOC); @@ -891,11 +891,12 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) unsigned long nr_pages = (pe - ps) >> PAGE_SHIFT; unsigned long nr_pdxs = pfn_to_pdx(nr_pages); unsigned long frametable_size = nr_pdxs * sizeof(struct page_info); - unsigned long base_mfn; + mfn_t base_mfn; const unsigned long mapping_size = frametable_size < MB(32) ? MB(2) : MB(32); #ifdef CONFIG_ARM_64 lpae_t *second, pte; - unsigned long nr_second, second_base; + unsigned long nr_second; + mfn_t second_base; int i; #endif @@ -908,18 +909,19 @@ 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(second_base); + second = mfn_to_virt(mfn_x(second_base)); for ( i = 0; i < nr_second; i++ ) { - clear_page(mfn_to_virt(second_base + i)); - pte = mfn_to_xen_entry(_mfn(second_base + i), WRITEALLOC); + clear_page(mfn_to_virt(mfn_x(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); } - create_mappings(second, 0, base_mfn, frametable_size >> PAGE_SHIFT, mapping_size); + create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> PAGE_SHIFT, + mapping_size); #else - create_mappings(xen_second, FRAMETABLE_VIRT_START, - base_mfn, frametable_size >> PAGE_SHIFT, mapping_size); + create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn), + frametable_size >> PAGE_SHIFT, mapping_size); #endif memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 3b34855668..277b566b88 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -561,7 +561,7 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) init_boot_pages(pfn_to_paddr(boot_mfn_start), pfn_to_paddr(boot_mfn_end)); /* Copy the DTB. */ - fdt = mfn_to_virt(alloc_boot_pages(dtb_pages, 1)); + fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1))); copy_from_paddr(fdt, dtb_paddr, dtb_size); device_tree_flattened = fdt; @@ -671,7 +671,7 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) dtb_pages = (dtb_size + PAGE_SIZE-1) >> PAGE_SHIFT; /* Copy the DTB. */ - fdt = mfn_to_virt(alloc_boot_pages(dtb_pages, 1)); + fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1))); copy_from_paddr(fdt, dtb_paddr, dtb_size); device_tree_flattened = fdt; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 66e337109d..dc54ebf2e6 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -200,7 +200,7 @@ static void __init init_frametable_chunk(void *start, void *end) */ while ( step && s + (step << PAGE_SHIFT) > e + (4 << PAGE_SHIFT) ) step >>= PAGETABLE_ORDER; - mfn = alloc_boot_pages(step, step); + mfn = mfn_x(alloc_boot_pages(step, step)); map_pages_to_xen(s, mfn, step, PAGE_HYPERVISOR); } @@ -5417,7 +5417,7 @@ void *alloc_xen_pagetable(void) return ptr; } - return mfn_to_virt(alloc_boot_pages(1, 1)); + return mfn_to_virt(mfn_x(alloc_boot_pages(1, 1))); } void free_xen_pagetable(void *v) diff --git a/xen/arch/x86/numa.c b/xen/arch/x86/numa.c index ffeba6e180..90422517b0 100644 --- a/xen/arch/x86/numa.c +++ b/xen/arch/x86/numa.c @@ -99,7 +99,7 @@ static int __init populate_memnodemap(const struct node *nodes, static int __init allocate_cachealigned_memnodemap(void) { unsigned long size = PFN_UP(memnodemapsize * sizeof(*memnodemap)); - unsigned long mfn = alloc_boot_pages(size, 1); + unsigned long mfn = mfn_x(alloc_boot_pages(size, 1)); memnodemap = mfn_to_virt(mfn); mfn <<= PAGE_SHIFT; diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 95660a9bbc..5d38a9ac62 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -193,7 +193,7 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) "Not used.\n"); return; } - mfn = alloc_boot_pages(PFN_UP(slit->header.length), 1); + mfn = mfn_x(alloc_boot_pages(PFN_UP(slit->header.length), 1)); acpi_slit = mfn_to_virt(mfn); memcpy(acpi_slit, slit, slit->header.length); } diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 64fe951e8d..ecffac6a28 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -315,8 +315,7 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) } } -unsigned long __init alloc_boot_pages( - unsigned long nr_pfns, unsigned long pfn_align) +mfn_t __init alloc_boot_pages(unsigned long nr_pfns, unsigned long pfn_align) { unsigned long pg, _e; unsigned int i = nr_bootmem_regions; @@ -345,14 +344,14 @@ unsigned long __init alloc_boot_pages( if ( pg + nr_pfns > PFN_DOWN(highmem_start) ) continue; r->s = pg + nr_pfns; - return pg; + return _mfn(pg); } #endif _e = r->e; r->e = pg; bootmem_region_add(pg + nr_pfns, _e); - return pg; + return _mfn(pg); } BUG(); diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c index 9881db19da..52c9b4ba9a 100644 --- a/xen/drivers/acpi/osl.c +++ b/xen/drivers/acpi/osl.c @@ -214,7 +214,7 @@ void *__init acpi_os_alloc_memory(size_t sz) void *ptr; if (system_state == SYS_STATE_early_boot) - return mfn_to_virt(alloc_boot_pages(PFN_UP(sz), 1)); + return mfn_to_virt(mfn_x(alloc_boot_pages(PFN_UP(sz), 1))); ptr = xmalloc_bytes(sz); ASSERT(!ptr || is_xmalloc_memory(ptr)); diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index eb0409d832..cf3f0fc396 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -157,8 +157,7 @@ struct domain *__must_check page_get_owner_and_reference(struct page_info *); /* Boot-time allocator. Turns into generic allocator after bootstrap. */ void init_boot_pages(paddr_t ps, paddr_t pe); -unsigned long alloc_boot_pages( - unsigned long nr_pfns, unsigned long pfn_align); +mfn_t alloc_boot_pages(unsigned long nr_pfns, unsigned long pfn_align); void end_boot_allocator(void); /* Xen suballocator. These functions are interrupt-safe. */