All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86, 64bit: do not assume CPU is NX capable when setting early page tables
@ 2013-05-02  6:40 Fernando Luis Vázquez Cao
  2013-05-02 18:33 ` [tip:x86/urgent] x86-64, init: Do not set NX bits on non-NX capable hardware tip-bot for H. Peter Anvin
  0 siblings, 1 reply; 4+ messages in thread
From: Fernando Luis Vázquez Cao @ 2013-05-02  6:40 UTC (permalink / raw)
  To: H. Peter Anvin, Yinghai Lu; +Cc: x86, linux-kernel

The kernel sets the NX bit in the early page tables without checking whether
the CPU actually supports this feature. If it doesn't the first attempt to use
them will cause a kernel hang. Since these are temporary page tables marked as
initdata this fix takes the approach of not bothering with the NX bit at all.

Noticed when my AMD machine that happened to have the NX feature disabled by
the BIOS failed to boot after the update to 3.9.

Cc: stable@vger.kernel.org
Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
---

diff -urNp linux-3.9/arch/x86/kernel/head64.c linux-3.9-fix/arch/x86/kernel/head64.c
--- linux-3.9/arch/x86/kernel/head64.c	2013-04-29 09:36:01.000000000 +0900
+++ linux-3.9-fix/arch/x86/kernel/head64.c	2013-05-02 14:38:52.589276092 +0900
@@ -99,7 +99,7 @@ again:
 			pmd_p[i] = 0;
 		*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
 	}
-	pmd = (physaddr & PMD_MASK) + (__PAGE_KERNEL_LARGE & ~_PAGE_GLOBAL);
+	pmd = (physaddr & PMD_MASK) + (__PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL);
 	pmd_p[pmd_index(address)] = pmd;
 
 	return 0;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:x86/urgent] x86-64, init: Do not set NX bits on non-NX capable hardware
  2013-05-02  6:40 [PATCH] x86, 64bit: do not assume CPU is NX capable when setting early page tables Fernando Luis Vázquez Cao
@ 2013-05-02 18:33 ` tip-bot for H. Peter Anvin
  2013-05-11  5:57   ` Yuhong Bao
  0 siblings, 1 reply; 4+ messages in thread
From: tip-bot for H. Peter Anvin @ 2013-05-02 18:33 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, fernando, tglx, hpa

Commit-ID:  78d77df71510a96e042de7ba6dbd7998103642cb
Gitweb:     http://git.kernel.org/tip/78d77df71510a96e042de7ba6dbd7998103642cb
Author:     H. Peter Anvin <hpa@linux.intel.com>
AuthorDate: Thu, 2 May 2013 10:33:46 -0700
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Thu, 2 May 2013 11:27:35 -0700

x86-64, init: Do not set NX bits on non-NX capable hardware

During early init, we would incorrectly set the NX bit even if the NX
feature was not supported.  Instead, only set this bit if NX is
actually available and enabled.  We already do very early detection of
the NX bit to enable it in EFER, this simply extends this detection to
the early page table mask.

Reported-by: Fernando Luis Vázquez Cao <fernando@oss.ntt.co.jp>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Link: http://lkml.kernel.org/r/1367476850.5660.2.camel@nexus
Cc: <stable@vger.kernel.org> v3.9
---
 arch/x86/kernel/head64.c  | 3 ++-
 arch/x86/kernel/head_64.S | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 101ac1a9..dab95a8 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -34,6 +34,7 @@
 extern pgd_t early_level4_pgt[PTRS_PER_PGD];
 extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD];
 static unsigned int __initdata next_early_pgt = 2;
+pmdval_t __initdata early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);
 
 /* Wipe all early page tables except for the kernel symbol map */
 static void __init reset_early_page_tables(void)
@@ -99,7 +100,7 @@ again:
 			pmd_p[i] = 0;
 		*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
 	}
-	pmd = (physaddr & PMD_MASK) + (__PAGE_KERNEL_LARGE & ~_PAGE_GLOBAL);
+	pmd = (physaddr & PMD_MASK) + early_pmd_flags;
 	pmd_p[pmd_index(address)] = pmd;
 
 	return 0;
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 6859e96..08f7e80 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -200,6 +200,7 @@ ENTRY(secondary_startup_64)
 	btl	$20,%edi		/* No Execute supported? */
 	jnc     1f
 	btsl	$_EFER_NX, %eax
+	btsq	$_PAGE_BIT_NX,early_pmd_flags(%rip)
 1:	wrmsr				/* Make changes effective */
 
 	/* Setup cr0 */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [tip:x86/urgent] x86-64, init:  Do not set NX bits on non-NX capable hardware
  2013-05-02 18:33 ` [tip:x86/urgent] x86-64, init: Do not set NX bits on non-NX capable hardware tip-bot for H. Peter Anvin
@ 2013-05-11  5:57   ` Yuhong Bao
  2013-05-11 14:55     ` H. Peter Anvin
  0 siblings, 1 reply; 4+ messages in thread
From: Yuhong Bao @ 2013-05-11  5:57 UTC (permalink / raw)
  To: mingo, linux-tip-commits; +Cc: linux-kernel, hpa, fernando, tglx, hpa

(resending as plaintext)
> During early init, we would incorrectly set the NX bit even if the NX
> feature was not supported.  Instead, only set this bit if NX is
> actually available and enabled.  We already do very early detection of
> the NX bit to enable it in EFER, this simply extends this detection to
> the early page table mask.
AFAIK the only production x86-64 processor that don't support NX that I know of is the original Nocona D0 stepping.
Must more common are the problem of BIOSes disabling the NX feature.


Yuhong Bao 		 	   		  

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [tip:x86/urgent] x86-64, init:  Do not set NX bits on non-NX capable hardware
  2013-05-11  5:57   ` Yuhong Bao
@ 2013-05-11 14:55     ` H. Peter Anvin
  0 siblings, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2013-05-11 14:55 UTC (permalink / raw)
  To: Yuhong Bao, mingo, linux-tip-commits; +Cc: linux-kernel, fernando, tglx, hpa

Yes... But both apply.

Yuhong Bao <yuhongbao_386@hotmail.com> wrote:

>(resending as plaintext)
>> During early init, we would incorrectly set the NX bit even if the NX
>> feature was not supported.  Instead, only set this bit if NX is
>> actually available and enabled.  We already do very early detection
>of
>> the NX bit to enable it in EFER, this simply extends this detection
>to
>> the early page table mask.
>AFAIK the only production x86-64 processor that don't support NX that I
>know of is the original Nocona D0 stepping.
>Must more common are the problem of BIOSes disabling the NX feature.
>
>
>Yuhong Bao 		 	   		  

-- 
Sent from my mobile phone. Please excuse brevity and lack of formatting.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-11 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-02  6:40 [PATCH] x86, 64bit: do not assume CPU is NX capable when setting early page tables Fernando Luis Vázquez Cao
2013-05-02 18:33 ` [tip:x86/urgent] x86-64, init: Do not set NX bits on non-NX capable hardware tip-bot for H. Peter Anvin
2013-05-11  5:57   ` Yuhong Bao
2013-05-11 14:55     ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.