* [PATCH 1/5] x86-32: use symbolic constants, safer CPUID when enabling EFER.NX
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
@ 2009-11-13 23:28 ` H. Peter Anvin
2009-11-16 22:06 ` [tip:x86/mm] x86-32: Use " tip-bot for H. Peter Anvin
2009-11-13 23:28 ` [PATCH 2/5] x86, sleep: always save the value of EFER H. Peter Anvin
` (4 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2009-11-13 23:28 UTC (permalink / raw)
To: linux-kernel; +Cc: mingo, tglx, x86, H. Peter Anvin
Use symbolic constants rather than hard-coded values when setting
EFER.NX in head_32.S, and do a more rigorous test for the validity of
the response when probing for the extended CPUID range.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/kernel/head_32.S | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 050c278..7fd318b 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -18,6 +18,8 @@
#include <asm/asm-offsets.h>
#include <asm/setup.h>
#include <asm/processor-flags.h>
+#include <asm/msr-index.h>
+#include <asm/cpufeature.h>
#include <asm/percpu.h>
/* Physical address */
@@ -297,25 +299,27 @@ ENTRY(startup_32_smp)
orl %edx,%eax
movl %eax,%cr4
- btl $5, %eax # check if PAE is enabled
- jnc 6f
+ testb $X86_CR4_PAE, %al # check if PAE is enabled
+ jz 6f
/* Check if extended functions are implemented */
movl $0x80000000, %eax
cpuid
- cmpl $0x80000000, %eax
- jbe 6f
+ /* Value must be in the range 0x80000001 to 0x8000ffff */
+ subl $0x80000001, %eax
+ cmpl $(0x8000ffff-0x80000001), %eax
+ ja 6f
mov $0x80000001, %eax
cpuid
/* Execute Disable bit supported? */
- btl $20, %edx
+ btl $(X86_FEATURE_NX & 31), %edx
jnc 6f
/* Setup EFER (Extended Feature Enable Register) */
- movl $0xc0000080, %ecx
+ movl $MSR_EFER, %ecx
rdmsr
- btsl $11, %eax
+ btsl $_EFER_NX, %eax
/* Make changes effective */
wrmsr
--
1.6.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread* [tip:x86/mm] x86-32: Use symbolic constants, safer CPUID when enabling EFER.NX
2009-11-13 23:28 ` [PATCH 1/5] x86-32: use symbolic constants, safer CPUID when enabling EFER.NX H. Peter Anvin
@ 2009-11-16 22:06 ` tip-bot for H. Peter Anvin
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for H. Peter Anvin @ 2009-11-16 22:06 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, kees.cook, tglx
Commit-ID: 8a50e5135af0c243e117e94e27feb8d149c879b4
Gitweb: http://git.kernel.org/tip/8a50e5135af0c243e117e94e27feb8d149c879b4
Author: H. Peter Anvin <hpa@zytor.com>
AuthorDate: Fri, 13 Nov 2009 15:28:13 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 16 Nov 2009 13:44:56 -0800
x86-32: Use symbolic constants, safer CPUID when enabling EFER.NX
Use symbolic constants rather than hard-coded values when setting
EFER.NX in head_32.S, and do a more rigorous test for the validity of
the response when probing for the extended CPUID range.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
LKML-Reference: <1258154897-6770-2-git-send-email-hpa@zytor.com>
Acked-by: Kees Cook <kees.cook@canonical.com>
---
arch/x86/kernel/head_32.S | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 050c278..7fd318b 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -18,6 +18,8 @@
#include <asm/asm-offsets.h>
#include <asm/setup.h>
#include <asm/processor-flags.h>
+#include <asm/msr-index.h>
+#include <asm/cpufeature.h>
#include <asm/percpu.h>
/* Physical address */
@@ -297,25 +299,27 @@ ENTRY(startup_32_smp)
orl %edx,%eax
movl %eax,%cr4
- btl $5, %eax # check if PAE is enabled
- jnc 6f
+ testb $X86_CR4_PAE, %al # check if PAE is enabled
+ jz 6f
/* Check if extended functions are implemented */
movl $0x80000000, %eax
cpuid
- cmpl $0x80000000, %eax
- jbe 6f
+ /* Value must be in the range 0x80000001 to 0x8000ffff */
+ subl $0x80000001, %eax
+ cmpl $(0x8000ffff-0x80000001), %eax
+ ja 6f
mov $0x80000001, %eax
cpuid
/* Execute Disable bit supported? */
- btl $20, %edx
+ btl $(X86_FEATURE_NX & 31), %edx
jnc 6f
/* Setup EFER (Extended Feature Enable Register) */
- movl $0xc0000080, %ecx
+ movl $MSR_EFER, %ecx
rdmsr
- btsl $11, %eax
+ btsl $_EFER_NX, %eax
/* Make changes effective */
wrmsr
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/5] x86, sleep: always save the value of EFER
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
2009-11-13 23:28 ` [PATCH 1/5] x86-32: use symbolic constants, safer CPUID when enabling EFER.NX H. Peter Anvin
@ 2009-11-13 23:28 ` H. Peter Anvin
2009-11-14 0:16 ` Rafael J. Wysocki
2009-11-16 22:06 ` [tip:x86/mm] x86, sleep: Always " tip-bot for H. Peter Anvin
2009-11-13 23:28 ` [PATCH 3/5] x86, pageattr: make set_memory_(x|nx) aware of NX support H. Peter Anvin
` (3 subsequent siblings)
5 siblings, 2 replies; 13+ messages in thread
From: H. Peter Anvin @ 2009-11-13 23:28 UTC (permalink / raw)
To: linux-kernel
Cc: mingo, tglx, x86, H. Peter Anvin, Pavel Machek, Rafael J. Wysocki,
Nigel Cunningham
Always save the value of EFER, regardless of the state of NX. Since
EFER may not actually exist, use rdmsr_safe() to do so.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@tuxonice.net>
---
arch/x86/kernel/acpi/sleep.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index ca93638..c2e4455 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -78,12 +78,9 @@ int acpi_save_state_mem(void)
#ifndef CONFIG_64BIT
store_gdt((struct desc_ptr *)&header->pmode_gdt);
- header->pmode_efer_low = nx_enabled;
- if (header->pmode_efer_low & 1) {
- /* This is strange, why not save efer, always? */
- rdmsr(MSR_EFER, header->pmode_efer_low,
- header->pmode_efer_high);
- }
+ header->pmode_efer_low = header->pmode_efer_high = 0;
+ rdmsr_safe(MSR_EFER,
+ &header->pmode_efer_low, &header->pmode_efer_high);
#endif /* !CONFIG_64BIT */
header->pmode_cr0 = read_cr0();
--
1.6.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 2/5] x86, sleep: always save the value of EFER
2009-11-13 23:28 ` [PATCH 2/5] x86, sleep: always save the value of EFER H. Peter Anvin
@ 2009-11-14 0:16 ` Rafael J. Wysocki
2009-11-16 22:06 ` [tip:x86/mm] x86, sleep: Always " tip-bot for H. Peter Anvin
1 sibling, 0 replies; 13+ messages in thread
From: Rafael J. Wysocki @ 2009-11-14 0:16 UTC (permalink / raw)
To: H. Peter Anvin
Cc: linux-kernel, mingo, tglx, x86, Pavel Machek, Nigel Cunningham
On Saturday 14 November 2009, H. Peter Anvin wrote:
> Always save the value of EFER, regardless of the state of NX. Since
> EFER may not actually exist, use rdmsr_safe() to do so.
>
> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
> Cc: Nigel Cunningham <nigel@tuxonice.net>
> ---
> arch/x86/kernel/acpi/sleep.c | 9 +++------
> 1 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
> index ca93638..c2e4455 100644
> --- a/arch/x86/kernel/acpi/sleep.c
> +++ b/arch/x86/kernel/acpi/sleep.c
> @@ -78,12 +78,9 @@ int acpi_save_state_mem(void)
> #ifndef CONFIG_64BIT
> store_gdt((struct desc_ptr *)&header->pmode_gdt);
>
> - header->pmode_efer_low = nx_enabled;
> - if (header->pmode_efer_low & 1) {
> - /* This is strange, why not save efer, always? */
> - rdmsr(MSR_EFER, header->pmode_efer_low,
> - header->pmode_efer_high);
> - }
> + header->pmode_efer_low = header->pmode_efer_high = 0;
> + rdmsr_safe(MSR_EFER,
> + &header->pmode_efer_low, &header->pmode_efer_high);
> #endif /* !CONFIG_64BIT */
>
> header->pmode_cr0 = read_cr0();
>
^ permalink raw reply [flat|nested] 13+ messages in thread* [tip:x86/mm] x86, sleep: Always save the value of EFER
2009-11-13 23:28 ` [PATCH 2/5] x86, sleep: always save the value of EFER H. Peter Anvin
2009-11-14 0:16 ` Rafael J. Wysocki
@ 2009-11-16 22:06 ` tip-bot for H. Peter Anvin
1 sibling, 0 replies; 13+ messages in thread
From: tip-bot for H. Peter Anvin @ 2009-11-16 22:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, kees.cook, tglx, rjw, nigel, pavel
Commit-ID: a7c4c0d934c6cbc58de262d090d4a715445453f0
Gitweb: http://git.kernel.org/tip/a7c4c0d934c6cbc58de262d090d4a715445453f0
Author: H. Peter Anvin <hpa@zytor.com>
AuthorDate: Fri, 13 Nov 2009 15:28:14 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 16 Nov 2009 13:44:57 -0800
x86, sleep: Always save the value of EFER
Always save the value of EFER, regardless of the state of NX. Since
EFER may not actually exist, use rdmsr_safe() to do so.
v2: check the return value from rdmsr_safe() instead of relying on
the output values being unchanged on error.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@tuxonice.net>
LKML-Reference: <1258154897-6770-3-git-send-email-hpa@zytor.com>
Acked-by: Kees Cook <kees.cook@canonical.com>
---
arch/x86/kernel/acpi/sleep.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index 4a41145..82e5086 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -78,12 +78,9 @@ int acpi_save_state_mem(void)
#ifndef CONFIG_64BIT
store_gdt((struct desc_ptr *)&header->pmode_gdt);
- header->pmode_efer_low = nx_enabled;
- if (header->pmode_efer_low & 1) {
- /* This is strange, why not save efer, always? */
- rdmsr(MSR_EFER, header->pmode_efer_low,
- header->pmode_efer_high);
- }
+ if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low,
+ &header->pmode_efer_high))
+ header->pmode_efer_low = header->pmode_efer_high = 0;
#endif /* !CONFIG_64BIT */
header->pmode_cr0 = read_cr0();
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/5] x86, pageattr: make set_memory_(x|nx) aware of NX support
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
2009-11-13 23:28 ` [PATCH 1/5] x86-32: use symbolic constants, safer CPUID when enabling EFER.NX H. Peter Anvin
2009-11-13 23:28 ` [PATCH 2/5] x86, sleep: always save the value of EFER H. Peter Anvin
@ 2009-11-13 23:28 ` H. Peter Anvin
2009-11-16 22:07 ` [tip:x86/mm] x86, pageattr: Make " tip-bot for H. Peter Anvin
2009-11-13 23:28 ` [PATCH 4/5] x86, mm: clean up and simplify NX enablement H. Peter Anvin
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2009-11-13 23:28 UTC (permalink / raw)
To: linux-kernel
Cc: mingo, tglx, x86, H. Peter Anvin, Huang Ying, Venkatesh Pallipadi,
Suresh Siddha, Tejun Heo, Tim Starling, Hannes Eder
Make set_memory_x/set_memory_nx directly aware of if NX is supported
in the system or not, rather than requiring that every caller assesses
that support independently.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Tim Starling <tstarling@wikimedia.org>
Cc: Hannes Eder <hannes@hanneseder.net>
---
arch/x86/kernel/machine_kexec_32.c | 6 ++----
arch/x86/mm/pageattr.c | 6 ++++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
index c1c429d..03657e7 100644
--- a/arch/x86/kernel/machine_kexec_32.c
+++ b/arch/x86/kernel/machine_kexec_32.c
@@ -157,8 +157,7 @@ int machine_kexec_prepare(struct kimage *image)
{
int error;
- if (nx_enabled)
- set_pages_x(image->control_code_page, 1);
+ set_pages_x(image->control_code_page, 1);
error = machine_kexec_alloc_page_tables(image);
if (error)
return error;
@@ -172,8 +171,7 @@ int machine_kexec_prepare(struct kimage *image)
*/
void machine_kexec_cleanup(struct kimage *image)
{
- if (nx_enabled)
- set_pages_nx(image->control_code_page, 1);
+ set_pages_nx(image->control_code_page, 1);
machine_kexec_free_page_tables(image);
}
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index dd38bfb..442b8ac 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1069,12 +1069,18 @@ EXPORT_SYMBOL(set_memory_array_wb);
int set_memory_x(unsigned long addr, int numpages)
{
+ if (!(__supported_pte_mask & _PAGE_NX))
+ return 0;
+
return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_NX), 0);
}
EXPORT_SYMBOL(set_memory_x);
int set_memory_nx(unsigned long addr, int numpages)
{
+ if (!(__supported_pte_mask & _PAGE_NX))
+ return 0;
+
return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_NX), 0);
}
EXPORT_SYMBOL(set_memory_nx);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread* [tip:x86/mm] x86, pageattr: Make set_memory_(x|nx) aware of NX support
2009-11-13 23:28 ` [PATCH 3/5] x86, pageattr: make set_memory_(x|nx) aware of NX support H. Peter Anvin
@ 2009-11-16 22:07 ` tip-bot for H. Peter Anvin
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for H. Peter Anvin @ 2009-11-16 22:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, venkatesh.pallipadi, tstarling,
ying.huang, kees.cook, suresh.b.siddha, tj, hannes, tglx
Commit-ID: 583140afb989f24d115e80be5c91e503b58ccfc0
Gitweb: http://git.kernel.org/tip/583140afb989f24d115e80be5c91e503b58ccfc0
Author: H. Peter Anvin <hpa@zytor.com>
AuthorDate: Fri, 13 Nov 2009 15:28:15 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 16 Nov 2009 13:44:58 -0800
x86, pageattr: Make set_memory_(x|nx) aware of NX support
Make set_memory_x/set_memory_nx directly aware of if NX is supported
in the system or not, rather than requiring that every caller assesses
that support independently.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Tim Starling <tstarling@wikimedia.org>
Cc: Hannes Eder <hannes@hanneseder.net>
LKML-Reference: <1258154897-6770-4-git-send-email-hpa@zytor.com>
Acked-by: Kees Cook <kees.cook@canonical.com>
---
arch/x86/kernel/machine_kexec_32.c | 6 ++----
arch/x86/mm/pageattr.c | 6 ++++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
index c1c429d..03657e7 100644
--- a/arch/x86/kernel/machine_kexec_32.c
+++ b/arch/x86/kernel/machine_kexec_32.c
@@ -157,8 +157,7 @@ int machine_kexec_prepare(struct kimage *image)
{
int error;
- if (nx_enabled)
- set_pages_x(image->control_code_page, 1);
+ set_pages_x(image->control_code_page, 1);
error = machine_kexec_alloc_page_tables(image);
if (error)
return error;
@@ -172,8 +171,7 @@ int machine_kexec_prepare(struct kimage *image)
*/
void machine_kexec_cleanup(struct kimage *image)
{
- if (nx_enabled)
- set_pages_nx(image->control_code_page, 1);
+ set_pages_nx(image->control_code_page, 1);
machine_kexec_free_page_tables(image);
}
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 09a140c..1d4eb93 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1085,12 +1085,18 @@ EXPORT_SYMBOL(set_memory_array_wb);
int set_memory_x(unsigned long addr, int numpages)
{
+ if (!(__supported_pte_mask & _PAGE_NX))
+ return 0;
+
return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_NX), 0);
}
EXPORT_SYMBOL(set_memory_x);
int set_memory_nx(unsigned long addr, int numpages)
{
+ if (!(__supported_pte_mask & _PAGE_NX))
+ return 0;
+
return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_NX), 0);
}
EXPORT_SYMBOL(set_memory_nx);
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/5] x86, mm: clean up and simplify NX enablement
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
` (2 preceding siblings ...)
2009-11-13 23:28 ` [PATCH 3/5] x86, pageattr: make set_memory_(x|nx) aware of NX support H. Peter Anvin
@ 2009-11-13 23:28 ` H. Peter Anvin
2009-11-16 22:07 ` [tip:x86/mm] x86, mm: Clean " tip-bot for H. Peter Anvin
2009-11-13 23:28 ` [PATCH 5/5] x86, mm: report state of NX protections during boot H. Peter Anvin
2009-11-14 0:36 ` [PATCH 0/5] x86: cleanup of NX enabling Kees Cook
5 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2009-11-13 23:28 UTC (permalink / raw)
To: linux-kernel
Cc: mingo, tglx, x86, H. Peter Anvin, Tejun Heo, Brian Gerst,
Yinghai Lu, Pekka Enberg, Vegard Nossum, Jeremy Fitzhardinge,
Chris Wright
The 32- and 64-bit code used very different mechanisms for enabling
NX, but even the 32-bit code was enabling NX in head_32.S if it is
available. Furthermore, we had a bewildering collection of tests for
the available of NX.
This patch:
a) merges the 32-bit set_nx() and the 64-bit check_efer() function
into a single x86_configure_nx() function. EFER control is left
to the head code.
b) eliminates the nx_enabled variable entirely. Things that need to
test for NX enablement can verify __supported_pte_mask directly,
and cpu_has_nx gives the supported status of NX.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Vegard Nossum <vegardno@ifi.uio.no>
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: Chris Wright <chrisw@sous-sol.org>
---
arch/x86/include/asm/proto.h | 2 +-
arch/x86/kernel/cpu/common.c | 2 +-
arch/x86/kernel/setup.c | 8 +-----
arch/x86/mm/init.c | 4 +-
arch/x86/mm/setup_nx.c | 43 +++++------------------------------------
arch/x86/xen/enlighten.c | 4 +--
6 files changed, 13 insertions(+), 50 deletions(-)
diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index 621f56d..add7f18 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -16,7 +16,7 @@ extern void ia32_sysenter_target(void);
extern void syscall32_cpu_init(void);
-extern void check_efer(void);
+extern void x86_configure_nx(void);
extern int reboot_force;
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cc25c2b..18346da 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1136,7 +1136,7 @@ void __cpuinit cpu_init(void)
wrmsrl(MSR_KERNEL_GS_BASE, 0);
barrier();
- check_efer();
+ x86_configure_nx();
if (cpu != 0)
enable_x2apic();
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index e09f0e2..cdb3ac4 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -783,21 +783,17 @@ void __init setup_arch(char **cmdline_p)
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
-#ifdef CONFIG_X86_64
/*
* Must call this twice: Once just to detect whether hardware doesn't
* support NX (so that the early EHCI debug console setup can safely
* call set_fixmap(), and then again after parsing early parameters to
* honor the respective command line option.
*/
- check_efer();
-#endif
+ x86_configure_nx();
parse_early_param();
-#ifdef CONFIG_X86_64
- check_efer();
-#endif
+ x86_configure_nx();
/* Must be before kernel pagetables are setup */
vmi_activate();
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 73ffd55..27ec2c2 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -146,8 +146,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
use_gbpages = direct_gbpages;
#endif
- set_nx();
- if (nx_enabled)
+ /* XXX: replace this with Kees' improved messages */
+ if (__supported_pte_mask & _PAGE_NX)
printk(KERN_INFO "NX (Execute Disable) protection: active\n");
/* Enable PSE if available */
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 513d8ed..355818b 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -3,10 +3,8 @@
#include <linux/init.h>
#include <asm/pgtable.h>
+#include <asm/proto.h>
-int nx_enabled;
-
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
static int disable_nx __cpuinitdata;
/*
@@ -22,48 +20,19 @@ static int __init noexec_setup(char *str)
if (!str)
return -EINVAL;
if (!strncmp(str, "on", 2)) {
- __supported_pte_mask |= _PAGE_NX;
disable_nx = 0;
} else if (!strncmp(str, "off", 3)) {
disable_nx = 1;
- __supported_pte_mask &= ~_PAGE_NX;
}
+ x86_configure_nx();
return 0;
}
early_param("noexec", noexec_setup);
-#endif
-
-#ifdef CONFIG_X86_PAE
-void __init set_nx(void)
-{
- unsigned int v[4], l, h;
-
- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
-
- if ((v[3] & (1 << 20)) && !disable_nx) {
- rdmsr(MSR_EFER, l, h);
- l |= EFER_NX;
- wrmsr(MSR_EFER, l, h);
- nx_enabled = 1;
- __supported_pte_mask |= _PAGE_NX;
- }
- }
-}
-#else
-void set_nx(void)
-{
-}
-#endif
-#ifdef CONFIG_X86_64
-void __cpuinit check_efer(void)
+void __cpuinit x86_configure_nx(void)
{
- unsigned long efer;
-
- rdmsrl(MSR_EFER, efer);
- if (!(efer & EFER_NX) || disable_nx)
+ if (cpu_has_nx && !disable_nx)
+ __supported_pte_mask |= _PAGE_NX;
+ else
__supported_pte_mask &= ~_PAGE_NX;
}
-#endif
-
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index dfbf70e..c462cea 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1093,10 +1093,8 @@ asmlinkage void __init xen_start_kernel(void)
__supported_pte_mask |= _PAGE_IOMAP;
-#ifdef CONFIG_X86_64
/* Work out if we support NX */
- check_efer();
-#endif
+ x86_configure_nx();
xen_setup_features();
--
1.6.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread* [tip:x86/mm] x86, mm: Clean up and simplify NX enablement
2009-11-13 23:28 ` [PATCH 4/5] x86, mm: clean up and simplify NX enablement H. Peter Anvin
@ 2009-11-16 22:07 ` tip-bot for H. Peter Anvin
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for H. Peter Anvin @ 2009-11-16 22:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, yinghai, penberg, brgerst,
jeremy.fitzhardinge, vegardno, chrisw, kees.cook, tj, tglx
Commit-ID: 4763ed4d45522b876c97e1f7f4b659d211f75571
Gitweb: http://git.kernel.org/tip/4763ed4d45522b876c97e1f7f4b659d211f75571
Author: H. Peter Anvin <hpa@zytor.com>
AuthorDate: Fri, 13 Nov 2009 15:28:16 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 16 Nov 2009 13:44:59 -0800
x86, mm: Clean up and simplify NX enablement
The 32- and 64-bit code used very different mechanisms for enabling
NX, but even the 32-bit code was enabling NX in head_32.S if it is
available. Furthermore, we had a bewildering collection of tests for
the available of NX.
This patch:
a) merges the 32-bit set_nx() and the 64-bit check_efer() function
into a single x86_configure_nx() function. EFER control is left
to the head code.
b) eliminates the nx_enabled variable entirely. Things that need to
test for NX enablement can verify __supported_pte_mask directly,
and cpu_has_nx gives the supported status of NX.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Vegard Nossum <vegardno@ifi.uio.no>
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: Chris Wright <chrisw@sous-sol.org>
LKML-Reference: <1258154897-6770-5-git-send-email-hpa@zytor.com>
Acked-by: Kees Cook <kees.cook@canonical.com>
---
arch/x86/include/asm/proto.h | 2 +-
arch/x86/kernel/cpu/common.c | 2 +-
arch/x86/kernel/setup.c | 8 +-----
arch/x86/mm/init.c | 4 +-
arch/x86/mm/setup_nx.c | 43 +++++------------------------------------
arch/x86/xen/enlighten.c | 4 +--
6 files changed, 13 insertions(+), 50 deletions(-)
diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index 621f56d..add7f18 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -16,7 +16,7 @@ extern void ia32_sysenter_target(void);
extern void syscall32_cpu_init(void);
-extern void check_efer(void);
+extern void x86_configure_nx(void);
extern int reboot_force;
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cc25c2b..18346da 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1136,7 +1136,7 @@ void __cpuinit cpu_init(void)
wrmsrl(MSR_KERNEL_GS_BASE, 0);
barrier();
- check_efer();
+ x86_configure_nx();
if (cpu != 0)
enable_x2apic();
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 0a6e94a..23b7f46 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -787,21 +787,17 @@ void __init setup_arch(char **cmdline_p)
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
-#ifdef CONFIG_X86_64
/*
* Must call this twice: Once just to detect whether hardware doesn't
* support NX (so that the early EHCI debug console setup can safely
* call set_fixmap(), and then again after parsing early parameters to
* honor the respective command line option.
*/
- check_efer();
-#endif
+ x86_configure_nx();
parse_early_param();
-#ifdef CONFIG_X86_64
- check_efer();
-#endif
+ x86_configure_nx();
/* Must be before kernel pagetables are setup */
vmi_activate();
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 73ffd55..27ec2c2 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -146,8 +146,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
use_gbpages = direct_gbpages;
#endif
- set_nx();
- if (nx_enabled)
+ /* XXX: replace this with Kees' improved messages */
+ if (__supported_pte_mask & _PAGE_NX)
printk(KERN_INFO "NX (Execute Disable) protection: active\n");
/* Enable PSE if available */
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 513d8ed..355818b 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -3,10 +3,8 @@
#include <linux/init.h>
#include <asm/pgtable.h>
+#include <asm/proto.h>
-int nx_enabled;
-
-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
static int disable_nx __cpuinitdata;
/*
@@ -22,48 +20,19 @@ static int __init noexec_setup(char *str)
if (!str)
return -EINVAL;
if (!strncmp(str, "on", 2)) {
- __supported_pte_mask |= _PAGE_NX;
disable_nx = 0;
} else if (!strncmp(str, "off", 3)) {
disable_nx = 1;
- __supported_pte_mask &= ~_PAGE_NX;
}
+ x86_configure_nx();
return 0;
}
early_param("noexec", noexec_setup);
-#endif
-
-#ifdef CONFIG_X86_PAE
-void __init set_nx(void)
-{
- unsigned int v[4], l, h;
-
- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
-
- if ((v[3] & (1 << 20)) && !disable_nx) {
- rdmsr(MSR_EFER, l, h);
- l |= EFER_NX;
- wrmsr(MSR_EFER, l, h);
- nx_enabled = 1;
- __supported_pte_mask |= _PAGE_NX;
- }
- }
-}
-#else
-void set_nx(void)
-{
-}
-#endif
-#ifdef CONFIG_X86_64
-void __cpuinit check_efer(void)
+void __cpuinit x86_configure_nx(void)
{
- unsigned long efer;
-
- rdmsrl(MSR_EFER, efer);
- if (!(efer & EFER_NX) || disable_nx)
+ if (cpu_has_nx && !disable_nx)
+ __supported_pte_mask |= _PAGE_NX;
+ else
__supported_pte_mask &= ~_PAGE_NX;
}
-#endif
-
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 3439616..c5e805d 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1082,10 +1082,8 @@ asmlinkage void __init xen_start_kernel(void)
__supported_pte_mask |= _PAGE_IOMAP;
-#ifdef CONFIG_X86_64
/* Work out if we support NX */
- check_efer();
-#endif
+ x86_configure_nx();
xen_setup_features();
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/5] x86, mm: report state of NX protections during boot
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
` (3 preceding siblings ...)
2009-11-13 23:28 ` [PATCH 4/5] x86, mm: clean up and simplify NX enablement H. Peter Anvin
@ 2009-11-13 23:28 ` H. Peter Anvin
2009-11-16 22:07 ` [tip:x86/mm] x86, mm: Report " tip-bot for Kees Cook
2009-11-14 0:36 ` [PATCH 0/5] x86: cleanup of NX enabling Kees Cook
5 siblings, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2009-11-13 23:28 UTC (permalink / raw)
To: linux-kernel; +Cc: mingo, tglx, x86, Kees Cook, H. Peter Anvin
From: Kees Cook <kees.cook@canonical.com>
It is possible for x86_64 systems to lack the NX bit either due to the
hardware lacking support or the BIOS having turned off the CPU capability,
so NX status should be reported. Additionally, anyone booting NX-capable
CPUs in 32bit mode without PAE will lack NX functionality, so this change
provides feedback for that case as well.
Signed-off-by: Kees Cook <kees.cook@canonical.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/include/asm/proto.h | 1 +
arch/x86/kernel/setup.c | 11 ++++++-----
arch/x86/mm/init.c | 4 ----
arch/x86/mm/setup_nx.c | 22 ++++++++++++++++++++++
4 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index add7f18..450c56b 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -17,6 +17,7 @@ extern void ia32_sysenter_target(void);
extern void syscall32_cpu_init(void);
extern void x86_configure_nx(void);
+extern void x86_report_nx(void);
extern int reboot_force;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index cdb3ac4..29a645f 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -784,16 +784,17 @@ void __init setup_arch(char **cmdline_p)
*cmdline_p = command_line;
/*
- * Must call this twice: Once just to detect whether hardware doesn't
- * support NX (so that the early EHCI debug console setup can safely
- * call set_fixmap(), and then again after parsing early parameters to
- * honor the respective command line option.
+ * x86_configure_nx() is called before parse_early_param() to detect
+ * whether hardware doesn't support NX (so that the early EHCI debug
+ * console setup can safely call set_fixmap()). It may then be called
+ * again from within noexec_setup() during parsing early parameters
+ * to honor the respective command line option.
*/
x86_configure_nx();
parse_early_param();
- x86_configure_nx();
+ x86_report_nx();
/* Must be before kernel pagetables are setup */
vmi_activate();
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 27ec2c2..d406c52 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -146,10 +146,6 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
use_gbpages = direct_gbpages;
#endif
- /* XXX: replace this with Kees' improved messages */
- if (__supported_pte_mask & _PAGE_NX)
- printk(KERN_INFO "NX (Execute Disable) protection: active\n");
-
/* Enable PSE if available */
if (cpu_has_pse)
set_in_cr4(X86_CR4_PSE);
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 355818b..a3250aa 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -36,3 +36,25 @@ void __cpuinit x86_configure_nx(void)
else
__supported_pte_mask &= ~_PAGE_NX;
}
+
+void __init x86_report_nx(void)
+{
+ if (!cpu_has_nx) {
+ printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
+ "missing in CPU or disabled in BIOS!\n");
+ } else {
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
+ if (disable_nx) {
+ printk(KERN_INFO "NX (Execute Disable) protection: "
+ "disabled by kernel command line option\n");
+ } else {
+ printk(KERN_INFO "NX (Execute Disable) protection: "
+ "active\n");
+ }
+#else
+ /* 32bit non-PAE kernel, NX cannot be used */
+ printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
+ "cannot be enabled: non-PAE kernel!\n");
+#endif
+ }
+}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread* [tip:x86/mm] x86, mm: Report state of NX protections during boot
2009-11-13 23:28 ` [PATCH 5/5] x86, mm: report state of NX protections during boot H. Peter Anvin
@ 2009-11-16 22:07 ` tip-bot for Kees Cook
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Kees Cook @ 2009-11-16 22:07 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, kees.cook, tglx
Commit-ID: 4b0f3b81eb33ef18283aa71440cccfede1753ae0
Gitweb: http://git.kernel.org/tip/4b0f3b81eb33ef18283aa71440cccfede1753ae0
Author: Kees Cook <kees.cook@canonical.com>
AuthorDate: Fri, 13 Nov 2009 15:28:17 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 16 Nov 2009 13:44:59 -0800
x86, mm: Report state of NX protections during boot
It is possible for x86_64 systems to lack the NX bit either due to the
hardware lacking support or the BIOS having turned off the CPU capability,
so NX status should be reported. Additionally, anyone booting NX-capable
CPUs in 32bit mode without PAE will lack NX functionality, so this change
provides feedback for that case as well.
Signed-off-by: Kees Cook <kees.cook@canonical.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
LKML-Reference: <1258154897-6770-6-git-send-email-hpa@zytor.com>
---
arch/x86/include/asm/proto.h | 1 +
arch/x86/kernel/setup.c | 11 ++++++-----
arch/x86/mm/init.c | 4 ----
arch/x86/mm/setup_nx.c | 22 ++++++++++++++++++++++
4 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index add7f18..450c56b 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -17,6 +17,7 @@ extern void ia32_sysenter_target(void);
extern void syscall32_cpu_init(void);
extern void x86_configure_nx(void);
+extern void x86_report_nx(void);
extern int reboot_force;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 23b7f46..d2043a0 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -788,16 +788,17 @@ void __init setup_arch(char **cmdline_p)
*cmdline_p = command_line;
/*
- * Must call this twice: Once just to detect whether hardware doesn't
- * support NX (so that the early EHCI debug console setup can safely
- * call set_fixmap(), and then again after parsing early parameters to
- * honor the respective command line option.
+ * x86_configure_nx() is called before parse_early_param() to detect
+ * whether hardware doesn't support NX (so that the early EHCI debug
+ * console setup can safely call set_fixmap()). It may then be called
+ * again from within noexec_setup() during parsing early parameters
+ * to honor the respective command line option.
*/
x86_configure_nx();
parse_early_param();
- x86_configure_nx();
+ x86_report_nx();
/* Must be before kernel pagetables are setup */
vmi_activate();
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 27ec2c2..d406c52 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -146,10 +146,6 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
use_gbpages = direct_gbpages;
#endif
- /* XXX: replace this with Kees' improved messages */
- if (__supported_pte_mask & _PAGE_NX)
- printk(KERN_INFO "NX (Execute Disable) protection: active\n");
-
/* Enable PSE if available */
if (cpu_has_pse)
set_in_cr4(X86_CR4_PSE);
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 355818b..a3250aa 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -36,3 +36,25 @@ void __cpuinit x86_configure_nx(void)
else
__supported_pte_mask &= ~_PAGE_NX;
}
+
+void __init x86_report_nx(void)
+{
+ if (!cpu_has_nx) {
+ printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
+ "missing in CPU or disabled in BIOS!\n");
+ } else {
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
+ if (disable_nx) {
+ printk(KERN_INFO "NX (Execute Disable) protection: "
+ "disabled by kernel command line option\n");
+ } else {
+ printk(KERN_INFO "NX (Execute Disable) protection: "
+ "active\n");
+ }
+#else
+ /* 32bit non-PAE kernel, NX cannot be used */
+ printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
+ "cannot be enabled: non-PAE kernel!\n");
+#endif
+ }
+}
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] x86: cleanup of NX enabling
2009-11-13 23:28 [RFC] x86: cleanup of NX enabling H. Peter Anvin
` (4 preceding siblings ...)
2009-11-13 23:28 ` [PATCH 5/5] x86, mm: report state of NX protections during boot H. Peter Anvin
@ 2009-11-14 0:36 ` Kees Cook
5 siblings, 0 replies; 13+ messages in thread
From: Kees Cook @ 2009-11-14 0:36 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: linux-kernel, mingo, tglx, x86
On Fri, Nov 13, 2009 at 03:28:17PM -0800, H. Peter Anvin wrote:
> Posting this patch series for review; I intend to commit it to
> tip:x86/mm unless someone objects over the next few days.
>
> This came about based on Kees' original patch to give better dmesg
> information about the status of NX availability.
FWIW, I tested this stack of patches (in an earlier form) with the
following configurations and confirmed expected behavior:
- 64-bit, 64-bit noexec=off
- 32-bit pae with nx bit, x86_32 pae with nx bit noexec=off
- 32-bit pae without nx bit
- 32-bit non-pae
Acked-by: Kees Cook <kees.cook@canonical.com>
--
Kees Cook
Ubuntu Security Team
^ permalink raw reply [flat|nested] 13+ messages in thread