From nobody Thu Sep 24 20:25:23 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=1785147574; cv=none; d=zohomail.com; s=zohoarc; b=hVAVvYq83gSFxeOH/zys67MrbZe1MCwcQMQSqIusBbyG3bZI5W+N/QdCzjqj3T/tHMblHlabYg4m/uqKK3w0qSQDsP6F9/LD6TW3OgpZjUl8zKMCOGfal6AJC4F7BGYAOeGyBsd4SYRZCpp6bs+dOHEh69M0fJ+oj3nF6ZshEA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785147574; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QQeKvAlM6SQzoqidXEVQvyJcj1pj7jbbJp3aYbBoUHY=; b=NG60xLA5yJmk0r/dodfEWbCs7MWs+/fV08/30kR+6+cuCXf7AOllEogiqArHOD9a5aOzjlWA6oFk40Jrt8apONdTX8khGncZq9JoN/iuBw/b9ayczzttc8ml+jw6XlVzN+H3Oh680crLPZsuCTilCki6NlBbq/G0hytGdD3ab30= 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 1785147574218179.42366377619214; Mon, 27 Jul 2026 03:19:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1371512.1619000 (Exim 4.92) (envelope-from ) id 1woIQa-0006Hl-8w; Mon, 27 Jul 2026 10:19:20 +0000 Received: by outflank-mailman (output) from mailman id 1371512.1619000; Mon, 27 Jul 2026 10:19:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIQa-0006He-67; Mon, 27 Jul 2026 10:19:20 +0000 Received: by outflank-mailman (input) for mailman id 1371512; Mon, 27 Jul 2026 10:19:18 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIQY-0006HO-IS for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 10:19:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woIQX-003Lf7-Ux for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 12:19:17 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a67309f-e002-0a2a0a5209dd-0a2a4502be9e-20 for ; Mon, 27 Jul 2026 12:19:17 +0200 Received: from [209.85.128.45] (helo=mail-wm1-f45.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6730a5-6ca4-0a2a45020019-d155802df099-3 for ; Mon, 27 Jul 2026 12:19:17 +0200 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4953e04ef16so28290035e9.2 for ; Mon, 27 Jul 2026 03:19:17 -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 5b1f17b1804b1-496b4ee4504sm212578435e9.6.2026.07.27.03.19.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jul 2026 03:19:17 -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=1785147557; x=1785752357; 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=QQeKvAlM6SQzoqidXEVQvyJcj1pj7jbbJp3aYbBoUHY=; b=UQ/qK6fBxR40AuYVyHOrfsOiaj9RllNi6bem55H5IX5yyiWqO/bRYRUr36+zhssnvX zMiuz8IMRq9CQdOJJzip5fOhfXPHaFu9+pOLa+jyAiIw5W1Fet15MhXwuoZvSxo0yue4 L2VkjLTv7WBbXNtFVfAWCNThD8tAcCJOv2NNJonGBzr0iqJIKgO0ob+98J4JCCdcepn5 fvYj4nyGr4Mvqz8OtvAPb2v/AekxNvcG9qA0hL6GpRUnegVOoMZCXBRlUSsqVmVn7pHo 7vJEm7OYj5QW60ojh7FHu9HZ/Lul9flmgFrnGmL3QoK8y3VH6c5g3USSjV1tF912Pk3e MBfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785147557; x=1785752357; 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=QQeKvAlM6SQzoqidXEVQvyJcj1pj7jbbJp3aYbBoUHY=; b=C8J57QmBvXrrQV6cJ9am0Z+LMRe2Kprjc2Xji78e75fjviGdb/I6aM0AGauK4V7x/+ N+etuMu2lVSmaYJ3pLRhzd03nQe5L3YrDkk49PyfzHbbAMUBm0/zBoPQBVxDp9DPAhDo oz9Lr2EUel1QUphFm9Kdnllw0/8vvej3t3OV2jiPqBAOxwzuLHVDLsvUFFkYxS/8p1Ta l6OVk5HSLf+f1TODyYg7vkbHgrFGqreQwFvfg0Jt1PtmIqRTap3YL5Gbxv1CMkvK4tyy WiREL1CBY3aIolIcMD2eRFDr9Zod9JDBJXgWTfBKlYotzkIDY6/g867I6a/dWb4f8seV mS5Q== X-Gm-Message-State: AOJu0YxzFLGrxirsXs/apdagv/nClS6HDSF9w2g3uMwbpw7jWbxkOjIe CptqKLGD4i/imkDaVe7b5XKSOkqIH4iI6vRjaNncwCW0abgcGgYLsKvUQFOY/T7SaXmlGuDYhMw 35BZzuQ== X-Gm-Gg: AR+sD116Q1CICWs03T/nx3jjiOS1kyQubXbWAdGVlHByjf3c/0bEBlwW9JvRtMXYurR twohnGYID5MAXECrMUAjYJPhj9ae0HYQNhyl+6MFV17AeR1Wkb0OLV9fnBmWGAL2N+/+e2aheai vjMQJm/+eAS8+WSm4aEWhgkV8k2GZKh9aDeq1gXSSyswmmD89w7ZJ89AO0ETDaQ17zKqMebHrLa DkSXgOT/V2khtCcdU47zxOeAF0oOYxm0lw0Xgf3FiHwGCPm7z/RpchHVaUAUghUK6eCAWN9AqR3 dt80CQ5GwQSI9oMxzupMkRaDlTfXz3d84bEXFdPZfMJK3oSAUDIPJO8xEzfV38naRcJPxqFx1aO 7u1Fxp1SVpz6mVzyCMC0OPipkYVhxtpHrjaovN8D3N1clnAh6tAx/QINnqOFEpyd3bFk5movTxa 2uStXRVQmy+HN3GgU3QKBrnlt4raIuwqyBAP7yzSmw3BH95JOI/6I1pq0OeyIJ2vusonOmluB0N TTx X-Received: by 2002:a05:600c:1553:b0:493:e97c:216e with SMTP id 5b1f17b1804b1-496b5731987mr102856695e9.39.1785147557288; Mon, 27 Jul 2026 03:19:17 -0700 (PDT) Message-ID: Date: Mon, 27 Jul 2026 12:19:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/3] x86: introduce "brk" allocator From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@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: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@suse.com> Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1785147557-F10A02AC-A2151BDC/0/0 X-purgate-type: clean X-purgate-size: 4281 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1785147575796158500 Content-Type: text/plain; charset="utf-8" ... to replace ebmalloc(), and then to find further use(s) to allow recovering memory which is needed very early (and hence needs setting up statically), but may not fully be used (or not used at all). Note that unlike free_ebmalloc_unused_mem(), brk_free_unused() (once other code is converted) will be able to free part of the BRK space even in the xen.efi case. That would happen if BRK space extends across a 2Mb boundary, and actual use stops before that boundary. Signed-off-by: Jan Beulich --- Changing setup.c's reserve_e820_ram() uses would be cumbersome when done right here. That'll be done when ebmalloc() is replaced, and hence what's there can also simply be replaced. The xen.efi detection may want separating out into a helper. When linking xen.efi, ld produces a base relocation for the reference to __subsystem__, which is wrong (that's an absolute symbol, after all). While that will need fixing there, it does no harm for our purposes. --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,4 +1,5 @@ obj-bin-y +=3D head.o +obj-bin-y +=3D brk.init.o obj-bin-y +=3D built-in-32.o obj-bin-y +=3D $(obj64) =20 --- /dev/null +++ b/xen/arch/x86/boot/brk.c @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include + +#include + +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 =3D __brk_start + allocated; + + if ( finished ) + return NULL; + + /* Allocations PAGE_SIZE and up will be page-aligned. */ + if ( size >=3D PAGE_SIZE ) + allocated =3D ROUNDUP(allocated, PAGE_SIZE); + + allocated +=3D ROUNDUP(size, sizeof(void *)); + + if ( allocated > __bss_end - __brk_start ) + return NULL; + + return ptr; +} + +unsigned long __init brk_get_unused_start(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_get_unused_start(), + end =3D (unsigned long)__bss_end; + unsigned int subsys; + + /* + * Only xen.efi will have the symbol __subsystem__ available, and it'll + * be non-zero (10) there. In ELF the symbol will be undefined, and + * hence zero will be loaded into the register. + */ + asm ( ".weak __subsystem__; mov $__subsystem__, %0" : "=3Dr" (subsys) = ); + + /* using_2M_mapping() isn't available here. */ + if ( IS_ENABLED(CONFIG_XEN_ALIGN_2M) || subsys ) + start =3D PAGE_ALIGN_2M(start); + + if ( start >=3D end ) + return; + + destroy_xen_mappings(start, PAGE_ALIGN_2M(end)); + + /* + * By reserving needed space early in the E820 map, excess space gets = freed + * way before we make it here. Don't free the range a 2nd time. + */ + + printk(XENLOG_INFO "Freed %lukB unused BRK memory\n", (end - start) >>= 10); +} --- /dev/null +++ b/xen/arch/x86/include/asm/brk.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include + +void *brk_alloc(size_t size); +unsigned long brk_get_unused_start(void); +void brk_free_unused(void); --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -321,7 +321,11 @@ SECTIONS __bss_start =3D .; *(.bss.page_aligned*) PERCPU_BSS - *(.bss .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 .; } PHDR(text) --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -112,6 +112,7 @@ #include #include =20 +#include #include #include #include @@ -338,6 +339,8 @@ void __init arch_init_memory(void) =20 efi_init_memory(); =20 + brk_free_unused(); + #ifndef NDEBUG if ( highmem_start ) { From nobody Thu Sep 24 20:25:23 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=1785147634; cv=none; d=zohomail.com; s=zohoarc; b=FVi2BVrdPFpNmIGKXMIDk4z83fuLaIsxPXuQlKuUuIE97hsH01PlPL8WUwWoEvSh3y7d+ocnoTVSWtSvI5dwVTR9XitI+CqyPKvNxQgVxg8sQl2oXLGa3MAqYh54HMX/k9KPshtdkYd+OMLuqB143Vi4tg5ciZoJYwuG5rGi6HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785147634; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FN7W45SrJHwi206FXCh2uedKhx/KQMiLh+IoEidA5MA=; b=WMKnxPtYu3HWGSxj2uAz5Zsl/064Mlrx4AU+zg+GjU9+joW083tQlfefwl7bgb0JtgSXs9q6eDJE4vulP956bMLrawTpi5AFEn39QjEnpnjPCFJXYv3NkED1C1kRJO/VrWe1CiL43KXWjMzH+JBxVOz+P89mdS16V17yPrS67jM= 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 1785147634617339.14889079750674; Mon, 27 Jul 2026 03:20:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1371519.1619009 (Exim 4.92) (envelope-from ) id 1woIRT-0007lE-HQ; Mon, 27 Jul 2026 10:20:15 +0000 Received: by outflank-mailman (output) from mailman id 1371519.1619009; Mon, 27 Jul 2026 10:20:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIRT-0007l7-Ed; Mon, 27 Jul 2026 10:20:15 +0000 Received: by outflank-mailman (input) for mailman id 1371519; Mon, 27 Jul 2026 10:20:13 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIRR-0007kp-9Q for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 10:20:13 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woIRQ-000sPx-Az for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 12:20:12 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6730d3-bab6-0a2a0a5309dd-0a2a450c9838-24 for ; Mon, 27 Jul 2026 12:20:12 +0200 Received: from [209.85.221.54] (helo=mail-wr1-f54.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6730dc-f479-0a2a450c0019-d155dd36e01d-3 for ; Mon, 27 Jul 2026 12:20:12 +0200 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-47f3b39f2a1so2094476f8f.2 for ; Mon, 27 Jul 2026 03:20:12 -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-47f85b9a596sm46797487f8f.4.2026.07.27.03.20.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jul 2026 03:20:11 -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=1785147612; x=1785752412; 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=FN7W45SrJHwi206FXCh2uedKhx/KQMiLh+IoEidA5MA=; b=JvlO8rTgRDXpiZ06aJC3RGCQagDpqY9Yi5jzd8WnIQ7o+GnRz9R2zccPU7/me9ABhO dl1GhLsrJT2tpOjoeBij3wLrF+hjYsCVd8OQq6tG0vqRI3+ovr7nfQumQBYm2tXWhVuD wWoni2lkCOqKgU/7pvWCMjzXxFUX18QqPPaxxx8ZZ5ZEM9hVoZu9mlWnesKfD1ngJQX7 3ccHf12IxnL3rIr97dAE/O/zhW1Mnl1iQGpF5A4ZnLmEE5g2qhh+ZGNmfuiENbeZIIGr Ty7Pc5J6qozY0mIIJ44HPFkp6I5tulf4IGnOHnonYrz4jijfe37Ku/wbk92J1M7hft0U 9u9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785147612; x=1785752412; 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=FN7W45SrJHwi206FXCh2uedKhx/KQMiLh+IoEidA5MA=; b=fxabuECFmBUP13/ffo1ptt+WXj58OFammGRAGGoXQR5CEmpGEaryUuUdGIJ1yK4Ee5 HSsY+4SjhHajuqEiNkN7lW2UZgzDINHGALHz0khFwx0mten0jXJ8z1E4gxuL02PfiSLI YmvyI/VSORpVbzjJTDdtzGENS9AZ4osyEyORf7w50pGf1MvvsqC2jtFJHQHaUMa6/vYY JbuFgR0J9iqT88crHBUONL/RH4OcO0wLqxXEabY2BRgZqmj4Aj0EFi5To9oyPhFp9P/2 sHqgHq0Zt1h/bhdhQyU/37WXMfdVml8K5RSDiGkqbkb7mgXkVEYY5zZ3FK1Grj+vZt9d A2nA== X-Gm-Message-State: AOJu0YwFMe89Eto2Pg1O92t4DmXW+i43SOsWgHGt337oEKi3Nh+ScfMN uTqBVnVP6lPlw4Nv6FYc8z072gBfZ7F8yYTYWE6X6QS65syAHp0/zDxRqT/LAxMG6qIpCc7aPmc 83nGG6Q== X-Gm-Gg: AR+sD13NvrmX62KnsTmzYnxTWNOTwnq1btqACwApfV3NnUcYER6QYvu5eDnaxK9W7zy tHuW/dUzq6GqCLiruLeeHuqvJIOEWA2ZJ0vvrXy+N8Wy9Xdq+CReLDBJ2GqG1SYW5zy9cQlgi42 BB/hFJ3uHTYAj4TGL8EousR/UJ80FIJzR1qmO5UVjxuFAbRkPK10z9SXR4dkhbd9aduQCnUA8yN r0wtL233f7sKUAT+vyTtHMsV4QHJLuhJMvfvkpyxgnPqViFwwA80z79t265AtcoIasS2OilzMeX 76Iw46o+QrMJeasGlAx18aP325apILEQbv2lVeyWXDZAtV0Aa3UWADewNcHyf5xOSAg9BgspNan YXtGjYoz2GfdyFxOPm35B4pkMHLFp3EWYtia2FcJyu6urbBZNFBgHKjRNnAoqC0TZxzkNGszLK3 bnBvlYWnf/qhGhD6MhtTY2aWk7kGtonPm+Rsc2I9ruJjfIRs1uWvtN81NlX+uDiGnH2g== X-Received: by 2002:a05:6000:4903:b0:47f:93d8:f480 with SMTP id ffacd0b85a97d-47f9fea2d13mr9482811f8f.39.1785147611673; Mon, 27 Jul 2026 03:20:11 -0700 (PDT) Message-ID: <98388998-c5c6-4991-8662-2b4bf25188f2@suse.com> Date: Mon, 27 Jul 2026 12:20:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 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 , Teddy Astie , Marek Marczykowski , Daniel Smith References: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@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: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1785147612-03ED2A5B-FCB42320/0/0 X-purgate-type: clean X-purgate-size: 11267 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1785147637911158500 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. --- 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) ;; \ + .*.local|.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 @@ -10,6 +10,7 @@ #include =20 #include +#include #include #include #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/brk.h +++ b/xen/arch/x86/include/asm/brk.h @@ -2,6 +2,10 @@ =20 #include =20 +#define DEFINE_BRK(var, size) \ + static char __section(".bss..brk.page_aligned") __aligned(PAGE_SIZE) \ + __used var ## _brk_[size] + void *brk_alloc(size_t size); unsigned long brk_get_unused_start(void); void brk_free_unused(void); --- 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 @@ -31,6 +31,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]; @@ -1141,7 +1144,6 @@ void asmlinkage __init noreturn __start_ struct boot_info *bi; unsigned long nr_pages, 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; @@ -1511,7 +1513,7 @@ void asmlinkage __init noreturn __start_ /* * This needs to remain in sync with remove_xen_ranges() and the * respective reserve_e820_ram() invocation below. No need to - * query efi_boot_mem_unused() here, though. + * query brk_get_unused_start() here, though. */ xen->start =3D virt_to_maddr(_stext); xen->size =3D __2M_rwdata_end - _stext; @@ -1654,18 +1656,11 @@ void asmlinkage __init noreturn __start_ if ( !xen_phys_start ) panic("Not enough memory to relocate Xen\n"); =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) ) - { - reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start)); - reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end)); - } - else - reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end)); + brk_end =3D brk_get_unused_start(); + if ( using_2M_mapping() ) + brk_end =3D PAGE_ALIGN_2M(brk_end); + reserve_e820_ram(&boot_e820, __pa(_stext), __pa(brk_end)); =20 /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(); @@ -2267,7 +2262,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) */ @@ -2289,26 +2283,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 @@ -1825,8 +1825,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 Sep 24 20:25:23 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=1785147653; cv=none; d=zohomail.com; s=zohoarc; b=QHsei4HteXBFktwPXFrNTjgwQ/xvKZPYBZ4r7an9vY1jtdcZRkuY9GqNhnt+DDIoxtMTOHnPQT9rSdpwhVgjoPV21mcg/bP1qurYKWBTzN++glxMbOFTCL6T/vM8Utuh4esTgAzu8Qa4ty6SjHXwUSir+U3Uxcfq2p4EHKlO8WU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785147653; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R+gGXDm7e3E7luUT03vkRevAy5s7Sddb9vqNWLAUZMQ=; b=PUbEY+yMZr0Q31Dwq15KyqBNwA/MorlFPfEF/kWiTHlKR8MYyvW11G+SiI3P5j8BKb+qTiT5Gk1ygM6uk7czvy4TGdKUrL57ZS6FUb4SQAEg95oGVKQzPguIcHE7+Fnru94hAyK13KzH+udi0AMEYzGD2rjHp9MmP5Vkwt7dsqY= 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 1785147653427954.2108624270612; Mon, 27 Jul 2026 03:20:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1371525.1619019 (Exim 4.92) (envelope-from ) id 1woIRu-0008Dv-Se; Mon, 27 Jul 2026 10:20:42 +0000 Received: by outflank-mailman (output) from mailman id 1371525.1619019; Mon, 27 Jul 2026 10:20:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIRu-0008Do-Ps; Mon, 27 Jul 2026 10:20:42 +0000 Received: by outflank-mailman (input) for mailman id 1371525; Mon, 27 Jul 2026 10:20:41 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woIRt-0008DY-Hu for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 10:20:41 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woIRs-003M40-UB for xen-devel@lists.xenproject.org; Mon, 27 Jul 2026 12:20:40 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6730eb-e002-0a2a0a5209dd-0a2a4504e8f6-34 for ; Mon, 27 Jul 2026 12:20:40 +0200 Received: from [209.85.128.45] (helo=mail-wm1-f45.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6730f8-b57f-0a2a45040019-d155802ddc3e-3 for ; Mon, 27 Jul 2026 12:20:40 +0200 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4954afac04bso29923265e9.0 for ; Mon, 27 Jul 2026 03:20:40 -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 5b1f17b1804b1-4957bfe07e1sm224907225e9.3.2026.07.27.03.20.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jul 2026 03:20:39 -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=1785147640; x=1785752440; 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=R+gGXDm7e3E7luUT03vkRevAy5s7Sddb9vqNWLAUZMQ=; b=Hb1aVC10FSzRxeUfP6Jfrf+6LBwOlPqHBwgCOkWtLCe5kaHRAZIXN7elQe/tHWzwm/ yGr5S4GdM2/GQi+1QjfXCIQcDkH0PJm3XCBpwGes1RunXk+aE9Q+GPoqI8JbGiA9uYOU 5+QjPPdZ4ySYDsj0wxARgcfyiOSxr3r119fs5qIAn4Mqng2ET2Dos1bVolSib/2jdheQ UApHT+B70pT7hO+OfUPCT/0r14G/QCpDUEt5Ox/yGKjYM3GXo8muQxi3Iohw4K62NuFe SLZg1tdovtmeJOiIc3fwgwZit7wgh6WHDz6719HHiuqUCKb4TdV3PhDyXmSnSQX8Syot 3Jbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785147640; x=1785752440; 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=R+gGXDm7e3E7luUT03vkRevAy5s7Sddb9vqNWLAUZMQ=; b=BgNT9G70vSA248MEBTwinfa7Vk3oCJ1ByxCAFndfn/HijymQaVswQGok2Zrrn5hE9x +bVf6BgYW6zzpDdwwnS2Rs3SdgXiyln3ofi9TZiXEYPLnRsPXyiIO3a5AmKlvf/Z7Jm8 o1xvrem3EjYcWNv7zq/TQ2RWVGJ6JCG4805QWzHT8nMeSJ8bTphBIDydWEqC3t6ch0Xy KK+6LoUxSC3JI/DQOcF4BqgEI4Hs33JC0iFK+Ch8Cft4ONd99X1eipS37phHFKxDOGcM lI3lqjKQtBGL+i5JsKxK8r2FPVRC5cNRScxGvNg3ZEt0f9fS9VNzTF0e6Nbii3Mc7tsU WPNw== X-Gm-Message-State: AOJu0YzcXWRXo0IR3YIXKHTTgnxpkXsuvtGMDT+pqHDiJ8ZJlJ7g4Rnb J8rDsZ+2uLEje+mE/FjTRgoemO625Bz5UFmacMt38027YuO11jLwilelOGSUEr7tp8Ch/gbMrEm +qttGcA== X-Gm-Gg: AR+sD12LNt0qL7PCghOoVuCnKpl41u624aTHZ8NZRp+oYvC20A8Rk6XaWx+6rRNdV0k KSt+fAyqEyD/dTPxDSui5kKdzqONue5vnuV2Ys2WXJAM8Pk6ZdwjABVkaiyMl/d3KBwixwGZadX UkVn/R1zNqrRSkQdjm5WM0qfGJ0Uaizl5Cpdq/g40U4mZUl99sf/JVCOIjJ4lFXE2pAKmApoBU6 pNKaZJ7b38mBMcKr59k8k/whyfcLGkRoeWkumPTjhQPk06QCLq8J/O/DCcnUG7TPVp8ZrFr9xOQ 14uZ7PKRpoVci0RfqSNdabcSqJILOY2q3XMvlEbURFESWKvzZD/qENR9eoEf3dizPLSHVZJjL3I XowqR+4NrxefMD2iwLb6RV7Bb32s98WPkKYoQ93valoyg6/mVw4SRUsG4fsorzcxnhtR2NN4w3l qwFs+EqRdO3Aq8GJ/yM7ck3BhxYJKsiSRZYB0X9fdA6jpSTmNYSNIeD+kJKEZU5d6Ydf1It2eru jtv X-Received: by 2002:a05:600c:12d4:b0:495:4dd3:ca97 with SMTP id 5b1f17b1804b1-496b56fa62bmr62636045e9.29.1785147640288; Mon, 27 Jul 2026 03:20:40 -0700 (PDT) Message-ID: Date: Mon, 27 Jul 2026 12:20:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/3] xhci-dbc: use brk_alloc() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Marek Marczykowski References: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@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: <31ba7ff2-a42d-44aa-976c-17fbff44a56f@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ebf023/1785147640-C26CAB50-33559181/0/0 X-purgate-type: clean X-purgate-size: 2748 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1785147655711158500 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 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -27,6 +27,8 @@ #include #include #include + +#include #include #include #include @@ -1321,7 +1323,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]; @@ -1335,8 +1337,7 @@ struct dbc_dma_bufs { * DMA-reachable by the USB controller. */ }; -static struct dbc_dma_bufs __section(".bss.page_aligned") __aligned(PAGE_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) { @@ -1413,24 +1414,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);