Received: by 10.223.185.116 with SMTP id b49csp670293wrg; Wed, 14 Feb 2018 05:16:46 -0800 (PST) X-Google-Smtp-Source: AH8x2276KREW/zTDtnTr863Jctaelj4godITCahxLcWwrFKOqtgxIBeJlgFJmTC4R/8dbzrIgFPB X-Received: by 2002:a17:902:b707:: with SMTP id d7-v6mr1760092pls.119.1518614206500; Wed, 14 Feb 2018 05:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518614206; cv=none; d=google.com; s=arc-20160816; b=lgfNYvT+SCHGadZ26nHLytowf7jdFhibTLW++1h5hZ35FXfL//A3V0BMm92TGGzuPy I+3haav+6t1BUPxRtG+L9Xs+h+2qGwJmpJAOKsgfEDfZ1b1/YTpvTw/YiABrsbdoZqJt ho5PTCVHqfceZKuWMTOtqiauVw5xhe/Z3pengQOilE6IcmM+S54gfw6mViAib9/5otPC GzGieFH6CwDWXIKAVjzXi4tVtLWZs7hyX0I5pAcg7NCjm5NJ5apiFYfrEEF0YW1h8d+f EeyRTQykOJXwDIP77emlWzxORRueoyoiLR8HjamRsmKswng/zITZrkEP6U8Bnkv970rI ll0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=63KwfTrtCnbWu4JYYAR8CBhMMKBleQ/DeIAY2ykD5L8=; b=eduhMq5DDgBTV22VXD3ETNDjyq53oEM5ZNinPmY84qrPwbe2acgdDmQLbDP8swbotW sxFQE51erKXO58nos4N6Cjqqj/0xMbdrgSeKiIc/3Vf3PjK43xCDECVl41B5vnePrqtW pobDkEGav0jRlrxz+4sa62jJM0mI1h42mRSUmfnG6MiKD65R0Oka7qd70A6CsGXJJ4HY cTNiR3CsQW7WlotLp34G0zgmQzjuusawTk/W6EgXoeWQLBXlPOF0G6aSaUL88UD8GO4o LVyUEnfGQMgAGRnJGp9zrRM53pXZGmSsOX+/0quRvGsbXSZrjQUdOrJkpy+bryAxfD4z P0LA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si1302498pgs.52.2018.02.14.05.16.31; Wed, 14 Feb 2018 05:16:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967822AbeBNNPt (ORCPT + 99 others); Wed, 14 Feb 2018 08:15:49 -0500 Received: from terminus.zytor.com ([198.137.202.136]:52051 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967717AbeBNNPs (ORCPT ); Wed, 14 Feb 2018 08:15:48 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1ED5N3E026972; Wed, 14 Feb 2018 05:05:23 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1ED5NTO026969; Wed, 14 Feb 2018 05:05:23 -0800 Date: Wed, 14 Feb 2018 05:05:23 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Kirill A. Shutemov" Message-ID: Cc: peterz@infradead.org, luto@amacapital.net, hpa@zytor.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, mingo@kernel.org, bp@suse.de, tglx@linutronix.de, kirill.shutemov@linux.intel.com Reply-To: hpa@zytor.com, torvalds@linux-foundation.org, luto@amacapital.net, peterz@infradead.org, tglx@linutronix.de, kirill.shutemov@linux.intel.com, bp@suse.de, mingo@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20180214111656.88514-4-kirill.shutemov@linux.intel.com> References: <20180214111656.88514-4-kirill.shutemov@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm: Make virtual memory layout dynamic for CONFIG_X86_5LEVEL=y Git-Commit-ID: eedb92abb9bb03ef21442614a6f5867eaac6e77f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: eedb92abb9bb03ef21442614a6f5867eaac6e77f Gitweb: https://git.kernel.org/tip/eedb92abb9bb03ef21442614a6f5867eaac6e77f Author: Kirill A. Shutemov AuthorDate: Wed, 14 Feb 2018 14:16:50 +0300 Committer: Ingo Molnar CommitDate: Wed, 14 Feb 2018 13:11:13 +0100 x86/mm: Make virtual memory layout dynamic for CONFIG_X86_5LEVEL=y We need to be able to adjust virtual memory layout at runtime to be able to switch between 4- and 5-level paging at boot-time. KASLR already has movable __VMALLOC_BASE, __VMEMMAP_BASE and __PAGE_OFFSET. Let's re-use it. Signed-off-by: Kirill A. Shutemov Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180214111656.88514-4-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/Kconfig | 8 ++++++++ arch/x86/include/asm/kaslr.h | 4 ---- arch/x86/include/asm/page_64.h | 4 ++++ arch/x86/include/asm/page_64_types.h | 4 ++-- arch/x86/include/asm/pgtable_64_types.h | 4 ++-- arch/x86/kernel/head64.c | 9 +++++++++ arch/x86/mm/kaslr.c | 8 -------- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 63bf349..9225648 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1430,6 +1430,7 @@ config X86_PAE config X86_5LEVEL bool "Enable 5-level page tables support" + select DYNAMIC_MEMORY_LAYOUT depends on X86_64 ---help--- 5-level paging enables access to larger address space: @@ -2143,10 +2144,17 @@ config PHYSICAL_ALIGN Don't change this unless you know what you are doing. +config DYNAMIC_MEMORY_LAYOUT + bool + ---help--- + This option makes base addresses of vmalloc and vmemmap as well as + __PAGE_OFFSET movable during boot. + config RANDOMIZE_MEMORY bool "Randomize the kernel memory sections" depends on X86_64 depends on RANDOMIZE_BASE + select DYNAMIC_MEMORY_LAYOUT default RANDOMIZE_BASE ---help--- Randomizes the base virtual address of kernel memory sections diff --git a/arch/x86/include/asm/kaslr.h b/arch/x86/include/asm/kaslr.h index 460991e..db7ba2f 100644 --- a/arch/x86/include/asm/kaslr.h +++ b/arch/x86/include/asm/kaslr.h @@ -5,10 +5,6 @@ unsigned long kaslr_get_random_long(const char *purpose); #ifdef CONFIG_RANDOMIZE_MEMORY -extern unsigned long page_offset_base; -extern unsigned long vmalloc_base; -extern unsigned long vmemmap_base; - void kernel_randomize_memory(void); #else static inline void kernel_randomize_memory(void) { } diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index 4baa6bc..09637865 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -11,6 +11,10 @@ extern unsigned long max_pfn; extern unsigned long phys_base; +extern unsigned long page_offset_base; +extern unsigned long vmalloc_base; +extern unsigned long vmemmap_base; + static inline unsigned long __phys_addr_nodebug(unsigned long x) { unsigned long y = x - __START_KERNEL_map; diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h index f68e652..d54a3d5 100644 --- a/arch/x86/include/asm/page_64_types.h +++ b/arch/x86/include/asm/page_64_types.h @@ -43,11 +43,11 @@ #define __PAGE_OFFSET_BASE _AC(0xffff880000000000, UL) #endif -#ifdef CONFIG_RANDOMIZE_MEMORY +#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT #define __PAGE_OFFSET page_offset_base #else #define __PAGE_OFFSET __PAGE_OFFSET_BASE -#endif /* CONFIG_RANDOMIZE_MEMORY */ +#endif /* CONFIG_DYNAMIC_MEMORY_LAYOUT */ #define __START_KERNEL_map _AC(0xffffffff80000000, UL) diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index 7168de7..a0db91a 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -100,13 +100,13 @@ typedef struct { pteval_t pte; } pte_t; # define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT) #endif -#ifdef CONFIG_RANDOMIZE_MEMORY +#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT # define VMALLOC_START vmalloc_base # define VMEMMAP_START vmemmap_base #else # define VMALLOC_START __VMALLOC_BASE # define VMEMMAP_START __VMEMMAP_BASE -#endif /* CONFIG_RANDOMIZE_MEMORY */ +#endif /* CONFIG_DYNAMIC_MEMORY_LAYOUT */ #define VMALLOC_END (VMALLOC_START + _AC((VMALLOC_SIZE_TB << 40) - 1, UL)) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 7ba5d81..bf5c9ba 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -39,6 +39,15 @@ extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; static unsigned int __initdata next_early_pgt; pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX); +#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT +unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE; +EXPORT_SYMBOL(page_offset_base); +unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE; +EXPORT_SYMBOL(vmalloc_base); +unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE; +EXPORT_SYMBOL(vmemmap_base); +#endif + #define __head __section(.head.text) static void __head *fixup_pointer(void *ptr, unsigned long physaddr) diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index aedebd2..515b98a 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c @@ -43,14 +43,6 @@ static const unsigned long vaddr_start = __PAGE_OFFSET_BASE; static const unsigned long vaddr_end = CPU_ENTRY_AREA_BASE; -/* Default values */ -unsigned long page_offset_base = __PAGE_OFFSET_BASE; -EXPORT_SYMBOL(page_offset_base); -unsigned long vmalloc_base = __VMALLOC_BASE; -EXPORT_SYMBOL(vmalloc_base); -unsigned long vmemmap_base = __VMEMMAP_BASE; -EXPORT_SYMBOL(vmemmap_base); - /* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This