return entry;
 }
 
+static bool should_map_region(efi_memory_desc_t *md)
+{
+       /*
+        * Runtime regions always require runtime mappings (obviously).
+        */
+       if (md->attribute & EFI_MEMORY_RUNTIME)
+               return true;
+
+       /*
+        * 32-bit EFI doesn't suffer from the bug that requires us to
+        * reserve boot services regions, and mixed mode support
+        * doesn't exist for 32-bit kernels.
+        */
+       if (IS_ENABLED(CONFIG_X86_32))
+               return false;
+
+       /*
+        * Map all of RAM so that we can access arguments in the 1:1
+        * mapping when making EFI runtime calls.
+        */
+       if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_is_native()) {
+               if (md->type == EFI_CONVENTIONAL_MEMORY ||
+                   md->type == EFI_LOADER_DATA ||
+                   md->type == EFI_LOADER_CODE)
+                       return true;
+       }
+
+       /*
+        * Map boot services regions as a workaround for buggy
+        * firmware that accesses them even when they shouldn't.
+        *
+        * See efi_{reserve,free}_boot_services().
+        */
+       if (md->type == EFI_BOOT_SERVICES_CODE ||
+           md->type == EFI_BOOT_SERVICES_DATA)
+               return true;
+
+       return false;
+}
+
 /*
  * Map the efi memory ranges of the runtime services and update new_mmap with
  * virtual addresses.
        p = NULL;
        while ((p = efi_map_next_entry(p))) {
                md = p;
-               if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
-#ifdef CONFIG_X86_64
-                       if (md->type != EFI_BOOT_SERVICES_CODE &&
-                           md->type != EFI_BOOT_SERVICES_DATA)
-#endif
-                               continue;
-               }
+
+               if (!should_map_region(md))
+                       continue;
 
                efi_map_region(md);
                get_systab_virt_addr(md);
 
 int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
 {
        unsigned long pfn, text;
-       efi_memory_desc_t *md;
        struct page *page;
        unsigned npages;
        pgd_t *pgd;
        if (!IS_ENABLED(CONFIG_EFI_MIXED))
                return 0;
 
-       /*
-        * Map all of RAM so that we can access arguments in the 1:1
-        * mapping when making EFI runtime calls.
-        */
-       for_each_efi_memory_desc(md) {
-               if (md->type != EFI_CONVENTIONAL_MEMORY &&
-                   md->type != EFI_LOADER_DATA &&
-                   md->type != EFI_LOADER_CODE)
-                       continue;
-
-               pfn = md->phys_addr >> PAGE_SHIFT;
-               npages = md->num_pages;
-
-               if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, _PAGE_RW)) {
-                       pr_err("Failed to map 1:1 memory\n");
-                       return 1;
-               }
-       }
-
        page = alloc_page(GFP_KERNEL|__GFP_DMA32);
        if (!page)
                panic("Unable to allocate EFI runtime stack < 4GB\n");