Re: [PATCH 3/3] efi: Make the 'linux,uefi-boot-memmap' DT property optional
Richard Lyu <[email protected]>
| Newsgroups | org.kernel.vger.linux-efi,dev.linux.lists.loongarch,org.infradead.lists.linux-arm-kernel |
|---|---|
| Message-ID | <an1_kKjIWebhWVT5@r1chard> |
On 2026/08/13 09:45, Ard Biesheuvel wrote: >The 'linux,uefi-boot-memmap DT property' is redundant in principle, >given that it carries a physical address that is also passed via a EFI >config table entry. > >However, if SetVirtualAddressMap() has been called, the address of the >config table array has been translated to virtual, and so the memory map >is needed to translate it back to physical before it can be located. > >This means that passing the linux,uefi-boot-memmap DT property is only >needed if SetVirtualAddressMap() has been called, which is a terrible >idea anyway, and if it has not been called, the config table array can >simply be parsed to look for LINUX_EFI_BOOT_MEMMAP_TABLE_GUID, and the >address taken from there. > >So permit this, and make the boot memmap property optional. > >Signed-off-by: Ard Biesheuvel <[email protected]> >--- > drivers/firmware/efi/fdtparams.c | 42 ++++++++++++++++++-- > 1 file changed, 38 insertions(+), 4 deletions(-) > >diff --git a/drivers/firmware/efi/fdtparams.c b/drivers/firmware/efi/fdtparams.c >index a54a76a6aaeb..89ffccf35fd7 100644 >--- a/drivers/firmware/efi/fdtparams.c >+++ b/drivers/firmware/efi/fdtparams.c >@@ -89,14 +89,15 @@ static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname, > u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm) > { > const void *fdt = initial_boot_params; >- unsigned long systab, memmap; >+ unsigned long systab, memmap = 0; > int i, j, node; > struct { > void *var; > int size; >+ int optional; > } target[] = { > [SYSTAB] = { &systab, sizeof(systab) }, >- [MEMMAP] = { &memmap, sizeof(memmap) }, >+ [MEMMAP] = { &memmap, sizeof(memmap), 1 }, > #ifdef CONFIG_XEN > [MMBASE] = { &mm->phys_map, sizeof(mm->phys_map) }, > [MMSIZE] = { &mm->size, sizeof(mm->size) }, >@@ -131,14 +132,47 @@ u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm) > continue; > if (!j) > goto notfound; >- pr_err("Can't find property '%s' in DT!\n", pname); >- return 0; >+ if (!target[j].optional) { >+ pr_err("Can't find property '%s' in DT!\n", pname); >+ return 0; >+ } > } > if (IS_ENABLED(CONFIG_XEN) && dt_params[i].paravirt) { > set_bit(EFI_PARAVIRT, &efi.flags); > } else { > struct efi_boot_memmap *bm; > >+ if (!memmap) { >+ unsigned long tables, nr_tables; >+ efi_system_table_t *st; >+ efi_config_table_t *tbl; >+ >+ st = early_memremap_ro(systab, sizeof(*st)); >+ if (!st) { >+ pr_err("Cannot remap EFI system table\n"); >+ return 0; >+ } >+ >+ tables = st->tables; >+ nr_tables = st->nr_tables; >+ >+ early_memunmap(st, sizeof(*st)); >+ >+ tbl = early_memremap_ro(tables, sizeof(*tbl) * nr_tables); >+ if (!tbl) { >+ pr_err("Cannot remap EFI config table array\n"); >+ return 0; >+ } >+ >+ for (int i = 0; i < nr_tables; i++) { >+ if (!efi_guidcmp(tbl[i].guid, LINUX_EFI_BOOT_MEMMAP_GUID)) { >+ memmap = (unsigned long)tbl[i].table; >+ break; >+ } >+ } >+ early_memunmap(tbl, sizeof(*tbl) * nr_tables); >+ } >+ > bm = early_memremap_ro(memmap, sizeof(*bm)); > if (!bm) { > pr_err("Cannot remap EFI boot memory map\n"); >-- >2.47.3 > > Reviewed-by: Richard Lyu <[email protected]>