Can EFI memory descriptors overlap? [PING v1]

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

 



Hi, I'm working on the rework of
https://lore.kernel.org/linux-efi/CAMj1kXEqjHVRNV131=o_aO3TX+58xhYzgfaVDrd0RngAqqtrVg@xxxxxxxxxxxxxx/T/
and I wanted to know if the memory map given by EFI have any guarantee
that the regions don't overlap.

I couldn't find anything in the UEFI spec, but there is a piece of
code in the kernel that seems to "doesn't care" and assumes that the
regions given by EFI are sorted and don't overlap.

https://elixir.bootlin.com/linux/latest/source/arch/x86/platform/efi/efi.c#L502

static void __init efi_merge_regions(void)
{
    efi_memory_desc_t *md, *prev_md = NULL;

    for_each_efi_memory_desc(md) {
        u64 prev_size;

        if (!prev_md) {
            prev_md = md;
            continue;
        }

        if (prev_md->type != md->type ||
            prev_md->attribute != md->attribute) {
            prev_md = md;
            continue;
        }

        prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;

        if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
            prev_md->num_pages += md->num_pages;
            md->type = EFI_RESERVED_TYPE;
            md->attribute = 0;
            continue;
        }
        prev_md = md;
    }
}

Is this a bug or in practice EFI always gives a "nice" memory map? I
think that if there is no overlap then the sorting (EFI doesn't give
me a sorted memory map on my machine) is a kind of easy problem to
solve, but if there is overlap involved then we need to decide for the
type and the attributes of those overlaps, which can be tricky.

I'm working on x86 and with the master branch of the kernel.

Martin.



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux