Commit 9cd2b07c authored by Matthew Garrett's avatar Matthew Garrett Committed by H. Peter Anvin

x86, efi: Consolidate EFI nx control

The core EFI code and 64-bit EFI code currently have independent
implementations of code for setting memory regions as executable or not.
Let's consolidate them.
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
Link: http://lkml.kernel.org/r/1304623186-18261-2-git-send-email-mjg@redhat.comSigned-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parent 2b5e8ef3
......@@ -90,6 +90,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
#endif /* CONFIG_X86_32 */
extern int add_efi_memmap;
extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
extern void efi_memblock_x86_reserve_range(void);
extern void efi_call_phys_prelog(void);
extern void efi_call_phys_epilog(void);
......
......@@ -457,11 +457,25 @@ void __init efi_init(void)
#endif
}
void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
{
u64 addr, npages;
addr = md->virt_addr;
npages = md->num_pages;
memrange_efi_to_native(&addr, &npages);
if (executable)
set_memory_x(addr, npages);
else
set_memory_nx(addr, npages);
}
static void __init runtime_code_page_mkexec(void)
{
efi_memory_desc_t *md;
void *p;
u64 addr, npages;
/* Make EFI runtime service code area executable */
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
......@@ -470,10 +484,7 @@ static void __init runtime_code_page_mkexec(void)
if (md->type != EFI_RUNTIME_SERVICES_CODE)
continue;
addr = md->virt_addr;
npages = md->num_pages;
memrange_efi_to_native(&addr, &npages);
set_memory_x(addr, npages);
efi_set_executable(md, true);
}
}
......
......@@ -41,22 +41,7 @@
static pgd_t save_pgd __initdata;
static unsigned long efi_flags __initdata;
static void __init early_mapping_set_exec(unsigned long start,
unsigned long end,
int executable)
{
unsigned long num_pages;
start &= PMD_MASK;
end = (end + PMD_SIZE - 1) & PMD_MASK;
num_pages = (end - start) >> PAGE_SHIFT;
if (executable)
set_memory_x((unsigned long)__va(start), num_pages);
else
set_memory_nx((unsigned long)__va(start), num_pages);
}
static void __init early_runtime_code_mapping_set_exec(int executable)
static void __init early_code_mapping_set_exec(int executable)
{
efi_memory_desc_t *md;
void *p;
......@@ -67,11 +52,8 @@ static void __init early_runtime_code_mapping_set_exec(int executable)
/* Make EFI runtime 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) {
unsigned long end;
end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
early_mapping_set_exec(md->phys_addr, end, executable);
}
if (md->type == EFI_RUNTIME_SERVICES_CODE)
efi_set_executable(md, executable);
}
}
......@@ -79,7 +61,7 @@ void __init efi_call_phys_prelog(void)
{
unsigned long vaddress;
early_runtime_code_mapping_set_exec(1);
early_code_mapping_set_exec(1);
local_irq_save(efi_flags);
vaddress = (unsigned long)__va(0x0UL);
save_pgd = *pgd_offset_k(0x0UL);
......@@ -95,7 +77,7 @@ void __init efi_call_phys_epilog(void)
set_pgd(pgd_offset_k(0x0UL), save_pgd);
__flush_tlb_all();
local_irq_restore(efi_flags);
early_runtime_code_mapping_set_exec(0);
early_code_mapping_set_exec(0);
}
void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment