Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3006415imu; Fri, 18 Jan 2019 03:11:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ZrtAtc6ibDeMb3p1SHk6JmZ9Nb3wq+XOYBKMiQ9A0pHJNZ8gs76prFkuzNHurwxSQW94t X-Received: by 2002:a17:902:5ac2:: with SMTP id g2mr18819316plm.313.1547809910024; Fri, 18 Jan 2019 03:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547809910; cv=none; d=google.com; s=arc-20160816; b=cRlSjsPJ88RQ0t+XqdGcMnIhAFFW6FrQ4JLMpwUSYSWVtRu0ZhVRt8xssEFl017/8D idt3qjvOSCdWNUh277IrTCEu6QnWWXprV5AJjlFuzKjdMVQur/sCTlBvblAQOT4FXjaZ UmIvpib28tifFtr5plqk9KhqUzwY2I8xtGHpG14b8ntXeXr8FFxFbiBHDM7Xmtwdkoag Y5CP5s9CGuOsnjq91mPVCSHTfV/3a8kLCUMIOvrAvTT/uaGsQMsHdVvFMct6lIBhb9vP CIvbAX0d1ZjSVNjG3/Lspa26rEl0fxMotQUUgpbbyU26lLbuzAGl3viBCyaYyL9nscrS 5Ruw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:subject:cc:to:from:date:message-id :mime-version:dkim-signature; bh=vJ0vJrzTwis8w2+AQlcWaXGQ6PMulOuhthc3OKzqbnM=; b=Ru4h9jdKKqzkEeM3vqxHJs5G4mriMX6hNONqjfsEBIWn8qhhljQrL0ZGjFQEhZlBcw 4a29sOJbrtaSyox48j78fzGYC9ftBmhWpFlCI2o9ZKnLH+VD+0Ffyyu4OeaHxQt8Apjk k5rp2QxfpyH+mCT3IDXQhuaLhWkopYkjYTk6jNlviOluvuzvAXiiGxbXILGOZcDQmH+Z j/gPvXKmKmPH6Ul8Yku4Gwzb2u9oFCwy8VtKjWL2GAg+PtzwTCh0fj2TCNVCfAxtun+C A3vStk1VoqpK0f9kmEtNzx2tLuMbdcpyT/3gKrz4+Y7MqHAr+99Nb33W/+CtEtfm4Wl0 uozg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=zqSqv6En; 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 l129si4713325pfl.284.2019.01.18.03.11.34; Fri, 18 Jan 2019 03:11:49 -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-2018-07-02 header.b=zqSqv6En; 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 S1727164AbfARLKY (ORCPT + 99 others); Fri, 18 Jan 2019 06:10:24 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:44098 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725982AbfARLKX (ORCPT ); Fri, 18 Jan 2019 06:10:23 -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 x0IB3nd2097799; Fri, 18 Jan 2019 11:09:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=vJ0vJrzTwis8w2+AQlcWaXGQ6PMulOuhthc3OKzqbnM=; b=zqSqv6En949O1MnRipyzH3VB4x8nRv7kbP2WvnPrGWXPrf6CuFit4KyxvD2SXkumhECO pcb9mEJLlZihvbXpSvNNXVby1kysnf1uf7p3lPW47wsP/ez7rWq2a42B1zcLclo3wQo7 iE0ofE0dKeaufNMHmr5aPEfj1xTKSvTBwjjH6/Y+v6hxtriigBYVNjkAbw/yEFB7PA1F JMzrQG7TTVn0d6J8iBzg8AnIPRZ57nPbnuW6L6Z85n6EjjXeLmDlqLvXlDa4u1e6LVYi N4MdHbx0GkJ4HwTMWfR7sSB4wK0TRknoYqknVf1Q5RoGsaAeOFQr0RC75aZScsZHg2dQ 2A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2pybjsn2k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jan 2019 11:09:57 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0IB9tut019376 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jan 2019 11:09:55 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0IB9sXN031280; Fri, 18 Jan 2019 11:09:54 GMT MIME-Version: 1.0 Message-ID: <48a105d3-fa32-40e4-9775-37d49f42eac0@default> Date: Fri, 18 Jan 2019 03:09:54 -0800 (PST) From: Zhenzhong Duan To: Cc: , , , , , , , , Subject: [PATCH] x86/speculation: Update TIF_SPEC_IB before ibpb barrier X-Mailer: Zimbra on Oracle Beehive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9139 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=536 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901180083 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a task is set for updating TIF_SPEC_IB throuth SECCOMP by others and it's scheduled in the first time, a stale TIF_SPEC_IB value is picked in cond_ibpb(). This is due to TIF_SPEC_IB is updated later at __switch_to_xtra(). Add an extra call to speculation_ctrl_update_tif() to update it before IBPB barrier. Signed-off-by: Zhenzhong Duan --- arch/x86/include/asm/spec-ctrl.h | 1 + arch/x86/kernel/process.c | 2 +- arch/x86/mm/tlb.c | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/spec-ctrl.h b/arch/x86/include/asm/spec-c= trl.h index 5393bab..8b2814a 100644 --- a/arch/x86/include/asm/spec-ctrl.h +++ b/arch/x86/include/asm/spec-ctrl.h @@ -82,6 +82,7 @@ static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn) static inline void speculative_store_bypass_ht_init(void) { } #endif =20 +extern unsigned long speculation_ctrl_update_tif(struct task_struct *tsk); extern void speculation_ctrl_update(unsigned long tif); extern void speculation_ctrl_update_current(void); =20 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 90ae0ca..454e71d 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -446,7 +446,7 @@ static __always_inline void __speculation_ctrl_update(u= nsigned long tifp, =09=09wrmsrl(MSR_IA32_SPEC_CTRL, msr); } =20 -static unsigned long speculation_ctrl_update_tif(struct task_struct *tsk) +unsigned long speculation_ctrl_update_tif(struct task_struct *tsk) { =09if (test_and_clear_tsk_thread_flag(tsk, TIF_SPEC_FORCE_UPDATE)) { =09=09if (task_spec_ssb_disable(tsk)) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 999d6d8..c0f3fcf 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -8,6 +8,7 @@ #include #include =20 +#include #include #include #include @@ -190,7 +191,8 @@ static void sync_current_stack_to_mm(struct mm_struct *= mm) =20 static inline unsigned long mm_mangle_tif_spec_ib(struct task_struct *next= ) { -=09unsigned long next_tif =3D task_thread_info(next)->flags; +=09/* Update the flag bits to newest value actively */ +=09unsigned long next_tif =3D speculation_ctrl_update_tif(next); =09unsigned long ibpb =3D (next_tif >> TIF_SPEC_IB) & LAST_USER_MM_IBPB; =20 =09return (unsigned long)next->mm | ibpb; --=20 1.8.3.1