From nobody Mon Nov 23 22:39:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1791982911; cv=none; d=zohomail.com; s=zohoarc; b=JzetOHc5vCcjtRuPJpv2jQ35UAwZeH1VwYHseBcTyFjezBO7wk9gJC9WHcFZJZwA9liwFM0zlmUBGRVXrdEmbhFQ3y2+r2TkdfbeBjlvu9lcSdzL/Gwk2+6fPx3r4MoL7I4Y6X1K8mODw8RIfHvawr9YH6tKliB/uQTjwCL5GjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791982911; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ad8BiGbd56/98Ou5diYjrztGQdgtHVrz8EjnYsYECAc=; b=RO7VlrCPSJXFo03D8ygZbVgSudyJwFGq+WUlGcm5aWAy/rJlzn9GHcLc4oe1maj9/rjAYj4FRyClq7bu6Ssludw5ywCBt2PXHjKjjS4DdZzLUJorJoDZObfWJEoggrW25LemupdTGov10jJrB9CUqXV2wC8A7AQGVy51S/yK41w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1791982911070263.3031056626279; Wed, 14 Oct 2026 06:01:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1448990.1664940 (Exim 4.92) (envelope-from ) id 1xGybp-0006sK-2Q; Wed, 14 Oct 2026 13:01:29 +0000 Received: by outflank-mailman (output) from mailman id 1448990.1664940; Wed, 14 Oct 2026 13:01:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xGybo-0006sB-V0; Wed, 14 Oct 2026 13:01:28 +0000 Received: by outflank-mailman (input) for mailman id 1448990; Wed, 14 Oct 2026 13:01:27 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xGybn-0006s3-Og for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 13:01:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xGybm-00BSwC-Ud for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 15:01:26 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6acf7d1d-e002-0a2a0a5209dd-0a2a4501804c-48 for ; Wed, 14 Oct 2026 15:01:26 +0200 Received: from [209.85.128.44] (helo=mail-wm1-f44.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6acf7d26-5984-0a2a45010019-d155802ce9ec-3 for ; Wed, 14 Oct 2026 15:01:26 +0200 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-49ff680331aso10989195e9.3 for ; Wed, 14 Oct 2026 06:01:26 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0aaa5dbsm12376317f8f.12.2026.10.14.06.01.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2026 06:01:25 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1791982886; x=1792587686; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Ad8BiGbd56/98Ou5diYjrztGQdgtHVrz8EjnYsYECAc=; b=OXXriEbW1Pg1AHQXbpo6Wh1zF2b9o1Fn3ivVFn4LM+ldyf55Et20HIJBFcAUS0PUpZ fy2qsqd1OjYpuTMR6qmvI3sLnrYEq9uqsLN33/YU+j8dMZBwy42Y2hTmmluxWCPkwkom KXcWfqgcwG5aIv71YHVThzCvo+MC6kl2GW/vjW9dEeXHQJY7tywoiablQKISYvOkhhhz 1py5bQNoUuXx0xaL2ZZ/oWY3vHoyTzuYq7RJRiQF31fYIKOnc0YLX+/cmDWQ77nmOxF8 98w6abjXVM5A4feRPeGtZxqIloN7fIm6/N4bcQG+5dWU2o79tkZLNP6tjVqsXTFdd11h MfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791982886; x=1792587686; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Ad8BiGbd56/98Ou5diYjrztGQdgtHVrz8EjnYsYECAc=; b=r5Z1efruKEOdeR5lG/t7MvWyC7bEJx0tLeq9D54Di9lyqv2kwqSsRWT7RboYHzJ2hb /+P2G3IFkp9x18qB+MZT1dsrCCPvAks0bdBQ8dxN3kN5DJ/a8zQ8C9IW1kXbarEJzEMI XbcJVBLmmWoxV4Ax/jWaGjYaIYbKKPR3Lde6uG+OTURian5vBgZmofBL8P3Hg6yZaIH+ 2ACV+o49htW83IBk0/KpYItpOP1w2+Yd6GhGgF5us6fLZeiDlPTKxJpRdR6ZSE8eohLO XtboyzR0YvilcM33HTAYYEaXK6iIAt1j5RO55gxuqCE2RiBqK2yYQF8OjFhRMeN1fa3h EAow== X-Gm-Message-State: AFq9FYKjuOsXM1RGb2ugdmbqEqAsl94KzPNmxAY0d25vTbRCdRv9YM71 F+IENXN4gkOEaMg1CadRmq2kqF5qkaeGf3YIRYVB5LucbZM+mXt/QiuEFGBfx/nu+gDBcL+nWZm bxVQl5A== X-Gm-Gg: AYBFou3L54Kw67BsWtheRm0sC8XBUWyM3wGtORtsuRGIzTIgsj8JS1H8AZARfDN4u/v RnP3yfNzd/c2IqC4cLtfw0GbuvOICXAYQPOYpAmhHlG5Kio1wbt4hg0wG/1LX8qazo7ISuUGjt6 sMTZQdaCTednJeiUHqRRxkS6RNNWaifmfyB92LYTMZdgDKgQHiPy+DbrZpYoxcd74yx9uANmqcw J4ET2JioeIScZVRrlHBwE1OQXQtnH6LxVyP4Olq4STz9wQKlUEceFai0tLS/1I8f6oTGTgOvG0Y BQqN6bgyJajHcYI7lS4521hqtW/3HdBSL/utvON5bTxcpTWePQValRHz2EDPqc9hg5nd4sSiscq eQTSDUWOfZT1IOq1XOZ42nXWaDVayKhvs9Ju6QrJ6Pf9vDi450ieR++Yo1kwblLd75Q21MSkoJX KkBOKr4LjIu2kA/x1i7NjHjKp2HhK6/YwU+BlNVGSIzjoF+WtsIc96M+fjTnfU4PyXH+ISKupZd rC6dPOqTS7FwCs4qOl0CYhQl/Ehg16pV4poSY5u7lOFStZp33jx3xWvaQxwruo= X-Received: by 2002:a05:600d:17:b0:4a1:9663:7639 with SMTP id 5b1f17b1804b1-4a196637a39mr221905375e9.34.1791982885740; Wed, 14 Oct 2026 06:01:25 -0700 (PDT) Message-ID: <4fc90702-fb9a-4f96-88f0-35bd3b4857f4@suse.com> Date: Wed, 14 Oct 2026 15:01:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 1/3] common: introduce "brk" allocator From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Anthony PERARD , Michal Orzel , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie References: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1791982886-BF063757-E4A22E33/10/78276251493 X-purgate-type: spam X-purgate-size: 8016 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1791982912866158501 Content-Type: text/plain; charset="utf-8" ... 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 Reviewed-by: Jason Andryuk --- 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. --- 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,23 @@ +/* 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 ( ".weak __subsystem__; mov $__subsystem__, %0" : "=3Dr" (subsys) = ); + + /* using_2M_mapping() isn't available here. */ + if ( IS_ENABLED(CONFIG_XEN_ALIGN_2M) || subsys ) + start =3D 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. */ =20 +#include #include #include #include @@ -337,6 +338,8 @@ void __init arch_init_memory(void) =20 efi_init_memory(); =20 + 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 =20 DECL_SECTION(.bss) { - __bss_start =3D .; - *(.bss.page_aligned*) - PERCPU_BSS - *(.bss .bss.*) - . =3D ALIGN(POINTER_ALIGN); - __bss_end =3D .; + BSS_WITH_BRK } PHDR(text) _end =3D . ; =20 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -118,6 +118,9 @@ config GENERIC_BUG_FRAME config HAS_ALTERNATIVE bool =20 +config HAS_BRK_ALLOCATOR + bool + config HAS_COMPAT bool =20 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -1,6 +1,7 @@ obj-$(CONFIG_ARGO) +=3D argo.o obj-y +=3D bitmap.o obj-bin-$(CONFIG_SELF_TESTS) +=3D bitops.init.o +obj-bin-$(CONFIG_HAS_BRK_ALLOCATOR) +=3D brk.init.o obj-$(CONFIG_GENERIC_BUG_FRAME) +=3D bug.o obj-$(CONFIG_HYPFS_CONFIG) +=3D config_data.o obj-$(CONFIG_CORE_PARKING) +=3D core_parking.o --- /dev/null +++ b/xen/common/brk.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include + +#if __has_include() +# include +#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; + + if ( finished ) + return NULL; + + /* Allocations PAGE_SIZE and up will be page-aligned. */ + if ( size >=3D PAGE_SIZE ) + allocated =3D ROUNDUP(allocated, PAGE_SIZE); + + ptr =3D __brk_start + allocated; + + allocated +=3D ROUNDUP(size, sizeof(void *)); + + if ( allocated > __bss_end - __brk_start ) + { + printk_once_init( + "%pS: over-sized BRK request: %zu bytes\n", + __builtin_extract_return_addr(__builtin_return_address(0)), + size); + return NULL; + } + + return ptr; +} + +unsigned long __init brk_cease(void) +{ + finished =3D true; + + allocated =3D ROUNDUP(allocated, PAGE_SIZE); + + return (unsigned long)__brk_start + allocated; +} + +void __init brk_free_unused(void) +{ + unsigned long start =3D brk_cease(), end =3D (unsigned long)__bss_end; + +#if __has_include() + start =3D brk_adjust_start(start); +#endif + + if ( start >=3D end ) + return; + + destroy_xen_mappings(start, PAGE_ALIGN_2M(end)); + + /* + * By reserving needed space early (on x86: in the E820 map), excess s= pace + * 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 spa= ce + * 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. Rese= rved + * 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 + +#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 } \ }) =20 +#define printk_once_init(fmt, args...) \ +({ \ + static bool __initdata once_; \ + if ( unlikely(!once_) ) \ + { \ + once_ =3D 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 @@ . =3D ALIGN(SMP_CACHE_BYTES); \ __per_cpu_data_end =3D .; \ =20 +#define BSS_WITH_BRK \ + __bss_start =3D .; \ + *(.bss.page_aligned*) \ + PERCPU_BSS \ + *(.bss .bss.[a-zA-Z0-9_]*) \ + . =3D ALIGN(PAGE_SIZE); \ + __brk_start =3D .; \ + *(.bss..brk.page_aligned*) \ + *(.bss..brk*) \ + . =3D ALIGN(POINTER_ALIGN); \ + __bss_end =3D .; + #ifdef CONFIG_HAS_VPCI #define VPCI_ARRAY \ . =3D ALIGN(POINTER_ALIGN); \ From nobody Mon Nov 23 22:39:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1791982959; cv=none; d=zohomail.com; s=zohoarc; b=ZEGBbkTQ+4fn0NmHFF8oGDoC8tSpjqO3Np1J7dzxp4AOpKUVqPyF6odt/hhnxeegKxmiDdBgy0Q5GlqhzQABhC3y4vk0nICdmouCbZhMQqv6wXmfArM9l7wf1Fd2Ymt7xQOFgRk/Cq+Z6u3tCLGJoLQW+3S0f03+L6hrH6ndgYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791982959; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FEcDM12NwGn05VrFecyuXD7d11qyEb4DovUBu5I+7Oc=; b=d/ufHMVEpE9N5saMDLOGD5kCKgJtieYursfu41FCqaKFZyeJocIwCf33h7TxtcZMtj82mGU/Jl5Pgy1u4BXHrZ7m8t3cWlc8tXDk/UZqQQKBMq2VPpK/e/9cUz5KO8H1V8OAnIXWGzi4pHxDwSM1MVwQZrHSbELzAY/HCsb7SqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1791982959559561.9631085650481; Wed, 14 Oct 2026 06:02:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1448994.1664950 (Exim 4.92) (envelope-from ) id 1xGych-0007K6-FE; Wed, 14 Oct 2026 13:02:23 +0000 Received: by outflank-mailman (output) from mailman id 1448994.1664950; Wed, 14 Oct 2026 13:02:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xGych-0007Jz-CU; Wed, 14 Oct 2026 13:02:23 +0000 Received: by outflank-mailman (input) for mailman id 1448994; Wed, 14 Oct 2026 13:02:22 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xGycf-0007Jl-Vy for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 13:02:22 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xGycf-00CF8l-Ch for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 15:02:21 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6acf7d56-2eae-0a2a0a5409dd-0a2a4506b48e-24 for ; Wed, 14 Oct 2026 15:02:21 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6acf7d5d-195a-0a2a45060019-d155dd35dce0-3 for ; Wed, 14 Oct 2026 15:02:21 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-48c5358fc28so375890f8f.0 for ; Wed, 14 Oct 2026 06:02:21 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0bc506asm12256603f8f.47.2026.10.14.06.02.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2026 06:02:19 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1791982941; x=1792587741; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=FEcDM12NwGn05VrFecyuXD7d11qyEb4DovUBu5I+7Oc=; b=Fu5u6XbSZPaQ91xW9brl8jvOVH4D3Fb/bs9H75S5sMrllTEVFlb/4iD+EtoR9ldwKl TflzftS0Md//clnVCav/Vo5B0qiqwj26sz1kMxm13+ME51t8Z8ilnq6HaQuCG4J9zCqx 0dKC3nWNQ2CI4vHiOV6o71bF3ktUyeg0A4T4Zbsc1ImO27eCYzLoq7MzYUG8w5817M0q scMeqra1idTO8ynRnb0ovMFWkRqskqfgSRWRwvdWCJIqBm2L127TGGtfaCYlYTGFulif 34Wb39et8lTGuAB3RBHhiMPBxgDOmpWDsVdSGoPoMNCtXE/xfyLHh7syLzH+ba9lx4kZ eYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791982941; x=1792587741; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=FEcDM12NwGn05VrFecyuXD7d11qyEb4DovUBu5I+7Oc=; b=vGkZ0b74L+gPO6GLHCDqJ9OuYd7qFrTUQ+dkponul9UROxyVJhp6+gnGRjaEP/nv4k 1iZT9tdOz5khFibMnF6BNePkckMiJO8QIIOpO+6NtF1OpU1IKTGTtkXNJdPDlmkMakFZ 0Pz9sgABcxpagNmcm2Wo7+SSmcKSJMWZXT8jlLbfQ18hMRe/wy7mWxXJJwIK5O21uMxw jHSMvtULlVDR9yMX69Ny5ShpHVCfPHbviQ7zVOLXJJtyXVlAVHXVvZw7JXt/9veW5jCk MtmM2Rq3RqZ+voIVFSjUdUd3iTRiQqopvZX5DluSpdUy1LGmfdHTgrt/ZY+Z2IvvCoN4 q0jQ== X-Gm-Message-State: AFq9FYIm8TrS28i6j7ZHL/6rbHGAvCoBf71kyrGYcJ2+Kq+OKfYPuDd/ TKnFS7kQzDromL7pQ5SKvvgV/mkMyh8lDCaV/DVJ3qrhBJ1OO97M9qBHn7xmvVSJVrEJZertZjG aDhcSzg== X-Gm-Gg: AYBFou1zEV4HnFpd/bQcuOSMOPpir1TD70tYxPQdocVvLVw/axGrDcAsWsYfqsDfJWW E8QlxDX3A4EOII8tphQcplI64JM+4qkhrOovQ0S4u82qBMOTdRgp6bzXeD1eHlj9jl+cYWarFtd 4qYSnoYEYY3Lezwhnm3Wzmr2nYPIpZqCeVmHMrHvzSYSXK6KMw6NCRBPrUd1Ug/f4lTnbIzEGzA ODvW6PdBx1NqB49OGF6Xs3zCtDg4cN08Lde7In5Htsv26dgUIjUMnapZ0f7X2RaRdBtBzHmeddJ WeaKhS8SDo4edAB6CwDJIc2WfMHBTOzSZXM7QHiFgBPaisK/ZyqMU5sfJmgOLJAKPY24mZ5kLI0 zhNuR80zcVrCwcpdF3Tej2MdN6TFz4FOmcO8H2h968yZHs2fE2qs/O4kpsnHn63zr3ovFOk1C61 9qcAvVF5FVnqYVnn/lWmnCpzqop4MwkmgayOK33X55opGZQiiBujbJfENpeLhT8Ogalkg1Qwr+I mEWst+GZiw+8eoU1BiGx0wAcq6d4fyoXoo/QIugDI7FM6aX/49mG3QVUq5rpYF3 X-Received: by 2002:a5d:6f18:0:b0:48d:f14a:9174 with SMTP id ffacd0b85a97d-48df14a925amr288746f8f.13.1791982940714; Wed, 14 Oct 2026 06:02:20 -0700 (PDT) Message-ID: Date: Wed, 14 Oct 2026 15:02:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 2/3] x86/EFI: replace ebmalloc() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Anthony PERARD , Michal Orzel , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie , Marek Marczykowski , Daniel Smith References: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1791982941-FC80577B-2F385E8C/10/78276251493 X-purgate-type: spam X-purgate-size: 11144 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1791982962217158500 Use the new brk_alloc() instead, with ebmalloc() merely being a thin wrapper. Signed-off-by: Jan Beulich Reviewed-by: Marek Marczykowski-G=C3=B3recki --- 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. --- 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 =3D 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,') !=3D 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 =20 +#include #include =20 #include @@ -119,6 +120,18 @@ static void __init relocate_trampoline(u reloc_trampoline64(); } =20 +DEFINE_BRK(efi, MB(1)); + +static void *__init ebmalloc(size_t size) +{ + void *ptr =3D 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 =3D 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_ =20 void __init efi_init_memory(void) { } =20 -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 =3D *end =3D (unsigned long)_end; - return false; -} - void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { } --- 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[]; =20 +extern unsigned long brk_end; + extern unsigned long xenheap_initial_phys_start; extern uint64_t boot_tsc_stamp; =20 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -164,6 +165,8 @@ cpumask_t __read_mostly cpu_present_map; =20 unsigned long __read_mostly xen_phys_start; =20 +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]; @@ -1152,7 +1155,6 @@ void asmlinkage __init noreturn __start_ struct boot_info *bi; unsigned long raw_max_page; int i, j, bytes =3D 0; - unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; bool vm_init_done =3D false; int ret; @@ -1518,7 +1520,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 =3D virt_to_maddr(_stext); xen->size =3D __2M_rwdata_end - _stext; @@ -1662,20 +1664,12 @@ void asmlinkage __init noreturn __start_ if ( !xen_phys_start ) panic("Not enough memory to relocate Xen\n"); =20 - /* 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 =3D brk_cease(); + if ( using_2M_mapping() ) + brk_end =3D PAGE_ALIGN_2M(brk_end); + if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(brk_end)) ) + panic("Failed to reserve Xen in E820\n"); =20 /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(); @@ -2272,7 +2266,6 @@ __initcall(init_xen_cap_info); =20 int __hwdom_init remove_xen_ranges(struct rangeset *r) { - paddr_t start, end; int rc; =20 /* S3 resume code (and other real mode trampoline code) */ @@ -2294,26 +2287,10 @@ int __hwdom_init remove_xen_ranges(struc return rc; =20 /* hypervisor .data + .bss */ - if ( efi_boot_mem_unused(&start, &end) ) - { - ASSERT(__pa(start) >=3D __pa(&__2M_rwdata_start)); - rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), - PFN_DOWN(__pa(start) - 1)); - if ( rc ) - return rc; - ASSERT(__pa(end) <=3D __pa(&__2M_rwdata_end)); - rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(end)), - PFN_DOWN(__pa(&__2M_rwdata_end) - 1)); - if ( rc ) - return rc; - } - else - { - rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), - PFN_DOWN(__pa(&__2M_rwdata_end) - 1)); - if ( rc ) - return rc; - } + rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), + PFN_DOWN(__pa(brk_end) - 1)); + if ( rc ) + return rc; =20 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 =3D=3D 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 =3D __2M_rodata_end - _stext; /* hypervisor .data + .bss */ g_tboot_shared->mac_regions[2].start =3D (uint64_t)__pa(&__2M_rwda= ta_start); - g_tboot_shared->mac_regions[2].size =3D __2M_rwdata_end - __2M_rwd= ata_start; - if ( efi_boot_mem_unused(&s, &e) ) - { - g_tboot_shared->mac_regions[2].size =3D - s - (unsigned long)__2M_rwdata_start; - g_tboot_shared->mac_regions[3].start =3D __pa(e); - g_tboot_shared->mac_regions[3].size =3D - (unsigned long)__2M_rwdata_end - e; - g_tboot_shared->num_mac_regions =3D 4; - } + g_tboot_shared->mac_regions[2].size =3D + brk_end - (unsigned long)__2M_rwdata_start; =20 /* * 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 =3D NULL; =20 - free_ebmalloc_unused_mem(); - if ( !efi_enabled(EFI_BOOT) ) return; =20 --- a/xen/common/efi/ebmalloc.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "efi.h" -#include -#include - -#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 =3D ebmalloc_mem + ebmalloc_allocated; - - ebmalloc_allocated +=3D 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 =3D sizeof(ebmalloc_mem); - return false; - } - - *start =3D (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated= ); - *end =3D (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 bef= ore - * 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 :=3D boot.init.o pe.init.o ebmalloc.o runtime.o +EFIOBJ-y :=3D boot.init.o pe.init.o runtime.o EFIOBJ-$(CONFIG_COMPAT) +=3D compat.o =20 CFLAGS-y +=3D -fshort-wchar --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -48,10 +48,6 @@ void noreturn blexit(const CHAR16 *str); =20 const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n); =20 -/* 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); =20 --- 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; =20 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 From nobody Mon Nov 23 22:39:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1791982988; cv=none; d=zohomail.com; s=zohoarc; b=fd2+6bP1inkO/GVp0l9/03TeS8QdIqGZibUKErDyLVPBOR+/IAT95KGEMmxPa49380sWjaHN94sIAjfYVFOjDquFoojPAof+mPDw73KfGWunFt5vhs3/CRIoBqLNS44Q4Z7FEM/4rbh/wH1qxia2k6IiHqru++pbPkHoE0OjLcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791982988; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2gMm2a7QNwXZYXz1DEn6YS019avxsFmIWcQ9BJGK0Ao=; b=RHpkKt/jJPwqVv7yedFZT9CNmoUpGCSVsr3epc75onTYAoNfr9q9vZ8XqdkwhkVzu+LsEzabz2cwK0DN9U22PDWixbsVJhc5j719yQn1InZOkXwL6YIH0pUUUFOfwAPlpK/k2KnJsmR01oFn2TTMR3M5fwVXiB8DjkhWtYtow6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1791982988953233.97867582327933; Wed, 14 Oct 2026 06:03:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1448999.1664959 (Exim 4.92) (envelope-from ) id 1xGyd8-0007mR-Nx; Wed, 14 Oct 2026 13:02:50 +0000 Received: by outflank-mailman (output) from mailman id 1448999.1664959; Wed, 14 Oct 2026 13:02:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xGyd8-0007mK-Kl; Wed, 14 Oct 2026 13:02:50 +0000 Received: by outflank-mailman (input) for mailman id 1448999; Wed, 14 Oct 2026 13:02:50 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xGyd7-0007m2-W1 for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 13:02:50 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xGyd7-00CFKO-8V for xen-devel@lists.xenproject.org; Wed, 14 Oct 2026 15:02:49 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6acf7d77-2eae-0a2a0a5409dd-0a2a45048820-16 for ; Wed, 14 Oct 2026 15:02:49 +0200 Received: from [209.85.221.42] (helo=mail-wr1-f42.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6acf7d78-b57f-0a2a45040019-d155dd2ae46e-3 for ; Wed, 14 Oct 2026 15:02:48 +0200 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-48b0ef9c76eso371429f8f.0 for ; Wed, 14 Oct 2026 06:02:48 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0ac5265sm12597064f8f.41.2026.10.14.06.02.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2026 06:02:47 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1791982968; x=1792587768; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=2gMm2a7QNwXZYXz1DEn6YS019avxsFmIWcQ9BJGK0Ao=; b=JgpgByf4XX2iTWgRn28KC6AtVRz2fVCJetba/xoBfLDkBc3BePfT+8VUi/Q4dzUKVp PymubaPbK95QftOBY62emHoneBK2TMYhpkRERiq7OZYKLndp8aPqElk8IVHMZIMzSTtn gO58VqCkFXDOagu7nyyK8aSaCBdaEQb5SYCQ4v+DWaghj3eS4qlPeM+ZIQJzBM5f9paz 4FqDCePBT4+iTynKD6UXvtY1802Ed0EMvocg326ZZlSnwcXluiEWrou7GTZes45ssfFS 7DjZmmMLFfPpZlt59xduuLRgLdijxKreK7tC6XRAYUioyOwitlzRPM07e8WbGcg6LAOd n5LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791982968; x=1792587768; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=2gMm2a7QNwXZYXz1DEn6YS019avxsFmIWcQ9BJGK0Ao=; b=xJfAZb90RzcsOx0iTRC3p2Shra11c9knFIb2LjnQypkF/8kA6PDnW7K+Y9e2SGOYtO csCavz5lmNIQ/2omMyhM0+FfuzxDNyUsJGuDzrqhSv4qLcesCkHUIYhNb/f95B8bc+hT HQRBettOsIajAu49ezd939wWK22eIfExlCWYQ7Hr+o2Zt4R+3b4g0aby2t5XJ+r7nlFo ildfOjbrZtTIEPaEIwbq6BThdYxqq/vEKKhwSqHpsm3jpIkZJ2tFYs3f7N+hXycz3HzD HroDQFXPwF7ZTGWqg1vH2DRXtgL0qXFkt7ClET1vWYoRYVorFX0N1f6XRt+thxXO+OGQ IXsA== X-Gm-Message-State: AFq9FYJllsIHHTvFJ+krZYYIO+n9XK4VIQUaEsv+6QgMXOvLvGBSElAK G4hmuONdgmANgKvqa/QvJSSZX3+WYkOvCzYNl1SZyeBFGQU2U3KMLQ8Zkwmw4///aBXXp9RpJ4o RbY/eUQ== X-Gm-Gg: AYBFou3tPXBMVGFEAfvwg7Kv1FGkhO54T2lWE3SJzbAkQeyt5P9Ko7Uqr2bU62Kba1P OC0m7TUvgdI8gWfvPP+YjckJuE7YjYmQr4lK+z7N26pyWJhqG7KPbCcxYcIitcGc5pdMHZ9Vyv8 mYEQW9OUaVIFPG9/RThjw3aF3ylAg1iIzkqe/ydIdZaKKakxtjkEG1+RLhpGsXBSf1g3xvqfUnD h0DqyqWVpwqSkUnOOjSpvkDQ72XdBXhS5dkAFtzeBkwGmMLg2zihA13vLAxoGSt9ZsIF7hmiJ80 BBWEfwszNxcXcDPy4+0+Edsvm5Kn98lChPKpAZTlc2e1WjkMHPHsUVw8vphNXtFepaKHLtXTstj en/otj5ixVXERerban18SiL8VQcpO/1lzhGIdZ5H9um/aNDOLjmCvd0qsWemzleDx226cprEMiq kV/8rX1+IWknAwtorjKgOolV86awYo0rqAy2g/wwo4eVE71fH0+9bUwTK0hxEbXkV0nutrb58yC 1yztrFaepQD3VvwTUNakSAcSbX51tEtxchWFHfAcbf6Pipgnr8tg7rrIVtMcGozQy89jsxG8A== X-Received: by 2002:a05:6000:4550:b0:48a:fd58:a7dc with SMTP id ffacd0b85a97d-48dba9beee6mr22008962f8f.12.1791982968124; Wed, 14 Oct 2026 06:02:48 -0700 (PDT) Message-ID: <6e448cc8-d733-4767-b8a2-563fd6a81350@suse.com> Date: Wed, 14 Oct 2026 15:02:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 3/3] xhci-dbc: use brk_alloc() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Anthony PERARD , Michal Orzel , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Marek Marczykowski References: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <8ad3beb3-af5a-477b-af97-614edb22631a@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ebf023/1791982968-50CDFB50-B42EBD28/10/78276251493 X-purgate-type: spam X-purgate-size: 2953 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1791982994716158500 This way the relatively large chunk of DMA buffers can be freed when the driver isn't in use. Signed-off-by: Jan Beulich Reviewed-by: Marek Marczykowski-G=C3=B3recki --- 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. */ =20 +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include + #include #include #include @@ -1332,7 +1334,7 @@ static struct uart_driver dbc_uart_drive }; =20 /* 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_S= IZE) - dbc_dma_bufs; +DEFINE_BRK(xhci, sizeof(struct dbc_dma_bufs)); =20 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 =3D &dbc_uart; struct dbc *dbc =3D &uart->dbc; + struct dbc_dma_bufs *dma_bufs; =20 if ( !dbc->enable ) return; =20 - dbc->dbc_ctx =3D &dbc_dma_bufs.ctx; - dbc->dbc_erst =3D &dbc_dma_bufs.erst; - dbc->dbc_ering.trb =3D dbc_dma_bufs.evt_trb; - dbc->dbc_oring.trb =3D dbc_dma_bufs.out_trb; - dbc->dbc_iring.trb =3D dbc_dma_bufs.in_trb; - dbc->dbc_owork.buf =3D dbc_dma_bufs.out_wrk_buf; - dbc->dbc_iwork.buf =3D dbc_dma_bufs.in_wrk_buf; - dbc->dbc_str =3D dbc_dma_bufs.str_buf; + dma_bufs =3D brk_alloc(sizeof(*dma_bufs)); + if ( !dma_bufs ) + { + dbc->enable =3D false; + printk(XENLOG_ERR "XHCI: not enough BRK space available\n"); + return; + } + + dbc->dbc_ctx =3D &dma_bufs->ctx; + dbc->dbc_erst =3D &dma_bufs->erst; + dbc->dbc_ering.trb =3D dma_bufs->evt_trb; + dbc->dbc_oring.trb =3D dma_bufs->out_trb; + dbc->dbc_iring.trb =3D dma_bufs->in_trb; + dbc->dbc_owork.buf =3D dma_bufs->out_wrk_buf; + dbc->dbc_iwork.buf =3D dma_bufs->in_wrk_buf; + dbc->dbc_str =3D dma_bufs->str_buf; =20 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);