Received: by 10.213.65.68 with SMTP id h4csp178918imn; Tue, 3 Apr 2018 18:16:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx48wnleZuim6wK48HtJXeYFa2qvldyswN/x7m5I3iVHF9ztaiJJ61UFmjxxJoheJQh+tPnQM X-Received: by 2002:a17:902:3204:: with SMTP id y4-v6mr16404630plb.226.1522804610670; Tue, 03 Apr 2018 18:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522804610; cv=none; d=google.com; s=arc-20160816; b=hX2sFNbEEsOx4PbZSBbbYEEbt1yWebnsyESsT5RMyrfa/l4lR5OHDwd7CDiekaW+9/ Xqa5KTKD5f2VlIuYQL9s9C6Q90FYtboIY9PXmtYJHlbmiAbrVGCSeGm+aBalchP6SrCE VOLqzTQt40mw2O6l8Ek1AxQMKSmcJn6qe/YCw4o9n1APW3bOEx2Bv9oJ5DUb52oYyNU4 c68SSCesFmJUYUlRy1BLbz3tKJbf2dGmw3HcCvr8TenIxcC4DLno9F2lNpD5ajPYUaCE zmnnTQd0zMRqOPo33lrUG5j0cs88B3dvNYPjd6zqF2bumThIhHH6wcJ3b0sJwkPb5twd NInQ== 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=fmB8esjXdiCRm98xh4TSVAQVIyL/EbTxUCSl0Hrb/Fg=; b=xKT/7J/9doCfpC7Tf1CuXF2W1oebsbSmIPw+eK9wNYE1MuvPPBdq9X1uu8fy91cEQy Hpa1OJxNpD57MU97Rs1CC79Y2y28cjDLsVjyD+Y25rriXeM3KJs3yKnxfqvtzCz+iHix jutgJboeO+UmKG58OO97h7uUPAmVNqcwmwkKQxU23KR9rOSZqYoLRw8db/DLPuIK0Ii2 yFjvUW9YbDGCMT0dOb8LcBo1DYR0oHCymjtN/H8Ms+OVjdMAeSX5aILCCJsi3MmUTgjP BXH8SdvN7IV2YhY0yX47MRi7MKXHk7IytBeXnRS37ftK+Ig1p1BvcpGjKs93D8JF0x9A a+3g== 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 m11-v6si1738050pls.337.2018.04.03.18.16.36; Tue, 03 Apr 2018 18:16:50 -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 S1754969AbeDDBMv (ORCPT + 99 others); Tue, 3 Apr 2018 21:12:51 -0400 Received: from mga03.intel.com ([134.134.136.65]:44002 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754887AbeDDBMu (ORCPT ); Tue, 3 Apr 2018 21:12:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2018 18:12:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,403,1517904000"; d="scan'208";a="29340448" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga007.fm.intel.com with ESMTP; 03 Apr 2018 18:12:49 -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: Tue, 03 Apr 2018 18:10:04 -0700 References: <20180404010946.6186729B@viggo.jf.intel.com> In-Reply-To: <20180404010946.6186729B@viggo.jf.intel.com> Message-Id: <20180404011004.FE082845@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-02 16:41:16.085605170 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-02 16:41:16.088605170 -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) _