Received: by 10.192.165.148 with SMTP id m20csp450648imm; Wed, 25 Apr 2018 02:10:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/vJf/K9taPaBcAWXR75OuwFKA/VyuTtdCargtwPqib8hbITQ2DAq3N6/sVjg6aJEJ6jAMi X-Received: by 2002:a17:902:8606:: with SMTP id f6-v6mr28430158plo.258.1524647402957; Wed, 25 Apr 2018 02:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524647402; cv=none; d=google.com; s=arc-20160816; b=OoRpZlydDiQ3Q95fT9djeEzSBaOd+mUoWgh0IDS1f0/wFq+x184c4x8VbcKiRL/jF2 T4hi/9BD1pCJrheLdRGjLlHy/t6lRCg001RquIHfk+vUDbIMPR7oBfLgCdHmtjD0468B zgS8H8McKHK42fpyMr5E3+cvXq9W5rm0VGeQwkvLY+pzJpGM6/ioSKDH5zpnZXqOjotl 7uCgUhNhSnXviyXgqj8TuiDgdZmibuXTvQ3Ix8UdYnuWuYS+S/NEGhuKXA3A5xLQKa5/ q3dsbkdL0pYaoz2mc6y+kKj1mLqfG4joSfGFrVr0tYWYbZRXHdTVTaNQ9tBJMK+9VRlB z9eA== 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=lHVFY1z2nOLA8zn25blzQT5I+UmVXYyku7KoUfg6zh8=; b=o4m0YSYFZKL4t3W+uID4aIyNpSEVPfmihQvaM3qXI0gqclNE64dKlGCW+wpHp1KSE5 pCbI2YMEup5iPAlzmsEl0d7oOelDlVqOobKWenqPaJhAxYPLtvr9Y0IaCfR7lCjIcxvg ltlkJULKfhrXcq0jNGNcCVYMQV4CnxG2hZAvQTBK/UCDtx9bXoDdhzUFJvsM3U7WWPvM uEMaQgnyxyJBENViAkGIaUk5nvfvkCliN5i3mJeAxMxbwjqdoFMIfjI2ng+4LhArixsq dt6p0+n/pfZLTfa1JnTwzSG/VuBrRbSIVhEi7H7sMSQy64Ii+GU/agab/Tq1ub4cxW3e SIFA== 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 d29si2446150pfb.232.2018.04.25.02.09.48; Wed, 25 Apr 2018 02:10:02 -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 S1751496AbeDYJIn (ORCPT + 99 others); Wed, 25 Apr 2018 05:08:43 -0400 Received: from terminus.zytor.com ([198.137.202.136]:34707 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750882AbeDYJIk (ORCPT ); Wed, 25 Apr 2018 05:08:40 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3P97UIX1423808; Wed, 25 Apr 2018 02:07:30 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3P97TFN1423805; Wed, 25 Apr 2018 02:07:29 -0700 Date: Wed, 25 Apr 2018 02:07:29 -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: tglx@linutronix.de, jgross@suse.com, dwmw2@infradead.org, arjan@linux.intel.com, jpoimboe@redhat.com, dan.j.williams@intel.com, namit@vmware.com, hughd@google.com, gregkh@linuxfoundation.org, hpa@zytor.com, aaro.koskinen@nokia.com, bp@alien8.de, peterz@infradead.org, aarcange@redhat.com, mingo@kernel.org, keescook@google.com, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, mceier@gmail.com, luto@kernel.org, torvalds@linux-foundation.org Reply-To: dwmw2@infradead.org, tglx@linutronix.de, jgross@suse.com, arjan@linux.intel.com, jpoimboe@redhat.com, dan.j.williams@intel.com, namit@vmware.com, hughd@google.com, gregkh@linuxfoundation.org, hpa@zytor.com, aaro.koskinen@nokia.com, bp@alien8.de, peterz@infradead.org, aarcange@redhat.com, mingo@kernel.org, keescook@google.com, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, mceier@gmail.com, luto@kernel.org, torvalds@linux-foundation.org In-Reply-To: <20180420222021.1C7D2B3F@viggo.jf.intel.com> References: <20180420222021.1C7D2B3F@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/pti: Fix boot warning from Global-bit setting Git-Commit-ID: 58e65b51e6f9b9dd94a25ff2b2772222e0358099 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: 58e65b51e6f9b9dd94a25ff2b2772222e0358099 Gitweb: https://git.kernel.org/tip/58e65b51e6f9b9dd94a25ff2b2772222e0358099 Author: Dave Hansen AuthorDate: Fri, 20 Apr 2018 15:20:21 -0700 Committer: Thomas Gleixner CommitDate: Wed, 25 Apr 2018 11:02:50 +0200 x86/pti: Fix boot warning from Global-bit setting commit 231df823c4f04176f607afc4576c989895cff40e The pageattr.c code attempts to process "faults" when it goes looking for PTEs to change and finds non-present entries. It allows these faults in the linear map which is "expected to have holes", but WARN()s about them elsewhere, like when called on the kernel image. However, change_page_attr_clear() is now called on the kernel image in the process of trying to clear the Global bit. This trips the warning in __cpa_process_fault() if a non-present PTE is encountered in the kernel image. The "holes" in the kernel image result from free_init_pages()'s use of set_memory_np(). These holes are totally fine, and result from normal operation, just as they would be in the kernel linear map. Just silence the warning when holes in the kernel image are encountered. Fixes: 39114b7a7 (x86/pti: Never implicitly clear _PAGE_GLOBAL for kernel image) Reported-by: Mariusz Ceier Reported-by: Aaro Koskinen Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Tested-by: Aaro Koskinen Acked-by: Ingo Molnar Cc: Andrea Arcangeli Cc: Juergen Gross Cc: Nadav Amit Cc: Kees Cook Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: David Woodhouse Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: Linus Torvalds Cc: Andy Lutomirski Cc: Greg Kroah-Hartman Cc: Borislav Petkov Cc: Dan Williams Cc: Arjan van de Ven Link: https://lkml.kernel.org/r/20180420222021.1C7D2B3F@viggo.jf.intel.com --- arch/x86/mm/pageattr.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 4fadfd2b7017..3bded76e8d5c 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -93,6 +93,18 @@ void arch_report_meminfo(struct seq_file *m) static inline void split_page_count(int level) { } #endif +static inline int +within(unsigned long addr, unsigned long start, unsigned long end) +{ + return addr >= start && addr < end; +} + +static inline int +within_inclusive(unsigned long addr, unsigned long start, unsigned long end) +{ + return addr >= start && addr <= end; +} + #ifdef CONFIG_X86_64 static inline unsigned long highmap_start_pfn(void) @@ -106,20 +118,25 @@ static inline unsigned long highmap_end_pfn(void) return __pa_symbol(roundup(_brk_end, PMD_SIZE) - 1) >> PAGE_SHIFT; } -#endif - -static inline int -within(unsigned long addr, unsigned long start, unsigned long end) +static bool __cpa_pfn_in_highmap(unsigned long pfn) { - return addr >= start && addr < end; + /* + * Kernel text has an alias mapping at a high address, known + * here as "highmap". + */ + return within_inclusive(pfn, highmap_start_pfn(), highmap_end_pfn()); } -static inline int -within_inclusive(unsigned long addr, unsigned long start, unsigned long end) +#else + +static bool __cpa_pfn_in_highmap(unsigned long pfn) { - return addr >= start && addr <= end; + /* There is no highmap on 32-bit */ + return false; } +#endif + /* * Flushing functions */ @@ -1183,6 +1200,10 @@ static int __cpa_process_fault(struct cpa_data *cpa, unsigned long vaddr, cpa->numpages = 1; cpa->pfn = __pa(vaddr) >> PAGE_SHIFT; return 0; + + } else if (__cpa_pfn_in_highmap(cpa->pfn)) { + /* Faults in the highmap are OK, so do not warn: */ + return -EFAULT; } else { WARN(1, KERN_WARNING "CPA: called for zero pte. " "vaddr = %lx cpa->vaddr = %lx\n", vaddr, @@ -1335,8 +1356,7 @@ static int cpa_process_alias(struct cpa_data *cpa) * to touch the high mapped kernel as well: */ if (!within(vaddr, (unsigned long)_text, _brk_end) && - within_inclusive(cpa->pfn, highmap_start_pfn(), - highmap_end_pfn())) { + __cpa_pfn_in_highmap(cpa->pfn)) { unsigned long temp_cpa_vaddr = (cpa->pfn << PAGE_SHIFT) + __START_KERNEL_map - phys_base; alias_cpa = *cpa;