diff options
author | Pekka Enberg <penberg@cs.helsinki.fi> | 2009-04-21 04:39:27 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-21 04:48:08 -0400 |
commit | 89388913f2c88a2cd15d24abab571b17a2596127 (patch) | |
tree | 2d3791f3fe4b844ba007371c2fe203b304e4c2cc /arch/x86/mm/init.c | |
parent | 8ecee4620e76aae418bfa0e8cc830e92cb559bbb (diff) |
x86: unify noexec handling
This patch unifies noexec handling on 32-bit and 64-bit.
[ Impact: cleanup ]
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
[ mingo@elte.hu: build fix ]
LKML-Reference: <1240303167.771.69.camel@penberg-laptop>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/mm/init.c')
-rw-r--r-- | arch/x86/mm/init.c | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index fd3da1dda1c9..fedde5359a04 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c | |||
@@ -22,6 +22,69 @@ int direct_gbpages | |||
22 | #endif | 22 | #endif |
23 | ; | 23 | ; |
24 | 24 | ||
25 | int nx_enabled; | ||
26 | |||
27 | #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) | ||
28 | static int disable_nx __cpuinitdata; | ||
29 | |||
30 | /* | ||
31 | * noexec = on|off | ||
32 | * | ||
33 | * Control non-executable mappings for processes. | ||
34 | * | ||
35 | * on Enable | ||
36 | * off Disable | ||
37 | */ | ||
38 | static int __init noexec_setup(char *str) | ||
39 | { | ||
40 | if (!str) | ||
41 | return -EINVAL; | ||
42 | if (!strncmp(str, "on", 2)) { | ||
43 | __supported_pte_mask |= _PAGE_NX; | ||
44 | disable_nx = 0; | ||
45 | } else if (!strncmp(str, "off", 3)) { | ||
46 | disable_nx = 1; | ||
47 | __supported_pte_mask &= ~_PAGE_NX; | ||
48 | } | ||
49 | return 0; | ||
50 | } | ||
51 | early_param("noexec", noexec_setup); | ||
52 | #endif | ||
53 | |||
54 | #ifdef CONFIG_X86_PAE | ||
55 | static void __init set_nx(void) | ||
56 | { | ||
57 | unsigned int v[4], l, h; | ||
58 | |||
59 | if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) { | ||
60 | cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]); | ||
61 | |||
62 | if ((v[3] & (1 << 20)) && !disable_nx) { | ||
63 | rdmsr(MSR_EFER, l, h); | ||
64 | l |= EFER_NX; | ||
65 | wrmsr(MSR_EFER, l, h); | ||
66 | nx_enabled = 1; | ||
67 | __supported_pte_mask |= _PAGE_NX; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | #else | ||
72 | static inline void set_nx(void) | ||
73 | { | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | #ifdef CONFIG_X86_64 | ||
78 | void __cpuinit check_efer(void) | ||
79 | { | ||
80 | unsigned long efer; | ||
81 | |||
82 | rdmsrl(MSR_EFER, efer); | ||
83 | if (!(efer & EFER_NX) || disable_nx) | ||
84 | __supported_pte_mask &= ~_PAGE_NX; | ||
85 | } | ||
86 | #endif | ||
87 | |||
25 | static void __init find_early_table_space(unsigned long end, int use_pse, | 88 | static void __init find_early_table_space(unsigned long end, int use_pse, |
26 | int use_gbpages) | 89 | int use_gbpages) |
27 | { | 90 | { |
@@ -158,12 +221,9 @@ unsigned long __init_refok init_memory_mapping(unsigned long start, | |||
158 | use_gbpages = direct_gbpages; | 221 | use_gbpages = direct_gbpages; |
159 | #endif | 222 | #endif |
160 | 223 | ||
161 | #ifdef CONFIG_X86_32 | ||
162 | #ifdef CONFIG_X86_PAE | ||
163 | set_nx(); | 224 | set_nx(); |
164 | if (nx_enabled) | 225 | if (nx_enabled) |
165 | printk(KERN_INFO "NX (Execute Disable) protection: active\n"); | 226 | printk(KERN_INFO "NX (Execute Disable) protection: active\n"); |
166 | #endif | ||
167 | 227 | ||
168 | /* Enable PSE if available */ | 228 | /* Enable PSE if available */ |
169 | if (cpu_has_pse) | 229 | if (cpu_has_pse) |
@@ -174,7 +234,6 @@ unsigned long __init_refok init_memory_mapping(unsigned long start, | |||
174 | set_in_cr4(X86_CR4_PGE); | 234 | set_in_cr4(X86_CR4_PGE); |
175 | __supported_pte_mask |= _PAGE_GLOBAL; | 235 | __supported_pte_mask |= _PAGE_GLOBAL; |
176 | } | 236 | } |
177 | #endif | ||
178 | 237 | ||
179 | if (use_gbpages) | 238 | if (use_gbpages) |
180 | page_size_mask |= 1 << PG_LEVEL_1G; | 239 | page_size_mask |= 1 << PG_LEVEL_1G; |