From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
xen-devel@lists.xenproject.org, wei.liu2@citrix.com
Subject: Re: [PATCH 21/22] mini-os: get physical memory map
Date: Wed, 24 Aug 2016 00:58:21 +0200 [thread overview]
Message-ID: <20160823225821.GO4401@var.home> (raw)
In-Reply-To: <1471965368-6159-22-git-send-email-jgross@suse.com>
Juergen Gross, on Tue 23 Aug 2016 17:16:07 +0200, wrote:
> On HVMlite we have to look at the physical memory map to know which
> memory frames are usable.
>
> In order to make life easier we define a dummy memory map for other
> domain types (pv and arm) which has just one entry with a maximum
> memory size.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> arch/arm/mm.c | 8 ++++++
> arch/x86/mm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++
> arch/x86/setup.c | 1 +
> include/e820.h | 48 +++++++++++++++++++++++++++++++
> include/x86/arch_mm.h | 4 +++
> mm.c | 79 ++++++++++++++++++++++++++++++++-------------------
> 6 files changed, 183 insertions(+), 29 deletions(-)
> create mode 100644 include/e820.h
>
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index dbde162..8c156c4 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -7,6 +7,14 @@
> #include <lib.h>
>
> uint32_t physical_address_offset;
> +struct e820entry e820_map[1] = {
> + {
> + .addr = 0,
> + .size = ULONG_MAX - 1,
> + .type = E820_RAM
> + }
> +};
> +unsigned e820_entries = 1;
>
> unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
> {
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index 762599d..8dd90b8 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -43,6 +43,7 @@
> #include <mini-os/types.h>
> #include <mini-os/lib.h>
> #include <mini-os/xmalloc.h>
> +#include <mini-os/e820.h>
> #include <xen/memory.h>
>
> #ifdef MM_DEBUG
> @@ -63,6 +64,15 @@ extern char stack[];
> extern void page_walk(unsigned long va);
>
> #ifdef CONFIG_PARAVIRT
> +struct e820entry e820_map[1] = {
> + {
> + .addr = 0,
> + .size = ULONG_MAX - 1,
> + .type = E820_RAM
> + }
> +};
> +unsigned e820_entries = 1;
> +
> void arch_mm_preinit(void *p)
> {
> start_info_t *si = p;
> @@ -102,10 +112,25 @@ desc_ptr idt_ptr =
> .base = (unsigned long)&idt,
> };
>
> +struct e820entry e820_map[E820_MAX];
> +unsigned e820_entries;
> +
> +static char *e820_types[E820_TYPES] = {
> + [E820_RAM] = "RAM",
> + [E820_RESERVED] = "Reserved",
> + [E820_ACPI] = "ACPI",
> + [E820_NVS] = "NVS",
> + [E820_UNUSABLE] = "Unusable",
> + [E820_PMEM] = "PMEM"
> +};
> +
> void arch_mm_preinit(void *p)
> {
> long ret;
> domid_t domid = DOMID_SELF;
> + struct xen_memory_map memmap;
> + int i;
> + unsigned long pfn, max = 0;
>
> pt_base = page_table_base;
> first_free_pfn = PFN_UP(to_phys(&_end));
> @@ -116,6 +141,53 @@ void arch_mm_preinit(void *p)
> do_exit();
> }
> last_free_pfn = ret;
> +
> + memmap.nr_entries = E820_MAX;
> + set_xen_guest_handle(memmap.buffer, e820_map);
> + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
> + if ( ret < 0 )
> + {
> + xprintk("could not get memory map\n");
> + do_exit();
> + }
> + e820_entries = memmap.nr_entries;
> +
> + for ( i = 0; i < e820_entries; i++ )
> + {
> + if ( e820_map[i].type != E820_RAM )
> + continue;
> + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT;
> + if ( pfn > max )
> + max = pfn;
> + }
> +
> + if ( max < last_free_pfn )
> + last_free_pfn = max;
> +}
> +
> +void arch_print_memmap(void)
> +{
> + int i;
> + unsigned long from, to;
> + char *type;
> + char buf[12];
> +
> + printk("Memory map:\n");
> + for ( i = 0; i < e820_entries; i++ )
> + {
> + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] )
> + {
> + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type);
> + type = buf;
> + }
> + else
> + {
> + type = e820_types[e820_map[i].type];
> + }
> + from = e820_map[i].addr;
> + to = from + e820_map[i].size - 1;
> + printk("%012lx-%012lx: %s\n", from, to, type);
> + }
> }
> #endif
>
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 948b08a..829b03c 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -150,6 +150,7 @@ static void print_start_of_day(void *p)
> printk(" flags: 0x%x\n", (unsigned int)si->flags);
> printk(" cmd_line: %s\n", cmdline);
> printk(" stack: %p-%p\n", stack, stack + sizeof(stack));
> + arch_print_memmap();
> }
> #endif
>
> diff --git a/include/e820.h b/include/e820.h
> new file mode 100644
> index 0000000..920551c
> --- /dev/null
> +++ b/include/e820.h
> @@ -0,0 +1,48 @@
> +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
> + *
> + * (C) 2016 - Juergen Gross, SUSE Linux GmbH
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
> + * sell copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef __E820_HEADER
> +#define __E820_HEADER
> +
> +/* PC BIOS standard E820 types and structure. */
> +#define E820_RAM 1
> +#define E820_RESERVED 2
> +#define E820_ACPI 3
> +#define E820_NVS 4
> +#define E820_UNUSABLE 5
> +#define E820_PMEM 7
> +#define E820_TYPES 8
> +
> +struct __packed e820entry {
> + uint64_t addr;
> + uint64_t size;
> + uint32_t type;
> +};
> +
> +/* Maximum number of entries. */
> +#define E820_MAX 128
> +
> +extern struct e820entry e820_map[];
> +extern unsigned e820_entries;
> +
> +#endif /*__E820_HEADER*/
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index 9372f1e..ab8a53e 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -279,6 +279,10 @@ pgentry_t *need_pgt(unsigned long addr);
> void arch_mm_preinit(void *p);
> unsigned long alloc_virt_kernel(unsigned n_pages);
>
> +#ifndef CONFIG_PARAVIRT
> +void arch_print_memmap(void);
> +#endif
> +
> #endif
>
> #endif /* _ARCH_MM_H_ */
> diff --git a/mm.c b/mm.c
> index c76be7f..932ceeb 100644
> --- a/mm.c
> +++ b/mm.c
> @@ -43,6 +43,7 @@
> #include <mini-os/types.h>
> #include <mini-os/lib.h>
> #include <mini-os/xmalloc.h>
> +#include <mini-os/e820.h>
>
> /*********************
> * ALLOCATION BITMAP
> @@ -147,10 +148,14 @@ static chunk_head_t free_tail[FREELIST_SIZE];
> */
> static void init_page_allocator(unsigned long min, unsigned long max)
> {
> - int i;
> + int i, m;
> unsigned long range;
> + unsigned long r_min, r_max;
> chunk_head_t *ch;
> chunk_tail_t *ct;
> +
> + printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
> + (u_long)to_virt(min), min, (u_long)to_virt(max), max);
> for ( i = 0; i < FREELIST_SIZE; i++ )
> {
> free_head[i] = &free_tail[i];
> @@ -166,38 +171,57 @@ static void init_page_allocator(unsigned long min, unsigned long max)
> mm_alloc_bitmap_size = round_pgup(mm_alloc_bitmap_size);
> mm_alloc_bitmap = (unsigned long *)to_virt(min);
> min += mm_alloc_bitmap_size;
> - range = max - min;
>
> /* All allocated by default. */
> memset(mm_alloc_bitmap, ~0, mm_alloc_bitmap_size);
> - /* Free up the memory we've been given to play with. */
> - map_free(PHYS_PFN(min), range>>PAGE_SHIFT);
>
> - /* The buddy lists are addressed in high memory. */
> - min = (unsigned long) to_virt(min);
> - max = (unsigned long) to_virt(max);
> -
> - while ( range != 0 )
> + for ( m = 0; m < e820_entries; m++ )
> {
> - /*
> - * Next chunk is limited by alignment of min, but also
> - * must not be bigger than remaining range.
> - */
> - for ( i = PAGE_SHIFT; (1UL<<(i+1)) <= range; i++ )
> - if ( min & (1UL<<i) ) break;
> + if ( e820_map[m].type != E820_RAM )
> + continue;
> + if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
> + BUG();
>
> + r_min = e820_map[m].addr;
> + r_max = r_min + e820_map[m].size;
> + if ( r_max <= min || r_min >= max )
> + continue;
> + if ( r_min < min )
> + r_min = min;
> + if ( r_max > max )
> + r_max = max;
>
> - ch = (chunk_head_t *)min;
> - min += (1UL<<i);
> - range -= (1UL<<i);
> - ct = (chunk_tail_t *)min-1;
> - i -= PAGE_SHIFT;
> - ch->level = i;
> - ch->next = free_head[i];
> - ch->pprev = &free_head[i];
> - ch->next->pprev = &ch->next;
> - free_head[i] = ch;
> - ct->level = i;
> + printk(" Adding memory range %lx-%lx\n", r_min, r_max);
> +
> + /* The buddy lists are addressed in high memory. */
> + r_min = (unsigned long)to_virt(r_min);
> + r_max = (unsigned long)to_virt(r_max);
> + range = r_max - r_min;
> +
> + /* Free up the memory we've been given to play with. */
> + map_free(PHYS_PFN(r_min), range >> PAGE_SHIFT);
> +
> + while ( range != 0 )
> + {
> + /*
> + * Next chunk is limited by alignment of min, but also
> + * must not be bigger than remaining range.
> + */
> + for ( i = PAGE_SHIFT; (1UL << (i + 1)) <= range; i++ )
> + if ( r_min & (1UL << i) ) break;
> +
> + ch = (chunk_head_t *)r_min;
> + r_min += 1UL << i;
> + range -= 1UL << i;
> + ct = (chunk_tail_t *)r_min - 1;
> + i -= PAGE_SHIFT;
> + ch->level = i;
> + ch->next = free_head[i];
> + ch->pprev = &free_head[i];
> + ch->next->pprev = &ch->next;
> + free_head[i] = ch;
> + ct->level = i;
> + }
> }
>
> mm_alloc_bitmap_remap();
> @@ -377,9 +401,6 @@ void init_mm(void)
> /*
> * now we can initialise the page allocator
> */
> - printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
> - (u_long)to_virt(PFN_PHYS(start_pfn)), (u_long)PFN_PHYS(start_pfn),
> - (u_long)to_virt(PFN_PHYS(max_pfn)), (u_long)PFN_PHYS(max_pfn));
> init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
> printk("MM: done\n");
>
> --
> 2.6.6
>
--
Samuel
Les roots ne sont plus ce qu'ils étaient...Maintenant il sont dioxinés,
c'est de la m... ! Avant on les élevaient avec du bon unix mais ça été
remplacé par des farines industrielles nouvelles technologies (NT).
-+- JdK in NPC : Exigez un root élevé sous la mère ! -+-
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-23 22:58 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
2016-08-23 19:44 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
2016-08-23 19:44 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
2016-08-23 19:54 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
2016-08-23 19:46 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
2016-08-23 20:51 ` Samuel Thibault
2016-08-24 5:13 ` Juergen Gross
2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
2016-08-23 21:03 ` Samuel Thibault
2016-08-24 5:10 ` Juergen Gross
2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
2016-08-23 22:00 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
2016-08-23 22:05 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
2016-08-23 22:10 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
2016-08-23 22:20 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
2016-08-23 22:27 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
2016-08-23 22:40 ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
2016-08-23 19:49 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
2016-08-23 22:42 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
2016-08-23 22:44 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
2016-08-23 22:45 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
2016-08-23 23:03 ` [Minios-devel] " Samuel Thibault
2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
2016-08-23 22:47 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
2016-08-23 22:48 ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
2016-08-23 22:51 ` Samuel Thibault
2016-08-24 5:09 ` Juergen Gross
2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
2016-08-23 22:58 ` Samuel Thibault [this message]
2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
2016-08-23 23:01 ` Samuel Thibault
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160823225821.GO4401@var.home \
--to=samuel.thibault@ens-lyon.org \
--cc=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).