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: Matthew Garrett <mjg@redhat.com> Link: http://lkml.kernel.org/r/1304623186-18261-2-git-send-email-mjg@redhat.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
2b5e8ef35b
commit
9cd2b07c19
3 changed files with 22 additions and 28 deletions
|
@ -90,6 +90,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
|
||||||
#endif /* CONFIG_X86_32 */
|
#endif /* CONFIG_X86_32 */
|
||||||
|
|
||||||
extern int add_efi_memmap;
|
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_memblock_x86_reserve_range(void);
|
||||||
extern void efi_call_phys_prelog(void);
|
extern void efi_call_phys_prelog(void);
|
||||||
extern void efi_call_phys_epilog(void);
|
extern void efi_call_phys_epilog(void);
|
||||||
|
|
|
@ -457,11 +457,25 @@ void __init efi_init(void)
|
||||||
#endif
|
#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)
|
static void __init runtime_code_page_mkexec(void)
|
||||||
{
|
{
|
||||||
efi_memory_desc_t *md;
|
efi_memory_desc_t *md;
|
||||||
void *p;
|
void *p;
|
||||||
u64 addr, npages;
|
|
||||||
|
|
||||||
/* Make EFI runtime service code area executable */
|
/* Make EFI runtime service code area executable */
|
||||||
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
|
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)
|
if (md->type != EFI_RUNTIME_SERVICES_CODE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addr = md->virt_addr;
|
efi_set_executable(md, true);
|
||||||
npages = md->num_pages;
|
|
||||||
memrange_efi_to_native(&addr, &npages);
|
|
||||||
set_memory_x(addr, npages);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,22 +41,7 @@
|
||||||
static pgd_t save_pgd __initdata;
|
static pgd_t save_pgd __initdata;
|
||||||
static unsigned long efi_flags __initdata;
|
static unsigned long efi_flags __initdata;
|
||||||
|
|
||||||
static void __init early_mapping_set_exec(unsigned long start,
|
static void __init early_code_mapping_set_exec(int executable)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
efi_memory_desc_t *md;
|
efi_memory_desc_t *md;
|
||||||
void *p;
|
void *p;
|
||||||
|
@ -67,11 +52,8 @@ static void __init early_runtime_code_mapping_set_exec(int executable)
|
||||||
/* Make EFI runtime service code area executable */
|
/* Make EFI runtime service code area executable */
|
||||||
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
|
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
|
||||||
md = p;
|
md = p;
|
||||||
if (md->type == EFI_RUNTIME_SERVICES_CODE) {
|
if (md->type == EFI_RUNTIME_SERVICES_CODE)
|
||||||
unsigned long end;
|
efi_set_executable(md, executable);
|
||||||
end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
|
|
||||||
early_mapping_set_exec(md->phys_addr, end, executable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +61,7 @@ void __init efi_call_phys_prelog(void)
|
||||||
{
|
{
|
||||||
unsigned long vaddress;
|
unsigned long vaddress;
|
||||||
|
|
||||||
early_runtime_code_mapping_set_exec(1);
|
early_code_mapping_set_exec(1);
|
||||||
local_irq_save(efi_flags);
|
local_irq_save(efi_flags);
|
||||||
vaddress = (unsigned long)__va(0x0UL);
|
vaddress = (unsigned long)__va(0x0UL);
|
||||||
save_pgd = *pgd_offset_k(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);
|
set_pgd(pgd_offset_k(0x0UL), save_pgd);
|
||||||
__flush_tlb_all();
|
__flush_tlb_all();
|
||||||
local_irq_restore(efi_flags);
|
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,
|
void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
|
||||||
|
|
Loading…
Reference in a new issue