i386: NX emulation
[linux-flexiantxendom0-natty.git] / arch / x86 / mm / setup_nx.c
1 #include <linux/sched.h>
2 #include <linux/spinlock.h>
3 #include <linux/errno.h>
4 #include <linux/init.h>
5
6 #include <asm/pgtable.h>
7 #include <asm/proto.h>
8
9 static int disable_nx __cpuinitdata;
10
11 /*
12  * noexec = on|off
13  *
14  * Control non-executable mappings for processes.
15  *
16  * on      Enable
17  * off     Disable
18  */
19 static int __init noexec_setup(char *str)
20 {
21         if (!str)
22                 return -EINVAL;
23         if (!strncmp(str, "on", 2)) {
24                 disable_nx = 0;
25         } else if (!strncmp(str, "off", 3)) {
26                 disable_nx = 1;
27                 exec_shield = 0;
28         }
29         x86_configure_nx();
30         return 0;
31 }
32 early_param("noexec", noexec_setup);
33
34 void __cpuinit x86_configure_nx(void)
35 {
36         if (cpu_has_nx && !disable_nx)
37                 __supported_pte_mask |= _PAGE_NX;
38         else
39                 __supported_pte_mask &= ~_PAGE_NX;
40 }
41
42 void __init x86_report_nx(void)
43 {
44         if (!cpu_has_nx) {
45                 if (exec_shield)
46                         printk(KERN_INFO "Using x86 segment limits to approximate NX protection\n");
47                 else
48
49                 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
50                        "missing in CPU!\n");
51         } else {
52 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
53                 if (disable_nx) {
54                         printk(KERN_INFO "NX (Execute Disable) protection: "
55                                "disabled by kernel command line option\n");
56                 } else {
57                         printk(KERN_INFO "NX (Execute Disable) protection: "
58                                "active\n");
59                 }
60 #else
61                 /* 32bit non-PAE kernel, NX cannot be used */
62                 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
63                        "cannot be enabled: non-PAE kernel!\n");
64 #endif
65         }
66 }