Skip to content

Commit b976690

Browse files
joergroedelKAGA-KOKO
authored andcommitted
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
1 parent 1ac228a commit b976690

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

arch/x86/include/asm/pti.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#ifdef CONFIG_PAGE_TABLE_ISOLATION
77
extern void pti_init(void);
88
extern void pti_check_boottime_disable(void);
9-
extern void pti_clone_kernel_text(void);
9+
extern void pti_finalize(void);
1010
#else
1111
static inline void pti_check_boottime_disable(void) { }
12-
static inline void pti_clone_kernel_text(void) { }
1312
#endif
1413

1514
#endif /* __ASSEMBLY__ */

arch/x86/mm/init_64.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,6 @@ void mark_rodata_ro(void)
12911291
(unsigned long) __va(__pa_symbol(_sdata)));
12921292

12931293
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();
13001294
}
13011295

13021296
int kern_addr_valid(unsigned long addr)

arch/x86/mm/pti.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static inline bool pti_kernel_image_global_ok(void)
462462
* For some configurations, map all of kernel text into the user page
463463
* tables. This reduces TLB misses, especially on non-PCID systems.
464464
*/
465-
void pti_clone_kernel_text(void)
465+
static void pti_clone_kernel_text(void)
466466
{
467467
/*
468468
* rodata is part of the kernel image and is normally
@@ -526,3 +526,15 @@ void __init pti_init(void)
526526
pti_setup_espfix64();
527527
pti_setup_vsyscall();
528528
}
529+
530+
/*
531+
* Finalize the kernel mappings in the userspace page-table.
532+
*/
533+
void 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+
}

include/linux/pti.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <asm/pti.h>
77
#else
88
static inline void pti_init(void) { }
9+
static inline void pti_finalize(void) { }
910
#endif
1011

1112
#endif

init/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,13 @@ static int __ref kernel_init(void *unused)
10651065
jump_label_invalidate_initmem();
10661066
free_initmem();
10671067
mark_readonly();
1068+
1069+
/*
1070+
* Kernel mappings are now finalized - update the userspace page-table
1071+
* to finalize PTI.
1072+
*/
1073+
pti_finalize();
1074+
10681075
system_state = SYSTEM_RUNNING;
10691076
numa_default_policy();
10701077

0 commit comments

Comments
 (0)