aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2018-07-18 05:41:06 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-07-19 19:11:45 -0400
commitb976690f5db26fbc7c2be413bfa0fbd270547a94 (patch)
treec4335658e52551a0eb1c724c294cc82d78013b7c
parent1ac228a7c87f697d1d01eb6362a6b5246705b0dd (diff)
x86/mm/pti: Introduce pti_finalize()
Introduce a new function to finalize the kernel mappings for the userspace page-table after all ro/nx protections have been applied to the kernel mappings. Also move the call to pti_clone_kernel_text() to that function so that it will run on 32 bit kernels too. Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Pavel Machek <pavel@ucw.cz> Cc: "H . Peter Anvin" <hpa@zytor.com> Cc: linux-mm@kvack.org Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Brian Gerst <brgerst@gmail.com> Cc: David Laight <David.Laight@aculab.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Will Deacon <will.deacon@arm.com> Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Waiman Long <llong@redhat.com> Cc: "David H . Gutteridge" <dhgutteridge@sympatico.ca> Cc: joro@8bytes.org Link: https://lkml.kernel.org/r/1531906876-13451-30-git-send-email-joro@8bytes.org
-rw-r--r--arch/x86/include/asm/pti.h3
-rw-r--r--arch/x86/mm/init_64.c6
-rw-r--r--arch/x86/mm/pti.c14
-rw-r--r--include/linux/pti.h1
-rw-r--r--init/main.c7
5 files changed, 22 insertions, 9 deletions
diff --git a/arch/x86/include/asm/pti.h b/arch/x86/include/asm/pti.h
index 38a17f1d5c9d..5df09a0b80b8 100644
--- a/arch/x86/include/asm/pti.h
+++ b/arch/x86/include/asm/pti.h
@@ -6,10 +6,9 @@
6#ifdef CONFIG_PAGE_TABLE_ISOLATION 6#ifdef CONFIG_PAGE_TABLE_ISOLATION
7extern void pti_init(void); 7extern void pti_init(void);
8extern void pti_check_boottime_disable(void); 8extern void pti_check_boottime_disable(void);
9extern void pti_clone_kernel_text(void); 9extern void pti_finalize(void);
10#else 10#else
11static inline void pti_check_boottime_disable(void) { } 11static inline void pti_check_boottime_disable(void) { }
12static inline void pti_clone_kernel_text(void) { }
13#endif 12#endif
14 13
15#endif /* __ASSEMBLY__ */ 14#endif /* __ASSEMBLY__ */
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a688617c727e..9b19f9a8948e 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1291,12 +1291,6 @@ void mark_rodata_ro(void)
1291 (unsigned long) __va(__pa_symbol(_sdata))); 1291 (unsigned long) __va(__pa_symbol(_sdata)));
1292 1292
1293 debug_checkwx(); 1293 debug_checkwx();
1294
1295 /*
1296 * Do this after all of the manipulation of the
1297 * kernel text page tables are complete.
1298 */
1299 pti_clone_kernel_text();
1300} 1294}
1301 1295
1302int kern_addr_valid(unsigned long addr) 1296int kern_addr_valid(unsigned long addr)
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index e41ee93c430d..fcfb815d420f 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -462,7 +462,7 @@ static inline bool pti_kernel_image_global_ok(void)
462 * For some configurations, map all of kernel text into the user page 462 * For some configurations, map all of kernel text into the user page
463 * tables. This reduces TLB misses, especially on non-PCID systems. 463 * tables. This reduces TLB misses, especially on non-PCID systems.
464 */ 464 */
465void pti_clone_kernel_text(void) 465static void pti_clone_kernel_text(void)
466{ 466{
467 /* 467 /*
468 * rodata is part of the kernel image and is normally 468 * rodata is part of the kernel image and is normally
@@ -526,3 +526,15 @@ void __init pti_init(void)
526 pti_setup_espfix64(); 526 pti_setup_espfix64();
527 pti_setup_vsyscall(); 527 pti_setup_vsyscall();
528} 528}
529
530/*
531 * Finalize the kernel mappings in the userspace page-table.
532 */
533void pti_finalize(void)
534{
535 /*
536 * Do this after all of the manipulation of the
537 * kernel text page tables are complete.
538 */
539 pti_clone_kernel_text();
540}
diff --git a/include/linux/pti.h b/include/linux/pti.h
index 0174883a935a..1a941efcaa62 100644
--- a/include/linux/pti.h
+++ b/include/linux/pti.h
@@ -6,6 +6,7 @@
6#include <asm/pti.h> 6#include <asm/pti.h>
7#else 7#else
8static inline void pti_init(void) { } 8static inline void pti_init(void) { }
9static inline void pti_finalize(void) { }
9#endif 10#endif
10 11
11#endif 12#endif
diff --git a/init/main.c b/init/main.c
index 3b4ada11ed52..fcfef46c935a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1065,6 +1065,13 @@ static int __ref kernel_init(void *unused)
1065 jump_label_invalidate_initmem(); 1065 jump_label_invalidate_initmem();
1066 free_initmem(); 1066 free_initmem();
1067 mark_readonly(); 1067 mark_readonly();
1068
1069 /*
1070 * Kernel mappings are now finalized - update the userspace page-table
1071 * to finalize PTI.
1072 */
1073 pti_finalize();
1074
1068 system_state = SYSTEM_RUNNING; 1075 system_state = SYSTEM_RUNNING;
1069 numa_default_policy(); 1076 numa_default_policy();
1070 1077