Received: by 10.223.185.116 with SMTP id b49csp674074wrg; Wed, 14 Feb 2018 05:20:25 -0800 (PST) X-Google-Smtp-Source: AH8x226WmIPhYYUgpQYXqjE89WT2Gae4WpIi7SOcvVEr2aav4OIdOfCbHZVeQxGyq51LrSDGlRgY X-Received: by 10.167.129.129 with SMTP id g1mr2203746pfi.224.1518614425119; Wed, 14 Feb 2018 05:20:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518614425; cv=none; d=google.com; s=arc-20160816; b=xKwjmMbOzNf6697LRJTcTgu2901xfqeWKzlb6U/FScO6GesYydURFumiIZokf9SWDt +Bhg+WXhNT0HX2IoniBZrIP5Odp4w3QPX0h5FPCsmBUQEVyM+enpkv/H+/ElNukMXDrT r/W558lcBNwVWWwubjBwTLVqBQ+99THXZcNVvAl0dWgEdrAKdnJZ1GzpokcQH/rHFn0w M/gAGg4Nlwj4jmjJqn/XcYOXQUkUv3jb7sfgLf5+ac3ZJTIBvDyuvgCxBTSwfWkgk/iG VFCBxQkqowHee7/So/gt6n+oT3bBPWiumQ15mQ8FuKhB0wr3iwAP+SYfT8S+crcm6jmG 0dnQ== 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=N5UPdu6Tf+VUeWNaMNYF/DNyUiglcCmVUxrS9AtBQLs=; b=gNV2P2lYJ49asn9x/J96BR8IJZrdc22g/HAVptUGtBW6ko2bwiVAEcqENmVynAPhmu lLNXk8VpF+frnRk4AJreHDuxlRc2rEC1WPA6ysiGZ3IICx4LPk8aWoJav6Pr7VfOlcJC lussYMnzkZPDdLCN0WtrwwQ8klwc8YZdl1m98CU/MmFHAx4kB8WBpDNQqsWf/sxuIHTD RScO9WgL+CBoWneVg24tk+2aebO69MbsWTuQxumivSdQiOt+K4KSsR3f4vvJMhL2+W68 1VVn9fVzDoZJWvejbQLLY1gSZkX/PSk1kr0f267gEws45yUf+GS+Zb6McA52bue/LqMb r4xA== 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 h75si1254537pfh.395.2018.02.14.05.20.10; Wed, 14 Feb 2018 05:20:25 -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 S1030293AbeBNNSO (ORCPT + 99 others); Wed, 14 Feb 2018 08:18:14 -0500 Received: from terminus.zytor.com ([198.137.202.136]:47373 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030219AbeBNNSM (ORCPT ); Wed, 14 Feb 2018 08:18:12 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1ED7piT027640; Wed, 14 Feb 2018 05:07:51 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1ED7pQq027636; Wed, 14 Feb 2018 05:07:51 -0800 Date: Wed, 14 Feb 2018 05:07:51 -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: tglx@linutronix.de, peterz@infradead.org, bp@suse.de, hpa@zytor.com, luto@amacapital.net, torvalds@linux-foundation.org, mingo@kernel.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com Reply-To: torvalds@linux-foundation.org, mingo@kernel.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, bp@suse.de, luto@amacapital.net In-Reply-To: <20180214111656.88514-9-kirill.shutemov@linux.intel.com> References: <20180214111656.88514-9-kirill.shutemov@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm: Make __VIRTUAL_MASK_SHIFT dynamic Git-Commit-ID: 09e61a779e7f171c50325e6d7108a593afb2e5d4 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: 09e61a779e7f171c50325e6d7108a593afb2e5d4 Gitweb: https://git.kernel.org/tip/09e61a779e7f171c50325e6d7108a593afb2e5d4 Author: Kirill A. Shutemov AuthorDate: Wed, 14 Feb 2018 14:16:55 +0300 Committer: Ingo Molnar CommitDate: Wed, 14 Feb 2018 13:11:15 +0100 x86/mm: Make __VIRTUAL_MASK_SHIFT dynamic For boot-time switching between paging modes, we need to be able to adjust virtual mask shifts. The change doesn't affect the kernel image size much: text data bss dec hex filename 8628892 4734340 1368064 14731296 e0c820 vmlinux.before 8628966 4734340 1368064 14731370 e0c86a vmlinux.after 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-9-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/entry/entry_64.S | 12 ++++++++++++ arch/x86/include/asm/page_64_types.h | 2 +- arch/x86/mm/dump_pagetables.c | 12 ++++++++++-- arch/x86/mm/kaslr.c | 4 +++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 30c8c53..2c06348 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -274,8 +274,20 @@ GLOBAL(entry_SYSCALL_64_after_hwframe) * Change top bits to match most significant bit (47th or 56th bit * depending on paging mode) in the address. */ +#ifdef CONFIG_X86_5LEVEL + testl $1, pgtable_l5_enabled(%rip) + jz 1f + shl $(64 - 57), %rcx + sar $(64 - 57), %rcx + jmp 2f +1: + shl $(64 - 48), %rcx + sar $(64 - 48), %rcx +2: +#else shl $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx sar $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx +#endif /* If this changed %rcx, it was not canonical */ cmpq %rcx, %r11 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h index d54a3d5..fa7dc7c 100644 --- a/arch/x86/include/asm/page_64_types.h +++ b/arch/x86/include/asm/page_64_types.h @@ -56,7 +56,7 @@ #define __PHYSICAL_MASK_SHIFT 52 #ifdef CONFIG_X86_5LEVEL -#define __VIRTUAL_MASK_SHIFT 56 +#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled ? 56 : 47) #else #define __VIRTUAL_MASK_SHIFT 47 #endif diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 420058b..9efee6f 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -85,8 +85,12 @@ static struct addr_marker address_markers[] = { [VMALLOC_START_NR] = { 0UL, "vmalloc() Area" }, [VMEMMAP_START_NR] = { 0UL, "Vmemmap" }, #ifdef CONFIG_KASAN - [KASAN_SHADOW_START_NR] = { KASAN_SHADOW_START, "KASAN shadow" }, - [KASAN_SHADOW_END_NR] = { KASAN_SHADOW_END, "KASAN shadow end" }, + /* + * These fields get initialized with the (dynamic) + * KASAN_SHADOW_{START,END} values in pt_dump_init(). + */ + [KASAN_SHADOW_START_NR] = { 0UL, "KASAN shadow" }, + [KASAN_SHADOW_END_NR] = { 0UL, "KASAN shadow end" }, #endif #ifdef CONFIG_MODIFY_LDT_SYSCALL [LDT_NR] = { 0UL, "LDT remap" }, @@ -571,6 +575,10 @@ static int __init pt_dump_init(void) #ifdef CONFIG_MODIFY_LDT_SYSCALL address_markers[LDT_NR].start_address = LDT_BASE_ADDR; #endif +#ifdef CONFIG_KASAN + address_markers[KASAN_SHADOW_START_NR].start_address = KASAN_SHADOW_START; + address_markers[KASAN_SHADOW_END_NR].start_address = KASAN_SHADOW_END; +#endif #endif #ifdef CONFIG_X86_32 address_markers[VMALLOC_START_NR].start_address = VMALLOC_START; diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index 515b98a..d079878 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c @@ -52,7 +52,7 @@ static __initdata struct kaslr_memory_region { unsigned long *base; unsigned long size_tb; } kaslr_regions[] = { - { &page_offset_base, 1 << (__PHYSICAL_MASK_SHIFT - TB_SHIFT) /* Maximum */ }, + { &page_offset_base, 0 }, { &vmalloc_base, VMALLOC_SIZE_TB }, { &vmemmap_base, 1 }, }; @@ -93,6 +93,8 @@ void __init kernel_randomize_memory(void) if (!kaslr_memory_enabled()) return; + kaslr_regions[0].size_tb = 1 << (__PHYSICAL_MASK_SHIFT - TB_SHIFT); + /* * Update Physical memory mapping to available and * add padding if needed (especially for memory hotplug support).