Received: by 10.223.185.116 with SMTP id b49csp2243128wrg; Thu, 15 Feb 2018 08:38:31 -0800 (PST) X-Google-Smtp-Source: AH8x226MN8SnJxyuaRc1lXmCjuWAuZIbt0/GavdG39KY/jHjPMGAgJvM+d8vrQmCJaMYtVt/8/vX X-Received: by 2002:a17:902:42c3:: with SMTP id h61-v6mr3041117pld.269.1518712711214; Thu, 15 Feb 2018 08:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518712711; cv=none; d=google.com; s=arc-20160816; b=F3zez7dwAWrBTjL2HelWkTMpdDMPgXtVn7vyahAupUR8oFCDPIfswfSHVLBAFa/R7x X2vw/DsohZIVi2z8xSx1FuvLtVJmLF0gI0ddH0d6IVWTXAKfTnYpvPboTB4F0PxIY6Wa AQvwWXtCRM3PFHd1RSHrw2pnx+EnXS2m2a5CrBdwO4gBTwkwp6o23nPbywTLnTll8/TH M0pSdoiqj+Ptwrrz736UUtbu6ZA1bP0e90h7351x/80xTylGb2g7Tu1vTkzX1SKT6bTN EMPEd2yZUOLy32B65Fofu29tLfaHPfj1g3oLGOSNVdF/oLk7wk+bbXGoZExt44oybIr7 4cbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=M10Alfiu4eMJn2wTl6VsIpllIawq61Fxl2dRVwv7lY8=; b=DBVzS9aBeQZwBFipZub9+X1PaO67wk0ouGqoG4BP3eTv3f9IMsu951wIYqDM2BZtTd FIdBMIhbA4dquaIOiIuqSUgcOsMGL9TNKxNw4cQpdBg7eNimscoTfo4U2ZFZ7hvdlHCK 2J0SblIl5GjEZqkM1urSR5QXzWzTacehX3KSTaQeShIi+Ex0r6LUpJksia58cW1toiy0 Egwt2KSJkvR6G0di+yBtq1iLP/MchRolWBinGU0uRrz6DlGofXu38aRXIpdam9innyqk u1S4F5SPhbJjyxHKuhoaysHm8f15QhdpyimW2g5RjwIrqC82nefx2O/Ibaoh8vpDWFi9 uWtQ== 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 199si3396477pfy.92.2018.02.15.08.38.16; Thu, 15 Feb 2018 08:38: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 S1426111AbeBOQgh (ORCPT + 99 others); Thu, 15 Feb 2018 11:36:37 -0500 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:37394 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1426090AbeBOQgU (ORCPT ); Thu, 15 Feb 2018 11:36:20 -0500 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 15 Feb 2018 08:36:08 -0800 Received: from ubuntu.localdomain (unknown [10.2.101.129]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 6D0A040B58; Thu, 15 Feb 2018 08:36:16 -0800 (PST) From: Nadav Amit To: Ingo Molnar CC: Thomas Gleixner , Andy Lutomirski , Peter Zijlstra , Dave Hansen , Willy Tarreau , Nadav Amit , , , Nadav Amit Subject: [PATCH RFC v2 5/6] x86: Use global pages when PTI is disabled Date: Thu, 15 Feb 2018 08:36:01 -0800 Message-ID: <20180215163602.61162-6-namit@vmware.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180215163602.61162-1-namit@vmware.com> References: <20180215163602.61162-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As long as PTI is disabled, it is possible to use global pages, as long as we remove them once PTI is enabled again. To do so, return the global bit to __supported_pte_mask and disable global pages using CR4. Signed-off-by: Nadav Amit --- arch/x86/include/asm/tlbflush.h | 6 ++++++ arch/x86/mm/init.c | 14 ++++++-------- arch/x86/mm/tlb.c | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index ea65cf951c49..3a44cb0a9f56 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -319,6 +319,12 @@ static inline void set_cpu_pti_disable(unsigned short disable) WARN_ON_ONCE(preemptible()); pti_update_user_cs64(cpu_pti_disable(), disable); + if (__supported_pte_mask & _PAGE_GLOBAL) { + if (disable) + cr4_set_bits(X86_CR4_PGE); + else + cr4_clear_bits(X86_CR4_PGE); + } this_cpu_write(cpu_tlbstate.pti_disable, disable); } diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 82f5252c723a..7f918a59c536 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -161,12 +161,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) { /* @@ -186,8 +180,10 @@ static void __init probe_page_size_mask(void) /* Enable PGE if available */ __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; + + if (!static_cpu_has(X86_FEATURE_PTI)) + cr4_set_bits_and_update_boot(X86_CR4_PGE); } /* Enable 1 GB linear kernel mappings if available: */ @@ -683,6 +679,8 @@ void __init init_mem_mapping(void) #else early_ioremap_page_table_range_init(); #endif + if (static_cpu_has(X86_FEATURE_PTI)) + cr4_clear_bits(X86_CR4_PGE); load_cr3(swapper_pg_dir); __flush_tlb_all(); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index c67ef3fb4f35..979c7ec6baab 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -74,7 +74,8 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, return; } - if (this_cpu_read(cpu_tlbstate.invalidate_other)) + if (this_cpu_read(cpu_tlbstate.invalidate_other) && + !mm_pti_disable(next)) clear_asid_other(); for (asid = 0; asid < TLB_NR_DYN_ASIDS; asid++) { -- 2.14.1