[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 2/3] x86/EFI: replace ebmalloc()


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 18 Nov 2026 15:34:19 +0100
  • 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:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; 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
  • Cc: Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Marek Marczykowski <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Daniel Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 18 Nov 2026 14:34:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 18.11.2026 14:26, Andrew Cooper wrote:
> On 17/11/2026 7:37 am, Jan Beulich wrote:
>> On 16.11.2026 19:13, Andrew Cooper wrote:
>>> On 03/11/2026 12:50 pm, Jan Beulich wrote:
>>>> --- a/xen/arch/x86/include/asm/setup.h
>>>> +++ b/xen/arch/x86/include/asm/setup.h
>>>> @@ -9,6 +9,8 @@ extern const char __2M_rodata_start[], _
>>>>  extern char __2M_init_start[], __2M_init_end[];
>>>>  extern char __2M_rwdata_start[], __2M_rwdata_end[];
>>>>  
>>>> +extern unsigned long brk_end;
>>>> +
>>>>  extern unsigned long xenheap_initial_phys_start;
>>>>  extern uint64_t boot_tsc_stamp;
>>>>  
>>>> --- a/xen/arch/x86/setup.c
>>>> +++ b/xen/arch/x86/setup.c
>>>> @@ -1,6 +1,7 @@
>>>>  #include <xen/acpi.h>
>>>>  #include <xen/alternative-call.h>
>>>>  #include <xen/bitops.h>
>>>> +#include <xen/brk.h>
>>>>  #include <xen/console.h>
>>>>  #include <xen/cpu.h>
>>>>  #include <xen/cpuidle.h>
>>>> @@ -164,6 +165,8 @@ cpumask_t __read_mostly cpu_present_map;
>>>>  
>>>>  unsigned long __read_mostly xen_phys_start;
>>>>  
>>>> +unsigned long __ro_after_init brk_end;
>>>> +
>>> I know it's only x86 which uses brk_end right now, but given uses such
>>> as ...
>>>
>>>
>>>>  /* Only used in asm code and within this source file */
>>>>  char asmlinkage __section(".init.bss.stack_aligned") __aligned(STACK_SIZE)
>>>>      cpu0_stack[STACK_SIZE];
>>>> @@ -1157,7 +1160,6 @@ void asmlinkage __init noreturn __start_
>>>>      struct boot_info *bi;
>>>>      unsigned long raw_max_page;
>>>>      int i, j, bytes = 0;
>>>> -    unsigned long eb_start, eb_end;
>>>>      bool acpi_boot_table_init_done = false, relocated = false;
>>>>      bool vm_init_done = false;
>>>>      int ret;
>>>> @@ -1523,7 +1525,7 @@ void asmlinkage __init noreturn __start_
>>>>          /*
>>>>           * This needs to remain in sync with remove_xen_ranges() and the
>>>>           * respective reserve_e820_ram() invocation below. No need to
>>>> -         * query efi_boot_mem_unused() here, though.
>>>> +         * query brk_cease() here, though.
>>>>           */
>>>>          xen->start = virt_to_maddr(_stext);
>>>>          xen->size  = __2M_rwdata_end - _stext;
>>>> @@ -1667,20 +1669,12 @@ void asmlinkage __init noreturn __start_
>>>>      if ( !xen_phys_start )
>>>>          panic("Not enough memory to relocate Xen\n");
>>>>  
>>>> -    /* FIXME: Putting a hole in .bss would shatter the large page 
>>>> mapping. */
>>>> -    if ( using_2M_mapping() )
>>>> -        efi_boot_mem_unused(NULL, NULL);
>>>> -
>>>>      /* This needs to remain in sync with remove_xen_ranges(). */
>>>> -    if ( efi_boot_mem_unused(&eb_start, &eb_end) )
>>>> -    {
>>>> -        if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start)) 
>>>> ||
>>>> -             !reserve_e820_ram(&boot_e820, __pa(eb_end), 
>>>> __pa(__2M_rwdata_end)) )
>>>> -            panic("Failed to reserve Xen in E820\n");
>>>> -    }
>>>> -    else
>>>> -        if ( !reserve_e820_ram(&boot_e820, __pa(_stext), 
>>>> __pa(__2M_rwdata_end)) )
>>>> -            panic("Failed to reserve Xen in E820\n");
>>>> +    brk_end = brk_cease();
>>>> +    if ( using_2M_mapping() )
>>>> +        brk_end = PAGE_ALIGN_2M(brk_end);
>>>> +    if ( !reserve_e820_ram(&boot_e820, __pa(_stext), __pa(brk_end)) )
>>>> +        panic("Failed to reserve Xen in E820\n");
>>>>  
>>>>      /* Late kexec reservation (dynamic start address). */
>>>>      kexec_reserve_area();
>>>> @@ -2274,7 +2268,6 @@ __initcall(init_xen_cap_info);
>>>>  
>>>>  int __hwdom_init remove_xen_ranges(struct rangeset *r)
>>>>  {
>>>> -    paddr_t start, end;
>>>>      int rc;
>>>>  
>>>>      /* S3 resume code (and other real mode trampoline code) */
>>>> @@ -2296,26 +2289,10 @@ int __hwdom_init remove_xen_ranges(struc
>>>>          return rc;
>>>>  
>>>>      /* hypervisor .data + .bss */
>>>> -    if ( efi_boot_mem_unused(&start, &end) )
>>>> -    {
>>>> -        ASSERT(__pa(start) >= __pa(&__2M_rwdata_start));
>>>> -        rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
>>>> -                                   PFN_DOWN(__pa(start) - 1));
>>>> -        if ( rc )
>>>> -            return rc;
>>>> -        ASSERT(__pa(end) <= __pa(&__2M_rwdata_end));
>>>> -        rc = rangeset_remove_range(r, PFN_DOWN(__pa(end)),
>>>> -                                   PFN_DOWN(__pa(&__2M_rwdata_end) - 1));
>>>> -        if ( rc )
>>>> -            return rc;
>>>> -    }
>>>> -    else
>>>> -    {
>>>> -        rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
>>>> -                                   PFN_DOWN(__pa(&__2M_rwdata_end) - 1));
>>>> -        if ( rc )
>>>> -            return rc;
>>>> -    }
>>>> +    rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)),
>>>> +                               PFN_DOWN(__pa(brk_end) - 1));
>>>> +    if ( rc )
>>>> +        return rc;
>>> ... this, it clearly needs to be common in order for other architectures
>>> to start using the allocator.
>> I don't see why this would necessarily be this way. This is x86-specific
>> memory management, and other ports may have no need. I'd therefore prefer
>> to leave brk_end x86-only until proven otherwise. It was, after all, a
>> deliberate decision to make this x86-only.
> 
> I'm very unconvinced.
> 
> An architecture that doesn't care to reclaim unused space just uses
> plain data/bss objects, which is what happens today.
> 
> An architecture will only care to switch to brk in order to reclaim
> space, and to do so it *must* replace all of it's current end markers
> with brk_end.

Or we want to start using brk_alloc() in common code, without forcing
all ports to deal with the freeing of excess space. They then don't
need to record the return value of brk_cease(), they don't need to
call brk_free_unused(), and they would have no need for any form of
brk_end.

> brk_end will probably only be consumed by arch-specific code, but it's
> produced by common code and therefore it needs to be part of the common
> brk infrastructure.  This also has the important property of preventing
> it from getting named differently in different architectures.

Well, as almost always (no matter that as the patch author I think I
should have some room to choose between options) it's going to be me
to give in. Just to finally get this done.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.