From patchwork Wed Aug 24 10:11:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9297407 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 C09CC607F0 for ; Wed, 24 Aug 2016 10:14:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1A4728E8E for ; Wed, 24 Aug 2016 10:14:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A673E28EEA; Wed, 24 Aug 2016 10:14:08 +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 30D8328E8E for ; Wed, 24 Aug 2016 10:14:08 +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 1bcVA3-0001cF-Re; Wed, 24 Aug 2016 10:11:55 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcVA1-0001Qy-P1; Wed, 24 Aug 2016 10:11:53 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id A2/D6-03281-8E27DB75; Wed, 24 Aug 2016 10:11:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRWlGSWpSXmKPExsVyuP0Ov+6Lor3 hBh9v81u8/bqE2eL7lslMDkwehz9cYQlgjGLNzEvKr0hgzXh87wtjwVq9itenrjM3ME5S62Lk 5JAQMJJ4O/EfUxcjF4eQwEJGiV8tH1lAEmwCqhIbrp9iBbFFBNwkvnyfxQZiMwtESMz5cAqsR ljAQWLLqTtgNgtQ/b1TvWA2L1D80YIPTBAL5CSuz5wOZnMCxactfgBWIyRgL7H/7VTWCYzcCx gZVjGqF6cWlaUW6ZrpJRVlpmeU5CZm5ugaGhjr5aYWFyemp+YkJhXrJefnbmIE+rmegYFxB+O VNudDjJIcTEqivDdV94YL8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuD9UgiUEyxKTU+tSMvMAQYc TFqCg0dJhJcDGHRCvMUFibnFmekQqVOMilLivNYgCQGQREZpHlwbLMgvMcpKCfMyMjAwCPEUp BblZpagyr9iFOdgVBLm3QuynSczrwRu+iugxUxAi1vu7wZZXJKIkJJqYIzRYb9Wxmu/qeBQxd PyWZ0unQu0dRbdzJgusUfKXzYu04b/gjZDtMzPgO7+QwqODje/uHNPcrlWvyDE3NyoYqb8PP7 GiT9uh4ZN9LozUz9y7h9JHnUj1dm/yr82PKpU7ObZ495W4m4ia/I8naVT6qhaRUhJY5hyZu3i TNtrBUdzZQ7L3pqnxFKckWioxVxUnAgA9ACSrW0CAAA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1472033512!53927198!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18274 invoked from network); 24 Aug 2016 10:11:52 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-5.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 24 Aug 2016 10:11:52 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E24DFAD3B; Wed, 24 Aug 2016 10:11:51 +0000 (UTC) From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Date: Wed, 24 Aug 2016 12:11:36 +0200 Message-Id: <1472033504-23180-15-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1472033504-23180-1-git-send-email-jgross@suse.com> References: <1472033504-23180-1-git-send-email-jgross@suse.com> Cc: Juergen Gross , samuel.thibault@ens-lyon.org, wei.liu2@citrix.com Subject: [Xen-devel] [PATCH v2 14/22] mini-os: add map_frame_virt() function 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 Add a function map_frame_virt() to map a given frame and return its virtual address. On arm we just use the frame physical address, while on x86 we take a page from the virtual kernel area. For this purpose make this area available even in case of undefined CONFIG_BALLOON. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- arch/arm/balloon.c | 2 -- arch/arm/mm.c | 5 +++++ arch/x86/balloon.c | 13 ++++--------- arch/x86/mm.c | 23 +++++++++++++++++++++++ balloon.c | 9 ++++----- include/balloon.h | 1 - include/mm.h | 1 + include/x86/arch_mm.h | 1 + 8 files changed, 38 insertions(+), 17 deletions(-) diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c index 958ecba..1df7d1c 100644 --- a/arch/arm/balloon.c +++ b/arch/arm/balloon.c @@ -25,8 +25,6 @@ #ifdef CONFIG_BALLOON -unsigned long virt_kernel_area_end; /* TODO: find a virtual area */ - void arch_pfn_add(unsigned long pfn, unsigned long mfn) { } diff --git a/arch/arm/mm.c b/arch/arm/mm.c index 4f58fc7..dbde162 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -141,3 +141,8 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames) return to_virt(gnttab_table); } + +unsigned long map_frame_virt(unsigned long mfn) +{ + return mfn_to_virt(mfn); +} diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c index 16aaae4..10b440c 100644 --- a/arch/x86/balloon.c +++ b/arch/x86/balloon.c @@ -29,9 +29,6 @@ #include #ifdef CONFIG_BALLOON - -unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA; - #ifdef CONFIG_PARAVIRT static void p2m_invalidate(unsigned long *list, unsigned long start_idx) { @@ -53,7 +50,7 @@ static inline unsigned long *p2m_to_virt(unsigned long p2m) void arch_remap_p2m(unsigned long max_pfn) { - unsigned long pfn; + unsigned long pfn, new_p2m; unsigned long *l3_list, *l2_list, *l1_list; l3_list = p2m_l3list(); @@ -67,17 +64,15 @@ void arch_remap_p2m(unsigned long max_pfn) if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) ) return; + new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages)); for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES ) { - map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES), + map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES), virt_to_mfn(phys_to_machine_mapping + pfn)); } - phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end; + phys_to_machine_mapping = (unsigned long *)new_p2m; printk("remapped p2m list to %p\n", phys_to_machine_mapping); - - virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages); - ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA); } int arch_expand_p2m(unsigned long max_pfn) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index f5248a4..762599d 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -57,6 +57,7 @@ unsigned long mfn_zero; pgentry_t *pt_base; static unsigned long first_free_pfn; static unsigned long last_free_pfn; +static unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA; extern char stack[]; extern void page_walk(unsigned long va); @@ -829,3 +830,25 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames) HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); return map_frames(frames, nr_grant_frames); } + +unsigned long alloc_virt_kernel(unsigned n_pages) +{ + unsigned long addr; + + addr = virt_kernel_area_end; + virt_kernel_area_end += PAGE_SIZE * n_pages; + ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA); + + return addr; +} + +unsigned long map_frame_virt(unsigned long mfn) +{ + unsigned long addr; + + addr = alloc_virt_kernel(1); + if ( map_frame_rw(addr, mfn) ) + return 0; + + return addr; +} diff --git a/balloon.c b/balloon.c index 8669edb..b0d0230 100644 --- a/balloon.c +++ b/balloon.c @@ -50,20 +50,19 @@ void get_max_pages(void) void mm_alloc_bitmap_remap(void) { - unsigned long i; + unsigned long i, new_bitmap; if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) ) return; + new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3)); for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE ) { - map_frame_rw(virt_kernel_area_end + i, + map_frame_rw(new_bitmap + i, virt_to_mfn((unsigned long)(mm_alloc_bitmap) + i)); } - mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end; - virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3); - ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA); + mm_alloc_bitmap = (unsigned long *)new_bitmap; } #define N_BALLOON_FRAMES 64 diff --git a/include/balloon.h b/include/balloon.h index 8cd41af..6cfec4f 100644 --- a/include/balloon.h +++ b/include/balloon.h @@ -33,7 +33,6 @@ #define BALLOON_EMERGENCY_PAGES 64 extern unsigned long nr_max_pages; -extern unsigned long virt_kernel_area_end; extern unsigned long nr_mem_pages; void get_max_pages(void); diff --git a/include/mm.h b/include/mm.h index 953570c..4fc364f 100644 --- a/include/mm.h +++ b/include/mm.h @@ -79,6 +79,7 @@ int do_map_frames(unsigned long addr, unsigned long increment, domid_t id, int *err, unsigned long prot); int unmap_frames(unsigned long va, unsigned long num_frames); int map_frame_rw(unsigned long addr, unsigned long mfn); +unsigned long map_frame_virt(unsigned long mfn); #ifdef HAVE_LIBC extern unsigned long heap, brk, heap_mapped, heap_end; #endif diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h index e0ae552..9372f1e 100644 --- a/include/x86/arch_mm.h +++ b/include/x86/arch_mm.h @@ -277,6 +277,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine) pgentry_t *need_pgt(unsigned long addr); void arch_mm_preinit(void *p); +unsigned long alloc_virt_kernel(unsigned n_pages); #endif