Received: by 10.223.185.116 with SMTP id b49csp3214633wrg; Mon, 5 Mar 2018 16:43:38 -0800 (PST) X-Google-Smtp-Source: AG47ELu/+H7fedwxjJVp4Ec3hieWbd+lNm86bsJx5Eoo8hGv/Ngcm1cM81ezFS485vwVu99It9sw X-Received: by 2002:a17:902:9349:: with SMTP id g9-v6mr4900329plp.319.1520297018793; Mon, 05 Mar 2018 16:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520297018; cv=none; d=google.com; s=arc-20160816; b=E+trpVbzaexEFv8vaiFarWrz8QC97MA2EbnJOzWhWVPw4j4ru3WbdmzpOiMCTbhQTN EVV4+2ZS8dSzr0WLu8XkGh88cjRbLy0FagNrFg9IsxEjL1nD6sjCIc256YF9bTUjRWEh 1SlE/fjpDbJnBDfaP9LBb12FpTaKNtN2q3R2vyz2NEjjG6c5oswomT2DLSMUf9wApVmL NkC2V9WRkrs8I8V+ZGdCEY+ZfRU17vEkmFQze7ZQo3cX9RtdOiOzd/ugHik5YZ6k7ajx WyjNBAeZXp/j3mUNCyWnNbxSJRjH9ns8GZbNy0cYAaXf4veQruffRzQvxv3FOl46iyob Hu8w== 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=j/xUg9Pel3D+OY1q+CzCfCXs2LDA5NFVvcjGpCg+b4s=; b=jWRJeTrByKNPN97wjOMZBoK9xqexqnpTir4AP4ALg/aiq6oNczoZ7cHjQcagfpOr4y 8fHUNJiBh3onYCNp4E0x1pu1zlKpezFgiZSdow4KGRKVY6G3+dd7B5DyIR88Xind5Fl0 HEuZ8z4EtxpLq7nTwwnfK9jF59xYCj6q8aPWUEmcc8SKCpaq/JrJy11ZYJ+xDnSkioU6 H6ZCHRWtDOilVjmgTBNAX5kTDXZ22gUArPizmWfYVnbxnrqTXkjLBAFx06G8n8nTDllN fRkSxCnVLvACq6U2QXrGkhB/rAxR1jHkos8Mzppdr/VoYymirDgEtNUGm0OQFxyp1Y20 xxJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=N+z8Ngk0; 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 m15-v6si10430356pln.718.2018.03.05.16.43.24; Mon, 05 Mar 2018 16:43:38 -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=N+z8Ngk0; 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 S933613AbeCFAll (ORCPT + 99 others); Mon, 5 Mar 2018 19:41:41 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42552 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932692AbeCFA0E (ORCPT ); Mon, 5 Mar 2018 19:26:04 -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 w260MvNZ075031; Tue, 6 Mar 2018 00:25:59 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=j/xUg9Pel3D+OY1q+CzCfCXs2LDA5NFVvcjGpCg+b4s=; b=N+z8Ngk0PaoGi9h3ChwFTcbNAhxLoTRlMMoPNMgwntS9vNf7XeJvwnf0l0nf7+1nxfDq HiTR3UpO0Zc6vrR0MYSpYlcK9TrQGhlPGw5mkH1dEUn6xM5ZzbEcEmX7YHSpTlcAm0cm 4FzgwEd5fGH5JbkaiDP2m5cmQVAK6+QNe4k3xxKszC1zoeYE3x793UWUOAvRWCVa8ztr 4weGjH+t/ZIynHX3VfcVo2zj/tDGD2eWKI4dEjippTMfqjXUM35p4oetVm1Bb2YRGYjw EXpk9c9YrHmKN/YpVY37CctyRGxASL8pLlNcsdMFn8N5IOFRNRVat3ryUaDFu/Tt5QAE aQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2ghe5xgeyf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 00:25:59 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w260PwtN022135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Mar 2018 00:25:58 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w260PvwU024868; Tue, 6 Mar 2018 00:25:57 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Mar 2018 16:25:56 -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 01/65] x86/mm: Add INVPCID helpers Date: Mon, 5 Mar 2018 19:24:34 -0500 Message-Id: <20180306002538.1761-2-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=999 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: Andy Lutomirski commit 060a402a1ddb551455ee410de2eadd3349f2801b upstream. This adds helpers for each of the four currently-specified INVPCID modes. Signed-off-by: Andy Lutomirski Reviewed-by: Borislav Petkov Cc: Andrew Morton Cc: Andrey Ryabinin Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Luis R. Rodriguez Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Toshi Kani Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/8a62b23ad686888cee01da134c91409e22064db9.1454096309.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman (cherry picked from commit becf292446e9f2dc8842c448836bbe8005e24db0) Signed-off-by: Pavel Tatashin --- arch/x86/include/asm/tlbflush.h | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 7e459b7ee708..995937999e1f 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -7,6 +7,54 @@ #include #include +static inline void __invpcid(unsigned long pcid, unsigned long addr, + unsigned long type) +{ + u64 desc[2] = { pcid, addr }; + + /* + * The memory clobber is because the whole point is to invalidate + * stale TLB entries and, especially if we're flushing global + * mappings, we don't want the compiler to reorder any subsequent + * memory accesses before the TLB flush. + * + * The hex opcode is invpcid (%ecx), %eax in 32-bit mode and + * invpcid (%rcx), %rax in long mode. + */ + asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01" + : : "m" (desc), "a" (type), "c" (desc) : "memory"); +} + +#define INVPCID_TYPE_INDIV_ADDR 0 +#define INVPCID_TYPE_SINGLE_CTXT 1 +#define INVPCID_TYPE_ALL_INCL_GLOBAL 2 +#define INVPCID_TYPE_ALL_NON_GLOBAL 3 + +/* Flush all mappings for a given pcid and addr, not including globals. */ +static inline void invpcid_flush_one(unsigned long pcid, + unsigned long addr) +{ + __invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR); +} + +/* Flush all mappings for a given PCID, not including globals. */ +static inline void invpcid_flush_single_context(unsigned long pcid) +{ + __invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT); +} + +/* Flush all mappings, including globals, for all PCIDs. */ +static inline void invpcid_flush_all(void) +{ + __invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL); +} + +/* Flush all mappings for all PCIDs except globals. */ +static inline void invpcid_flush_all_nonglobals(void) +{ + __invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL); +} + #ifdef CONFIG_PARAVIRT #include #else -- 2.16.2