Received: by 10.223.185.116 with SMTP id b49csp2022115wrg; Thu, 15 Feb 2018 05:26:31 -0800 (PST) X-Google-Smtp-Source: AH8x224B+Qxjkxs19oDXSoFuhp/KjsM5RyXGyi0ei1eG5bCSi5hzsYhb3kLTSQ0G9/Kep1fxOaj4 X-Received: by 10.99.95.201 with SMTP id t192mr2261658pgb.313.1518701191268; Thu, 15 Feb 2018 05:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518701191; cv=none; d=google.com; s=arc-20160816; b=ihPuQKGItzaRJHGyznApuH4XkmaMIS8KXJRT9XZanotGTq6hsG9kId0igYpSiwnuu2 GhtaQBMHcLeoy+sXuFpgUxDBUSdBRJpNcQM9nLPbGcVFtxQ76Cak1kKaoxmeI+9zlUZR HLTRxe95t5sKBChh5mcc5IAIid5cpeQrFaJU4Xj7AYAl7fNS3av9vW+BJojJMXg6Ls6i 7uaCHxPl1TofgcY/+Z0tJ1u0Pvz2mvGH9YfcFKDEHDg7snuNNtZ+oFzco4DKbhSirtHc FmZoeNcRQ5eDKWYAhu5KdoG0wA/gfQdikQJcgATR8iKW51Zl0Bef4LB1m4MZnZP5agqF fZMg== 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=eVTlkMaJu/RMCCjQ6c6hZVP1Id1/oOz0OMxP3HrXyjs=; b=qnbr03TGYH58iiNatwGKVT7+mzGxwMRDbMzYJ4yXokFdn4lXftfPNy6yLqG4Sskoto IwUKjAYfAw5jErglDf37apbX28kdZZOsMn/muhQKjy40Q7PVqCStvXTibT4Gwe0TWi77 WUa84dPKnKf857rnJrLCoirYfGV4ner9E7cbfeOkB8AeEsqta7RHv597Zy8uRO3lNG0i QoaZKjQdB9pgj9i0B7FV5+wHL3fROBpwNwvhKG5viKJEBQA89/GPwjzPN3N9O1ZNtcT6 x9otgiHYiYVs2+qPCa25AiJB9TDx7zvzCHqiipplTKb8msxTFef6hB+6mV9yfV6ubTHT Iwsw== 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 94-v6si1351401plf.451.2018.02.15.05.26.17; Thu, 15 Feb 2018 05:26:31 -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 S1032743AbeBONZW (ORCPT + 99 others); Thu, 15 Feb 2018 08:25:22 -0500 Received: from mga14.intel.com ([192.55.52.115]:51857 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032335AbeBONZU (ORCPT ); Thu, 15 Feb 2018 08:25:20 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2018 05:25:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,517,1511856000"; d="scan'208";a="201366266" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga005.jf.intel.com with ESMTP; 15 Feb 2018 05:25:19 -0800 Subject: [PATCH 2/3] x86/mm: introduce __PAGE_KERNEL_GLOBAL To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , luto@kernel.org, torvalds@linux-foundation.org, keescook@google.com, hughd@google.com, jgross@suse.com, x86@kernel.org From: Dave Hansen Date: Thu, 15 Feb 2018 05:20:55 -0800 References: <20180215132053.6C9B48C8@viggo.jf.intel.com> In-Reply-To: <20180215132053.6C9B48C8@viggo.jf.intel.com> Message-Id: <20180215132055.F341C31E@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 Kernel mappings are historically _PAGE_GLOBAL. But, with PTI, we do not want them to be _PAGE_GLOBAL. We currently accomplish this by simply clearing _PAGE_GLOBAL from the suppotred mask which ensures it is cleansed from many of our PTE construction sites: if (!static_cpu_has(X86_FEATURE_PTI)) __supported_pte_mask |= _PAGE_GLOBAL; But, this also means that we now get *no* opportunity to use global pages with PTI, even for data which is shared such as the cpu_entry_area and entry/exit text. This patch introduces a new mask: __PAGE_KERNEL_GLOBAL. This mask can be thought of as the default global bit value when creating kernel mappings. We make it _PAGE_GLOBAL when PTI=n, but 0 when PTI=y. This ensures that on PTI kernels, all of the __PAGE_KERNEL_* users will not get _PAGE_GLOBAL. This also restores _PAGE_GLOBAL to __supported_pte_mask, allowing it to be set in the first place. Signed-off-by: Dave Hansen Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x86@kernel.org --- b/arch/x86/include/asm/pgtable_types.h | 9 ++++++++- b/arch/x86/mm/init.c | 8 +------- b/arch/x86/mm/pageattr.c | 9 +++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff -puN arch/x86/include/asm/pgtable_types.h~kpti-no-global-for-kernel-mappings arch/x86/include/asm/pgtable_types.h --- a/arch/x86/include/asm/pgtable_types.h~kpti-no-global-for-kernel-mappings 2018-02-13 15:17:56.144210060 -0800 +++ b/arch/x86/include/asm/pgtable_types.h 2018-02-13 15:17:56.152210060 -0800 @@ -180,8 +180,15 @@ enum page_cache_mode { #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \ _PAGE_ACCESSED) +#ifdef CONFIG_PAGE_TABLE_ISOLATION +#define __PAGE_KERNEL_GLOBAL 0 +#else +#define __PAGE_KERNEL_GLOBAL _PAGE_GLOBAL +#endif + #define __PAGE_KERNEL_EXEC \ - (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL) + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | \ + __PAGE_KERNEL_GLOBAL) #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX) #define __PAGE_KERNEL_RO (__PAGE_KERNEL & ~_PAGE_RW) diff -puN arch/x86/mm/init.c~kpti-no-global-for-kernel-mappings arch/x86/mm/init.c --- a/arch/x86/mm/init.c~kpti-no-global-for-kernel-mappings 2018-02-13 15:17:56.146210060 -0800 +++ b/arch/x86/mm/init.c 2018-02-13 15:17:56.152210060 -0800 @@ -162,12 +162,6 @@ struct map_range { static int page_size_mask; -static void enable_global_pages(void) -{ - if (!static_cpu_has(X86_FEATURE_PTI)) - __supported_pte_mask |= _PAGE_GLOBAL; -} - static void __init probe_page_size_mask(void) { /* @@ -189,7 +183,7 @@ static void __init probe_page_size_mask( __supported_pte_mask &= ~_PAGE_GLOBAL; if (boot_cpu_has(X86_FEATURE_PGE)) { cr4_set_bits_and_update_boot(X86_CR4_PGE); - enable_global_pages(); + __supported_pte_mask |= _PAGE_GLOBAL; } /* Enable 1 GB linear kernel mappings if available: */ diff -puN arch/x86/mm/pageattr.c~kpti-no-global-for-kernel-mappings arch/x86/mm/pageattr.c --- a/arch/x86/mm/pageattr.c~kpti-no-global-for-kernel-mappings 2018-02-13 15:17:56.148210060 -0800 +++ b/arch/x86/mm/pageattr.c 2018-02-13 15:17:56.153210060 -0800 @@ -593,7 +593,8 @@ try_preserve_large_page(pte_t *kpte, uns * different bit positions in the two formats. */ req_prot = pgprot_4k_2_large(req_prot); - req_prot = pgprot_set_on_present(req_prot, _PAGE_GLOBAL | _PAGE_PSE); + req_prot = pgprot_set_on_present(req_prot, + __PAGE_KERNEL_GLOBAL | _PAGE_PSE); req_prot = canon_pgprot(req_prot); /* @@ -703,7 +704,7 @@ __split_large_page(struct cpa_data *cpa, return 1; } - ref_prot = pgprot_set_on_present(ref_prot, _PAGE_GLOBAL); + ref_prot = pgprot_set_on_present(ref_prot, __PAGE_KERNEL_GLOBAL); /* * Get the target pfn from the original entry: @@ -926,7 +927,7 @@ static void populate_pte(struct cpa_data pte = pte_offset_kernel(pmd, start); - pgprot = pgprot_set_on_present(pgprot, _PAGE_GLOBAL); + pgprot = pgprot_set_on_present(pgprot, __PAGE_KERNEL_GLOBAL); pgprot = canon_pgprot(pgprot); while (num_pages-- && start < end) { @@ -1219,7 +1220,7 @@ repeat: new_prot = static_protections(new_prot, address, pfn); - new_prot = pgprot_set_on_present(new_prot, _PAGE_GLOBAL); + new_prot = pgprot_set_on_present(new_prot, __PAGE_KERNEL_GLOBAL); /* * We need to keep the pfn from the existing PTE, _