Skip to content

Commit b234e8a

Browse files
thgarnieIngo Molnar
authored andcommitted
x86/mm: Separate variable for trampoline PGD
Use a separate global variable to define the trampoline PGD used to start other processors. This change will allow KALSR memory randomization to change the trampoline PGD to be correctly aligned with physical memory. Signed-off-by: Thomas Garnier <[email protected]> Signed-off-by: Kees Cook <[email protected]> Cc: Alexander Kuleshov <[email protected]> Cc: Alexander Popov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Baoquan He <[email protected]> Cc: Boris Ostrovsky <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Dan Williams <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Young <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Jan Beulich <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Lv Zheng <[email protected]> Cc: Mark Salter <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephen Smalley <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Toshi Kani <[email protected]> Cc: Xiao Guangrong <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent faa3793 commit b234e8a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,18 @@ extern int direct_gbpages;
729729
void init_mem_mapping(void);
730730
void early_alloc_pgt_buf(void);
731731

732+
#ifdef CONFIG_X86_64
733+
/* Realmode trampoline initialization. */
734+
extern pgd_t trampoline_pgd_entry;
735+
static inline void __meminit init_trampoline(void)
736+
{
737+
/* Default trampoline pgd value */
738+
trampoline_pgd_entry = init_level4_pgt[pgd_index(__PAGE_OFFSET)];
739+
}
740+
#else
741+
static inline void init_trampoline(void) { }
742+
#endif
743+
732744
/* local pte updates need not use xchg for locking */
733745
static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
734746
{

arch/x86/mm/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ void __init init_mem_mapping(void)
590590
/* the ISA range is always mapped regardless of memory holes */
591591
init_memory_mapping(0, ISA_END_ADDRESS);
592592

593+
/* Init the trampoline, possibly with KASLR memory offset */
594+
init_trampoline();
595+
593596
/*
594597
* If the allocation is in bottom-up direction, we setup direct mapping
595598
* in bottom-up, otherwise we setup direct mapping in top-down.

arch/x86/realmode/init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
struct real_mode_header *real_mode_header;
99
u32 *trampoline_cr4_features;
1010

11+
/* Hold the pgd entry used on booting additional CPUs */
12+
pgd_t trampoline_pgd_entry;
13+
1114
void __init reserve_real_mode(void)
1215
{
1316
phys_addr_t mem;
@@ -84,7 +87,7 @@ void __init setup_real_mode(void)
8487
*trampoline_cr4_features = __read_cr4();
8588

8689
trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
87-
trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
90+
trampoline_pgd[0] = trampoline_pgd_entry.pgd;
8891
trampoline_pgd[511] = init_level4_pgt[511].pgd;
8992
#endif
9093
}

0 commit comments

Comments
 (0)