Received: by 10.213.65.68 with SMTP id h4csp1071001imn; Fri, 6 Apr 2018 14:04:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ofd5m2A0jNn9oIQWFqwp/FUqPN9eUGmaADDmEbWEfASaDLJnT+w4BJqqXtsFNJpmtwJly X-Received: by 2002:a17:902:d20f:: with SMTP id t15-v6mr23776748ply.263.1523048695738; Fri, 06 Apr 2018 14:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523048695; cv=none; d=google.com; s=arc-20160816; b=PM99kF2SqZII4OwEMfQQzCyKW06WP49AMTl7TwbMv1rY+mCmjdhoPzY6kXZyTUDima vtxPXOtX9ar36nMyVtXtDrwF+jCZFJLQZh6ZdcqDsnwZfxLUu3Z4wcJDylCixV0FmskB JgYMOLuTeDATUYJaYOok465lyxA2mKMnTMcXkifQiG8eB1xBoeEShcvFQoYhYtyyGuJB TVZj9GuIR6gb3wPbEHt2QZEgvnKMJFlKmIMDn6NovaXSa1xhxCYahqffNU7KTJ27Jt0P SO1zdFfZQNffqSxq3rEE39CCmgpuzZw5aIwzfO7ysUqp42hv0XESx9s9ZlbP+oCTwuVd csfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:arc-authentication-results; bh=VJ+/q2L+FEXAjNP8qatTDhQxebL/EUORhvv9qRm14kk=; b=vGaQmvezqNOcQQPggmtSd7p+uSeG04Q3Er6Wc9fcAOLLk6tlGAMuIdl0m64+qIhcSW VNKVT/VHj5io9l/sMNCA1/fz7SFN5HfzTKGM+kbFJ7iQuWl0ufWgaWbNhY+JcwBy2wjW TABMIO4GqfQR3gttFtTwkjKjMPVCfzLuC+E/4Ubh+0oSLNwSDgmydvLbV2QiQXx/PxxK XK896pv4bw7N2eoyxLcYOrSWWhMvLA7wKcxjmKHwf6bJGz/Pg5Trd2yR1fvDs0n7IQ0s mSlhhVerUiJ/IEI4VmMPQ4StwMrMLtE5pH2exeN06JZfW3F7DZ1v9yrHb2ocXBCLLMPM /bJg== 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 x5-v6si9700383plr.680.2018.04.06.14.04.19; Fri, 06 Apr 2018 14:04:55 -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 S1752631AbeDFU7u (ORCPT + 99 others); Fri, 6 Apr 2018 16:59:50 -0400 Received: from mga18.intel.com ([134.134.136.126]:45030 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbeDFU6K (ORCPT ); Fri, 6 Apr 2018 16:58:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Apr 2018 13:58:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,416,1517904000"; d="scan'208";a="41307051" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga003.jf.intel.com with ESMTP; 06 Apr 2018 13:58:09 -0700 Subject: [PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , aarcange@redhat.com, luto@kernel.org, torvalds@linux-foundation.org, keescook@google.com, hughd@google.com, jgross@suse.com, x86@kernel.org, namit@vmware.com From: Dave Hansen Date: Fri, 06 Apr 2018 13:55:13 -0700 References: <20180406205501.24A1A4E7@viggo.jf.intel.com> In-Reply-To: <20180406205501.24A1A4E7@viggo.jf.intel.com> Message-Id: <20180406205513.079BB265@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen 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: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x86@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-06 10:47:57.176796121 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-06 10:47:57.179796121 -0700 @@ -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) _