Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 252692
b: refs/heads/master
c: 916f676
h: refs/heads/master
v: v3
  • Loading branch information
Matthew Garrett authored and H. Peter Anvin committed May 26, 2011
1 parent a94a7b1 commit 9f0c214
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8b27f2ff7a24f0735c96055e676872f05398d99b
refs/heads/master: 916f676f8dc016103f983c7ec54c18ecdbb6e349
7 changes: 7 additions & 0 deletions trunk/arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,13 @@ void __init setup_arch(char **cmdline_p)
memblock.current_limit = get_max_mapped();
memblock_x86_fill();

/*
* The EFI specification says that boot service code won't be called
* after ExitBootServices(). This is, in fact, a lie.
*/
if (efi_enabled)
efi_reserve_boot_services();

/* preallocate 4k for mptable mpc */
early_reserve_e820_mpc_new();

Expand Down
45 changes: 44 additions & 1 deletion trunk/arch/x86/platform/efi/efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,40 @@ static void __init print_efi_memmap(void)
}
#endif /* EFI_DEBUG */

void __init efi_reserve_boot_services(void)
{
void *p;

for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
efi_memory_desc_t *md = p;
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;

if (md->type != EFI_BOOT_SERVICES_CODE &&
md->type != EFI_BOOT_SERVICES_DATA)
continue;

memblock_x86_reserve_range(start, start + size, "EFI Boot");
}
}

static void __init efi_free_boot_services(void)
{
void *p;

for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
efi_memory_desc_t *md = p;
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;

if (md->type != EFI_BOOT_SERVICES_CODE &&
md->type != EFI_BOOT_SERVICES_DATA)
continue;

free_bootmem_late(start, size);
}
}

void __init efi_init(void)
{
efi_config_table_t *config_tables;
Expand Down Expand Up @@ -536,7 +570,9 @@ void __init efi_enter_virtual_mode(void)

for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
md = p;
if (!(md->attribute & EFI_MEMORY_RUNTIME))
if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
md->type != EFI_BOOT_SERVICES_CODE &&
md->type != EFI_BOOT_SERVICES_DATA)
continue;

size = md->num_pages << EFI_PAGE_SHIFT;
Expand Down Expand Up @@ -592,6 +628,13 @@ void __init efi_enter_virtual_mode(void)
panic("EFI call to SetVirtualAddressMap() failed!");
}

/*
* Thankfully, it does seem that no runtime services other than
* SetVirtualAddressMap() will touch boot services code, so we can
* get rid of it all at this point
*/
efi_free_boot_services();

/*
* Now that EFI is in virtual mode, update the function
* pointers in the runtime service table to the new virtual addresses.
Expand Down
5 changes: 3 additions & 2 deletions trunk/arch/x86/platform/efi/efi_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ static void __init early_code_mapping_set_exec(int executable)
if (!(__supported_pte_mask & _PAGE_NX))
return;

/* Make EFI runtime service code area executable */
/* Make EFI service code area executable */
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
md = p;
if (md->type == EFI_RUNTIME_SERVICES_CODE)
if (md->type == EFI_RUNTIME_SERVICES_CODE ||
md->type == EFI_BOOT_SERVICES_CODE)
efi_set_executable(md, executable);
}
}
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ extern void efi_initialize_iomem_resources(struct resource *code_resource,
struct resource *data_resource, struct resource *bss_resource);
extern unsigned long efi_get_time(void);
extern int efi_set_rtc_mmss(unsigned long nowtime);
extern void efi_reserve_boot_services(void);
extern struct efi_memory_map memmap;

/**
Expand Down

0 comments on commit 9f0c214

Please sign in to comment.