Skip to content

Commit 17baa44

Browse files
committed
Merge tag 'efi-urgent-2020-07-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into master
Pull EFI fixes from Ingo Molnar: "Various EFI fixes: - Fix the layering violation in the use of the EFI runtime services availability mask in users of the 'efivars' abstraction - Revert build fix for GCC v4.8 which is no longer supported - Clean up some x86 EFI stub details, some of which are borderline bugs that copy around garbage into padding fields - let's fix these out of caution. - Fix build issues while working on RISC-V support - Avoid --whole-archive when linking the stub on arm64" * tag 'efi-urgent-2020-07-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: efi: Revert "efi/x86: Fix build with gcc 4" efi/efivars: Expose RT service availability via efivars abstraction efi/libstub: Move the function prototypes to header file efi/libstub: Fix gcc error around __umoddi3 for 32 bit builds efi/libstub/arm64: link stub lib.a conditionally efi/x86: Only copy upto the end of setup_header efi/x86: Remove unused variables
2 parents 7cb3a5c + 74f8555 commit 17baa44

File tree

12 files changed

+43
-40
lines changed

12 files changed

+43
-40
lines changed

arch/arm64/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export TEXT_OFFSET
137137

138138
core-y += arch/arm64/
139139
libs-y := arch/arm64/lib/ $(libs-y)
140-
core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
140+
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
141141

142142
# Default target when executing plain make
143143
boot := arch/arm64/boot

drivers/firmware/efi/efi-pstore.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,7 @@ static struct pstore_info efi_pstore_info = {
356356

357357
static __init int efivars_pstore_init(void)
358358
{
359-
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
360-
return 0;
361-
362-
if (!efivars_kobject())
359+
if (!efivars_kobject() || !efivar_supports_writes())
363360
return 0;
364361

365362
if (efivars_pstore_disable)

drivers/firmware/efi/efi.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ static struct efivar_operations generic_ops;
176176
static int generic_ops_register(void)
177177
{
178178
generic_ops.get_variable = efi.get_variable;
179-
generic_ops.set_variable = efi.set_variable;
180-
generic_ops.set_variable_nonblocking = efi.set_variable_nonblocking;
181179
generic_ops.get_next_variable = efi.get_next_variable;
182180
generic_ops.query_variable_store = efi_query_variable_store;
183181

182+
if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) {
183+
generic_ops.set_variable = efi.set_variable;
184+
generic_ops.set_variable_nonblocking = efi.set_variable_nonblocking;
185+
}
184186
return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
185187
}
186188

@@ -382,7 +384,8 @@ static int __init efisubsys_init(void)
382384
return -ENOMEM;
383385
}
384386

385-
if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) {
387+
if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE |
388+
EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME)) {
386389
efivar_ssdt_load();
387390
error = generic_ops_register();
388391
if (error)
@@ -416,7 +419,8 @@ static int __init efisubsys_init(void)
416419
err_remove_group:
417420
sysfs_remove_group(efi_kobj, &efi_subsys_attr_group);
418421
err_unregister:
419-
if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
422+
if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE |
423+
EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME))
420424
generic_ops_unregister();
421425
err_put:
422426
kobject_put(efi_kobj);

drivers/firmware/efi/efivars.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,8 @@ int efivars_sysfs_init(void)
680680
struct kobject *parent_kobj = efivars_kobject();
681681
int error = 0;
682682

683-
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
684-
return -ENODEV;
685-
686683
/* No efivars has been registered yet */
687-
if (!parent_kobj)
684+
if (!parent_kobj || !efivar_supports_writes())
688685
return 0;
689686

690687
printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,

drivers/firmware/efi/libstub/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
# enabled, even if doing so doesn't break the build.
77
#
88
cflags-$(CONFIG_X86_32) := -march=i386
9-
cflags-$(CONFIG_X86_64) := -mcmodel=small \
10-
$(call cc-option,-maccumulate-outgoing-args)
9+
cflags-$(CONFIG_X86_64) := -mcmodel=small
1110
cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \
1211
-fPIC -fno-strict-aliasing -mno-red-zone \
1312
-mno-mmx -mno-sse -fshort-wchar \

drivers/firmware/efi/libstub/alignedmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
4444
*addr = ALIGN((unsigned long)alloc_addr, align);
4545

4646
if (slack > 0) {
47-
int l = (alloc_addr % align) / EFI_PAGE_SIZE;
47+
int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
4848

4949
if (l) {
5050
efi_bs_call(free_pages, alloc_addr, slack - l + 1);

drivers/firmware/efi/libstub/efi-stub.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,6 @@ static unsigned long get_dram_base(void)
121121
return membase;
122122
}
123123

124-
/*
125-
* This function handles the architcture specific differences between arm and
126-
* arm64 regarding where the kernel image must be loaded and any memory that
127-
* must be reserved. On failure it is required to free all
128-
* all allocations it has made.
129-
*/
130-
efi_status_t handle_kernel_image(unsigned long *image_addr,
131-
unsigned long *image_size,
132-
unsigned long *reserve_addr,
133-
unsigned long *reserve_size,
134-
unsigned long dram_base,
135-
efi_loaded_image_t *image);
136-
137-
asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
138-
unsigned long fdt_addr,
139-
unsigned long fdt_size);
140-
141124
/*
142125
* EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint
143126
* that is described in the PE/COFF header. Most of the code is the same

drivers/firmware/efi/libstub/efistub.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,22 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image,
776776
unsigned long *load_size,
777777
unsigned long soft_limit,
778778
unsigned long hard_limit);
779+
/*
780+
* This function handles the architcture specific differences between arm and
781+
* arm64 regarding where the kernel image must be loaded and any memory that
782+
* must be reserved. On failure it is required to free all
783+
* all allocations it has made.
784+
*/
785+
efi_status_t handle_kernel_image(unsigned long *image_addr,
786+
unsigned long *image_size,
787+
unsigned long *reserve_addr,
788+
unsigned long *reserve_size,
789+
unsigned long dram_base,
790+
efi_loaded_image_t *image);
791+
792+
asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
793+
unsigned long fdt_addr,
794+
unsigned long fdt_size);
779795

780796
void efi_handle_post_ebs_state(void);
781797

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/efi.h>
1010
#include <linux/pci.h>
11+
#include <linux/stddef.h>
1112

1213
#include <asm/efi.h>
1314
#include <asm/e820/types.h>
@@ -361,8 +362,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
361362
int options_size = 0;
362363
efi_status_t status;
363364
char *cmdline_ptr;
364-
unsigned long ramdisk_addr;
365-
unsigned long ramdisk_size;
366365

367366
efi_system_table = sys_table_arg;
368367

@@ -390,8 +389,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
390389

391390
hdr = &boot_params->hdr;
392391

393-
/* Copy the second sector to boot_params */
394-
memcpy(&hdr->jump, image_base + 512, 512);
392+
/* Copy the setup header from the second sector to boot_params */
393+
memcpy(&hdr->jump, image_base + 512,
394+
sizeof(struct setup_header) - offsetof(struct setup_header, jump));
395395

396396
/*
397397
* Fill out some of the header fields ourselves because the

drivers/firmware/efi/vars.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,3 +1229,9 @@ int efivars_unregister(struct efivars *efivars)
12291229
return rv;
12301230
}
12311231
EXPORT_SYMBOL_GPL(efivars_unregister);
1232+
1233+
int efivar_supports_writes(void)
1234+
{
1235+
return __efivars && __efivars->ops->set_variable;
1236+
}
1237+
EXPORT_SYMBOL_GPL(efivar_supports_writes);

0 commit comments

Comments
 (0)