aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>2018-11-30 15:23:27 -0500
committerThomas Gleixner <tglx@linutronix.de>2018-12-11 05:19:24 -0500
commit16877a5570e0c5f4270d5b17f9bab427bcae9514 (patch)
treeb915b29ee748f254aa810b46fa33119434c0e55a
parentac3e233d29f7f77f28243af0132057d378d3ea58 (diff)
x86/mm: Fix guard hole handling
There is a guard hole at the beginning of the kernel address space, also used by hypervisors. It occupies 16 PGD entries. This reserved range is not defined explicitely, it is calculated relative to other entities: direct mapping and user space ranges. The calculation got broken by recent changes of the kernel memory layout: LDT remap range is now mapped before direct mapping and makes the calculation invalid. The breakage leads to crash on Xen dom0 boot[1]. Define the reserved range explicitely. It's part of kernel ABI (hypervisors expect it to be stable) and must not depend on changes in the rest of kernel memory layout. [1] https://lists.xenproject.org/archives/html/xen-devel/2018-11/msg03313.html Fixes: d52888aa2753 ("x86/mm: Move LDT remap out of KASLR region on 5-level paging") Reported-by: Hans van Kranenburg <hans.van.kranenburg@mendix.com> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Hans van Kranenburg <hans.van.kranenburg@mendix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Cc: bp@alien8.de Cc: hpa@zytor.com Cc: dave.hansen@linux.intel.com Cc: luto@kernel.org Cc: peterz@infradead.org Cc: boris.ostrovsky@oracle.com Cc: bhe@redhat.com Cc: linux-mm@kvack.org Cc: xen-devel@lists.xenproject.org Link: https://lkml.kernel.org/r/20181130202328.65359-2-kirill.shutemov@linux.intel.com
-rw-r--r--arch/x86/include/asm/pgtable_64_types.h5
-rw-r--r--arch/x86/mm/dump_pagetables.c8
-rw-r--r--arch/x86/xen/mmu_pv.c11
3 files changed, 15 insertions, 9 deletions
diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
index 84bd9bdc1987..88bca456da99 100644
--- a/arch/x86/include/asm/pgtable_64_types.h
+++ b/arch/x86/include/asm/pgtable_64_types.h
@@ -111,6 +111,11 @@ extern unsigned int ptrs_per_p4d;
111 */ 111 */
112#define MAXMEM (1UL << MAX_PHYSMEM_BITS) 112#define MAXMEM (1UL << MAX_PHYSMEM_BITS)
113 113
114#define GUARD_HOLE_PGD_ENTRY -256UL
115#define GUARD_HOLE_SIZE (16UL << PGDIR_SHIFT)
116#define GUARD_HOLE_BASE_ADDR (GUARD_HOLE_PGD_ENTRY << PGDIR_SHIFT)
117#define GUARD_HOLE_END_ADDR (GUARD_HOLE_BASE_ADDR + GUARD_HOLE_SIZE)
118
114#define LDT_PGD_ENTRY -240UL 119#define LDT_PGD_ENTRY -240UL
115#define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT) 120#define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT)
116#define LDT_END_ADDR (LDT_BASE_ADDR + PGDIR_SIZE) 121#define LDT_END_ADDR (LDT_BASE_ADDR + PGDIR_SIZE)
diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index fc37bbd23eb8..dad153e5a427 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -512,11 +512,11 @@ static inline bool is_hypervisor_range(int idx)
512{ 512{
513#ifdef CONFIG_X86_64 513#ifdef CONFIG_X86_64
514 /* 514 /*
515 * ffff800000000000 - ffff87ffffffffff is reserved for 515 * A hole in the beginning of kernel address space reserved
516 * the hypervisor. 516 * for a hypervisor.
517 */ 517 */
518 return (idx >= pgd_index(__PAGE_OFFSET) - 16) && 518 return (idx >= pgd_index(GUARD_HOLE_BASE_ADDR)) &&
519 (idx < pgd_index(__PAGE_OFFSET)); 519 (idx < pgd_index(GUARD_HOLE_END_ADDR));
520#else 520#else
521 return false; 521 return false;
522#endif 522#endif
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index a5d7ed125337..0f4fe206dcc2 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -648,19 +648,20 @@ static int __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd,
648 unsigned long limit) 648 unsigned long limit)
649{ 649{
650 int i, nr, flush = 0; 650 int i, nr, flush = 0;
651 unsigned hole_low, hole_high; 651 unsigned hole_low = 0, hole_high = 0;
652 652
653 /* The limit is the last byte to be touched */ 653 /* The limit is the last byte to be touched */
654 limit--; 654 limit--;
655 BUG_ON(limit >= FIXADDR_TOP); 655 BUG_ON(limit >= FIXADDR_TOP);
656 656
657#ifdef CONFIG_X86_64
657 /* 658 /*
658 * 64-bit has a great big hole in the middle of the address 659 * 64-bit has a great big hole in the middle of the address
659 * space, which contains the Xen mappings. On 32-bit these 660 * space, which contains the Xen mappings.
660 * will end up making a zero-sized hole and so is a no-op.
661 */ 661 */
662 hole_low = pgd_index(USER_LIMIT); 662 hole_low = pgd_index(GUARD_HOLE_BASE_ADDR);
663 hole_high = pgd_index(PAGE_OFFSET); 663 hole_high = pgd_index(GUARD_HOLE_END_ADDR);
664#endif
664 665
665 nr = pgd_index(limit) + 1; 666 nr = pgd_index(limit) + 1;
666 for (i = 0; i < nr; i++) { 667 for (i = 0; i < nr; i++) {