Skip to content

Commit 162b246

Browse files
committed
Merge branch 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull EFI updates from Ingo Molnar: "The main changes in this cycle were: - Rework the EFI capsule loader to allow for workarounds for non-compliant firmware (Ard Biesheuvel) - Implement a capsule loader quirk for Quark X102x (Jan Kiszka) - Enable SMBIOS/DMI support for the ARM architecture (Ard Biesheuvel) - Add CONFIG_EFI_PGT_DUMP=y support for x86-32 and kexec (Sai Praneeth) - Fixes for EFI support for Xen dom0 guests running under x86-64 hosts (Daniel Kiper)" * 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/xen/efi: Initialize only the EFI struct members used by Xen efi: Process the MEMATTR table only if EFI_MEMMAP is enabled efi/arm: Enable DMI/SMBIOS x86/efi: Extend CONFIG_EFI_PGT_DUMP support to x86_32 and kexec as well efi/efi_test: Use memdup_user() helper efi/capsule: Add support for Quark security header efi/capsule-loader: Use page addresses rather than struct page pointers efi/capsule-loader: Redirect calls to efi_capsule_setup_info() via weak alias efi/capsule: Remove NULL test on kmap() efi/capsule-loader: Use a cached copy of the capsule header efi/capsule: Adjust return type of efi_capsule_setup_info() efi/capsule: Clean up pr_err/_info() messages efi/capsule: Remove pr_debug() on ENOMEM or EFAULT efi/capsule: Fix return code on failing kmap/vmap
2 parents 330e9e4 + 6c64447 commit 162b246

15 files changed

Lines changed: 295 additions & 136 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,23 @@ config EFI
20622062
is only useful for kernels that may run on systems that have
20632063
UEFI firmware.
20642064

2065+
config DMI
2066+
bool "Enable support for SMBIOS (DMI) tables"
2067+
depends on EFI
2068+
default y
2069+
help
2070+
This enables SMBIOS/DMI feature for systems.
2071+
2072+
This option is only useful on systems that have UEFI firmware.
2073+
However, even with this option, the resultant kernel should
2074+
continue to boot on existing non-UEFI platforms.
2075+
2076+
NOTE: This does *NOT* enable or encourage the use of DMI quirks,
2077+
i.e., the the practice of identifying the platform via DMI to
2078+
decide whether certain workarounds for buggy hardware and/or
2079+
firmware need to be enabled. This would require the DMI subsystem
2080+
to be enabled much earlier than we do on ARM, which is non-trivial.
2081+
20652082
endmenu
20662083

20672084
menu "CPU Power Management"

‎arch/arm/include/asm/dmi.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License version 2 as
4+
* published by the Free Software Foundation.
5+
*/
6+
7+
#ifndef __ASM_DMI_H
8+
#define __ASM_DMI_H
9+
10+
#include <linux/io.h>
11+
#include <linux/slab.h>
12+
13+
#define dmi_early_remap(x, l) memremap(x, l, MEMREMAP_WB)
14+
#define dmi_early_unmap(x, l) memunmap(x)
15+
#define dmi_remap(x, l) memremap(x, l, MEMREMAP_WB)
16+
#define dmi_unmap(x) memunmap(x)
17+
#define dmi_alloc(l) kzalloc(l, GFP_KERNEL)
18+
19+
#endif

‎arch/arm64/kernel/efi.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*
1212
*/
1313

14-
#include <linux/dmi.h>
1514
#include <linux/efi.h>
1615
#include <linux/init.h>
1716

@@ -117,20 +116,6 @@ int __init efi_set_mapping_permissions(struct mm_struct *mm,
117116
set_permissions, md);
118117
}
119118

120-
static int __init arm64_dmi_init(void)
121-
{
122-
/*
123-
* On arm64, DMI depends on UEFI, and dmi_scan_machine() needs to
124-
* be called early because dmi_id_init(), which is an arch_initcall
125-
* itself, depends on dmi_scan_machine() having been called already.
126-
*/
127-
dmi_scan_machine();
128-
if (dmi_available)
129-
dmi_set_dump_stack_arch_desc();
130-
return 0;
131-
}
132-
core_initcall(arm64_dmi_init);
133-
134119
/*
135120
* UpdateCapsule() depends on the system being shutdown via
136121
* ResetSystem().

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,6 @@ static void __init __efi_enter_virtual_mode(void)
10141014
* necessary relocation fixups for the new virtual addresses.
10151015
*/
10161016
efi_runtime_update_mappings();
1017-
efi_dump_pagetable();
10181017

10191018
/* clean DUMMY object */
10201019
efi_delete_dummy_variable();
@@ -1029,6 +1028,8 @@ void __init efi_enter_virtual_mode(void)
10291028
kexec_enter_virtual_mode();
10301029
else
10311030
__efi_enter_virtual_mode();
1031+
1032+
efi_dump_pagetable();
10321033
}
10331034

10341035
/*

‎arch/x86/platform/efi/efi_32.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ int __init efi_alloc_page_tables(void)
4444
}
4545

4646
void efi_sync_low_kernel_mappings(void) {}
47-
void __init efi_dump_pagetable(void) {}
47+
48+
void __init efi_dump_pagetable(void)
49+
{
50+
#ifdef CONFIG_EFI_PGT_DUMP
51+
ptdump_walk_pgd_level(NULL, swapper_pg_dir);
52+
#endif
53+
}
54+
4855
int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
4956
{
5057
return 0;

‎arch/x86/platform/efi/efi_64.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,10 @@ void __init efi_runtime_update_mappings(void)
589589
void __init efi_dump_pagetable(void)
590590
{
591591
#ifdef CONFIG_EFI_PGT_DUMP
592-
ptdump_walk_pgd_level(NULL, efi_pgd);
592+
if (efi_enabled(EFI_OLD_MEMMAP))
593+
ptdump_walk_pgd_level(NULL, swapper_pg_dir);
594+
else
595+
ptdump_walk_pgd_level(NULL, efi_pgd);
593596
#endif
594597
}
595598

‎arch/x86/platform/efi/quirks.c‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,66 @@
1515
#include <asm/e820/api.h>
1616
#include <asm/efi.h>
1717
#include <asm/uv/uv.h>
18+
#include <asm/cpu_device_id.h>
1819

1920
#define EFI_MIN_RESERVE 5120
2021

2122
#define EFI_DUMMY_GUID \
2223
EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9)
2324

25+
#define QUARK_CSH_SIGNATURE 0x5f435348 /* _CSH */
26+
#define QUARK_SECURITY_HEADER_SIZE 0x400
27+
28+
/*
29+
* Header prepended to the standard EFI capsule on Quark systems the are based
30+
* on Intel firmware BSP.
31+
* @csh_signature: Unique identifier to sanity check signed module
32+
* presence ("_CSH").
33+
* @version: Current version of CSH used. Should be one for Quark A0.
34+
* @modulesize: Size of the entire module including the module header
35+
* and payload.
36+
* @security_version_number_index: Index of SVN to use for validation of signed
37+
* module.
38+
* @security_version_number: Used to prevent against roll back of modules.
39+
* @rsvd_module_id: Currently unused for Clanton (Quark).
40+
* @rsvd_module_vendor: Vendor Identifier. For Intel products value is
41+
* 0x00008086.
42+
* @rsvd_date: BCD representation of build date as yyyymmdd, where
43+
* yyyy=4 digit year, mm=1-12, dd=1-31.
44+
* @headersize: Total length of the header including including any
45+
* padding optionally added by the signing tool.
46+
* @hash_algo: What Hash is used in the module signing.
47+
* @cryp_algo: What Crypto is used in the module signing.
48+
* @keysize: Total length of the key data including including any
49+
* padding optionally added by the signing tool.
50+
* @signaturesize: Total length of the signature including including any
51+
* padding optionally added by the signing tool.
52+
* @rsvd_next_header: 32-bit pointer to the next Secure Boot Module in the
53+
* chain, if there is a next header.
54+
* @rsvd: Reserved, padding structure to required size.
55+
*
56+
* See also QuartSecurityHeader_t in
57+
* Quark_EDKII_v1.2.1.1/QuarkPlatformPkg/Include/QuarkBootRom.h
58+
* from https://downloadcenter.intel.com/download/23197/Intel-Quark-SoC-X1000-Board-Support-Package-BSP
59+
*/
60+
struct quark_security_header {
61+
u32 csh_signature;
62+
u32 version;
63+
u32 modulesize;
64+
u32 security_version_number_index;
65+
u32 security_version_number;
66+
u32 rsvd_module_id;
67+
u32 rsvd_module_vendor;
68+
u32 rsvd_date;
69+
u32 headersize;
70+
u32 hash_algo;
71+
u32 cryp_algo;
72+
u32 keysize;
73+
u32 signaturesize;
74+
u32 rsvd_next_header;
75+
u32 rsvd[2];
76+
};
77+
2478
static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
2579

2680
static bool efi_no_storage_paranoia;
@@ -504,3 +558,86 @@ bool efi_poweroff_required(void)
504558
{
505559
return acpi_gbl_reduced_hardware || acpi_no_s5;
506560
}
561+
562+
#ifdef CONFIG_EFI_CAPSULE_QUIRK_QUARK_CSH
563+
564+
static int qrk_capsule_setup_info(struct capsule_info *cap_info, void **pkbuff,
565+
size_t hdr_bytes)
566+
{
567+
struct quark_security_header *csh = *pkbuff;
568+
569+
/* Only process data block that is larger than the security header */
570+
if (hdr_bytes < sizeof(struct quark_security_header))
571+
return 0;
572+
573+
if (csh->csh_signature != QUARK_CSH_SIGNATURE ||
574+
csh->headersize != QUARK_SECURITY_HEADER_SIZE)
575+
return 1;
576+
577+
/* Only process data block if EFI header is included */
578+
if (hdr_bytes < QUARK_SECURITY_HEADER_SIZE +
579+
sizeof(efi_capsule_header_t))
580+
return 0;
581+
582+
pr_debug("Quark security header detected\n");
583+
584+
if (csh->rsvd_next_header != 0) {
585+
pr_err("multiple Quark security headers not supported\n");
586+
return -EINVAL;
587+
}
588+
589+
*pkbuff += csh->headersize;
590+
cap_info->total_size = csh->headersize;
591+
592+
/*
593+
* Update the first page pointer to skip over the CSH header.
594+
*/
595+
cap_info->pages[0] += csh->headersize;
596+
597+
return 1;
598+
}
599+
600+
#define ICPU(family, model, quirk_handler) \
601+
{ X86_VENDOR_INTEL, family, model, X86_FEATURE_ANY, \
602+
(unsigned long)&quirk_handler }
603+
604+
static const struct x86_cpu_id efi_capsule_quirk_ids[] = {
605+
ICPU(5, 9, qrk_capsule_setup_info), /* Intel Quark X1000 */
606+
{ }
607+
};
608+
609+
int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff,
610+
size_t hdr_bytes)
611+
{
612+
int (*quirk_handler)(struct capsule_info *, void **, size_t);
613+
const struct x86_cpu_id *id;
614+
int ret;
615+
616+
if (hdr_bytes < sizeof(efi_capsule_header_t))
617+
return 0;
618+
619+
cap_info->total_size = 0;
620+
621+
id = x86_match_cpu(efi_capsule_quirk_ids);
622+
if (id) {
623+
/*
624+
* The quirk handler is supposed to return
625+
* - a value > 0 if the setup should continue, after advancing
626+
* kbuff as needed
627+
* - 0 if not enough hdr_bytes are available yet
628+
* - a negative error code otherwise
629+
*/
630+
quirk_handler = (typeof(quirk_handler))id->driver_data;
631+
ret = quirk_handler(cap_info, &kbuff, hdr_bytes);
632+
if (ret <= 0)
633+
return ret;
634+
}
635+
636+
memcpy(&cap_info->header, kbuff, sizeof(cap_info->header));
637+
638+
cap_info->total_size += cap_info->header.imagesize;
639+
640+
return __efi_capsule_setup_info(cap_info);
641+
}
642+
643+
#endif

‎arch/x86/xen/efi.c‎

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,6 @@ static efi_system_table_t efi_systab_xen __initdata = {
5454
.tables = EFI_INVALID_TABLE_ADDR /* Initialized later. */
5555
};
5656

57-
static const struct efi efi_xen __initconst = {
58-
.systab = NULL, /* Initialized later. */
59-
.runtime_version = 0, /* Initialized later. */
60-
.mps = EFI_INVALID_TABLE_ADDR,
61-
.acpi = EFI_INVALID_TABLE_ADDR,
62-
.acpi20 = EFI_INVALID_TABLE_ADDR,
63-
.smbios = EFI_INVALID_TABLE_ADDR,
64-
.smbios3 = EFI_INVALID_TABLE_ADDR,
65-
.sal_systab = EFI_INVALID_TABLE_ADDR,
66-
.boot_info = EFI_INVALID_TABLE_ADDR,
67-
.hcdp = EFI_INVALID_TABLE_ADDR,
68-
.uga = EFI_INVALID_TABLE_ADDR,
69-
.uv_systab = EFI_INVALID_TABLE_ADDR,
70-
.fw_vendor = EFI_INVALID_TABLE_ADDR,
71-
.runtime = EFI_INVALID_TABLE_ADDR,
72-
.config_table = EFI_INVALID_TABLE_ADDR,
73-
.get_time = xen_efi_get_time,
74-
.set_time = xen_efi_set_time,
75-
.get_wakeup_time = xen_efi_get_wakeup_time,
76-
.set_wakeup_time = xen_efi_set_wakeup_time,
77-
.get_variable = xen_efi_get_variable,
78-
.get_next_variable = xen_efi_get_next_variable,
79-
.set_variable = xen_efi_set_variable,
80-
.query_variable_info = xen_efi_query_variable_info,
81-
.update_capsule = xen_efi_update_capsule,
82-
.query_capsule_caps = xen_efi_query_capsule_caps,
83-
.get_next_high_mono_count = xen_efi_get_next_high_mono_count,
84-
.reset_system = xen_efi_reset_system,
85-
.set_virtual_address_map = NULL, /* Not used under Xen. */
86-
.flags = 0 /* Initialized later. */
87-
};
88-
8957
static efi_system_table_t __init *xen_efi_probe(void)
9058
{
9159
struct xen_platform_op op = {
@@ -102,7 +70,18 @@ static efi_system_table_t __init *xen_efi_probe(void)
10270

10371
/* Here we know that Xen runs on EFI platform. */
10472

105-
efi = efi_xen;
73+
efi.get_time = xen_efi_get_time;
74+
efi.set_time = xen_efi_set_time;
75+
efi.get_wakeup_time = xen_efi_get_wakeup_time;
76+
efi.set_wakeup_time = xen_efi_set_wakeup_time;
77+
efi.get_variable = xen_efi_get_variable;
78+
efi.get_next_variable = xen_efi_get_next_variable;
79+
efi.set_variable = xen_efi_set_variable;
80+
efi.query_variable_info = xen_efi_query_variable_info;
81+
efi.update_capsule = xen_efi_update_capsule;
82+
efi.query_capsule_caps = xen_efi_query_capsule_caps;
83+
efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
84+
efi.reset_system = xen_efi_reset_system;
10685

10786
efi_systab_xen.tables = info->cfg.addr;
10887
efi_systab_xen.nr_tables = info->cfg.nent;

‎drivers/firmware/efi/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ config EFI_CAPSULE_LOADER
112112

113113
Most users should say N.
114114

115+
config EFI_CAPSULE_QUIRK_QUARK_CSH
116+
boolean "Add support for Quark capsules with non-standard headers"
117+
depends on X86 && !64BIT
118+
select EFI_CAPSULE_LOADER
119+
default y
120+
help
121+
Add support for processing Quark X1000 EFI capsules, whose header
122+
layout deviates from the layout mandated by the UEFI specification.
123+
115124
config EFI_TEST
116125
tristate "EFI Runtime Service Tests Support"
117126
depends on EFI

‎drivers/firmware/efi/arm-runtime.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
*/
1313

14+
#include <linux/dmi.h>
1415
#include <linux/efi.h>
1516
#include <linux/io.h>
1617
#include <linux/memblock.h>
@@ -166,3 +167,18 @@ void efi_virtmap_unload(void)
166167
efi_set_pgd(current->active_mm);
167168
preempt_enable();
168169
}
170+
171+
172+
static int __init arm_dmi_init(void)
173+
{
174+
/*
175+
* On arm64/ARM, DMI depends on UEFI, and dmi_scan_machine() needs to
176+
* be called early because dmi_id_init(), which is an arch_initcall
177+
* itself, depends on dmi_scan_machine() having been called already.
178+
*/
179+
dmi_scan_machine();
180+
if (dmi_available)
181+
dmi_set_dump_stack_arch_desc();
182+
return 0;
183+
}
184+
core_initcall(arm_dmi_init);

0 commit comments

Comments
 (0)