All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] x86/mm: A _PAGE_NX fixlet and a kmap cleanup
@ 2016-01-19 21:38 Andy Lutomirski
  2016-01-19 21:38 ` [PATCH v2 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging Andy Lutomirski
  2016-01-19 21:38 ` [PATCH v2 2/2] x86/mm: Make kmap_prot into a #define Andy Lutomirski
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Lutomirski @ 2016-01-19 21:38 UTC (permalink / raw)
  To: x86
  Cc: Arjan van de Ven, Linus Torvalds, Borislav Petkov, linux-kernel,
	Stephen Smalley, Brian Gerst, Denys Vlasenko, hpa,
	Mike Galbraith, Peter Zijlstra, Pavel Machek, Andy Lutomirski

The fixlet might help with some WX warnings.  The kmap cleanup is
just a cleanup.

This is very lightly tested.

Changes from v1:
 - Rebased on top of the cpu_has_xyz cleanups.

Andy Lutomirski (2):
  x86_32/mm: Set NX in __supported_pte_mask before enabling paging
  x86/mm: Make kmap_prot into a #define

 arch/x86/include/asm/fixmap.h | 2 +-
 arch/x86/kernel/head_32.S     | 6 ++++++
 arch/x86/mm/init_32.c         | 3 ---
 arch/x86/mm/setup_nx.c        | 5 ++---
 4 files changed, 9 insertions(+), 7 deletions(-)

-- 
2.5.0

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

* [PATCH v2 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging
  2016-01-19 21:38 [PATCH v2 0/2] x86/mm: A _PAGE_NX fixlet and a kmap cleanup Andy Lutomirski
@ 2016-01-19 21:38 ` Andy Lutomirski
  2016-01-20 11:12   ` [tip:x86/mm] x86/mm/32: " tip-bot for Andy Lutomirski
  2016-01-19 21:38 ` [PATCH v2 2/2] x86/mm: Make kmap_prot into a #define Andy Lutomirski
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2016-01-19 21:38 UTC (permalink / raw)
  To: x86
  Cc: Arjan van de Ven, Linus Torvalds, Borislav Petkov, linux-kernel,
	Stephen Smalley, Brian Gerst, Denys Vlasenko, hpa,
	Mike Galbraith, Peter Zijlstra, Pavel Machek, Andy Lutomirski

There's a short window in which very early mappings can end up with
NX clear because they are created before we've noticed that we have
NX.

It turns out that we detect NX very early, so there's no need to
defer __supported_pte_mask setup.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/kernel/head_32.S | 6 ++++++
 arch/x86/mm/setup_nx.c    | 5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 6bc9ae24b6d2..57fc3f8c85fd 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -389,6 +389,12 @@ default_entry:
 	/* Make changes effective */
 	wrmsr
 
+	/*
+	 * And make sure that all the mappings we set up have NX set from
+	 * the beginning.
+	 */
+	orl $(1 << (_PAGE_BIT_NX - 32)), pa(__supported_pte_mask + 4)
+
 enable_paging:
 
 /*
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 92e2eacb3321..78f5d5907f98 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -31,9 +31,8 @@ early_param("noexec", noexec_setup);
 
 void x86_configure_nx(void)
 {
-	if (boot_cpu_has(X86_FEATURE_NX) && !disable_nx)
-		__supported_pte_mask |= _PAGE_NX;
-	else
+	/* If disable_nx is set, clear NX on all new mappings going forward. */
+	if (disable_nx)
 		__supported_pte_mask &= ~_PAGE_NX;
 }
 
-- 
2.5.0

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

* [PATCH v2 2/2] x86/mm: Make kmap_prot into a #define
  2016-01-19 21:38 [PATCH v2 0/2] x86/mm: A _PAGE_NX fixlet and a kmap cleanup Andy Lutomirski
  2016-01-19 21:38 ` [PATCH v2 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging Andy Lutomirski
@ 2016-01-19 21:38 ` Andy Lutomirski
  2016-01-20 11:13   ` [tip:x86/mm] " tip-bot for Andy Lutomirski
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2016-01-19 21:38 UTC (permalink / raw)
  To: x86
  Cc: Arjan van de Ven, Linus Torvalds, Borislav Petkov, linux-kernel,
	Stephen Smalley, Brian Gerst, Denys Vlasenko, hpa,
	Mike Galbraith, Peter Zijlstra, Pavel Machek, Andy Lutomirski

The value (once we initialize it) is a foregone conclusion.  Make it
a #define to save a tiny amount of text and data size and to make it
more comprehensible.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/include/asm/fixmap.h | 2 +-
 arch/x86/mm/init_32.c         | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index 32c60a02ec80..ce941b7e7900 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -142,7 +142,7 @@ extern void reserve_top_address(unsigned long reserve);
 extern int fixmaps_set;
 
 extern pte_t *kmap_pte;
-extern pgprot_t kmap_prot;
+#define kmap_prot PAGE_KERNEL
 extern pte_t *pkmap_page_table;
 
 void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index cb4ef3de61f9..a4bb1c7ab65e 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -388,7 +388,6 @@ repeat:
 }
 
 pte_t *kmap_pte;
-pgprot_t kmap_prot;
 
 static inline pte_t *kmap_get_fixmap_pte(unsigned long vaddr)
 {
@@ -405,8 +404,6 @@ static void __init kmap_init(void)
 	 */
 	kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
 	kmap_pte = kmap_get_fixmap_pte(kmap_vstart);
-
-	kmap_prot = PAGE_KERNEL;
 }
 
 #ifdef CONFIG_HIGHMEM
-- 
2.5.0

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

* [tip:x86/mm] x86/mm/32: Set NX in __supported_pte_mask before enabling paging
  2016-01-19 21:38 ` [PATCH v2 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging Andy Lutomirski
@ 2016-01-20 11:12   ` tip-bot for Andy Lutomirski
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Andy Lutomirski @ 2016-01-20 11:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, peterz, brgerst, torvalds, tglx, efault, luto, hpa,
	mingo, luto, sds, pavel, bp, dvlasenk, arjan

Commit-ID:  320d25b6a05f8b73c23fc21025d2906ecdd2d4fc
Gitweb:     http://git.kernel.org/tip/320d25b6a05f8b73c23fc21025d2906ecdd2d4fc
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Tue, 19 Jan 2016 13:38:58 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 20 Jan 2016 11:39:14 +0100

x86/mm/32: Set NX in __supported_pte_mask before enabling paging

There's a short window in which very early mappings can end up
with NX clear because they are created before we've noticed that
we have NX.

It turns out that we detect NX very early, so there's no need to
defer __supported_pte_mask setup.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/2b544627345f7110160545a3f47031eb45c3ad4f.1453239349.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/head_32.S | 6 ++++++
 arch/x86/mm/setup_nx.c    | 5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 6bc9ae2..57fc3f8 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -389,6 +389,12 @@ default_entry:
 	/* Make changes effective */
 	wrmsr
 
+	/*
+	 * And make sure that all the mappings we set up have NX set from
+	 * the beginning.
+	 */
+	orl $(1 << (_PAGE_BIT_NX - 32)), pa(__supported_pte_mask + 4)
+
 enable_paging:
 
 /*
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index 92e2eac..78f5d59 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -31,9 +31,8 @@ early_param("noexec", noexec_setup);
 
 void x86_configure_nx(void)
 {
-	if (boot_cpu_has(X86_FEATURE_NX) && !disable_nx)
-		__supported_pte_mask |= _PAGE_NX;
-	else
+	/* If disable_nx is set, clear NX on all new mappings going forward. */
+	if (disable_nx)
 		__supported_pte_mask &= ~_PAGE_NX;
 }
 

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

* [tip:x86/mm] x86/mm: Make kmap_prot into a #define
  2016-01-19 21:38 ` [PATCH v2 2/2] x86/mm: Make kmap_prot into a #define Andy Lutomirski
@ 2016-01-20 11:13   ` tip-bot for Andy Lutomirski
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Andy Lutomirski @ 2016-01-20 11:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, pavel, mingo, brgerst, arjan, sds, efault, peterz,
	torvalds, dvlasenk, linux-kernel, bp, luto, hpa, luto

Commit-ID:  7c360572b430a0e9757bafc0c20f26c920f2a07f
Gitweb:     http://git.kernel.org/tip/7c360572b430a0e9757bafc0c20f26c920f2a07f
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Tue, 19 Jan 2016 13:38:59 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 20 Jan 2016 11:39:14 +0100

x86/mm: Make kmap_prot into a #define

The value (once we initialize it) is a foregone conclusion.
Make it a #define to save a tiny amount of text and data size
and to make it more comprehensible.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/0850eb0213de9da88544ff7fae72dc6d06d2b441.1453239349.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fixmap.h | 2 +-
 arch/x86/mm/init_32.c         | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index 6d7d0e5..8554f96 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -138,7 +138,7 @@ extern void reserve_top_address(unsigned long reserve);
 extern int fixmaps_set;
 
 extern pte_t *kmap_pte;
-extern pgprot_t kmap_prot;
+#define kmap_prot PAGE_KERNEL
 extern pte_t *pkmap_page_table;
 
 void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index cb4ef3d..a4bb1c7 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -388,7 +388,6 @@ repeat:
 }
 
 pte_t *kmap_pte;
-pgprot_t kmap_prot;
 
 static inline pte_t *kmap_get_fixmap_pte(unsigned long vaddr)
 {
@@ -405,8 +404,6 @@ static void __init kmap_init(void)
 	 */
 	kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
 	kmap_pte = kmap_get_fixmap_pte(kmap_vstart);
-
-	kmap_prot = PAGE_KERNEL;
 }
 
 #ifdef CONFIG_HIGHMEM

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

end of thread, other threads:[~2016-01-20 11:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19 21:38 [PATCH v2 0/2] x86/mm: A _PAGE_NX fixlet and a kmap cleanup Andy Lutomirski
2016-01-19 21:38 ` [PATCH v2 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging Andy Lutomirski
2016-01-20 11:12   ` [tip:x86/mm] x86/mm/32: " tip-bot for Andy Lutomirski
2016-01-19 21:38 ` [PATCH v2 2/2] x86/mm: Make kmap_prot into a #define Andy Lutomirski
2016-01-20 11:13   ` [tip:x86/mm] " tip-bot for Andy Lutomirski

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.