]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
efi: make efi_mem_type() and efi_mem_attributes() work on Xen PV
authorMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Mon, 9 Mar 2026 12:17:22 +0000 (13:17 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 10 Mar 2026 20:56:27 +0000 (21:56 +0100)
Xen doesn't give direct access to the EFI memory map, but provides a
hypercall interface for it. efi_mem_desc_lookup() was already adjusted
in aca1d27ac38a "efi: xen: Implement memory descriptor lookup based on
hypercall" to (optionally) use it. Now make efi_mem_type() and
efi_mem_attributes() use common efi_mem_desc_lookup() too.
This also reduces code duplication a bit.
efi_mem_type() retains separate check for -ENOTSUPP error case (even
though no caller seems to rely on this currently).

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
[ardb: Drop erroneous 'const' qualifier]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/efi.c

index b2fb92a4bbd119ea2a8879f536bc36e946511775..288834a193d108071bf432f5392bddb383e2bb3d 100644 (file)
@@ -983,18 +983,12 @@ char * __init efi_md_typeattr_format(char *buf, size_t size,
  */
 u64 efi_mem_attributes(unsigned long phys_addr)
 {
-       efi_memory_desc_t *md;
+       efi_memory_desc_t md;
 
-       if (!efi_enabled(EFI_MEMMAP))
+       if (efi_mem_desc_lookup(phys_addr, &md))
                return 0;
 
-       for_each_efi_memory_desc(md) {
-               if ((md->phys_addr <= phys_addr) &&
-                   (phys_addr < (md->phys_addr +
-                   (md->num_pages << EFI_PAGE_SHIFT))))
-                       return md->attribute;
-       }
-       return 0;
+       return md.attribute;
 }
 
 /*
@@ -1007,18 +1001,15 @@ u64 efi_mem_attributes(unsigned long phys_addr)
  */
 int efi_mem_type(unsigned long phys_addr)
 {
-       const efi_memory_desc_t *md;
+       efi_memory_desc_t md;
 
-       if (!efi_enabled(EFI_MEMMAP))
+       if (!efi_enabled(EFI_MEMMAP) && !efi_enabled(EFI_PARAVIRT))
                return -ENOTSUPP;
 
-       for_each_efi_memory_desc(md) {
-               if ((md->phys_addr <= phys_addr) &&
-                   (phys_addr < (md->phys_addr +
-                                 (md->num_pages << EFI_PAGE_SHIFT))))
-                       return md->type;
-       }
-       return -EINVAL;
+       if (efi_mem_desc_lookup(phys_addr, &md))
+               return -EINVAL;
+
+       return md.type;
 }
 
 int efi_status_to_err(efi_status_t status)