diff --git a/arch/x86/kernel/cpu.c b/arch/x86/kernel/cpu.c index 82c59e93..4432ddd5 100644 --- a/arch/x86/kernel/cpu.c +++ b/arch/x86/kernel/cpu.c @@ -311,9 +311,45 @@ static void enable_page_protection_fault(void) return; } +static int no_execute_available = 0; + +static void enable_no_execute(void) +{ + unsigned long efer; + + if (!no_execute_available) { + return; + } + + efer = rdmsr(MSR_EFER); +#define IA32_EFER_NXE (1UL << 11) + efer |= IA32_EFER_NXE; + wrmsr(MSR_EFER, efer); + + return; +} + +static void check_no_execute(void) +{ + uint32_t edx; + extern void enable_ptattr_no_execute(void); + + /* check Execute Disable Bit available bit */ + asm ("cpuid" : "=d" (edx) : "a" (0x80000001) : "%rbx", "%rcx"); + no_execute_available = (edx & (1 << 20))? 1: 0; + kprintf("no_execute_available: %d\n", no_execute_available); + + if (no_execute_available) { + enable_ptattr_no_execute(); + } + + return; +} + void init_cpu(void) { enable_page_protection_fault(); + enable_no_execute(); init_fpu(); init_lapic(); init_syscall(); @@ -330,6 +366,8 @@ void setup_x86(void) init_page_table(); + check_no_execute(); + init_cpu(); kprintf("setup_x86 done.\n"); diff --git a/arch/x86/kernel/memory.c b/arch/x86/kernel/memory.c index 32181fd2..c765cb49 100644 --- a/arch/x86/kernel/memory.c +++ b/arch/x86/kernel/memory.c @@ -219,7 +219,15 @@ static struct page_table *__alloc_new_pt(enum ihk_mc_ap_flag ap_flag) * but L2 and L1 do not! */ -#define ATTR_MASK (PTATTR_WRITABLE | PTATTR_USER | PTATTR_ACTIVE) +static enum ihk_mc_pt_attribute attr_mask = PTATTR_WRITABLE | PTATTR_USER | PTATTR_ACTIVE; +#define ATTR_MASK attr_mask + +void enable_ptattr_no_execute(void) +{ + attr_mask |= PTATTR_NO_EXECUTE; + return; +} + #if 0 static unsigned long attr_to_l4attr(enum ihk_mc_pt_attribute attr) {