x86: EFI runtime code mapping enhancement
This patch enhances EFI runtime code memory mapping as following: - Move __supported_pte_mask & _PAGE_NX checking before invoking runtime_code_page_mkexec(). This makes it possible for compiler to eliminate runtime_code_page_mkexec() on machine without NX support. - Use set_memory_x/nx in early_mapping_set_exec(). This eliminates the duplicated implementation. This patch has been tested on Intel x86_64 platform with EFI64/32 firmware. Signed-off-by: Huang Ying <ying.huang@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
@@ -384,9 +384,6 @@ static void __init runtime_code_page_mkexec(void)
|
|||||||
efi_memory_desc_t *md;
|
efi_memory_desc_t *md;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!(__supported_pte_mask & _PAGE_NX))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* 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;
|
||||||
@@ -476,6 +473,7 @@ void __init efi_enter_virtual_mode(void)
|
|||||||
efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
|
efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
|
||||||
efi.reset_system = virt_efi_reset_system;
|
efi.reset_system = virt_efi_reset_system;
|
||||||
efi.set_virtual_address_map = virt_efi_set_virtual_address_map;
|
efi.set_virtual_address_map = virt_efi_set_virtual_address_map;
|
||||||
|
if (__supported_pte_mask & _PAGE_NX)
|
||||||
runtime_code_page_mkexec();
|
runtime_code_page_mkexec();
|
||||||
early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
|
early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
|
||||||
memmap.map = NULL;
|
memmap.map = NULL;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include <asm/tlbflush.h>
|
#include <asm/tlbflush.h>
|
||||||
#include <asm/proto.h>
|
#include <asm/proto.h>
|
||||||
#include <asm/efi.h>
|
#include <asm/efi.h>
|
||||||
|
#include <asm/cacheflush.h>
|
||||||
|
|
||||||
static pgd_t save_pgd __initdata;
|
static pgd_t save_pgd __initdata;
|
||||||
static unsigned long efi_flags __initdata;
|
static unsigned long efi_flags __initdata;
|
||||||
@@ -43,22 +44,15 @@ static void __init early_mapping_set_exec(unsigned long start,
|
|||||||
unsigned long end,
|
unsigned long end,
|
||||||
int executable)
|
int executable)
|
||||||
{
|
{
|
||||||
pte_t *kpte;
|
unsigned long num_pages;
|
||||||
unsigned int level;
|
|
||||||
|
|
||||||
while (start < end) {
|
start &= PMD_MASK;
|
||||||
kpte = lookup_address((unsigned long)__va(start), &level);
|
end = (end + PMD_SIZE - 1) & PMD_MASK;
|
||||||
BUG_ON(!kpte);
|
num_pages = (end - start) >> PAGE_SHIFT;
|
||||||
if (executable)
|
if (executable)
|
||||||
set_pte(kpte, pte_mkexec(*kpte));
|
set_memory_x((unsigned long)__va(start), num_pages);
|
||||||
else
|
else
|
||||||
set_pte(kpte, __pte((pte_val(*kpte) | _PAGE_NX) & \
|
set_memory_nx((unsigned long)__va(start), num_pages);
|
||||||
__supported_pte_mask));
|
|
||||||
if (level == PG_LEVEL_4K)
|
|
||||||
start = (start + PAGE_SIZE) & PAGE_MASK;
|
|
||||||
else
|
|
||||||
start = (start + PMD_SIZE) & PMD_MASK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __init early_runtime_code_mapping_set_exec(int executable)
|
static void __init early_runtime_code_mapping_set_exec(int executable)
|
||||||
@@ -74,7 +68,7 @@ static void __init early_runtime_code_mapping_set_exec(int executable)
|
|||||||
md = p;
|
md = p;
|
||||||
if (md->type == EFI_RUNTIME_SERVICES_CODE) {
|
if (md->type == EFI_RUNTIME_SERVICES_CODE) {
|
||||||
unsigned long end;
|
unsigned long end;
|
||||||
end = md->phys_addr + (md->num_pages << PAGE_SHIFT);
|
end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
|
||||||
early_mapping_set_exec(md->phys_addr, end, executable);
|
early_mapping_set_exec(md->phys_addr, end, executable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,8 +78,8 @@ void __init efi_call_phys_prelog(void)
|
|||||||
{
|
{
|
||||||
unsigned long vaddress;
|
unsigned long vaddress;
|
||||||
|
|
||||||
local_irq_save(efi_flags);
|
|
||||||
early_runtime_code_mapping_set_exec(1);
|
early_runtime_code_mapping_set_exec(1);
|
||||||
|
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);
|
||||||
set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
|
set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
|
||||||
@@ -98,9 +92,9 @@ void __init efi_call_phys_epilog(void)
|
|||||||
* After the lock is released, the original page table is restored.
|
* After the lock is released, the original page table is restored.
|
||||||
*/
|
*/
|
||||||
set_pgd(pgd_offset_k(0x0UL), save_pgd);
|
set_pgd(pgd_offset_k(0x0UL), save_pgd);
|
||||||
early_runtime_code_mapping_set_exec(0);
|
|
||||||
__flush_tlb_all();
|
__flush_tlb_all();
|
||||||
local_irq_restore(efi_flags);
|
local_irq_restore(efi_flags);
|
||||||
|
early_runtime_code_mapping_set_exec(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __init efi_reserve_bootmem(void)
|
void __init efi_reserve_bootmem(void)
|
||||||
|
Reference in New Issue
Block a user