* [PATCH v4 1/3] common: introduce "brk" allocator
2026-11-03 12:47 [PATCH v4 0/3] "brk" allocator Jan Beulich
@ 2026-11-03 12:49 ` Jan Beulich
2026-11-16 17:27 ` Andrew Cooper
2026-11-03 12:50 ` [PATCH v4 2/3] x86/EFI: replace ebmalloc() Jan Beulich
2026-11-03 12:51 ` [PATCH v4 3/3] xhci-dbc: use brk_alloc() Jan Beulich
2 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2026-11-03 12:49 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
Michal Orzel, Roger Pau Monné, Teddy Astie
... to replace (on x86) 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 be 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 on x86. That would happen if BRK space extends across
a 2Mb boundary, and actual use stops before that boundary.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
---
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.
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.
---
v4: Use asm-inline in brk_adjust_start(). Introduce stub fallback for
brk_adjust_start(). Introduce local "alloc" in brk_alloc(). Add
comment ahead of the use of printk_once_init().
v3: Move to common code and introduce BSS_WITH_BRK. Rename
brk_get_unused_start() to brk_cease(). Add header guard to brk.h. In
brk_alloc() don't calculate result too early. Add printk_once_init(),
for use in brk_alloc(). Move introduction of DEFINE_BRK() here; add
comment.
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -15,6 +15,7 @@ config X86
select FUNCTION_ALIGNMENT_16B
select GENERIC_BUG_FRAME
select HAS_ALTERNATIVE
+ select HAS_BRK_ALLOCATOR
select HAS_COMPAT
select HAS_CPUFREQ
select HAS_DIT
--- /dev/null
+++ b/xen/arch/x86/include/asm/brk.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef X86_BRK_H
+#define X86_BRK_H
+
+static inline unsigned long brk_adjust_start(unsigned long start)
+{
+ 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_inline ( ".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);
+
+ return start;
+}
+
+#endif /* X86_BRK_H */
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -87,6 +87,7 @@
* doing the final put_page(), and remove it from the iommu if so.
*/
+#include <xen/brk.h>
#include <xen/domain.h>
#include <xen/domain_page.h>
#include <xen/efi.h>
@@ -337,6 +338,8 @@ void __init arch_init_memory(void)
efi_init_memory();
+ brk_free_unused();
+
#ifndef NDEBUG
if ( highmem_start )
{
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -309,12 +309,7 @@ SECTIONS
LLVM_COV_RW_DATA
DECL_SECTION(.bss) {
- __bss_start = .;
- *(.bss.page_aligned*)
- PERCPU_BSS
- *(.bss .bss.*)
- . = ALIGN(POINTER_ALIGN);
- __bss_end = .;
+ BSS_WITH_BRK
} PHDR(text)
_end = . ;
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -118,6 +118,9 @@ config GENERIC_BUG_FRAME
config HAS_ALTERNATIVE
bool
+config HAS_BRK_ALLOCATOR
+ bool
+
config HAS_COMPAT
bool
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -1,6 +1,7 @@
obj-$(CONFIG_ARGO) += argo.o
obj-y += bitmap.o
obj-bin-$(CONFIG_SELF_TESTS) += bitops.init.o
+obj-bin-$(CONFIG_HAS_BRK_ALLOCATOR) += brk.init.o
obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o
obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
obj-$(CONFIG_CORE_PARKING) += core_parking.o
--- /dev/null
+++ b/xen/common/brk.c
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/brk.h>
+#include <xen/efi.h>
+#include <xen/lib.h>
+#include <xen/mm.h>
+#include <xen/page-defs.h>
+
+#if __has_include(<asm/brk.h>)
+# include <asm/brk.h>
+#else
+static inline unsigned long brk_adjust_start(unsigned long start)
+{
+ return start;
+}
+#endif
+
+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;
+ unsigned long alloc = allocated;
+
+ if ( finished )
+ return NULL;
+
+ /* Allocations PAGE_SIZE and up will be page-aligned. */
+ if ( size >= PAGE_SIZE )
+ alloc = ROUNDUP(alloc, PAGE_SIZE);
+
+ ptr = __brk_start + alloc;
+
+ alloc += ROUNDUP(size, sizeof(void *));
+
+ if ( alloc > __bss_end - __brk_start )
+ {
+ /* Expected to be fatal to boot, but cannot be panic(). */
+ printk_once_init(
+ "%pS: over-sized BRK request: %zu bytes\n",
+ __builtin_extract_return_addr(__builtin_return_address(0)),
+ size);
+ return NULL;
+ }
+
+ allocated = alloc;
+
+ return ptr;
+}
+
+unsigned long __init brk_cease(void)
+{
+ finished = true;
+
+ allocated = ROUNDUP(allocated, PAGE_SIZE);
+
+ return (unsigned long)__brk_start + allocated;
+}
+
+void __init brk_free_unused(void)
+{
+ unsigned long start = brk_cease(), end = (unsigned long)__bss_end;
+
+ start = brk_adjust_start(start);
+
+ if ( start >= end )
+ return;
+
+ destroy_xen_mappings(start, PAGE_ALIGN_2M(end));
+
+ /*
+ * By reserving needed space early (on x86: 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);
+}
--- /dev/null
+++ b/xen/include/xen/brk.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Early Boot memory allocator.
+ *
+ * Subsystems which conditionally need memory prior to the boot allocator
+ * (or the main heap) being set up may 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, as far as possible, handed to the main heap, so it
+ * doesn't go to waste.
+ */
+
+#ifndef XEN_BRK_H
+#define XEN_BRK_H
+
+#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_cease(void);
+void brk_free_unused(void);
+
+#endif /* XEN_BRK_H */
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -79,6 +79,16 @@ void vprintk(const char *fmt, va_list ar
} \
})
+#define printk_once_init(fmt, args...) \
+({ \
+ static bool __initdata once_; \
+ if ( unlikely(!once_) ) \
+ { \
+ once_ = true; \
+ printk(fmt, ## args); \
+ } \
+})
+
extern void guest_printk(const struct domain *d, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern void noreturn panic(const char *fmt, ...)
--- a/xen/include/xen/xen.lds.h
+++ b/xen/include/xen/xen.lds.h
@@ -221,6 +221,18 @@
. = ALIGN(SMP_CACHE_BYTES); \
__per_cpu_data_end = .; \
+#define BSS_WITH_BRK \
+ __bss_start = .; \
+ *(.bss.page_aligned*) \
+ PERCPU_BSS \
+ *(.bss .bss.[a-zA-Z0-9_]*) \
+ . = ALIGN(PAGE_SIZE); \
+ __brk_start = .; \
+ *(.bss..brk.page_aligned*) \
+ *(.bss..brk*) \
+ . = ALIGN(POINTER_ALIGN); \
+ __bss_end = .;
+
#ifdef CONFIG_HAS_VPCI
#define VPCI_ARRAY \
. = ALIGN(POINTER_ALIGN); \
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v4 2/3] x86/EFI: replace ebmalloc()
2026-11-03 12:47 [PATCH v4 0/3] "brk" allocator Jan Beulich
2026-11-03 12:49 ` [PATCH v4 1/3] common: introduce " Jan Beulich
@ 2026-11-03 12:50 ` Jan Beulich
2026-11-16 18:13 ` Andrew Cooper
2026-11-03 12:51 ` [PATCH v4 3/3] xhci-dbc: use brk_alloc() Jan Beulich
2 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2026-11-03 12:50 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper, Roger Pau Monné, Teddy Astie,
Marek Marczykowski, Daniel Smith
Use the new brk_alloc() instead, with ebmalloc() merely being a thin
wrapper.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
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.
As of now, is_xen_fixed_mfn()'s use of brk_end happens to okay with that
variable's declaration living in asm/setup.h. Hence I'd prefer to keep it
that way, yet eventually the decl may need to move to asm/setup.h.
---
v4: Also adjust is_xen_fixed_mfn().
v3: Re-base, in particular over moving of brk.c to common/.
v2: Re-base.
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -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|.data.rel.ro|.data.rel.ro.*) ;; \
+ .*.local|.data.rel.ro|.data.rel.ro.*|.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; \
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -7,6 +7,7 @@
#ifndef X86_EFI_EFI_BOOT_H
#define X86_EFI_EFI_BOOT_H
+#include <xen/brk.h>
#include <xen/vga.h>
#include <asm/boot-helpers.h>
@@ -119,6 +120,18 @@ static void __init relocate_trampoline(u
reloc_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;
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -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) { }
--- a/xen/arch/x86/include/asm/mm.h
+++ b/xen/arch/x86/include/asm/mm.h
@@ -313,7 +313,7 @@ struct page_info
(mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
#define is_xen_fixed_mfn(mfn) \
(((mfn_to_maddr(mfn)) >= virt_to_maddr((unsigned long)_stext)) && \
- ((mfn_to_maddr(mfn)) <= virt_to_maddr((unsigned long)__2M_rwdata_end - 1)))
+ (mfn_to_maddr(mfn) <= virt_to_maddr(brk_end - 1)))
#define PRtype_info "016lx"/* should only be used for printk's */
--- a/xen/arch/x86/include/asm/setup.h
+++ b/xen/arch/x86/include/asm/setup.h
@@ -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;
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1,6 +1,7 @@
#include <xen/acpi.h>
#include <xen/alternative-call.h>
#include <xen/bitops.h>
+#include <xen/brk.h>
#include <xen/console.h>
#include <xen/cpu.h>
#include <xen/cpuidle.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];
@@ -1157,7 +1160,6 @@ void asmlinkage __init noreturn __start_
struct boot_info *bi;
unsigned long 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;
@@ -1523,7 +1525,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_cease() here, though.
*/
xen->start = virt_to_maddr(_stext);
xen->size = __2M_rwdata_end - _stext;
@@ -1667,20 +1669,12 @@ 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) )
- {
- if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start)) ||
- !reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end)) )
- panic("Failed to reserve Xen in E820\n");
- }
- else
- if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end)) )
- panic("Failed to reserve Xen in E820\n");
+ brk_end = brk_cease();
+ if ( using_2M_mapping() )
+ brk_end = PAGE_ALIGN_2M(brk_end);
+ if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(brk_end)) )
+ panic("Failed to reserve Xen in E820\n");
/* Late kexec reservation (dynamic start address). */
kexec_reserve_area();
@@ -2274,7 +2268,6 @@ __initcall(init_xen_cap_info);
int __hwdom_init remove_xen_ranges(struct rangeset *r)
{
- paddr_t start, end;
int rc;
/* S3 resume code (and other real mode trampoline code) */
@@ -2296,26 +2289,10 @@ int __hwdom_init remove_xen_ranges(struc
return rc;
/* hypervisor .data + .bss */
- if ( efi_boot_mem_unused(&start, &end) )
- {
- ASSERT(__pa(start) >= __pa(&__2M_rwdata_start));
- rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
- PFN_DOWN(__pa(start) - 1));
- if ( rc )
- return rc;
- ASSERT(__pa(end) <= __pa(&__2M_rwdata_end));
- rc = rangeset_remove_range(r, PFN_DOWN(__pa(end)),
- PFN_DOWN(__pa(&__2M_rwdata_end) - 1));
- if ( rc )
- return rc;
- }
- else
- {
- rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
- PFN_DOWN(__pa(&__2M_rwdata_end) - 1));
- if ( rc )
- return rc;
- }
+ rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
+ PFN_DOWN(__pa(brk_end) - 1));
+ if ( rc )
+ return rc;
return 0;
}
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -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
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -1830,8 +1830,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;
--- a/xen/common/efi/ebmalloc.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "efi.h"
-#include <xen/init.h>
-#include <xen/mm.h>
-
-#ifdef CONFIG_ARM
-/*
- * TODO: Enable EFI boot allocator on ARM.
- * This code can be common for x86 and ARM.
- * Things TODO on ARM before enabling ebmalloc:
- * - estimate required EBMALLOC_SIZE value,
- * - where (in which section) ebmalloc_mem[] should live; if in
- * .bss.page_aligned, as it is right now, then whole BSS zeroing
- * have to be disabled in xen/arch/arm/arm64/head.S; though BSS
- * should be initialized somehow before use of variables living there,
- * - use ebmalloc() in ARM/common EFI boot code,
- * - call free_ebmalloc_unused_mem() somewhere in init code.
- */
-#define EBMALLOC_SIZE MB(0)
-#else
-#define EBMALLOC_SIZE MB(1)
-#endif
-
-static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
- ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __read_mostly ebmalloc_allocated;
-
-/* EFI boot allocator. */
-void __init *ebmalloc(size_t size)
-{
- void *ptr = ebmalloc_mem + ebmalloc_allocated;
-
- ebmalloc_allocated += ROUNDUP(size, sizeof(void *));
-
- if ( ebmalloc_allocated > sizeof(ebmalloc_mem) )
- blexit(L"Out of static memory\r\n");
-
- return ptr;
-}
-
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
-{
- /* FIXME: Drop once the call here with two NULLs goes away. */
- if ( !start && !end )
- {
- ebmalloc_allocated = sizeof(ebmalloc_mem);
- return false;
- }
-
- *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
- *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
-
- return *start < *end;
-}
-
-void __init free_ebmalloc_unused_mem(void)
-{
- unsigned long start, end;
-
- if ( !efi_boot_mem_unused(&start, &end) )
- return;
-
- destroy_xen_mappings(start, end);
-
-#ifdef CONFIG_X86
- /*
- * By reserving the space early in the E820 map, it gets freed way before
- * we make it here. Don't free the range a 2nd time.
- */
-#else
- init_xenheap_pages(__pa(start), __pa(end));
-#endif
-
- printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
-}
--- a/xen/common/efi/efi-common.mk
+++ b/xen/common/efi/efi-common.mk
@@ -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
--- a/xen/common/efi/efi.h
+++ b/xen/common/efi/efi.h
@@ -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);
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -39,7 +39,6 @@ static inline bool efi_enabled(unsigned
extern 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
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v4 3/3] xhci-dbc: use brk_alloc()
2026-11-03 12:47 [PATCH v4 0/3] "brk" allocator Jan Beulich
2026-11-03 12:49 ` [PATCH v4 1/3] common: introduce " Jan Beulich
2026-11-03 12:50 ` [PATCH v4 2/3] x86/EFI: replace ebmalloc() Jan Beulich
@ 2026-11-03 12:51 ` Jan Beulich
2 siblings, 0 replies; 8+ messages in thread
From: Jan Beulich @ 2026-11-03 12:51 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
Michal Orzel, Roger Pau Monné, Marek Marczykowski
This way the relatively large chunk of DMA buffers can be freed when the
driver isn't in use.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
v3: Re-base over moving of brk.c to common/.
--- a/xen/drivers/char/xhci-dbc.c
+++ b/xen/drivers/char/xhci-dbc.c
@@ -19,6 +19,7 @@
* Copyright (c) 2019 Assured Information Security.
*/
+#include <xen/brk.h>
#include <xen/delay.h>
#include <xen/iommu.h>
#include <xen/mm.h>
@@ -27,6 +28,7 @@
#include <xen/serial.h>
#include <xen/timer.h>
#include <xen/types.h>
+
#include <asm/fixmap.h>
#include <asm/io.h>
#include <asm/string.h>
@@ -1332,7 +1334,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];
@@ -1346,8 +1348,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)
{
@@ -1424,24 +1425,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);
^ permalink raw reply [flat|nested] 8+ messages in thread