x86: "brk" allocator
v2 cover x86: "brk" allocator
Derive for our purposes something similar to what Linux has been having for a long while.
v2 is merely a re-base, mainly targeted at reminding people that this series is still pending review.
1: x86: introduce "brk" allocator
2: x86/EFI: replace ebmalloc()
3: xhci-dbc: use brk_alloc()
To reduce padding holes, .bss.page_aligned and per-CPU data may want moving immediately ahead of __brk_start[]. Albeit then the tail of per-CPU data will all be padding space; sadly the TSS wants/needs page-aligning for XPTI purposes.
Jan
PATCH v2 1/3 x86: introduce "brk" allocator
... to replace ebmalloc(), and then to find further use(s) to allow recovering memory which is needed very early (and hence needs setting up statically), but may not fully be used (or not used at all).
Note that unlike free_ebmalloc_unused_mem(), brk_free_unused() (once other code is converted) will be able to free part of the BRK space even in the xen.efi case. That would happen if BRK space extends across a 2Mb boundary, and actual use stops before that boundary.
---
Changing setup.c's reserve_e820_ram() uses would be cumbersome when done right here. That'll be done when ebmalloc() is replaced, and hence what's there can also simply be replaced.
The xen.efi detection may want separating out into a helper.
When linking xen.efi, ld produces a base relocation for the reference to __subsystem__, which is wrong (that's an absolute symbol, after all). While that will need fixing there, it does no harm for our purposes.
xen/arch/x86/boot/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-bin-y += head.o +obj-bin-y += brk.init.o obj-bin-y += built-in-32.o obj-bin-y += $(obj64)
xen/arch/x86/boot/brk.c new file +72 -0
72 lines not on this page · raw message
xen/arch/x86/include/asm/brk.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/types.h> + +void *brk_alloc (size_t size); +unsigned long brk_get_unused_start (void ); +void brk_free_unused (void );
xen/arch/x86/xen.lds.S +5 -1
@@ -321,7 +321,11 @@ SECTIONS __bss_start = .; *(.bss.page_aligned*) PERCPU_BSS - *(.bss .bss.*) + *(.bss .bss.[a-zA-Z0-9_]*) + . = ALIGN(PAGE_SIZE); + __brk_start = .; + *(.bss..brk.page_aligned*) + *(.bss..brk*) . = ALIGN(POINTER_ALIGN); __bss_end = .; } PHDR(text)
xen/arch/x86/mm.c +3 -0
@@ -112,6 +112,7 @@#include <xen/vmap.h> #include <xen/xmalloc.h> +#include <asm/brk.h> #include <asm/e820.h> #include <asm/fixmap.h> #include <asm/flushtlb.h>
@@ -338,6 +339,8 @@ void __init arch_init_memory(void)efi_init_memory (); +brk_free_unused (); +#ifndef NDEBUG if ( highmem_start ) {
Re: [PATCH v2 1/3] x86: introduce "brk" allocator
Quoted 15 lines · Jan Beulich
... to replace
ebmalloc(), and then to find further use(s) to allow recovering memory which is needed very early (and hence needs setting up statically), but may not fully be used (or not used at all).Note that unlike
free_ebmalloc_unused_mem(),brk_free_unused()(once other code is converted) will be able to free part of the BRK space even in the xen.efi case. That would happen if BRK space extends across a 2Mb boundary, and actual use stops before that boundary.Signed-off-by Jan Beulich <[email protected]>---
Changing setup.c'sreserve_e820_ram()uses would be cumbersome when done right here. That'll be done whenebmalloc()is replaced, and hence what's there can also simply be replaced.
Quoted 5 lines
The xen.efi detection may want separating out into a helper.
When linking xen.efi, ld produces a base relocation for the reference to
__subsystem__, which is wrong (that's an absolute symbol, after all). While that will need fixing there, it does no harm for our purposes.
This remark is stale, I've updated it to:
"When linking xen.efi, GNU ld prior to 2.46 produces a base relocation for
the reference to __subsystem__, which is wrong (that's an absolute symbol, after all). That does no harm for our purposes, though."
Jan
Re: [PATCH v2 1/3] x86: introduce "brk" allocator
In reply to Jan Beulichxen/arch/x86/boot/brk.c
Quoted 10 lines · Jan Beulich
xen/arch/x86/boot/Makefile +1
-0@@ -1,4 +1,5 @@ obj-bin-y += head.o +obj-bin-y += brk.init.o obj-bin-y += built-in-32.o obj-bin-y += $(obj64)xen/arch/x86/boot/brk.c new file +0
-0
While brk.c has x86 specifics, I'm not sure it's worthy if being in boot/, rather than simply in x86/. It's used until mid way through __start_xen().
Quoted 21 lines
xen/arch/x86/boot/brk.c new file +20
-0@@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/efi.h> +#include <xen/lib.h> +#include <xen/mm.h> +#include <xen/page-defs.h> + +#include <asm/brk.h> + +extern char __brk_start[]; +extern const char __bss_end[]; + +static unsigned long __initdata allocated; +static bool __initdata finished; + +void *__init brk_alloc (size_t size) +{ +void *ptr = __brk_start + allocated; + +if ( finished )
xen/arch/x86/boot/brk.c line 30
Quoted 10 lines
xen/arch/x86/boot/brk.c new file +10
-0+return NULL ; + +/* Allocations PAGE_SIZE and up will be page-aligned. */ +if ( size >=PAGE_SIZE ) + allocated =ROUNDUP (allocated,PAGE_SIZE ); + + allocated +=ROUNDUP (size,sizeof (void *)); + +if ( allocated > __bss_end - __brk_start ) +return NULL ;
This means one (or more) subsystem has brk_alloc()'d more than they reserved.
While returning NULL is probably the best action, I think a printk_once() is also warranted.
xen/arch/x86/boot/brk.c line 37
Quoted 7 lines
xen/arch/x86/boot/brk.c new file +7
-0+ +return ptr; +} + +unsigned long __init brk_get_unused_start (void ) +{ + finished = true;
This doesn't get the unused start. It also terminates the allocator, and the name needs to reflect that.
But combined with brk_end in the next patch, it's really quite a mess. Integrating brk_end properly simplifies this patch too.
Quoted 38 lines
xen/arch/x86/boot/brk.c new file +35
-0+ + allocated =ROUNDUP (allocated,PAGE_SIZE ); + +return (unsigned long )__brk_start + allocated; +} + +void __init brk_free_unused (void ) +{ +unsigned long start =brk_get_unused_start (), + end = (unsigned long )__bss_end; +unsigned int subsys; + +/* +* Only xen.efi will have the symbol __subsystem__ available, and it'll +* be non-zero (10) there. In ELF the symbol will be undefined, and +* hence zero will be loaded into the register. +*/ + asm (".weak __subsystem__; mov $__subsystem__, %0" :"=r" (subsys) ); + +/* using_2M_mapping() isn't available here. */ +if (IS_ENABLED (CONFIG_XEN_ALIGN_2M ) || subsys ) + start =PAGE_ALIGN_2M (start); + +if ( start >= end ) +return ; + +destroy_xen_mappings (start,PAGE_ALIGN_2M (end)); + +/* +* By reserving needed space early in the E820 map, excess space gets freed +* way before we make it here. Don't free the range a 2nd time. +*/ + +printk (XENLOG_INFO "Freed %lukB unused BRK memory\n" , (end - start) >>10 ); +}
xen/arch/x86/include/asm/brk.h line 7
Quoted 7 lines
xen/arch/x86/include/asm/brk.h new file +7
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/types.h> + +void *brk_alloc (size_t size); +unsigned long brk_get_unused_start (void ); +void brk_free_unused (void );
It's inevitable that brk is going to be used in other architectures, and none of this is x86 specific.
This should be xen/include/brk.h right from the outset, even if that's all we do in the way of making it generic.
Except, brk_end in patch 2 really needs to live in common/brk.c so it's probably easier to go in arch-neutral right from the outset and use "select ARCH_HAS_BRK" or so to allow the arches to opt into using it.
Furthermore, this header needs some commentary. To do this nicely, DEFINE_BRK() needs to be introduced here so the comment makes sense.
-----
Early Boot memory allocator.
Subsystems which conditionally need memory prior to the main heap being set up should use DEFINE_BRK() to reserve BSS space in Xen.
During boot, brk_alloc() allocates memory from the reserved space. Such allocations are good for the lifetime of Xen. Subsystems MUST NOT brk_alloc() more memory than they reserved.
When the main heap is set up, brk allocations become unavailable. Reserved but unallocated space is handed to the main heap, so it doesn't go to waste.
-----
With just a few sentences, it's now far clearer what brk is and how to use it.
xen/arch/x86/xen.lds.S SECTIONS · line 329
Quoted 13 lines
xen/arch/x86/xen.lds.S +5
-1@@ -321,7 +321,11 @@ SECTIONS __bss_start = .; *(.bss.page_aligned*) PERCPU_BSS - *(.bss .bss.*) + *(.bss .bss.[a-zA-Z0-9_]*) + . = ALIGN(PAGE_SIZE); + __brk_start = .; + *(.bss..brk.page_aligned*) + *(.bss..brk*) . = ALIGN(POINTER_ALIGN);
This looks fine, but if it's becoming common then it wants to be a macro in xen.lds.h
~Andrew
Re: [PATCH v2 1/3] x86: introduce "brk" allocator
Quoted 7 lines · Andrew Cooper
xen/arch/x86/boot/brk.c
Quoted 2 lines · Jan Beulich
xen/arch/x86/boot/brk.c new file +0
-0While
brk.chas x86 specifics, I'm not sure it's worthy if being in boot/, rather than simply in x86/. It's used until mid way through__start_xen().
As discussed, I'll move this to common/brk.c right away, abstracting out the x86 specifics.
Quoted 35 lines
Quoted 21 lines
xen/arch/x86/boot/brk.c new file +20
-0@@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/efi.h> +#include <xen/lib.h> +#include <xen/mm.h> +#include <xen/page-defs.h> + +#include <asm/brk.h> + +extern char __brk_start[]; +extern const char __bss_end[]; + +static unsigned long __initdata allocated; +static bool __initdata finished; + +void *__init brk_alloc (size_t size) +{ +void *ptr = __brk_start + allocated; + +if ( finished )xen/arch/x86/boot/brk.c line 30
Quoted 10 lines
xen/arch/x86/boot/brk.c new file +10
-0+return NULL ; + +/* Allocations PAGE_SIZE and up will be page-aligned. */ +if ( size >=PAGE_SIZE ) + allocated =ROUNDUP (allocated,PAGE_SIZE ); + + allocated +=ROUNDUP (size,sizeof (void *)); + +if ( allocated > __bss_end - __brk_start ) +return NULL ;This means one (or more) subsystem has brk_alloc()'d more than they reserved.
Quoted 2 lines
While returning NULL is probably the best action, I think a
printk_once()is also warranted.
Hmm, yes, just that there's a quirk to work around: The static that printk_once() uses gets in the way of the file getting compiled into brk.init.o.
Quoted 10 lines
xen/arch/x86/boot/brk.c line 37
Quoted 7 lines
xen/arch/x86/boot/brk.c new file +7
-0+ +return ptr; +} + +unsigned long __init brk_get_unused_start (void ) +{ + finished = true;This doesn't get the unused start. It also terminates the allocator, and the name needs to reflect that.
brk_cease() then.
Quoted 2 lines
But combined with
brk_endin the next patch, it's really quite a mess. Integratingbrk_endproperly simplifies this patch too.
No, brk_end really is an x86-specific helper variable. I'd like to keep that as it is.
Quoted 17 lines
xen/arch/x86/include/asm/brk.h line 7
Quoted 10 lines
xen/arch/x86/include/asm/brk.h new file +7
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/types.h> + +void *brk_alloc (size_t size); +unsigned long brk_get_unused_start (void ); +void brk_free_unused (void );It's inevitable that brk is going to be used in other architectures, and none of this is x86 specific.
This should be
xen/include/brk.hright from the outset, even if that's all we do in the way of making it generic.
Quoted 6 lines
Except,
brk_endin patch 2 really needs to live incommon/brk.cso it's probably easier to go in arch-neutral right from the outset and use "selectARCH_HAS_BRK" or so to allow the arches to opt into using it.Furthermore, this header needs some commentary. To do this nicely,
DEFINE_BRK()needs to be introduced here so the comment makes sense.
Sure, I can move introduction of the macro here.
Jan
Quoted 38 lines
-----
Early Boot memory allocator.Subsystems which conditionally need memory prior to the main heap being set up should use
DEFINE_BRK()to reserve BSS space in Xen.During boot,
brk_alloc()allocates memory from the reserved space. Such allocations are good for the lifetime of Xen. Subsystems MUST NOTbrk_alloc()more memory than they reserved.When the main heap is set up, brk allocations become unavailable. Reserved but unallocated space is handed to the main heap, so it doesn't go to waste.
-----With just a few sentences, it's now far clearer what brk is and how to use it.
xen/arch/x86/xen.lds.S SECTIONS · line 329
Quoted 13 lines
xen/arch/x86/xen.lds.S +5
-1@@ -321,7 +321,11 @@ SECTIONS __bss_start = .; *(.bss.page_aligned*) PERCPU_BSS - *(.bss .bss.*) + *(.bss .bss.[a-zA-Z0-9_]*) + . = ALIGN(PAGE_SIZE); + __brk_start = .; + *(.bss..brk.page_aligned*) + *(.bss..brk*) . = ALIGN(POINTER_ALIGN);This looks fine, but if it's becoming common then it wants to be a macro in
xen.lds.h~Andrew
PATCH v2 2/3 x86/EFI: replace ebmalloc()
In reply to Jan BeulichUse the new brk_alloc() instead, with ebmalloc() merely being a thin wrapper.
---
I'm not quite certain whether we ought to permit non-page-granular reservations. The in-memory image being somewhat larger due to possibly excessive padding isn't really a big problem, I think.
---
v2: Re-base.
xen/Rules.mk +1 -1
@@ -263,7 +263,7 @@ quiet_cmd_obj_init_o = INIT_O $@ define cmd_obj_init_o $(OBJDUMP) -h $< | while read idx name sz rest; do \ case "$$name" in \ - .*.local) ;; \ + .*.local|.bss..brk*) ;; \ .text|.text.*|.data|.data.*|.bss|.bss.*) \ test $$(echo $$sz | sed 's,00*,0,') != 0 || continue; \ echo "Error: size of $<:$$name is 0x$$sz" >&2; \
xen/arch/x86/efi/efi-boot.h +13 -0
@@ -10,6 +10,7 @@#include <xen/vga.h> #include <asm/boot-helpers.h> +#include <asm/brk.h> #include <asm/e820.h> #include <asm/edd.h> #include <asm/microcode.h>
@@ -119,6 +120,18 @@ static void __init relocate_trampoline(ureloc_trampoline64 (); } +DEFINE_BRK (efi,MB (1 )); + +static void *__init ebmalloc (size_t size) +{ +void *ptr =brk_alloc (size); + +if ( !ptr ) +blexit (L"Out of BRK memory\r\n" ); + +return ptr; +} +static void __init place_string (u32 *addr,const char *s) {char *alloc =NULL ;
xen/arch/x86/efi/stub.c +0 -8
@@ -41,12 +41,4 @@ void __init noreturn efi_multiboot2(EFI_void __init efi_init_memory (void ) { } -bool efi_boot_mem_unused (unsigned long *start,unsigned long *end) -{ -/* FIXME: Simplify once the call here with two NULLs goes away. */ -if ( start || end ) - *start = *end = (unsigned long )_end; -return false; -} -void efi_update_l4_pgtable (unsigned int l4idx,l4_pgentry_t l4e) { }
xen/arch/x86/include/asm/brk.h +4 -0
@@ -2,6 +2,10 @@#include <xen/types.h> +#define DEFINE_BRK (var, size) \ + static char __section(".bss..brk.page_aligned") __aligned(PAGE_SIZE) \ + __used var ## _brk_[size] +void *brk_alloc (size_t size);unsigned long brk_get_unused_start (void );void brk_free_unused (void );
xen/arch/x86/include/asm/setup.h +2 -0
@@ -9,6 +9,8 @@ extern const char __2M_rodata_start[], _extern char __2M_init_start[], __2M_init_end[];extern char __2M_rwdata_start[], __2M_rwdata_end[]; +extern unsigned long brk_end; +extern unsigned long xenheap_initial_phys_start;extern uint64_t boot_tsc_stamp;
xen/arch/x86/setup.c +12 -34
89 lines not on this page · raw message
xen/arch/x86/tboot.c +2 -12
@@ -321,8 +321,6 @@ void tboot_shutdown(uint32_t shutdown_ty/* if this is S3 then set regions to MAC */ if ( shutdown_type ==TB_SHUTDOWN_S3 ) { -unsigned long s, e; -/* * Xen regions for tboot to MAC. This needs to remain in sync with * remove_xen_ranges().
@@ -336,16 +334,8 @@ void tboot_shutdown(uint32_t shutdown_ty g_tboot_shared->mac_regions[1 ].size = __2M_rodata_end - _stext;/* hypervisor .data + .bss */ g_tboot_shared->mac_regions[2 ].start = (uint64_t )__pa (&__2M_rwdata_start); - g_tboot_shared->mac_regions[2 ].size = __2M_rwdata_end - __2M_rwdata_start; -if (efi_boot_mem_unused (&s, &e) ) - { - g_tboot_shared->mac_regions[2 ].size = - s - (unsigned long )__2M_rwdata_start; - g_tboot_shared->mac_regions[3 ].start =__pa (e); - g_tboot_shared->mac_regions[3 ].size = - (unsigned long )__2M_rwdata_end - e; - g_tboot_shared->num_mac_regions =4 ; - } + g_tboot_shared->mac_regions[2 ].size = + brk_end - (unsigned long )__2M_rwdata_start;/* * MAC domains and other Xen memory
xen/common/efi/boot.c +0 -2
@@ -1825,8 +1825,6 @@ void __init efi_init_memory(void)pte_attr_t prot; } *extra, *extra_head =NULL ; -free_ebmalloc_unused_mem (); -if ( !efi_enabled (EFI_BOOT ) )return ;
xen/common/efi/ebmalloc.c deleted +0 -74
74 lines not on this page · raw message
xen/common/efi/efi-common.mk +1 -1
@@ -1,4 +1,4 @@ -EFIOBJ-y := boot.init.o pe.init.o ebmalloc.o runtime.o +EFIOBJ-y := boot.init.o pe.init.o runtime.o EFIOBJ-$(CONFIG_COMPAT) += compat.o CFLAGS-y += -fshort-wchar
xen/common/efi/efi.h +0 -4
@@ -48,10 +48,6 @@ void noreturn blexit(const CHAR16 *str);const CHAR16 *wmemchr (const CHAR16 *s,CHAR16 c,UINTN n); -/* EFI boot allocator. */ -void *ebmalloc (size_t size); -void free_ebmalloc_unused_mem (void ); -const void *pe_find_section (const void *image,const UINTN image_size,const CHAR16 *section_name,UINTN *size_out);
xen/include/xen/efi.h +0 -1
@@ -39,7 +39,6 @@ static inline bool efi_enabled(unsignedextern bool efi_secure_boot;void efi_init_memory (void ); -bool efi_boot_mem_unused (unsigned long *start,unsigned long *end);unsigned long efi_get_time (void );void efi_reset_system (bool warm);#ifndef COMPAT
Re: [PATCH v2 2/3] x86/EFI: replace ebmalloc()
Quoted 46 lines · Jan Beulich
xen/arch/x86/setup.c +4
-7@@ -31,6 +31,7 @@#include <asm/alternative.h> #include <asm/apic.h> #include <asm/bootinfo.h> +#include <asm/brk.h> #include <asm/bzimage.h> #include <asm/cpu-policy.h> #include <asm/e820.h> @@ -164,6 +165,8 @@ cpumask_t __read_mostly cpu_present_map;unsigned long __read_mostly xen_phys_start; +unsigned long __ro_after_init brk_end; +/* Only used in asm code and within this source file */ char asmlinkage __section(".init.bss.stack_aligned") __aligned(STACK_SIZE) cpu0_stack[STACK_SIZE];@@ -1141,7 +1144,6 @@ void asmlinkage __init noreturn __start_struct boot_info *bi;unsigned long nr_pages, raw_max_page;int i, j, bytes =0 ; -unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;bool vm_init_done = false;int ret;@@ -1511,7 +1513,7 @@ void asmlinkage __init noreturn __start_/* * This needs to remain in sync with remove_xen_ranges() and the * respective reserve_e820_ram() invocation below. No need to -* query efi_boot_mem_unused() here, though. +* query brk_get_unused_start() here, though. */ xen->start =virt_to_maddr (_stext); xen->size = __2M_rwdata_end - _stext;@@ -1654,18 +1656,11 @@ void asmlinkage __init noreturn __start_if ( !xen_phys_start )panic ("Not enough memory to relocate Xen\n" ); -/* FIXME: Putting a hole in .bss would shatter the large page mapping. */ -if (using_2M_mapping () ) -efi_boot_mem_unused (NULL ,NULL ); -/* This needs to remain in sync with remove_xen_ranges(). */ -if (efi_boot_mem_unused (&eb_start, &eb_end) )
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_ · line 1663
Quoted 10 lines
xen/arch/x86/setup.c +4
-6- { -reserve_e820_ram (&boot_e820,__pa (_stext),__pa (eb_start)); -reserve_e820_ram (&boot_e820,__pa (eb_end),__pa (__2M_rwdata_end)); - } - else - reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end)); + brk_end =brk_get_unused_start (); +if (using_2M_mapping () ) + brk_end =PAGE_ALIGN_2M (brk_end); +reserve_e820_ram (&boot_e820,__pa (_stext),__pa (brk_end));
Hiding brk_end in setup.c like this is quite rude. I guess it's because you want to have brk.c be brk.init.o, but it really does live with the other brk functions.
Furthermore, having brk_end right from the outset fixes the fact that brk_get_unused_start() is doing things beyond retrieving a value.
With brk_end being the real bump pointer the allocator uses, then the only function you need is brk_finish() (name subject to improvement) which is now very clear about the point at which brk allocations cease working.
The rest, dropping EFI's current ebmalloc() all looks fine now.
~Andrew
Re: [PATCH v2 2/3] x86/EFI: replace ebmalloc()
Quoted 53 lines · Andrew Cooper
Quoted 52 lines · Jan Beulich
xen/arch/x86/setup.c +4
-13@@ -31,6 +31,7 @@#include <asm/alternative.h> #include <asm/apic.h> #include <asm/bootinfo.h> +#include <asm/brk.h> #include <asm/bzimage.h> #include <asm/cpu-policy.h> #include <asm/e820.h> @@ -164,6 +165,8 @@ cpumask_t __read_mostly cpu_present_map;unsigned long __read_mostly xen_phys_start; +unsigned long __ro_after_init brk_end; +/* Only used in asm code and within this source file */ char asmlinkage __section(".init.bss.stack_aligned") __aligned(STACK_SIZE) cpu0_stack[STACK_SIZE];@@ -1141,7 +1144,6 @@ void asmlinkage __init noreturn __start_struct boot_info *bi;unsigned long nr_pages, raw_max_page;int i, j, bytes =0 ; -unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;bool vm_init_done = false;int ret;@@ -1511,7 +1513,7 @@ void asmlinkage __init noreturn __start_/* * This needs to remain in sync with remove_xen_ranges() and the * respective reserve_e820_ram() invocation below. No need to -* query efi_boot_mem_unused() here, though. +* query brk_get_unused_start() here, though. */ xen->start =virt_to_maddr (_stext); xen->size = __2M_rwdata_end - _stext;@@ -1654,18 +1656,11 @@ void asmlinkage __init noreturn __start_if ( !xen_phys_start )panic ("Not enough memory to relocate Xen\n" ); -/* FIXME: Putting a hole in .bss would shatter the large page mapping. */ -if (using_2M_mapping () ) -efi_boot_mem_unused (NULL ,NULL ); -/* This needs to remain in sync with remove_xen_ranges(). */ -if (efi_boot_mem_unused (&eb_start, &eb_end) ) - { -reserve_e820_ram (&boot_e820,__pa (_stext),__pa (eb_start)); -reserve_e820_ram (&boot_e820,__pa (eb_end),__pa (__2M_rwdata_end)); - } -else -reserve_e820_ram (&boot_e820,__pa (_stext),__pa (__2M_rwdata_end));
Quoted 8 lines
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_ · line 1663
Quoted 4 lines
xen/arch/x86/setup.c +4
-0+ brk_end =brk_get_unused_start (); +if (using_2M_mapping () ) + brk_end =PAGE_ALIGN_2M (brk_end); +reserve_e820_ram (&boot_e820,__pa (_stext),__pa (brk_end));Hiding
brk_endinsetup.clike this is quite rude. I guess it's because you want to havebrk.cbe brk.init.o, but it really does live with the other brk functions.
As said in reply to you comments on patch 1 - brk_end is purely an x86 helper variable. I don't want it to move to common code.
Quoted 4 lines
Furthermore, having
brk_endright from the outset fixes the fact thatbrk_get_unused_start()is doing things beyond retrieving a value.With
brk_endbeing the real bump pointer the allocator uses,
Hmm, no - I don't view the variable as fulfilling that purpose.
Jan
Quoted 8 lines
then the
only function you need isbrk_finish()(name subject to improvement) which is now very clear about the point at which brk allocations cease working.The rest, dropping EFI's current
ebmalloc()all looks fine now.~Andrew
Re: [PATCH v2 2/3] x86/EFI: replace ebmalloc()
Quoted 66 lines · Jan Beulich
Quoted 53 lines · Andrew Cooper
Quoted 52 lines · Jan Beulich
xen/arch/x86/setup.c +4
-13@@ -31,6 +31,7 @@#include <asm/alternative.h> #include <asm/apic.h> #include <asm/bootinfo.h> +#include <asm/brk.h> #include <asm/bzimage.h> #include <asm/cpu-policy.h> #include <asm/e820.h> @@ -164,6 +165,8 @@ cpumask_t __read_mostly cpu_present_map;unsigned long __read_mostly xen_phys_start; +unsigned long __ro_after_init brk_end; +/* Only used in asm code and within this source file */ char asmlinkage __section(".init.bss.stack_aligned") __aligned(STACK_SIZE) cpu0_stack[STACK_SIZE];@@ -1141,7 +1144,6 @@ void asmlinkage __init noreturn __start_struct boot_info *bi;unsigned long nr_pages, raw_max_page;int i, j, bytes =0 ; -unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;bool vm_init_done = false;int ret;@@ -1511,7 +1513,7 @@ void asmlinkage __init noreturn __start_/* * This needs to remain in sync with remove_xen_ranges() and the * respective reserve_e820_ram() invocation below. No need to -* query efi_boot_mem_unused() here, though. +* query brk_get_unused_start() here, though. */ xen->start =virt_to_maddr (_stext); xen->size = __2M_rwdata_end - _stext;@@ -1654,18 +1656,11 @@ void asmlinkage __init noreturn __start_if ( !xen_phys_start )panic ("Not enough memory to relocate Xen\n" ); -/* FIXME: Putting a hole in .bss would shatter the large page mapping. */ -if (using_2M_mapping () ) -efi_boot_mem_unused (NULL ,NULL ); -/* This needs to remain in sync with remove_xen_ranges(). */ -if (efi_boot_mem_unused (&eb_start, &eb_end) ) - { -reserve_e820_ram (&boot_e820,__pa (_stext),__pa (eb_start)); -reserve_e820_ram (&boot_e820,__pa (eb_end),__pa (__2M_rwdata_end)); - } -else -reserve_e820_ram (&boot_e820,__pa (_stext),__pa (__2M_rwdata_end));Quoted 8 lines
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_ · line 1663
Quoted 4 lines
xen/arch/x86/setup.c +4
-0+ brk_end =brk_get_unused_start (); +if (using_2M_mapping () ) + brk_end =PAGE_ALIGN_2M (brk_end); +reserve_e820_ram (&boot_e820,__pa (_stext),__pa (brk_end));Hiding
brk_endinsetup.clike this is quite rude. I guess it's because you want to havebrk.cbe brk.init.o, but it really does live with the other brk functions.As said in reply to you comments on patch 1 -
brk_endis purely an x86 helper variable. I don't want it to move to common code.
Quoted 6 lines
Quoted 4 lines
Furthermore, having
brk_endright from the outset fixes the fact thatbrk_get_unused_start()is doing things beyond retrieving a value.With
brk_endbeing the real bump pointer the allocator uses,Hmm, no - I don't view the variable as fulfilling that purpose.
In fact, to add to this, originally I had a variable of this purpose. It simply didn't work out nicely, in particular because of the page alignment which may need enforcing. (Surely it could be done like you say, but I'd really prefer not to.)
Jan
PATCH v2 3/3 xhci-dbc: use brk_alloc()
In reply to Jan BeulichThis way the relatively large chunk of DMA buffers can be freed when the driver isn't in use.
xen/drivers/char/xhci-dbc.c +23 -13
@@ -27,6 +27,8 @@#include <xen/serial.h> #include <xen/timer.h> #include <xen/types.h> + +#include <asm/brk.h> #include <asm/fixmap.h> #include <asm/io.h> #include <asm/string.h>
@@ -1321,7 +1323,7 @@ static struct uart_driver dbc_uart_drive };/* Those are accessed via DMA. */ -struct dbc_dma_bufs { +struct __aligned(PAGE_SIZE) dbc_dma_bufs {struct xhci_trb evt_trb[DBC_TRB_RING_CAP ];struct xhci_trb out_trb[DBC_TRB_RING_CAP ];struct xhci_trb in_trb[DBC_TRB_RING_CAP ];
@@ -1335,8 +1337,7 @@ struct dbc_dma_bufs {* DMA-reachable by the USB controller. */ }; -static struct dbc_dma_bufs __section(".bss.page_aligned") __aligned(PAGE_SIZE) - dbc_dma_bufs; +DEFINE_BRK (xhci,sizeof (struct dbc_dma_bufs )); static int __init cf_check xhci_parse_dbgp(const char *opt_dbgp) {
@@ -1413,24 +1414,33 @@ void __init xhci_dbc_uart_init(void) {struct dbc_uart *uart = &dbc_uart;struct dbc *dbc = &uart->dbc; +struct dbc_dma_bufs *dma_bufs;if ( !dbc->enable )return ; - dbc->dbc_ctx = &dbc_dma_bufs.ctx; - dbc->dbc_erst = &dbc_dma_bufs.erst; - dbc->dbc_ering.trb = dbc_dma_bufs.evt_trb; - dbc->dbc_oring.trb = dbc_dma_bufs.out_trb; - dbc->dbc_iring.trb = dbc_dma_bufs.in_trb; - dbc->dbc_owork.buf = dbc_dma_bufs.out_wrk_buf; - dbc->dbc_iwork.buf = dbc_dma_bufs.in_wrk_buf; - dbc->dbc_str = dbc_dma_bufs.str_buf; + dma_bufs =brk_alloc (sizeof (*dma_bufs)); +if ( !dma_bufs ) + { + dbc->enable = false; +printk (XENLOG_ERR "XHCI: not enough BRK space available\n" ); +return ; + } + + dbc->dbc_ctx = &dma_bufs->ctx; + dbc->dbc_erst = &dma_bufs->erst; + dbc->dbc_ering.trb = dma_bufs->evt_trb; + dbc->dbc_oring.trb = dma_bufs->out_trb; + dbc->dbc_iring.trb = dma_bufs->in_trb; + dbc->dbc_owork.buf = dma_bufs->out_wrk_buf; + dbc->dbc_iwork.buf = dma_bufs->in_wrk_buf; + dbc->dbc_str = dma_bufs->str_buf;if (dbc_open (dbc) ) {iommu_add_extra_reserved_device_memory ( -PFN_DOWN (virt_to_maddr (&dbc_dma_bufs)), -PFN_UP (sizeof (dbc_dma_bufs)), +PFN_DOWN (virt_to_maddr (dma_bufs)), +PFN_DOWN (sizeof (*dma_bufs)), uart->dbc.sbdf,"XHCI console" );serial_register_uart (SERHND_XHCI , &dbc_uart_driver, &dbc_uart);