Re: [PATCH v3 2/5] mm/memory-failure: libstub: install the poisoned-memory EFI table

From: Breno Leitao

Date: Mon Sep 07 2026 - 10:49:40 EST


On Fri, Aug 28, 2026 at 02:59:43PM +0100, Kiryl Shutsemau wrote:
> On Wed, Aug 26, 2026 at 05:03:53AM -0700, Breno Leitao wrote:
> > A EFI config table can only be installed while boot services are still
> > up, so the stub has to create it; the running kernel can only flip bits
> > in a table that already exists.
> >
> > Size the bitmap from the top of usable RAM, which efi_get_ram_top()
> > works out by walking the UEFI memory map, since the stub has no max_pfn.
> > Bit N covers unit N counting from address 0, so the table tracks
> > max_pfn. Memory the firmware hot-adds later sits above it and is not
> > carried across a kexec.
> >
> > One table has to serve every architecture, so efi_get_ram_top() takes
> > the union of the memory types they turn into RAM: what setup_e820() maps
> > to E820_TYPE_RAM on x86, plus the EFI_ACPI_RECLAIM_MEMORY and
> > EFI_PERSISTENT_MEMORY that is_usable_memory() accepts on arm64. Sizing
> > wide only costs bitmap bytes; sizing narrow silently drops the records
> > for every frame above the top.
>
> x86 and ARM doesn't seem to agree what RAM is. On x86 it is by ->type
> and on ARM it is by ->attribute (anything WB/WC/WT).
>
> is_usable_memory() only decides nomap. Everything is_memory() lets in
> lands in memblock.memory, and max_pfn is PFN_DOWN(memblock_end_of_DRAM()),
> so the top of RAM there can be a type that is not on your list.

Thanks. I will just ignore the memory types and get the base and top
based on the memory map descriptors.

Now that I need to get the phys base (from previous patch discussion),
I will need to get the range, doing something like:

static efi_status_t efi_get_ram_range(u64 *base, u64 *top)
{
struct efi_boot_memmap *map __free(efi_pool) = NULL;
u64 ram_base = ULLONG_MAX, ram_top = 0;
efi_status_t status;
int i, nr_desc;

status = efi_get_memory_map(&map, false);
if (status != EFI_SUCCESS)
return status;

nr_desc = map->map_size / map->desc_size;
for (i = 0; i < nr_desc; i++) {
efi_memory_desc_t *d;

d = efi_memdesc_ptr((unsigned long)map->map, map->desc_size, i);
ram_base = min(ram_base, d->phys_addr);
ram_top = max(ram_top,
d->phys_addr + d->num_pages * EFI_PAGE_SIZE);
}
if (!ram_top)
return EFI_NOT_FOUND;

*base = round_down(ram_base, EFI_POISON_UNIT_SIZE);
*top = round_up(ram_top, EFI_POISON_UNIT_SIZE);

return EFI_SUCCESS;
}

is it what you had in mind?

Thanks,
--breno