All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Daniel Kiper <daniel.kiper@oracle.com>
Cc: jgross@suse.com, grub-devel@gnu.org, keir@xen.org,
	ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
	andrew.cooper3@citrix.com, gang.wei@intel.com,
	roy.franz@linaro.org, ning.sun@intel.com,
	david.vrabel@citrix.com, jbeulich@suse.com, phcoder@gmail.com,
	xen-devel@lists.xenproject.org, wei.liu2@citrix.com,
	richard.l.maliszewski@intel.com, qiaowei.ren@intel.com,
	fu.wei@linaro.org
Subject: Re: [PATCH v2 19/23] x86/efi: create new early memory allocator
Date: Mon, 10 Aug 2015 15:49:19 -0400	[thread overview]
Message-ID: <20150810194919.GP13576__7811.61190611801$1439236286$gmane$org@l.oracle.com> (raw)
In-Reply-To: <1437402558-7313-20-git-send-email-daniel.kiper@oracle.com>

On Mon, Jul 20, 2015 at 04:29:14PM +0200, Daniel Kiper wrote:
> There is a problem with place_string() which is used as early memory
> allocator. It gets memory chunks starting from start symbol and
> going down. Sadly this does not work when Xen is loaded using multiboot2
> protocol because start lives on 1 MiB address. So, I tried to use

s/So, I tried to use/With/
> mem_lower address calculated by GRUB2. However, it works only on some

s/GRUB2. However, //

> machines. There are machines in the wild (e.g. Dell PowerEdge R820)
> which uses first ~640 KiB for boot services code or data... :-(((
> 
> In case of multiboot2 protocol we need that place_string() only allocate

s/only/to only/
> memory chunk for EFI memory map. However, I think that it should be fixed
> instead of making another function used just in one case. I thought about
> two solutions.

s/I think ...two solutions/There are two solutions:/

> 
> 1) We could use native EFI allocation functions (e.g. AllocatePool()
>    or AllocatePages()) to get memory chunk. However, later (somewhere
>    in __start_xen()) we must copy its contents to safe place or reserve
>    this in e820 memory map and map it in Xen virtual address space.
>    In later case we must also care about conflicts with e.g. crash
>    kernel regions which could be quite difficult.
> 
> 2) We may allocate memory area statically somewhere in Xen code which
>    could be used as memory pool for early dynamic allocations. Looks
>    quite simple. Additionally, it would not depend on EFI at all and
>    could be used on legacy BIOS platforms if we need it. However, we
>    must carefully choose size of this pool. We do not want increase
>    Xen binary size too much and waste too much memory but also we must fit

Aren't we gziping the binary? In which you do not waste that much disk space.

>    at least memory map on x86 EFI platforms. As I saw on small machine,

s/at least memory map on/on small memory/

s/As I saw on small machine/For example on/

>    e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more
>    than 200 entries. Every entry on x86-64 platform is 40 bytes in size.

s/entries. Every entry on .. is/wherein every entry is/

>    So, it means that we need more than 8 KiB for EFI memory map only.

s/So, it means that we need more than/Brings it up to/

>    Additionally, if we want to use this memory pool for Xen and modules
>    command line storage (it would be used when xen.efi is executed as EFI
>    application) then we should add, I think, about 1 KiB. In this case,

s/,I think, //

>    to be on safe side, we should assume at least 64 KiB pool for early
>    memory allocations, which is about 4 times of our earlier calculations.
>    However, during discussion on Xen-devel Jan Beulich suggested that
>    just in case we should use 1 MiB memory pool like it was in original
>    place_string() implementation. So, let's use 1 MiB as it was proposed.

s/If we think that we should not/To not/

>    If we think that we should not waste unallocated memory in the pool
>    on running system then we can mark this region as __initdata and move
>    all required data to dynamically allocated places somewhere in __start_xen().
> 
> Now solution #2 is implemented but maybe we should consider #1 one day.

s/Now ../This patch implements #2 solution./

> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> with the
adjustments mentioned.
> ---
>  xen/arch/x86/efi/efi-boot.h |   38 ++++++++++++++++++++++++++++++--------
>  xen/arch/x86/setup.c        |    3 +--
>  2 files changed, 31 insertions(+), 10 deletions(-)
> 
> diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
> index 2dd69f6..3d25c48 100644
> --- a/xen/arch/x86/efi/efi-boot.h
> +++ b/xen/arch/x86/efi/efi-boot.h
> @@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long phys)
>          *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
>  }
>  
> +#define EBMALLOC_SIZE	MB(1)
> +
> +static char __initdata ebmalloc_mem[EBMALLOC_SIZE];
> +static char __initdata *ebmalloc_free = NULL;
> +
> +/* EFI boot allocator. */
> +static void __init *ebmalloc(size_t size)
> +{
> +    void *ptr;
> +
> +    /*
> +     * Init ebmalloc_free on runtime. Static initialization
> +     * will not work because it puts virtual address there.

And why is that bad?

> +     */
> +    if ( ebmalloc_free == NULL )
> +        ebmalloc_free = ebmalloc_mem;
> +
> +    ptr = ebmalloc_free;
> +
> +    ebmalloc_free += size;
> +
> +    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
> +        blexit(L"Out of static memory\r\n");
> +
> +    return ptr;
> +}
> +
>  static void __init place_string(u32 *addr, const char *s)
>  {
> -    static char *__initdata alloc = start;
> +    char *alloc = NULL;
>  
>      if ( s && *s )
>      {
> @@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
>          const char *old = (char *)(long)*addr;
>          size_t len2 = *addr ? strlen(old) + 1 : 0;
>  
> -        alloc -= len1 + len2;
> +        alloc = ebmalloc(len1 + len2);
>          /*
>           * Insert new string before already existing one. This is needed
>           * for options passed on the command line to override options from
> @@ -196,12 +223,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
>  
>  static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
>  {
> -    place_string(&mbi.mem_upper, NULL);
> -    mbi.mem_upper -= map_size;
> -    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
> -    if ( mbi.mem_upper < xen_phys_start )
> -        return NULL;
> -    return (void *)(long)mbi.mem_upper;
> +    return ebmalloc(map_size);
>  }
>  
>  static void __init efi_arch_pre_exit_boot(void)
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index bce708c..a59fc4e 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -994,8 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>  
>      if ( !xen_phys_start )
>          panic("Not enough memory to relocate Xen.");
> -    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
> -                     __pa(&_end));
> +    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
>  
>      /* Late kexec reservation (dynamic start address). */
>      kexec_reserve_area(&boot_e820);
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  parent reply	other threads:[~2015-08-10 19:49 UTC|newest]

Thread overview: 201+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-20 14:28 [PATCH v2 00/23] x86: multiboot2 protocol support Daniel Kiper
2015-07-20 14:28 ` [PATCH v2 01/23] x86/boot: remove unneeded instruction Daniel Kiper
2015-07-24 16:22   ` Konrad Rzeszutek Wilk
2015-07-24 16:22   ` Konrad Rzeszutek Wilk
2015-07-27 19:46     ` Daniel Kiper
2015-08-10 16:07       ` Konrad Rzeszutek Wilk
2015-08-10 16:07       ` Konrad Rzeszutek Wilk
2015-07-27 19:46     ` Daniel Kiper
2015-07-20 14:28 ` Daniel Kiper
2015-07-20 14:28 ` [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file Daniel Kiper
2015-07-20 14:28 ` Daniel Kiper
2015-07-21  9:35   ` Jan Beulich
2015-07-21 17:23     ` Daniel Kiper
2015-07-22  5:14       ` Jan Beulich
2015-07-22  8:02       ` Jan Beulich
2015-07-22 13:31         ` Daniel Kiper
2015-07-22 14:07           ` Jan Beulich
2015-07-20 14:28 ` [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb Daniel Kiper
2015-07-20 14:28 ` Daniel Kiper
2015-07-21  9:37   ` Jan Beulich
2015-07-21 18:23     ` Daniel Kiper
2015-07-22  5:18       ` Jan Beulich
2015-07-22  8:42         ` Andrew Cooper
2015-07-22 10:04           ` Jan Beulich
2015-07-22 11:22             ` Andrew Cooper
2015-07-22 11:48               ` Jan Beulich
2015-07-20 14:28 ` [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention Daniel Kiper
2015-07-20 14:28 ` Daniel Kiper
2015-08-10 16:33   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 16:33   ` Konrad Rzeszutek Wilk
2015-08-17 15:44   ` Jan Beulich
2015-08-17 15:44   ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions Daniel Kiper
2015-08-17 15:51   ` Jan Beulich
2015-08-17 22:03     ` Daniel Kiper
2015-08-17 15:51   ` Jan Beulich
2015-07-20 14:29 ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 06/23] x86/boot: use %ecx instead of %eax Daniel Kiper
2015-07-20 14:29 ` Daniel Kiper
2015-08-10 16:36   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 16:36   ` Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit Daniel Kiper
2015-08-10 16:40   ` Konrad Rzeszutek Wilk
2015-08-10 16:40   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-17 15:55   ` Jan Beulich
2015-08-17 15:55   ` Jan Beulich
2015-07-20 14:29 ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 08/23] x86: add multiboot2 protocol support Daniel Kiper
2015-08-10 19:17   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-13 19:22     ` Daniel Kiper
2015-08-14 10:03       ` Jan Beulich
2015-08-15  6:00         ` Andrew Cooper
2015-08-15  6:00         ` [Xen-devel] " Andrew Cooper
2015-08-14 10:03       ` Jan Beulich
2015-08-13 19:22     ` Daniel Kiper
2015-08-10 19:17   ` Konrad Rzeszutek Wilk
2015-08-18  8:12   ` Jan Beulich
2015-08-18 12:00     ` Daniel Kiper
2015-08-18 14:20       ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 09/23] efi: create efi_enabled() Daniel Kiper
2015-08-10 19:20   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:20   ` Konrad Rzeszutek Wilk
2015-08-20 15:18   ` Jan Beulich
2015-08-22 12:33     ` Daniel Kiper
2015-08-22 12:33     ` Daniel Kiper
2015-08-24 11:29       ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 10/23] efi: build xen.gz with EFI code Daniel Kiper
2015-07-20 14:29 ` Daniel Kiper
2015-08-10 19:24   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:24   ` Konrad Rzeszutek Wilk
2015-08-20 15:39   ` Jan Beulich
2015-08-22 13:59     ` Daniel Kiper
2015-08-24 11:35       ` Jan Beulich
2015-08-24 20:54         ` Daniel Kiper
2015-08-24 20:54         ` Daniel Kiper
2015-08-25 10:50           ` Andrew Cooper
2015-08-25 15:39             ` Daniel Kiper
2015-08-25 15:39             ` Daniel Kiper
2015-08-25 10:50           ` Andrew Cooper
2015-08-25 12:09           ` Jan Beulich
2015-08-25 12:09           ` Jan Beulich
2015-08-25 16:31             ` Daniel Kiper
2015-08-26  6:46               ` Jan Beulich
2015-08-26 12:33                 ` Daniel Kiper
2015-08-26 12:40                   ` Jan Beulich
2015-08-26 12:58                     ` Daniel Kiper
2015-08-26 12:58                     ` Daniel Kiper
2015-08-26 12:40                   ` Jan Beulich
2015-08-26 12:33                 ` Daniel Kiper
2015-08-26  6:46               ` Jan Beulich
2015-08-25 16:31             ` Daniel Kiper
2015-08-22 13:59     ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 11/23] efi: split out efi_init() Daniel Kiper
2015-08-10 19:25   ` Konrad Rzeszutek Wilk
2015-08-10 19:25   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 12/23] efi: split out efi_console_set_mode() Daniel Kiper
2015-07-20 14:29 ` Daniel Kiper
2015-08-10 19:25   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:25   ` Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 13/23] efi: split out efi_get_gop() Daniel Kiper
2015-07-20 14:29 ` Daniel Kiper
2015-08-10 19:27   ` Konrad Rzeszutek Wilk
2015-08-10 19:27   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 14/23] efi: split out efi_find_gop_mode() Daniel Kiper
2015-08-10 19:31   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:31   ` Konrad Rzeszutek Wilk
2015-08-20 15:48   ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 15/23] efi: split out efi_tables() Daniel Kiper
2015-08-10 19:32   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:32   ` Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 16/23] efi: split out efi_variables() Daniel Kiper
2015-08-10 19:34   ` Konrad Rzeszutek Wilk
2015-08-10 19:34   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 17/23] efi: split out efi_set_gop_mode() Daniel Kiper
2015-08-10 19:34   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:34   ` Konrad Rzeszutek Wilk
2015-07-20 14:29 ` [PATCH v2 18/23] efi: split out efi_exit_boot() Daniel Kiper
2015-08-10 19:36   ` Konrad Rzeszutek Wilk
2015-08-10 19:36   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-07-20 14:29 ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 19/23] x86/efi: create new early memory allocator Daniel Kiper
2015-08-10 19:49   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-10 19:49   ` Konrad Rzeszutek Wilk [this message]
2015-08-27 11:23   ` Jan Beulich
2015-08-27 11:23   ` Jan Beulich
2015-07-20 14:29 ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms Daniel Kiper
2015-08-10 20:07   ` Konrad Rzeszutek Wilk
2015-08-10 20:07   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-11 15:23   ` Konrad Rzeszutek Wilk
2015-08-11 15:23   ` Konrad Rzeszutek Wilk
2015-08-27 12:01   ` Jan Beulich
2015-09-22 15:21     ` Daniel Kiper
2015-09-22 15:58       ` Jan Beulich
2015-09-22 15:58       ` Jan Beulich
2015-08-27 12:01   ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 21/23] x86/boot: implement early command line parser in C Daniel Kiper
2015-07-20 14:29 ` Daniel Kiper
2015-08-10 20:31   ` Konrad Rzeszutek Wilk
2015-08-10 20:31   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-11 14:43   ` Konrad Rzeszutek Wilk
2015-08-11 14:43   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-27 12:43   ` Jan Beulich
2015-08-27 12:43   ` Jan Beulich
2015-09-22 17:03     ` Daniel Kiper
2015-09-22 17:03     ` Daniel Kiper
2015-09-23  7:25       ` Jan Beulich
2015-09-23  7:25       ` Jan Beulich
2015-07-20 14:29 ` [PATCH v2 22/23] x86: make Xen early boot code relocatable Daniel Kiper
2015-08-11 16:48   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-14 11:52     ` Daniel Kiper
2015-08-14 11:52     ` [Xen-devel] " Daniel Kiper
2015-08-14 12:49       ` Jan Beulich
2015-08-14 12:49       ` [Xen-devel] " Jan Beulich
2015-08-14 13:59         ` Daniel Kiper
2015-08-14 14:32           ` Jan Beulich
2015-08-14 14:37             ` Daniel Kiper
2015-08-14 14:37             ` [Xen-devel] " Daniel Kiper
2015-08-14 15:12               ` Jan Beulich
2015-08-14 15:12                 ` [Xen-devel] " Jan Beulich
2015-08-14 14:32           ` Jan Beulich
2015-08-14 13:59         ` Daniel Kiper
2015-08-14 15:20       ` Konrad Rzeszutek Wilk
2015-08-14 15:20       ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-08-11 16:48   ` Konrad Rzeszutek Wilk
2015-08-27 13:12   ` Jan Beulich
2015-08-27 15:10     ` Daniel Kiper
2015-08-27 15:10     ` Daniel Kiper
2015-08-27 15:29       ` Jan Beulich
2015-08-27 17:56         ` Ben Hildred
2015-08-28  8:22           ` Jan Beulich
2015-08-28  8:22           ` [Xen-devel] " Jan Beulich
2015-08-28 13:42             ` Konrad Rzeszutek Wilk
2015-08-28 14:16               ` Jan Beulich
2015-08-28 14:16                 ` [Xen-devel] " Jan Beulich
2015-08-31 19:49                 ` Daniel Kiper
2015-08-31 19:49                 ` [Xen-devel] " Daniel Kiper
2015-09-01  6:59                   ` Jan Beulich
2015-09-01  6:59                   ` Jan Beulich
2015-08-28 13:42             ` Konrad Rzeszutek Wilk
2015-08-27 17:56         ` Ben Hildred
2015-08-27 18:04         ` Andrew Cooper
2015-08-28  6:54           ` Jan Beulich
2015-08-28 11:59             ` Andrew Cooper
2015-08-28 11:59             ` Andrew Cooper
2015-08-28  6:54           ` Jan Beulich
2015-08-27 18:04         ` Andrew Cooper
2015-08-28 14:24         ` [Xen-devel] " Jan Beulich
2015-08-28 14:24         ` Jan Beulich
2015-08-27 15:29       ` Jan Beulich
2015-08-27 13:12   ` Jan Beulich
2015-07-20 14:29 ` Daniel Kiper
2015-07-20 14:29 ` [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images Daniel Kiper
2015-08-11 16:56   ` Konrad Rzeszutek Wilk
2015-08-14 11:57     ` Daniel Kiper
2015-08-14 13:43       ` Konrad Rzeszutek Wilk
2015-08-14 13:43       ` Konrad Rzeszutek Wilk
2015-08-14 11:57     ` Daniel Kiper
2015-08-11 16:56   ` Konrad Rzeszutek Wilk
2015-07-21  9:39 ` [PATCH v2 00/23] x86: multiboot2 protocol support Jan Beulich
2015-07-21  9:39 ` Jan Beulich

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='20150810194919.GP13576__7811.61190611801$1439236286$gmane$org@l.oracle.com' \
    --to=konrad.wilk@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=daniel.kiper@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=fu.wei@linaro.org \
    --cc=gang.wei@intel.com \
    --cc=grub-devel@gnu.org \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=keir@xen.org \
    --cc=ning.sun@intel.com \
    --cc=phcoder@gmail.com \
    --cc=qiaowei.ren@intel.com \
    --cc=richard.l.maliszewski@intel.com \
    --cc=roy.franz@linaro.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.