Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'core-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull EFI update from Ingo Molnar:
"This tree includes various fixes, cleanups, a new efi=debug boot
option and EFI boot stub memory allocation optimizations"

* 'core-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
efi/libstub: Retrieve FDT size when loaded from UEFI config table
efi: Clean up the efi_call_phys_[prolog|epilog]() save/restore interaction
efi: Disable interrupts around EFI calls, not in the epilog/prolog calls
x86/efi: Add a "debug" option to the efi= cmdline
firmware: dmi_scan: Use direct access to static vars
firmware: dmi_scan: Use full dmi version for SMBIOS3

+79 -53
+2 -1
Documentation/kernel-parameters.txt
··· 1036 1036 Format: {"off" | "on" | "skip[mbr]"} 1037 1037 1038 1038 efi= [EFI] 1039 - Format: { "old_map", "nochunk", "noruntime" } 1039 + Format: { "old_map", "nochunk", "noruntime", "debug" } 1040 1040 old_map [X86-64]: switch to the old ioremap-based EFI 1041 1041 runtime services mapping. 32-bit still uses this one by 1042 1042 default. ··· 1044 1044 boot stub, as chunking can cause problems with some 1045 1045 firmware implementations. 1046 1046 noruntime : disable EFI runtime services support 1047 + debug: enable misc debug output 1047 1048 1048 1049 efi_no_storage_paranoia [EFI; X86] 1049 1050 Using this parameter you can use more than 50% of
+4 -2
arch/x86/include/asm/efi.h
··· 2 2 #define _ASM_X86_EFI_H 3 3 4 4 #include <asm/i387.h> 5 + #include <asm/pgtable.h> 6 + 5 7 /* 6 8 * We map the EFI regions needed for runtime services non-contiguously, 7 9 * with preserved alignment on virtual addresses starting from -4G down ··· 91 89 extern struct efi_scratch efi_scratch; 92 90 extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable); 93 91 extern int __init efi_memblock_x86_reserve_range(void); 94 - extern void __init efi_call_phys_prolog(void); 95 - extern void __init efi_call_phys_epilog(void); 92 + extern pgd_t * __init efi_call_phys_prolog(void); 93 + extern void __init efi_call_phys_epilog(pgd_t *save_pgd); 96 94 extern void __init efi_unmap_memmap(void); 97 95 extern void __init efi_memory_uc(u64 addr, unsigned long size); 98 96 extern void __init efi_map_region(efi_memory_desc_t *md);
+14 -3
arch/x86/platform/efi/efi.c
··· 85 85 efi_memory_desc_t *virtual_map) 86 86 { 87 87 efi_status_t status; 88 + unsigned long flags; 89 + pgd_t *save_pgd; 88 90 89 - efi_call_phys_prolog(); 91 + save_pgd = efi_call_phys_prolog(); 92 + 93 + /* Disable interrupts around EFI calls: */ 94 + local_irq_save(flags); 90 95 status = efi_call_phys(efi_phys.set_virtual_address_map, 91 96 memory_map_size, descriptor_size, 92 97 descriptor_version, virtual_map); 93 - efi_call_phys_epilog(); 98 + local_irq_restore(flags); 99 + 100 + efi_call_phys_epilog(save_pgd); 101 + 94 102 return status; 95 103 } 96 104 ··· 499 491 if (efi_memmap_init()) 500 492 return; 501 493 502 - print_efi_memmap(); 494 + if (efi_enabled(EFI_DBG)) 495 + print_efi_memmap(); 503 496 } 504 497 505 498 void __init efi_late_init(void) ··· 948 939 { 949 940 if (parse_option_str(str, "old_map")) 950 941 set_bit(EFI_OLD_MEMMAP, &efi.flags); 942 + if (parse_option_str(str, "debug")) 943 + set_bit(EFI_DBG, &efi.flags); 951 944 952 945 return 0; 953 946 }
+11 -11
arch/x86/platform/efi/efi_32.c
··· 33 33 34 34 /* 35 35 * To make EFI call EFI runtime service in physical addressing mode we need 36 - * prolog/epilog before/after the invocation to disable interrupt, to 37 - * claim EFI runtime service handler exclusively and to duplicate a memory in 38 - * low memory space say 0 - 3G. 36 + * prolog/epilog before/after the invocation to claim the EFI runtime service 37 + * handler exclusively and to duplicate a memory mapping in low memory space, 38 + * say 0 - 3G. 39 39 */ 40 - static unsigned long efi_rt_eflags; 41 40 42 41 void efi_sync_low_kernel_mappings(void) {} 43 42 void __init efi_dump_pagetable(void) {} ··· 56 57 void __init efi_map_region_fixed(efi_memory_desc_t *md) {} 57 58 void __init parse_efi_setup(u64 phys_addr, u32 data_len) {} 58 59 59 - void __init efi_call_phys_prolog(void) 60 + pgd_t * __init efi_call_phys_prolog(void) 60 61 { 61 62 struct desc_ptr gdt_descr; 63 + pgd_t *save_pgd; 62 64 63 - local_irq_save(efi_rt_eflags); 64 - 65 + /* Current pgd is swapper_pg_dir, we'll restore it later: */ 66 + save_pgd = swapper_pg_dir; 65 67 load_cr3(initial_page_table); 66 68 __flush_tlb_all(); 67 69 68 70 gdt_descr.address = __pa(get_cpu_gdt_table(0)); 69 71 gdt_descr.size = GDT_SIZE - 1; 70 72 load_gdt(&gdt_descr); 73 + 74 + return save_pgd; 71 75 } 72 76 73 - void __init efi_call_phys_epilog(void) 77 + void __init efi_call_phys_epilog(pgd_t *save_pgd) 74 78 { 75 79 struct desc_ptr gdt_descr; 76 80 ··· 81 79 gdt_descr.size = GDT_SIZE - 1; 82 80 load_gdt(&gdt_descr); 83 81 84 - load_cr3(swapper_pg_dir); 82 + load_cr3(save_pgd); 85 83 __flush_tlb_all(); 86 - 87 - local_irq_restore(efi_rt_eflags); 88 84 } 89 85 90 86 void __init efi_runtime_mkexec(void)
+16 -13
arch/x86/platform/efi/efi_64.c
··· 41 41 #include <asm/realmode.h> 42 42 #include <asm/time.h> 43 43 44 - static pgd_t *save_pgd __initdata; 45 - static unsigned long efi_flags __initdata; 46 - 47 44 /* 48 45 * We allocate runtime services regions bottom-up, starting from -4G, i.e. 49 46 * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G. ··· 75 78 } 76 79 } 77 80 78 - void __init efi_call_phys_prolog(void) 81 + pgd_t * __init efi_call_phys_prolog(void) 79 82 { 80 83 unsigned long vaddress; 84 + pgd_t *save_pgd; 85 + 81 86 int pgd; 82 87 int n_pgds; 83 88 84 89 if (!efi_enabled(EFI_OLD_MEMMAP)) 85 - return; 90 + return NULL; 86 91 87 92 early_code_mapping_set_exec(1); 88 - local_irq_save(efi_flags); 89 93 90 94 n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE); 91 95 save_pgd = kmalloc(n_pgds * sizeof(pgd_t), GFP_KERNEL); ··· 97 99 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress)); 98 100 } 99 101 __flush_tlb_all(); 102 + 103 + return save_pgd; 100 104 } 101 105 102 - void __init efi_call_phys_epilog(void) 106 + void __init efi_call_phys_epilog(pgd_t *save_pgd) 103 107 { 104 108 /* 105 109 * After the lock is released, the original page table is restored. 106 110 */ 107 - int pgd; 108 - int n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE); 111 + int pgd_idx; 112 + int nr_pgds; 109 113 110 - if (!efi_enabled(EFI_OLD_MEMMAP)) 114 + if (!save_pgd) 111 115 return; 112 116 113 - for (pgd = 0; pgd < n_pgds; pgd++) 114 - set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]); 117 + nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE); 118 + 119 + for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++) 120 + set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]); 121 + 115 122 kfree(save_pgd); 123 + 116 124 __flush_tlb_all(); 117 - local_irq_restore(efi_flags); 118 125 early_code_mapping_set_exec(0); 119 126 } 120 127
+21 -17
drivers/firmware/dmi_scan.c
··· 17 17 */ 18 18 static const char dmi_empty_string[] = " "; 19 19 20 - static u16 __initdata dmi_ver; 20 + static u32 dmi_ver __initdata; 21 + static u32 dmi_len; 22 + static u16 dmi_num; 21 23 /* 22 24 * Catch too early calls to dmi_check_system(): 23 25 */ ··· 80 78 * We have to be cautious here. We have seen BIOSes with DMI pointers 81 79 * pointing to completely the wrong place for example 82 80 */ 83 - static void dmi_table(u8 *buf, u32 len, int num, 81 + static void dmi_table(u8 *buf, 84 82 void (*decode)(const struct dmi_header *, void *), 85 83 void *private_data) 86 84 { ··· 93 91 * off the end of the table (should never happen but sometimes does 94 92 * on bogus implementations.) 95 93 */ 96 - while ((!num || i < num) && 97 - (data - buf + sizeof(struct dmi_header)) <= len) { 94 + while ((!dmi_num || i < dmi_num) && 95 + (data - buf + sizeof(struct dmi_header)) <= dmi_len) { 98 96 const struct dmi_header *dm = (const struct dmi_header *)data; 99 97 100 98 /* ··· 103 101 * table in dmi_decode or dmi_string 104 102 */ 105 103 data += dm->length; 106 - while ((data - buf < len - 1) && (data[0] || data[1])) 104 + while ((data - buf < dmi_len - 1) && (data[0] || data[1])) 107 105 data++; 108 - if (data - buf < len - 1) 106 + if (data - buf < dmi_len - 1) 109 107 decode(dm, private_data); 110 108 111 109 /* ··· 120 118 } 121 119 122 120 static phys_addr_t dmi_base; 123 - static u32 dmi_len; 124 - static u16 dmi_num; 125 121 126 122 static int __init dmi_walk_early(void (*decode)(const struct dmi_header *, 127 123 void *)) ··· 130 130 if (buf == NULL) 131 131 return -1; 132 132 133 - dmi_table(buf, dmi_len, dmi_num, decode, NULL); 133 + dmi_table(buf, decode, NULL); 134 134 135 135 add_device_randomness(buf, dmi_len); 136 136 ··· 201 201 * the UUID are supposed to be little-endian encoded. The specification 202 202 * says that this is the defacto standard. 203 203 */ 204 - if (dmi_ver >= 0x0206) 204 + if (dmi_ver >= 0x020600) 205 205 sprintf(s, "%pUL", d); 206 206 else 207 207 sprintf(s, "%pUB", d); ··· 473 473 */ 474 474 static int __init dmi_present(const u8 *buf) 475 475 { 476 - int smbios_ver; 476 + u32 smbios_ver; 477 477 478 478 if (memcmp(buf, "_SM_", 4) == 0 && 479 479 buf[5] < 32 && dmi_checksum(buf, buf[5])) { ··· 506 506 if (dmi_walk_early(dmi_decode) == 0) { 507 507 if (smbios_ver) { 508 508 dmi_ver = smbios_ver; 509 - pr_info("SMBIOS %d.%d present.\n", 510 - dmi_ver >> 8, dmi_ver & 0xFF); 509 + pr_info("SMBIOS %d.%d%s present.\n", 510 + dmi_ver >> 8, dmi_ver & 0xFF, 511 + (dmi_ver < 0x0300) ? "" : ".x"); 511 512 } else { 512 513 dmi_ver = (buf[14] & 0xF0) << 4 | 513 514 (buf[14] & 0x0F); 514 515 pr_info("Legacy DMI %d.%d present.\n", 515 516 dmi_ver >> 8, dmi_ver & 0xFF); 516 517 } 518 + dmi_ver <<= 8; 517 519 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 518 520 printk(KERN_DEBUG "DMI: %s\n", dmi_ids_string); 519 521 return 0; ··· 533 531 { 534 532 if (memcmp(buf, "_SM3_", 5) == 0 && 535 533 buf[6] < 32 && dmi_checksum(buf, buf[6])) { 536 - dmi_ver = get_unaligned_be16(buf + 7); 534 + dmi_ver = get_unaligned_be32(buf + 6); 535 + dmi_ver &= 0xFFFFFF; 537 536 dmi_num = 0; /* No longer specified */ 538 537 dmi_len = get_unaligned_le32(buf + 12); 539 538 dmi_base = get_unaligned_le64(buf + 16); 540 539 541 540 if (dmi_walk_early(dmi_decode) == 0) { 542 - pr_info("SMBIOS %d.%d present.\n", 543 - dmi_ver >> 8, dmi_ver & 0xFF); 541 + pr_info("SMBIOS %d.%d.%d present.\n", 542 + dmi_ver >> 16, (dmi_ver >> 8) & 0xFF, 543 + dmi_ver & 0xFF); 544 544 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 545 545 pr_debug("DMI: %s\n", dmi_ids_string); 546 546 return 0; ··· 897 893 if (buf == NULL) 898 894 return -1; 899 895 900 - dmi_table(buf, dmi_len, dmi_num, decode, private_data); 896 + dmi_table(buf, decode, private_data); 901 897 902 898 dmi_unmap(buf); 903 899 return 0;
+3 -4
drivers/firmware/efi/libstub/arm-stub.c
··· 175 175 unsigned long initrd_addr; 176 176 u64 initrd_size = 0; 177 177 unsigned long fdt_addr = 0; /* Original DTB */ 178 - u64 fdt_size = 0; /* We don't get size from configuration table */ 178 + unsigned long fdt_size = 0; 179 179 char *cmdline_ptr = NULL; 180 180 int cmdline_size = 0; 181 181 unsigned long new_fdt_addr; ··· 239 239 } else { 240 240 status = handle_cmdline_files(sys_table, image, cmdline_ptr, 241 241 "dtb=", 242 - ~0UL, (unsigned long *)&fdt_addr, 243 - (unsigned long *)&fdt_size); 242 + ~0UL, &fdt_addr, &fdt_size); 244 243 245 244 if (status != EFI_SUCCESS) { 246 245 pr_efi_err(sys_table, "Failed to load device tree!\n"); ··· 251 252 pr_efi(sys_table, "Using DTB from command line\n"); 252 253 } else { 253 254 /* Look for a device tree configuration table entry. */ 254 - fdt_addr = (uintptr_t)get_fdt(sys_table); 255 + fdt_addr = (uintptr_t)get_fdt(sys_table, &fdt_size); 255 256 if (fdt_addr) 256 257 pr_efi(sys_table, "Using DTB from configuration table\n"); 257 258 }
+1 -1
drivers/firmware/efi/libstub/efistub.h
··· 41 41 unsigned long fdt_addr, 42 42 unsigned long fdt_size); 43 43 44 - void *get_fdt(efi_system_table_t *sys_table); 44 + void *get_fdt(efi_system_table_t *sys_table, unsigned long *fdt_size); 45 45 46 46 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size, 47 47 unsigned long desc_size, efi_memory_desc_t *runtime_map,
+6 -1
drivers/firmware/efi/libstub/fdt.c
··· 323 323 return EFI_LOAD_ERROR; 324 324 } 325 325 326 - void *get_fdt(efi_system_table_t *sys_table) 326 + void *get_fdt(efi_system_table_t *sys_table, unsigned long *fdt_size) 327 327 { 328 328 efi_guid_t fdt_guid = DEVICE_TREE_GUID; 329 329 efi_config_table_t *tables; ··· 336 336 for (i = 0; i < sys_table->nr_tables; i++) 337 337 if (efi_guidcmp(tables[i].guid, fdt_guid) == 0) { 338 338 fdt = (void *) tables[i].table; 339 + if (fdt_check_header(fdt) != 0) { 340 + pr_efi_err(sys_table, "Invalid header detected on UEFI supplied FDT, ignoring ...\n"); 341 + return NULL; 342 + } 343 + *fdt_size = fdt_totalsize(fdt); 339 344 break; 340 345 } 341 346
+1
include/linux/efi.h
··· 942 942 #define EFI_64BIT 5 /* Is the firmware 64-bit? */ 943 943 #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */ 944 944 #define EFI_ARCH_1 7 /* First arch-specific bit */ 945 + #define EFI_DBG 8 /* Print additional debug info at runtime */ 945 946 946 947 #ifdef CONFIG_EFI 947 948 /*