Received: by 10.192.165.156 with SMTP id m28csp1634112imm; Thu, 12 Apr 2018 00:21:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+f9VwxHsNRTAXmAvBcEkLqVLk0Zswv4IsgzJAWOVZ4JE8+C85q62bRNUMBwNzaV0GsROfU X-Received: by 10.99.117.79 with SMTP id f15mr5811307pgn.263.1523517686453; Thu, 12 Apr 2018 00:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523517686; cv=none; d=google.com; s=arc-20160816; b=yJlusqLGjzmxZj+W93aJee0YrRgayy0rko1w6Vy9N9cenrWKi30zQRc8GhRKGg7/t7 tjsPHJNOgJyiaJLLaJT+AnRuoPkxWT4srjnOAuPp5aN4zDGXwAT5CYO8kpMvRCDbETKT MiZeIRpKWWWQdoGwQ8zb1rj1yUchiJmwlfESRhdVDDI/a8BPFnwvJou9cfUoT0DbvfL4 IMOSwgFWStOv5UFt+/MBdl5NI9nRp9AP+0+GP5lmWJJT9sGyug7P6xBI2gch+dQH51AB 4aKjV06E1OVbvPeNbfRKq6mpwGYmn77AcryO1MmsOT55Hk2Pz8Br2OyNH9xDe7LbA7Rn sfAQ== 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=AR6oQaOFZtzU4VAsi+2Uau9tRcWlKFMlKObeEmaEYNo=; b=XKDd/iIwtD48I7OBxpzckHWcZYe0PLl5mP7vv5wXohFtBn/0UJXZtyoMpHk3K1OaHx 9V3iRidw2qUlOLCj5vuUhi4GHB9rTGbI/OuWERzPzQHHMF5j5TxHW/slbIJp/ZDu/5yz VWnpbaeMM1Eu0ySRtJM8+v/ksnpXe4wTLeut077gwH10Ln3Qb7wq4N8W2l52UlQK/2Rl nM0ToEeWrMNP/iIEc/druJlYDizGdeE7lQ4oWCa0UWEfQWCqGl81h3LR+Tt0HRQjpWDj zH2DX8zRvlU3BAums3cz0v2Ea+q0DdAFuIrXOR54EUr3fY8PWSxuTTnBVclHdgGHEk3p IZzQ== 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 189si1856241pgc.616.2018.04.12.00.20.49; Thu, 12 Apr 2018 00:21:26 -0700 (PDT) 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 S1752853AbeDLHQ5 (ORCPT + 99 others); Thu, 12 Apr 2018 03:16:57 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39113 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752041AbeDLHQy (ORCPT ); Thu, 12 Apr 2018 03:16:54 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3C7EwJN2970006; Thu, 12 Apr 2018 00:14:58 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3C7Ewtv2970003; Thu, 12 Apr 2018 00:14:58 -0700 Date: Thu, 12 Apr 2018 00:14:58 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dave Hansen Message-ID: Cc: luto@kernel.org, dave.hansen@linux.intel.com, keescook@google.com, dan.j.williams@intel.com, torvalds@linux-foundation.org, mingo@kernel.org, jgross@suse.com, dwmw2@infradead.org, hughd@google.com, gregkh@linuxfoundation.org, peterz@infradead.org, hpa@zytor.com, namit@vmware.com, arjan@linux.intel.com, tglx@linutronix.de, jpoimboe@redhat.com, aarcange@redhat.com, linux-kernel@vger.kernel.org, bp@alien8.de Reply-To: dwmw2@infradead.org, jgross@suse.com, hughd@google.com, gregkh@linuxfoundation.org, peterz@infradead.org, hpa@zytor.com, namit@vmware.com, luto@kernel.org, dave.hansen@linux.intel.com, keescook@google.com, mingo@kernel.org, torvalds@linux-foundation.org, dan.j.williams@intel.com, aarcange@redhat.com, linux-kernel@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, arjan@linux.intel.com, jpoimboe@redhat.com In-Reply-To: <20180406205513.079BB265@viggo.jf.intel.com> References: <20180406205513.079BB265@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/mm: Comment _PAGE_GLOBAL mystery Git-Commit-ID: 430d4005b8b41c19966dd3bfdb33004bdb2de01c 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: 430d4005b8b41c19966dd3bfdb33004bdb2de01c Gitweb: https://git.kernel.org/tip/430d4005b8b41c19966dd3bfdb33004bdb2de01c Author: Dave Hansen AuthorDate: Fri, 6 Apr 2018 13:55:13 -0700 Committer: Ingo Molnar CommitDate: Thu, 12 Apr 2018 09:05:58 +0200 x86/mm: Comment _PAGE_GLOBAL mystery I was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dan Williams Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Hugh Dickins Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Kees Cook Cc: Linus Torvalds Cc: Nadav Amit Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180406205513.079BB265@viggo.jf.intel.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/head_64.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 48385c1074a5..8344dd2f310a 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* + * Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. + * + * Note: This sets _PAGE_GLOBAL despite whether + * the CPU supports it or it is enabled. But, + * the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) + * + * This table is eventually used by the kernel during normal + * runtime. Care must be taken to clear out undesired bits + * later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)