From nobody Thu Nov 5 07:28:49 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=1793710195; cv=none; d=zohomail.com; s=zohoarc; b=C0XOWv2m3u/mJMP4RM2263doHt5Xx+xO5luaOe5IHA8+NPqDhsxwAGbBlL8p48rq+R7M1kQ75I61l4+iD4orCBo2//cbCkZHG7ne1Fqc9al1mSuyob3TAJaw4TdqIdB3OHVMyaGRgCaY/zxAhM6Ag6YQx1LfpapxZIhmQsFaPdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793710195; 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=ea76sT97/Jj9c4zXiDZbZrXgPF1Fz7XWAOxDEa7crk0=; b=ivBMXpb+gt2nSZWceCcuEcGbltVXxFl5l9mMGsp+8TV7zlYwtuqmhYnEhWbzlWZbYLskvMuSu6b7vvHeuLZhNE5eb5Fe/5J1MbdDrPbgPZT8MeRRXQRhuEZC4Nol0Xu2ZbxCrJA6Mbn5kqXDASblgOGpPI4odRDMnyxY+KUVCjQ= 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 1793710195900321.58720464665396; Tue, 3 Nov 2026 04:49:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1469706.1678460 (Exim 4.92) (envelope-from ) id 1xODxJ-0005Jw-TQ; Tue, 03 Nov 2026 12:49:37 +0000 Received: by outflank-mailman (output) from mailman id 1469706.1678460; Tue, 03 Nov 2026 12:49:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xODxJ-0005Jp-QS; Tue, 03 Nov 2026 12:49:37 +0000 Received: by outflank-mailman (input) for mailman id 1469706; Tue, 03 Nov 2026 12:49:36 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xODxI-0005Jd-5J for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 12:49:36 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xODxH-003Sqn-IC for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 13:49:35 +0100 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ae9d85e-8faa-0a2a0a5109dd-0a2a450a9e12-6 for ; Tue, 03 Nov 2026 13:49:35 +0100 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ae9d85f-f2d2-0a2a450a0019-d155dd31b8e9-3 for ; Tue, 03 Nov 2026 13:49:35 +0100 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-48c4be28b82so4325835f8f.2 for ; Tue, 03 Nov 2026 04:49:35 -0800 (PST) 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-48e71b8c6e9sm24849397f8f.43.2026.11.03.04.49.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2026 04:49:34 -0800 (PST) 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=1793710175; x=1794314975; 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=ea76sT97/Jj9c4zXiDZbZrXgPF1Fz7XWAOxDEa7crk0=; b=CY5Hqd31kd2ldkbgyajiLYKeGFt+zXYA1sYZrcUW0FxjHC5G65TDHLw9+I8/y5WgLC cB2/ISybdGZXKJdYHPYqA/Z4yDWODOlQ6rschOWz0I3V51pm+QT7q6MOla9J1L7+a8kl pxC+UGZYOmxH5ZLRcYWZl/yLGOQ3tQVuQs5ZYwTEDdYvWzIuZNR6PYZWuIem9rZTPtLw QhF/1RBEenMj/xgIJtHkGhxbmDFVhDH4YlOQ5+nVUKDGGd7Uoc/j5CY1MNtZ64gvB+FB X6weA7dj6OpnvcwjM+HJlb/A2kZrpxpN3ntsQQNxNu36SSWsl3rQosrd7OGwzEewC6np rZoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793710175; x=1794314975; 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=ea76sT97/Jj9c4zXiDZbZrXgPF1Fz7XWAOxDEa7crk0=; b=0JEUL+Fg5zCcasUEo7LySBC0P5w8HJDe8WknLOamN/mtFzRrqbeKUrgr2jreAtCwCq 9ICngOYUIrI9v9JQQYce3HrS3WXpKopE1/VmyZoxiOVIIUlmnrEYygPgCt+/WywQUTKO ui/2iFfNUIM2c+a47TnmWXx4DGZ/glRVCNJvcUqYiYvjhJRQcC2p45Br/K2fnKjQ8Eqo X9J8j5VmLGF1BCX2BWI7PiOBwWou8Y7oSlUlnnqf99SiGKvQprTzpEWBnGVR5Z1zVdeT JPSzLnvQvXDWC7jp6rSKimhfCJVtWS71X/igVwJc9nQa6Nrl1PXmtpvrdYwOhB8yLmvq L2MA== X-Gm-Message-State: APuU4Z+XQMpNZSDgQxCABXRbydbJttxdiYqvGyn2YAmkl5rmnQMGtFUT czpZ0usKU12qJhza9g87+GBpIFl9qCmDY5iJ60FOYlwZCBxgFmZFJjkadCgpyQloyBwtavmasVc 5cAcbMA== X-Gm-Gg: AYBFou2rLpogW0JwIo6rsg1g4Oq+zEyQ+SOKyh/BMd2uKNcReIHq4P0mj6xq/osTeH3 YnLuLEPFLHbv6h9d6gT47zsaiEKHUDkQ3Y8F2fXJbRhKdKrZY9AurXtbTqC7pL2/5WLzkpCoNqx LrGlsFoyKMSrqPbCg4FY8+vioIA63yM9Hd0oocvTViB0AV05IgKecR1fzQr897xfJIzkxD81tBS 4U+EiupEp7UUWGMd5vVTB8gTjUXVJ6jv2biod24MYckTVhDGNNG/M1E2TOR/weSSGwcAR/CnNHm 3xFdjBzrJqT0CsXotygZfWphLAYWfzINCWZiS6ys7VY2EcIyAbR9PZ8Mz505wRh5fpnLQtSlbxw khk7GRrY2/lE+o7ihOW3WHByMLyQJt+8qIctdiisjwI7m0NoTUmWsdfb1isc3NN9GlLKNVGdHYe 8apCXNvYB7c9Hr7fNJLy6uEf34Y1mUfy4BMx1/moyNsTc6T5WxkI4bFi1oEOhdkm0B3tdtqCNZ6 ZVa/hqIDfUIxaVPL3QlW+53L7UyTetTga0TXAB2Nq2eC41RDUcWWooGVcuhcBR8nL2k0jF6VUhm vJiHBZUz9h8lak2+AZCmRjM8Y8Rtq6Kf2B0Aw0IT8RfnZCVoE0OMRM5apaHOU8do7MGmpehndTa pok7IKtxJKiMy8p/zDFvZGVe997/5FA6X7q1Leg== X-Received: by 2002:a05:6000:41d1:b0:48e:6a23:4a09 with SMTP id ffacd0b85a97d-48e6e50d8cdmr31098567f8f.54.1793710174811; Tue, 03 Nov 2026 04:49:34 -0800 (PST) Message-ID: <43e47410-7d5c-43c1-bff5-8e1ce3746b7d@suse.com> Date: Tue, 3 Nov 2026 13:49:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 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: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@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+AOVBJBACrZcnHA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Sui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@suse.com> Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1793710175-583CCCFC-D747743A/10/78276251493 X-purgate-type: spam X-purgate-size: 8465 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1793710196716158500 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. --- 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" + : "=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,81 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include + +#if __has_include() +# include +#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 =3D allocated; + + if ( finished ) + return NULL; + + /* Allocations PAGE_SIZE and up will be page-aligned. */ + if ( size >=3D PAGE_SIZE ) + alloc =3D ROUNDUP(alloc, PAGE_SIZE); + + ptr =3D __brk_start + alloc; + + alloc +=3D 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 =3D alloc; + + 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; + + start =3D brk_adjust_start(start); + + 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 Thu Nov 5 07:28:49 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=1793710253; cv=none; d=zohomail.com; s=zohoarc; b=VPX/3D3trPRW60f1TYSCIs9Vs/6yoAaCN65U3jKIvaiiCmOKcO3+yc0akAanlePmgoNKU3uHljXa2XGDJTCuhOD40L4HBWD13PaMGnPTQK94NJ7XSosrI9Ld6nL/n6+rbqaI94yBTaN1huv2vHIiynPU+jW9/u8VKXO3o1jnv+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793710253; 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=OBgoBm3kYY5Yh481MZr1RVDa7YTnM3GtRDCWh4EEjZQ=; b=UlEZ+Xby2m9SP2YtV+NC7gBi0zIHpW+eJJ18WZfhPOsek48+MLPXNU4s8J7tMRScm9XnWl6VZ9eNDQilwoXnBjw7nKi5rtWf3Z3B81PdNcU/SjgSBoQ4UbYKRKkJ7GaMy8P05yL6hNkx82RS9WobdSlfGhrkk4XgpmtBY4Jzgzg= 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 1793710253909105.72279547547123; Tue, 3 Nov 2026 04:50:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1469715.1678471 (Exim 4.92) (envelope-from ) id 1xODyL-0006pd-B1; Tue, 03 Nov 2026 12:50:41 +0000 Received: by outflank-mailman (output) from mailman id 1469715.1678471; Tue, 03 Nov 2026 12:50:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xODyL-0006pW-6v; Tue, 03 Nov 2026 12:50:41 +0000 Received: by outflank-mailman (input) for mailman id 1469715; Tue, 03 Nov 2026 12:50:40 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xODyK-0006pO-3c for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 12:50:40 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xODyJ-006lV5-Fu for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 13:50:39 +0100 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ae9d88d-bab6-0a2a0a5309dd-0a2a450be35c-40 for ; Tue, 03 Nov 2026 13:50:39 +0100 Received: from [209.85.128.44] (helo=mail-wm1-f44.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ae9d89f-b7e8-0a2a450b0019-d155802ce460-3 for ; Tue, 03 Nov 2026 13:50:39 +0100 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso39195005e9.0 for ; Tue, 03 Nov 2026 04:50:39 -0800 (PST) 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 5b1f17b1804b1-4b2a96fc87fsm51937385e9.12.2026.11.03.04.50.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2026 04:50:38 -0800 (PST) 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=1793710239; x=1794315039; 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=OBgoBm3kYY5Yh481MZr1RVDa7YTnM3GtRDCWh4EEjZQ=; b=aRJr09IZusX8SXtCMrcYjNIHJwTsycTTgBVAyjtDr+Uz8MF9km19eWxdJ47obltBQE Ev0lVqp6Ty6JGtCvG8hvT+7q3aBXpeCVm6v8KhqIXyfVb8D44TAbpmAQfJsFyeHmxVnZ 2c5jacrAcGi+/JLNW+LVPUA3m4uSooxZteDhRgFxbVk9mlrhMrqFN5uR4LaxgzDbGFlQ HoulsH5Z9W5sH01tLAw0NCpI3aEof4/XXtGg/buAovQ5e4OIu+ZXtgvoWk/BvhyzF26h Ptnea3sP5hPX3KEzC9mVWFuhxmE/Psmk3ZVl5rQKfCuq2tXiizvNGePCxOBufP2sLslT lH8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793710239; x=1794315039; 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=OBgoBm3kYY5Yh481MZr1RVDa7YTnM3GtRDCWh4EEjZQ=; b=UJA85vlZSCg+2DmJIgzFYBOLp+0bo3qxXwd9zARe/22wGJiRJ+1yAHNcaufUOCSY+W SXB61ruMg9SRgTtxsSLwtB1D9EhyIQ8V4Sher4pwuzJ+SCzhoqS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G8FUsSh1tk= X-Received: by 2002:a05:600c:3d05:b0:4a1:faa1:3813 with SMTP id 5b1f17b1804b1-4ac187a6960mr296030155e9.27.1793710238737; Tue, 03 Nov 2026 04:50:38 -0800 (PST) Message-ID: <2d45d102-e26f-4e93-a213-b02fb685b6ef@suse.com> Date: Tue, 3 Nov 2026 13:50:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 2/3] x86/EFI: replace ebmalloc() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie , Marek Marczykowski , Daniel Smith References: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@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: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1793710239-1B0DD9EA-72A81B5F/10/78276251493 X-purgate-type: spam X-purgate-size: 11914 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1793710255173158500 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. 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 =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/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)) >=3D virt_to_maddr((unsigned long)_stext)) && \ - ((mfn_to_maddr(mfn)) <=3D virt_to_maddr((unsigned long)__2M_rwdata_en= d - 1))) + (mfn_to_maddr(mfn) <=3D virt_to_maddr(brk_end - 1))) =20 #define PRtype_info "016lx"/* should only be used for printk's */ =20 --- 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]; @@ -1157,7 +1160,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; @@ -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 =3D virt_to_maddr(_stext); xen->size =3D __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"); =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(); @@ -2274,7 +2268,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) */ @@ -2296,26 +2289,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 Thu Nov 5 07:28:49 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=1793710300; cv=none; d=zohomail.com; s=zohoarc; b=Gp5VADuQDKjsKv7YVOqk7FxCmf/s80QTCLRB5CdWrDfOCHTuhqWlP6wajCQBDexVtG8KGNciD2WwrawPFyXkHSK2fYAkChtYex6aW0sADuXJb9M4bUXVRJsXcwhj5eclqa2xKdf4DT6a1h+LXtg0SHdRIZPRkkarJhgKiEERq18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793710300; 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=MxqIEucFmiU72oAmb3EKw6fCdMgxF78MB8zBEYT+0qBctwPNdntvjNKN0jUdb3Yjkdmm0TV2wQit/fcMWnBORlHfCT8CIcaDTSUxR1o1bovOMHtv6LCAxtGyJpfM5/aoMF42GzC0+OHYxTFFdPqin3GEdUD3EmhujDcILUC/j+A= 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 1793710300615224.05813602062653; Tue, 3 Nov 2026 04:51:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1469721.1678479 (Exim 4.92) (envelope-from ) id 1xODz2-0007Jl-Hv; Tue, 03 Nov 2026 12:51:24 +0000 Received: by outflank-mailman (output) from mailman id 1469721.1678479; Tue, 03 Nov 2026 12:51:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xODz2-0007Je-Ey; Tue, 03 Nov 2026 12:51:24 +0000 Received: by outflank-mailman (input) for mailman id 1469721; Tue, 03 Nov 2026 12:51:22 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xODz0-0007JI-Kx for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 12:51:22 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xODz0-00DBGH-1I for xen-devel@lists.xenproject.org; Tue, 03 Nov 2026 13:51:22 +0100 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ae9d8c6-8faa-0a2a0a5109dd-0a2a4505bc92-12 for ; Tue, 03 Nov 2026 13:51:22 +0100 Received: from [209.85.128.42] (helo=mail-wm1-f42.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ae9d8c9-4cb1-0a2a45050019-d155802aa466-3 for ; Tue, 03 Nov 2026 13:51:21 +0100 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4a549cd7fd2so6707755e9.0 for ; Tue, 03 Nov 2026 04:51:21 -0800 (PST) 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-48e71b9b54dsm24535110f8f.47.2026.11.03.04.51.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2026 04:51:21 -0800 (PST) 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=1793710281; x=1794315081; 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=dRAY0OR8SI5o9mO44co8aahxMKZ1UPaBgyT2oWh0dt4axI4jLryx7I8LSWAHVv6hgY YUAaxb1tGFfYYN2UQAaGVq1tz36xoc5+hZ73Bwg5g96tUpsaE+uSEs6Bok7WHjleh5gI GTP75LDL1QFAw6bUZfjvydphNI/u3wwQiZznJGM2TRdPzFLNjzkzfR8T7QvYgi44tqAz 4GcE4scZXX1aPfKsMDTfMpITgnf22uFPLKNM2fH56vZMaozXwmRJg8ksmYm09azJdYQd 5lYIBGfrNnlQnYSRM8bbW6i1T57JXKN1710soMNK5zxVxe09Gt5lQ7ho8ektJRuAGtsG bHvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793710281; x=1794315081; 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=GBTzgAGYVw0obYQgMaygZjB/UgkcdZ1BxVNOvHPXdHvVwUHHPfkdXuteVhPK12h+jo y5qD8zf2h98uQHa/eepdSoSojzqdJboO5lQC3cUhJJk87+diQaBq0IeB3nMHay0u6xW2 X6JycmmHE/Y7izEb3ElyIdII9ghtQy1NX8xy8bZ5B3UOaCWN64u+FLIr18o2auuWmLxb Gx9+x7CFrYpmVlM/6KzDZNtTD7Za3DjwLvqXvb4TIc/LGKECdB6dobKqwg/I04g7ABxB 7k255GPiZRwAHQXnWIYq+DRWsEHV6epSiRxKH+S4UOWftmv3+erqKNKBzj5WhrsbjISn 6a7w== X-Gm-Message-State: APuU4Z+AOz2uF3BS+fkUPxZM9zyLbfuSlV7kW7n3DhmUU3FES07E4gD0 UBiyqjFBsIIOc/H99u2IgM8SCWTHAJEjMnzfW2FfRLRNuYIghrbpb0Lw2oddlutwDcYFSnQTypc 4y8SMtg== X-Gm-Gg: AYBFou1P5kMBWuPKSP0CuHdP9Gnm4Bb3YWFdWzANOWsnxxbDq/ZuRjzK5LnL2oOwsUp 01njPq6rSqM5lP8iXkKLDMOt5+T1fyschyt60kNdJovxXcC5KkVoXADsQxu2drhw1m+VnpqjvRU vpk46zBUrjlRND+fVcvmIVvA8cAu9xA0b3oCQmJ8ryCeaWx5UWQmOCilJJtWcs+0nhYbczDFTn3 1odUh50ahhYgm4B7MTIEGtKzBJotFxYEu25hygiHAejpjhzEv0McEXSniHSks2nbFCjDP50Z3z6 XpdLpV3DrT9BvAxuciLsvh9D9hCaYKZrdXyyFHi8tLXOLwZPBC/ANVCCSRyKAGeCi27CpiOr9OA SAFgyPlmTvw1jbXheLqho3f5j327Q7Tzw3Lty6goNHi8EiIoZU+wys1x9k/wGIfoyA8XMTtzt0s GuhF1PbyyS+ltXU5rQhFJmbw5a0MCwqJXAIEbVHbH1VMNxSnzmXyNwGyot7W7ChgRgO29adJn58 iINf0L7ccyb1WBwXtvHBMrwCFzBUashmla2W1pKIdRj9fpqvKdKqDOgw87/P2+HgclFJeF8dytc YR9w/CNj5dcgoMv25RepnsmluRmk8sp8DOyJswoqDF9bCb6dWgSO9Ue0P0wZvCcH/Un9hB46AWf FoL2w8FSdGo9tTos= X-Received: by 2002:a05:600c:4715:b0:49f:ffa2:1c72 with SMTP id 5b1f17b1804b1-4ac17567cc8mr285886085e9.11.1793710281510; Tue, 03 Nov 2026 04:51:21 -0800 (PST) Message-ID: <0360de96-99e0-49da-942b-45727ac6b296@suse.com> Date: Tue, 3 Nov 2026 13:51:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 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: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJk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/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <640c0ea5-fbbf-436d-b150-4537cbe98fdf@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1793710282-F76BD2A1-B78C87DE/10/78276251493 X-purgate-type: spam X-purgate-size: 2953 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1793710301275158500 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);