Skip to content

Commit 4074ca7

Browse files
kirylgregkh
authored andcommitted
x86/mm: Move LDT remap out of KASLR region on 5-level paging
commit d52888a upstream On 5-level paging the LDT remap area is placed in the middle of the KASLR randomization region and it can overlap with the direct mapping, the vmalloc or the vmap area. The LDT mapping is per mm, so it cannot be moved into the P4D page table next to the CPU_ENTRY_AREA without complicating PGD table allocation for 5-level paging. The 4 PGD slot gap just before the direct mapping is reserved for hypervisors, so it cannot be used. Move the direct mapping one slot deeper and use the resulting gap for the LDT remap area. The resulting layout is the same for 4 and 5 level paging. [ tglx: Massaged changelog ] Fixes: f55f050 ("x86/pti: Put the LDT in its own PGD if PTI is on") Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Andy Lutomirski <luto@kernel.org> Cc: bp@alien8.de Cc: hpa@zytor.com Cc: dave.hansen@linux.intel.com Cc: peterz@infradead.org Cc: boris.ostrovsky@oracle.com Cc: jgross@suse.com Cc: bhe@redhat.com Cc: willy@infradead.org Cc: linux-mm@kvack.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20181026122856.66224-2-kirill.shutemov@linux.intel.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7818cf3 commit 4074ca7

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎Documentation/x86/x86_64/mm.txt‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Virtual memory map with 4 level page tables:
44
0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm
55
hole caused by [47:63] sign extension
66
ffff800000000000 - ffff87ffffffffff (=43 bits) guard hole, reserved for hypervisor
7-
ffff880000000000 - ffffc7ffffffffff (=64 TB) direct mapping of all phys. memory
8-
ffffc80000000000 - ffffc8ffffffffff (=40 bits) hole
7+
ffff880000000000 - ffff887fffffffff (=39 bits) LDT remap for PTI
8+
ffff888000000000 - ffffc87fffffffff (=64 TB) direct mapping of all phys. memory
9+
ffffc88000000000 - ffffc8ffffffffff (=39 bits) hole
910
ffffc90000000000 - ffffe8ffffffffff (=45 bits) vmalloc/ioremap space
1011
ffffe90000000000 - ffffe9ffffffffff (=40 bits) hole
1112
ffffea0000000000 - ffffeaffffffffff (=40 bits) virtual memory map (1TB)
@@ -30,8 +31,9 @@ Virtual memory map with 5 level page tables:
3031
0000000000000000 - 00ffffffffffffff (=56 bits) user space, different per mm
3132
hole caused by [56:63] sign extension
3233
ff00000000000000 - ff0fffffffffffff (=52 bits) guard hole, reserved for hypervisor
33-
ff10000000000000 - ff8fffffffffffff (=55 bits) direct mapping of all phys. memory
34-
ff90000000000000 - ff9fffffffffffff (=52 bits) LDT remap for PTI
34+
ff10000000000000 - ff10ffffffffffff (=48 bits) LDT remap for PTI
35+
ff11000000000000 - ff90ffffffffffff (=55 bits) direct mapping of all phys. memory
36+
ff91000000000000 - ff9fffffffffffff (=3840 TB) hole
3537
ffa0000000000000 - ffd1ffffffffffff (=54 bits) vmalloc/ioremap space (12800 TB)
3638
ffd2000000000000 - ffd3ffffffffffff (=49 bits) hole
3739
ffd4000000000000 - ffd5ffffffffffff (=49 bits) virtual memory map (512TB)

‎arch/x86/include/asm/page_64_types.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333

3434
/*
3535
* Set __PAGE_OFFSET to the most negative possible address +
36-
* PGDIR_SIZE*16 (pgd slot 272). The gap is to allow a space for a
37-
* hypervisor to fit. Choosing 16 slots here is arbitrary, but it's
38-
* what Xen requires.
36+
* PGDIR_SIZE*17 (pgd slot 273).
37+
*
38+
* The gap is to allow a space for LDT remap for PTI (1 pgd slot) and space for
39+
* a hypervisor (16 slots). Choosing 16 slots for a hypervisor is arbitrary,
40+
* but it's what Xen requires.
3941
*/
40-
#define __PAGE_OFFSET_BASE_L5 _AC(0xff10000000000000, UL)
41-
#define __PAGE_OFFSET_BASE_L4 _AC(0xffff880000000000, UL)
42+
#define __PAGE_OFFSET_BASE_L5 _AC(0xff11000000000000, UL)
43+
#define __PAGE_OFFSET_BASE_L4 _AC(0xffff888000000000, UL)
4244

4345
#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT
4446
#define __PAGE_OFFSET page_offset_base

‎arch/x86/include/asm/pgtable_64_types.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ extern unsigned int ptrs_per_p4d;
111111
*/
112112
#define MAXMEM (1UL << MAX_PHYSMEM_BITS)
113113

114-
#define LDT_PGD_ENTRY_L4 -3UL
115-
#define LDT_PGD_ENTRY_L5 -112UL
116-
#define LDT_PGD_ENTRY (pgtable_l5_enabled() ? LDT_PGD_ENTRY_L5 : LDT_PGD_ENTRY_L4)
114+
#define LDT_PGD_ENTRY -240UL
117115
#define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT)
118116
#define LDT_END_ADDR (LDT_BASE_ADDR + PGDIR_SIZE)
119117

‎arch/x86/xen/mmu_pv.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
18971897
init_top_pgt[0] = __pgd(0);
18981898

18991899
/* Pre-constructed entries are in pfn, so convert to mfn */
1900-
/* L4[272] -> level3_ident_pgt */
1900+
/* L4[273] -> level3_ident_pgt */
19011901
/* L4[511] -> level3_kernel_pgt */
19021902
convert_pfn_mfn(init_top_pgt);
19031903

@@ -1917,8 +1917,8 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
19171917
addr[0] = (unsigned long)pgd;
19181918
addr[1] = (unsigned long)l3;
19191919
addr[2] = (unsigned long)l2;
1920-
/* Graft it onto L4[272][0]. Note that we creating an aliasing problem:
1921-
* Both L4[272][0] and L4[511][510] have entries that point to the same
1920+
/* Graft it onto L4[273][0]. Note that we creating an aliasing problem:
1921+
* Both L4[273][0] and L4[511][510] have entries that point to the same
19221922
* L2 (PMD) tables. Meaning that if you modify it in __va space
19231923
* it will be also modified in the __ka space! (But if you just
19241924
* modify the PMD table to point to other PTE's or none, then you

0 commit comments

Comments
 (0)