Received: by 10.223.185.116 with SMTP id b49csp3206243wrg; Mon, 5 Mar 2018 16:31:42 -0800 (PST) X-Google-Smtp-Source: AG47ELu1dm3pc5Np84k6iuUc4tig4sNzrQFfS1t0QDzfb0hf0ec42C/Hqd5TLuSy8ZtU1gz+uW4J X-Received: by 2002:a17:902:650c:: with SMTP id b12-v6mr4750096plk.451.1520296301907; Mon, 05 Mar 2018 16:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520296301; cv=none; d=google.com; s=arc-20160816; b=ABNCEEDYvVpRpNSAdCmsUWcR+uMDMCPl/BOiLW5ZTMZQ9wSTbbAefiAdTqzRVuDlVy p/451zrj9v1Mc2KHqyF7DXqcurZIl/PtEjzdsV/e6vvpSuWyf+oz2ym7/htg1RKA4pqE cHRfAXrD7HCyBEWTLpIhiVsHJnul3QE4JLMOhB3bFHLFmPpPc5a9dzECWAGn6Db80SDz zikEOHgIGI4ljg0Q+F8p5Tb5oIQ8is+ZohobbB2NexaX0JZDpltGFPHbNdueI5nbo4Bj Wh9RLpW1029/ar77yvJKbS4nBm/eA355nwx13VfElospXvvtyVo1Z+l/X996kjFafFid 11pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=7COaSwNHM8GwD2NOErSCYZCtyklx2L6JRnEBSdfk9CY=; b=yrgqzOYlyJRew7rywh9RtPOBFZ936VkiB/+Z7jo/0VPofQjPyRXVPVfmKrP0kMyUFV HbHichzT7WsjX2jm6/xqddy6xWrUq/w/nehSCqll4NTUB+qAz6QyuBI5aZsZMQ2f7czY cVKSc4A5RNz+TYGV9IJ0Nbvoe7ifuMxAg5EtPt0Gzd7Fbnr+7SV/Ooc4OxRwzQvnYPlU Iit/hNJEyYjm4xx4QQ7kHhZ2k7GkqW76bmynfvDYPJ0CUjp1nF2Ez5jiaLjKSpQbC8Kn 02HFYxErKZzsRcS6PkN/hAufWyXPTveYb+gHaYNvdWsuSeb5HOghHdLRkyTMTfXTYwTb 9eaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=JUNqkWs+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si9029997pgd.763.2018.03.05.16.31.28; Mon, 05 Mar 2018 16:31:41 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=JUNqkWs+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933696AbeCFA3u (ORCPT + 99 others); Mon, 5 Mar 2018 19:29:50 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:43088 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933501AbeCFA0z (ORCPT ); Mon, 5 Mar 2018 19:26:55 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w260LpFd073979; Tue, 6 Mar 2018 00:26:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=7COaSwNHM8GwD2NOErSCYZCtyklx2L6JRnEBSdfk9CY=; b=JUNqkWs+S4W0a1H9TcFFiZrv4PymnWsSvyK1SKsThi8Yy9jI1NH7zhxgY3e7HaBEg+TC BxomyAAqw5r4GndUPYVzx8btpHnenPeLUsVUA2vE3OlCehGkb3+iVSSLYTHSQM45eBqj CLPCjj1y3oyH+akdEWi6Mdr3qiWy5fyqjpjHvuTlD989uTUEyxn9GFCAG4+apd9eKuaS 3aOw8tqepGVY3+OeyLjHp5Je+p356Hp53vj3wUJA6u1lYtk8TaiZX8jQAwd9V48T1/38 BoVADYOM5853Mz5V+WsP8S7/IK97/n8MJ1zLeJXxKuoKmXnWwbdFGXvvIwiOCY6A4DMl oQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2ghe5xgf1m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 00:26:50 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w260QnEa012151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Mar 2018 00:26:49 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w260QnBT000546; Tue, 6 Mar 2018 00:26:49 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Mar 2018 16:26:48 -0800 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, Alexander.Levin@microsoft.com, dan.j.williams@intel.com, sathyanarayanan.kuppuswamy@intel.com, pankaj.laxminarayan.bharadiya@intel.com, akuster@mvista.com, cminyard@mvista.com, pasha.tatashin@oracle.com, gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH 4.1 56/65] kaiser: kaiser_flush_tlb_on_return_to_user() check PCID Date: Mon, 5 Mar 2018 19:25:29 -0500 Message-Id: <20180306002538.1761-57-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180306002538.1761-1-pasha.tatashin@oracle.com> References: <20180306002538.1761-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8823 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=815 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803060003 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugh Dickins Let kaiser_flush_tlb_on_return_to_user() do the X86_FEATURE_PCID check, instead of each caller doing it inline first: nobody needs to optimize for the noPCID case, it's clearer this way, and better suits later changes. Replace those no-op X86_CR3_PCID_KERN_FLUSH lines by a BUILD_BUG_ON() in load_new_mm_cr3(), in case something changes. Signed-off-by: Hugh Dickins Acked-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 8eaca4c7d9f167209a9cc568ff028c0a3b0deb2d) Signed-off-by: Pavel Tatashin --- arch/x86/include/asm/tlbflush.h | 4 ++-- arch/x86/mm/kaiser.c | 6 +++--- arch/x86/mm/tlb.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 6fdc8c399601..73865b174090 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -157,7 +157,7 @@ static inline void __native_flush_tlb(void) * back: */ preempt_disable(); - if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) + if (kaiser_enabled) kaiser_flush_tlb_on_return_to_user(); native_write_cr3(native_read_cr3()); preempt_enable(); @@ -216,7 +216,7 @@ static inline void __native_flush_tlb_single(unsigned long addr) */ if (!this_cpu_has(X86_FEATURE_INVPCID_SINGLE)) { - if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) + if (kaiser_enabled) kaiser_flush_tlb_on_return_to_user(); asm volatile("invlpg (%0)" ::"r" (addr) : "memory"); return; diff --git a/arch/x86/mm/kaiser.c b/arch/x86/mm/kaiser.c index c64bfef99ee8..9d6b7517fca5 100644 --- a/arch/x86/mm/kaiser.c +++ b/arch/x86/mm/kaiser.c @@ -436,12 +436,12 @@ void kaiser_setup_pcid(void) /* * Make a note that this cpu will need to flush USER tlb on return to user. - * Caller checks whether this_cpu_has(X86_FEATURE_PCID) before calling: - * if cpu does not, then the NOFLUSH bit will never have been set. + * If cpu does not have PCID, then the NOFLUSH bit will never have been set. */ void kaiser_flush_tlb_on_return_to_user(void) { - this_cpu_write(x86_cr3_pcid_user, + if (this_cpu_has(X86_FEATURE_PCID)) + this_cpu_write(x86_cr3_pcid_user, X86_CR3_PCID_USER_FLUSH | KAISER_SHADOW_PGD_OFFSET); } EXPORT_SYMBOL(kaiser_flush_tlb_on_return_to_user); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 5539d613c263..5939c549905f 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -39,7 +39,7 @@ static void load_new_mm_cr3(pgd_t *pgdir) { unsigned long new_mm_cr3 = __pa(pgdir); - if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) { + if (kaiser_enabled) { /* * We reuse the same PCID for different tasks, so we must * flush all the entries for the PCID out when we change tasks. @@ -50,10 +50,10 @@ static void load_new_mm_cr3(pgd_t *pgdir) * do it here, but can only be used if X86_FEATURE_INVPCID is * available - and many machines support pcid without invpcid. * - * The line below is a no-op: X86_CR3_PCID_KERN_FLUSH is now 0; - * but keep that line in there in case something changes. + * If X86_CR3_PCID_KERN_FLUSH actually added something, then it + * would be needed in the write_cr3() below - if PCIDs enabled. */ - new_mm_cr3 |= X86_CR3_PCID_KERN_FLUSH; + BUILD_BUG_ON(X86_CR3_PCID_KERN_FLUSH); kaiser_flush_tlb_on_return_to_user(); } -- 2.16.2