Skip to content

Commit 8c81f48

Browse files
committed
Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 EFI updates from Peter Anvin: "This patchset falls under the "maintainers that grovel" clause in the v3.18-rc1 announcement. We had intended to push it late in the merge window since we got it into the -tip tree relatively late. Many of these are relatively simple things, but there are a couple of key bits, especially Ard's and Matt's patches" * 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (24 commits) rtc: Disable EFI rtc for x86 efi: rtc-efi: Export platform:rtc-efi as module alias efi: Delete the in_nmi() conditional runtime locking efi: Provide a non-blocking SetVariable() operation x86/efi: Adding efi_printks on memory allocationa and pci.reads x86/efi: Mark initialization code as such x86/efi: Update comment regarding required phys mapped EFI services x86/efi: Unexport add_efi_memmap variable x86/efi: Remove unused efi_call* macros efi: Resolve some shadow warnings arm64: efi: Format EFI memory type & attrs with efi_md_typeattr_format() ia64: efi: Format EFI memory type & attrs with efi_md_typeattr_format() x86: efi: Format EFI memory type & attrs with efi_md_typeattr_format() efi: Introduce efi_md_typeattr_format() efi: Add macro for EFI_MEMORY_UCE memory attribute x86/efi: Clear EFI_RUNTIME_SERVICES if failing to enter virtual mode arm64/efi: Do not enter virtual mode if booting with efi=noruntime or noefi arm64/efi: uefi_init error handling fix efi: Add kernel param efi=noruntime lib: Add a generic cmdline parse function parse_option_str ...
2 parents 5de551e + 75b1285 commit 8c81f48

20 files changed

Lines changed: 528 additions & 123 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,14 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
10151015
Format: {"off" | "on" | "skip[mbr]"}
10161016

10171017
efi= [EFI]
1018-
Format: { "old_map" }
1018+
Format: { "old_map", "nochunk", "noruntime" }
10191019
old_map [X86-64]: switch to the old ioremap-based EFI
10201020
runtime services mapping. 32-bit still uses this one by
10211021
default.
1022+
nochunk: disable reading files in "chunks" in the EFI
1023+
boot stub, as chunking can cause problems with some
1024+
firmware implementations.
1025+
noruntime : disable EFI runtime services support
10221026

10231027
efi_no_storage_paranoia [EFI; X86]
10241028
Using this parameter you can use more than 50% of
@@ -2232,7 +2236,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
22322236

22332237
nodsp [SH] Disable hardware DSP at boot time.
22342238

2235-
noefi [X86] Disable EFI runtime services support.
2239+
noefi Disable EFI runtime services support.
22362240

22372241
noexec [IA-64]
22382242

‎arch/arm64/kernel/efi.c‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static int __init uefi_init(void)
8989
*/
9090
if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
9191
pr_err("System table signature incorrect\n");
92-
return -EINVAL;
92+
retval = -EINVAL;
93+
goto out;
9394
}
9495
if ((efi.systab->hdr.revision >> 16) < 2)
9596
pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n",
@@ -103,6 +104,7 @@ static int __init uefi_init(void)
103104
for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i)
104105
vendor[i] = c16[i];
105106
vendor[i] = '\0';
107+
early_memunmap(c16, sizeof(vendor));
106108
}
107109

108110
pr_info("EFI v%u.%.02u by %s\n",
@@ -113,29 +115,11 @@ static int __init uefi_init(void)
113115
if (retval == 0)
114116
set_bit(EFI_CONFIG_TABLES, &efi.flags);
115117

116-
early_memunmap(c16, sizeof(vendor));
118+
out:
117119
early_memunmap(efi.systab, sizeof(efi_system_table_t));
118-
119120
return retval;
120121
}
121122

122-
static __initdata char memory_type_name[][32] = {
123-
{"Reserved"},
124-
{"Loader Code"},
125-
{"Loader Data"},
126-
{"Boot Code"},
127-
{"Boot Data"},
128-
{"Runtime Code"},
129-
{"Runtime Data"},
130-
{"Conventional Memory"},
131-
{"Unusable Memory"},
132-
{"ACPI Reclaim Memory"},
133-
{"ACPI Memory NVS"},
134-
{"Memory Mapped I/O"},
135-
{"MMIO Port Space"},
136-
{"PAL Code"},
137-
};
138-
139123
/*
140124
* Return true for RAM regions we want to permanently reserve.
141125
*/
@@ -166,10 +150,13 @@ static __init void reserve_regions(void)
166150
paddr = md->phys_addr;
167151
npages = md->num_pages;
168152

169-
if (uefi_debug)
170-
pr_info(" 0x%012llx-0x%012llx [%s]",
153+
if (uefi_debug) {
154+
char buf[64];
155+
156+
pr_info(" 0x%012llx-0x%012llx %s",
171157
paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
172-
memory_type_name[md->type]);
158+
efi_md_typeattr_format(buf, sizeof(buf), md));
159+
}
173160

174161
memrange_efi_to_native(&paddr, &npages);
175162
size = npages << PAGE_SHIFT;
@@ -393,11 +380,16 @@ static int __init arm64_enter_virtual_mode(void)
393380
return -1;
394381
}
395382

396-
pr_info("Remapping and enabling EFI services.\n");
397-
398-
/* replace early memmap mapping with permanent mapping */
399383
mapsize = memmap.map_end - memmap.map;
400384
early_memunmap(memmap.map, mapsize);
385+
386+
if (efi_runtime_disabled()) {
387+
pr_info("EFI runtime services will be disabled.\n");
388+
return -1;
389+
}
390+
391+
pr_info("Remapping and enabling EFI services.\n");
392+
/* replace early memmap mapping with permanent mapping */
401393
memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,
402394
mapsize);
403395
memmap.map_end = memmap.map + mapsize;

‎arch/ia64/kernel/efi.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ efi_init (void)
568568
{
569569
const char *unit;
570570
unsigned long size;
571+
char buf[64];
571572

572573
md = p;
573574
size = md->num_pages << EFI_PAGE_SHIFT;
@@ -586,9 +587,10 @@ efi_init (void)
586587
unit = "KB";
587588
}
588589

589-
printk("mem%02d: type=%2u, attr=0x%016lx, "
590+
printk("mem%02d: %s "
590591
"range=[0x%016lx-0x%016lx) (%4lu%s)\n",
591-
i, md->type, md->attribute, md->phys_addr,
592+
i, efi_md_typeattr_format(buf, sizeof(buf), md),
593+
md->phys_addr,
592594
md->phys_addr + efi_md_size(md), size, unit);
593595
}
594596
}

‎arch/x86/boot/compressed/eboot.c‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,10 @@ __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
330330
size = pci->romsize + sizeof(*rom);
331331

332332
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
333-
if (status != EFI_SUCCESS)
333+
if (status != EFI_SUCCESS) {
334+
efi_printk(sys_table, "Failed to alloc mem for rom\n");
334335
return status;
336+
}
335337

336338
memset(rom, 0, sizeof(*rom));
337339

@@ -344,14 +346,18 @@ __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
344346
status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
345347
PCI_VENDOR_ID, 1, &(rom->vendor));
346348

347-
if (status != EFI_SUCCESS)
349+
if (status != EFI_SUCCESS) {
350+
efi_printk(sys_table, "Failed to read rom->vendor\n");
348351
goto free_struct;
352+
}
349353

350354
status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
351355
PCI_DEVICE_ID, 1, &(rom->devid));
352356

353-
if (status != EFI_SUCCESS)
357+
if (status != EFI_SUCCESS) {
358+
efi_printk(sys_table, "Failed to read rom->devid\n");
354359
goto free_struct;
360+
}
355361

356362
status = efi_early->call(pci->get_location, pci, &(rom->segment),
357363
&(rom->bus), &(rom->device), &(rom->function));
@@ -432,8 +438,10 @@ __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
432438
size = pci->romsize + sizeof(*rom);
433439

434440
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
435-
if (status != EFI_SUCCESS)
441+
if (status != EFI_SUCCESS) {
442+
efi_printk(sys_table, "Failed to alloc mem for rom\n");
436443
return status;
444+
}
437445

438446
rom->data.type = SETUP_PCI;
439447
rom->data.len = size - sizeof(struct setup_data);
@@ -444,14 +452,18 @@ __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
444452
status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
445453
PCI_VENDOR_ID, 1, &(rom->vendor));
446454

447-
if (status != EFI_SUCCESS)
455+
if (status != EFI_SUCCESS) {
456+
efi_printk(sys_table, "Failed to read rom->vendor\n");
448457
goto free_struct;
458+
}
449459

450460
status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
451461
PCI_DEVICE_ID, 1, &(rom->devid));
452462

453-
if (status != EFI_SUCCESS)
463+
if (status != EFI_SUCCESS) {
464+
efi_printk(sys_table, "Failed to read rom->devid\n");
454465
goto free_struct;
466+
}
455467

456468
status = efi_early->call(pci->get_location, pci, &(rom->segment),
457469
&(rom->bus), &(rom->device), &(rom->function));
@@ -538,8 +550,10 @@ static void setup_efi_pci(struct boot_params *params)
538550
EFI_LOADER_DATA,
539551
size, (void **)&pci_handle);
540552

541-
if (status != EFI_SUCCESS)
553+
if (status != EFI_SUCCESS) {
554+
efi_printk(sys_table, "Failed to alloc mem for pci_handle\n");
542555
return;
556+
}
543557

544558
status = efi_call_early(locate_handle,
545559
EFI_LOCATE_BY_PROTOCOL, &pci_proto,
@@ -1105,6 +1119,10 @@ struct boot_params *make_boot_params(struct efi_config *c)
11051119

11061120
memset(sdt, 0, sizeof(*sdt));
11071121

1122+
status = efi_parse_options(cmdline_ptr);
1123+
if (status != EFI_SUCCESS)
1124+
goto fail2;
1125+
11081126
status = handle_cmdline_files(sys_table, image,
11091127
(char *)(unsigned long)hdr->cmd_line_ptr,
11101128
"initrd=", hdr->initrd_addr_max,

‎arch/x86/include/asm/efi.h‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,23 @@ extern u64 asmlinkage efi_call(void *fp, ...);
8181
*/
8282
#define __efi_call_virt(f, args...) efi_call_virt(f, args)
8383

84-
extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
85-
u32 type, u64 attribute);
84+
extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
85+
u32 type, u64 attribute);
8686

8787
#endif /* CONFIG_X86_32 */
8888

89-
extern int add_efi_memmap;
9089
extern struct efi_scratch efi_scratch;
91-
extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
92-
extern int efi_memblock_x86_reserve_range(void);
93-
extern void efi_call_phys_prelog(void);
94-
extern void efi_call_phys_epilog(void);
95-
extern void efi_unmap_memmap(void);
96-
extern void efi_memory_uc(u64 addr, unsigned long size);
90+
extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
91+
extern int __init efi_memblock_x86_reserve_range(void);
92+
extern void __init efi_call_phys_prolog(void);
93+
extern void __init efi_call_phys_epilog(void);
94+
extern void __init efi_unmap_memmap(void);
95+
extern void __init efi_memory_uc(u64 addr, unsigned long size);
9796
extern void __init efi_map_region(efi_memory_desc_t *md);
9897
extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
9998
extern void efi_sync_low_kernel_mappings(void);
100-
extern int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
101-
extern void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
99+
extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
100+
extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
102101
extern void __init old_map_region(efi_memory_desc_t *md);
103102
extern void __init runtime_code_page_mkexec(void);
104103
extern void __init efi_runtime_mkexec(void);
@@ -162,16 +161,6 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
162161
extern bool efi_reboot_required(void);
163162

164163
#else
165-
/*
166-
* IF EFI is not configured, have the EFI calls return -ENOSYS.
167-
*/
168-
#define efi_call0(_f) (-ENOSYS)
169-
#define efi_call1(_f, _a1) (-ENOSYS)
170-
#define efi_call2(_f, _a1, _a2) (-ENOSYS)
171-
#define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
172-
#define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
173-
#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
174-
#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
175164
static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
176165
static inline bool efi_reboot_required(void)
177166
{

‎arch/x86/platform/efi/efi-bgrt.c‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,59 @@ void __init efi_bgrt_init(void)
4040
if (ACPI_FAILURE(status))
4141
return;
4242

43-
if (bgrt_tab->header.length < sizeof(*bgrt_tab))
43+
if (bgrt_tab->header.length < sizeof(*bgrt_tab)) {
44+
pr_err("Ignoring BGRT: invalid length %u (expected %zu)\n",
45+
bgrt_tab->header.length, sizeof(*bgrt_tab));
4446
return;
45-
if (bgrt_tab->version != 1 || bgrt_tab->status != 1)
47+
}
48+
if (bgrt_tab->version != 1) {
49+
pr_err("Ignoring BGRT: invalid version %u (expected 1)\n",
50+
bgrt_tab->version);
51+
return;
52+
}
53+
if (bgrt_tab->status != 1) {
54+
pr_err("Ignoring BGRT: invalid status %u (expected 1)\n",
55+
bgrt_tab->status);
56+
return;
57+
}
58+
if (bgrt_tab->image_type != 0) {
59+
pr_err("Ignoring BGRT: invalid image type %u (expected 0)\n",
60+
bgrt_tab->image_type);
4661
return;
47-
if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address)
62+
}
63+
if (!bgrt_tab->image_address) {
64+
pr_err("Ignoring BGRT: null image address\n");
4865
return;
66+
}
4967

5068
image = efi_lookup_mapped_addr(bgrt_tab->image_address);
5169
if (!image) {
5270
image = early_memremap(bgrt_tab->image_address,
5371
sizeof(bmp_header));
5472
ioremapped = true;
55-
if (!image)
73+
if (!image) {
74+
pr_err("Ignoring BGRT: failed to map image header memory\n");
5675
return;
76+
}
5777
}
5878

5979
memcpy_fromio(&bmp_header, image, sizeof(bmp_header));
6080
if (ioremapped)
6181
early_iounmap(image, sizeof(bmp_header));
6282
bgrt_image_size = bmp_header.size;
6383

64-
bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL);
65-
if (!bgrt_image)
84+
bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL | __GFP_NOWARN);
85+
if (!bgrt_image) {
86+
pr_err("Ignoring BGRT: failed to allocate memory for image (wanted %zu bytes)\n",
87+
bgrt_image_size);
6688
return;
89+
}
6790

6891
if (ioremapped) {
6992
image = early_memremap(bgrt_tab->image_address,
7093
bmp_header.size);
7194
if (!image) {
95+
pr_err("Ignoring BGRT: failed to map image memory\n");
7296
kfree(bgrt_image);
7397
bgrt_image = NULL;
7498
return;

0 commit comments

Comments
 (0)