void __init efi_runtime_update_mappings(void) { efi_memory_desc_t *md; if (efi_enabled(EFI_OLD_MEMMAP)) { if (__supported_pte_mask & _PAGE_NX) runtime_code_page_mkexec(); return; } /* * Use the EFI Memory Attribute Table for mapping permissions if it * exists, since it is intended to supersede EFI_PROPERTIES_TABLE. */ if (efi_enabled(EFI_MEM_ATTR)) { efi_memattr_apply_permissions(NULL, efi_update_mem_attr); return; } /* * EFI_MEMORY_ATTRIBUTES_TABLE is intended to replace * EFI_PROPERTIES_TABLE. So, use EFI_PROPERTIES_TABLE to update * permissions only if EFI_MEMORY_ATTRIBUTES_TABLE is not * published by the firmware. Even if we find a buggy implementation of * EFI_MEMORY_ATTRIBUTES_TABLE, don't fall back to * EFI_PROPERTIES_TABLE, because of the same reason. */ if (!efi_enabled(EFI_NX_PE_DATA)) return; for_each_efi_memory_desc(md) { unsigned long pf = 0; if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (!(md->attribute & EFI_MEMORY_WB)) pf |= _PAGE_PCD; if ((md->attribute & EFI_MEMORY_XP) || (md->type == EFI_RUNTIME_SERVICES_DATA)) pf |= _PAGE_NX; if (!(md->attribute & EFI_MEMORY_RO) && (md->type != EFI_RUNTIME_SERVICES_CODE)) pf |= _PAGE_RW; if (sev_active()) pf |= _PAGE_ENC; efi_update_mappings(md, pf); } }
static bool __init efi_virtmap_init(void) { efi_memory_desc_t *md; bool systab_found; efi_mm.pgd = pgd_alloc(&efi_mm); init_new_context(NULL, &efi_mm); systab_found = false; for_each_efi_memory_desc(md) { phys_addr_t phys = md->phys_addr; int ret; if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (md->virt_addr == 0) return false; ret = efi_create_mapping(&efi_mm, md); if (!ret) { pr_info(" EFI remap %pa => %p\n", &phys, (void *)(unsigned long)md->virt_addr); } else { pr_warn(" EFI remap %pa: failed to create mapping (%d)\n", &phys, ret); return false; } /* * If this entry covers the address of the UEFI system table, * calculate and record its virtual address. */ if (efi_system_table >= phys && efi_system_table < phys + (md->num_pages * EFI_PAGE_SIZE)) { efi.systab = (void *)(unsigned long)(efi_system_table - phys + md->virt_addr); systab_found = true; } } if (!systab_found) { pr_err("No virtual mapping found for the UEFI System Table\n"); return false; } if (efi_memattr_apply_permissions(&efi_mm, efi_set_mapping_permissions)) return false; return true; }